Hi, On 12/3/25 4:19 PM, Sascha Hauer wrote: > There are two GPT partition tables on a device, the primary at the > beginning of a device and the alternate at the end of the device. > > For the sake of being more robust against power failures let's write the > inactive GPT first and the currently active one afterwards. This always > leaves us a usable GPT on the device when updating the partition table. > > Signed-off-by: Sascha Hauer <[email protected]>
Reviewed-by: Ahmad Fatoum <[email protected]> > --- > common/partitions/efi.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/common/partitions/efi.c b/common/partitions/efi.c > index > 8da62acf36646b62ff2fac25673adbc48650d299..1766f0123353d502065673d02e983e6cdd51b9af > 100644 > --- a/common/partitions/efi.c > +++ b/common/partitions/efi.c > @@ -27,6 +27,8 @@ struct efi_partition_desc { > gpt_header *gpt; > gpt_entry *ptes; > struct param_d *param_guid; > + bool good_pgpt; > + bool good_agpt; > }; > > struct efi_partition { > @@ -424,6 +426,9 @@ static int find_valid_gpt(struct efi_partition_desc *epd, > void *buf) > if (IS_ENABLED(CONFIG_PARTITION_DISK_EFI_GPT_COMPARE)) > compare_gpts(blk->dev, pgpt, agpt, lastlba); > > + epd->good_pgpt = good_pgpt; > + epd->good_agpt = good_agpt; > + > /* The good cases */ > if (good_pgpt) { > epd->gpt = pgpt; > @@ -810,11 +815,11 @@ static __maybe_unused int efi_partition_write(struct > partition_desc *pd) > if (ret) > return ret; > > - ret = __efi_partition_write(epd, true); > + ret = __efi_partition_write(epd, !epd->good_pgpt); > if (ret) > goto err_block_write; > > - ret = __efi_partition_write(epd, false); > + ret = __efi_partition_write(epd, epd->good_pgpt); > if (ret) > goto err_block_write; > > -- 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 |
