sm8250-common: bootctrl: don't assume both partition's slots are on the same disk

* 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
This commit is contained in:
Dan Pasanen 2018-01-15 18:14:38 -06:00 committed by SGCMarkus
parent e9423387bd
commit 15492e786c
2 changed files with 86 additions and 40 deletions

View File

@ -290,7 +290,8 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
unsigned slot) unsigned slot)
{ {
char buf[PATH_MAX] = {0}; 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 slotA[MAX_GPT_NAME_SIZE + 1] = {0};
char slotB[MAX_GPT_NAME_SIZE + 1] = {0}; char slotB[MAX_GPT_NAME_SIZE + 1] = {0};
char active_guid[TYPE_GUID_SIZE + 1] = {0}; char active_guid[TYPE_GUID_SIZE + 1] = {0};
@ -328,24 +329,28 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
if (stat(buf, &st)) if (stat(buf, &st))
continue; continue;
memset(slotA, 0, sizeof(slotA)); 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(), snprintf(slotA, sizeof(slotA) - 1, "%s%s", prefix.c_str(),
AB_SLOT_A_SUFFIX); AB_SLOT_A_SUFFIX);
snprintf(slotB, sizeof(slotB) - 1,"%s%s", prefix.c_str(), snprintf(slotB, sizeof(slotB) - 1,"%s%s", prefix.c_str(),
AB_SLOT_B_SUFFIX); AB_SLOT_B_SUFFIX);
//Get the disk containing the partitions that were passed in. //Get the disks containing the partitions that were passed in.
//All partitions passed in must lie on the same disk. if (!diskA) {
if (!disk) { diskA = boot_ctl_get_disk_info(slotA);
disk = boot_ctl_get_disk_info(slotA); if (!diskA)
if (!disk) goto error;
}
if (!diskB) {
diskB = boot_ctl_get_disk_info(slotB);
if (!diskB)
goto error; goto error;
} }
//Get partition entry for slot A & B from the primary //Get partition entry for slot A & B from the primary
//and backup tables. //and backup tables.
pentryA = gpt_disk_get_pentry(disk, slotA, PRIMARY_GPT); pentryA = gpt_disk_get_pentry(diskA, slotA, PRIMARY_GPT);
pentryA_bak = gpt_disk_get_pentry(disk, slotA, SECONDARY_GPT); pentryA_bak = gpt_disk_get_pentry(diskA, slotA, SECONDARY_GPT);
pentryB = gpt_disk_get_pentry(disk, slotB, PRIMARY_GPT); pentryB = gpt_disk_get_pentry(diskB, slotB, PRIMARY_GPT);
pentryB_bak = gpt_disk_get_pentry(disk, slotB, SECONDARY_GPT); pentryB_bak = gpt_disk_get_pentry(diskB, slotB, SECONDARY_GPT);
if ( !pentryA || !pentryA_bak || !pentryB || !pentryB_bak) { if ( !pentryA || !pentryA_bak || !pentryB || !pentryB_bak) {
//None of these should be NULL since we have already //None of these should be NULL since we have already
//checked for A & B versions earlier. //checked for A & B versions earlier.
@ -398,8 +403,16 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
ALOGE("%s: Unknown slot suffix!", __func__); ALOGE("%s: Unknown slot suffix!", __func__);
goto error; 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", ALOGE("%s: Failed to update gpt_disk crc",
__func__); __func__);
goto error; goto error;
@ -407,18 +420,27 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
} }
} }
//write updated content to disk //write updated content to disk
if (disk) { if (diskA) {
if (gpt_disk_commit(disk)) { if (gpt_disk_commit(diskA)) {
ALOGE("Failed to commit disk entry"); ALOGE("Failed to commit disk entry");
goto error; 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; return 0;
error: error:
if (disk) if (diskA)
gpt_disk_free(disk); gpt_disk_free(diskA);
if (diskB)
gpt_disk_free(diskB);
return -1; return -1;
} }
@ -596,9 +618,10 @@ int set_active_boot_slot(unsigned slot)
PTN_XBL_CFG, PTN_XBL_CFG,
strlen(PTN_XBL_CFG)))) strlen(PTN_XBL_CFG))))
continue; 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]; 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); ptn_vec.push_back(cur_ptn);
} }

View File

@ -385,7 +385,8 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
unsigned slot) unsigned slot)
{ {
char buf[PATH_MAX] = {0}; 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 slotA[MAX_GPT_NAME_SIZE + 1] = {0};
char slotB[MAX_GPT_NAME_SIZE + 1] = {0}; char slotB[MAX_GPT_NAME_SIZE + 1] = {0};
char active_guid[TYPE_GUID_SIZE + 1] = {0}; char active_guid[TYPE_GUID_SIZE + 1] = {0};
@ -423,24 +424,28 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
if (stat(buf, &st)) if (stat(buf, &st))
continue; continue;
memset(slotA, 0, sizeof(slotA)); 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(), snprintf(slotA, sizeof(slotA) - 1, "%s%s", prefix.c_str(),
AB_SLOT_A_SUFFIX); AB_SLOT_A_SUFFIX);
snprintf(slotB, sizeof(slotB) - 1,"%s%s", prefix.c_str(), snprintf(slotB, sizeof(slotB) - 1,"%s%s", prefix.c_str(),
AB_SLOT_B_SUFFIX); AB_SLOT_B_SUFFIX);
//Get the disk containing the partitions that were passed in. //Get the disks containing the partitions that were passed in.
//All partitions passed in must lie on the same disk. if (!diskA) {
if (!disk) { diskA = boot_ctl_get_disk_info(slotA);
disk = boot_ctl_get_disk_info(slotA); if (!diskA)
if (!disk) goto error;
}
if (!diskB) {
diskB = boot_ctl_get_disk_info(slotB);
if (!diskB)
goto error; goto error;
} }
//Get partition entry for slot A & B from the primary //Get partition entry for slot A & B from the primary
//and backup tables. //and backup tables.
pentryA = gpt_disk_get_pentry(disk, slotA, PRIMARY_GPT); pentryA = gpt_disk_get_pentry(diskA, slotA, PRIMARY_GPT);
pentryA_bak = gpt_disk_get_pentry(disk, slotA, SECONDARY_GPT); pentryA_bak = gpt_disk_get_pentry(diskA, slotA, SECONDARY_GPT);
pentryB = gpt_disk_get_pentry(disk, slotB, PRIMARY_GPT); pentryB = gpt_disk_get_pentry(diskB, slotB, PRIMARY_GPT);
pentryB_bak = gpt_disk_get_pentry(disk, slotB, SECONDARY_GPT); pentryB_bak = gpt_disk_get_pentry(diskB, slotB, SECONDARY_GPT);
if ( !pentryA || !pentryA_bak || !pentryB || !pentryB_bak) { if ( !pentryA || !pentryA_bak || !pentryB || !pentryB_bak) {
//None of these should be NULL since we have already //None of these should be NULL since we have already
//checked for A & B versions earlier. //checked for A & B versions earlier.
@ -493,8 +498,16 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
ALOGE("%s: Unknown slot suffix!", __func__); ALOGE("%s: Unknown slot suffix!", __func__);
goto error; 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", ALOGE("%s: Failed to update gpt_disk crc",
__func__); __func__);
goto error; goto error;
@ -502,18 +515,27 @@ static int boot_ctl_set_active_slot_for_partitions(vector<string> part_list,
} }
} }
//write updated content to disk //write updated content to disk
if (disk) { if (diskA) {
if (gpt_disk_commit(disk)) { if (gpt_disk_commit(diskA)) {
ALOGE("Failed to commit disk entry"); ALOGE("Failed to commit disk entry");
goto error; 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; return 0;
error: error:
if (disk) if (diskA)
gpt_disk_free(disk); gpt_disk_free(diskA);
if (diskB)
gpt_disk_free(diskB);
return -1; return -1;
} }
@ -545,9 +567,10 @@ int set_active_boot_slot(struct boot_control_module *module, unsigned slot)
PTN_XBL_CFG, PTN_XBL_CFG,
strlen(PTN_XBL_CFG)))) strlen(PTN_XBL_CFG))))
continue; 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]; 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); ptn_vec.push_back(cur_ptn);
} }