clearfog: custom config for redundant boot via RAUC

Hopefully this is better than requiring yet another partition
essentially just for this boot script. Instead of that, it's a part of
the hardcoded U-Boot binary. However, still delegate as much stuff as
possible to the individual firmware slots.  It is quite dangerous to
attempt to re-flash the entire card, including the bootloader, on the
fly. Moving as much bits as possible to the environment makes it a bit
easier to introduce important changes such as, for example, volatile
rootfs, later on. Also for ad-hoc manual testing, this should be easier
than hacking bootcmd directly.

The "|| reset" are required because the watchdog timer is left running
*and* being periodically reset from within the uboot's prompt, which
completely defeats the point of our logic.
diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h
index 7c7ada1..ed7eb08 100644
--- a/include/configs/clearfog.h
+++ b/include/configs/clearfog.h
@@ -106,12 +106,43 @@
 	"scriptaddr=" SCRIPT_ADDR_R "\0" \
 	"pxefile_addr_r=" PXEFILE_ADDR_R "\0"
 
-#include <config_distro_bootcmd.h>
-
 #define CFG_EXTRA_ENV_SETTINGS \
 	RELOCATION_LIMITS_ENV_SETTINGS \
 	LOAD_ADDRESS_ENV_SETTINGS \
 	"console=ttyS0,115200\0" \
-	BOOTENV
+	"usbboot=usb start; fatload usb 0:1 ${scriptaddr} boot.scr; source ${scriptaddr}\0" \
+	"bootcmd=test -n \"${BOOT_A_LEFT}\" || setenv BOOT_A_LEFT 3;" \
+	"test -n \"${BOOT_B_LEFT}\" || setenv BOOT_B_LEFT 3;" \
+	"test -n \"${BOOT_ORDER}\" || setenv BOOT_ORDER \"A B\";" \
+	"for BOOT_SLOT in \"${BOOT_ORDER}\"; do" \
+	"  if test \"x${rauc_part}\" != \"x\"; then" \
+	"    ;" \
+	"  elif test \"x${BOOT_SLOT}\" = \"xA\"; then" \
+	"    if test ${BOOT_A_LEFT} -gt 0; then" \
+	"      setexpr BOOT_A_LEFT ${BOOT_A_LEFT} - 1;" \
+	"      echo \"Found valid slot A, ${BOOT_A_LEFT} attempts remaining\";" \
+	"      rauc_part=1;" \
+	"      rauc_slot=A;" \
+	"    fi;" \
+	"  elif test \"x${BOOT_SLOT}\" = \"xB\"; then" \
+	"    if test ${BOOT_B_LEFT} -gt 0; then" \
+	"      setexpr BOOT_B_LEFT ${BOOT_B_LEFT} - 1;" \
+	"      echo \"Found valid slot B, ${BOOT_B_LEFT} attempts remaining\";" \
+	"      rauc_part=3;" \
+	"      rauc_slot=B;" \
+	"    fi;" \
+	"  fi;" \
+	"done;" \
+	"if test -n \"${rauc_part}\"; then" \
+	"  saveenv ;" \
+	"else" \
+	"  echo \"No valid slot found, resetting tries to 3\";" \
+	"  setenv BOOT_A_LEFT 3;" \
+	"  setenv BOOT_B_LEFT 3;" \
+	"  saveenv;" \
+	"  reset;" \
+	"fi;" \
+	"load mmc 0:${rauc_part} ${scriptaddr} /boot/boot.scr || reset;" \
+	"source ${scriptaddr} || reset\0"
 
 #endif /* _CONFIG_CLEARFOG_H */