Skip to contentSkip to conversation

env: ti: boot: Handle reboot reason from BCB

PATCH New Sam Protsenko 3 participants 5 messages Jul 9, 2019 – Jul 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 env: ti: boot: Handle reboot reason from BCB

In case of Android boot, reboot reason can be written into BCB (usually it's an area in 'misc' partition). U-Boot then can obtain that reboot reason from BCB and handle it accordingly to achieve correct Android boot flow, like it was suggested in [1]:
- if it's empty: perform normal Android boot from eMMC
- if it contains "bootonce-bootloader": get into fastboot mode
- if it contains "boot-recovery": perform recovery boot

The latter is not implemented yet, as it depends on some features that are not implemented on TI platforms yet (in AOSP and in U-Boot).

[1] https://marc.info/?l=u-boot&m=152508418909737&w=2

---
 include/environment/ti/boot.h | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
include/environment/ti/boot.h +26 -2
index 54e9b2de4d..e37004af46 100644
@@ -98,6 +98,10 @@
 #define AB_SELECT ""
 #endif
 
+#define FASTBOOT_CMD \
+	"echo Booting into fastboot ...; " \
+	"fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; "
+
 #define DEFAULT_COMMON_BOOT_TI_ARGS \
 	"console=" CONSOLEDEV ",115200n8\0" \
 	"fdtfile=undefined\0" \
@@ -117,6 +121,27 @@
 		"setenv mmcroot /dev/mmcblk0p2 rw; " \
 		"run mmcboot;\0" \
 	"emmc_android_boot=" \
+	"if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " misc; " \
+	"then " \
+		"if bcb test command = bootonce-bootloader; then " \
+			"echo BCB: Bootloader boot...; " \
+			"bcb clear command; bcb store; " \
+			FASTBOOT_CMD \
+		"elif bcb test command = boot-recovery; then " \
+			"echo BCB: Recovery boot...; " \
+			"echo Warning: recovery boot is not implemented; " \
+			"echo Performing normal boot for now...; " \
+			"run emmc_android_normal_boot; " \
+		"else " \
+			"echo BCB: Normal boot requested...; " \
+			"run emmc_android_normal_boot; " \
+		"fi; " \
+	"else " \
+		"echo Warning: BCB is corrupted or does not exist; " \
+		"echo Performing normal boot...; " \
+		"run emmc_android_normal_boot; " \
+	"fi;\0" \
+	"emmc_android_normal_boot=" \
 		"echo Trying to boot Android from eMMC ...; " \
 		"run update_to_fit; " \
 		"setenv eval_bootargs setenv bootargs $bootargs; " \
@@ -176,8 +201,7 @@
 	"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) "; " \
+		FASTBOOT_CMD \
 	"fi;" \
 	"if test ${boot_fit} -eq 1; then "	\
 		"run update_to_fit;"	\
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 env: ti: boot: Handle reboot reason from BCB

Hi Sam,

include/environment/ti/boot.h line 128

Quoted 6 lines · Sam Protsenko
include/environment/ti/boot.h +5 -0
 	"emmc_android_boot=" \
+	"if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " misc; " \
+	"then " \
+		"if bcb test command = bootonce-bootloader; then " \
+			"echo BCB: Bootloader boot...; " \
+			"bcb clear command; bcb store; " \

Assuming there are multiple reboot reasons of type "bootonce/oneshot" (i.e. assumed to be cleared once detected/handled), 'bcb test' could implement the '-c' (clear) flag. This would allow removing the "bcb clear command; bcb store;" line, w/o altering the behavior.

It could be done in phase 2 (optimization/refinement).

Quoted 5 lines
include/environment/ti/boot.h +5 -0
+			FASTBOOT_CMD \
+		"elif bcb test command = boot-recovery; then " \
+			"echo BCB: Recovery boot...; " \
+			"echo Warning: recovery boot is not implemented; " \
+			"echo Performing normal boot for now...; " \

include/environment/ti/boot.h line 143

Quoted 10 lines
include/environment/ti/boot.h +10 -0
+			"run emmc_android_normal_boot; " \
+		"else " \
+			"echo BCB: Normal boot requested...; " \
+			"run emmc_android_normal_boot; " \
+		"fi; " \
+	"else " \
+		"echo Warning: BCB is corrupted or does not exist; " \
+		"echo Performing normal boot...; " \
+		"run emmc_android_normal_boot; " \
+	"fi;\0" \

As a general comment, yes, arguments can be brought that this scripted handling is getting hairy and could be replaced by a command like boot{a,_android} (you name it).

In my opinion, the main downside of "boot{a,_android}" wrapper is that it implies sprinkling U-Boot with special-purpose variables like ${fastbootcmd} [1], ${recoverycmd}, ${my_usecase_cmd}, etc (the number of those would likely match the number of if/else branches in this patch). Decentralized usage of those variables (i.e. set at point A and read/used at point B) would IMHO:
- complicate the boot flow and its understanding, hence would
- require to write and maintain additional documentation
- open doors for creative issues

I contrast to the above, the approach taken in this patch:
- avoids any special-purpose global variables
- avoids spawning yet another boot{*} command
- centralizes/limits the boot flow handling to one file
- doesn't require much documentation (the code is self-explanatory)
- in case of bugs, would require coming back to the same place
- makes debugging easier

Quoted 5 lines
include/environment/ti/boot.h +1 -0
+	"emmc_android_normal_boot=" \
 		"echo Trying to boot Android from eMMC ...; " \
 		"run update_to_fit; " \
 		"setenv eval_bootargs setenv bootargs $bootargs; " \

include/environment/ti/boot.h line 207

Quoted 9 lines
include/environment/ti/boot.h +1 -2
@@ -176,8 +201,7 @@
 	"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) "; " \
+		FASTBOOT_CMD \
 	"fi;" \
 	"if test ${boot_fit} -eq 1; then "	\
 		"run update_to_fit;"	\

That said, I still admit that my statements could be highly subjective and that the best of our collective experience (as users, developers and maintainers) would be achieved in a different way than described.

Below is based on code review only (can't test due to lack of HW):

[1] https://android.googlesource.com/platform/external/u-boot/+/7d8d87584d7c/cmd/boot_android.c#67

Signature · 2 lines
Best Regards,
Eugeniu.
#2 lore raw

PATCH 1/1 env: ti: boot: Handle reboot reason from BCB

Hi Eugeniu,

Quoted 48 lines · Eugeniu Rosca

Hi Sam,

include/environment/ti/boot.h line 128

Quoted 6 lines · Sam Protsenko
      "emmc_android_boot=" \
include/environment/ti/boot.h +5 -0
+     "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " misc; " \
+     "then " \
+             "if bcb test command = bootonce-bootloader; then " \
+                     "echo BCB: Bootloader boot...; " \
+                     "bcb clear command; bcb store; " \

Assuming there are multiple reboot reasons of type "bootonce/oneshot" (i.e. assumed to be cleared once detected/handled), 'bcb test' could implement the '-c' (clear) flag. This would allow removing the "bcb clear command; bcb store;" line, w/o altering the behavior.

It could be done in phase 2 (optimization/refinement).

Quoted 5 lines
include/environment/ti/boot.h +5 -0
+                     FASTBOOT_CMD \
+             "elif bcb test command = boot-recovery; then " \
+                     "echo BCB: Recovery boot...; " \
+                     "echo Warning: recovery boot is not implemented; " \
+                     "echo Performing normal boot for now...; " \

include/environment/ti/boot.h line 143

Quoted 10 lines
include/environment/ti/boot.h +10 -0
+                     "run emmc_android_normal_boot; " \
+             "else " \
+                     "echo BCB: Normal boot requested...; " \
+                     "run emmc_android_normal_boot; " \
+             "fi; " \
+     "else " \
+             "echo Warning: BCB is corrupted or does not exist; " \
+             "echo Performing normal boot...; " \
+             "run emmc_android_normal_boot; " \
+     "fi;\0" \

As a general comment, yes, arguments can be brought that this scripted handling is getting hairy and could be replaced by a command like boot{a,_android} (you name it).

In my opinion, the main downside of "boot{a,_android}" wrapper is that it implies sprinkling U-Boot with special-purpose variables like ${fastbootcmd} [1], ${recoverycmd}, ${my_usecase_cmd}, etc (the number of those would likely match the number of if/else branches in this patch). Decentralized usage of those variables (i.e. set at point A and read/used at point B) would IMHO:
- complicate the boot flow and its understanding, hence would
- require to write and maintain additional documentation
- open doors for creative issues

Quoted 8 lines

I contrast to the above, the approach taken in this patch:
- avoids any special-purpose global variables
- avoids spawning yet another boot{*} command
- centralizes/limits the boot flow handling to one file
- doesn't require much documentation (the code is self-explanatory)
- in case of bugs, would require coming back to the same place
- makes debugging easier

Let's finalize modern Android boot flow via scripting (as we need all those commands anyway), then we can think if we need to wrap the whole thing into boot_android command. There is a lot of stuff happening during the Android boot, not only reboot reason check, e.g.
- AVB
- A/B slotting
- partitions reading
- preparing the cmdline

So once we implement Android-Q requirements for Android boot flow, we can experiment with separate command. But let's postpone that at least for next merge window. Then we can decide together which way is better.

Quoted 28 lines
Quoted 5 lines
include/environment/ti/boot.h +1 -0
+     "emmc_android_normal_boot=" \
              "echo Trying to boot Android from eMMC ...; " \
              "run update_to_fit; " \
              "setenv eval_bootargs setenv bootargs $bootargs; " \

include/environment/ti/boot.h line 207

Quoted 9 lines
include/environment/ti/boot.h +1 -2
@@ -176,8 +201,7 @@
      "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) "; " \
+             FASTBOOT_CMD \
      "fi;" \
      "if test ${boot_fit} -eq 1; then "      \
              "run update_to_fit;"    \

That said, I still admit that my statements could be highly subjective and that the best of our collective experience (as users, developers and maintainers) would be achieved in a different way than described.

Below is based on code review only (can't test due to lack of HW):

[1] https://android.googlesource.com/platform/external/u-boot/+/7d8d87584d7c/cmd/boot_android.c#67

--
Best Regards,
Eugeniu.

#3 lore raw

PATCH 1/1 env: ti: boot: Handle reboot reason from BCB

Hi Sam,

Quoted 9 lines · Sam Protsenko

Let's finalize modern Android boot flow via scripting (as we need all those commands anyway), then we can think if we need to wrap the whole thing into boot_android command. There is a lot of stuff happening during the Android boot, not only reboot reason check, e.g.
- AVB
- A/B slotting
- partitions reading
- preparing the cmdline

Quoted 4 lines

So once we implement Android-Q requirements for Android boot flow, we can experiment with separate command. But let's postpone that at least for next merge window. Then we can decide together which way is better.

Sounds good. Agreed.

Signature · 2 lines
Best Regards,
Eugeniu.
#4 lore raw

PATCH 1/1 env: ti: boot: Handle reboot reason from BCB

In reply to Sam Protsenko

Superseded by v2.

Quoted 75 lines · Sam Protsenko

In case of Android boot, reboot reason can be written into BCB (usually it's an area in 'misc' partition). U-Boot then can obtain that reboot reason from BCB and handle it accordingly to achieve correct Android boot flow, like it was suggested in [1]:
- if it's empty: perform normal Android boot from eMMC
- if it contains "bootonce-bootloader": get into fastboot mode
- if it contains "boot-recovery": perform recovery boot

The latter is not implemented yet, as it depends on some features that are not implemented on TI platforms yet (in AOSP and in U-Boot).

[1] https://marc.info/?l=u-boot&m=152508418909737&w=2

---
 include/environment/ti/boot.h | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
include/environment/ti/boot.h +26 -3
index 54e9b2de4d..e37004af46 100644
@@ -98,6 +98,10 @@
 #define AB_SELECT ""
 #endif
 
+#define FASTBOOT_CMD \
+       "echo Booting into fastboot ...; " \
+       "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; "
+
 #define DEFAULT_COMMON_BOOT_TI_ARGS \
        "console=" CONSOLEDEV ",115200n8\0" \
        "fdtfile=undefined\0" \
@@ -117,6 +121,27 @@
                "setenv mmcroot /dev/mmcblk0p2 rw; " \
                "run mmcboot;\0" \
        "emmc_android_boot=" \
+       "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " misc; " \
+       "then " \
+               "if bcb test command = bootonce-bootloader; then " \
+                       "echo BCB: Bootloader boot...; " \
+                       "bcb clear command; bcb store; " \
+                       FASTBOOT_CMD \
+               "elif bcb test command = boot-recovery; then " \
+                       "echo BCB: Recovery boot...; " \
+                       "echo Warning: recovery boot is not implemented; " \
+                       "echo Performing normal boot for now...; " \
+                       "run emmc_android_normal_boot; " \
+               "else " \
+                       "echo BCB: Normal boot requested...; " \
+                       "run emmc_android_normal_boot; " \
+               "fi; " \
+       "else " \
+               "echo Warning: BCB is corrupted or does not exist; " \
+               "echo Performing normal boot...; " \
+               "run emmc_android_normal_boot; " \
+       "fi;\0" \
+       "emmc_android_normal_boot=" \
                "echo Trying to boot Android from eMMC ...; " \
                "run update_to_fit; " \
                "setenv eval_bootargs setenv bootargs $bootargs; " \
@@ -176,8 +201,7 @@
        "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) "; " \
+               FASTBOOT_CMD \
        "fi;" \
        "if test ${boot_fit} -eq 1; then "      \
                "run update_to_fit;"    \
--

2.20.1