Skip to content

Commit

Permalink
nash: bootctrl: don't assume both partition's slots are on the same disk
Browse files Browse the repository at this point in the history
* Call out for the disk of both slots of the target partition
  separately in case they are actually on a different disk

Change-Id: Ief0997a1d59556c08b9128777f07679f49e97877
  • Loading branch information
invisiblek committed Feb 11, 2018
1 parent 6bbb93f commit ba70a48
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions bootctrl/boot_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
unsigned slot)
{
char buf[PATH_MAX] = {0};
struct gpt_disk *disk = NULL;
struct gpt_disk *diskA = NULL;
struct gpt_disk *diskB = NULL;
char slotA[MAX_GPT_NAME_SIZE + 1] = {0};
char slotB[MAX_GPT_NAME_SIZE + 1] = {0};
char active_guid[TYPE_GUID_SIZE + 1] = {0};
Expand Down Expand Up @@ -423,24 +424,28 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
if (stat(buf, &st))
continue;
memset(slotA, 0, sizeof(slotA));
memset(slotB, 0, sizeof(slotA));
memset(slotB, 0, sizeof(slotB));
snprintf(slotA, sizeof(slotA) - 1, "%s%s", prefix.c_str(),
AB_SLOT_A_SUFFIX);
snprintf(slotB, sizeof(slotB) - 1,"%s%s", prefix.c_str(),
AB_SLOT_B_SUFFIX);
//Get the disk containing the partitions that were passed in.
//All partitions passed in must lie on the same disk.
if (!disk) {
disk = boot_ctl_get_disk_info(slotA);
if (!disk)
//Get the disks containing the partitions that were passed in.
if (!diskA) {
diskA = boot_ctl_get_disk_info(slotA);
if (!diskA)
goto error;
}
if (!diskB) {
diskB = boot_ctl_get_disk_info(slotB);
if (!diskB)
goto error;
}
//Get partition entry for slot A & B from the primary
//and backup tables.
pentryA = gpt_disk_get_pentry(disk, slotA, PRIMARY_GPT);
pentryA_bak = gpt_disk_get_pentry(disk, slotA, SECONDARY_GPT);
pentryB = gpt_disk_get_pentry(disk, slotB, PRIMARY_GPT);
pentryB_bak = gpt_disk_get_pentry(disk, slotB, SECONDARY_GPT);
pentryA = gpt_disk_get_pentry(diskA, slotA, PRIMARY_GPT);
pentryA_bak = gpt_disk_get_pentry(diskA, slotA, SECONDARY_GPT);
pentryB = gpt_disk_get_pentry(diskB, slotB, PRIMARY_GPT);
pentryB_bak = gpt_disk_get_pentry(diskB, slotB, SECONDARY_GPT);
if ( !pentryA || !pentryA_bak || !pentryB || !pentryB_bak) {
//None of these should be NULL since we have already
//checked for A & B versions earlier.
Expand Down Expand Up @@ -492,27 +497,44 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
ALOGE("%s: Unknown slot suffix!", __func__);
goto error;
}
if (disk) {
if (gpt_disk_update_crc(disk) != 0) {

if (diskA) {
if (gpt_disk_update_crc(diskA) != 0) {
ALOGE("%s: Failed to update gpt_disk crc",
__func__);
goto error;
}
}
if (diskB) {
if (gpt_disk_update_crc(diskB) != 0) {
ALOGE("%s: Failed to update gpt_disk crc",
__func__);
goto error;
}
}
}
//write updated content to disk
if (disk) {
if (gpt_disk_commit(disk)) {
if (diskA) {
if (gpt_disk_commit(diskA)) {
ALOGE("Failed to commit disk entry");
goto error;
}
gpt_disk_free(disk);
gpt_disk_free(diskA);
}
if (diskB) {
if (gpt_disk_commit(diskB)) {
ALOGE("Failed to commit disk entry");
goto error;
}
gpt_disk_free(diskB);
}
return 0;

error:
if (disk)
gpt_disk_free(disk);
if (diskA)
gpt_disk_free(diskA);
if (diskB)
gpt_disk_free(diskB);
return -1;
}

Expand All @@ -539,9 +561,10 @@ int set_active_boot_slot(struct boot_control_module *module, unsigned slot)
//XBL is handled differrently for ufs devices so ignore it
if (is_ufs && !strncmp(ptn_list[i], PTN_XBL, strlen(PTN_XBL)))
continue;
//The partition list will be the list of _a partitions
//The partition list will be the list of partitions
//corresponding to the slot being set active
string cur_ptn = ptn_list[i];
cur_ptn.append(AB_SLOT_A_SUFFIX);
cur_ptn.append(slot_suffix_arr[slot]);
ptn_vec.push_back(cur_ptn);

}
Expand Down

0 comments on commit ba70a48

Please sign in to comment.