]> Git Repo - J-u-boot.git/commitdiff
bootstd: android: add non-A/B image support
authorGuillaume La Roque <[email protected]>
Tue, 26 Nov 2024 08:06:10 +0000 (09:06 +0100)
committerMattijs Korpershoek <[email protected]>
Tue, 26 Nov 2024 08:59:01 +0000 (09:59 +0100)
Update android bootmeth to support non-A/B image.
Enable AB support only when ANDROID_AB is enabled.

Reviewed-by: Mattijs Korpershoek <[email protected]>
Signed-off-by: Guillaume La Roque <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mattijs Korpershoek <[email protected]>
boot/Kconfig
boot/bootmeth_android.c
configs/am62x_a53_android.config
configs/sandbox_defconfig

index 7dd30a030e39952b08d19fac4976d6458f67dad5..661e89ca05b2b5a76cc378871b09d11c9daafe3b 100644 (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
index 2e7f85e4a7082a1a3682a83befa6a31aa991331b..2aac32331d3c28853bc87d05a8c76ae868ea97c7 100644 (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);
index adbe2b8e126fce783cdff6d22480edf91d0962e2..2aca51e3a1074415be9b9bccd861ad4cdd4a7dd3 100644 (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
index 718e4a8283c846939108a825c261476876f1e36b..8c244c859bcf9035016bfdaa800fe88796098d0f 100644 (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
This page took 0.044282 seconds and 4 git commands to generate.