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@baylibre.com>
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
Link: https://lore.kernel.org/r/20241126-adnroidv2-v4-2-11636106dc69@baylibre.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
This commit is contained in:
Guillaume La Roque 2024-11-26 09:06:10 +01:00 committed by Mattijs Korpershoek
parent 51a2fc40d3
commit 9ef8b3bf8a
4 changed files with 44 additions and 10 deletions

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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