Commit 42ed8fa2873d577183779740dcb7115b0a26157a

Authored by Ji Luo
1 parent 35ab562a3b

MA-18422 Locate the misc partition by name

Locating the misc partition by ID can help reduce the boot
time but error may happen if the ID of the misc partition
is changed. Moving the misc partition to the start of the
GPT and locate the partition by name is another option but
it will break the backward compatibility as the GPT is
changed.

part_get_info_by_name() will loop the PTE and return the
matched partition info, but it will cost much time as it
will reload the whole PTE from storage in each loop.

This commit provides part_get_info_efi_by_name() to support
return the partition info by name without reloading the whole
PTE.

Test: A/B slot switch in dual bootloader.

Change-Id: I13cb2a7b3217f73aecc2aec6e06abc0d6e8abcdd
Signed-off-by: Ji Luo <ji.luo@nxp.com>

Showing 3 changed files with 63 additions and 14 deletions Side-by-side Diff

... ... @@ -333,6 +333,62 @@
333 333 return 0;
334 334 }
335 335  
  336 +#if defined(CONFIG_DUAL_BOOTLOADER) && defined(CONFIG_SPL_BUILD)
  337 +int part_get_info_efi_by_name(struct blk_desc *dev_desc, const char *name,
  338 + disk_partition_t *info)
  339 +{
  340 + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
  341 + /* We don't free gpt_pte because the memory is allocated at
  342 + * CONFIG_SYS_SPL_PTE_RAM_BASE due to the limited memory at
  343 + * SPL stage.
  344 + */
  345 + gpt_entry *gpt_pte = NULL;
  346 + int i = 0;
  347 +
  348 + if (name == NULL) {
  349 + printf("%s: Invalid Argument(s)\n", __func__);
  350 + return -1;
  351 + }
  352 +
  353 + /* This function validates AND fills in the GPT header and PTE */
  354 + if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1)
  355 + return -1;
  356 +
  357 + /* Search PTE to find matched partition. */
  358 + for (i = 0; i < le32_to_cpu(gpt_head->num_partition_entries); i++) {
  359 + if (is_pte_valid(&gpt_pte[i]) &&
  360 + strcmp(name, print_efiname(&gpt_pte[i])) == 0) {
  361 + /* Matched partition found, copy it. */
  362 + /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */
  363 + info->start = (lbaint_t)le64_to_cpu(gpt_pte[i].starting_lba);
  364 + /* The ending LBA is inclusive, to calculate size, add 1 to it */
  365 + info->size = (lbaint_t)le64_to_cpu(gpt_pte[i].ending_lba) + 1
  366 + - info->start;
  367 + info->blksz = dev_desc->blksz;
  368 +
  369 + snprintf((char *)info->name, sizeof(info->name), "%s", name);
  370 + strcpy((char *)info->type, "U-Boot");
  371 + info->bootable = is_bootable(&gpt_pte[i]);
  372 +#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
  373 + uuid_bin_to_str(gpt_pte[i].unique_partition_guid.b, info->uuid,
  374 + UUID_STR_FORMAT_GUID);
  375 +#endif
  376 +#ifdef CONFIG_PARTITION_TYPE_GUID
  377 + uuid_bin_to_str(gpt_pte[i].partition_type_guid.b,
  378 + info->type_guid, UUID_STR_FORMAT_GUID);
  379 +#endif
  380 +
  381 + debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__,
  382 + info->start, info->size, info->name);
  383 +
  384 + return i;
  385 + }
  386 + }
  387 +
  388 + return -1;
  389 +}
  390 +#endif /* CONFIG_DUAL_BOOTLOADER && CONFIG_SPL_BUILD */
  391 +
336 392 static int part_test_efi(struct blk_desc *dev_desc)
337 393 {
338 394 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
... ... @@ -453,6 +453,11 @@
453 453 */
454 454 int get_disk_guid(struct blk_desc *dev_desc, char *guid);
455 455  
  456 +#if defined(CONFIG_DUAL_BOOTLOADER) && defined(CONFIG_SPL_BUILD)
  457 +int part_get_info_efi_by_name(struct blk_desc *dev_desc, const char *name,
  458 + disk_partition_t *info);
  459 +#endif
  460 +
456 461 #endif
457 462  
458 463 #if CONFIG_IS_ENABLED(DOS_PARTITION)
lib/avb/fsl/fsl_bootctrl.c
... ... @@ -462,10 +462,6 @@
462 462  
463 463 #define PARTITION_NAME_LEN 13
464 464 #define PARTITION_BOOTLOADER "bootloader"
465   -#ifdef CONFIG_ANDROID_AUTO_SUPPORT
466   -/* This should always sync with the gpt */
467   -#define PARTITION_MISC_ID 9
468   -#endif
469 465  
470 466 extern int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value);
471 467  
... ... @@ -487,11 +483,7 @@
487 483 /* Save metadata if changed. */
488 484 if (memcmp(ab_data, ab_data_orig, sizeof(struct bootloader_control)) != 0) {
489 485 /* Get misc partition info */
490   -#ifdef CONFIG_ANDROID_AUTO_SUPPORT
491   - if (part_get_info(dev_desc, PARTITION_MISC_ID, &info) == -1) {
492   -#else
493   - if (part_get_info_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) {
494   -#endif
  486 + if (part_get_info_efi_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) {
495 487 printf("Can't get partition info of partition: misc\n");
496 488 return -1;
497 489 }
... ... @@ -519,11 +511,7 @@
519 511 struct bootloader_control serialized;
520 512 size_t num_bytes;
521 513  
522   -#ifdef CONFIG_ANDROID_AUTO_SUPPORT
523   - if (part_get_info(dev_desc, PARTITION_MISC_ID, &info) == -1) {
524   -#else
525   - if (part_get_info_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) {
526   -#endif
  514 + if (part_get_info_efi_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) {
527 515 printf("Can't get partition info of partition: misc\n");
528 516 return -1;
529 517 } else {