Consolidate flash image generation

Before c7248eb11c and 794bd3d4ac, flash image generation was split
between obmc-phosphor-image_types_uboot.bbclass and
image-overlay.bbclass.  This was because generate_flash() relied on
calling oe_mkimage() which was also defined in
obmc-phosphor-image_types_uboot.bbclass.  With that dependency removed,
all of the flash image generation can now be consolidated into
image-overlay.bbclass.  This location makes more sense as the .uboot
image type is for generating U-Boot legacy ramdisks while the overlay
image type is specifically for OpenBMC and its flash layout.
obmc-phopshor-image_types_uboot.bbclass is now empty and has been
removed.

Change-Id: Idcf38d3ef6f419780a7c54c77f1195bf3b5f5667
Signed-off-by: Rick Altherr <raltherr@google.com>
diff --git a/meta-phosphor/classes/image-overlay.bbclass b/meta-phosphor/classes/image-overlay.bbclass
index f0c4060..520ca6e 100644
--- a/meta-phosphor/classes/image-overlay.bbclass
+++ b/meta-phosphor/classes/image-overlay.bbclass
@@ -2,6 +2,7 @@
 EXCLUDE_FROM_WORLD = "1"
 
 INITRD_IMAGE ?= "obmc-phosphor-initramfs"
+INITRD_LINK_NAME = "${INITRD_IMAGE}-${MACHINE}${INITRAMFS_FSTYPE}"
 
 IMAGE_BASETYPE ?= "squashfs-xz"
 OVERLAY_BASETYPE ?= "jffs2"
@@ -13,7 +14,90 @@
 
 ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.${IMAGE_BASETYPE}"
 
+FLASH_IMAGE_NAME ?= "flash-${MACHINE}-${DATETIME}"
+FLASH_IMAGE_NAME[vardepsexclude] = "DATETIME"
+FLASH_IMAGE_LINK ?= "flash-${MACHINE}"
+
+FLASH_KERNEL_IMAGETYPE ?= "fitImage"
+
+FLASH_UBOOT_OFFSET ?= "0"
+FLASH_KERNEL_OFFSET ?= "512"
+FLASH_INITRD_OFFSET ?= "3072"
+FLASH_ROFS_OFFSET ?= "4864"
+FLASH_RWFS_OFFSET ?= "28672"
+RWFS_SIZE ?= "4096"
+
+# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
+# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
+# reserved for the primary image (and setting them currently breaks the build).
+# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
+DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}"
+
+OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file"
+
+# $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} ))
+
+mk_nor_image() {
+       image_dst="$1"
+       image_size_kb=$2
+       dd if=/dev/zero bs=1k count=${image_size_kb} \
+              | tr '\000' '\377' > ${image_dst}
+}
+
+do_generate_flash() {
+       INITRD_CTYPE=${INITRAMFS_CTYPE}
+       ddir="${DEPLOY_DIR_IMAGE}"
+       kernel="${FLASH_KERNEL_IMAGETYPE}"
+       uboot="u-boot.${UBOOT_SUFFIX}"
+       uinitrd="${INITRD_LINK_NAME}.cpio.${INITRD_CTYPE}.u-boot"
+       rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
+       rwfs="rwfs.${OVERLAY_BASETYPE}"
+
+       if [ ! -f $ddir/$kernel ]; then
+              bbfatal "Kernel file ${ddir}/${kernel} does not exist"
+       fi
+       if [ ! -f $ddir/$uboot ]; then
+              bbfatal "U-boot file ${ddir}/${uboot} does not exist"
+       fi
+       if [ ! -f $ddir/$uinitrd ]; then
+              bbfatal "uinitrd file ${ddir}/${uinitrd} does not exist"
+       fi
+       if [ ! -f $ddir/$rootfs ]; then
+              bbfatal "Rootfs file ${ddir}/${rootfs} does not exist"
+       fi
+
+       mk_nor_image ${ddir}/${rwfs} ${RWFS_SIZE}
+       if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then
+              mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} ${ddir}/${rwfs} || \
+                     bbfatal "mkfs rwfs"
+       fi
+
+       dst="${ddir}/${FLASH_IMAGE_NAME}"
+       rm -rf $dst
+       mk_nor_image ${dst} ${FLASH_SIZE}
+       dd if=${ddir}/${uboot} of=${dst} bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET}
+       dd if=${ddir}/${kernel} of=${dst} bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET}
+       dd if=${ddir}/${uinitrd} of=${dst} bs=1k conv=notrunc seek=${FLASH_INITRD_OFFSET}
+       dd if=${ddir}/${rootfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET}
+       dd if=${ddir}/${rwfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET}
+       dstlink="${ddir}/${FLASH_IMAGE_LINK}"
+       rm -rf $dstlink
+       ln -sf ${FLASH_IMAGE_NAME} $dstlink
+
+       ln -sf ${FLASH_IMAGE_NAME} ${ddir}/image-bmc
+       ln -sf ${uboot} ${ddir}/image-u-boot
+       ln -sf ${kernel} ${ddir}/image-kernel
+       ln -sf ${uinitrd} ${ddir}/image-initramfs
+       ln -sf ${rootfs} ${ddir}/image-rofs
+       ln -sf ${rwfs} ${ddir}/image-rwfs
+
+       tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.all.tar -C ${ddir} image-bmc
+       tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.tar -C ${ddir} image-u-boot image-kernel image-initramfs image-rofs image-rwfs
+}
+do_generate_flash[vardepsexclude] = "DATETIME"
+
 do_generate_flash[depends] += "${INITRD_IMAGE}:do_image_complete"
 do_generate_flash[depends] += "${PN}:do_image_complete"
+do_generate_flash[depends] += "u-boot:do_populate_sysroot"
 
 addtask generate_flash before do_build
diff --git a/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass b/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass
deleted file mode 100644
index 193cf8c..0000000
--- a/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass
+++ /dev/null
@@ -1,87 +0,0 @@
-inherit image_types_uboot
-
-INITRD_LINK_NAME = "${INITRD_IMAGE}-${MACHINE}${INITRAMFS_FSTYPE}"
-
-FLASH_IMAGE_NAME ?= "flash-${MACHINE}-${DATETIME}"
-FLASH_IMAGE_NAME[vardepsexclude] = "DATETIME"
-FLASH_IMAGE_LINK ?= "flash-${MACHINE}"
-
-FLASH_KERNEL_IMAGETYPE ?= "fitImage"
-
-FLASH_UBOOT_OFFSET ?= "0"
-FLASH_KERNEL_OFFSET ?= "512"
-FLASH_INITRD_OFFSET ?= "3072"
-FLASH_ROFS_OFFSET ?= "4864"
-FLASH_RWFS_OFFSET ?= "28672"
-RWFS_SIZE ?= "4096"
-
-# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
-# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
-# reserved for the primary image (and setting them currently breaks the build).
-# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
-DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}"
-
-OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file"
-
-# $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} ))
-
-# IMAGE_POSTPROCESS_COMMAND += "do_generate_flash"
-
-mk_nor_image() {
-       image_dst="$1"
-       image_size_kb=$2
-       dd if=/dev/zero bs=1k count=${image_size_kb} \
-              | tr '\000' '\377' > ${image_dst}
-}
-
-do_generate_flash() {
-       INITRD_CTYPE=${INITRAMFS_CTYPE}
-       ddir="${DEPLOY_DIR_IMAGE}"
-       kernel="${FLASH_KERNEL_IMAGETYPE}"
-       uboot="u-boot.${UBOOT_SUFFIX}"
-       uinitrd="${INITRD_LINK_NAME}.cpio.${INITRD_CTYPE}.u-boot"
-       rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
-       rwfs="rwfs.${OVERLAY_BASETYPE}"
-
-       if [ ! -f $ddir/$kernel ]; then
-              bbfatal "Kernel file ${ddir}/${kernel} does not exist"
-       fi
-       if [ ! -f $ddir/$uboot ]; then
-              bbfatal "U-boot file ${ddir}/${uboot} does not exist"
-       fi
-       if [ ! -f $ddir/$uinitrd ]; then
-              bbfatal "uinitrd file ${ddir}/${uinitrd} does not exist"
-       fi
-       if [ ! -f $ddir/$rootfs ]; then
-              bbfatal "Rootfs file ${ddir}/${rootfs} does not exist"
-       fi
-
-       mk_nor_image ${ddir}/${rwfs} ${RWFS_SIZE}
-       if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then
-              mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} ${ddir}/${rwfs} || \
-                     bbfatal "mkfs rwfs"
-       fi
-
-       dst="${ddir}/${FLASH_IMAGE_NAME}"
-       rm -rf $dst
-       mk_nor_image ${dst} ${FLASH_SIZE}
-       dd if=${ddir}/${uboot} of=${dst} bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET}
-       dd if=${ddir}/${kernel} of=${dst} bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET}
-       dd if=${ddir}/${uinitrd} of=${dst} bs=1k conv=notrunc seek=${FLASH_INITRD_OFFSET}
-       dd if=${ddir}/${rootfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET}
-       dd if=${ddir}/${rwfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET}
-       dstlink="${ddir}/${FLASH_IMAGE_LINK}"
-       rm -rf $dstlink
-       ln -sf ${FLASH_IMAGE_NAME} $dstlink
-
-       ln -sf ${FLASH_IMAGE_NAME} ${ddir}/image-bmc
-       ln -sf ${uboot} ${ddir}/image-u-boot
-       ln -sf ${kernel} ${ddir}/image-kernel
-       ln -sf ${uinitrd} ${ddir}/image-initramfs
-       ln -sf ${rootfs} ${ddir}/image-rofs
-       ln -sf ${rwfs} ${ddir}/image-rwfs
-
-       tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.all.tar -C ${ddir} image-bmc
-       tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.tar -C ${ddir} image-u-boot image-kernel image-initramfs image-rofs image-rwfs
-}
-do_generate_flash[vardepsexclude] = "DATETIME"
diff --git a/meta-phosphor/conf/machine/include/obmc-bsp-common.inc b/meta-phosphor/conf/machine/include/obmc-bsp-common.inc
index 99855ca..fb68f31 100644
--- a/meta-phosphor/conf/machine/include/obmc-bsp-common.inc
+++ b/meta-phosphor/conf/machine/include/obmc-bsp-common.inc
@@ -17,7 +17,7 @@
 IMAGE_FSTYPES += "cpio.${INITRAMFS_CTYPE}.u-boot"
 OBMC_IMAGE_EXTRA_INSTALL_append = " u-boot-fw-utils"
 
-IMAGE_CLASSES += "obmc-phosphor-image_types_uboot"
+IMAGE_CLASSES += "image_types_uboot"
 
 INITRAMFS_CTYPE ?= "lzma"
 INITRAMFS_FSTYPES += "cpio.${INITRAMFS_CTYPE}.u-boot"