[PATCH v3 0/5] Add support of Android Boot Image version 2 and non-AB image

Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
patchset was tested on khadas VIM3 and VIM3L with AOSP main branch and android-mainline kernel and with TI AM62P with android release provided by TI.
Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- Changes in v3: - Remove gpio recovery stuff not needed anymore. - Link to v2: https://lore.kernel.org/r/20241114-adnroidv2-v2-0-015bffb1373a@baylibre.com
Changes in v2: - Drop patch 3 (configs: khadas-vim3{l}: fix userdata size) already applied - Apply Tested-by and Reviewed-by from v1 - Fix comments - Revert malloc/free for slot_suffix - Remove vim3/vim3l stuff in meson64_android.h - Link to v1: https://lore.kernel.org/r/20241017-adnroidv2-v1-0-781c939902c9@baylibre.com
--- Guillaume La Roque (5): bootstd: android: add support of bootimage v2 bootstd: android: add non-A/B image support configs: khadas-vim3l_android{_ab}: move on bootmeth android configs: khadas-vim3_android{_ab}: move on bootmeth android bootstd: Add test for Android boot image v2
arch/sandbox/dts/test.dts | 10 +++- boot/Kconfig | 1 - boot/bootmeth_android.c | 78 +++++++++++++++++++++---------- configs/am62x_a53_android.config | 1 + configs/khadas-vim3_android_ab_defconfig | 7 ++- configs/khadas-vim3_android_defconfig | 7 ++- configs/khadas-vim3l_android_ab_defconfig | 7 ++- configs/khadas-vim3l_android_defconfig | 7 ++- configs/sandbox_defconfig | 1 + include/configs/khadas-vim3_android.h | 25 ++++++++-- include/configs/khadas-vim3l_android.h | 25 ++++++++-- include/configs/meson64_android.h | 6 --- test/boot/bootflow.c | 29 ++++++++++-- test/py/tests/test_ut.py | 49 +++++++++++++++++++ 14 files changed, 206 insertions(+), 47 deletions(-) --- base-commit: ce427e40a2422b75374ee3404e3f5c6536e8984a change-id: 20241015-adnroidv2-a01dca609707
Best regards,

Android bootmeth only support boot image v3/4.
Add support of Android Boot Image version 2 [1]. Vendor boot image is only supported in version 3 and 4 so don't try to read it when header version is less than 3.
[1] https://source.android.com/docs/core/architecture/bootloader/boot-image-head...
Tested-by: Julien Masson jmasson@baylibre.com Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- boot/bootmeth_android.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c index 19b1f2c377b9..2e7f85e4a708 100644 --- a/boot/bootmeth_android.c +++ b/boot/bootmeth_android.c @@ -259,16 +259,12 @@ static int android_read_bootflow(struct udevice *dev, struct bootflow *bflow) goto free_priv; }
- if (priv->header_version != 4) { - log_debug("only boot.img v4 is supported %u\n", priv->header_version); - ret = -EINVAL; - goto free_priv; - } - - ret = scan_vendor_boot_part(bflow->blk, priv); - if (ret < 0) { - log_debug("scan vendor_boot failed: err=%d\n", ret); - goto free_priv; + if (priv->header_version >= 3) { + ret = scan_vendor_boot_part(bflow->blk, priv); + if (ret < 0) { + log_debug("scan vendor_boot failed: err=%d\n", ret); + goto free_priv; + } }
/* @@ -476,12 +472,13 @@ static int boot_android_normal(struct bootflow *bflow) if (ret < 0) return log_msg_ret("read boot", ret);
- ret = read_slotted_partition(desc, "vendor_boot", priv->slot, vloadaddr); - if (ret < 0) - return log_msg_ret("read vendor_boot", ret); - + if (priv->header_version >= 3) { + ret = read_slotted_partition(desc, "vendor_boot", priv->slot, vloadaddr); + if (ret < 0) + return log_msg_ret("read vendor_boot", ret); + set_avendor_bootimg_addr(vloadaddr); + } set_abootimg_addr(loadaddr); - set_avendor_bootimg_addr(vloadaddr);
ret = bootm_boot_start(loadaddr, bflow->cmdline);

Update android bootmeth to support non-A/B image. Enable AB support only when ANDROID_AB is enabled.
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- boot/Kconfig | 1 - boot/bootmeth_android.c | 51 +++++++++++++++++++++++++++++++++------- configs/am62x_a53_android.config | 1 + configs/sandbox_defconfig | 1 + 4 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/boot/Kconfig b/boot/Kconfig index 7dd30a030e39..661e89ca05b2 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -500,7 +500,6 @@ config BOOTMETH_ANDROID bool "Bootdev support for Android" depends on X86 || ARM || SANDBOX depends on CMDLINE - select ANDROID_AB select ANDROID_BOOT_IMAGE select CMD_BCB imply CMD_FASTBOOT diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c index 2e7f85e4a708..2aac32331d3c 100644 --- a/boot/bootmeth_android.c +++ b/boot/bootmeth_android.c @@ -29,6 +29,7 @@ #define BCB_PART_NAME "misc" #define BOOT_PART_NAME "boot" #define VENDOR_BOOT_PART_NAME "vendor_boot" +#define SLOT_LEN 2
/** * struct android_priv - Private data @@ -42,7 +43,7 @@ */ struct android_priv { enum android_boot_mode boot_mode; - char slot[2]; + char *slot; u32 header_version; };
@@ -71,7 +72,11 @@ static int scan_boot_part(struct udevice *blk, struct android_priv *priv) char *buf; int ret;
- sprintf(partname, BOOT_PART_NAME "_%s", priv->slot); + if (priv->slot) + sprintf(partname, BOOT_PART_NAME "_%s", priv->slot); + else + sprintf(partname, BOOT_PART_NAME); + ret = part_get_info_by_name(desc, partname, &partition); if (ret < 0) return log_msg_ret("part info", ret); @@ -108,7 +113,11 @@ static int scan_vendor_boot_part(struct udevice *blk, struct android_priv *priv) char *buf; int ret;
- sprintf(partname, VENDOR_BOOT_PART_NAME "_%s", priv->slot); + if (priv->slot) + sprintf(partname, VENDOR_BOOT_PART_NAME "_%s", priv->slot); + else + sprintf(partname, VENDOR_BOOT_PART_NAME); + ret = part_get_info_by_name(desc, partname, &partition); if (ret < 0) return log_msg_ret("part info", ret); @@ -142,6 +151,11 @@ static int android_read_slot_from_bcb(struct bootflow *bflow, bool decrement) char slot_suffix[3]; int ret;
+ if (!CONFIG_IS_ENABLED(ANDROID_AB)) { + priv->slot = NULL; + return 0; + } + ret = part_get_info_by_name(desc, BCB_PART_NAME, &misc); if (ret < 0) return log_msg_ret("part", ret); @@ -150,6 +164,7 @@ static int android_read_slot_from_bcb(struct bootflow *bflow, bool decrement) if (ret < 0) return log_msg_ret("slot", ret);
+ priv->slot = malloc(SLOT_LEN); priv->slot[0] = BOOT_SLOT_NAME(ret); priv->slot[1] = '\0';
@@ -274,7 +289,7 @@ static int android_read_bootflow(struct udevice *dev, struct bootflow *bflow) configure_serialno(bflow); configure_bootloader_version(bflow);
- if (priv->boot_mode == ANDROID_BOOT_MODE_NORMAL) { + if (priv->boot_mode == ANDROID_BOOT_MODE_NORMAL && priv->slot) { ret = bootflow_cmdline_set_arg(bflow, "androidboot.force_normal_boot", "1", false); if (ret < 0) { @@ -323,14 +338,28 @@ static int read_slotted_partition(struct blk_desc *desc, const char *const name, { struct disk_partition partition; char partname[PART_NAME_LEN]; + size_t partname_len; int ret; u32 n;
- /* Ensure name fits in partname it should be: <name>_<slot>\0 */ - if (strlen(name) > (PART_NAME_LEN - 2 - 1)) + /* + * Ensure name fits in partname. + * For A/B, it should be <name>_<slot>\0 + * For non A/B, it should be <name>\0 + */ + if (CONFIG_IS_ENABLED(ANDROID_AB)) + partname_len = PART_NAME_LEN - 2 - 1; + else + partname_len = PART_NAME_LEN - 1; + + if (strlen(name) > partname_len) return log_msg_ret("name too long", -EINVAL);
- sprintf(partname, "%s_%s", name, slot); + if (slot) + sprintf(partname, "%s_%s", name, slot); + else + sprintf(partname, "%s", name); + ret = part_get_info_by_name(desc, partname, &partition); if (ret < 0) return log_msg_ret("part", ret); @@ -382,7 +411,7 @@ static int run_avb_verification(struct bootflow *bflow) AvbSlotVerifyData *out_data; enum avb_boot_state boot_state; char *extra_args; - char slot_suffix[3]; + char slot_suffix[3] = ""; bool unlocked = false; int ret;
@@ -390,7 +419,8 @@ static int run_avb_verification(struct bootflow *bflow) if (!avb_ops) return log_msg_ret("avb ops", -ENOMEM);
- sprintf(slot_suffix, "_%s", priv->slot); + if (priv->slot) + sprintf(slot_suffix, "_%s", priv->slot);
ret = avb_ops->read_is_device_unlocked(avb_ops, &unlocked); if (ret != AVB_IO_RESULT_OK) @@ -480,6 +510,9 @@ static int boot_android_normal(struct bootflow *bflow) } set_abootimg_addr(loadaddr);
+ if (priv->slot) + free(priv->slot); + ret = bootm_boot_start(loadaddr, bflow->cmdline);
return log_msg_ret("boot", ret); diff --git a/configs/am62x_a53_android.config b/configs/am62x_a53_android.config index adbe2b8e126f..2aca51e3a107 100644 --- a/configs/am62x_a53_android.config +++ b/configs/am62x_a53_android.config @@ -11,6 +11,7 @@ CONFIG_RANDOM_UUID=y # Needed for FASTBOOT_CMD_OEM_FORMAT CONFIG_FASTBOOT_CMD_OEM_FORMAT=y # Enable Android boot flow CONFIG_BOOTMETH_ANDROID=y +CONFIG_ANDROID_AB=y CONFIG_SYS_BOOTM_LEN=0x4000000 CONFIG_SYS_MALLOC_LEN=0x08000000 CONFIG_AVB_VERIFY=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index d111858082d5..6b8dedf20712 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -50,6 +50,7 @@ CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_LOGF_FUNC=y CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_STACKPROTECTOR=y +CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_SMBIOS=y

Actually khadas vim3l use distro command to boot android image. Move on new bootmeth android for A/B and non-A/B vim3l android.
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Acked-by: Neil Armstrong neil.armstrong@linaro.org Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- configs/khadas-vim3l_android_ab_defconfig | 7 ++++++- configs/khadas-vim3l_android_defconfig | 7 ++++++- include/configs/khadas-vim3l_android.h | 25 +++++++++++++++++++++---- include/configs/meson64_android.h | 3 --- 4 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/configs/khadas-vim3l_android_ab_defconfig b/configs/khadas-vim3l_android_ab_defconfig index 4d7b90f23002..43db61056baf 100644 --- a/configs/khadas-vim3l_android_ab_defconfig +++ b/configs/khadas-vim3l_android_ab_defconfig @@ -24,6 +24,12 @@ CONFIG_REMAKE_ELF=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_BOOTMETH_ANDROID=y +# CONFIG_BOOTMETH_EXTLINUX is not set +# CONFIG_BOOTMETH_EXTLINUX_PXE is not set +# CONFIG_BOOTMETH_EFILOADER is not set +# CONFIG_BOOTMETH_EFI_BOOTMGR is not set +# CONFIG_BOOTMETH_VBE is not set CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_OF_BOARD_SETUP=y # CONFIG_DISPLAY_CPUINFO is not set @@ -35,7 +41,6 @@ CONFIG_SYS_MAXARGS=32 CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_IMI is not set -CONFIG_CMD_BCB=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y diff --git a/configs/khadas-vim3l_android_defconfig b/configs/khadas-vim3l_android_defconfig index 4ec27262cdc7..32d57a5b9090 100644 --- a/configs/khadas-vim3l_android_defconfig +++ b/configs/khadas-vim3l_android_defconfig @@ -24,6 +24,12 @@ CONFIG_REMAKE_ELF=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_BOOTMETH_ANDROID=y +# CONFIG_BOOTMETH_EXTLINUX is not set +# CONFIG_BOOTMETH_EXTLINUX_PXE is not set +# CONFIG_BOOTMETH_EFILOADER is not set +# CONFIG_BOOTMETH_EFI_BOOTMGR is not set +# CONFIG_BOOTMETH_VBE is not set CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_OF_BOARD_SETUP=y # CONFIG_DISPLAY_CPUINFO is not set @@ -34,7 +40,6 @@ CONFIG_SYS_MAXARGS=32 CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_IMI is not set -CONFIG_CMD_BCB=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y diff --git a/include/configs/khadas-vim3l_android.h b/include/configs/khadas-vim3l_android.h index f39a3782d663..1869249e7c9e 100644 --- a/include/configs/khadas-vim3l_android.h +++ b/include/configs/khadas-vim3l_android.h @@ -41,10 +41,27 @@ "name=rootfs,size=-,uuid=" ROOT_UUID #endif
-#define EXTRA_ANDROID_ENV_SETTINGS \ - "board=vim3l\0" \ - "board_name=vim3l\0" \ +#define CFG_EXTRA_ENV_SETTINGS \ + "board=vim3l\0" \ + "board_name=vim3l\0" \ + "bootmeths=android\0" \ + "bootcmd=bootflow scan\0" \ + "adtb_idx=2\0" \ + "partitions=" PARTS_DEFAULT "\0" \ + "mmcdev=2\0" \ + "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \ + "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \ + "stdin=" STDIN_CFG "\0" \ + "stdout=" STDOUT_CFG "\0" \ + "stderr=" STDOUT_CFG "\0" \ + "dtboaddr=0x08200000\0" \ + "loadaddr=0x01080000\0" \ + "fdt_addr_r=0x01000000\0" \ + "scriptaddr=0x08000000\0" \ + "kernel_addr_r=0x01080000\0" \ + "pxefile_addr_r=0x01080000\0" \ + "ramdisk_addr_r=0x13000000\0" \
-#include <configs/meson64_android.h> +#include <configs/meson64.h>
#endif /* __CONFIG_H */ diff --git a/include/configs/meson64_android.h b/include/configs/meson64_android.h index 77364bbf9cf0..37ef8b8f7a7e 100644 --- a/include/configs/meson64_android.h +++ b/include/configs/meson64_android.h @@ -104,9 +104,6 @@ "elif test $board_name = sei610; then " \ "echo " Reading DTB for sei610..."; " \ "setenv dtb_index 1;" \ - "elif test $board_name = vim3l; then " \ - "echo " Reading DTB for vim3l..."; " \ - "setenv dtb_index 2;" \ "elif test $board_name = vim3; then " \ "echo " Reading DTB for vim3..."; " \ "setenv dtb_index 3;" \

Actually khadas vim3 use distro command to boot android image. Move on new bootmeth android for A/B and non-A/B vim3 android.
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Acked-by: Neil Armstrong neil.armstrong@linaro.org Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- configs/khadas-vim3_android_ab_defconfig | 7 ++++++- configs/khadas-vim3_android_defconfig | 7 ++++++- include/configs/khadas-vim3_android.h | 25 +++++++++++++++++++++---- include/configs/meson64_android.h | 3 --- 4 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/configs/khadas-vim3_android_ab_defconfig b/configs/khadas-vim3_android_ab_defconfig index de5357c45cbf..a078c5d363ae 100644 --- a/configs/khadas-vim3_android_ab_defconfig +++ b/configs/khadas-vim3_android_ab_defconfig @@ -24,6 +24,12 @@ CONFIG_REMAKE_ELF=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_BOOTMETH_ANDROID=y +# CONFIG_BOOTMETH_EXTLINUX is not set +# CONFIG_BOOTMETH_EXTLINUX_PXE is not set +# CONFIG_BOOTMETH_EFILOADER is not set +# CONFIG_BOOTMETH_EFI_BOOTMGR is not set +# CONFIG_BOOTMETH_VBE is not set CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_OF_BOARD_SETUP=y # CONFIG_DISPLAY_CPUINFO is not set @@ -35,7 +41,6 @@ CONFIG_SYS_MAXARGS=32 CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_IMI is not set -CONFIG_CMD_BCB=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y diff --git a/configs/khadas-vim3_android_defconfig b/configs/khadas-vim3_android_defconfig index a0d9c423c3c3..b77a44ce859b 100644 --- a/configs/khadas-vim3_android_defconfig +++ b/configs/khadas-vim3_android_defconfig @@ -24,6 +24,12 @@ CONFIG_REMAKE_ELF=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_BOOTMETH_ANDROID=y +# CONFIG_BOOTMETH_EXTLINUX is not set +# CONFIG_BOOTMETH_EXTLINUX_PXE is not set +# CONFIG_BOOTMETH_EFILOADER is not set +# CONFIG_BOOTMETH_EFI_BOOTMGR is not set +# CONFIG_BOOTMETH_VBE is not set CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_OF_BOARD_SETUP=y # CONFIG_DISPLAY_CPUINFO is not set @@ -34,7 +40,6 @@ CONFIG_SYS_MAXARGS=32 CONFIG_CMD_ADTIMG=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_IMI is not set -CONFIG_CMD_BCB=y CONFIG_CMD_GPIO=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y diff --git a/include/configs/khadas-vim3_android.h b/include/configs/khadas-vim3_android.h index 0e2953fe71b3..551ab51c8813 100644 --- a/include/configs/khadas-vim3_android.h +++ b/include/configs/khadas-vim3_android.h @@ -41,10 +41,27 @@ "name=rootfs,size=-,uuid=" ROOT_UUID #endif
-#define EXTRA_ANDROID_ENV_SETTINGS \ - "board=vim3\0" \ - "board_name=vim3\0" \ +#define CFG_EXTRA_ENV_SETTINGS \ + "board=vim3\0" \ + "board_name=vim3\0" \ + "bootmeths=android\0" \ + "bootcmd=bootflow scan\0" \ + "adtb_idx=3\0" \ + "partitions=" PARTS_DEFAULT "\0" \ + "mmcdev=2\0" \ + "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \ + "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \ + "stdin=" STDIN_CFG "\0" \ + "stdout=" STDOUT_CFG "\0" \ + "stderr=" STDOUT_CFG "\0" \ + "dtboaddr=0x08200000\0" \ + "loadaddr=0x01080000\0" \ + "fdt_addr_r=0x01000000\0" \ + "scriptaddr=0x08000000\0" \ + "kernel_addr_r=0x01080000\0" \ + "pxefile_addr_r=0x01080000\0" \ + "ramdisk_addr_r=0x13000000\0" \
-#include <configs/meson64_android.h> +#include <configs/meson64.h>
#endif /* __CONFIG_H */ diff --git a/include/configs/meson64_android.h b/include/configs/meson64_android.h index 37ef8b8f7a7e..d6ef0a83a686 100644 --- a/include/configs/meson64_android.h +++ b/include/configs/meson64_android.h @@ -104,9 +104,6 @@ "elif test $board_name = sei610; then " \ "echo " Reading DTB for sei610..."; " \ "setenv dtb_index 1;" \ - "elif test $board_name = vim3; then " \ - "echo " Reading DTB for vim3..."; " \ - "setenv dtb_index 3;" \ "else " \ "echo Error: Android boot is not supported for $board_name; " \ "exit; " \

Rename actual android bootmethod test to specify it's for boot image version 4. Add a unit test for testing the Android bootmethod with boot image version 2.
This requires another mmc image (mmc8) to contain the following partitions: - misc: contains the Bootloader Control Block (BCB) - boot_a: contains a fake generic kernel image
we can test this with:
$ ./test/py/test.py --bd sandbox --build -k test_ut # build the mmc8.img $ ./test/py/test.py --bd sandbox --build -k bootflow_android
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com Signed-off-by: Guillaume La Roque glaroque@baylibre.com --- arch/sandbox/dts/test.dts | 10 +++++++++- test/boot/bootflow.c | 29 +++++++++++++++++++++++++--- test/py/tests/test_ut.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index dee280184b1b..36cfbf213e4c 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -44,6 +44,7 @@ mmc5 = "/mmc5"; mmc6 = "/mmc6"; mmc7 = "/mmc7"; + mmc8 = "/mmc8"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2; @@ -1138,13 +1139,20 @@ filename = "mmc6.img"; };
- /* This is used for Android tests */ + /* This is used for Android boot image v4 tests */ mmc7 { status = "disabled"; compatible = "sandbox,mmc"; filename = "mmc7.img"; };
+ /* This is used for Android boot image v2 tests. */ + mmc8 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc8.img"; + }; + pch { compatible = "sandbox,pch"; }; diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 9397328609d0..60649886402c 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1199,8 +1199,8 @@ static int bootflow_cros(struct unit_test_state *uts) } BOOTSTD_TEST(bootflow_cros, UTF_CONSOLE);
-/* Test Android bootmeth */ -static int bootflow_android(struct unit_test_state *uts) +/* Test Android bootmeth with boot image version 4 */ +static int bootflow_android_image_v4(struct unit_test_state *uts) { if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID)) return -EAGAIN; @@ -1220,7 +1220,30 @@ static int bootflow_android(struct unit_test_state *uts)
return 0; } -BOOTSTD_TEST(bootflow_android, UTF_CONSOLE); +BOOTSTD_TEST(bootflow_android_image_v4, UTF_CONSOLE); + +/* Test Android bootmeth with boot image version 2 */ +static int bootflow_android_image_v2(struct unit_test_state *uts) +{ + if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID)) + return -EAGAIN; + + ut_assertok(scan_mmc_android_bootdev(uts, "mmc8")); + ut_assertok(run_command("bootflow list", 0)); + + ut_assert_nextlinen("Showing all"); + ut_assert_nextlinen("Seq"); + ut_assert_nextlinen("---"); + ut_assert_nextlinen(" 0 extlinux"); + ut_assert_nextlinen(" 1 android ready mmc 0 mmc8.bootdev.whole "); + ut_assert_nextlinen("---"); + ut_assert_skip_to_line("(2 bootflows, 2 valid)"); + + ut_assert_console_end(); + + return 0; +} +BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE);
/* Test EFI bootmeth */ static int bootflow_efi(struct unit_test_state *uts) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 6d44191976bb..7a0bde4da256 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -501,6 +501,55 @@ def setup_android_image(cons):
print(f'wrote to {fname}')
+ mmc_dev = 8 + fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img') + u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M') + u_boot_utils.run_and_log(cons, f'cgpt create {fname}') + + ptr = 40 + + # Number of sectors in 1MB + sect_size = 512 + sect_1mb = (1 << 20) // sect_size + + required_parts = [ + {'num': 1, 'label':'misc', 'size': '1M'}, + {'num': 2, 'label':'boot_a', 'size': '4M'}, + {'num': 3, 'label':'boot_b', 'size': '4M'}, + ] + + for part in required_parts: + size_str = part['size'] + if 'M' in size_str: + size = int(size_str[:-1]) * sect_1mb + else: + size = int(size_str) + u_boot_utils.run_and_log( + cons, + f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") + ptr += size + + u_boot_utils.run_and_log(cons, f'cgpt boot -p {fname}') + out = u_boot_utils.run_and_log(cons, f'cgpt show -q {fname}') + + # Create a dict (indexed by partition number) containing the above info + for line in out.splitlines(): + start, size, num, name = line.split(maxsplit=3) + parts[int(num)] = Partition(int(start), int(size), name) + + with open(fname, 'rb') as inf: + disk_data = inf.read() + + test_abootimg.AbootimgTestDiskImage(cons, 'boot.img', test_abootimg.img_hex) + boot_img = os.path.join(cons.config.result_dir, 'boot.img') + with open(boot_img, 'rb') as inf: + set_part_data(2, inf.read()) + + with open(fname, 'wb') as outf: + outf.write(disk_data) + + print(f'wrote to {fname}') + return fname
def setup_cedit_file(cons):

Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
-- Mattijs

Hi Guillaume,
On mar., nov. 19, 2024 at 15:16, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
CI has found some issues when applying these series: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23452
Could you have a look please?
Thanks!
-- Mattijs

Hi,
Le 19/11/2024 à 18:21, Mattijs Korpershoek a écrit :
Hi Guillaume,
On mar., nov. 19, 2024 at 15:16, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
CI has found some issues when applying these series: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23452
Could you have a look please?
i will check
Thanks!
-- Mattijs

Hi,
unfortunately i don't find for now how i can fix issue in test.
i don't really understand with when we launch test individually it's working but if we launch test_ut test not working , I see on android test for image version 4 to mmc7 in bootflow list detected.
=> ut bootstd bootflow_android_image_v4 Test: bootflow_android_image_v4: bootflow.c scan_mmc_android_bootdev: mmc7 order 0: mmc2 order 1: mmc1 order 2: mmc7 order 3: <NULL> Enabled mmc mmc7 bootdev ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 Older order: mmc2 Showing all bootflows Seq Method State Uclass Part Name Filename --- ----------- ------ -------- ---- ------------------------ ---------------- 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf 1 android ready mmc 0 mmc7.bootdev.whole 2 android ready mmc 0 mmc7.bootdev.whole --- ----------- ------ -------- ---- ------------------------ ---------------- (3 bootflows, 3 valid)
if we just launch bootflow_android_image_v4 we have only a mmc7.bootdev.whole and so test is ok.
if someone have an idea or can give some idea of what i can try or check .
thanks for helping.
Guillaume Le 20/11/2024 à 13:56, Guillaume LA ROQUE a écrit :
Hi,
Le 19/11/2024 à 18:21, Mattijs Korpershoek a écrit :
Hi Guillaume,
On mar., nov. 19, 2024 at 15:16, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
CI has found some issues when applying these series: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23452
Could you have a look please?
i will check
Thanks!
-- Mattijs

Hi Guillaume,
On mer., nov. 20, 2024 at 18:54, Guillaume LA ROQUE glaroque@baylibre.com wrote:
Hi,
unfortunately i don't find for now how i can fix issue in test.
i don't really understand with when we launch test individually it's working but if we launch test_ut test not working , I see on android test for image version 4 to mmc7 in bootflow list detected.
=> ut bootstd bootflow_android_image_v4 Test: bootflow_android_image_v4: bootflow.c scan_mmc_android_bootdev: mmc7 order 0: mmc2 order 1: mmc1 order 2: mmc7 order 3: <NULL> Enabled mmc mmc7 bootdev ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 Older order: mmc2 Showing all bootflows Seq Method State Uclass Part Name Filename
--- ----------- ------ -------- ---- ------------------------
0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf 1 android ready mmc 0 mmc7.bootdev.whole 2 android ready mmc 0 mmc7.bootdev.whole
--- ----------- ------ -------- ---- ------------------------
(3 bootflows, 3 valid)
if we just launch bootflow_android_image_v4 we have only a mmc7.bootdev.whole and so test is ok.
if someone have an idea or can give some idea of what i can try or check .
thanks for helping.
I'll have a look
Guillaume Le 20/11/2024 à 13:56, Guillaume LA ROQUE a écrit :
Hi,
Le 19/11/2024 à 18:21, Mattijs Korpershoek a écrit :
Hi Guillaume,
On mar., nov. 19, 2024 at 15:16, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
CI has found some issues when applying these series: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23452
Could you have a look please?
i will check
Thanks!
-- Mattijs

Hi,
On jeu., nov. 21, 2024 at 10:40, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi Guillaume,
On mer., nov. 20, 2024 at 18:54, Guillaume LA ROQUE glaroque@baylibre.com wrote:
Hi,
unfortunately i don't find for now how i can fix issue in test.
i don't really understand with when we launch test individually it's working but if we launch test_ut test not working , I see on android test for image version 4 to mmc7 in bootflow list detected.
=> ut bootstd bootflow_android_image_v4 Test: bootflow_android_image_v4: bootflow.c scan_mmc_android_bootdev: mmc7 order 0: mmc2 order 1: mmc1 order 2: mmc7 order 3: <NULL> Enabled mmc mmc7 bootdev ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 ab_select_slot() ANDROID: Attempting slot a, tries remaining 7 Older order: mmc2 Showing all bootflows Seq Method State Uclass Part Name Filename
--- ----------- ------ -------- ---- ------------------------
0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf 1 android ready mmc 0 mmc7.bootdev.whole 2 android ready mmc 0 mmc7.bootdev.whole
--- ----------- ------ -------- ---- ------------------------
(3 bootflows, 3 valid)
if we just launch bootflow_android_image_v4 we have only a mmc7.bootdev.whole and so test is ok.
if someone have an idea or can give some idea of what i can try or check .
thanks for helping.
I'll have a look
The following command fails: $ ./test/py/test.py --bd sandbox --build -k test_ut
Running both test at the same time fails as well: $ ./test/py/test.py --bd sandbox --build -k bootflow_android_image_v
However, running individually, no issues are observed: $ ./test/py/test.py --bd sandbox --build -k bootflow_android_image_v4 $ ./test/py/test.py --bd sandbox --build -k bootflow_android_image_v2
Going back to look at the v1 series [1], the tests were working fine.
If we use the following base (from [1]), it works fine: commit 9e1cd2f2cb86 ("Merge https://source.denx.de/u-boot/custodians/u-boot-usb")
However, the don't when using this base: commit b7d4c80fce44 ("Merge tag 'efi-next-2024-11-18' of https://source.denx.de/u-boot/custodians/u-boot-efi into next")
I've bisected the issue and I've found that the following patch from Simon causes the issue: commit fbdac8155c89 ("test: Expand implementation of ut_list_has_dm_tests()")
Reverting the above patch fixes the problem when running with: $ ./test/py/test.py --bd sandbox --build -k test_ut
However, I don't understand why Simon's patch causes a duplicate mmc7 dev to be mounted.
I will continue the investigation.
[1] https://lore.kernel.org/all/20241017-adnroidv2-v1-0-781c939902c9@baylibre.co...
Guillaume Le 20/11/2024 à 13:56, Guillaume LA ROQUE a écrit :
Hi,
Le 19/11/2024 à 18:21, Mattijs Korpershoek a écrit :
Hi Guillaume,
On mar., nov. 19, 2024 at 15:16, Mattijs Korpershoek mkorpershoek@baylibre.com wrote:
Hi,
On Tue, 19 Nov 2024 12:37:37 +0100, Guillaume La Roque wrote:
Actually bootmethod android only support android boot image version 4 and with AB image, some old platform wtill use android boot image version 2 with AB or without AB slot.
This patchset add support of both version 2 and non-AB slot images. It's fixed in same time a boot issue seen on khadas vim3{l} board with 16GB eMMC
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/5] bootstd: android: add support of bootimage v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/dbe7eee992e90bb... [2/5] bootstd: android: add non-A/B image support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a85f2e0e7bd3665... [3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/88547773b2df5e4... [4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4a2e58717f2f33e... [5/5] bootstd: Add test for Android boot image v2 https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/acaa7f35a33146f...
CI has found some issues when applying these series: https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23452
Could you have a look please?
i will check
Thanks!
-- Mattijs
participants (3)
-
Guillaume LA ROQUE
-
Guillaume La Roque
-
Mattijs Korpershoek