clearfog: Store the machine-id in uboot's env

It would be nice to simply save this into /etc/machine-id, but our
overlayfs which is mounted at /etc makes this, er, "tricky" (just take a
look at the etc-overlay.service). We *could* probably do something like
temporarily mounting the rootfs r/w just to update that file at bootup,
and writing it to the other slot during updates from within RAUC, but
that would be yet another special case. How would we handle the initial
flashing, for example?

This approach, while needlessly complicating the bootloader's setup (and
that's a big consideration for me) makes the overlay FS provisioning a
bit easier. We caught that special case of /etc/machine-id being a mount
of tmpfs early enough. The root filesystem remains truly read-only, etc.

Change-Id: I27972ef99b8e19cd44736d062cb5e6e7a1f16bde
diff --git a/board/czechlight/clearfog/overlay/usr/lib/systemd/system/multi-user.target.wants/save-machineid-to-uboot.service b/board/czechlight/clearfog/overlay/usr/lib/systemd/system/multi-user.target.wants/save-machineid-to-uboot.service
new file mode 120000
index 0000000..b60a4f9
--- /dev/null
+++ b/board/czechlight/clearfog/overlay/usr/lib/systemd/system/multi-user.target.wants/save-machineid-to-uboot.service
@@ -0,0 +1 @@
+../save-machineid-to-uboot.service
\ No newline at end of file
diff --git a/board/czechlight/clearfog/overlay/usr/lib/systemd/system/save-machineid-to-uboot.service b/board/czechlight/clearfog/overlay/usr/lib/systemd/system/save-machineid-to-uboot.service
new file mode 100644
index 0000000..892411b
--- /dev/null
+++ b/board/czechlight/clearfog/overlay/usr/lib/systemd/system/save-machineid-to-uboot.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=Save the machine-id into U-Boot environment if not set
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c 'fw_printenv machineid &>/dev/null || fw_setenv machineid $(cat /etc/machine-id)'
diff --git a/board/czechlight/clearfog/patches/u-boot/boot.patch b/board/czechlight/clearfog/patches/u-boot/boot.patch
index 3ec36c0..1d4520b 100644
--- a/board/czechlight/clearfog/patches/u-boot/boot.patch
+++ b/board/czechlight/clearfog/patches/u-boot/boot.patch
@@ -88,7 +88,7 @@
 +CONFIG_WDT=y
 +CONFIG_WDT_ORION=y
 diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h
-index 5061f6c6fd..04faf5c49f 100644
+index 5061f6c6fd..2465b3d933 100644
 --- a/include/configs/clearfog.h
 +++ b/include/configs/clearfog.h
 @@ -32,6 +32,11 @@
@@ -157,7 +157,7 @@
 +	"  saveenv;" \
 +	"  reset;" \
 +	"fi;" \
-+	"setenv bootargs root=/dev/mmcblk0p${rauc_part} rauc.slot=${rauc_slot} czechlight=${czechlight} ${extra_bootargs};" \
++	"setenv bootargs root=/dev/mmcblk0p${rauc_part} rauc.slot=${rauc_slot} czechlight=${czechlight} systemd.machine_id=${machineid} ${extra_bootargs};" \
 +	"load mmc 0:${rauc_part} ${fdt_addr_r} /boot/armada-388-clearfog-base.dtb || reset;" \
 +	"load mmc 0:${rauc_part} ${kernel_addr_r} /boot/zImage || reset;" \
 +	"bootz ${kernel_addr_r} - ${fdt_addr_r} || reset\0"