Commit d9972736dc0272377f89ccf528e8a873199c7903
Committed by
Ye Li
1 parent
a6161b780d
Exists in
smarc_8mq_lf_v2020.04
and in
4 other branches
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> (cherry picked from commit cd8f603f0d977ed73f0d0b44437c5c68fcebde25)
Showing 3 changed files with 63 additions and 13 deletions Side-by-side Diff
disk/part_efi.c
... | ... | @@ -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); |
include/part.h
... | ... | @@ -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,9 +462,6 @@ |
462 | 462 | |
463 | 463 | #define PARTITION_NAME_LEN 13 |
464 | 464 | #define PARTITION_BOOTLOADER "bootloader" |
465 | -#ifdef CONFIG_ANDROID_AUTO_SUPPORT | |
466 | -#define PARTITION_MISC_ID 11 | |
467 | -#endif | |
468 | 465 | |
469 | 466 | extern int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value); |
470 | 467 | |
... | ... | @@ -486,11 +483,7 @@ |
486 | 483 | /* Save metadata if changed. */ |
487 | 484 | if (memcmp(ab_data, ab_data_orig, sizeof(struct bootloader_control)) != 0) { |
488 | 485 | /* Get misc partition info */ |
489 | -#ifdef CONFIG_ANDROID_AUTO_SUPPORT | |
490 | - if (part_get_info(dev_desc, PARTITION_MISC_ID, &info) == -1) { | |
491 | -#else | |
492 | - if (part_get_info_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) { | |
493 | -#endif | |
486 | + if (part_get_info_efi_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) { | |
494 | 487 | printf("Can't get partition info of partition: misc\n"); |
495 | 488 | return -1; |
496 | 489 | } |
... | ... | @@ -518,11 +511,7 @@ |
518 | 511 | struct bootloader_control serialized; |
519 | 512 | size_t num_bytes; |
520 | 513 | |
521 | -#ifdef CONFIG_ANDROID_AUTO_SUPPORT | |
522 | - if (part_get_info(dev_desc, PARTITION_MISC_ID, &info) == -1) { | |
523 | -#else | |
524 | - if (part_get_info_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) { | |
525 | -#endif | |
514 | + if (part_get_info_efi_by_name(dev_desc, FASTBOOT_PARTITION_MISC, &info) == -1) { | |
526 | 515 | printf("Can't get partition info of partition: misc\n"); |
527 | 516 | return -1; |
528 | 517 | } else { |
-
mentioned in commit e975d8