From 4ce1a3fd8bcd92d2960c446652ffe32390f9864c Mon Sep 17 00:00:00 2001 From: jizhenlo Date: Wed, 25 Oct 2023 12:16:07 +0800 Subject: [PATCH 1/2] Support share_data partition fast erase Only erase the first 4KB of the partition and set to 0. fs_mgr will format the partiton if all 0 in first 4kB. Tracked-On: OAM-115408 Signed-off-by: jizhenlo --- libfastboot/flash.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libfastboot/flash.c b/libfastboot/flash.c index af08bdcd..2edd8989 100644 --- a/libfastboot/flash.c +++ b/libfastboot/flash.c @@ -59,6 +59,7 @@ static struct gpt_partition_interface gparti; static UINT64 cur_offset; static BOOLEAN userdata_erased = FALSE; +static BOOLEAN share_data_erased = FALSE; BOOLEAN new_install_device = FALSE; #define part_start (gparti.part.starting_lba * gparti.bio->Media->BlockSize) @@ -603,20 +604,22 @@ static EFI_STATUS fast_erase_part(const CHAR16 *label) EFI_STATUS erase_by_label(CHAR16 *label) { EFI_STATUS ret; + BOOLEAN is_data = (!StrCmp(label, L"userdata") || !StrCmp(label, L"data")); + BOOLEAN is_share_data = !StrCmp(label, L"share_data"); /* userdata/data partition only need to be erased once during each boot */ - if (!StrCmp(label, L"userdata") || !StrCmp(label, L"data")) { - if (userdata_erased) { - debug(L"userdata/data partition had already been erased. skip."); + if (is_data || is_share_data) { + if ((is_data && userdata_erased) || (is_share_data && share_data_erased)) { + debug(L"userdata/share_data partition had already been erased. skip."); return EFI_SUCCESS; } if (new_install_device) { - debug(L"New install devcie, fast erase userdata/data partition"); + debug(L"New install devcie, fast erase userdata/share_data partition"); return fast_erase_part(label); } else { #ifndef USER - debug(L"fast erase userdata/data partition for userdebug build"); + debug(L"fast erase userdata/share_data partition for userdebug build"); return fast_erase_part(label); #endif } @@ -635,8 +638,10 @@ EFI_STATUS erase_by_label(CHAR16 *label) if (!CompareGuid(&gparti.part.type, &EfiPartTypeSystemPartitionGuid)) return gpt_refresh(); - if (!StrCmp(label, L"userdata") || !StrCmp(label, L"data")) + if (is_data) userdata_erased = TRUE; + if (is_share_data) + share_data_erased = TRUE; return EFI_SUCCESS; } From c0ee2a03e6e1ac082d81d5cbffcf27b2ea16a6c9 Mon Sep 17 00:00:00 2001 From: jizhenlo Date: Tue, 17 Oct 2023 10:56:54 +0800 Subject: [PATCH 2/2] Add flash support for bootloader a/b slots bootloader a/b partitions will be adopted, and the flash should support bootloader a/b slots. Tracked-On: OAM-115408 Signed-off-by: jizhenlo --- libfastboot/flash.c | 15 +++++++++------ libkernelflinger/slot_avb.c | 8 +++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libfastboot/flash.c b/libfastboot/flash.c index 2edd8989..fe3cbc5e 100644 --- a/libfastboot/flash.c +++ b/libfastboot/flash.c @@ -486,11 +486,6 @@ static struct label_exception { { L"kernel", flash_kernel }, { L"ramdisk", flash_ramdisk }, { ESP_LABEL, flash_esp }, -#ifndef USE_SBL - { BOOTLOADER_LABEL, flash_bootloader }, - { BOOTLOADER_A_LABEL, flash_bootloader_a }, - { BOOTLOADER_B_LABEL, flash_bootloader_b }, -#endif #if defined(IOC_USE_SLCAN) || defined(IOC_USE_CBC) { L"ioc", flash_ioc }, #endif @@ -502,6 +497,7 @@ static struct label_exception { EFI_STATUS flash(VOID *data, UINTN size, CHAR16 *label) { UINTN i; + CHAR16 *full_label; #ifndef USER /* special case for writing inside esp partition */ @@ -514,7 +510,14 @@ EFI_STATUS flash(VOID *data, UINTN size, CHAR16 *label) if (!StrCmp(LABEL_EXCEPTIONS[i].name, label)) return LABEL_EXCEPTIONS[i].flash_func(data, size); - return flash_partition(data, size, label); + full_label = (CHAR16 *)slot_label(label); + + if (!full_label) { + error(L"invalid bootloader label"); + return EFI_INVALID_PARAMETER; + } + + return flash_partition(data, size, full_label); } EFI_STATUS flash_file(EFI_HANDLE image, CHAR16 *filename, CHAR16 *label) diff --git a/libkernelflinger/slot_avb.c b/libkernelflinger/slot_avb.c index 0a058f5d..ea60b8c1 100644 --- a/libkernelflinger/slot_avb.c +++ b/libkernelflinger/slot_avb.c @@ -283,6 +283,7 @@ const CHAR16 *slot_label(const CHAR16 *base) { const CHAR16 *label; UINTN nb_slot; + char *suffix; if (!use_slot()) return base; @@ -298,10 +299,11 @@ const CHAR16 *slot_label(const CHAR16 *base) return base; } - if (!base || !slot_get_active()) - return NULL; + suffix = (char *)slot_get_active(); + if (!suffix) + suffix = suffixes[0]; - label = label_with_suffix(base, slot_get_active()); + label = label_with_suffix(base, suffix); return label; }