[PATCH v2 1/4] partitions: efi: add support to specify gpt-location

Sascha Hauer s.hauer at pengutronix.de
Thu Apr 24 05:08:44 PDT 2025


On Wed, Apr 23, 2025 at 04:09:10PM +0200, Marco Felsch wrote:
> -static __maybe_unused struct partition_desc *efi_partition_create_table(struct block_device *blk)
> +static __maybe_unused struct partition_desc *
> +efi_partition_create_table(struct block_device *blk, sector_t gpt_location)
>  {
>  	struct efi_partition_desc *epd = xzalloc(sizeof(*epd));
>  	gpt_header *gpt;
>  
> +	if (gpt_location < 2) {
> +		pr_err("Invalid starting LBA (%llu) of array of partition entries\n",
> +		       gpt_location);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>  	partition_desc_init(&epd->pd, blk);
>  
>  	epd->gpt = xzalloc(512);
> @@ -594,10 +601,10 @@ static __maybe_unused struct partition_desc *efi_partition_create_table(struct b
>  	gpt->header_size = cpu_to_le32(sizeof(*gpt));
>  	gpt->my_lba = cpu_to_le64(1);
>  	gpt->alternate_lba = cpu_to_le64(last_lba(blk));
> -	gpt->first_usable_lba = cpu_to_le64(34);
> +	gpt->first_usable_lba = cpu_to_le64(gpt_location + 32);

Since you are changing this default you should also check against
gpt->first_usable_lba in efi_partition_mkpart():

	if (start_lba < 34) {
		pr_err("invalid start LBA %lld, minimum is 34\n", start_lba);
		return -EINVAL;
	}

We should have done that from the start, but now that you are touching
it it's your turn ;)

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list