Skip to contentSkip to conversation

cmd: gpt: backup boot code before writing MBR

PATCH New Andy Shevchenko 3 participants 3 messages Jan 30, 2017 – Feb 9, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: gpt: backup boot code before writing MBR

From: Vincent Tinelli <[email protected]>

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.

---
 disk/part_efi.c | 7 +++++++
 1 file changed, 7 insertions(+)
disk/part_efi.c +7 -0
index 19243380da..fcb267b42a 100644
@@ -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;
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 cmd: gpt: backup boot code before writing MBR

Quoted 6 lines · Andy Shevchenko

From: Vincent Tinelli <[email protected]>

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.

Quoted 8 lines

Preserve boot code area when run 'gpt write' command.

---
 disk/part_efi.c | 7 +++++++
 1 file changed, 7 insertions(+)
#2 lore raw

PATCH 1/1 cmd: gpt: backup boot code before writing MBR

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

From: Vincent Tinelli <[email protected]>

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.

Quoted 6 lines

Preserve boot code area when run 'gpt write' command.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170208/f2e23527/attachment.sig>