image_types_phosphor: mmc: Fill empty image with zeros

There are errors seeing in the eMMC when the empty space of an
image is filled with 0xff like it's done for NOR chips instead of
0s. Create a function to create empty images with 0s.

Also create an empty image for u-boot of 1MB (twice its current
size) so if the u-boot image that is flashed on a system is
smaller than what the system has, there's no leftover data at
the end that can cause issues.

Tested: Booted the new image-u-boot file on HW.

Change-Id: Ifc08b4e6a61fc52bbb37f13a0b02b2741a359997
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/classes/image_types_phosphor.bbclass b/classes/image_types_phosphor.bbclass
index 3980120..e466347 100644
--- a/classes/image_types_phosphor.bbclass
+++ b/classes/image_types_phosphor.bbclass
@@ -55,6 +55,7 @@
 FLASH_UBI_RWFS_TXT_SIZE_flash-131072 ?= "32MiB"
 
 # eMMC sizes in KB unless otherwise noted.
+MMC_UBOOT_SIZE ?= "1024"
 MMC_BOOT_PARTITION_SIZE ?= "65536"
 
 SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv"
@@ -104,6 +105,12 @@
 		| tr '\000' '\377' > $image_dst
 }
 
+mk_empty_image_zeros() {
+	image_dst="$1"
+	image_size_kb=$2
+	dd if=/dev/zero of=$image_dst bs=1k count=$image_size_kb
+}
+
 clean_rwfs() {
 	type=$1
 	shift
@@ -423,13 +430,14 @@
 
 do_generate_ext4_tar() {
 	# Generate the U-Boot image
+	mk_empty_image_zeros image-u-boot ${MMC_UBOOT_SIZE}
 	do_generate_image_uboot_file image-u-boot
 
 	# Generate a compressed ext4 filesystem with the fitImage file in it to be
 	# flashed to the boot partition of the eMMC
 	install -d boot-image
 	install -m 644 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} boot-image/fitImage
-	mk_empty_image boot-image.${FLASH_EXT4_BASETYPE} ${MMC_BOOT_PARTITION_SIZE}
+	mk_empty_image_zeros boot-image.${FLASH_EXT4_BASETYPE} ${MMC_BOOT_PARTITION_SIZE}
 	mkfs.ext4 -F -i 4096 -d boot-image boot-image.${FLASH_EXT4_BASETYPE}
 	# Error codes 0-3 indicate successfull operation of fsck
 	fsck.ext4 -pvfD boot-image.${FLASH_EXT4_BASETYPE} || [ $? -le 3 ]