clearfog: LED indication of a boot progress

On our board, a reset activates several CS GPIOs at once. We have a gate
which triggers a reset of the MAX14830 and MCP23S08 chips on that
condition. We *could* somehow hack around this, but that just screams
"too fragile" to me (GPIO state on reboot != GPIO state on power on),
which is why I'm leaving this as-is.

So all LEDs will be off after a reboot -- fine. Once the kernel gets
around to setting up drivers for SPI chips, the green LED will start
blinking. This phase should be quite short because there's a HW watchdog
which will reboot the board again (and therefore turn off all LEDs)
unless the system manages to boot properly.

Once everything is up, we simply turn the green LED to a steady on
state.

Change-Id: I3fde56f95e0db92aa763e013d6e5567dc26d85ed
diff --git a/board/czechlight/clearfog/sdn-roadm-clearfog.dtsi b/board/czechlight/clearfog/sdn-roadm-clearfog.dtsi
index 66bd340..6d91147 100644
--- a/board/czechlight/clearfog/sdn-roadm-clearfog.dtsi
+++ b/board/czechlight/clearfog/sdn-roadm-clearfog.dtsi
@@ -42,7 +42,7 @@
 
 		ok_led {
 			label = "status-ok";
-			linux,default-trigger = "default-on";
+			linux,default-trigger = "timer";
 #ifdef IFACE_V_1_0
 			gpios = <&max14830 9 GPIO_ACTIVE_HIGH>;
 #else
diff --git a/configs/czechlight_clearfog_defconfig b/configs/czechlight_clearfog_defconfig
index 1cc67d9..dd3330f 100644
--- a/configs/czechlight_clearfog_defconfig
+++ b/configs/czechlight_clearfog_defconfig
@@ -72,6 +72,7 @@
 CZECHLIGHT_CFG_FS_SIZE="256M"
 CZECHLIGHT_CFG_FS_PERSIST_SYSREPO=y
 CZECHLIGHT_CFG_FS_PERSIST_KEYS=y
+BR2_PACKAGE_CZECHLIGHT_CLEARFOG_LEDS_BOOT=y
 CZECHLIGHT_RAUC_ROOTFS=y
 CZECHLIGHT_RAUC_COMPATIBLE="czechlight-clearfog"
 CZECHLIGHT_RAUC_SLOT_A_ROOTFS_DEV="/dev/mmcblk0p1"
diff --git a/package/Config.in b/package/Config.in
index 17cd498..cc97cbe 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1,5 +1,6 @@
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/cla-sysrepo/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-cfg-fs/Config.in"
+source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-clearfog-leds-boot/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-rauc/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-separate-boot/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/grub2-tools/Config.in"
diff --git a/package/czechlight-clearfog-leds-boot/Config.in b/package/czechlight-clearfog-leds-boot/Config.in
new file mode 100644
index 0000000..88e47ff
--- /dev/null
+++ b/package/czechlight-clearfog-leds-boot/Config.in
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_CZECHLIGHT_CLEARFOG_LEDS_BOOT
+	bool "Indicate a successful boot via LEDs"
+	depends on CZECHLIGHT_RAUC_ROOTFS
+	depends on BR2_INIT_SYSTEMD
diff --git a/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds-boot.mk b/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds-boot.mk
new file mode 100644
index 0000000..8d0896a
--- /dev/null
+++ b/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds-boot.mk
@@ -0,0 +1,9 @@
+define CZECHLIGHT_CLEARFOG_LEDS_BOOT_INSTALL_TARGET_CMDS
+	mkdir -p $(TARGET_DIR)/usr/lib/systemd/system/multi-user.target.wants/
+	$(INSTALL) -D -m 0644 \
+		$(BR2_EXTERNAL_CZECHLIGHT_PATH)/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds.service \
+		$(TARGET_DIR)/usr/lib/systemd/system/
+	ln -sf ../czechlight-clearfog-leds.service $(TARGET_DIR)/usr/lib/systemd/system/multi-user.target.wants/
+endef
+
+$(eval $(generic-package))
diff --git a/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds.service b/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds.service
new file mode 100644
index 0000000..3ad6202
--- /dev/null
+++ b/package/czechlight-clearfog-leds-boot/czechlight-clearfog-leds.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Indicate a successful boot via LEDs
+Requires=multi-user.target
+After=multi-user.target
+
+[Service]
+Type=oneshot
+ExecStartPre=/bin/sh -c '[ "$(/bin/systemctl list-units --failed --all --no-legend --no-pager)" == "" ]'
+ExecStart=/bin/sh -c 'echo default-on > /sys/class/leds/status-ok/trigger'