[U-Boot] [RFC] env: ti: Handle reboot reason from BCB

Sam Protsenko semen.protsenko at linaro.org
Thu Jun 20 21:25:44 UTC 2019


*** PLEASE DO NOT MERGE.
*** This is only RFC, a discussion thread. Patch is only for the
*** reference here right now, to create a discussion context.

There are 2 possible reboot use-cases:
  1. User did "fastboot reboot bootloader" (we're setting "dofastboot"
     variable as an indicator in this case)
  2. User did "adb reboot bootloader" or "reboot bootloader" from Linux
     shell (Android sets "bootonce-bootloader" string into command field
     of BCB area inside of 'misc' partition as an indicator in this
     case)

We already had (1) handling implemented. This patch adds implementation
of (2). Possible drawbacks are:
  - user is able to re-define 'preboot' variable and break this
    mechanism this way
  - performance penalty due to scripting usage in 'preboot'

DISCUSSION ITEM 1: possible solution to those can be checking BCB area
(and 'dofastboot' variable) in C code, somewhere in board file, like
in late_init() function, and on;y set 'preboot' variable from there,
if conditions are met, to something like this:

    preboot=fastboot 1; setenv preboot;

so that next time 'preboot' variable will be empty. But this way also
has its shortcomings, like the necessity of board file modification,
need of BCB C API exposure, etc.

DISCUSSION ITEM 2: this patch only implements reboot reason handling for
TI platforms. I presume there could be another parties interested in
this feature. Should we somehow provide some generic way for handling
that (at least mechanism for checking), or is it a bad idea, and
everyone should handle this in their own way?

DISCUSSION ITEM 3: I didn't handle "reboot recovery" reason here. Does
anyone have some ideas on that? This doc [1] a bit of confuses me, but
as I understand, the 'recovery' partition will remain, so in case of
"reboot recovery" we just need to load recovery partition into the RAM
and run bootm for that. Is that correct or I'm missing something?

[1] https://source.android.com/devices/tech/ota/ab/ab_implement

Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
---
 include/environment/ti/boot.h | 43 ++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h
index 8ddb0416c4..943adcad40 100644
--- a/include/environment/ti/boot.h
+++ b/include/environment/ti/boot.h
@@ -126,13 +126,44 @@
 		"if test $fdtfile = undefined; then " \
 			"echo WARNING: Could not determine device tree to use; fi; \0"
 
-#define CONFIG_PREBOOT \
+#define FASTBOOT_CMD \
+	"echo Booting into fastboot ...; " \
+	"fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; "
+
+/* Check we are booting from "fastboot reboot bootloader" */
+#define PREBOOT_CHECK_DOFASTBOOT \
 	"if test ${dofastboot} -eq 1; then " \
-		"echo Boot fastboot requested, resetting dofastboot ...;" \
-		"setenv dofastboot 0; saveenv;" \
-		"echo Booting into fastboot ...; " \
-		"fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
-	"fi;" \
+		"echo Boot fastboot requested, resetting dofastboot ...; " \
+		"setenv dofastboot 0; saveenv; " \
+		FASTBOOT_CMD \
+	"fi; "
+
+/* Check reboot reason in BCB area of 'misc' partition */
+#define PREBOOT_CHECK_BCB \
+	"if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " misc; " \
+	"then " \
+		"if bcb test command = bootonce-bootloader; then " \
+			"echo Boot fastboot requested, resetting BCB ...; " \
+			"bcb clear command; bcb store; " \
+			FASTBOOT_CMD \
+		"elif bcb test command = boot-recovery; then " \
+			"echo Boot recovery requested; resetting BCB ...; " \
+			"bcb clear command; bcb store; " \
+			"echo TODO: RECOVERY_CMD is not implemented; " \
+		"fi; " \
+	"else " \
+		"echo Error: BCB/misc is corrupted or does not exist; " \
+	"fi; "
+
+/* Enter fastboot mode if user requested it */
+#if CONFIG_IS_ENABLED(CMD_BCB)
+# define CONFIG_PREBOOT \
+	PREBOOT_CHECK_DOFASTBOOT \
+	PREBOOT_CHECK_BCB
+#else
+# define CONFIG_PREBOOT \
+	PREBOOT_CHECK_DOFASTBOOT
+#endif
 
 #define CONFIG_BOOTCOMMAND \
 	"if test ${boot_fit} -eq 1; then "	\
-- 
2.20.1



More information about the U-Boot mailing list