android_ab: introduce bcb ab_dump command and provide several bcb fixes
v5 cover android_ab: introduce bcb ab_dump command and provide several bcb fixes
The patch series include changes:
- move ab_select_slot() documentation to @ notation
- redesign 'bcb' command to U_BOOT_LONGHELP approach
- move ab_select command to bcb subcommands
- introduce the ab_dump command to print the content of the BCB block; it's useful for debugging A/B logic on supported boards
- fix the slot suffix format in the ABC block to align with official Android BCB specifications
- add a test for the ab_dump command to verify the accuracy of each field within the ABC data displayed, it's also useful for testing slot_suffix problem code paths
---
Changes in v5:
- rework direct #ifdefs to IS_ENABLED() macro
- redesign 'bcb' command to U_BOOT_LONGHELP approach
- check argc directly in the ab_select and ab_dump subcommands handlers
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- add #ifdefs for CONFIG_ANDROID_AB in cmd/bcb.c to allow the usage of
the bcb command without A/B enabled
- run the savedefconfig command for all defconfigs that include the
CMD_BCB configuration
- resolve merge conflicts with latest master
- provide additional trailers from the previous version (excluding
changed patches)
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- return "Legend" block for bcb command
- additionally, verify the CONFIG_ANDROID_AB configuration alongside CONFIG_CMD_BCB to ensure that the A/B scheme is used for the
designated board.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- move ab_select_slot() documentation to @ notation
- move ab_select command to bcb subcommands per Simon and Mattijs
suggestions
- redesign ab_dump as bcb subcommand
- use spaces instead of tabs in the ab_dump command output
- print hex values in the lowercase
- add RvB tags
- Link to v1: https://lore.kernel.org/all/[email protected]/
---
Dmitry Rokosov (6):
include/android_ab: move ab_select_slot() documentation to @ notation
cmd: bcb: rework the command to U_BOOT_LONGHELP approach
treewide: bcb: move ab_select command to bcb subcommands
cmd: bcb: change strcmp() usage style in the do_bcb_ab_select()
cmd: bcb: introduce 'ab_dump' command to print BCB block content
common: android_ab: fix slot suffix for abc block
MAINTAINERS | 1 - boot/android_ab.c | 116 +++++++++++++--- cmd/Kconfig | 14 -- cmd/Makefile | 1 - cmd/ab_select.c | 66 --------- cmd/bcb.c | 221 +++++++++++++++++------------- configs/am57xx_evm_defconfig | 1 - configs/am57xx_hs_evm_defconfig | 1 - configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 1 - doc/android/ab.rst | 12 +- include/android_ab.h | 17 ++- include/configs/khadas-vim3_android.h | 2 +- include/configs/khadas-vim3l_android.h | 2 +- include/configs/meson64_android.h | 4 +- include/configs/ti_omap5_common.h | 4 +- test/py/tests/test_android/test_ab.py | 31 ++++- 20 files changed, 275 insertions(+), 224 deletions(-)
---
base-commit: 98a36deb9ab7aaea70b0b0db47718100e08cf3e8
change-id: 20241008-android_ab_master-d86d71c839ae
Best regards,
Signature · 1 line
Dmitry Rokosov <[email protected]>
PATCH v5 1/6 include/android_ab: move ab_select_slot() documentation to @ notation
There are new function documentation requirements in U-Boot, so apply these changes for android_ab.
--- boot/android_ab.c | 43 ++++++++++++++++++++++++------------------- include/android_ab.h | 7 ++++--- 2 files changed, 28 insertions(+), 22 deletions(-)
boot/android_ab.c +24 -19
@@ -13,13 +13,13 @@#include <u-boot/crc.h> /** -* Compute the CRC-32 of the bootloader control struct. +* ab_control_compute_crc() - Compute the CRC32 of the bootloader control. +* +* @abc: Bootloader control block * * Only the bytes up to the crc32_le field are considered for the CRC-32 * calculation. * -* @param[in] abc bootloader control block -* * Return: crc32 sum */ static uint32_t ab_control_compute_crc (struct bootloader_control *abc)
@@ -28,14 +28,14 @@ static uint32_t ab_control_compute_crc(struct bootloader_control *abc) }/** -* Initialize bootloader_control to the default value. +* ab_control_default() - Initialize bootloader_control to the default value. +* +* @abc: Bootloader control block * * It allows us to boot all slots in order from the first one. This value * should be used when the bootloader message is corrupted, but not when * a valid message indicates that all slots are unbootable. * -* @param[in] abc bootloader control block -* * Return: 0 on success and a negative on error */ static int ab_control_default (struct bootloader_control *abc)
@@ -67,7 +67,13 @@ static int ab_control_default(struct bootloader_control *abc) }/** -* Load the boot_control struct from disk into newly allocated memory. +* ab_control_create_from_disk() - Load the boot_control from disk into memory. +* +* @dev_desc: Device where to read the boot_control struct from +* @part_info: Partition in 'dev_desc' where to read from, normally +* the "misc" partition should be used +* @abc: pointer to pointer to bootloader_control data +* @offset: boot_control struct offset * * This function allocates and returns an integer number of disk blocks, * based on the block size of the passed device to help performing a
@@ -75,10 +81,6 @@ static int ab_control_default(struct bootloader_control *abc)* The boot_control struct offset (2 KiB) must be a multiple of the device * block size, for simplicity. * -* @param[in] dev_desc Device where to read the boot_control struct from -* @param[in] part_info Partition in 'dev_desc' where to read from, normally -* the "misc" partition should be used -* @param[out] pointer to pointer to bootloader_control data * Return: 0 on success and a negative on error */ static int ab_control_create_from_disk(struct blk_desc *dev_desc,
@@ -122,15 +124,17 @@ static int ab_control_create_from_disk(struct blk_desc *dev_desc, }/** -* Store the loaded boot_control block. +* ab_control_store() - Store the loaded boot_control block. +* +* @dev_desc: Device where we should write the boot_control struct +* @part_info: Partition on the 'dev_desc' where to write +* @abc Pointer to the boot control struct and the extra bytes after +* it up to the nearest block boundary +* @offset: boot_control struct offset * * Store back to the same location it was read from with * ab_control_create_from_misc(). * -* @param[in] dev_desc Device where we should write the boot_control struct -* @param[in] part_info Partition on the 'dev_desc' where to write -* @param[in] abc Pointer to the boot control struct and the extra bytes after -* it up to the nearest block boundary * Return: 0 on success and a negative on error */ static int ab_control_store(struct blk_desc *dev_desc,
@@ -160,12 +164,13 @@ static int ab_control_store(struct blk_desc *dev_desc, }/** -* Compare two slots. +* ab_compare_slots() - Compare two slots. +* +* @a: The first bootable slot metadata +* @b: The second bootable slot metadata * * The function determines slot which is should we boot from among the two. * -* @param[in] a The first bootable slot metadata -* @param[in] b The second bootable slot metadata * Return: Negative if the slot "a" is better, positive of the slot "b" is * better or 0 if they are equally good. */
include/android_ab.h +4 -3
@@ -18,7 +18,10 @@ struct disk_partition;#define NUM_SLOTS 2/** -* Select the slot where to boot from. +* ab_select_slot() - Select the slot where to boot from. +* +* @dev_desc: Place to store the device description pointer +* @part_info: Place to store the partition information * * On Android devices with more than one boot slot (multiple copies of the * kernel and system images) selects which slot should be used to boot from and
@@ -28,8 +31,6 @@ struct disk_partition;* registered before returning from this function so it isn't selected * indefinitely. * -* @param[in] dev_desc Place to store the device description pointer -* @param[in] part_info Place to store the partition information * Return: The slot number (>= 0) on success, or a negative on error */ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
Signature · 1 line
2.43.0
PATCH v5 2/6 cmd: bcb: rework the command to U_BOOT_LONGHELP approach
In reply to Dmitry RokosovU_BOOT_LONGHELP and U_BOOT_CMD_WITH_SUBCMDS offer numerous advantages, including:
- common argument restrictions checking
- automatic subcommand matching
- improved usage and help handling
By utilizing the U_BOOT_LONGHELP approach, we can reduce the amount of command management code and describe commands more succinctly.
--- cmd/bcb.c | 151 ++++++++++++++++++-------------------------------------------- 1 file changed, 43 insertions(+), 108 deletions(-)
cmd/bcb.c +43 -108
@@ -16,15 +16,6 @@#include <vsprintf.h> #include <linux/err.h> -enum bcb_cmd { -BCB_CMD_LOAD , -BCB_CMD_FIELD_SET , -BCB_CMD_FIELD_CLEAR , -BCB_CMD_FIELD_TEST , -BCB_CMD_FIELD_DUMP , -BCB_CMD_STORE , -}; -static const char *const fields[] = {"command" ,"status" ,
@@ -38,67 +29,9 @@ static struct disk_partition partition_data;static struct blk_desc *block;static struct disk_partition *partition = &partition_data; -static int bcb_cmd_get (char *cmd) -{ -if (!strcmp (cmd,"load" )) -return BCB_CMD_LOAD ; -if (!strcmp (cmd,"set" )) -return BCB_CMD_FIELD_SET ; -if (!strcmp (cmd,"clear" )) -return BCB_CMD_FIELD_CLEAR ; -if (!strcmp (cmd,"test" )) -return BCB_CMD_FIELD_TEST ; -if (!strcmp (cmd,"store" )) -return BCB_CMD_STORE ; -if (!strcmp (cmd,"dump" )) -return BCB_CMD_FIELD_DUMP ; -else -return -1 ; -} - -static int bcb_is_misused (int argc,char *const argv[]) +static int bcb_not_loaded (void ) { -int cmd =bcb_cmd_get (argv[0 ]); - -switch (cmd) { -case BCB_CMD_LOAD : -if (argc !=3 && argc !=4 ) - goto err; -break ; -case BCB_CMD_FIELD_SET : -if (argc !=3 ) - goto err; -break ; -case BCB_CMD_FIELD_TEST : -if (argc !=4 ) - goto err; -break ; -case BCB_CMD_FIELD_CLEAR : -if (argc !=1 && argc !=2 ) - goto err; -break ; -case BCB_CMD_STORE : -if (argc !=1 ) - goto err; -break ; -case BCB_CMD_FIELD_DUMP : -if (argc !=2 ) - goto err; -break ; -default : -printf ("Error: 'bcb %s' not supported\n" , argv[0 ]); -return -1 ; - } - -if (cmd !=BCB_CMD_LOAD && !block) { -printf ("Error: Please, load BCB first!\n" ); -return -1 ; - } - -return 0 ; -err: -printf ("Error: Bad usage of 'bcb %s'\n" , argv[0 ]); - +printf ("Error: Please, load BCB first!\n" );return -1 ; }
@@ -216,6 +149,9 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,char *endp;char *iface ="mmc" ; +if (argc <3 ) +return CMD_RET_USAGE ; +if (argc ==4 ) { iface = argv[1 ]; argc--;
@@ -270,6 +206,12 @@ static int __bcb_set(const char *fieldp, const char *valp)static int do_bcb_set (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { +if (argc <3 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); +return __bcb_set (argv[1 ], argv[2 ]); }
@@ -279,6 +221,9 @@ static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc,int size;char *field; +if (!block) +return bcb_not_loaded (); +if (argc ==1 ) {memset (&bcb,0 ,sizeof (bcb));return CMD_RET_SUCCESS ;
@@ -297,7 +242,15 @@ static int do_bcb_test(struct cmd_tbl *cmdtp, int flag, int argc, {int size;char *field; -char *op = argv[2 ]; +char *op; + +if (argc <4 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); + + op = argv[2 ];if (bcb_field_get (argv[1 ], &field, &size))return CMD_RET_FAILURE ;
@@ -325,6 +278,12 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,int size;char *field; +if (argc <2 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); +if (bcb_field_get (argv[1 ], &field, &size))return CMD_RET_FAILURE ;
@@ -356,6 +315,9 @@ err:static int do_bcb_store (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { +if (!block) +return bcb_not_loaded (); +return __bcb_store (); }
@@ -414,44 +376,7 @@ void bcb_reset(void)__bcb_reset (); } -static struct cmd_tbl cmd_bcb_sub[] = { -U_BOOT_CMD_MKENT (load,CONFIG_SYS_MAXARGS ,1 , do_bcb_load,"" ,"" ), -U_BOOT_CMD_MKENT (set,CONFIG_SYS_MAXARGS ,1 , do_bcb_set,"" ,"" ), -U_BOOT_CMD_MKENT (clear,CONFIG_SYS_MAXARGS ,1 , do_bcb_clear,"" ,"" ), -U_BOOT_CMD_MKENT (test,CONFIG_SYS_MAXARGS ,1 , do_bcb_test,"" ,"" ), -U_BOOT_CMD_MKENT (dump,CONFIG_SYS_MAXARGS ,1 , do_bcb_dump,"" ,"" ), -U_BOOT_CMD_MKENT (store,CONFIG_SYS_MAXARGS ,1 , do_bcb_store,"" ,"" ), -}; - -static int do_bcb (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) -{ -struct cmd_tbl *c; - -if (argc <2 ) -return CMD_RET_USAGE ; - - argc--; - argv++; - - c =find_cmd_tbl (argv[0 ], cmd_bcb_sub,ARRAY_SIZE (cmd_bcb_sub)); -if (!c) -return CMD_RET_USAGE ; - -if (bcb_is_misused (argc, argv)) { -/* -* We try to improve the user experience by reporting the -* root-cause of misusage, so don't return CMD_RET_USAGE, -* since the latter prints out the full-blown help text -*/ -return CMD_RET_FAILURE ; - } - -return c->cmd (cmdtp, flag, argc, argv); -} - -U_BOOT_CMD ( - bcb,CONFIG_SYS_MAXARGS ,1 , do_bcb, -"Load/set/clear/test/dump/store Android BCB fields" , +U_BOOT_LONGHELP (bcb,"load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n" "load <dev> <part> - load BCB from mmc <dev>:<part>\n" "bcb set <field> <val> - set BCB <field> to <val>\n"
@@ -472,3 +397,13 @@ U_BOOT_CMD(" NOTE: any ':' character in <val> will be replaced by line feed\n" " during 'bcb set' and used as separator by upper layers\n" ); + +U_BOOT_CMD_WITH_SUBCMDS (bcb, +"Load/set/clear/test/dump/store Android BCB fields" , bcb_help_text, +U_BOOT_SUBCMD_MKENT (load,4 ,1 , do_bcb_load), +U_BOOT_SUBCMD_MKENT (set,3 ,1 , do_bcb_set), +U_BOOT_SUBCMD_MKENT (clear,2 ,1 , do_bcb_clear), +U_BOOT_SUBCMD_MKENT (test,4 ,1 , do_bcb_test), +U_BOOT_SUBCMD_MKENT (dump,2 ,1 , do_bcb_dump), + U_BOOT_SUBCMD_MKENT(store, 1, 1, do_bcb_store), +);
Signature · 1 line
2.43.0
Re: [PATCH v5 2/6] cmd: bcb: rework the command to U_BOOT_LONGHELP approach
Hi Dmitry,
Thank you for the patch.
Quoted 6 lines · Dmitry Rokosov
U_BOOT_LONGHELPandU_BOOT_CMD_WITH_SUBCMDSoffer numerous advantages, including:
- common argument restrictions checking
- automatic subcommand matching
- improved usage and help handling
Quoted 7 lines
By utilizing the
U_BOOT_LONGHELPapproach, we can reduce the amount of command management code and describe commands more succinctly.Signed-off-by Dmitry Rokosov <[email protected]>--- cmd/bcb.c | 151 ++++++++++++++++++-------------------------------------------- 1 file changed, 43 insertions(+), 108 deletions(-)
Nice diffstat, always great to see code removed!
Quoted 227 lines
cmd/bcb.c +43
-108@@ -16,15 +16,6 @@#include <vsprintf.h> #include <linux/err.h> -enum bcb_cmd { -BCB_CMD_LOAD , -BCB_CMD_FIELD_SET , -BCB_CMD_FIELD_CLEAR , -BCB_CMD_FIELD_TEST , -BCB_CMD_FIELD_DUMP , -BCB_CMD_STORE , -}; -static const char *const fields[] = {"command" ,"status" ,@@ -38,67 +29,9 @@ static struct disk_partition partition_data;static struct blk_desc *block;static struct disk_partition *partition = &partition_data; -static int bcb_cmd_get (char *cmd) -{ -if (!strcmp (cmd,"load" )) -return BCB_CMD_LOAD ; -if (!strcmp (cmd,"set" )) -return BCB_CMD_FIELD_SET ; -if (!strcmp (cmd,"clear" )) -return BCB_CMD_FIELD_CLEAR ; -if (!strcmp (cmd,"test" )) -return BCB_CMD_FIELD_TEST ; -if (!strcmp (cmd,"store" )) -return BCB_CMD_STORE ; -if (!strcmp (cmd,"dump" )) -return BCB_CMD_FIELD_DUMP ; -else -return -1 ; -} - -static int bcb_is_misused (int argc,char *const argv[]) +static int bcb_not_loaded (void ) { -int cmd =bcb_cmd_get (argv[0 ]); - -switch (cmd) { -case BCB_CMD_LOAD : -if (argc !=3 && argc !=4 ) - goto err; -break ; -case BCB_CMD_FIELD_SET : -if (argc !=3 ) - goto err; -break ; -case BCB_CMD_FIELD_TEST : -if (argc !=4 ) - goto err; -break ; -case BCB_CMD_FIELD_CLEAR : -if (argc !=1 && argc !=2 ) - goto err; -break ; -case BCB_CMD_STORE : -if (argc !=1 ) - goto err; -break ; -case BCB_CMD_FIELD_DUMP : -if (argc !=2 ) - goto err; -break ; -default : -printf ("Error: 'bcb %s' not supported\n" , argv[0 ]); -return -1 ; - } - -if (cmd !=BCB_CMD_LOAD && !block) { -printf ("Error: Please, load BCB first!\n" ); -return -1 ; - } - -return 0 ; -err: -printf ("Error: Bad usage of 'bcb %s'\n" , argv[0 ]); - +printf ("Error: Please, load BCB first!\n" );return -1 ; }@@ -216,6 +149,9 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,char *endp;char *iface ="mmc" ; +if (argc <3 ) +return CMD_RET_USAGE ; +if (argc ==4 ) { iface = argv[1 ]; argc--;@@ -270,6 +206,12 @@ static int __bcb_set(const char *fieldp, const char *valp)static int do_bcb_set (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { +if (argc <3 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); +return __bcb_set (argv[1 ], argv[2 ]); }@@ -279,6 +221,9 @@ static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc,int size;char *field; +if (!block) +return bcb_not_loaded (); +if (argc ==1 ) {memset (&bcb,0 ,sizeof (bcb));return CMD_RET_SUCCESS ;@@ -297,7 +242,15 @@ static int do_bcb_test(struct cmd_tbl *cmdtp, int flag, int argc, {int size;char *field; -char *op = argv[2 ]; +char *op; + +if (argc <4 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); + + op = argv[2 ];if (bcb_field_get (argv[1 ], &field, &size))return CMD_RET_FAILURE ;@@ -325,6 +278,12 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,int size;char *field; +if (argc <2 ) +return CMD_RET_USAGE ; + +if (!block) +return bcb_not_loaded (); +if (bcb_field_get (argv[1 ], &field, &size))return CMD_RET_FAILURE ;@@ -356,6 +315,9 @@ err:static int do_bcb_store (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { +if (!block) +return bcb_not_loaded (); +return __bcb_store (); }@@ -414,44 +376,7 @@ void bcb_reset(void)__bcb_reset (); } -static struct cmd_tbl cmd_bcb_sub[] = { -U_BOOT_CMD_MKENT (load,CONFIG_SYS_MAXARGS ,1 , do_bcb_load,"" ,"" ), -U_BOOT_CMD_MKENT (set,CONFIG_SYS_MAXARGS ,1 , do_bcb_set,"" ,"" ), -U_BOOT_CMD_MKENT (clear,CONFIG_SYS_MAXARGS ,1 , do_bcb_clear,"" ,"" ), -U_BOOT_CMD_MKENT (test,CONFIG_SYS_MAXARGS ,1 , do_bcb_test,"" ,"" ), -U_BOOT_CMD_MKENT (dump,CONFIG_SYS_MAXARGS ,1 , do_bcb_dump,"" ,"" ), -U_BOOT_CMD_MKENT (store,CONFIG_SYS_MAXARGS ,1 , do_bcb_store,"" ,"" ), -}; - -static int do_bcb (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) -{ -struct cmd_tbl *c; - -if (argc <2 ) -return CMD_RET_USAGE ; - - argc--; - argv++; - - c =find_cmd_tbl (argv[0 ], cmd_bcb_sub,ARRAY_SIZE (cmd_bcb_sub)); -if (!c) -return CMD_RET_USAGE ; - -if (bcb_is_misused (argc, argv)) { -/* -* We try to improve the user experience by reporting the -* root-cause of misusage, so don't return CMD_RET_USAGE, -* since the latter prints out the full-blown help text -*/ -return CMD_RET_FAILURE ; - } - -return c->cmd (cmdtp, flag, argc, argv); -} - -U_BOOT_CMD ( - bcb,CONFIG_SYS_MAXARGS ,1 , do_bcb, -"Load/set/clear/test/dump/store Android BCB fields" , +U_BOOT_LONGHELP (bcb,"load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n" "load <dev> <part> - load BCB from mmc <dev>:<part>\n" "bcb set <field> <val> - set BCB <field> to <val>\n"@@ -472,3 +397,13 @@ U_BOOT_CMD(" NOTE: any ':' character in <val> will be replaced by line feed\n" " during 'bcb set' and used as separator by upper layers\n" ); + +U_BOOT_CMD_WITH_SUBCMDS (bcb, +"Load/set/clear/test/dump/store Android BCB fields" , bcb_help_text, +U_BOOT_SUBCMD_MKENT (load,4 ,1 , do_bcb_load), +U_BOOT_SUBCMD_MKENT (set,3 ,1 , do_bcb_set), +U_BOOT_SUBCMD_MKENT (clear,2 ,1 , do_bcb_clear), +U_BOOT_SUBCMD_MKENT (test,4 ,1 , do_bcb_test), +U_BOOT_SUBCMD_MKENT (dump,2 ,1 , do_bcb_dump), + U_BOOT_SUBCMD_MKENT(store, 1, 1, do_bcb_store), +);Signature · 2 lines
-- 2.43.0
PATCH v5 3/6 treewide: bcb: move ab_select command to bcb subcommands
In reply to Dmitry RokosovTo enhance code organization, it is beneficial to consolidate all A/B BCB management routines into a single super-command.
The 'bcb' command is an excellent candidate for this purpose.
This patch integrates the separate 'ab_select' command into the 'bcb' group as the 'ab_select' subcommand, maintaining the same parameter list for consistency.
--- MAINTAINERS | 1 - cmd/Kconfig | 14 ------- cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_evm_defconfig | 1 - configs/am57xx_hs_evm_defconfig | 1 - configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 1 - doc/android/ab.rst | 12 +++--- include/configs/khadas-vim3_android.h | 2 +- include/configs/khadas-vim3l_android.h | 2 +- include/configs/meson64_android.h | 4 +- include/configs/ti_omap5_common.h | 4 +- test/py/tests/test_android/test_ab.py | 8 ++-- 18 files changed, 81 insertions(+), 104 deletions(-)
MAINTAINERS +0 -1
@@ -65,7 +65,6 @@ R: Sam Protsenko <[email protected]> S: Maintained T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git F: boot/android_ab.c -F: cmd/ab_select.c F: doc/android/ab.rst F: include/android_ab.h F: test/py/tests/test_android/test_ab.py
cmd/Kconfig +0 -14
@@ -1775,20 +1775,6 @@ config CMD_XXD endmenu -menu "Android support commands" - -config CMD_AB_SELECT - bool "ab_select" - depends on ANDROID_AB - help - On Android devices with more than one boot slot (multiple copies of - the kernel and system images) this provides a command to select which - slot should be used to boot from and register the boot attempt. This - is used by the new A/B update model where one slot is updated in the - background while running from the other slot. - -endmenu - if NET || NET_LWIP menuconfig CMD_NET
cmd/Makefile +0 -1
@@ -17,7 +17,6 @@ obj-$(CONFIG_CMD_2048) += 2048.o obj-$(CONFIG_CMD_ACPI) += acpi.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_AES) += aes.o -obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o obj-$(CONFIG_CMD_ARMFLASH) += armflash.o obj-$(CONFIG_BLK) += blk_common.o
cmd/ab_select.c deleted +0 -66
66 lines not on this page · raw message
cmd/bcb.c +63 -0
85 lines not on this page · raw message
configs/am57xx_evm_defconfig +0 -1
@@ -48,7 +48,6 @@ CONFIG_CMD_SPL=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=y
configs/am57xx_hs_evm_defconfig +0 -1
@@ -44,7 +44,6 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=y
configs/am57xx_hs_evm_usb_defconfig +0 -1
@@ -46,7 +46,6 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=y
configs/khadas-vim3_android_ab_defconfig +0 -1
@@ -47,7 +47,6 @@ CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=y
configs/khadas-vim3l_android_ab_defconfig +0 -1
@@ -47,7 +47,6 @@ CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=y
configs/sandbox64_defconfig +2 -0
@@ -27,6 +27,7 @@ CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000 CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y
@@ -46,6 +47,7 @@ CONFIG_CMD_MD5SUM=y CONFIG_CMD_MEMINFO=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_BCB=y CONFIG_CMD_CLK=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y
configs/sandbox_defconfig +0 -1
@@ -103,7 +103,6 @@ CONFIG_CMD_AXI=y CONFIG_CMD_CAT=y CONFIG_CMD_SETEXPR_FMT=y CONFIG_CMD_XXD=y -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_DHCP6=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_PCAP=y
doc/android/ab.rst +6 -6
@@ -18,7 +18,7 @@ The A/B updates support can be activated by specifying next options in your board configuration file:: CONFIG_ANDROID_AB=y - CONFIG_CMD_AB_SELECT=y + CONFIG_CMD_BCB=y The disk space on target device must be partitioned in a way so that each partition which needs to be updated has two or more instances. The name of
@@ -26,8 +26,8 @@ each instance must be formed by adding suffixes: ``_a``, ``_b``, ``_c``, etc. For example: ``boot_a``, ``boot_b``, ``system_a``, ``system_b``, ``vendor_a``, ``vendor_b``. -As a result you can use ``ab_select`` command to ensure A/B boot process in your -boot script. This command analyzes and processes A/B metadata stored on a +As a result you can use ``bcb ab_select`` command to ensure A/B boot process in +your boot script. This command analyzes and processes A/B metadata stored on a special partition (e.g. ``misc``) and determines which slot should be used for booting up.
@@ -42,15 +42,15 @@ Command usage .. code-block:: none - ab_select <slot_var_name> <interface> <dev[:part_number|#part_name]> + bcb ab_select <slot_var_name> <interface> <dev[:part_number|#part_name]> for example:: - => ab_select slot_name mmc 1:4 + => bcb ab_select slot_name mmc 1:4 or:: - => ab_select slot_name mmc 1#misc + => bcb ab_select slot_name mmc 1#misc Result::
include/configs/khadas-vim3_android.h +1 -1
@@ -12,7 +12,7 @@#define LOGO_UUID "43a3305d-150f-4cc9-bd3b-38fca8693846;"#define ROOT_UUID "ddb8c3f6-d94d-4394-b633-3134139cc2e0;" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define PARTS_DEFAULT \ "uuid_disk=${uuid_gpt_disk};" \ "name=logo,start=512K,size=2M,uuid=" LOGO_UUID \
include/configs/khadas-vim3l_android.h +1 -1
@@ -12,7 +12,7 @@#define LOGO_UUID "43a3305d-150f-4cc9-bd3b-38fca8693846;"#define ROOT_UUID "ddb8c3f6-d94d-4394-b633-3134139cc2e0;" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define PARTS_DEFAULT \ "uuid_disk=${uuid_gpt_disk};" \ "name=logo,start=512K,size=2M,uuid=" LOGO_UUID \
include/configs/meson64_android.h +2 -2
@@ -47,13 +47,13 @@#define AVB_VERIFY_CMD ""#endif -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define ANDROIDBOOT_GET_CURRENT_SLOT_CMD "get_current_slot=" \ "if part number mmc ${mmcdev} " CONTROL_PARTITION " control_part_number; " \ "then " \ "echo " CONTROL_PARTITION \ " partition number:${control_part_number};" \ - "ab_select current_slot mmc ${mmcdev}:${control_part_number};" \ + "bcb ab_select current_slot mmc ${mmcdev}:${control_part_number};" \ "else " \ "echo " CONTROL_PARTITION " partition not found;" \ "fi;\0"
include/configs/ti_omap5_common.h +2 -2
@@ -93,13 +93,13 @@#define CONTROL_PARTITION "misc" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define AB_SELECT_SLOT \ "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \ "then " \ "echo " CONTROL_PARTITION \ " partition number:${control_part_number};" \ - "ab_select slot_name mmc ${mmcdev}:${control_part_number};" \ + "bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \ "else " \ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \
test/py/tests/test_android/test_ab.py +4 -4
@@ -56,20 +56,20 @@ def ab_disk_image(u_boot_console): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') [email protected]('cmd_ab_select') [email protected]('cmd_bcb') @pytest.mark.requiredtool('sgdisk') def test_ab(ab_disk_image, u_boot_console): - """Test the 'ab_select' command.""" + """Test the 'bcb ab_select' command.""" u_boot_console.run_command('host bind 0 ' + ab_disk_image.path) - output = u_boot_console.run_command('ab_select slot_name host 0#misc') + output = u_boot_console.run_command('bcb ab_select slot_name host 0#misc') assert 're-initializing A/B metadata' in output assert 'Attempting slot a, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=a' in output - output = u_boot_console.run_command('ab_select slot_name host 0:1') + output = u_boot_console.run_command('bcb ab_select slot_name host 0:1') assert 'Attempting slot b, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=b' in output
Signature · 1 line
2.43.0
Re: [PATCH v5 3/6] treewide: bcb: move ab_select command to bcb subcommands
Hi Dmitry,
Thank you for the patch.
Quoted 9 lines · Dmitry Rokosov
To enhance code organization, it is beneficial to consolidate all A/B BCB management routines into a single super-command.
The 'bcb' command is an excellent candidate for this purpose.This patch integrates the separate '
ab_select' command into the 'bcb' group as the 'ab_select' subcommand, maintaining the same parameter list for consistency.Signed-off-by Dmitry Rokosov <[email protected]>
Quoted 468 lines
--- MAINTAINERS | 1 - cmd/Kconfig | 14 ------- cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_evm_defconfig | 1 - configs/am57xx_hs_evm_defconfig | 1 - configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 1 - doc/android/ab.rst | 12 +++--- include/configs/khadas-vim3_android.h | 2 +- include/configs/khadas-vim3l_android.h | 2 +- include/configs/meson64_android.h | 4 +- include/configs/ti_omap5_common.h | 4 +- test/py/tests/test_android/test_ab.py | 8 ++-- 18 files changed, 81 insertions(+), 104 deletions(-)MAINTAINERS +0
-1@@ -65,7 +65,6 @@ R: Sam Protsenko <[email protected]> S: Maintained T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git F: boot/android_ab.c -F: cmd/ab_select.c F: doc/android/ab.rst F: include/android_ab.h F: test/py/tests/test_android/test_ab.pycmd/Kconfig +0
-14@@ -1775,20 +1775,6 @@ config CMD_XXD endmenu -menu "Android support commands" - -config CMD_AB_SELECT - bool "ab_select" - depends on ANDROID_AB - help - On Android devices with more than one boot slot (multiple copies of - the kernel and system images) this provides a command to select which - slot should be used to boot from and register the boot attempt. This - is used by the new A/B update model where one slot is updated in the - background while running from the other slot. - -endmenu - if NET || NET_LWIP menuconfig CMD_NETcmd/Makefile +0
-1@@ -17,7 +17,6 @@ obj-$(CONFIG_CMD_2048) += 2048.o obj-$(CONFIG_CMD_ACPI) += acpi.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_AES) += aes.o -obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o obj-$(CONFIG_CMD_ARMFLASH) += armflash.o obj-$(CONFIG_BLK) += blk_common.ocmd/ab_select.c deleted +0
-66@@ -1,66 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause -/* -* Copyright (C) 2017 The Android Open Source Project -*/ - -#include <android_ab.h> -#include <command.h> -#include <env.h> -#include <part.h> - -static int do_ab_select (struct cmd_tbl *cmdtp,int flag,int argc, -char *const argv[]) -{ -int ret; -struct blk_desc *dev_desc; -struct disk_partition part_info; -char slot[2 ]; -bool dec_tries = true; - -if (argc <4 ) -return CMD_RET_USAGE ; - -for (int i =4 ; i < argc; i++) { -if (strcmp (argv[i],"--no-dec" ) ==0 ) { - dec_tries = false; - }else { -return CMD_RET_USAGE ; - } - } - -/* Lookup the "misc" partition from argv[2] and argv[3] */ -if (part_get_info_by_dev_and_name_or_num (argv[2 ], argv[3 ], - &dev_desc, &part_info, - false) <0 ) { -return CMD_RET_FAILURE ; - } - - ret =ab_select_slot (dev_desc, &part_info, dec_tries); -if (ret <0 ) { -printf ("Android boot failed, error %d.\n" , ret); -return CMD_RET_FAILURE ; - } - -/* Android standard slot names are 'a', 'b', ... */ - slot[0 ] =BOOT_SLOT_NAME (ret); - slot[1 ] ='\0' ; -env_set (argv[1 ], slot); -printf ("ANDROID: Booting slot: %s\n" , slot); -return CMD_RET_SUCCESS ; -} - -U_BOOT_CMD (ab_select,5 ,0 , do_ab_select, -"Select the slot used to boot from and register the boot attempt." , -"<slot_var_name> <interface> <dev[:part|#part_name]> [--no-dec]\n" -" - Load the slot metadata from the partition 'part' on\n" -" device type 'interface' instance 'dev' and store the active\n" -" slot in the 'slot_var_name' variable. This also updates the\n" -" Android slot metadata with a boot attempt, which can cause\n" -" successive calls to this function to return a different result\n" -" if the returned slot runs out of boot attempts.\n" -" - If 'part_name' is passed, preceded with a # instead of :, the\n" -" partition name whose label is 'part_name' will be looked up in\n" -" the partition table. This is commonly the \"misc\" partition.\n" -" - If '--no-dec' is set, the number of tries remaining will not\n" -" decremented for the selected boot slot\n" -);cmd/bcb.c +63
-0@@ -8,6 +8,7 @@#include <android_bootloader_message.h> #include <bcb.h> #include <command.h> +#include <android_ab.h> #include <display_options.h> #include <log.h> #include <part.h> @@ -376,6 +377,48 @@ void bcb_reset(void)__bcb_reset (); } +__maybe_unused static int do_bcb_ab_select (struct cmd_tbl *cmdtp, +int flag,int argc, +char *const argv[]) +{ +int ret; +struct blk_desc *dev_desc; +struct disk_partition part_info; +char slot[2 ]; +bool dec_tries = true; + +if (argc <4 ) +return CMD_RET_USAGE ; + +for (int i =4 ; i < argc; i++) { +if (strcmp (argv[i],"--no-dec" ) ==0 ) + dec_tries = false; +else +return CMD_RET_USAGE ; + } + +/* Lookup the "misc" partition from argv[2] and argv[3] */ +if (part_get_info_by_dev_and_name_or_num (argv[2 ], argv[3 ], + &dev_desc, &part_info, + false) <0 ) { +return CMD_RET_FAILURE ; + } + + ret =ab_select_slot (dev_desc, &part_info, dec_tries); +if (ret <0 ) { +printf ("Android boot failed, error %d.\n" , ret); +return CMD_RET_FAILURE ; + } + +/* Android standard slot names are 'a', 'b', ... */ + slot[0 ] =BOOT_SLOT_NAME (ret); + slot[1 ] ='\0' ; +env_set (argv[1 ], slot); +printf ("ANDROID: Booting slot: %s\n" , slot); + +return CMD_RET_SUCCESS ; +} +U_BOOT_LONGHELP (bcb,"load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n" "load <dev> <part> - load BCB from mmc <dev>:<part>\n"@@ -385,6 +428,23 @@ U_BOOT_LONGHELP(bcb,"bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n" +#if IS_ENABLED (CONFIG_ANDROID_AB ) +"bcb ab_select -\n" +" Select the slot used to boot from and register the boot attempt.\n" +" <slot_var_name> <interface> <dev[:part|#part_name]> [--no-dec]\n" +" - Load the slot metadata from the partition 'part' on\n" +" device type 'interface' instance 'dev' and store the active\n" +" slot in the 'slot_var_name' variable. This also updates the\n" +" Android slot metadata with a boot attempt, which can cause\n" +" successive calls to this function to return a different result\n" +" if the returned slot runs out of boot attempts.\n" +" - If 'part_name' is passed, preceded with a # instead of :, the\n" +" partition name whose label is 'part_name' will be looked up in\n" +" the partition table. This is commonly the \"misc\" partition.\n" +" - If '--no-dec' is set, the number of tries remaining will not\n" +" decremented for the selected boot slot\n" + "\n" +#endif "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n" "<dev> - storage device index containing the BCB partition\n" @@ -406,4 +466,7 @@ U_BOOT_CMD_WITH_SUBCMDS(bcb,U_BOOT_SUBCMD_MKENT (test,4 ,1 , do_bcb_test),U_BOOT_SUBCMD_MKENT (dump,2 ,1 , do_bcb_dump),U_BOOT_SUBCMD_MKENT (store,1 ,1 , do_bcb_store), +#if IS_ENABLED(CONFIG_ANDROID_AB) + U_BOOT_SUBCMD_MKENT(ab_select, 5, 1, do_bcb_ab_select), +#endif );configs/am57xx_evm_defconfig +0
-1@@ -48,7 +48,6 @@ CONFIG_CMD_SPL=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=yconfigs/am57xx_hs_evm_defconfig +0
-1@@ -44,7 +44,6 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=yconfigs/am57xx_hs_evm_usb_defconfig +0
-1@@ -46,7 +46,6 @@ CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 CONFIG_CMD_BCB=y -CONFIG_CMD_AB_SELECT=y CONFIG_BOOTP_DNS2=y # CONFIG_CMD_PMIC is not set CONFIG_CMD_AVB=yconfigs/khadas-vim3_android_ab_defconfig +0
-1@@ -47,7 +47,6 @@ CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=yconfigs/khadas-vim3l_android_ab_defconfig +0
-1@@ -47,7 +47,6 @@ CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_CMD_SETEXPR is not set -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=yconfigs/sandbox64_defconfig +2
-0@@ -27,6 +27,7 @@ CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000 CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y@@ -46,6 +47,7 @@ CONFIG_CMD_MD5SUM=y CONFIG_CMD_MEMINFO=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_BCB=y CONFIG_CMD_CLK=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=yconfigs/sandbox_defconfig +0
-1@@ -103,7 +103,6 @@ CONFIG_CMD_AXI=y CONFIG_CMD_CAT=y CONFIG_CMD_SETEXPR_FMT=y CONFIG_CMD_XXD=y -CONFIG_CMD_AB_SELECT=y CONFIG_CMD_DHCP6=y CONFIG_BOOTP_DNS2=y CONFIG_CMD_PCAP=ydoc/android/ab.rst +6
-6@@ -18,7 +18,7 @@ The A/B updates support can be activated by specifying next options in your board configuration file:: CONFIG_ANDROID_AB=y - CONFIG_CMD_AB_SELECT=y + CONFIG_CMD_BCB=y The disk space on target device must be partitioned in a way so that each partition which needs to be updated has two or more instances. The name of@@ -26,8 +26,8 @@ each instance must be formed by adding suffixes: ``_a``, ``_b``, ``_c``, etc. For example: ``boot_a``, ``boot_b``, ``system_a``, ``system_b``, ``vendor_a``, ``vendor_b``. -As a result you can use ``ab_select`` command to ensure A/B boot process in your -boot script. This command analyzes and processes A/B metadata stored on a +As a result you can use ``bcb ab_select`` command to ensure A/B boot process in +your boot script. This command analyzes and processes A/B metadata stored on a special partition (e.g. ``misc``) and determines which slot should be used for booting up.@@ -42,15 +42,15 @@ Command usage .. code-block:: none - ab_select <slot_var_name> <interface> <dev[:part_number|#part_name]> + bcb ab_select <slot_var_name> <interface> <dev[:part_number|#part_name]> for example:: - => ab_select slot_name mmc 1:4 + => bcb ab_select slot_name mmc 1:4 or:: - => ab_select slot_name mmc 1#misc + => bcb ab_select slot_name mmc 1#misc Result::include/configs/khadas-vim3_android.h +1
-1@@ -12,7 +12,7 @@#define LOGO_UUID "43a3305d-150f-4cc9-bd3b-38fca8693846;"#define ROOT_UUID "ddb8c3f6-d94d-4394-b633-3134139cc2e0;" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define PARTS_DEFAULT \ "uuid_disk=${uuid_gpt_disk};" \ "name=logo,start=512K,size=2M,uuid=" LOGO_UUID \include/configs/khadas-vim3l_android.h +1
-1@@ -12,7 +12,7 @@#define LOGO_UUID "43a3305d-150f-4cc9-bd3b-38fca8693846;"#define ROOT_UUID "ddb8c3f6-d94d-4394-b633-3134139cc2e0;" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define PARTS_DEFAULT \ "uuid_disk=${uuid_gpt_disk};" \ "name=logo,start=512K,size=2M,uuid=" LOGO_UUID \include/configs/meson64_android.h +2
-2@@ -47,13 +47,13 @@#define AVB_VERIFY_CMD ""#endif -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define ANDROIDBOOT_GET_CURRENT_SLOT_CMD "get_current_slot=" \ "if part number mmc ${mmcdev} " CONTROL_PARTITION " control_part_number; " \ "then " \ "echo " CONTROL_PARTITION \ " partition number:${control_part_number};" \ - "ab_select current_slot mmc ${mmcdev}:${control_part_number};" \ + "bcb ab_select current_slot mmc ${mmcdev}:${control_part_number};" \ "else " \ "echo " CONTROL_PARTITION " partition not found;" \ "fi;\0"include/configs/ti_omap5_common.h +2
-2@@ -93,13 +93,13 @@#define CONTROL_PARTITION "misc" -#if defined(CONFIG_CMD_AB_SELECT ) +#if defined(CONFIG_CMD_BCB ) && defined(CONFIG_ANDROID_AB )#define AB_SELECT_SLOT \ "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \ "then " \ "echo " CONTROL_PARTITION \ " partition number:${control_part_number};" \ - "ab_select slot_name mmc ${mmcdev}:${control_part_number};" \ + "bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \ "else " \ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \test/py/tests/test_android/test_ab.py +4
-4@@ -56,20 +56,20 @@ def ab_disk_image(u_boot_console): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') [email protected]('cmd_ab_select') [email protected]('cmd_bcb') @pytest.mark.requiredtool('sgdisk') def test_ab(ab_disk_image, u_boot_console): - """Test the 'ab_select' command.""" + """Test the 'bcb ab_select' command.""" u_boot_console.run_command('host bind 0 ' + ab_disk_image.path) - output = u_boot_console.run_command('ab_select slot_name host 0#misc') + output = u_boot_console.run_command('bcb ab_select slot_name host 0#misc') assert 're-initializing A/B metadata' in output assert 'Attempting slot a, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=a' in output - output = u_boot_console.run_command('ab_select slot_name host 0:1') + output = u_boot_console.run_command('bcb ab_select slot_name host 0:1') assert 'Attempting slot b, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=b' in outputSignature · 2 lines
-- 2.43.0
PATCH v5 4/6 cmd: bcb: change strcmp() usage style in the do_bcb_ab_select()
In reply to Dmitry RokosovIn the entire cmd/bcb.c file, the return value of strcmp() is not directly compared to 0. Therefore, it would be better to maintain this style in the new do_bcb_ab_select() function as well.
--- cmd/bcb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/bcb.c +1 -1
@@ -391,7 +391,7 @@ __maybe_unused static int do_bcb_ab_select(struct cmd_tbl *cmdtp,return CMD_RET_USAGE ;for (int i =4 ; i < argc; i++) { -if (strcmp (argv[i],"--no-dec" ) ==0 ) +if (!strcmp (argv[i],"--no-dec" )) dec_tries = false;else return CMD_RET_USAGE ;
Signature · 1 line
2.43.0
PATCH v5 5/6 cmd: bcb: introduce 'ab_dump' command to print BCB block content
In reply to Dmitry RokosovIt's really helpful to have the ability to dump BCB block for debugging A/B logic on the board supported this partition schema.
Command 'bcb ab_dump' prints all fields of bootloader_control struct including slot_metadata for all presented slots.
Output example:
=====
Quoted 15 lines
board# bcb
ab_dumpubi 0#misc
Read 512 bytes from volume misc to000000000bf07580Read 512 bytes from volume misc to000000000bf42f40Bootloader Control: [misc] Active Slot: _a Magic Number: 0x42414342 Version: 1 Number of Slots: 2 Recovery Tries Remaining: 0 CRC: 0x2c8b50bc (Valid)Slot[0] Metadata:
- Priority: 15 - Tries Remaining: 0 - Successful Boot: 1
Quoted 7 lines
- Verity Corrupted: 0
Slot[1] Metadata:
- Priority: 14 - Tries Remaining: 7 - Successful Boot: 0- Verity Corrupted: 0
====
The ab_dump command allows you to display ABC data directly on the U-Boot console. During an A/B test execution, this test verifies the accuracy of each field within the ABC data.
--- boot/android_ab.c | 68 +++++++++++++++++++++++++++++++++++ cmd/bcb.c | 31 ++++++++++++++++ include/android_ab.h | 10 ++++++ test/py/tests/test_android/test_ab.py | 23 ++++++++++++ 4 files changed, 132 insertions(+)
boot/android_ab.c +68 -0
@@ -372,3 +372,71 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,return slot; } + +int ab_dump_abc (struct blk_desc *dev_desc,struct disk_partition *part_info) +{ +struct bootloader_control *abc; +u32 crc32_le; +int i, ret; +struct slot_metadata *slot; + +if (!dev_desc || !part_info) { +log_err ("ANDROID: Empty device descriptor or partition info\n" ); +return -EINVAL ; + } + + ret =ab_control_create_from_disk (dev_desc, part_info, &abc,0 ); +if (ret <0 ) { +log_err ("ANDROID: Cannot create bcb from disk %d\n" , ret); +return ret; + } + +if (abc->magic !=BOOT_CTRL_MAGIC ) { +log_err ("ANDROID: Unknown A/B metadata: %.8x\n" , abc->magic); + ret = -ENODATA ; + goto error; + } + +if (abc->version >BOOT_CTRL_VERSION ) { +log_err ("ANDROID: Unsupported A/B metadata version: %.8x\n" , + abc->version); + ret = -ENODATA ; + goto error; + } + +if (abc->nb_slot >ARRAY_SIZE (abc->slot_info)) { +log_err ("ANDROID: Wrong number of slots %u, expected %zu\n" , + abc->nb_slot,ARRAY_SIZE (abc->slot_info)); + ret = -ENODATA ; + goto error; + } + +printf ("Bootloader Control: [%s]\n" , part_info->name); +printf ("Active Slot: %s\n" , abc->slot_suffix); +printf ("Magic Number: 0x%x\n" , abc->magic); +printf ("Version: %u\n" , abc->version); +printf ("Number of Slots: %u\n" , abc->nb_slot); +printf ("Recovery Tries Remaining: %u\n" , abc->recovery_tries_remaining); + +printf ("CRC: 0x%.8x" , abc->crc32_le); + + crc32_le =ab_control_compute_crc (abc); +if (abc->crc32_le != crc32_le) +printf (" (Invalid, Expected: 0x%.8x)\n" , crc32_le); +else +printf (" (Valid)\n" ); + +for (i =0 ; i < abc->nb_slot; ++i) { + slot = &abc->slot_info[i]; +printf ("\nSlot[%d] Metadata:\n" , i); +printf ("\t- Priority: %u\n" , slot->priority); +printf ("\t- Tries Remaining: %u\n" , slot->tries_remaining); +printf ("\t- Successful Boot: %u\n" , slot->successful_boot); +printf ("\t- Verity Corrupted: %u\n" , slot->verity_corrupted); + } + +error: +free (abc); + +return ret; +}
cmd/bcb.c +31 -0
@@ -419,6 +419,32 @@ __maybe_unused static int do_bcb_ab_select(struct cmd_tbl *cmdtp,return CMD_RET_SUCCESS ; } +__maybe_unused static int do_bcb_ab_dump (struct cmd_tbl *cmdtp, +int flag,int argc, +char *const argv[]) +{ +int ret; +struct blk_desc *dev_desc; +struct disk_partition part_info; + +if (argc <3 ) +return CMD_RET_USAGE ; + +if (part_get_info_by_dev_and_name_or_num (argv[1 ], argv[2 ], + &dev_desc, &part_info, + false) <0 ) { +return CMD_RET_FAILURE ; + } + + ret =ab_dump_abc (dev_desc, &part_info); +if (ret <0 ) { +printf ("Cannot dump ABC data, error %d.\n" , ret); +return CMD_RET_FAILURE ; + } + +return CMD_RET_SUCCESS ; +} +U_BOOT_LONGHELP (bcb,"load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n" "load <dev> <part> - load BCB from mmc <dev>:<part>\n"
@@ -444,6 +470,10 @@ U_BOOT_LONGHELP(bcb," - If '--no-dec' is set, the number of tries remaining will not\n" " decremented for the selected boot slot\n" "\n" +"bcb ab_dump -\n" +" Dump boot_control information from specific partition.\n" +" <interface> <dev[:part|#part_name]>\n" + "\n"#endif "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n"
@@ -468,5 +498,6 @@ U_BOOT_CMD_WITH_SUBCMDS(bcb, U_BOOT_SUBCMD_MKENT(store, 1, 1, do_bcb_store),#if IS_ENABLED (CONFIG_ANDROID_AB )U_BOOT_SUBCMD_MKENT (ab_select,5 ,1 , do_bcb_ab_select), + U_BOOT_SUBCMD_MKENT(ab_dump, 3, 1, do_bcb_ab_dump), #endif );
include/android_ab.h +10 -0
@@ -36,4 +36,14 @@ struct disk_partition;int ab_select_slot (struct blk_desc *dev_desc,struct disk_partition *part_info,bool dec_tries); +/** +* ab_dump_abc() - Dump ABC information for specific partition. +* +* @dev_desc: Device description pointer +* @part_info: Partition information +* +* Return: 0 on success, or a negative on error +*/ +int ab_dump_abc (struct blk_desc *dev_desc,struct disk_partition *part_info); +#endif /* __ANDROID_AB_H */
test/py/tests/test_android/test_ab.py +23 -0
@@ -54,6 +54,27 @@ def ab_disk_image(u_boot_console): di = ABTestDiskImage(u_boot_console) return di +def ab_dump(u_boot_console, slot_num, crc): + output = u_boot_console.run_command('bcb ab_dump host 0#misc') + header, slot0, slot1 = output.split('\r\r\n\r\r\n') + slots = [slot0, slot1] + slot_suffixes = ['_a', '_b'] + + header = dict(map(lambda x: map(str.strip, x.split(':')), header.split('\r\r\n'))) + assert header['Bootloader Control'] == '[misc]' + assert header['Active Slot'] == slot_suffixes[slot_num] + assert header['Magic Number'] == '0x42414342' + assert header['Version'] == '1' + assert header['Number of Slots'] == '2' + assert header['Recovery Tries Remaining'] == '0' + assert header['CRC'] == '{} (Valid)'.format(crc) + + slot = dict(map(lambda x: map(str.strip, x.split(':')), slots[slot_num].split('\r\r\n\t- ')[1:])) + assert slot['Priority'] == '15' + assert slot['Tries Remaining'] == '6' + assert slot['Successful Boot'] == '0' + assert slot['Verity Corrupted'] == '0' + @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') @pytest.mark.buildconfigspec('cmd_bcb')
@@ -68,8 +89,10 @@ def test_ab(ab_disk_image, u_boot_console): assert 'Attempting slot a, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=a' in output + ab_dump(u_boot_console, 0, '0xd438d1b9') output = u_boot_console.run_command('bcb ab_select slot_name host 0:1') assert 'Attempting slot b, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=b' in output + ab_dump(u_boot_console, 1, '0x011ec016')
Signature · 1 line
2.43.0
Re: [PATCH v5 5/6] cmd: bcb: introduce 'ab_dump' command to print BCB block content
Hi Dmitry,
Thank you for the patch.
Quoted 30 lines · Dmitry Rokosov
It's really helpful to have the ability to dump BCB block for debugging A/B logic on the board supported this partition schema.
Command 'bcb
ab_dump' prints all fields ofbootloader_controlstruct includingslot_metadatafor all presented slots.Output example:
=====Quoted 15 lines
board# bcb
ab_dumpubi 0#misc
Read 512 bytes from volume misc to000000000bf07580Read 512 bytes from volume misc to000000000bf42f40Bootloader Control: [misc] Active Slot: _a Magic Number: 0x42414342 Version: 1 Number of Slots: 2 Recovery Tries Remaining: 0 CRC: 0x2c8b50bc (Valid)Slot[0] Metadata:
- Priority: 15 - Tries Remaining: 0 - Successful Boot: 1Quoted 7 lines
- Verity Corrupted: 0
Slot[1] Metadata:
- Priority: 14 - Tries Remaining: 7 - Successful Boot: 0- Verity Corrupted: 0
Quoted 7 lines
====
The
ab_dumpcommand allows you to display ABC data directly on the U-Boot console. During an A/B test execution, this test verifies the accuracy of each field within the ABC data.Signed-off-by Dmitry Rokosov <[email protected]>
Quoted 203 lines
--- boot/android_ab.c | 68 +++++++++++++++++++++++++++++++++++ cmd/bcb.c | 31 ++++++++++++++++ include/android_ab.h | 10 ++++++ test/py/tests/test_android/test_ab.py | 23 ++++++++++++ 4 files changed, 132 insertions(+)boot/android_ab.c +68
-0@@ -372,3 +372,71 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,return slot; } + +int ab_dump_abc (struct blk_desc *dev_desc,struct disk_partition *part_info) +{ +struct bootloader_control *abc; +u32 crc32_le; +int i, ret; +struct slot_metadata *slot; + +if (!dev_desc || !part_info) { +log_err ("ANDROID: Empty device descriptor or partition info\n" ); +return -EINVAL ; + } + + ret =ab_control_create_from_disk (dev_desc, part_info, &abc,0 ); +if (ret <0 ) { +log_err ("ANDROID: Cannot create bcb from disk %d\n" , ret); +return ret; + } + +if (abc->magic !=BOOT_CTRL_MAGIC ) { +log_err ("ANDROID: Unknown A/B metadata: %.8x\n" , abc->magic); + ret = -ENODATA ; + goto error; + } + +if (abc->version >BOOT_CTRL_VERSION ) { +log_err ("ANDROID: Unsupported A/B metadata version: %.8x\n" , + abc->version); + ret = -ENODATA ; + goto error; + } + +if (abc->nb_slot >ARRAY_SIZE (abc->slot_info)) { +log_err ("ANDROID: Wrong number of slots %u, expected %zu\n" , + abc->nb_slot,ARRAY_SIZE (abc->slot_info)); + ret = -ENODATA ; + goto error; + } + +printf ("Bootloader Control: [%s]\n" , part_info->name); +printf ("Active Slot: %s\n" , abc->slot_suffix); +printf ("Magic Number: 0x%x\n" , abc->magic); +printf ("Version: %u\n" , abc->version); +printf ("Number of Slots: %u\n" , abc->nb_slot); +printf ("Recovery Tries Remaining: %u\n" , abc->recovery_tries_remaining); + +printf ("CRC: 0x%.8x" , abc->crc32_le); + + crc32_le =ab_control_compute_crc (abc); +if (abc->crc32_le != crc32_le) +printf (" (Invalid, Expected: 0x%.8x)\n" , crc32_le); +else +printf (" (Valid)\n" ); + +for (i =0 ; i < abc->nb_slot; ++i) { + slot = &abc->slot_info[i]; +printf ("\nSlot[%d] Metadata:\n" , i); +printf ("\t- Priority: %u\n" , slot->priority); +printf ("\t- Tries Remaining: %u\n" , slot->tries_remaining); +printf ("\t- Successful Boot: %u\n" , slot->successful_boot); +printf ("\t- Verity Corrupted: %u\n" , slot->verity_corrupted); + } + +error: +free (abc); + +return ret; +}cmd/bcb.c +31
-0@@ -419,6 +419,32 @@ __maybe_unused static int do_bcb_ab_select(struct cmd_tbl *cmdtp,return CMD_RET_SUCCESS ; } +__maybe_unused static int do_bcb_ab_dump (struct cmd_tbl *cmdtp, +int flag,int argc, +char *const argv[]) +{ +int ret; +struct blk_desc *dev_desc; +struct disk_partition part_info; + +if (argc <3 ) +return CMD_RET_USAGE ; + +if (part_get_info_by_dev_and_name_or_num (argv[1 ], argv[2 ], + &dev_desc, &part_info, + false) <0 ) { +return CMD_RET_FAILURE ; + } + + ret =ab_dump_abc (dev_desc, &part_info); +if (ret <0 ) { +printf ("Cannot dump ABC data, error %d.\n" , ret); +return CMD_RET_FAILURE ; + } + +return CMD_RET_SUCCESS ; +} +U_BOOT_LONGHELP (bcb,"load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n" "load <dev> <part> - load BCB from mmc <dev>:<part>\n"@@ -444,6 +470,10 @@ U_BOOT_LONGHELP(bcb," - If '--no-dec' is set, the number of tries remaining will not\n" " decremented for the selected boot slot\n" "\n" +"bcb ab_dump -\n" +" Dump boot_control information from specific partition.\n" +" <interface> <dev[:part|#part_name]>\n" + "\n"#endif "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n" @@ -468,5 +498,6 @@ U_BOOT_CMD_WITH_SUBCMDS(bcb, U_BOOT_SUBCMD_MKENT(store, 1, 1, do_bcb_store),#if IS_ENABLED (CONFIG_ANDROID_AB )U_BOOT_SUBCMD_MKENT (ab_select,5 ,1 , do_bcb_ab_select), + U_BOOT_SUBCMD_MKENT(ab_dump, 3, 1, do_bcb_ab_dump), #endif );include/android_ab.h +10
-0@@ -36,4 +36,14 @@ struct disk_partition;int ab_select_slot (struct blk_desc *dev_desc,struct disk_partition *part_info,bool dec_tries); +/** +* ab_dump_abc() - Dump ABC information for specific partition. +* +* @dev_desc: Device description pointer +* @part_info: Partition information +* +* Return: 0 on success, or a negative on error +*/ +int ab_dump_abc (struct blk_desc *dev_desc,struct disk_partition *part_info); +#endif /* __ANDROID_AB_H */ test/py/tests/test_android/test_ab.py +23
-0@@ -54,6 +54,27 @@ def ab_disk_image(u_boot_console): di = ABTestDiskImage(u_boot_console) return di +def ab_dump(u_boot_console, slot_num, crc): + output = u_boot_console.run_command('bcb ab_dump host 0#misc') + header, slot0, slot1 = output.split('\r\r\n\r\r\n') + slots = [slot0, slot1] + slot_suffixes = ['_a', '_b'] + + header = dict(map(lambda x: map(str.strip, x.split(':')), header.split('\r\r\n'))) + assert header['Bootloader Control'] == '[misc]' + assert header['Active Slot'] == slot_suffixes[slot_num] + assert header['Magic Number'] == '0x42414342' + assert header['Version'] == '1' + assert header['Number of Slots'] == '2' + assert header['Recovery Tries Remaining'] == '0' + assert header['CRC'] == '{} (Valid)'.format(crc) + + slot = dict(map(lambda x: map(str.strip, x.split(':')), slots[slot_num].split('\r\r\n\t- ')[1:])) + assert slot['Priority'] == '15' + assert slot['Tries Remaining'] == '6' + assert slot['Successful Boot'] == '0' + assert slot['Verity Corrupted'] == '0' + @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') @pytest.mark.buildconfigspec('cmd_bcb')@@ -68,8 +89,10 @@ def test_ab(ab_disk_image, u_boot_console): assert 'Attempting slot a, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=a' in output + ab_dump(u_boot_console, 0, '0xd438d1b9') output = u_boot_console.run_command('bcb ab_select slot_name host 0:1') assert 'Attempting slot b, tries remaining 7' in output output = u_boot_console.run_command('printenv slot_name') assert 'slot_name=b' in output + ab_dump(u_boot_console, 1, '0x011ec016')Signature · 2 lines
-- 2.43.0
PATCH v5 6/6 common: android_ab: fix slot suffix for abc block
In reply to Dmitry RokosovTo align with the official Android BCB (Bootloader Control Block) specifications, it's important to note that the slot_suffix should start with an underscore symbol.
For a comprehensive understanding of the expected slot_suffix format in userspace, please refer to the provided reference [1].
Links:
[1] - https://source.android.com/docs/core/architecture/bootloader/updating#slots
Based-on: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446439
--- boot/android_ab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
boot/android_ab.c +3 -2
@@ -52,7 +52,7 @@ static int ab_control_default(struct bootloader_control *abc)if (!abc)return -EFAULT ; -memcpy (abc->slot_suffix,"a\0\0\0" ,4 ); +memcpy (abc->slot_suffix,"_a\0\0" ,4 ); abc->magic =BOOT_CTRL_MAGIC ; abc->version =BOOT_CTRL_VERSION ; abc->nb_slot =NUM_SLOTS ;
@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);if (memcmp (abc->slot_suffix, slot_suffix,sizeof (slot_suffix))) { memcpy(abc->slot_suffix, slot_suffix,
Signature · 1 line
2.43.0
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Hi Dmitry,
Quoted 45 lines · Dmitry Rokosov
To align with the official Android BCB (Bootloader Control Block) specifications, it's important to note that the
slot_suffixshould start with an underscore symbol.For a comprehensive understanding of the expected
slot_suffixformat in userspace, please refer to the provided reference [1].Links:
[1] - https://source.android.com/docs/core/architecture/bootloader/updating#slotsBased-on: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446439
Reviewed-by Mattijs Korpershoek <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Guillaume La Roque <[email protected]>Signed-off-by Dmitry Rokosov <[email protected]>--- boot/android_ab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)boot/android_ab.c +3
-3@@ -52,7 +52,7 @@ static int ab_control_default(struct bootloader_control *abc)if (!abc)return -EFAULT ; -memcpy (abc->slot_suffix,"a\0\0\0" ,4 ); +memcpy (abc->slot_suffix,"_a\0\0" ,4 ); abc->magic =BOOT_CTRL_MAGIC ; abc->version =BOOT_CTRL_VERSION ; abc->nb_slot =NUM_SLOTS ;@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);if (memcmp (abc->slot_suffix, slot_suffix,sizeof (slot_suffix))) { memcpy(abc->slot_suffix, slot_suffix, --
Quoted 2 lines
2.43.0
Signature · 7 lines
Best regards - Atentamente - Meilleures salutations Igor Opaniuk mailto: [email protected] skype: igor.opanyuk https://www.linkedin.com/in/iopaniuk
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Hi Igor,
Thank you for the review.
Quoted 48 lines · Igor Opaniuk
Hi Dmitry,
Quoted 44 lines · Dmitry Rokosov
To align with the official Android BCB (Bootloader Control Block) specifications, it's important to note that the
slot_suffixshould start with an underscore symbol.For a comprehensive understanding of the expected
slot_suffixformat in userspace, please refer to the provided reference [1].Links:
[1] - https://source.android.com/docs/core/architecture/bootloader/updating#slotsBased-on: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446439
Reviewed-by Mattijs Korpershoek <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Guillaume La Roque <[email protected]>Signed-off-by Dmitry Rokosov <[email protected]>--- boot/android_ab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)boot/android_ab.c +3
-2@@ -52,7 +52,7 @@ static int ab_control_default(struct bootloader_control *abc)if (!abc)return -EFAULT ; -memcpy (abc->slot_suffix,"a\0\0\0" ,4 ); +memcpy (abc->slot_suffix,"_a\0\0" ,4 ); abc->magic =BOOT_CTRL_MAGIC ; abc->version =BOOT_CTRL_VERSION ; abc->nb_slot =NUM_SLOTS ;@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);if (memcmp (abc->slot_suffix, slot_suffix,sizeof (slot_suffix))) { memcpy(abc->slot_suffix, slot_suffix,
Quoted 5 lines
Quoted 3 lines
--
2.43.0Reviewed-by Igor Opaniuk <[email protected]>
Sorry, I can't apply that R-b tag because this series has been merged into master already:
https://lore.kernel.org/r/all/20241025175409.GB4959@bill-the-cat/
Quoted 8 lines
Signature · 7 lines
Best regards - Atentamente - Meilleures salutations Igor Opaniuk mailto: [email protected] skype: igor.opanyuk https://www.linkedin.com/in/iopaniuk
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
In reply to Dmitry RokosovQuoted 8 lines · Dmitry Rokosov
To align with the official Android BCB (Bootloader Control Block) specifications, it's important to note that the
slot_suffixshould start with an underscore symbol.For a comprehensive understanding of the expected
slot_suffixformat in userspace, please refer to the provided reference [1].
Quoted 8 lines
Links:
[1] - https://source.android.com/docs/core/architecture/bootloader/updating#slotsBased-on: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446439
Reviewed-by Mattijs Korpershoek <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Guillaume La Roque <[email protected]>Signed-off-by Dmitry Rokosov <[email protected]>
Would be nice to add "Fixes:" tag here, pointing to the corresponding commit where the issue was introduced (see kernel docs for details). It could be quite useful for possible stable branches and other purposes, I'd recommend to add that tag for all fixes if you have more in this series.
Quoted 18 lines
--- boot/android_ab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)boot/android_ab.c +1
-1@@ -52,7 +52,7 @@ static int ab_control_default(struct bootloader_control *abc)if (!abc)return -EFAULT ; -memcpy (abc->slot_suffix,"a\0\0\0" ,4 ); +memcpy (abc->slot_suffix,"_a\0\0" ,4 ); abc->magic =BOOT_CTRL_MAGIC ; abc->version =BOOT_CTRL_VERSION ; abc->nb_slot =NUM_SLOTS ;
boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 6 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);
AFAIU, this changes the behavior of two above functions, and consequently of "bcb ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):
$ grep -sIrHn '"_' boot/bootmeth_android.c
boot/bootmeth_android.c:74: sprintf(partname, BOOT_PART_NAME "_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME "_%s", priv->slot);boot/bootmeth_android.c:156: sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397: sprintf(slot_suffix, "_%s", priv->slot);
$ grep -sIrHn 'slot_suffix _' include/configs/
include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};"
include/configs/meson64_android.h:65: "setenv slot_suffix
_${current_slot}; " \Quoted 7 lines
boot/android_ab.c +0
-1if (memcmp (abc->slot_suffix, slot_suffix,sizeof (slot_suffix))) { memcpy(abc->slot_suffix, slot_suffix, --2.43.0
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Hi Sam,
Thank you for the review.
Quoted 19 lines · Sam Protsenko
Quoted 8 lines · Dmitry Rokosov
To align with the official Android BCB (Bootloader Control Block) specifications, it's important to note that the
slot_suffixshould start with an underscore symbol.For a comprehensive understanding of the expected
slot_suffixformat in userspace, please refer to the provided reference [1].Quoted 8 lines
Links:
[1] - https://source.android.com/docs/core/architecture/bootloader/updating#slotsBased-on: https://android-review.googlesource.com/c/platform/external/u-boot/+/1446439
Reviewed-by Mattijs Korpershoek <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Guillaume La Roque <[email protected]>Signed-off-by Dmitry Rokosov <[email protected]>
Quoted 5 lines
Would be nice to add "Fixes:" tag here, pointing to the corresponding commit where the issue was introduced (see kernel docs for details). It could be quite useful for possible stable branches and other purposes, I'd recommend to add that tag for all fixes if you have more in this series.
I agree. Unfortunately, this series has already been merged here:
https://lore.kernel.org/r/all/20241025175409.GB4959@bill-the-cat/
Quoted 31 lines
Quoted 19 lines
--- boot/android_ab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)boot/android_ab.c +1
-1@@ -52,7 +52,7 @@ static int ab_control_default(struct bootloader_control *abc)if (!abc)return -EFAULT ; -memcpy (abc->slot_suffix,"a\0\0\0" ,4 ); +memcpy (abc->slot_suffix,"_a\0\0" ,4 ); abc->magic =BOOT_CTRL_MAGIC ; abc->version =BOOT_CTRL_VERSION ; abc->nb_slot =NUM_SLOTS ;boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 6 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);AFAIU, this changes the behavior of two above functions, and consequently of "bcb
ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):
Quoted 1 line
$ grep -sIrHn '"_' boot/bootmeth_android.c
I thought the same when first reviewing the patch. Looking a bit closer...
Quoted 7 lines
boot/bootmeth_android.c:74: sprintf(partname,BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:156:sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397:sprintf(slot_suffix, "_%s", priv->slot);
... We can see that ab_select_slot() returns an integer That integer is used later on to initialize priv->slot:
"""
priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';
"""
The change from Dmitry only changes what we **write** to the BCB (into the misc partition), not what is returned by ab_select_slot().
ab_select_slot() still returns an integer which needs to be converted via the BOOT_SLOT_NAME() macro.
Quoted 5 lines
$ grep -sIrHn 'slot_suffix _' include/configs/
include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};"
include/configs/meson64_android.h:65: "setenv slot_suffix
_${current_slot}; " \Same goes for these 2 examples, we use:
The "bcb ab_select current_slot" command to store the slot into the "current_slot" environment variable.
Looking at cmd/bcb.c we can see:
"""
ret = ab_select_slot(dev_desc, &part_info, dec_tries);
if (ret < 0) {
printf("Android boot failed, error %d.\n", ret);
return CMD_RET_FAILURE;
}
/* Android standard slot names are 'a', 'b', ... */
slot[0] = BOOT_SLOT_NAME(ret);
slot[1] = '\0';
env_set(argv[1], slot);
printf("ANDROID: Booting slot: %s\n", slot);"""
So I think this is fine.
Quoted 8 lines
Quoted 8 lines
boot/android_ab.c +0
-1if (memcmp (abc->slot_suffix, slot_suffix,sizeof (slot_suffix))) { memcpy(abc->slot_suffix, slot_suffix, --2.43.0
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Quoted 3 lines · Mattijs Korpershoek
Hi Sam,
Hey Mattijs,
[snip]
Quoted 29 lines
Quoted 13 lines
boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 7 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);AFAIU, this changes the behavior of two above functions, and consequently of "bcb
ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):Quoted 1 line
$ grep -sIrHn '"_' boot/bootmeth_android.cI thought the same when first reviewing the patch. Looking a bit closer...
Quoted 7 lines
boot/bootmeth_android.c:74: sprintf(partname,BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:156:sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397:sprintf(slot_suffix, "_%s", priv->slot);... We can see that
ab_select_slot()returns an integer That integer is used later on to initializepriv->slot:
Quoted 8 lines
"""
priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';"""
The change from Dmitry only changes what we **write** to the BCB (into the misc partition), not what is returned by
ab_select_slot().
Sure. Just wanted to double check that the behavior is not changed in any related parts, as the commit message doesn't mention that. Btw, BCB is an interface between the bootloader and AOSP, so if this patch changes what's being written into BCB, does it affect AOSP part of it somehow? Especially for already existing devices with particular BCB data, in case U-Boot gets updated there.
Quoted 30 lines
ab_select_slot()still returns an integer which needs to be converted via theBOOT_SLOT_NAME()macro.Quoted 5 lines
$ grep -sIrHn 'slot_suffix _' include/configs/ include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};" include/configs/meson64_android.h:65: "setenv slot_suffix _${current_slot}; " \Same goes for these 2 examples, we use:
The "bcbab_selectcurrent_slot" command to store the slot into the "current_slot" environment variable.
Looking atcmd/bcb.cwe can see:"""
ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; } /* Android standard slot names are 'a', 'b', ... */ slot[0] = BOOT_SLOT_NAME(ret); slot[1] = '\0'; env_set(argv[1], slot); printf("ANDROID: Booting slot: %s\n", slot);"""
So I think this is fine.
[snip]
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Hi Sam,
Quoted 48 lines · Sam Protsenko
Quoted 3 lines · Mattijs Korpershoek
Hi Sam,
Hey Mattijs,
[snip]
Quoted 29 lines
Quoted 13 lines
boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 7 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);AFAIU, this changes the behavior of two above functions, and consequently of "bcb
ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):Quoted 1 line
$ grep -sIrHn '"_' boot/bootmeth_android.cI thought the same when first reviewing the patch. Looking a bit closer...
Quoted 7 lines
boot/bootmeth_android.c:74: sprintf(partname,BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:156:sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397:sprintf(slot_suffix, "_%s", priv->slot);... We can see that
ab_select_slot()returns an integer That integer is used later on to initializepriv->slot:Quoted 8 lines
"""
priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';"""
The change from Dmitry only changes what we **write** to the BCB (into the misc partition), not what is returned by
ab_select_slot().
Quoted 6 lines
Sure. Just wanted to double check that the behavior is not changed in any related parts, as the commit message doesn't mention that. Btw, BCB is an interface between the bootloader and AOSP, so if this patch changes what's being written into BCB, does it affect AOSP part of it somehow? Especially for already existing devices with particular BCB data, in case U-Boot gets updated there.
Those are valid concerns.
Per my understanding, on recent Android versions the slot suffix is not read from BCB, but from the ro.boot.slot_suffix property:
"""
// Initialize the current_slot from the read-only property. If the property // was not set (from either the command line or the device tree), we can later // initialize it from the bootloader_control struct.
std::string suffix_prop = android::base::GetProperty("ro.boot.slot_suffix", "");
if (suffix_prop.empty()) {
LOG(ERROR) << "Slot suffix property is not set";
return false; }
current_slot_ = SlotSuffixToIndex(suffix_prop.c_str());
"""
This has been the case since 2019.
If we look at earlier implementations of libboot_control (which was in bootable/recovery)
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1191517
So implementations before 2019 that do not have this patch:
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1111899
Will get the slot suffix from the BCB (not from the commandline)
For these older implementations, we will go through the following:BootControl::Init()
LoadBootloaderControl(device.c_str(), &boot_ctrl) android::base::ReadFully(fd.get(), buffer, sizeof(bootloader_control)
And struct bootloader_control has:
struct bootloader_control {
// NUL terminated active slot suffix.
char slot_suffix[4];And if we look at how the BCB is initialized from userspace in:
https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/boot/1.1/default/boot_control/libboot_control.cpp;l=120;drc=86b8f575059a1799c760ca7012f540a528d68a9d
We can see that we copy _a, not a (for example, if slot == 0).
So I think this is fine.
If needed, I can dig more for behaviour on older devices (<2019), let me know!
Quoted 33 lines
Quoted 31 lines
ab_select_slot()still returns an integer which needs to be converted via theBOOT_SLOT_NAME()macro.Quoted 5 lines
$ grep -sIrHn 'slot_suffix _' include/configs/ include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};" include/configs/meson64_android.h:65: "setenv slot_suffix _${current_slot}; " \Same goes for these 2 examples, we use:
The "bcbab_selectcurrent_slot" command to store the slot into the "current_slot" environment variable.
Looking atcmd/bcb.cwe can see:"""
ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; } /* Android standard slot names are 'a', 'b', ... */ slot[0] = BOOT_SLOT_NAME(ret); slot[1] = '\0'; env_set(argv[1], slot); printf("ANDROID: Booting slot: %s\n", slot);"""
So I think this is fine.
[snip]
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Quoted 60 lines · Mattijs Korpershoek
Hi Sam,
Quoted 48 lines · Sam Protsenko
Quoted 3 lines · Mattijs Korpershoek
Hi Sam,
Hey Mattijs,
[snip]
Quoted 29 lines
Quoted 13 lines
boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 7 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);AFAIU, this changes the behavior of two above functions, and consequently of "bcb
ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):Quoted 1 line
$ grep -sIrHn '"_' boot/bootmeth_android.cI thought the same when first reviewing the patch. Looking a bit closer...
Quoted 7 lines
boot/bootmeth_android.c:74: sprintf(partname,BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:156:sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397:sprintf(slot_suffix, "_%s", priv->slot);... We can see that
ab_select_slot()returns an integer That integer is used later on to initializepriv->slot:Quoted 8 lines
"""
priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';"""
The change from Dmitry only changes what we **write** to the BCB (into the misc partition), not what is returned by
ab_select_slot().Quoted 6 lines
Sure. Just wanted to double check that the behavior is not changed in any related parts, as the commit message doesn't mention that. Btw, BCB is an interface between the bootloader and AOSP, so if this patch changes what's being written into BCB, does it affect AOSP part of it somehow? Especially for already existing devices with particular BCB data, in case U-Boot gets updated there.
Quoted 5 lines
Those are valid concerns.
Per my understanding, on recent Android versions the slot suffix is not read from BCB, but from the ro.boot.slot_suffix property:
That probably still leaves the possible combination of some devices running new U-Boot versions (with this patch applied) together with older Android versions. E.g. in case when U-Boot is updated but Android isn't, may be especially relevant for some dev boards out there.
Quoted 4 lines
"""
// Initialize thecurrent_slotfrom the read-only property. If the property // was not set (from either the command line or the device tree), we can later // initialize it from thebootloader_controlstruct.
So even in recent Android versions it's being initialized from BCB in case the property is not set.
Quoted 33 lines
std::stringsuffix_prop=android::base::GetProperty("ro.boot.slot_suffix", "");if (suffix_prop.empty()) { LOG(ERROR) << "Slot suffix property is not set"; return false;}
current_slot_= SlotSuffixToIndex(suffix_prop.c_str());
"""This has been the case since 2019.
If we look at earlier implementations of
libboot_control(which was in bootable/recovery)
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1191517So implementations before 2019 that do not have this patch:
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1111899Will get the slot suffix from the BCB (not from the commandline)
For these older implementations, we will go through the following:
BootControl::Init()
LoadBootloaderControl(device.c_str(), &boot_ctrl)android::base::ReadFully(fd.get(), buffer,sizeof(bootloader_control)And struct
bootloader_controlhas:struct bootloader_control { // NUL terminated active slot suffix. char slot_suffix[4];
Quoted 9 lines
And if we look at how the BCB is initialized from userspace in:
https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/boot/1.1/default/boot_control/libboot_control.cpp;l=120;drc=86b8f575059a1799c760ca7012f540a528d68a9dWe can see that we copy _a, not a (for example, if slot == 0).
So I think this is fine.
If needed, I can dig more for behaviour on older devices (<2019), let me know!
My point is, if it's possible to introduce this change but keep the same old behavior (across both U-Boot and AOSP), it's usually better to do that that way. If I'm not missing anything and that's a valid concern, maybe a separate patch can be developed on top of the merged patch series handling that. Anyways, I don't have enough time to work on this right now, so just pointing out what I noticed, if it's useful for anybody. I'll let the maintainers decide :)
Thanks!
Quoted 33 lines
Quoted 33 lines
Quoted 31 lines
ab_select_slot()still returns an integer which needs to be converted via theBOOT_SLOT_NAME()macro.Quoted 5 lines
$ grep -sIrHn 'slot_suffix _' include/configs/ include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};" include/configs/meson64_android.h:65: "setenv slot_suffix _${current_slot}; " \Same goes for these 2 examples, we use:
The "bcbab_selectcurrent_slot" command to store the slot into the "current_slot" environment variable.
Looking atcmd/bcb.cwe can see:"""
ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; } /* Android standard slot names are 'a', 'b', ... */ slot[0] = BOOT_SLOT_NAME(ret); slot[1] = '\0'; env_set(argv[1], slot); printf("ANDROID: Booting slot: %s\n", slot);"""
So I think this is fine.
[snip]
Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Hi Sam,
Quoted 68 lines · Sam Protsenko
Quoted 60 lines · Mattijs Korpershoek
Hi Sam,
Quoted 48 lines · Sam Protsenko
Quoted 3 lines · Mattijs Korpershoek
Hi Sam,
Hey Mattijs,
[snip]
Quoted 29 lines
Quoted 13 lines
boot/android_ab.c int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info, · line 332
Quoted 7 lines
boot/android_ab.c +2
-1@@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,* or the device tree. */ memset (slot_suffix,0 ,sizeof (slot_suffix)); - slot_suffix[0 ] =BOOT_SLOT_NAME (slot); + slot_suffix[0 ] ='_' ; + slot_suffix[1 ] =BOOT_SLOT_NAME (slot);AFAIU, this changes the behavior of two above functions, and consequently of "bcb
ab_select" command? If so, just to double check:
were all users of those reworked correspondingly? I can see next occurrences (there may be more):Quoted 1 line
$ grep -sIrHn '"_' boot/bootmeth_android.cI thought the same when first reviewing the patch. Looking a bit closer...
Quoted 7 lines
boot/bootmeth_android.c:74: sprintf(partname,BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:111: sprintf(partname,VENDOR_BOOT_PART_NAME"_%s",priv->slot);boot/bootmeth_android.c:156:sprintf(slot_suffix, "_%s", priv->slot);boot/bootmeth_android.c:397:sprintf(slot_suffix, "_%s", priv->slot);... We can see that
ab_select_slot()returns an integer That integer is used later on to initializepriv->slot:Quoted 8 lines
"""
priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';"""
The change from Dmitry only changes what we **write** to the BCB (into the misc partition), not what is returned by
ab_select_slot().Quoted 6 lines
Sure. Just wanted to double check that the behavior is not changed in any related parts, as the commit message doesn't mention that. Btw, BCB is an interface between the bootloader and AOSP, so if this patch changes what's being written into BCB, does it affect AOSP part of it somehow? Especially for already existing devices with particular BCB data, in case U-Boot gets updated there.
Quoted 5 lines
Those are valid concerns.
Per my understanding, on recent Android versions the slot suffix is not read from BCB, but from the ro.boot.slot_suffix property:
Quoted 5 lines
That probably still leaves the possible combination of some devices running new U-Boot versions (with this patch applied) together with older Android versions. E.g. in case when U-Boot is updated but Android isn't, may be especially relevant for some dev boards out there.
Yes, you are right. Boards with Android older than 2019 and U-Boot v2025.01+
My experience is that most of the time, it's the bootloader that stays out of date and the Android that gets updated. But that might not be the general case.
Quoted 8 lines
Quoted 5 lines
"""
// Initialize thecurrent_slotfrom the read-only property. If the property // was not set (from either the command line or the device tree), we can later // initialize it from thebootloader_controlstruct.So even in recent Android versions it's being initialized from BCB in case the property is not set.
Nope, the comment is wrong. If look at the lines below you can see that the function exits early when the property is not set.
So in recent Android versions if the propery is not set, we just fail to initialize.
Quoted 44 lines
Quoted 34 lines
std::stringsuffix_prop=android::base::GetProperty("ro.boot.slot_suffix", "");if (suffix_prop.empty()) { LOG(ERROR) << "Slot suffix property is not set"; return false;}
current_slot_= SlotSuffixToIndex(suffix_prop.c_str());
"""This has been the case since 2019.
If we look at earlier implementations of
libboot_control(which was in bootable/recovery)
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1191517So implementations before 2019 that do not have this patch:
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1111899Will get the slot suffix from the BCB (not from the commandline)
For these older implementations, we will go through the following:
BootControl::Init()
LoadBootloaderControl(device.c_str(), &boot_ctrl)android::base::ReadFully(fd.get(), buffer,sizeof(bootloader_control)And struct
bootloader_controlhas:struct bootloader_control { // NUL terminated active slot suffix. char slot_suffix[4];Quoted 9 lines
And if we look at how the BCB is initialized from userspace in:
https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/boot/1.1/default/boot_control/libboot_control.cpp;l=120;drc=86b8f575059a1799c760ca7012f540a528d68a9dWe can see that we copy _a, not a (for example, if slot == 0).
So I think this is fine.
If needed, I can dig more for behaviour on older devices (<2019), let me know!
Quoted 7 lines
My point is, if it's possible to introduce this change but keep the same old behavior (across both U-Boot and AOSP), it's usually better to do that that way. If I'm not missing anything and that's a valid concern, maybe a separate patch can be developed on top of the merged patch series handling that. Anyways, I don't have enough time to work on this right now, so just pointing out what I noticed, if it's useful for anybody. I'll let the maintainers decide :)
Yes, thanks a lot for noticing and taking the time to report your valid concerns :)
Quoted 36 lines
Thanks!
Quoted 33 lines
Quoted 33 lines
Quoted 31 lines
ab_select_slot()still returns an integer which needs to be converted via theBOOT_SLOT_NAME()macro.Quoted 5 lines
$ grep -sIrHn 'slot_suffix _' include/configs/ include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};" include/configs/meson64_android.h:65: "setenv slot_suffix _${current_slot}; " \Same goes for these 2 examples, we use:
The "bcbab_selectcurrent_slot" command to store the slot into the "current_slot" environment variable.
Looking atcmd/bcb.cwe can see:"""
ret = ab_select_slot(dev_desc, &part_info, dec_tries); if (ret < 0) { printf("Android boot failed, error %d.\n", ret); return CMD_RET_FAILURE; } /* Android standard slot names are 'a', 'b', ... */ slot[0] = BOOT_SLOT_NAME(ret); slot[1] = '\0'; env_set(argv[1], slot); printf("ANDROID: Booting slot: %s\n", slot);"""
So I think this is fine.
[snip]
Quoted 77 lines · Dmitry Rokosov
The patch series include changes:
- moveab_select_slot()documentation to @ notation
- redesign 'bcb' command toU_BOOT_LONGHELPapproach
- moveab_selectcommand to bcb subcommands
- introduce theab_dumpcommand to print the content of the BCB block; it's useful for debugging A/B logic on supported boards
- fix the slot suffix format in the ABC block to align with official Android BCB specifications
- add a test for theab_dumpcommand to verify the accuracy of each field within the ABC data displayed, it's also useful for testingslot_suffixproblem code pathsSigned-off-by Dmitry Rokosov <[email protected]>---
Changes in v5:
- rework direct #ifdefs toIS_ENABLED()macro
- redesign 'bcb' command toU_BOOT_LONGHELPapproach
- check argc directly in theab_selectandab_dumpsubcommands handlers
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- add #ifdefs forCONFIG_ANDROID_ABincmd/bcb.cto allow the usage of
the bcb command without A/B enabled
- run the savedefconfig command for all defconfigs that include the
CMD_BCBconfiguration
- resolve merge conflicts with latest master
- provide additional trailers from the previous version (excluding
changed patches)
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- return "Legend" block for bcb command
- additionally, verify theCONFIG_ANDROID_ABconfiguration alongsideCONFIG_CMD_BCBto ensure that the A/B scheme is used for the
designated board.
- Link to v2: https://lore.kernel.org/all/[email protected]/Changes in v2:
- moveab_select_slot()documentation to @ notation
- moveab_selectcommand to bcb subcommands per Simon and Mattijs
suggestions
- redesignab_dumpas bcb subcommand
- use spaces instead of tabs in theab_dumpcommand output
- print hex values in the lowercase
- add RvB tags
- Link to v1: https://lore.kernel.org/all/[email protected]/---
Dmitry Rokosov (6):
include/android_ab: moveab_select_slot()documentation to @ notation
cmd: bcb: rework the command toU_BOOT_LONGHELPapproach
treewide: bcb: moveab_selectcommand to bcb subcommands
cmd: bcb: changestrcmp()usage style in thedo_bcb_ab_select()
cmd: bcb: introduce 'ab_dump' command to print BCB block content
common:android_ab: fix slot suffix for abc blockMAINTAINERS | 1 - boot/android_ab.c | 116 +++++++++++++--- cmd/Kconfig | 14 -- cmd/Makefile | 1 - cmd/ab_select.c | 66 --------- cmd/bcb.c | 221 +++++++++++++++++------------- configs/am57xx_evm_defconfig | 1 - configs/am57xx_hs_evm_defconfig | 1 - configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 1 - doc/android/ab.rst | 12 +- include/android_ab.h | 17 ++- include/configs/khadas-vim3_android.h | 2 +- include/configs/khadas-vim3l_android.h | 2 +- include/configs/meson64_android.h | 4 +- include/configs/ti_omap5_common.h | 4 +- test/py/tests/test_android/test_ab.py | 31 ++++- 20 files changed, 275 insertions(+), 224 deletions(-)
Quoted 8 lines
---
base-commit:98a36deb9ab7aaea70b0b0db47718100e08cf3e8
change-id: 20241008-android_ab_master-d86d71c839aeBest regards,
Signature · 1 line
Dmitry Rokosov <[email protected]>
CI/CD tests have been successfully completed.
Please see more details:
https://github.com/u-boot/u-boot/pull/625/checks
Signature · 2 lines
Thank you, Dmitry
Hi Dmitry,
Thank you for this series.
Quoted 12 lines · Dmitry Rokosov
The patch series include changes:
- moveab_select_slot()documentation to @ notation
- redesign 'bcb' command toU_BOOT_LONGHELPapproach
- moveab_selectcommand to bcb subcommands
- introduce theab_dumpcommand to print the content of the BCB block; it's useful for debugging A/B logic on supported boards
- fix the slot suffix format in the ABC block to align with official Android BCB specifications
- add a test for theab_dumpcommand to verify the accuracy of each field within the ABC data displayed, it's also useful for testingslot_suffixproblem code paths
Quoted 1 line
Signed-off-by Dmitry Rokosov <[email protected]>
Boot tested AOSP using on Khadas VIM3 using khadas_vim3_android_defconfig
Boot tested Android 14 on Beagle Play using:am62x_beagleplay_a53_defconfig and am62x_a53_android.config
Quoted 71 lines
---
Changes in v5:
- rework direct #ifdefs toIS_ENABLED()macro
- redesign 'bcb' command toU_BOOT_LONGHELPapproach
- check argc directly in theab_selectandab_dumpsubcommands handlers
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- add #ifdefs forCONFIG_ANDROID_ABincmd/bcb.cto allow the usage of
the bcb command without A/B enabled
- run the savedefconfig command for all defconfigs that include the
CMD_BCBconfiguration
- resolve merge conflicts with latest master
- provide additional trailers from the previous version (excluding
changed patches)
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- return "Legend" block for bcb command
- additionally, verify theCONFIG_ANDROID_ABconfiguration alongsideCONFIG_CMD_BCBto ensure that the A/B scheme is used for the
designated board.
- Link to v2: https://lore.kernel.org/all/[email protected]/Changes in v2:
- moveab_select_slot()documentation to @ notation
- moveab_selectcommand to bcb subcommands per Simon and Mattijs
suggestions
- redesignab_dumpas bcb subcommand
- use spaces instead of tabs in theab_dumpcommand output
- print hex values in the lowercase
- add RvB tags
- Link to v1: https://lore.kernel.org/all/[email protected]/---
Dmitry Rokosov (6):
include/android_ab: moveab_select_slot()documentation to @ notation
cmd: bcb: rework the command toU_BOOT_LONGHELPapproach
treewide: bcb: moveab_selectcommand to bcb subcommands
cmd: bcb: changestrcmp()usage style in thedo_bcb_ab_select()
cmd: bcb: introduce 'ab_dump' command to print BCB block content
common:android_ab: fix slot suffix for abc blockMAINTAINERS | 1 - boot/android_ab.c | 116 +++++++++++++--- cmd/Kconfig | 14 -- cmd/Makefile | 1 - cmd/ab_select.c | 66 --------- cmd/bcb.c | 221 +++++++++++++++++------------- configs/am57xx_evm_defconfig | 1 - configs/am57xx_hs_evm_defconfig | 1 - configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 1 - doc/android/ab.rst | 12 +- include/android_ab.h | 17 ++- include/configs/khadas-vim3_android.h | 2 +- include/configs/khadas-vim3l_android.h | 2 +- include/configs/meson64_android.h | 4 +- include/configs/ti_omap5_common.h | 4 +- test/py/tests/test_android/test_ab.py | 31 ++++- 20 files changed, 275 insertions(+), 224 deletions(-)---
base-commit:98a36deb9ab7aaea70b0b0db47718100e08cf3e8
change-id: 20241008-android_ab_master-d86d71c839aeBest regards,
Signature · 1 line
Dmitry Rokosov <[email protected]>
Hi,
Quoted 12 lines · Dmitry Rokosov
The patch series include changes:
- moveab_select_slot()documentation to @ notation
- redesign 'bcb' command toU_BOOT_LONGHELPapproach
- moveab_selectcommand to bcb subcommands
- introduce theab_dumpcommand to print the content of the BCB block; it's useful for debugging A/B logic on supported boards
- fix the slot suffix format in the ABC block to align with official Android BCB specifications
- add a test for theab_dumpcommand to verify the accuracy of each field within the ABC data displayed, it's also useful for testingslot_suffixproblem code paths
Quoted 1 line
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/6] include/android_ab: move ab_select_slot() documentation to @ notation
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/01874ac7c06b8c657e7c3fda5ac555f821ef5b36 [2/6] cmd: bcb: rework the command to U_BOOT_LONGHELP approach https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a8ca7d46ea744381185c0bf70cbdf4db7dc734b7 [3/6] treewide: bcb: move ab_select command to bcb subcommands https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/b523b4d2c32f07ca0793bb0f926b02ecb0556cc6 [4/6] cmd: bcb: change strcmp() usage style in the do_bcb_ab_select() https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/b1bc9a2fc93da8ed25dfc4078e76220ac26eb6b0 [5/6] cmd: bcb: introduce 'ab_dump' command to print BCB block content https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a995084beb6682748002878ccb4b8c4de9fc0136 [6/6] common: android_ab: fix slot suffix for abc block https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/55c876c6f9b787488c7a9f9c678398c48d13db6f
--
Mattijs