Re: [PATCH v3 2/6] treewide: bcb: move ab_select command to bcb subcommands

On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
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 ddrokosov@salutedevices.com
MAINTAINERS | 1 - cmd/Kconfig | 15 +------ cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- 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 ++-- 16 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org 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 diff --git a/cmd/Kconfig b/cmd/Kconfig index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1067,6 +1067,7 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS - depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in: diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
+ if (!CONFIG_IS_ENABLED(AB_SELECT)) + return CMD_RET_SUCCESS; + for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false; @@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
+ if (!CONFIG_IS_ENABLED(AB_SELECT)) + return CMD_RET_SUCCESS; + if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in: @@ -1789,20 +1790,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
menuconfig CMD_NET diff --git a/cmd/Makefile b/cmd/Makefile index 91227f1249cbda5f7b383e8865c8cc23f3ad5f44..0fd7da3c0de91822c4299cc7034193c497d622b1 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/ab_select.c b/cmd/ab_select.c deleted file mode 100644 index 7c178c728ca4c8b5bcba02a04eef2d6a7c86afb6..0000000000000000000000000000000000000000 --- a/cmd/ab_select.c +++ /dev/null @@ -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"
-); diff --git a/cmd/bcb.c b/cmd/bcb.c index 97a96c009641cc094645607ef833575f3c03fe4b..4f3b8a1538a1f05b8b4a1a51c8962c422981166a 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -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> @@ -23,6 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE,
- BCB_CMD_AB_SELECT,
};
static const char * const fields[] = { @@ -52,6 +54,8 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP;
- if (!strcmp(cmd, "ab_select"))
else return -1;return BCB_CMD_AB_SELECT;
} @@ -85,6 +89,10 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break;
- case BCB_CMD_AB_SELECT:
if (argc != 4 && argc != 5)
goto err;
default: printf("Error: 'bcb %s' not supported\n", argv[0]); return -1;return 0;
@@ -414,6 +422,44 @@ void bcb_reset(void) __bcb_reset(); }
+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;
- 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;
+}
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, "", ""), @@ -421,6 +467,8 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""),
- U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1,
do_bcb_ab_select, "", ""),
};
static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -460,6 +508,21 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n"
- "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" "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n" "<dev> - storage device index containing the BCB partition\n"
diff --git a/configs/am57xx_hs_evm_usb_defconfig b/configs/am57xx_hs_evm_usb_defconfig index 81a938339d5934605cb7defa04ea92f76468b21a..2d8068ecdc79c01c1281ab3873fc892aa4c96be7 100644 --- a/configs/am57xx_hs_evm_usb_defconfig +++ b/configs/am57xx_hs_evm_usb_defconfig @@ -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 diff --git a/configs/khadas-vim3_android_ab_defconfig b/configs/khadas-vim3_android_ab_defconfig index 510fe4f8928fe39a040a615636fa550b3e0dc5db..de5357c45cbfe4742d9491a29386850570acc235 100644 --- a/configs/khadas-vim3_android_ab_defconfig +++ b/configs/khadas-vim3_android_ab_defconfig @@ -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 diff --git a/configs/khadas-vim3l_android_ab_defconfig b/configs/khadas-vim3l_android_ab_defconfig index d2da8ff2a69b209b8fb22a48be537bd4dd17a3bb..4d7b90f23002e464d7dc40516bcd3161b0f59439 100644 --- a/configs/khadas-vim3l_android_ab_defconfig +++ b/configs/khadas-vim3l_android_ab_defconfig @@ -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 diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index e2f57c11f0e110917928695936d1066bfc4e8902..e598d44359fff493f31d2a2f25697a3bc78cf0a8 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -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_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y @@ -169,8 +171,8 @@ CONFIG_PWRSEQ=y CONFIG_I2C_EEPROM=y CONFIG_MMC_SANDBOX=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 540ccef895059a57632d565d210bb449245e644d..6211c0f9ac916448d6730cee6144034966d0d1f6 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -75,6 +75,7 @@ CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEM_SEARCH=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_BCB=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPIO_READ=y @@ -102,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 @@ -228,8 +228,8 @@ CONFIG_MMC_PCI=y CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/doc/android/ab.rst b/doc/android/ab.rst index 2adf88781d60b61d1b3c74efe976a684b590c813..7fd4aeb6a724b839de9be5e9a8843ade2ad3667e 100644 --- a/doc/android/ab.rst +++ b/doc/android/ab.rst @@ -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::
diff --git a/include/configs/khadas-vim3_android.h b/include/configs/khadas-vim3_android.h index da6adf6c413add03413f40987959a24ad0d41e62..5468ac5878b34b82a70db84c209bab9f3a9dd79f 100644 --- a/include/configs/khadas-vim3_android.h +++ b/include/configs/khadas-vim3_android.h @@ -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 \ diff --git a/include/configs/khadas-vim3l_android.h b/include/configs/khadas-vim3l_android.h index b1768e2d821176452254fb07f2e3747402b9b4fd..32821b942109feae5ade9f7fd02924bca34cf58b 100644 --- a/include/configs/khadas-vim3l_android.h +++ b/include/configs/khadas-vim3l_android.h @@ -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 \ diff --git a/include/configs/meson64_android.h b/include/configs/meson64_android.h index c0e977abb01fb9efb7a462906a0073c84c800897..cc626dbf02418a49b367c8386797ce6ffc28c85b 100644 --- a/include/configs/meson64_android.h +++ b/include/configs/meson64_android.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "fi;\0""bcb ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
diff --git a/include/configs/ti_omap5_common.h b/include/configs/ti_omap5_common.h index 26494ae980108ad84eb173a0deaa7b701a5309d4..26b6c1cd188c05371c6455cd6247f07a1773d885 100644 --- a/include/configs/ti_omap5_common.h +++ b/include/configs/ti_omap5_common.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \"bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
diff --git a/test/py/tests/test_android/test_ab.py b/test/py/tests/test_android/test_ab.py index c79cb07fda35dfeb608ac7345cd3f22744e2e491..0d7b7995a9fab6e3daad748721818b9e4cfac452 100644 --- a/test/py/tests/test_android/test_ab.py +++ b/test/py/tests/test_android/test_ab.py @@ -56,20 +56,20 @@ def ab_disk_image(u_boot_console):
@pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') -@pytest.mark.buildconfigspec('cmd_ab_select') +@pytest.mark.buildconfigspec('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
-- 2.43.0
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#2439): https://groups.io/g/u-boot-amlogic/message/2439 Mute This Topic: https://groups.io/mt/108948527/1991006 Group Owner: u-boot-amlogic+owner@groups.io Unsubscribe: https://groups.io/g/u-boot-amlogic/unsub [mkorpershoek@baylibre.com] -=-=-=-=-=-=-=-=-=-=-=-

On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
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 ddrokosov@salutedevices.com
MAINTAINERS | 1 - cmd/Kconfig | 15 +------ cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- 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 ++-- 16 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org 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 diff --git a/cmd/Kconfig b/cmd/Kconfig index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1067,6 +1067,7 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
I will prepare v4, and I apologize for the breakage in the Khadas Android defconfig. Unfortunately, I do not have the capability to test it during runtime.
Please re-check v4 on the Khadas board if possible.
help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in: @@ -1789,20 +1790,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
menuconfig CMD_NET diff --git a/cmd/Makefile b/cmd/Makefile index 91227f1249cbda5f7b383e8865c8cc23f3ad5f44..0fd7da3c0de91822c4299cc7034193c497d622b1 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/ab_select.c b/cmd/ab_select.c deleted file mode 100644 index 7c178c728ca4c8b5bcba02a04eef2d6a7c86afb6..0000000000000000000000000000000000000000 --- a/cmd/ab_select.c +++ /dev/null @@ -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"
-); diff --git a/cmd/bcb.c b/cmd/bcb.c index 97a96c009641cc094645607ef833575f3c03fe4b..4f3b8a1538a1f05b8b4a1a51c8962c422981166a 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -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> @@ -23,6 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE,
- BCB_CMD_AB_SELECT,
};
static const char * const fields[] = { @@ -52,6 +54,8 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP;
- if (!strcmp(cmd, "ab_select"))
else return -1;return BCB_CMD_AB_SELECT;
} @@ -85,6 +89,10 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break;
- case BCB_CMD_AB_SELECT:
if (argc != 4 && argc != 5)
goto err;
default: printf("Error: 'bcb %s' not supported\n", argv[0]); return -1;return 0;
@@ -414,6 +422,44 @@ void bcb_reset(void) __bcb_reset(); }
+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;
- 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;
+}
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, "", ""), @@ -421,6 +467,8 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""),
- U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1,
do_bcb_ab_select, "", ""),
};
static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -460,6 +508,21 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n"
- "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" "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n" "<dev> - storage device index containing the BCB partition\n"
diff --git a/configs/am57xx_hs_evm_usb_defconfig b/configs/am57xx_hs_evm_usb_defconfig index 81a938339d5934605cb7defa04ea92f76468b21a..2d8068ecdc79c01c1281ab3873fc892aa4c96be7 100644 --- a/configs/am57xx_hs_evm_usb_defconfig +++ b/configs/am57xx_hs_evm_usb_defconfig @@ -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 diff --git a/configs/khadas-vim3_android_ab_defconfig b/configs/khadas-vim3_android_ab_defconfig index 510fe4f8928fe39a040a615636fa550b3e0dc5db..de5357c45cbfe4742d9491a29386850570acc235 100644 --- a/configs/khadas-vim3_android_ab_defconfig +++ b/configs/khadas-vim3_android_ab_defconfig @@ -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 diff --git a/configs/khadas-vim3l_android_ab_defconfig b/configs/khadas-vim3l_android_ab_defconfig index d2da8ff2a69b209b8fb22a48be537bd4dd17a3bb..4d7b90f23002e464d7dc40516bcd3161b0f59439 100644 --- a/configs/khadas-vim3l_android_ab_defconfig +++ b/configs/khadas-vim3l_android_ab_defconfig @@ -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 diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index e2f57c11f0e110917928695936d1066bfc4e8902..e598d44359fff493f31d2a2f25697a3bc78cf0a8 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -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_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y @@ -169,8 +171,8 @@ CONFIG_PWRSEQ=y CONFIG_I2C_EEPROM=y CONFIG_MMC_SANDBOX=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 540ccef895059a57632d565d210bb449245e644d..6211c0f9ac916448d6730cee6144034966d0d1f6 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -75,6 +75,7 @@ CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEM_SEARCH=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_BCB=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPIO_READ=y @@ -102,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 @@ -228,8 +228,8 @@ CONFIG_MMC_PCI=y CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/doc/android/ab.rst b/doc/android/ab.rst index 2adf88781d60b61d1b3c74efe976a684b590c813..7fd4aeb6a724b839de9be5e9a8843ade2ad3667e 100644 --- a/doc/android/ab.rst +++ b/doc/android/ab.rst @@ -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::
diff --git a/include/configs/khadas-vim3_android.h b/include/configs/khadas-vim3_android.h index da6adf6c413add03413f40987959a24ad0d41e62..5468ac5878b34b82a70db84c209bab9f3a9dd79f 100644 --- a/include/configs/khadas-vim3_android.h +++ b/include/configs/khadas-vim3_android.h @@ -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 \ diff --git a/include/configs/khadas-vim3l_android.h b/include/configs/khadas-vim3l_android.h index b1768e2d821176452254fb07f2e3747402b9b4fd..32821b942109feae5ade9f7fd02924bca34cf58b 100644 --- a/include/configs/khadas-vim3l_android.h +++ b/include/configs/khadas-vim3l_android.h @@ -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 \ diff --git a/include/configs/meson64_android.h b/include/configs/meson64_android.h index c0e977abb01fb9efb7a462906a0073c84c800897..cc626dbf02418a49b367c8386797ce6ffc28c85b 100644 --- a/include/configs/meson64_android.h +++ b/include/configs/meson64_android.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "fi;\0""bcb ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
diff --git a/include/configs/ti_omap5_common.h b/include/configs/ti_omap5_common.h index 26494ae980108ad84eb173a0deaa7b701a5309d4..26b6c1cd188c05371c6455cd6247f07a1773d885 100644 --- a/include/configs/ti_omap5_common.h +++ b/include/configs/ti_omap5_common.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \"bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
diff --git a/test/py/tests/test_android/test_ab.py b/test/py/tests/test_android/test_ab.py index c79cb07fda35dfeb608ac7345cd3f22744e2e491..0d7b7995a9fab6e3daad748721818b9e4cfac452 100644 --- a/test/py/tests/test_android/test_ab.py +++ b/test/py/tests/test_android/test_ab.py @@ -56,20 +56,20 @@ def ab_disk_image(u_boot_console):
@pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') -@pytest.mark.buildconfigspec('cmd_ab_select') +@pytest.mark.buildconfigspec('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
-- 2.43.0
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#2439): https://groups.io/g/u-boot-amlogic/message/2439 Mute This Topic: https://groups.io/mt/108948527/1991006 Group Owner: u-boot-amlogic+owner@groups.io Unsubscribe: https://groups.io/g/u-boot-amlogic/unsub [mkorpershoek@baylibre.com] -=-=-=-=-=-=-=-=-=-=-=-

Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
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 ddrokosov@salutedevices.com
MAINTAINERS | 1 - cmd/Kconfig | 15 +------ cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- 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 ++-- 16 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org 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 diff --git a/cmd/Kconfig b/cmd/Kconfig index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1067,6 +1067,7 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
I will prepare v4, and I apologize for the breakage in the Khadas Android defconfig. Unfortunately, I do not have the capability to test it during runtime.
No worries, that's what review is for! Thanks again for contributing these patches and for your patience.
Please re-check v4 on the Khadas board if possible.
Yes will do. Note that this is only for khadas-vim3_android_defconfig (which has non A/B partitioning)
On khadas-vim3_android_ab_defconfig, this behaves well (as Guillaume tested).
Regards Mattijs
help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in: @@ -1789,20 +1790,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
menuconfig CMD_NET diff --git a/cmd/Makefile b/cmd/Makefile index 91227f1249cbda5f7b383e8865c8cc23f3ad5f44..0fd7da3c0de91822c4299cc7034193c497d622b1 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/ab_select.c b/cmd/ab_select.c deleted file mode 100644 index 7c178c728ca4c8b5bcba02a04eef2d6a7c86afb6..0000000000000000000000000000000000000000 --- a/cmd/ab_select.c +++ /dev/null @@ -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"
-); diff --git a/cmd/bcb.c b/cmd/bcb.c index 97a96c009641cc094645607ef833575f3c03fe4b..4f3b8a1538a1f05b8b4a1a51c8962c422981166a 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -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> @@ -23,6 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE,
- BCB_CMD_AB_SELECT,
};
static const char * const fields[] = { @@ -52,6 +54,8 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP;
- if (!strcmp(cmd, "ab_select"))
else return -1;return BCB_CMD_AB_SELECT;
} @@ -85,6 +89,10 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break;
- case BCB_CMD_AB_SELECT:
if (argc != 4 && argc != 5)
goto err;
default: printf("Error: 'bcb %s' not supported\n", argv[0]); return -1;return 0;
@@ -414,6 +422,44 @@ void bcb_reset(void) __bcb_reset(); }
+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;
- 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;
+}
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, "", ""), @@ -421,6 +467,8 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""),
- U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1,
do_bcb_ab_select, "", ""),
};
static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -460,6 +508,21 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n"
- "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" "Legend:\n" "<interface> - storage device interface (virtio, mmc, etc)\n" "<dev> - storage device index containing the BCB partition\n"
diff --git a/configs/am57xx_hs_evm_usb_defconfig b/configs/am57xx_hs_evm_usb_defconfig index 81a938339d5934605cb7defa04ea92f76468b21a..2d8068ecdc79c01c1281ab3873fc892aa4c96be7 100644 --- a/configs/am57xx_hs_evm_usb_defconfig +++ b/configs/am57xx_hs_evm_usb_defconfig @@ -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 diff --git a/configs/khadas-vim3_android_ab_defconfig b/configs/khadas-vim3_android_ab_defconfig index 510fe4f8928fe39a040a615636fa550b3e0dc5db..de5357c45cbfe4742d9491a29386850570acc235 100644 --- a/configs/khadas-vim3_android_ab_defconfig +++ b/configs/khadas-vim3_android_ab_defconfig @@ -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 diff --git a/configs/khadas-vim3l_android_ab_defconfig b/configs/khadas-vim3l_android_ab_defconfig index d2da8ff2a69b209b8fb22a48be537bd4dd17a3bb..4d7b90f23002e464d7dc40516bcd3161b0f59439 100644 --- a/configs/khadas-vim3l_android_ab_defconfig +++ b/configs/khadas-vim3l_android_ab_defconfig @@ -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 diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index e2f57c11f0e110917928695936d1066bfc4e8902..e598d44359fff493f31d2a2f25697a3bc78cf0a8 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -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_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y @@ -169,8 +171,8 @@ CONFIG_PWRSEQ=y CONFIG_I2C_EEPROM=y CONFIG_MMC_SANDBOX=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 540ccef895059a57632d565d210bb449245e644d..6211c0f9ac916448d6730cee6144034966d0d1f6 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -75,6 +75,7 @@ CONFIG_CMD_MEMINFO=y CONFIG_CMD_MEM_SEARCH=y CONFIG_CMD_MX_CYCLIC=y CONFIG_CMD_MEMTEST=y +CONFIG_CMD_BCB=y CONFIG_CMD_DEMO=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPIO_READ=y @@ -102,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 @@ -228,8 +228,8 @@ CONFIG_MMC_PCI=y CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y -CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8 +CONFIG_MTD_RAW_NAND=y CONFIG_SYS_NAND_USE_FLASH_BBT=y CONFIG_NAND_SANDBOX=y CONFIG_SYS_NAND_ONFI_DETECTION=y diff --git a/doc/android/ab.rst b/doc/android/ab.rst index 2adf88781d60b61d1b3c74efe976a684b590c813..7fd4aeb6a724b839de9be5e9a8843ade2ad3667e 100644 --- a/doc/android/ab.rst +++ b/doc/android/ab.rst @@ -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::
diff --git a/include/configs/khadas-vim3_android.h b/include/configs/khadas-vim3_android.h index da6adf6c413add03413f40987959a24ad0d41e62..5468ac5878b34b82a70db84c209bab9f3a9dd79f 100644 --- a/include/configs/khadas-vim3_android.h +++ b/include/configs/khadas-vim3_android.h @@ -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 \ diff --git a/include/configs/khadas-vim3l_android.h b/include/configs/khadas-vim3l_android.h index b1768e2d821176452254fb07f2e3747402b9b4fd..32821b942109feae5ade9f7fd02924bca34cf58b 100644 --- a/include/configs/khadas-vim3l_android.h +++ b/include/configs/khadas-vim3l_android.h @@ -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 \ diff --git a/include/configs/meson64_android.h b/include/configs/meson64_android.h index c0e977abb01fb9efb7a462906a0073c84c800897..cc626dbf02418a49b367c8386797ce6ffc28c85b 100644 --- a/include/configs/meson64_android.h +++ b/include/configs/meson64_android.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "fi;\0""bcb ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
diff --git a/include/configs/ti_omap5_common.h b/include/configs/ti_omap5_common.h index 26494ae980108ad84eb173a0deaa7b701a5309d4..26b6c1cd188c05371c6455cd6247f07a1773d885 100644 --- a/include/configs/ti_omap5_common.h +++ b/include/configs/ti_omap5_common.h @@ -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};" \
"else " \ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \"bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
diff --git a/test/py/tests/test_android/test_ab.py b/test/py/tests/test_android/test_ab.py index c79cb07fda35dfeb608ac7345cd3f22744e2e491..0d7b7995a9fab6e3daad748721818b9e4cfac452 100644 --- a/test/py/tests/test_android/test_ab.py +++ b/test/py/tests/test_android/test_ab.py @@ -56,20 +56,20 @@ def ab_disk_image(u_boot_console):
@pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_ab') -@pytest.mark.buildconfigspec('cmd_ab_select') +@pytest.mark.buildconfigspec('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
-- 2.43.0
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#2439): https://groups.io/g/u-boot-amlogic/message/2439 Mute This Topic: https://groups.io/mt/108948527/1991006 Group Owner: u-boot-amlogic+owner@groups.io Unsubscribe: https://groups.io/g/u-boot-amlogic/unsub [mkorpershoek@baylibre.com] -=-=-=-=-=-=-=-=-=-=-=-
-- Thank you, Dmitry

Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
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 ddrokosov@salutedevices.com
MAINTAINERS | 1 - cmd/Kconfig | 15 +------ cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- 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 ++-- 16 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org 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 diff --git a/cmd/Kconfig b/cmd/Kconfig index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1067,6 +1067,7 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
[...]

Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
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 ddrokosov@salutedevices.com
MAINTAINERS | 1 - cmd/Kconfig | 15 +------ cmd/Makefile | 1 - cmd/ab_select.c | 66 ------------------------------- cmd/bcb.c | 63 +++++++++++++++++++++++++++++ configs/am57xx_hs_evm_usb_defconfig | 1 - configs/khadas-vim3_android_ab_defconfig | 1 - configs/khadas-vim3l_android_ab_defconfig | 1 - configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- 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 ++-- 16 files changed, 85 insertions(+), 104 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org 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 diff --git a/cmd/Kconfig b/cmd/Kconfig index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1067,6 +1067,7 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
[...]
Regards, Simon

Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
> 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 ddrokosov@salutedevices.com > --- > MAINTAINERS | 1 - > cmd/Kconfig | 15 +------ > cmd/Makefile | 1 - > cmd/ab_select.c | 66 ------------------------------- > cmd/bcb.c | 63 +++++++++++++++++++++++++++++ > configs/am57xx_hs_evm_usb_defconfig | 1 - > configs/khadas-vim3_android_ab_defconfig | 1 - > configs/khadas-vim3l_android_ab_defconfig | 1 - > configs/sandbox64_defconfig | 4 +- > configs/sandbox_defconfig | 4 +- > 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 ++-- > 16 files changed, 85 insertions(+), 104 deletions(-) > > diff --git a/MAINTAINERS b/MAINTAINERS > index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org > 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 > diff --git a/cmd/Kconfig b/cmd/Kconfig > index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -1067,6 +1067,7 @@ config CMD_ADC > config CMD_BCB > bool "bcb" > depends on PARTITIONS > + depends on ANDROID_AB
When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no longer part of that build:
$ grep CMD_BCB .config
<empty>
However, if we look at include/configs/meson64_android.h, we can see that the "bcb" command is not only used for checking the _slot suffix.
It's also used for checking the bootloader reason. For example, in BOOTENV_DEV_FASTBOOT, we call:
"if bcb test command = bootonce-bootloader; then " \
Since CMD_BCB is no longer part of the .config (due to this dependency), the boot script now shows errors:
""" U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (effective 3.8 GiB) Core: 411 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring Reading from MMC(2)... *** Warning - bad CRC, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0 Verify GPT: success! Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist dev: pinctrl@14 dev: pinctrl@40 gpio: pin 88 (gpio 88) value is 1 Unknown command 'bcb' - try 'help' Warning: BCB is corrupted or does not exist Loading Android boot partition... switch to partitions #0, OK mmc2(part 0) is current device """
I know we should not be using a boot script, nor non A/B configs but it's a bummer that this series breaks an upstream defconfig (khadas-vim3_android_defconfig)
My recommendation:
Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. This way, users can use CMD_BCB with and without ANDROID_AB being enabled.
We could do: When ANDROID_AB=y, implement bcb ab_select subcommand When ANDROID_AB=n, command is not accessible.
I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
[...]
Regards, Simon

Hi Mattijs,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
> Hi Dmitry, > > Thank you for the patch. > > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: > >> 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 ddrokosov@salutedevices.com >> --- >> MAINTAINERS | 1 - >> cmd/Kconfig | 15 +------ >> cmd/Makefile | 1 - >> cmd/ab_select.c | 66 ------------------------------- >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ >> configs/am57xx_hs_evm_usb_defconfig | 1 - >> configs/khadas-vim3_android_ab_defconfig | 1 - >> configs/khadas-vim3l_android_ab_defconfig | 1 - >> configs/sandbox64_defconfig | 4 +- >> configs/sandbox_defconfig | 4 +- >> 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 ++-- >> 16 files changed, 85 insertions(+), 104 deletions(-) >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org >> 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 >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 >> --- a/cmd/Kconfig >> +++ b/cmd/Kconfig >> @@ -1067,6 +1067,7 @@ config CMD_ADC >> config CMD_BCB >> bool "bcb" >> depends on PARTITIONS >> + depends on ANDROID_AB > > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no > longer part of that build: > > $ grep CMD_BCB .config > <empty> > > However, if we look at include/configs/meson64_android.h, we can see > that the "bcb" command is not only used for checking the _slot suffix. > > It's also used for checking the bootloader reason. For example, in > BOOTENV_DEV_FASTBOOT, we call: > > "if bcb test command = bootonce-bootloader; then " \ > > Since CMD_BCB is no longer part of the .config (due to this dependency), > the boot script now shows errors: > > """ > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 > > Model: Khadas VIM3 > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) > DRAM: 2 GiB (effective 3.8 GiB) > Core: 411 devices, 36 uclasses, devicetree: separate > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring > Reading from MMC(2)... *** Warning - bad CRC, using default environment > > In: usbkbd,serial > Out: vidconsole,serial > Err: vidconsole,serial > Net: eth0: ethernet@ff3f0000 > > Hit any key to stop autoboot: 0 > Verify GPT: success! > Unknown command 'bcb' - try 'help' > Warning: BCB is corrupted or does not exist > dev: pinctrl@14 > dev: pinctrl@40 > gpio: pin 88 (gpio 88) value is 1 > Unknown command 'bcb' - try 'help' > Warning: BCB is corrupted or does not exist > Loading Android boot partition... > switch to partitions #0, OK > mmc2(part 0) is current device > """ > > I know we should not be using a boot script, nor non A/B configs but > it's a bummer that this series breaks an upstream > defconfig (khadas-vim3_android_defconfig) > > My recommendation: > > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. > > We could do: > When ANDROID_AB=y, implement bcb ab_select subcommand > When ANDROID_AB=n, command is not accessible. > > I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
I just run build on the my x86 Ubuntu machine.
$ cd uboot $ make mproper $ make sandbox_defconfig $ make -j$(nproc)
That's all.
I've already sent the v4 patch with #ifdef. I can prepare the v5 patch using the IS_ENABLED() macro and will aim to send it today.
But I have one question:
Do we really want to display the ab_select and ab_dump subcommands to users if these commands are just stubs? Perhaps we should consider adding #ifdef directives to the subcommand arrays.

Hi Dmitry,
On mar., oct. 15, 2024 at 16:26, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hi Mattijs,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote: > On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote: > > > Hi Dmitry, > > > > Thank you for the patch. > > > > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: > > > >> 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 ddrokosov@salutedevices.com > >> --- > >> MAINTAINERS | 1 - > >> cmd/Kconfig | 15 +------ > >> cmd/Makefile | 1 - > >> cmd/ab_select.c | 66 ------------------------------- > >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ > >> configs/am57xx_hs_evm_usb_defconfig | 1 - > >> configs/khadas-vim3_android_ab_defconfig | 1 - > >> configs/khadas-vim3l_android_ab_defconfig | 1 - > >> configs/sandbox64_defconfig | 4 +- > >> configs/sandbox_defconfig | 4 +- > >> 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 ++-- > >> 16 files changed, 85 insertions(+), 104 deletions(-) > >> > >> diff --git a/MAINTAINERS b/MAINTAINERS > >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 > >> --- a/MAINTAINERS > >> +++ b/MAINTAINERS > >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org > >> 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 > >> diff --git a/cmd/Kconfig b/cmd/Kconfig > >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 > >> --- a/cmd/Kconfig > >> +++ b/cmd/Kconfig > >> @@ -1067,6 +1067,7 @@ config CMD_ADC > >> config CMD_BCB > >> bool "bcb" > >> depends on PARTITIONS > >> + depends on ANDROID_AB > > > > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no > > longer part of that build: > > > > $ grep CMD_BCB .config > > <empty> > > > > However, if we look at include/configs/meson64_android.h, we can see > > that the "bcb" command is not only used for checking the _slot suffix. > > > > It's also used for checking the bootloader reason. For example, in > > BOOTENV_DEV_FASTBOOT, we call: > > > > "if bcb test command = bootonce-bootloader; then " \ > > > > Since CMD_BCB is no longer part of the .config (due to this dependency), > > the boot script now shows errors: > > > > """ > > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 > > > > Model: Khadas VIM3 > > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) > > DRAM: 2 GiB (effective 3.8 GiB) > > Core: 411 devices, 36 uclasses, devicetree: separate > > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 > > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring > > Reading from MMC(2)... *** Warning - bad CRC, using default environment > > > > In: usbkbd,serial > > Out: vidconsole,serial > > Err: vidconsole,serial > > Net: eth0: ethernet@ff3f0000 > > > > Hit any key to stop autoboot: 0 > > Verify GPT: success! > > Unknown command 'bcb' - try 'help' > > Warning: BCB is corrupted or does not exist > > dev: pinctrl@14 > > dev: pinctrl@40 > > gpio: pin 88 (gpio 88) value is 1 > > Unknown command 'bcb' - try 'help' > > Warning: BCB is corrupted or does not exist > > Loading Android boot partition... > > switch to partitions #0, OK > > mmc2(part 0) is current device > > """ > > > > I know we should not be using a boot script, nor non A/B configs but > > it's a bummer that this series breaks an upstream > > defconfig (khadas-vim3_android_defconfig) > > > > My recommendation: > > > > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. > > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. > > > > We could do: > > When ANDROID_AB=y, implement bcb ab_select subcommand > > When ANDROID_AB=n, command is not accessible. > > > > I'll send you a diff shortly for this. > > Here is an illustration on how that would work: > > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 861c31e26408..e1a4a97b042d 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -1055,7 +1055,6 @@ config CMD_ADC > config CMD_BCB > bool "bcb" > depends on PARTITIONS > - depends on ANDROID_AB > help > Read/modify/write the fields of Bootloader Control Block, usually > stored on the flash "misc" partition with its structure defined in: > diff --git a/cmd/bcb.c b/cmd/bcb.c > index 4fd32186ae65..4fe634f14cc5 100644 > --- a/cmd/bcb.c > +++ b/cmd/bcb.c > @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, > char slot[2]; > bool dec_tries = true; > > + if (!CONFIG_IS_ENABLED(AB_SELECT)) > + return CMD_RET_SUCCESS; > + > for (int i = 4; i < argc; i++) { > if (!strcmp(argv[i], "--no-dec")) > dec_tries = false; > @@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, > struct blk_desc *dev_desc; > struct disk_partition part_info; > > + if (!CONFIG_IS_ENABLED(AB_SELECT)) > + return CMD_RET_SUCCESS; > + > if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], > &dev_desc, &part_info, > false) < 0) { >
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
I just run build on the my x86 Ubuntu machine.
$ cd uboot $ make mproper $ make sandbox_defconfig $ make -j$(nproc)
I tried these commands: Here is the successfull build output:
https://paste.debian.net/1332378/
I use: $ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* gcc --version gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* ld --version GNU ld version 2.41-37.fc40 Copyright (C) 2023 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
What toolchains do you use?
That's all.
I've already sent the v4 patch with #ifdef. I can prepare the v5 patch using the IS_ENABLED() macro and will aim to send it today.
But I have one question:
Do we really want to display the ab_select and ab_dump subcommands to users if these commands are just stubs? Perhaps we should consider adding #ifdef directives to the subcommand arrays.
That's a valid concern. I don't think we should display the ab_select and ab_dump commands to the users but I still want to have IS_ENABLED wherever possible to keep the code simple.
-- Thank you, Dmitry

On Tue, Oct 15, 2024 at 05:26:37PM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On mar., oct. 15, 2024 at 16:26, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hi Mattijs,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
> On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote: >> On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote: >> >> > Hi Dmitry, >> > >> > Thank you for the patch. >> > >> > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: >> > >> >> 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 ddrokosov@salutedevices.com >> >> --- >> >> MAINTAINERS | 1 - >> >> cmd/Kconfig | 15 +------ >> >> cmd/Makefile | 1 - >> >> cmd/ab_select.c | 66 ------------------------------- >> >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ >> >> configs/am57xx_hs_evm_usb_defconfig | 1 - >> >> configs/khadas-vim3_android_ab_defconfig | 1 - >> >> configs/khadas-vim3l_android_ab_defconfig | 1 - >> >> configs/sandbox64_defconfig | 4 +- >> >> configs/sandbox_defconfig | 4 +- >> >> 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 ++-- >> >> 16 files changed, 85 insertions(+), 104 deletions(-) >> >> >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 >> >> --- a/MAINTAINERS >> >> +++ b/MAINTAINERS >> >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org >> >> 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 >> >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 >> >> --- a/cmd/Kconfig >> >> +++ b/cmd/Kconfig >> >> @@ -1067,6 +1067,7 @@ config CMD_ADC >> >> config CMD_BCB >> >> bool "bcb" >> >> depends on PARTITIONS >> >> + depends on ANDROID_AB >> > >> > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no >> > longer part of that build: >> > >> > $ grep CMD_BCB .config >> > <empty> >> > >> > However, if we look at include/configs/meson64_android.h, we can see >> > that the "bcb" command is not only used for checking the _slot suffix. >> > >> > It's also used for checking the bootloader reason. For example, in >> > BOOTENV_DEV_FASTBOOT, we call: >> > >> > "if bcb test command = bootonce-bootloader; then " \ >> > >> > Since CMD_BCB is no longer part of the .config (due to this dependency), >> > the boot script now shows errors: >> > >> > """ >> > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 >> > >> > Model: Khadas VIM3 >> > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) >> > DRAM: 2 GiB (effective 3.8 GiB) >> > Core: 411 devices, 36 uclasses, devicetree: separate >> > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 >> > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring >> > Reading from MMC(2)... *** Warning - bad CRC, using default environment >> > >> > In: usbkbd,serial >> > Out: vidconsole,serial >> > Err: vidconsole,serial >> > Net: eth0: ethernet@ff3f0000 >> > >> > Hit any key to stop autoboot: 0 >> > Verify GPT: success! >> > Unknown command 'bcb' - try 'help' >> > Warning: BCB is corrupted or does not exist >> > dev: pinctrl@14 >> > dev: pinctrl@40 >> > gpio: pin 88 (gpio 88) value is 1 >> > Unknown command 'bcb' - try 'help' >> > Warning: BCB is corrupted or does not exist >> > Loading Android boot partition... >> > switch to partitions #0, OK >> > mmc2(part 0) is current device >> > """ >> > >> > I know we should not be using a boot script, nor non A/B configs but >> > it's a bummer that this series breaks an upstream >> > defconfig (khadas-vim3_android_defconfig) >> > >> > My recommendation: >> > >> > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. >> > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. >> > >> > We could do: >> > When ANDROID_AB=y, implement bcb ab_select subcommand >> > When ANDROID_AB=n, command is not accessible. >> > >> > I'll send you a diff shortly for this. >> >> Here is an illustration on how that would work: >> >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> index 861c31e26408..e1a4a97b042d 100644 >> --- a/cmd/Kconfig >> +++ b/cmd/Kconfig >> @@ -1055,7 +1055,6 @@ config CMD_ADC >> config CMD_BCB >> bool "bcb" >> depends on PARTITIONS >> - depends on ANDROID_AB >> help >> Read/modify/write the fields of Bootloader Control Block, usually >> stored on the flash "misc" partition with its structure defined in: >> diff --git a/cmd/bcb.c b/cmd/bcb.c >> index 4fd32186ae65..4fe634f14cc5 100644 >> --- a/cmd/bcb.c >> +++ b/cmd/bcb.c >> @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, >> char slot[2]; >> bool dec_tries = true; >> >> + if (!CONFIG_IS_ENABLED(AB_SELECT)) >> + return CMD_RET_SUCCESS; >> + >> for (int i = 4; i < argc; i++) { >> if (!strcmp(argv[i], "--no-dec")) >> dec_tries = false; >> @@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, >> struct blk_desc *dev_desc; >> struct disk_partition part_info; >> >> + if (!CONFIG_IS_ENABLED(AB_SELECT)) >> + return CMD_RET_SUCCESS; >> + >> if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], >> &dev_desc, &part_info, >> false) < 0) { >> > > We also need to include an #ifdef directive for the ab_select_slot() > function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
I just run build on the my x86 Ubuntu machine.
$ cd uboot $ make mproper $ make sandbox_defconfig $ make -j$(nproc)
I tried these commands: Here is the successfull build output:
https://paste.debian.net/1332378/
I use: $ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* gcc --version gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* ld --version GNU ld version 2.41-37.fc40 Copyright (C) 2023 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
What toolchains do you use?
By default, my machine, which I typically use for cross-compilation, has an outdated toolchain version:
$ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ld --version GNU ld (GNU Binutils for Ubuntu) 2.30 Copyright (C) 2018 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
That's all.
I've already sent the v4 patch with #ifdef. I can prepare the v5 patch using the IS_ENABLED() macro and will aim to send it today.
But I have one question:
Do we really want to display the ab_select and ab_dump subcommands to users if these commands are just stubs? Perhaps we should consider adding #ifdef directives to the subcommand arrays.
That's a valid concern. I don't think we should display the ab_select and ab_dump commands to the users but I still want to have IS_ENABLED wherever possible to keep the code simple.

Hi Dmitry,
On mer., oct. 16, 2024 at 17:06, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
[...]
I just run build on the my x86 Ubuntu machine.
$ cd uboot $ make mproper $ make sandbox_defconfig $ make -j$(nproc)
I tried these commands: Here is the successfull build output:
https://paste.debian.net/1332378/
I use: $ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* gcc --version gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ~/work/upstream/u-boot-dfu/ dmitry/ab-dump-v3* ld --version GNU ld version 2.41-37.fc40 Copyright (C) 2023 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
What toolchains do you use?
By default, my machine, which I typically use for cross-compilation, has an outdated toolchain version:
$ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ld --version GNU ld (GNU Binutils for Ubuntu) 2.30 Copyright (C) 2018 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
Thank you for sharing. that looks indeed very old and would explain why we see different results when building sandbox.
According to this commit [1], you should use gcc 13.0.2 at least Would it be possible to update?
[1] https://source.denx.de/u-boot/u-boot/-/commit/11934281526bda3be51783380b55c3...
That's all.
I've already sent the v4 patch with #ifdef. I can prepare the v5 patch using the IS_ENABLED() macro and will aim to send it today.
But I have one question:
Do we really want to display the ab_select and ab_dump subcommands to users if these commands are just stubs? Perhaps we should consider adding #ifdef directives to the subcommand arrays.
That's a valid concern. I don't think we should display the ab_select and ab_dump commands to the users but I still want to have IS_ENABLED wherever possible to keep the code simple.
-- Thank you, Dmitry

Hi Mattijs, Simon,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote:
On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote:
> Hi Dmitry, > > Thank you for the patch. > > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: > >> 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 ddrokosov@salutedevices.com >> --- >> MAINTAINERS | 1 - >> cmd/Kconfig | 15 +------ >> cmd/Makefile | 1 - >> cmd/ab_select.c | 66 ------------------------------- >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ >> configs/am57xx_hs_evm_usb_defconfig | 1 - >> configs/khadas-vim3_android_ab_defconfig | 1 - >> configs/khadas-vim3l_android_ab_defconfig | 1 - >> configs/sandbox64_defconfig | 4 +- >> configs/sandbox_defconfig | 4 +- >> 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 ++-- >> 16 files changed, 85 insertions(+), 104 deletions(-) >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org >> 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 >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 >> --- a/cmd/Kconfig >> +++ b/cmd/Kconfig >> @@ -1067,6 +1067,7 @@ config CMD_ADC >> config CMD_BCB >> bool "bcb" >> depends on PARTITIONS >> + depends on ANDROID_AB > > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no > longer part of that build: > > $ grep CMD_BCB .config > <empty> > > However, if we look at include/configs/meson64_android.h, we can see > that the "bcb" command is not only used for checking the _slot suffix. > > It's also used for checking the bootloader reason. For example, in > BOOTENV_DEV_FASTBOOT, we call: > > "if bcb test command = bootonce-bootloader; then " \ > > Since CMD_BCB is no longer part of the .config (due to this dependency), > the boot script now shows errors: > > """ > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 > > Model: Khadas VIM3 > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) > DRAM: 2 GiB (effective 3.8 GiB) > Core: 411 devices, 36 uclasses, devicetree: separate > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring > Reading from MMC(2)... *** Warning - bad CRC, using default environment > > In: usbkbd,serial > Out: vidconsole,serial > Err: vidconsole,serial > Net: eth0: ethernet@ff3f0000 > > Hit any key to stop autoboot: 0 > Verify GPT: success! > Unknown command 'bcb' - try 'help' > Warning: BCB is corrupted or does not exist > dev: pinctrl@14 > dev: pinctrl@40 > gpio: pin 88 (gpio 88) value is 1 > Unknown command 'bcb' - try 'help' > Warning: BCB is corrupted or does not exist > Loading Android boot partition... > switch to partitions #0, OK > mmc2(part 0) is current device > """ > > I know we should not be using a boot script, nor non A/B configs but > it's a bummer that this series breaks an upstream > defconfig (khadas-vim3_android_defconfig) > > My recommendation: > > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. > > We could do: > When ANDROID_AB=y, implement bcb ab_select subcommand > When ANDROID_AB=n, command is not accessible. > > I'll send you a diff shortly for this.
Here is an illustration on how that would work:
diff --git a/cmd/Kconfig b/cmd/Kconfig index 861c31e26408..e1a4a97b042d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1055,7 +1055,6 @@ config CMD_ADC config CMD_BCB bool "bcb" depends on PARTITIONS
- depends on ANDROID_AB help Read/modify/write the fields of Bootloader Control Block, usually stored on the flash "misc" partition with its structure defined in:
diff --git a/cmd/bcb.c b/cmd/bcb.c index 4fd32186ae65..4fe634f14cc5 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char slot[2]; bool dec_tries = true;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- for (int i = 4; i < argc; i++) { if (!strcmp(argv[i], "--no-dec")) dec_tries = false;
@@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, struct blk_desc *dev_desc; struct disk_partition part_info;
- if (!CONFIG_IS_ENABLED(AB_SELECT))
return CMD_RET_SUCCESS;
- if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], &dev_desc, &part_info, false) < 0) {
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
What do you think if we replace
``` #ifdef CONFIG_ANDROID_AB ```
with
``` #if IS_ENABLED(CONFIG_ANDROID_AB) ```
Like below:
``` git --no-pager diff . diff --git a/cmd/bcb.c b/cmd/bcb.c index a0eff55c2ed4..82ea4f04659b 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -24,7 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE, -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) BCB_CMD_AB_SELECT, BCB_CMD_AB_DUMP, #endif @@ -57,7 +57,7 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) if (!strcmp(cmd, "ab_select")) return BCB_CMD_AB_SELECT; if (!strcmp(cmd, "ab_dump")) @@ -96,7 +96,7 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) case BCB_CMD_AB_SELECT: if (argc != 4 && argc != 5) goto err; @@ -435,7 +435,7 @@ void bcb_reset(void) __bcb_reset(); }
-#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { @@ -504,7 +504,7 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""), -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1, do_bcb_ab_select, "", ""), U_BOOT_CMD_MKENT(ab_dump, CONFIG_SYS_MAXARGS, 1, @@ -549,7 +549,7 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n" -#ifdef CONFIG_ANDROID_AB +#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" ```

Hi Dmitry,
On Tue, 15 Oct 2024 at 08:42, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hi Mattijs, Simon,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote: > On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote: > > > Hi Dmitry, > > > > Thank you for the patch. > > > > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: > > > >> 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 ddrokosov@salutedevices.com > >> --- > >> MAINTAINERS | 1 - > >> cmd/Kconfig | 15 +------ > >> cmd/Makefile | 1 - > >> cmd/ab_select.c | 66 ------------------------------- > >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ > >> configs/am57xx_hs_evm_usb_defconfig | 1 - > >> configs/khadas-vim3_android_ab_defconfig | 1 - > >> configs/khadas-vim3l_android_ab_defconfig | 1 - > >> configs/sandbox64_defconfig | 4 +- > >> configs/sandbox_defconfig | 4 +- > >> 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 ++-- > >> 16 files changed, 85 insertions(+), 104 deletions(-) > >> > >> diff --git a/MAINTAINERS b/MAINTAINERS > >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 > >> --- a/MAINTAINERS > >> +++ b/MAINTAINERS > >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org > >> 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 > >> diff --git a/cmd/Kconfig b/cmd/Kconfig > >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 > >> --- a/cmd/Kconfig > >> +++ b/cmd/Kconfig > >> @@ -1067,6 +1067,7 @@ config CMD_ADC > >> config CMD_BCB > >> bool "bcb" > >> depends on PARTITIONS > >> + depends on ANDROID_AB > > > > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no > > longer part of that build: > > > > $ grep CMD_BCB .config > > <empty> > > > > However, if we look at include/configs/meson64_android.h, we can see > > that the "bcb" command is not only used for checking the _slot suffix. > > > > It's also used for checking the bootloader reason. For example, in > > BOOTENV_DEV_FASTBOOT, we call: > > > > "if bcb test command = bootonce-bootloader; then " \ > > > > Since CMD_BCB is no longer part of the .config (due to this dependency), > > the boot script now shows errors: > > > > """ > > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 > > > > Model: Khadas VIM3 > > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) > > DRAM: 2 GiB (effective 3.8 GiB) > > Core: 411 devices, 36 uclasses, devicetree: separate > > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 > > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring > > Reading from MMC(2)... *** Warning - bad CRC, using default environment > > > > In: usbkbd,serial > > Out: vidconsole,serial > > Err: vidconsole,serial > > Net: eth0: ethernet@ff3f0000 > > > > Hit any key to stop autoboot: 0 > > Verify GPT: success! > > Unknown command 'bcb' - try 'help' > > Warning: BCB is corrupted or does not exist > > dev: pinctrl@14 > > dev: pinctrl@40 > > gpio: pin 88 (gpio 88) value is 1 > > Unknown command 'bcb' - try 'help' > > Warning: BCB is corrupted or does not exist > > Loading Android boot partition... > > switch to partitions #0, OK > > mmc2(part 0) is current device > > """ > > > > I know we should not be using a boot script, nor non A/B configs but > > it's a bummer that this series breaks an upstream > > defconfig (khadas-vim3_android_defconfig) > > > > My recommendation: > > > > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. > > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. > > > > We could do: > > When ANDROID_AB=y, implement bcb ab_select subcommand > > When ANDROID_AB=n, command is not accessible. > > > > I'll send you a diff shortly for this. > > Here is an illustration on how that would work: > > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 861c31e26408..e1a4a97b042d 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -1055,7 +1055,6 @@ config CMD_ADC > config CMD_BCB > bool "bcb" > depends on PARTITIONS > - depends on ANDROID_AB > help > Read/modify/write the fields of Bootloader Control Block, usually > stored on the flash "misc" partition with its structure defined in: > diff --git a/cmd/bcb.c b/cmd/bcb.c > index 4fd32186ae65..4fe634f14cc5 100644 > --- a/cmd/bcb.c > +++ b/cmd/bcb.c > @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, > char slot[2]; > bool dec_tries = true; > > + if (!CONFIG_IS_ENABLED(AB_SELECT)) > + return CMD_RET_SUCCESS; > + > for (int i = 4; i < argc; i++) { > if (!strcmp(argv[i], "--no-dec")) > dec_tries = false; > @@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, > struct blk_desc *dev_desc; > struct disk_partition part_info; > > + if (!CONFIG_IS_ENABLED(AB_SELECT)) > + return CMD_RET_SUCCESS; > + > if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], > &dev_desc, &part_info, > false) < 0) { >
We also need to include an #ifdef directive for the ab_select_slot() function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
What do you think if we replace
#ifdef CONFIG_ANDROID_AB
with
#if IS_ENABLED(CONFIG_ANDROID_AB)
That seems OK to some extent...but see comments:
Like below:
git --no-pager diff . diff --git a/cmd/bcb.c b/cmd/bcb.c index a0eff55c2ed4..82ea4f04659b 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -24,7 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE, -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) BCB_CMD_AB_SELECT, BCB_CMD_AB_DUMP, #endif
We try to avoid this sort of thing, as it makes it impossible to use if() instead of #ifdef(). For the same reason, header files should always be included, not be behind #ifdefs
@@ -57,7 +57,7 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) if (!strcmp(cmd, "ab_select"))
if (IS_ENABLED(CONFIG_ANDROID_AB) && !strcmp(cmd, "ab_select"))
return BCB_CMD_AB_SELECT; if (!strcmp(cmd, "ab_dump"))
@@ -96,7 +96,7 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) case BCB_CMD_AB_SELECT: if (argc != 4 && argc != 5) goto err; @@ -435,7 +435,7 @@ void bcb_reset(void) __bcb_reset(); }
-#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { @@ -504,7 +504,7 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""), -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1, do_bcb_ab_select, "", ""), U_BOOT_CMD_MKENT(ab_dump, CONFIG_SYS_MAXARGS, 1, @@ -549,7 +549,7 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n" -#ifdef CONFIG_ANDROID_AB +#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"
Long help should use U_BOOT_LONGHELP, we normally handle this with #ifdef - see cmd/bootflow.c for example
Regards, Simon

Hi Simon,
On Tue, Oct 15, 2024 at 09:27:14AM -0600, Simon Glass wrote:
Hi Dmitry,
On Tue, 15 Oct 2024 at 08:42, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hi Mattijs, Simon,
On Tue, Oct 15, 2024 at 02:10:10PM +0200, Mattijs Korpershoek wrote:
Hi Simon, Dmitry
On lun., oct. 14, 2024 at 15:06, Simon Glass sjg@chromium.org wrote:
Hi Dmitry,
On Mon, 14 Oct 2024 at 14:38, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
Hello Mattijs,
On Sat, Oct 12, 2024 at 10:49:08AM +0200, Mattijs Korpershoek wrote:
Hi Dmitry,
On ven., oct. 11, 2024 at 21:00, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
> On Fri, Oct 11, 2024 at 04:20:39PM +0200, Mattijs Korpershoek wrote: >> On ven., oct. 11, 2024 at 15:30, "Mattijs Korpershoek via groups.io" mkorpershoek=baylibre.com@groups.io wrote: >> >> > Hi Dmitry, >> > >> > Thank you for the patch. >> > >> > On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov ddrokosov@salutedevices.com wrote: >> > >> >> 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 ddrokosov@salutedevices.com >> >> --- >> >> MAINTAINERS | 1 - >> >> cmd/Kconfig | 15 +------ >> >> cmd/Makefile | 1 - >> >> cmd/ab_select.c | 66 ------------------------------- >> >> cmd/bcb.c | 63 +++++++++++++++++++++++++++++ >> >> configs/am57xx_hs_evm_usb_defconfig | 1 - >> >> configs/khadas-vim3_android_ab_defconfig | 1 - >> >> configs/khadas-vim3l_android_ab_defconfig | 1 - >> >> configs/sandbox64_defconfig | 4 +- >> >> configs/sandbox_defconfig | 4 +- >> >> 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 ++-- >> >> 16 files changed, 85 insertions(+), 104 deletions(-) >> >> >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> >> index 7aefda93d017f07d616f0f6d191129914fbeb484..668ccec9ae6df47192b1af668e3fdbeb1dfa15ea 100644 >> >> --- a/MAINTAINERS >> >> +++ b/MAINTAINERS >> >> @@ -65,7 +65,6 @@ R: Sam Protsenko semen.protsenko@linaro.org >> >> 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 >> >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> >> index dd33266cec70a2b134b7244acae1b7f098b921e8..11e8d363dc9b137723a86a240412d82dd0dbccc5 100644 >> >> --- a/cmd/Kconfig >> >> +++ b/cmd/Kconfig >> >> @@ -1067,6 +1067,7 @@ config CMD_ADC >> >> config CMD_BCB >> >> bool "bcb" >> >> depends on PARTITIONS >> >> + depends on ANDROID_AB >> > >> > When building with khadas-vim3_android_defconfig, we can see that CMD_BCB is no >> > longer part of that build: >> > >> > $ grep CMD_BCB .config >> > <empty> >> > >> > However, if we look at include/configs/meson64_android.h, we can see >> > that the "bcb" command is not only used for checking the _slot suffix. >> > >> > It's also used for checking the bootloader reason. For example, in >> > BOOTENV_DEV_FASTBOOT, we call: >> > >> > "if bcb test command = bootonce-bootloader; then " \ >> > >> > Since CMD_BCB is no longer part of the .config (due to this dependency), >> > the boot script now shows errors: >> > >> > """ >> > U-Boot 2024.10-00796-g969325278805 (Oct 11 2024 - 14:46:00 +0200) khadas-vim3 >> > >> > Model: Khadas VIM3 >> > SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) >> > DRAM: 2 GiB (effective 3.8 GiB) >> > Core: 411 devices, 36 uclasses, devicetree: separate >> > MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2 >> > Loading Environment from MMC... fs uses incompatible features: 00020000, ignoring >> > Reading from MMC(2)... *** Warning - bad CRC, using default environment >> > >> > In: usbkbd,serial >> > Out: vidconsole,serial >> > Err: vidconsole,serial >> > Net: eth0: ethernet@ff3f0000 >> > >> > Hit any key to stop autoboot: 0 >> > Verify GPT: success! >> > Unknown command 'bcb' - try 'help' >> > Warning: BCB is corrupted or does not exist >> > dev: pinctrl@14 >> > dev: pinctrl@40 >> > gpio: pin 88 (gpio 88) value is 1 >> > Unknown command 'bcb' - try 'help' >> > Warning: BCB is corrupted or does not exist >> > Loading Android boot partition... >> > switch to partitions #0, OK >> > mmc2(part 0) is current device >> > """ >> > >> > I know we should not be using a boot script, nor non A/B configs but >> > it's a bummer that this series breaks an upstream >> > defconfig (khadas-vim3_android_defconfig) >> > >> > My recommendation: >> > >> > Make BCB_CMD_AB_SELECT implementation dependant on ANDROID_AB. >> > This way, users can use CMD_BCB with and without ANDROID_AB being enabled. >> > >> > We could do: >> > When ANDROID_AB=y, implement bcb ab_select subcommand >> > When ANDROID_AB=n, command is not accessible. >> > >> > I'll send you a diff shortly for this. >> >> Here is an illustration on how that would work: >> >> diff --git a/cmd/Kconfig b/cmd/Kconfig >> index 861c31e26408..e1a4a97b042d 100644 >> --- a/cmd/Kconfig >> +++ b/cmd/Kconfig >> @@ -1055,7 +1055,6 @@ config CMD_ADC >> config CMD_BCB >> bool "bcb" >> depends on PARTITIONS >> - depends on ANDROID_AB >> help >> Read/modify/write the fields of Bootloader Control Block, usually >> stored on the flash "misc" partition with its structure defined in: >> diff --git a/cmd/bcb.c b/cmd/bcb.c >> index 4fd32186ae65..4fe634f14cc5 100644 >> --- a/cmd/bcb.c >> +++ b/cmd/bcb.c >> @@ -438,6 +438,9 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, >> char slot[2]; >> bool dec_tries = true; >> >> + if (!CONFIG_IS_ENABLED(AB_SELECT)) >> + return CMD_RET_SUCCESS; >> + >> for (int i = 4; i < argc; i++) { >> if (!strcmp(argv[i], "--no-dec")) >> dec_tries = false; >> @@ -474,6 +477,9 @@ static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc, >> struct blk_desc *dev_desc; >> struct disk_partition part_info; >> >> + if (!CONFIG_IS_ENABLED(AB_SELECT)) >> + return CMD_RET_SUCCESS; >> + >> if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2], >> &dev_desc, &part_info, >> false) < 0) { >> > > We also need to include an #ifdef directive for the ab_select_slot() > function usage; otherwise, the code will not compile successfully.
Are you sure? Per my understanding, it's possible that the compiler optimizes this out because CONFIG_IS_ENABLED(AB_SELECT) is known as build time.
When I tried this diff with khadas-vim3_android_defconfig I did not see any build errors. I will try again early next week.
As I recall, the IS_ENABLED() mechanism serves as a runtime checker to determine whether specific CONFIG_* options are enabled. Consequently, all code paths under this mechanism are always compiled. I attempted to disable CONFIG_ANDROID_AB for the sandbox_defconfig, but it resulted in the expected linker error.
/tmp/ccAvYrKL.ltrans25.ltrans.o: In function `do_bcb_ab_select': <artificial>:(.text+0x6d5d): undefined reference to `ab_select_slot' collect2: error: ld returned 1 exit status Makefile:1813: recipe for target 'u-boot' failed make: *** [u-boot] Error 1
I have already prepared a new version using #ifdef directives. I will send it shortly.
Something else is going on here, since we do this all the time and rely on it. So long as the code is behind an if() the dead code should be eliminated.
I have passed my diff (using CONFIG_IS_ENABLED) through the U-Boot CI: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/22700
See the branch: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commits/dmitry/ab-dump...
There are some test errors (sandbox test) but the "world build" stage finished sucessfully.
I have also tested locally using the CI container: $ cd ~/work/upstream/u-boot $ git clean -xdf $ make mproper $ docker run -v $PWD:$PWD -it trini/u-boot-gitlab-ci-runner:jammy-20240227-14Mar2024 /bin/bash
# In container uboot@0ba059e8b7af/$ cd /home/mkorpershoek/work/upstream/u-boot uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ pip install -r test/py/requirements.txt uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./test/py/test.py --bd sandbox --build -k test_ut
No build errors either.
Dmitry, can you clarify what compiler/build commands you've used to see that error?
For reference, here is what buildman has in the CI container:
uboot@0ba059e8b7af:/home/mkorpershoek/work/upstream/u-boot$ ./tools/buildman/buildman --list-tool-chains List of available toolchains (17): aarch64 : /opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc arc : /opt/gcc-13.2.0-nolibc/arc-linux/bin/arc-linux-gcc arm : /opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc c89 : /usr/bin/c89-gcc c99 : /usr/bin/c99-gcc i386 : /opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc m68k : /opt/gcc-13.2.0-nolibc/m68k-linux/bin/m68k-linux-gcc microblaze: /opt/gcc-13.2.0-nolibc/microblaze-linux/bin/microblaze-linux-gcc mips : /opt/gcc-13.2.0-nolibc/mips-linux/bin/mips-linux-gcc nios2 : /opt/gcc-13.2.0-nolibc/nios2-linux/bin/nios2-linux-gcc powerpc : /opt/gcc-13.2.0-nolibc/powerpc-linux/bin/powerpc-linux-gcc riscv32 : /opt/gcc-13.2.0-nolibc/riscv32-linux/bin/riscv32-linux-gcc riscv64 : /opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc sandbox : /usr/bin/cgcc sh2 : /opt/gcc-13.2.0-nolibc/sh2-linux/bin/sh2-linux-gcc x86_64 : /usr/bin/x86_64-linux-gnu-gcc xtensa : /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-gcc
I think we should use CONFIG_IS_ENABLED if possible
What do you think if we replace
#ifdef CONFIG_ANDROID_AB
with
#if IS_ENABLED(CONFIG_ANDROID_AB)
That seems OK to some extent...but see comments:
Like below:
git --no-pager diff . diff --git a/cmd/bcb.c b/cmd/bcb.c index a0eff55c2ed4..82ea4f04659b 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -24,7 +24,7 @@ enum bcb_cmd { BCB_CMD_FIELD_TEST, BCB_CMD_FIELD_DUMP, BCB_CMD_STORE, -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) BCB_CMD_AB_SELECT, BCB_CMD_AB_DUMP, #endif
We try to avoid this sort of thing, as it makes it impossible to use if() instead of #ifdef(). For the same reason, header files should always be included, not be behind #ifdefs
@@ -57,7 +57,7 @@ static int bcb_cmd_get(char *cmd) return BCB_CMD_STORE; if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) if (!strcmp(cmd, "ab_select"))
if (IS_ENABLED(CONFIG_ANDROID_AB) && !strcmp(cmd, "ab_select"))
return BCB_CMD_AB_SELECT; if (!strcmp(cmd, "ab_dump"))
@@ -96,7 +96,7 @@ static int bcb_is_misused(int argc, char *const argv[]) if (argc != 2) goto err; break; -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) case BCB_CMD_AB_SELECT: if (argc != 4 && argc != 5) goto err; @@ -435,7 +435,7 @@ void bcb_reset(void) __bcb_reset(); }
-#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { @@ -504,7 +504,7 @@ static struct cmd_tbl cmd_bcb_sub[] = { 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, "", ""), -#ifdef CONFIG_ANDROID_AB +#if IS_ENABLED(CONFIG_ANDROID_AB) U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1, do_bcb_ab_select, "", ""), U_BOOT_CMD_MKENT(ab_dump, CONFIG_SYS_MAXARGS, 1, @@ -549,7 +549,7 @@ U_BOOT_CMD( "bcb dump <field> - dump BCB <field>\n" "bcb store - store BCB back to <interface>\n" "\n" -#ifdef CONFIG_ANDROID_AB +#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"
Long help should use U_BOOT_LONGHELP, we normally handle this with #ifdef - see cmd/bootflow.c for example
Thank you for pointing me to U_BOOT_LONGHELP. I have redesigned cmd/bcb.c to utilize the U_BOOT_LONGHELP(), U_BOOT_CMD_WITH_SUBCMDS(), and U_BOOT_SUBCMD_MKENT() functions. As a result, a significant amount of command management code has been removed from cmd/bcb.c, making it look much more compact.
To be honest, I think I missed the minargs parameter in U_BOOT_CMD_WITH_SUBCMDS(). Including minargs would enable us to avoid checking argc for a minimum value in the each subcmd callback and returning CMD_RET_USAGE in case of any errors.
Anyway, I will prepare v5 version with refactored cmd/bcb.c to U_BOOT_LONGHELP usage.

Hi Dmitry,
On mer., oct. 16, 2024 at 18:48, Dmitry Rokosov ddrokosov@salutedevices.com wrote:
[...]
Long help should use U_BOOT_LONGHELP, we normally handle this with #ifdef - see cmd/bootflow.c for example
Thank you for pointing me to U_BOOT_LONGHELP. I have redesigned cmd/bcb.c to utilize the U_BOOT_LONGHELP(), U_BOOT_CMD_WITH_SUBCMDS(), and U_BOOT_SUBCMD_MKENT() functions. As a result, a significant amount of command management code has been removed from cmd/bcb.c, making it look much more compact.
To be honest, I think I missed the minargs parameter in U_BOOT_CMD_WITH_SUBCMDS(). Including minargs would enable us to avoid checking argc for a minimum value in the each subcmd callback and returning CMD_RET_USAGE in case of any errors.
Anyway, I will prepare v5 version with refactored cmd/bcb.c to U_BOOT_LONGHELP usage.
Thank you for your patience with all the back and forth on this. Looking forward to v5 !
Cheers Mattijs
-- Thank you, Dmitry
participants (3)
-
Dmitry Rokosov
-
Mattijs Korpershoek
-
Simon Glass