From fc04460b2eee00337e8769b6fb8688a91208c00a Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 8 Feb 2021 16:45:47 +0800 Subject: [PATCH] common: android: support boot recovery system In android A/B system, there is no recovery partition, but in the linux system, we need the recovery to update system. Signed-off-by: Jason Zhu Change-Id: Idac88720b260791b1ad4c51a5ebc7aae9c66ca67 --- arch/arm/mach-rockchip/resource_img.c | 14 +++++++++---- common/android_bootloader.c | 29 ++++++++++++++++++--------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-rockchip/resource_img.c b/arch/arm/mach-rockchip/resource_img.c index d173f906db..a87bbc5b2c 100644 --- a/arch/arm/mach-rockchip/resource_img.c +++ b/arch/arm/mach-rockchip/resource_img.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -416,13 +417,18 @@ static int get_resource_base_sector(struct blk_desc *dev_desc, #ifdef CONFIG_ANDROID_BOOT_IMAGE struct andr_img_hdr *hdr; u32 os_ver = 0, os_lvl; + const char *part_boot = PART_BOOT; /* - * Anyway, we must read android hdr firstly from boot partition to get - * the 'os_version' for android_bcb_msg_sector_offset(), in order to - * confirm BCB message offset of *MISC* partition. + * Anyway, we must read android hdr firstly from boot/recovery partition + * to get the 'os_version' for android_bcb_msg_sector_offset(), in order + * to confirm BCB message offset of *MISC* partition. */ - if (part_get_info_by_name(dev_desc, PART_BOOT, &part) < 0) +#ifdef CONFIG_ANDROID_AB + part_boot = ab_can_find_recovery_part() ? PART_RECOVERY : PART_BOOT; +#endif + + if (part_get_info_by_name(dev_desc, part_boot, &part) < 0) goto resource_part; hdr = populate_andr_img_hdr(dev_desc, &part); diff --git a/common/android_bootloader.c b/common/android_bootloader.c index 1ef2925843..33ee2281c0 100644 --- a/common/android_bootloader.c +++ b/common/android_bootloader.c @@ -795,23 +795,27 @@ int android_fdt_overlay_apply(void *fdt_addr) { struct andr_img_hdr *hdr; struct blk_desc *dev_desc; - const char *part_boot; + const char *part_boot = PART_BOOT; disk_partition_t part_info; char *fdt_backup; - char *part_dtbo; + char *part_dtbo = PART_DTBO; char buf[32] = {0}; ulong fdt_dtbo = -1; u32 totalsize; int index = -1; int ret; - if (IS_ENABLED(CONFIG_ANDROID_AB) || - (rockchip_get_boot_mode() != BOOT_MODE_RECOVERY)) { - part_boot = PART_BOOT; - part_dtbo = PART_DTBO; - } else { + if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY) { +#ifdef CONFIG_ANDROID_AB + bool can_find_recovery; + + can_find_recovery = ab_can_find_recovery_part(); + part_boot = can_find_recovery ? PART_RECOVERY : PART_BOOT; + part_dtbo = can_find_recovery ? PART_RECOVERY : PART_DTBO; +#else part_boot = PART_RECOVERY; part_dtbo = PART_RECOVERY; +#endif } dev_desc = rockchip_get_bootdev(); @@ -978,10 +982,15 @@ int android_bootloader_boot_flow(struct blk_desc *dev_desc, #endif break; case ANDROID_BOOT_MODE_RECOVERY: - /* In recovery mode we still boot the kernel from "boot" but - * don't skip the initramfs so it boots to recovery. + /* + * In recovery mode, if have recovery partition, we still boot the + * kernel from "recovery". If not, don't skip the initramfs so it + * boots to recovery from image in partition "boot". */ -#ifndef CONFIG_ANDROID_AB +#ifdef CONFIG_ANDROID_AB + boot_partname = ab_can_find_recovery_part() ? + ANDROID_PARTITION_RECOVERY : ANDROID_PARTITION_BOOT; +#else boot_partname = ANDROID_PARTITION_RECOVERY; #endif break;