[PATCH 2/3] arm: meson: sm: get rid of SM_CHIP_ID_SIZE
SM_CHIP_ID_SIZE is used nowhere. Moreover, it specifies wrong chip_id size: Amlogic chip_id v1 and v2 is always 16 bytes long. Signed-off-by: Evgeny Bachinin <EABachinin@...> --- arch/arm/mach-meson/sm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c index 4d9f83d3b38d54e20d7d2bec997793cca5d7f0e4..43a259d695b058361445d7ef7047353b3afd5419 100644 --- a/arch/arm/mach-meson/sm.c +++ b/arch/arm/mach-meson/sm.c @@ -78,7 +78,6 @@ ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size) #define SM_CHIP_ID_LENGTH 119 #define SM_CHIP_ID_OFFSET 4 -#define SM_CHIP_ID_SIZE 12 int meson_sm_get_serial(void *buffer, size_t size) { -- 2.34.1
|
[PATCH 3/3] arch: arm: meson: support Amlogic chip_id v1 and v2
Patch introduces: * chip_id API - useful for various things, but used now for device_id (did) generation as mentioned in [1] on our private board code. Our device_id is calculated by means of permutations of chip_id value. * new SoCs (a1, s4, etc) are usually coming with the support of chip_id v2 right away, whereas secure monitors on old SoCs (like axg, g12b, g12a, etc) may support only chip_id v1. Chip_id API handles both cases * meson_sm_get_serial() is described via chip_id API. Links: [1] https://lore.kernel.org/linux-arm-kernel/202311242104.RjBPI3uI-lkp@.../T/#m630fbeea6a6e7d531290b5c0af205af4fb979757 Signed-off-by: Viacheslav Bocharov <adeep@...> Co-developed-by: Arseniy Krasnov <avkrasnov@...> Signed-off-by: Arseniy Krasnov <avkrasnov@...> Signed-off-by: Evgeny Bachinin <EABachinin@...> --- === Theory and research 1) Amlogic efuse data layout. Layout differs for old (axg, g12a, g12b) and new (a1, s4) SoCs. efuse layout for old SoCs +----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | +----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |0x0 | Ver | Serial (12 bytes) *(1) | +----+---------------+-----------------------------------------------+ |0x10| < ... Another data ... > | +----+---------------------------------------------------------------+ NOTES: *(1) - in U-Boot & Linux upstream is known as "serial". See [1] efuse layout for new SoCs +----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | +----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |0x0 | Ver | cpu_id | Serial... | +----+---------------+---------------+-------------------------------+ |0x10| ...(12 bytes) | < ... Another data ... > | +----+---------------+-----------------------------------------------+ 2) About Amlogic chip_id V1 & V2 in Amlogic U-Boot Briefly, some statements and observations: a) v1 & v2 are 16 bytes in size b) v1 format: { cpu_id | serial (12b) } * Old SoCs (axg, g12a, g12b, etc): * cpu_id = value, read from reg (aka socinfo) * serial - 12 unique bytes from efuse. (Before arriving to the client their order is reversed to little-endian) * New SoCs (a1, s4, etc): * cpu_id = 0; * serial = {8 unique bytes from efuse | cpu_id (reversed order)} (Before arriving to client their order is reversed) c) v2 format: { 16 bytes from efuse } * For old & new SoCs: { 16 bytes from efuse } = = { cpu_id | serial (12b, little-endian) } (They come from eFUSE in the correct order right away) d) Old SoCs: chip_id V1 == V2 e) New SoCs: chip_id V1 != V2 (due to (b)) f) New SoCs are coming with chip_id V2 support right away. g) Due to (f), final format/layout of chip_id V1 & V2 can be considered the same. 3) Experimental data from Amlogic U-Boot. * AXG ver 2: ``` [in-efuse view]: 02 00 00 00 25 0C 43 00 C0 22 B6 54 74 79 FA 18 6E 0D 43 86 ver | cpu_id | 12 bytes of unique data in | | | little-endian: efuse_chip_id[0:11] | [chip_id]: 16 bytes (same as ver.1) 25 0C 43 00 C0 22 B6 54 74 79 FA 18 6E 0D 43 86 ``` * AXG ver 1: ``` [in-efuse view]: 01 00 00 00 86 43 0D 6E 18 FA 79 74 54 B6 22 C0 00 00 00 00 ver | 12 bytes of unique data in | | big-endian: efuse_chip_id[11:0] | [chip_id]: 16 bytes 25 0C 43 00 C0 22 B6 54 74 79 FA 18 6E 0D 43 86 cpu_id from | 12 bytes of unique data in | register | little-endian: efuse_chip_id[0:11] | ``` * A1 ver 2: ``` [in-efuse view]: 02 00 00 00 2C 0A 01 0A 01 44 18 00 00 06 39 36 32 41 34 50 ver | cpu_id | 12 bytes of unique data in | | | little-endian: efuse_chip_id[0:11] | [chip_id]: 2C 0A 01 0A 01 44 18 00 00 06 39 36 32 41 34 50 ``` * A1 ver 1: ``` [in-efuse view]: 01 00 00 00 2C 0A 01 0A 50 34 41 32 36 39 06 00 00 00 00 00 ver | cpu_id | 8b of unique data in | | | big-endian: | | | efuse_chip_id[11:0] | [chip_id]: 00 00 00 00 00 06 39 36 32 41 34 50 0A 01 0A 2C *(1) buff[0] = 0 | 8b of unique data in | cpu_id | | little-endian: | | | efuse_chip_id[0:11] | | NOTES: *(1) - for details see [2] ``` Links: [1] https://lore
|
[PATCH v1] arch: meson: sm: add retrieve SoC chipid
2
From: Nikita Maslo <nam@...> The Amlogic Meson SoC Secure Monitor implements a call to retrieve an unique SoC ID starting from the GX Family and all new families. But GX-family chips (e.g. GXB, GXL and newer) supports also 128-bit chip ID. 128-bit chip ID consists 32-bit SoC version and 96-bit OTP data. Add new subcommand "chipid" to Amlogic specific "sm" cmd to write the SoC chip ID to memory. Signed-off-by: Nikita Maslo <nam@...> Co-developed-by: Viacheslav Bocharov <adeep@...> Signed-off-by: Viacheslav Bocharov <adeep@...> --- arch/arm/include/asm/arch-meson/sm.h | 12 ++++++++++- arch/arm/mach-meson/sm.c | 32 +++++++++++++++++++++++++++- cmd/meson/sm.c | 22 ++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/arch-meson/sm.h b/arch/arm/include/asm/= arch-meson/sm.h index 4b1d564bc48..812c5ed020a 100644 --- a/arch/arm/include/asm/arch-meson/sm.h +++ b/arch/arm/include/asm/arch-meson/sm.h @@ -27,9 +27,10 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *bu= ffer, size_t size); ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size= ); =20 #define SM_SERIAL_SIZE 12 +#define SM_CHIP_ID_SIZE 16 =20 /** - * meson_sm_get_serial - read chip unique id into buffer + * meson_sm_get_serial - read chip unique serial into buffer * * @buffer: pointer to buffer * @size: buffer size. @@ -37,6 +38,15 @@ ssize_t meson_sm_write_efuse(uintptr_t offset, void *b= uffer, size_t size); */ int meson_sm_get_serial(void *buffer, size_t size); =20 +/** + * meson_sm_get_chip_id - read unique chip ID into buffer + * + * @buffer: pointer to buffer + * @size: buffer size. + * @return: zero on success or -errno on failure + */ +int meson_sm_get_chip_id(void *buffer, size_t size); + enum { REBOOT_REASON_COLD =3D 0, REBOOT_REASON_NORMAL =3D 1, diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c index 4d9f83d3b38..05d92f878d9 100644 --- a/arch/arm/mach-meson/sm.c +++ b/arch/arm/mach-meson/sm.c @@ -78,7 +78,6 @@ ssize_t meson_sm_write_efuse(uintptr_t offset, void *bu= ffer, size_t size) =20 #define SM_CHIP_ID_LENGTH 119 #define SM_CHIP_ID_OFFSET 4 -#define SM_CHIP_ID_SIZE 12 =20 int meson_sm_get_serial(void *buffer, size_t size) { @@ -101,6 +100,37 @@ int meson_sm_get_serial(void *buffer, size_t size) return 0; } =20 +int meson_sm_get_chip_id(void *buffer, size_t size) +{ + struct udevice *dev; + struct pt_regs regs =3D { 0 }; + u8 id_buffer[SM_CHIP_ID_LENGTH]; + int err; + + dev =3D meson_get_sm_device(); + if (IS_ERR(dev)) + return PTR_ERR(dev); + + regs.regs[1] =3D 2; + err =3D sm_call_read(dev, id_buffer, SM_CHIP_ID_LENGTH, + MESON_SMC_CMD_CHIP_ID_GET, ®s); + + if (err < 0) { + pr_err("Failed to read chipid (%d)\n", err); + return err; + } + + if (((u32 *)id_buffer)[0] !=3D 2) { + pr_err("Failed to read chipid: invalid chipid call version\n"); + return -EINVAL; + } + + memcpy(buffer, id_buffer + SM_CHIP_ID_OFFSET, + size > SM_CHIP_ID_LENGTH ? SM_CHIP_ID_LENGTH : size); + + return 0; +} + #define AO_SEC_SD_CFG15 0xfc #define REBOOT_REASON_MASK GENMASK(15, 12) =20 diff --git a/cmd/meson/sm.c b/cmd/meson/sm.c index b69f8123ee2..21bfa58e507 100644 --- a/cmd/meson/sm.c +++ b/cmd/meson/sm.c @@ -33,6 +33,24 @@ static int do_sm_serial(struct cmd_tbl *cmdtp, int fla= g, int argc, return CMD_RET_SUCCESS; } =20 +static int do_sm_chip_id(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong address; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + address =3D simple_strtoul(argv[1], NULL, 0); + + ret =3D meson_sm_get_chip_id((void *)address, SM_CHIP_ID_SIZE); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + #define MAX_REBOOT_REASONS 14 =20 static const char *reboot_reasons[MAX_REBOOT_REASONS] =3D { @@ -154,6 +172,7 @@ free_buffer: =20 static struct cmd_tbl cmd_sm_sub[] =3D { U_BOOT_CMD_MKENT(serial, 2, 1, do_sm_serial, "", ""), + U_BOOT_CMD_MKENT(chipid, 2, 1, do_sm_chip_id, "", ""), U_BOOT_CMD_MKENT(reboot_reason, 1, 1, do_sm_reboot_reason, "", ""), U_BOOT_CMD_MKENT(efuseread, 4, 1, do_efuse_read, "", ""), U_BOOT_CMD_MKENT
|
[PATCH] Squashed 'dts/upstream/' changes from 9b6ba2666d63..8531b4b4988c
3
8531b4b4988c Merge tag 'v6.13-rc7-dts-raw' [snip] git-subtree-dir: dts/upstream git-subtree-split: 8531b4b4988c2c9bddc90ea74f2d3e2dca9d5056 --- This will bring us to the v6.13-dts tag of the devicetree-rebasing tree and so match v6.13 release. Changes and changelog omitted due to size, and everyone who is listed as a maintainer of a platform with OF_UPSTREAM enabled has been bcc'd, while other lists were cc'd to avoid being marked as spam, hopefully. -- Tom
|
[PATCH] board: amlogic: odroid-n2: remove amlogic prefix from fdtdir path
2
Commit 834e7c8136c6 ("dts: meson-g12a: Switch to using upstream DT") changed Amlogic configs to contain the default /amlogic device-tree path prefix, e.g. for odroid-n2: CONFIG_DEFAULT_DEVICE_TREE="amlogic/meson-g12b-odroid-n2" The board files also prefix amlogic when using fdtdir resulting in an /amlogic/amlogic/meson-g12b-odroid-n2.dtb path which is invalid with most distro packaging. Drop the prefix here to align with the board configs. This resolves fdtdir boot on Odroid N2/C4/HC4. Signed-off-by: Christian Hewitt <christianshewitt@...> --- board/amlogic/odroid-n2/odroid-n2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/amlogic/odroid-n2/odroid-n2.c b/board/amlogic/odroid-n2/odroid-n2.c index ae953d0e4ba..e98580631ec 100644 --- a/board/amlogic/odroid-n2/odroid-n2.c +++ b/board/amlogic/odroid-n2/odroid-n2.c @@ -62,7 +62,7 @@ static void odroid_set_fdtfile(char *soc, char *variant) { char s[128]; - snprintf(s, sizeof(s), "amlogic/meson-%s-odroid-%s.dtb", soc, variant); + snprintf(s, sizeof(s), "meson-%s-odroid-%s.dtb", soc, variant); env_set("fdtfile", s); } -- 2.34.1
|
[PATCH 1/2] tools: mkimage: Add Amlogic Boot Image type
4
Add support for creating an Amlogic Boot Image that pass CHK in BL1 on Amlogic AArch64 SoCs. Images can optionally be signed for secure boot scenario, however creation of signed images has not been implemented. Example of how to use it: # Create an amlogic boot image tools/mkimage -T amlimage -n gxbb -d u-boot-spl.bin u-boot-amlogic.bin # List boot image header information tools/mkimage -l u-boot-amlogic.bin # Extract amlogic boot image payload tools/dumpimage -T amlimage -o bl2-payload.bin u-boot-amlogic.bin Or with binman using something like: binman { u-boot-amlogic { filename = "u-boot-amlogic.bin"; pad-byte = <0xff>; mkimage { filename = "bl2.bin"; args = "-n", "gxbb", "-T", "amlimage"; u-boot-spl { }; }; }; }; Signed-off-by: Jonas Karlman <jonas@...> --- MAINTAINERS | 1 + boot/image.c | 1 + include/image.h | 1 + tools/Makefile | 1 + tools/amlimage.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 tools/amlimage.c diff --git a/MAINTAINERS b/MAINTAINERS index ba31f86feb6d..6a92daa489da 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -181,6 +181,7 @@ F: drivers/video/meson/ F: drivers/watchdog/meson_gxbb_wdt.c F: include/configs/meson64.h F: include/configs/meson64_android.h +F: tools/amlimage* F: doc/board/amlogic/ N: meson diff --git a/boot/image.c b/boot/image.c index abac254e0264..814ad182a525 100644 --- a/boot/image.c +++ b/boot/image.c @@ -183,6 +183,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_FDT_LEGACY, "fdt_legacy", "legacy Image with Flat Device Tree ", }, { IH_TYPE_RENESAS_SPKG, "spkgimage", "Renesas SPKG Image" }, { IH_TYPE_STARFIVE_SPL, "sfspl", "StarFive SPL Image" }, + { IH_TYPE_AMLIMAGE, "amlimage", "Amlogic Boot Image" }, { -1, "", "", }, }; diff --git a/include/image.h b/include/image.h index 0a61dfd556c5..acad8997d190 100644 --- a/include/image.h +++ b/include/image.h @@ -232,6 +232,7 @@ enum image_type_t { IH_TYPE_FDT_LEGACY, /* Binary Flat Device Tree Blob in a Legacy Image */ IH_TYPE_RENESAS_SPKG, /* Renesas SPKG image */ IH_TYPE_STARFIVE_SPL, /* StarFive SPL image */ + IH_TYPE_AMLIMAGE, /* Amlogic Boot Image */ IH_TYPE_COUNT, /* Number of image types */ }; diff --git a/tools/Makefile b/tools/Makefile index ee08a9675df8..0dbc429d6419 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -100,6 +100,7 @@ ROCKCHIP_OBS = generated/lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o # common objs for dumpimage and mkimage dumpimage-mkimage-objs := aisimage.o \ + amlimage.o \ atmelimage.o \ $(FIT_OBJS-y) \ $(FIT_SIG_OBJS-y) \ diff --git a/tools/amlimage.c b/tools/amlimage.c new file mode 100644 index 000000000000..9af795602e69 --- /dev/null +++ b/tools/amlimage.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright Contributors to the U-Boot project. + +#include "imagetool.h" +#include <u-boot/sha256.h> + +/* + * Image contain data in the following order: + * Nonce 16 byte + * Header 64 byte + * Digest 32 byte + * Padding align up to 4K + * Payload + */ + +#define HEADER_MAGIC 0x4c4d4140 /* @AML */ +#define HEADER_OFFSET 0x10 /* 16 */ +#define HEADER_SIZE 0x40 /* 64 */ +#define PAYLOAD_OFFSET 0x1000 /* 4096 */ + +struct amlimage_header { + uint32_t magic; + uint32_t total_size; + uint8_t header_size; + uint8_t root_key_index; + uint8_t version_major; + uint8_t version_minor; + uint32_t padding1; + uint32_t digest_type; + uint32_t digest_offset; + uint32_t digest_size; + uint32_t data_offset; + uint32_t key_type; + uint32_t key_offset; + uint32_t key_size; + uint32_t data_size; + uint32_t payload_type; + uint32_t payload_offset; + uint32_t payload_size; + uint32_t padding2; +} __packed; + +struct amlimage_variant { + const char *name; + const struct amlimage_header hdr; +}; + +#define VARIANT(name, major, minor, size) \ + { name, { .magic = HEADER_MAGIC, .header_size = HEADER_SIZE, \ + .version_major = major, .version_minor = minor, \ + .payload_size = size, } } + +static const struct amlimage_variant variants[] = { + VARIANT("gxbb", 1, 0, 0xb000), + VARIANT("gxl", 1, 1, 0xb000), + VARIANT("gxm", 1, 1, 0xb000), +
|
[PATCH] board: odroid-n2: Add script and update docs for signing
2
Hi, I'm not a big fan of moving the instructions in a script, the script is already avaible in the amlogic-boot-fip project, so rather could you fix the documentation instead ? Thanks, Neil
|
[PATCH v5 00/13] Add video damage tracking
On Mon, Aug 21, 2023 at 01:50 PM Alper Nebi Yasak <alpernebiyasak@...> wrote: > > This is a rebase of Alexander Graf's video damage tracking series, with > some tests and other changes. The original cover letter is as follows: > > > > This patch set speeds up graphics output on ARM by a factor of 60x. > > > > On most ARM SBCs, we keep the frame buffer in DRAM and map it as cached, > > but need it accessible by the display controller which reads directly > > from a later point of consistency. Hence, we flush the frame buffer to > > DRAM on every change. The full frame buffer. > > > > Unfortunately, with the advent of 4k displays, we are seeing frame buffers > > that can take a while to flush out. This was reported by Da Xue with grub, > > which happily print 1000s of spaces on the screen to draw a menu. Every > > printed space triggers a cache flush. > > > > This patch set implements the easiest mitigation against this problem: > > Damage tracking. We remember the lowest common denominator region that was > > touched since the last video_sync() call and only flush that. The most > > typical writer to the frame buffer is the video console, which always > > writes rectangles of characters on the screen and syncs afterwards. > > > > With this patch set applied, we reduce drawing a large grub menu (with > > serial console attached for size information) on an RK3399-ROC system > > at 1440p from 55 seconds to less than 1 second. > > > > Version 2 also implements VIDEO_COPY using this mechanism, reducing its > > overhead compared to before as well. So even x86 systems should be faster > > with this now :). > > > > > > Alternatives considered: > > > > 1) Lazy sync - Sandbox does this. It only calls video_sync(true) ever > > so often. We are missing timers to do this generically. > > > > 2) Double buffering - We could try to identify whether anything changed > > at all and only draw to the FB if it did. That would require > > maintaining a second buffer that we need to scan. > > > > 3) Text buffer - Maintain a buffer of all text printed on the screen with > > respective location. Don't write if the old and new character are > > identical. This would limit applicability to text only and is an > > optimization on top of this patch set. > > > > 4) Hash screen lines - Create a hash (sha256?) over every line when it > > changes. Only flush when it does. I'm not sure if this would waste > > more time, memory and cache than the current approach. It would make > > full screen updates much more expensive. > > > Changes in v5: > - Add patch "video: test: Split copy frame buffer check into a function" > - Add patch "video: test: Support checking copy frame buffer contents" > - Add patch "video: test: Test partial updates of hardware frame buffer" > - Use xstart, ystart, xend, yend as names for damage region > - Document damage struct and fields in struct video_priv comment > - Return void from video_damage() > - Fix undeclared priv error in video_sync() > - Drop unused headers from video-uclass.c > - Use IS_ENABLED() instead of CONFIG_IS_ENABLED() > - Call video_damage() also in video_fill_part() > - Use met->baseline instead of priv->baseline > - Use fontdata->height/width instead of VIDEO_FONT_HEIGHT/WIDTH > - Update console_rotate.c video_damage() calls to pass video tests > - Remove mention about not having minimal damage for console_rotate.c > - Add patch "video: test: Test video damage tracking via vidconsole" > - Document new vdev field in struct efi_gop_obj comment > - Remove video_sync_copy() also from video_fill(), video_fill_part() > - Fix memmove() calls by removing the extra dev argument > - Call video_sync() before checking copy_fb in video tests > - Imply VIDEO_DAMAGE for video drivers instead of selecting it > - Imply VIDEO_DAMAGE also for VIDEO_TIDSS > > > v4: https://lore.kernel.org/all/20230103215004.22646-1-agraf@.../ > > > Changes in v4: > - Move damage clear to patch "dm: video: Add damage tracking API" > - Simplify first damage logic > - Remove VIDEO_DAMAGE default for ARM > - Skip damage on EfiBltVideoToBltBuffer > -
|
[GIT PULL] Please pull u-boot-dfu-next-20241126
2
Hi Tom, Please find some new developments for next: Android: - bootstd: Implement bootimage v2 support - bootstd: Support non-A/B in bootmeth_android - Migrate VIM3 and VIM3L to use bootmeth_android - bootstd: Additional test for bootimage v2 - bootstd: Optimize load time when reading partitions CI job: - https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/23573 Thanks, Mattijs The following changes since commit 48380f9b2a12e3fc6339d6af5a154bded769d911: Merge tag 'v2025.01-rc3' into next (2024-11-25 17:34:08 -0600) are available in the Git repository at: https://source.denx.de/u-boot/custodians/u-boot-dfu.git tags/u-boot-dfu-next-20241126 for you to fetch changes up to abadcda24b100b8eb0f138085cca6595518cec85: bootstd: android: don't read whole partition sizes (2024-11-26 10:04:40 +0100) ---------------------------------------------------------------- u-boot-dfu-next-20241126 Android: - bootstd: Implement bootimage v2 support - bootstd: Support non-A/B in bootmeth_android - Migrate VIM3 and VIM3L to use bootmeth_android - bootstd: Additional test for bootimage v2 - bootstd: Optimize load time when reading partitions ---------------------------------------------------------------- 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 Julien Masson (1): bootstd: android: don't read whole partition sizes arch/sandbox/dts/test.dts | 10 ++- boot/Kconfig | 1 - boot/bootmeth_android.c | 104 ++++++++++++++++++++++-------- boot/image-android.c | 45 +++++++++++++ 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 -- include/image.h | 24 +++++++ test/boot/bootflow.c | 29 ++++++++- test/py/tests/test_ut.py | 49 ++++++++++++++ 16 files changed, 297 insertions(+), 51 deletions(-)
|
[PATCH v4 0/5] Add support of Android Boot Image version 2 and non-AB image
2
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@...> --- Changes in v4: - test: fix test after patch done on it by Mattijs : https://lore.kernel.org/r/all/20241123024300.GY3600562@bill-the-cat/ - Link to v3: https://lore.kernel.org/r/20241119-adnroidv2-v3-0-45baa486fb31@... Changes in v3: - Remove gpio recovery stuff not needed anymore. - Link to v2: https://lore.kernel.org/r/20241114-adnroidv2-v2-0-015bffb1373a@... 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@... --- 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: 48380f9b2a12e3fc6339d6af5a154bded769d911 change-id: 20241015-adnroidv2-a01dca609707 Best regards, -- Guillaume La Roque <glaroque@...>
|
[PATCH v4 5/5] bootstd: Add test for Android boot image v2
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@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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 da713d8ed72b..e33b08aa8cda 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 | UTF_DM | UTF_SCAN_FDT); -/* 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 | UTF_DM | UTF_SCAN_FDT); +BOOTSTD_TEST(bootflow_android_image_v4, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); + +/* 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 | UTF_DM | UTF_SCAN_FDT); /* 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 {fn
|
[PATCH v4 4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android
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@...> Acked-by: Neil Armstrong <neil.armstrong@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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; " \ -- 2.34.1
|
[PATCH v4 3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android
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@...> Acked-by: Neil Armstrong <neil.armstrong@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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;" \ -- 2.34.1
|
[PATCH v4 2/5] bootstd: android: add non-A/B image support
Update android bootmeth to support non-A/B image. Enable AB support only when ANDROID_AB is enabled. Reviewed-by: Mattijs Korpershoek <mkorpershoek@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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;
|
[PATCH v4 1/5] bootstd: android: add support of bootimage v2
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-header#header-v2 Tested-by: Julien Masson <jmasson@...> Reviewed-by: Mattijs Korpershoek <mkorpershoek@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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); -- 2.34.1
|
[PATCH v3 0/5] Add support of Android Boot Image version 2 and non-AB image
11
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@...> --- Changes in v3: - Remove gpio recovery stuff not needed anymore. - Link to v2: https://lore.kernel.org/r/20241114-adnroidv2-v2-0-015bffb1373a@... 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@... --- 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, -- Guillaume La Roque <glaroque@...>
|
[PATCH v3 5/5] bootstd: Add test for Android boot image v2
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@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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_
|
[PATCH v3 4/5] configs: khadas-vim3_android{_ab}: move on bootmeth android
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@...> Acked-by: Neil Armstrong <neil.armstrong@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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; " \ -- 2.34.1
|
[PATCH v3 3/5] configs: khadas-vim3l_android{_ab}: move on bootmeth android
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@...> Acked-by: Neil Armstrong <neil.armstrong@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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;" \ -- 2.34.1
|
[PATCH v3 2/5] bootstd: android: add non-A/B image support
Update android bootmeth to support non-A/B image. Enable AB support only when ANDROID_AB is enabled. Reviewed-by: Mattijs Korpershoek <mkorpershoek@...> Signed-off-by: Guillaume La Roque <glaroque@...> --- 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;
|