clearfog: Prepare data for flashing via USB to eMMC

At first, I tried to use just one `genimage` configuration file for this
purpose, but I wasn't able to come up with any method to either leverage
the sparseness of the sdcard.img file, or to make `genimage` compress
it. It would be quite wasteful to create huge image files, after all.
However, I wasn't able to find any proper way for doing that just with
`genimage`. I tried:

- The `tar` and `cpio` backends which implement compression. This didn't
work because it seems that one cannot redefine their actual *content*.
- Using `exec_pre` and `exec_post` to force a command. That didn't work
either because genimage checks for file availability prior to running
them.

In the end, this extra shell script simply compresses the SD card image
and calls `genimage` once more. I chose `mksquashfs` because it was much
faster with sparse input than both `gzip` and `bzip2`.

Change-Id: Ia80443108e879fe89b0815e45e5338c5eebf33f3
diff --git a/board/czechlight/clearfog/genimage.cfg b/board/czechlight/clearfog/genimage.cfg
index 548f538..7633c8f 100644
--- a/board/czechlight/clearfog/genimage.cfg
+++ b/board/czechlight/clearfog/genimage.cfg
@@ -36,26 +36,3 @@
 		size = 2000M
 	}
 }
-
-image usb-flash.vfat {
-	vfat {
-		file "boot.scr" { image = "usb-boot.scr" }
-		files = {
-			"zImage",
-			"czechlight-clearfog.dtb",
-			"rootfs.cpio.uboot"
-		}
-	}
-	size = 64M
-}
-
-image usb-flash.img {
-	hdimage {
-	}
-
-	partition boot {
-		partition-type = 0xc
-		bootable = true
-		image = "usb-flash.vfat"
-	}
-}
diff --git a/board/czechlight/clearfog/usb-flash-genimage.sh b/board/czechlight/clearfog/usb-flash-genimage.sh
new file mode 100755
index 0000000..c907625
--- /dev/null
+++ b/board/czechlight/clearfog/usb-flash-genimage.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -ex
+
+mksquashfs ${BINARIES_DIR}/sdcard.img ${BINARIES_DIR}/sdcard.img.squashfs -root-owned -comp gzip -progress
+
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+rm -rf "${GENIMAGE_TMP}"
+
+genimage --rootpath "${TARGET_DIR}" --tmppath "${GENIMAGE_TMP}" --inputpath "${BINARIES_DIR}" --outputpath "${BINARIES_DIR}" --config "${BR2_EXTERNAL_CZECHLIGHT_PATH}/board/czechlight/clearfog/usb-genimage.cfg"
diff --git a/board/czechlight/clearfog/usb-genimage.cfg b/board/czechlight/clearfog/usb-genimage.cfg
new file mode 100644
index 0000000..5f0820a
--- /dev/null
+++ b/board/czechlight/clearfog/usb-genimage.cfg
@@ -0,0 +1,24 @@
+image usb-flash.vfat {
+	vfat {
+		file "boot.scr" { image = "usb-boot.scr" }
+		files = {
+			"zImage",
+			"czechlight-clearfog.dtb",
+			"rootfs.cpio.uboot",
+			"u-boot-spl.kwb",
+			"sdcard.img.squashfs"
+		}
+	}
+	size = 128M
+}
+
+image usb-flash.img {
+	hdimage {
+	}
+
+	partition boot {
+		partition-type = 0xc
+		bootable = true
+		image = "usb-flash.vfat"
+	}
+}
diff --git a/configs/czechlight_clearfog_defconfig b/configs/czechlight_clearfog_defconfig
index e3cd782..60b84e1 100644
--- a/configs/czechlight_clearfog_defconfig
+++ b/configs/czechlight_clearfog_defconfig
@@ -13,7 +13,7 @@
 # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
 BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/overlay/ $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/clearfog/overlay/"
 BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/mk-empty-cfg-fs.sh $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/install-rauc-cert.sh $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/clearfog/copy-boot-scr.sh"
-BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/clearfog/mk-rauc-bundle.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/clearfog/mk-rauc-bundle.sh ${BR2_EXTERNAL_CZECHLIGHT_PATH}/board/czechlight/clearfog/usb-flash-genimage.sh"
 BR2_ROOTFS_POST_SCRIPT_ARGS="-c $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/clearfog/genimage.cfg"
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_VERSION=y