]> code.ossystems Code Review - bsp/u-boot.git/commitdiff
UpdateHub: Add common header 2017.07+ossystems
authorOtavio Salvador <otavio@ossystems.com.br>
Wed, 14 Jun 2017 15:21:16 +0000 (12:21 -0300)
committerOtavio Salvador <otavio@ossystems.com.br>
Fri, 14 Jul 2017 20:18:04 +0000 (17:18 -0300)
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
include/configs/updatehub-common.h [new file with mode: 0644]

diff --git a/include/configs/updatehub-common.h b/include/configs/updatehub-common.h
new file mode 100644 (file)
index 0000000..a1086aa
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 O.S. Systems Software LTDA.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * This header helps to add support for UpdateHub in U-Boot. It
+ * assumes your U-Boot has support for bootcount (either using a SoC
+ * feature or the environment fallback).
+ */
+
+#ifndef __UPDATEHUB_H
+#define __UPDATEHUB_H
+
+#define CONFIG_BOOTCOUNT_LIMIT
+
+#ifdef CONFIG_ENV_IS_NOWHERE
+# error Environment saving is required for UpdateHub use
+#endif
+
+#define UPDATEHUB_ENV \
+    "upgrade_available=0\0" \
+    "bootlimit=1\0" \
+    "bootcount=0\0" \
+    \
+    "updatehub_find_root_a=" UPDATEHUB_FIND_ROOT_A ";\0" \
+    "updatehub_load_os_a=" UPDATEHUB_LOAD_OS_A ";\0" \
+    \
+    "updatehub_find_root_b=" UPDATEHUB_FIND_ROOT_B ";\0" \
+    "updatehub_load_os_b=" UPDATEHUB_LOAD_OS_B ";\0" \
+    \
+    "updatehub_bootargs=setenv bootargs " UPDATEHUB_BOOTARGS ";\0" \
+    \
+    "updatehub_altbootcmd=" \
+        "if test ${updatehub_active} = 0; then " \
+            "echo Bootcount limit reached. Reverting to image B; " \
+            "setenv updatehub_active 1; " \
+        "else " \
+            "echo Bootcount limit reached. Reverting to image A; " \
+            "setenv updatehub_active 1; " \
+        "fi; " \
+        "setenv upgrade_available 0; " \
+        "saveenv;\0" \
+    "altbootcmd=run updatehub_altbootcmd bootcmd;\0"
+
+#undef CONFIG_BOOTCOMMAND
+#define CONFIG_BOOTCOMMAND \
+    "if test -z \"${updatehub_active}\"; then " \
+        "echo Ensuring environment is accessible in Linux...; " \
+        "setenv updatehub_active 0; " \
+        "saveenv; " \
+    "fi; " \
+    "if test ${updatehub_active} = 0; then " \
+        "echo Loading system from A; " \
+        "run updatehub_find_root_a updatehub_load_os_a updatehub_bootargs; " \
+    "else " \
+        "if test ${updatehub_active} = 1; then " \
+            "echo Loading system from B; " \
+            "run updatehub_find_root_b updatehub_load_os_b updatehub_bootargs; " \
+        "else " \
+            "echo Invalid updatehub_active value, resetting it; " \
+            "setenv updatehub_active 0; " \
+            "saveenv; " \
+            "reset; " \
+        "fi; " \
+    "fi;" \
+    UPDATEHUB_BOOTCMD
+
+#endif  /* __UPDATEHUB_H */