Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions libfastboot/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -485,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
Expand All @@ -501,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 */
Expand All @@ -513,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)
Expand Down Expand Up @@ -603,20 +607,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
}
Expand All @@ -635,8 +641,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;
}
Expand Down
8 changes: 5 additions & 3 deletions libkernelflinger/slot_avb.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const CHAR16 *slot_label(const CHAR16 *base)
{
const CHAR16 *label;
UINTN nb_slot;
char *suffix;

if (!use_slot())
return base;
Expand All @@ -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;
}
Expand Down