From b7b865cfee68190babd971ab9a897bdabbab075f Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 23 Aug 2012 15:06:25 -0700 Subject: Support alternative GPT header signature In order to dual boot Windows and ChromeOS, Windows must not find a GPT partition table on the disk. So change ChromeOS to cope with an alternative signature "CHROMEOS" instead of the standard "EFI PART" BUG=chrome-os-partner:6108 TEST=rebuild chromeos, install it, run cgpt legacy /dev/sda dd if=/dev/sda of=/tmp/x bs=1k hexdump -C /tmp/X see the string CHROMEOS BRANCH=link Signed-off-by: Stefan Reinauer Change-Id: Ia88eff33b9880bd73a78c1b8e026c1f8298c4557 Reviewed-on: https://gerrit.chromium.org/gerrit/31264 Reviewed-by: Randall Spangler Commit-Ready: Stefan Reinauer Tested-by: Stefan Reinauer --- cgpt/cgpt_common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'cgpt/cgpt_common.c') diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c index d69eb670..193f2e1e 100644 --- a/cgpt/cgpt_common.c +++ b/cgpt/cgpt_common.c @@ -733,7 +733,9 @@ void UpdateCrc(GptData *gpt) { primary_header = (GptHeader*)gpt->primary_header; secondary_header = (GptHeader*)gpt->secondary_header; - if (gpt->modified & GPT_MODIFIED_ENTRIES1) { + if (gpt->modified & GPT_MODIFIED_ENTRIES1 && + memcmp(primary_header, GPT_HEADER_SIGNATURE2, + GPT_HEADER_SIGNATURE_SIZE)) { primary_header->entries_crc32 = Crc32(gpt->primary_entries, TOTAL_ENTRIES_SIZE); } @@ -785,6 +787,14 @@ int IsSynonymous(const GptHeader* a, const GptHeader* b) { * Note that CRC is NOT re-computed in this function. */ uint8_t RepairEntries(GptData *gpt, const uint32_t valid_entries) { + /* If we have an alternate GPT header signature, don't overwrite + * the secondary GPT with the primary one as that might wipe the + * partition table. Also don't overwrite the primary one with the + * secondary one as that will stop Windows from booting. */ + GptHeader* h = (GptHeader*)(gpt->primary_header); + if (!memcmp(h->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE)) + return 0; + if (valid_entries == MASK_BOTH) { if (memcmp(gpt->primary_entries, gpt->secondary_entries, TOTAL_ENTRIES_SIZE)) { -- cgit v1.2.3