[PATCH 06/18] blspec: collect bootloader spec entries from ESP

Marco Felsch m.felsch at pengutronix.de
Mon Apr 14 03:14:05 PDT 2025


On 25-04-14, Ahmad Fatoum wrote:
> The spec points out that spec entries should be collected from ESP, even
> when XBOOTLDR partitions exist, but at a lower priority.
> 
> Implement this logic in barebox. As barebox as EFI payload systems have
> an ESP, but may have the bootloader spec files in a separate partition,
> we can't skip the walk through all partitions when we have an ESP like
> we do for XBOOTLDR partitions.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/blspec.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/common/blspec.c b/common/blspec.c
> index adc3fb2e2ea2..dd3bb1c167d7 100644
> --- a/common/blspec.c
> +++ b/common/blspec.c
> @@ -504,6 +504,7 @@ static int blspec_scan_disk(struct bootscanner *scanner,
>  {
>  	struct cdev *partcdev;
>  	int ret, err = 0, found = 0;
> +	bool have_esp = false;
>  
>  	for_each_cdev_partition(partcdev, cdev) {
>  		struct cdev *match = NULL;
> @@ -517,9 +518,13 @@ static int blspec_scan_disk(struct bootscanner *scanner,
>  		 * - GPT disk label, and a partition with the GPT type GUID of
>  		 *   bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists
>  		 *
> +		 * - an EFI System Partition and none of the above
> +		 *
>  		 * it should be used as $BOOT
>  		 */
> -		if (cdev_is_mbr_partitioned(cdev)) {
> +		if (partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP)
> +			have_esp = true;
> +		else if (cdev_is_mbr_partitioned(cdev)) {
>  			if (partcdev->dos_partition_type == 0xea)
>  				match = partcdev;
>  		} else if (cdev_is_gpt_partitioned(cdev)) {
> @@ -537,6 +542,25 @@ static int blspec_scan_disk(struct bootscanner *scanner,
>  			err = ret ?: -ENOENT;
>  	}
>  
> +	if (!have_esp)
> +		goto out;
> +
> +	for_each_cdev_partition(partcdev, cdev) {
> +		if (!(partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP))
> +			continue;
> +
> +		/*
> +		 * ESP is only a fallback. If we have an ESP, but no bootloader spec
> +		 * files inside, this is not an error.
> +		 */
> +		ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
> +		if (ret >= 0)
> +			found += ret;
> +		else
> +			err = ret;
> +	}

Is it allowed to have multiple ESP partitions? If not we could save us
the additional loop and just store the ESP directly and make use of it.

Regards,
  Marco


> +
> +out:
>  	return found ?: err;
>  }
>  
> -- 
> 2.39.5
> 
> 
> 



More information about the barebox mailing list