[PATCH 6/6] partitions: gpt: refresh partition tables when necessary

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Dec 15 04:47:09 PST 2025


Hi,

On 12/3/25 4:19 PM, Sascha Hauer wrote:
> The GPT alternative header must be at the end of the device. When disk
> images are written to a device this often is not the case which results
> in warnings:
> 
> WARNING: mmc0: GPT:Primary header thinks Alt. header is not at the end of the disk.
> WARNING: mmc0: GPT:6561831 != 62160895
> WARNING: mmc0: GPT:Alternate GPT header not at the end of the disk.
> WARNING: mmc0: GPT:6561831 != 62160895
> WARNING: mmc0: GPT: Use parted to correct GPT errors.
> 
> This patch adds support for automatically rewriting the partition table
> when this happens. This behaviour is optional and needs to be enabled at
> compile time with CONFIG_PARTITION_DISK_EFI_REFRESH. Also this is
> runtime configurable with global.system.gpt_refresh
> 
> Link: https://lore.barebox.org/20251128111929.2463263-1-s.hauer@pengutronix.de
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

With below point addressed:

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>


> -	if (error_found)
> +	if (error_found) {
> +		add_gpt_refresh(blk);
>  		dev_warn(dev, "GPT: Use parted to correct GPT errors.\n");

With CONFIG_PARTITION_DISK_EFI_REFRESH enabled, I would suggest changing
this to a dev_info(dev, "GPT: barebox will autocorrect.\n") or something.

> +	}
> +
>  	return;
>  }
>  
> @@ -424,7 +519,7 @@ static int find_valid_gpt(struct efi_partition_desc *epd, void *buf)
>  		goto fail;
>  
>  	if (IS_ENABLED(CONFIG_PARTITION_DISK_EFI_GPT_COMPARE))
> -		compare_gpts(blk->dev, pgpt, agpt, lastlba);
> +		compare_gpts(blk, pgpt, agpt, lastlba);
>  
>  	epd->good_pgpt = good_pgpt;
>  	epd->good_agpt = good_agpt;
> @@ -874,8 +969,16 @@ static struct partition_parser efi_partition_parser = {
>  	.name = "gpt",
>  };
>  
> +#ifdef CONFIG_PARTITION_DISK_EFI_REFRESH
> +BAREBOX_MAGICVAR(global.system.gpt_refresh, "When true, refresh GPT partitions when necessary");
> +#endif
> +
>  static int efi_partition_init(void)
>  {
> +	if (IS_ENABLED(CONFIG_PARTITION_DISK_EFI_REFRESH))
> +		globalvar_add_simple_bool("system.gpt_refresh",
> +					  &global_gpt_refresh);
> +
>  	return partition_parser_register(&efi_partition_parser);
>  }
>  postconsole_initcall(efi_partition_init);
> 

-- 
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