image_types_phosphor: Create a image-u-boot file with spl

If a u-boot spl file is built, generate a image-u-boot file
with it so that code update can flash the u-boot mtd with
the spl.

(From meta-phosphor rev: 8fe768d9c696730eb67d48c243cbab9b228b8334)

Change-Id: I8ead2155593945602c925b26e85d2b6effc206f9
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/meta-phosphor/classes/image_types_phosphor.bbclass b/meta-phosphor/classes/image_types_phosphor.bbclass
index 0259cf6..0d2ed89 100644
--- a/meta-phosphor/classes/image_types_phosphor.bbclass
+++ b/meta-phosphor/classes/image_types_phosphor.bbclass
@@ -315,6 +315,22 @@
 	mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
 }
 
+do_generate_image_uboot_file() {
+    image_dst="$1"
+    uboot_offset=${FLASH_UBOOT_OFFSET}
+
+    if [ ! -z ${SPL_BINARY} ]; then
+        dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
+            if=${DEPLOY_DIR_IMAGE}/u-boot-spl.${UBOOT_SUFFIX} \
+            of=${image_dst}
+        uboot_offset=${FLASH_UBOOT_SPL_SIZE}
+    fi
+
+    dd bs=1k conv=notrunc seek=${uboot_offset} \
+        if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
+        of=${image_dst}
+}
+
 python do_generate_static() {
     import subprocess
 
@@ -379,9 +395,9 @@
 	ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
 
 	# Maintain non-standard legacy links
+	do_generate_image_uboot_file ${IMGDEPLOYDIR}/image-u-boot
 	ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
 	ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
-	ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
 	ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
 	ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
 	ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
@@ -437,7 +453,7 @@
 
 	# Create some links to help make the tar archive in the format
 	# expected by phosphor-bmc-code-mgmt.
-	ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
+	do_generate_image_uboot_file image-u-boot
 	ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
 	ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
 	ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs