[U-Boot] [PATCH v1] cmd: gpt: backup boot code before writing MBR

From: Vincent Tinelli vincent.tinelli@intel.com
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 vincent.tinelli@intel.com Signed-off-by: Brennan Ashton brn@deako.com Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- disk/part_efi.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/disk/part_efi.c b/disk/part_efi.c index 19243380da..fcb267b42a 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;

On 30 January 2017 at 04:46, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
From: Vincent Tinelli vincent.tinelli@intel.com
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 vincent.tinelli@intel.com Signed-off-by: Brennan Ashton brn@deako.com Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
disk/part_efi.c | 7 +++++++ 1 file changed, 7 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Mon, Jan 30, 2017 at 03:46:07PM +0300, Andy Shevchenko wrote:
From: Vincent Tinelli vincent.tinelli@intel.com
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 vincent.tinelli@intel.com Signed-off-by: Brennan Ashton brn@deako.com Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
participants (3)
-
Andy Shevchenko
-
Simon Glass
-
Tom Rini