Merge branch 'emmc' into 'main'

Support eMMC-backed A/B

See merge request sdm845-mainline/qbootctl!1
merge-requests/7/head 0.1.2
Caleb Connolly 2 years ago
commit 77b48f092a
  1. 11
      bootctrl_impl.cpp
  2. 25
      gpt-utils.cpp
  3. 4
      gpt-utils.h

@ -602,13 +602,16 @@ int set_active_boot_slot(unsigned slot)
uint32_t i; uint32_t i;
int rc = -1; int rc = -1;
map<string, vector<string> >::iterator map_iter; map<string, vector<string> >::iterator map_iter;
bool ismmc;
if (boot_control_check_slot_sanity(slot)) { if (boot_control_check_slot_sanity(slot)) {
fprintf(stderr, "%s: Bad arguments\n", __func__); fprintf(stderr, "%s: Bad arguments\n", __func__);
goto error; goto error;
} }
if (ufs_bsg_dev_open() < 0) { ismmc = gpt_utils_is_partition_backed_by_emmc(PTN_XBL AB_SLOT_A_SUFFIX);
if (!ismmc && ufs_bsg_dev_open() < 0) {
goto error; goto error;
} }
@ -618,7 +621,7 @@ int set_active_boot_slot(unsigned slot)
//in the list. //in the list.
for (i = 0; i < ARRAY_SIZE(ptn_list); i++) { for (i = 0; i < ARRAY_SIZE(ptn_list); i++) {
//XBL is handled differrently for ufs devices so ignore it //XBL is handled differrently for ufs devices so ignore it
if (!strncmp(ptn_list[i], PTN_XBL, strlen(PTN_XBL))) if (!ismmc && !strncmp(ptn_list[i], PTN_XBL, strlen(PTN_XBL)))
continue; continue;
//The partition list will be the list of _a partitions //The partition list will be the list of _a partitions
string cur_ptn = ptn_list[i]; string cur_ptn = ptn_list[i];
@ -650,6 +653,10 @@ int set_active_boot_slot(unsigned slot)
} }
} }
// EMMC doesn't need attributes to be set.
if (ismmc)
return 0;
if (!strncmp(slot_suffix_arr[slot], AB_SLOT_A_SUFFIX, if (!strncmp(slot_suffix_arr[slot], AB_SLOT_A_SUFFIX,
strlen(AB_SLOT_A_SUFFIX))) { strlen(AB_SLOT_A_SUFFIX))) {
//Set xbl_a as the boot lun //Set xbl_a as the boot lun

@ -317,6 +317,7 @@ static int get_dev_path_from_partition_name(const char *partname, char *buf,
{ {
struct stat st; struct stat st;
char path[PATH_MAX] = { 0 }; char path[PATH_MAX] = { 0 };
int i;
(void)st; (void)st;
@ -334,7 +335,14 @@ static int get_dev_path_from_partition_name(const char *partname, char *buf,
if (!buf) { if (!buf) {
return -1; return -1;
} else { } else {
buf[PATH_TRUNCATE_LOC] = '\0'; for (i = strlen(buf); i > 0; i--)
if (!isdigit(buf[i - 1]))
break;
if (i >= 2 && buf[i - 1] == 'p' && isdigit(buf[i - 2]))
i--;
buf[i] = 0;
} }
return 0; return 0;
} }
@ -773,3 +781,18 @@ error:
close(fd); close(fd);
return -1; return -1;
} }
//Determine whether to handle the given partition as eMMC or UFS, using the
//name of the backing device.
//
//Note: In undefined cases (i.e. /dev/mmcblk1 and unresolvable), this function
//will tend to prefer UFS behavior. If it incorrectly reports this, then the
//program should exit (e.g. by failing) before making any changes.
bool gpt_utils_is_partition_backed_by_emmc(const char *part) {
char devpath[PATH_MAX] = { '\0' };
if (get_dev_path_from_partition_name(part, devpath, sizeof(devpath)))
return false;
return !strcmp(devpath, EMMC_DEVICE);
}

@ -84,6 +84,8 @@ extern "C" {
"product" "product"
#define BOOT_DEV_DIR "/dev/disk/by-partlabel" #define BOOT_DEV_DIR "/dev/disk/by-partlabel"
#define EMMC_DEVICE "/dev/mmcblk0"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
enum gpt_instance { PRIMARY_GPT = 0, SECONDARY_GPT }; enum gpt_instance { PRIMARY_GPT = 0, SECONDARY_GPT };
@ -163,6 +165,8 @@ int gpt_utils_set_xbl_boot_partition(enum boot_chain chain);
int gpt_utils_get_partition_map( int gpt_utils_get_partition_map(
std::vector<std::string> &partition_list, std::vector<std::string> &partition_list,
std::map<std::string, std::vector<std::string> > &partition_map); std::map<std::string, std::vector<std::string> > &partition_map);
bool gpt_utils_is_partition_backed_by_emmc(const char *part);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

Loading…
Cancel
Save