From: Vincent Tinelli Date: Mon, 30 Jan 2017 12:46:07 +0000 (+0300) Subject: cmd: gpt: backup boot code before writing MBR X-Git-Tag: v2017.03-rc2~33 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e163a931af34ba06d11b98707b69b8819e353257;p=oweals%2Fu-boot.git cmd: gpt: backup boot code before writing MBR On some cases the first 440 bytes of MBR are used to keep an additional information for ROM boot loader. 'gpt write' command doesn't preserve that area and makes boot code gone. Preserve boot code area when run 'gpt write' command. Signed-off-by: Vincent Tinelli Signed-off-by: Brennan Ashton Signed-off-by: Andy Shevchenko Reviewed-by: Simon Glass --- diff --git a/disk/part_efi.c b/disk/part_efi.c index b5928e5abe..893cbbdbda 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -324,6 +324,13 @@ static int set_protective_mbr(struct blk_desc *dev_desc) printf("%s: calloc failed!\n", __func__); return -1; } + + /* Read MBR to backup boot code if it exists */ + if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) { + error("** Can't read from device %d **\n", dev_desc->devnum); + return -1; + } + /* Append signature */ p_mbr->signature = MSDOS_MBR_SIGNATURE; p_mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT;