Attach the PNOR mtd device to UBI

Create a new service that gets the PNOR mtd device
from /proc/mtd and performs a ubiattach to it.
Since only one mtd device (PNOR) is being attached,
it's assumed that a /dev/ubi0 device is created.
Later when more devices/chips are attached, a udev
rule might be needed to link them to a specific ubi
device number.

Change-Id: I5e3018b7f4b9551861ca52718cc40b8ccfe0da6e
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/common/recipes-phosphor/flash/obmc-flash-bios.bb b/common/recipes-phosphor/flash/obmc-flash-bios.bb
index c425027..9fdd7e3 100644
--- a/common/recipes-phosphor/flash/obmc-flash-bios.bb
+++ b/common/recipes-phosphor/flash/obmc-flash-bios.bb
@@ -7,6 +7,9 @@
 inherit skeleton-gdbus
 inherit obmc-phosphor-dbus-service
 
+RDEPENDS_${PN} += "mtd-utils-ubifs"
+
 SKELETON_DIR = "flashbios"
 DBUS_SERVICE_${PN} += "org.openbmc.control.Flash.service"
 SYSTEMD_SERVICE_${PN} += "obmc-flash-init.service"
+SYSTEMD_SERVICE_${PN} += "obmc-flash-bios-ubiattach.service"
diff --git a/common/recipes-phosphor/flash/obmc-flash-bios/obmc-flash-bios-ubiattach.service b/common/recipes-phosphor/flash/obmc-flash-bios/obmc-flash-bios-ubiattach.service
new file mode 100644
index 0000000..90013ff
--- /dev/null
+++ b/common/recipes-phosphor/flash/obmc-flash-bios/obmc-flash-bios-ubiattach.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Attach the PNOR mtd device to UBI
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/sh -c 'grep pnor /proc/mtd |cut -c 4 |xargs {sbindir}/ubiattach /dev/ubi_ctrl -m'
+ExecStop=/bin/sh -c 'grep pnor /proc/mtd |cut -c 4 |xargs {sbindir}/ubidetach /dev/ubi_ctrl -m'