From patchwork Mon May 5 20:00:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Rae X-Patchwork-Id: 29666 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E1C222055D for ; Mon, 5 May 2014 20:00:55 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id cm18sf20537014qab.9 for ; Mon, 05 May 2014 13:00:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=uDG/uX1JDIhyK9EOPaMFXHywwLCD+q/v4GkvCcLyZkI=; b=Ni8jA00g1hwZHnKeQ2DZ9bZSlAEZ+zIhXLAO7/3+sM2iKhonfVCcHBfXbmouaR3j5j RItqhrV31LJN9G1hgi1FXMEzLaUT3EzSjJrqM5zuJxa3QlToFgVPbsTsFlPsnm2XOw/4 wf1rBXVP2F452y2Yl+He93Me261uErYrJ8ypt+Fo4BeHQio+lBcOqf+phN4qqX2dMq0y iMgDF2DWEPjVz1n4vcjsjl323bS8GFWXir73Vit38bYCLCdwC5+3532AAdY3Fgl7fRaj wXKaOE3KEexycAOfFEAC8mF1xHWmLivrZvdiwxclF7INjjnf7Q9RdlCWgfoDPN7FVWwD cFfQ== X-Gm-Message-State: ALoCoQmjciboLBGkLl8BIoAn/uuxYjW2xbx8R5K5ioCDQEbU081TqJcH6KglztML3vrEKH8jK6fP X-Received: by 10.236.134.235 with SMTP id s71mr3440850yhi.55.1399320055624; Mon, 05 May 2014 13:00:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.135 with SMTP id e7ls2679555qga.70.gmail; Mon, 05 May 2014 13:00:55 -0700 (PDT) X-Received: by 10.220.10.2 with SMTP id n2mr3788210vcn.26.1399320055486; Mon, 05 May 2014 13:00:55 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id z15si1814059vcj.144.2014.05.05.13.00.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 13:00:55 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id sa20so3188247veb.9 for ; Mon, 05 May 2014 13:00:55 -0700 (PDT) X-Received: by 10.220.12.66 with SMTP id w2mr29053683vcw.15.1399320055353; Mon, 05 May 2014 13:00:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp168020vcb; Mon, 5 May 2014 13:00:54 -0700 (PDT) X-Received: by 10.14.204.199 with SMTP id h47mr6316416eeo.48.1399320054417; Mon, 05 May 2014 13:00:54 -0700 (PDT) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id w48si11200178eel.116.2014.05.05.13.00.53 for ; Mon, 05 May 2014 13:00:54 -0700 (PDT) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 79DDA4B909; Mon, 5 May 2014 22:00:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QMlC3pg7RzG9; Mon, 5 May 2014 22:00:53 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 78AA74B8D9; Mon, 5 May 2014 22:00:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B301A4B8D9 for ; Mon, 5 May 2014 22:00:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7x81bw+cItZd for ; Mon, 5 May 2014 22:00:43 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-gw3-out.broadcom.com (mail-gw3-out.broadcom.com [216.31.210.64]) by theia.denx.de (Postfix) with ESMTP id 1DF804B87C for ; Mon, 5 May 2014 22:00:39 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.97,991,1389772800"; d="scan'208";a="27654232" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw3-out.broadcom.com with ESMTP; 05 May 2014 13:21:43 -0700 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Mon, 5 May 2014 13:00:24 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Mon, 5 May 2014 13:00:37 -0700 Received: from mail.broadcom.com (lbrmn-vmlnx03.ric.broadcom.com [10.136.4.105]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 69CC051EC1; Mon, 5 May 2014 13:00:20 -0700 (PDT) From: Steve Rae To: Date: Mon, 5 May 2014 13:00:08 -0700 Message-ID: <1399320008-3664-1-git-send-email-srae@broadcom.com> X-Mailer: git-send-email 1.8.5 MIME-Version: 1.0 Cc: Tom Rini , Steve Rae , Przemyslaw Marczak Subject: [U-Boot] [PATCH v3] disk: part_efi: add support for the Backup GPT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srae@broadcom.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Check the Backup GPT table if the Primary GPT table is invalid. Renamed "Secondary GPT" to "Backup GPT" as per: UEFI Specification (Version 2.3.1, Errata A) Signed-off-by: Steve Rae --- Changes in v3: - renamed: "Secondary GPT" to "Backup GPT" Changes in v2: - changed wording: "Alternate" to "Secondary" disk/part_efi.c | 22 +++++++++++++++++++--- doc/README.gpt | 14 +++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 216a292..c74b7b9 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -93,7 +93,15 @@ void print_part_efi(block_dev_desc_t * dev_desc) if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, &gpt_pte) != 1) { printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - return; + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), + gpt_head, &gpt_pte) != 1) { + printf("%s: *** ERROR: Invalid Backup GPT ***\n", + __func__); + return; + } else { + printf("%s: *** Using Backup GPT ***\n", + __func__); + } } debug("%s: gpt-entry at %p\n", __func__, gpt_pte); @@ -142,7 +150,15 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part, if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, &gpt_pte) != 1) { printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - return -1; + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), + gpt_head, &gpt_pte) != 1) { + printf("%s: *** ERROR: Invalid Backup GPT ***\n", + __func__); + return -1; + } else { + printf("%s: *** Using Backup GPT ***\n", + __func__); + } } if (part > le32_to_cpu(gpt_head->num_partition_entries) || @@ -252,7 +268,7 @@ int write_gpt_table(block_dev_desc_t *dev_desc, != pte_blk_cnt) goto err; - /* recalculate the values for the Second GPT Header */ + /* recalculate the values for the Backup GPT Header */ val = le64_to_cpu(gpt_h->my_lba); gpt_h->my_lba = gpt_h->alternate_lba; gpt_h->alternate_lba = cpu_to_le64(val); diff --git a/doc/README.gpt b/doc/README.gpt index f822894..ec0156d 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -66,14 +66,14 @@ GPT brief explanation: |Partition n | | | ---------------------------------------------------------- - LBA -34 |Entry 1|Entry 2| Entry 3| Entry 4| Secondary - -------------------------------------------------- (bkp) - LBA -33 |Entries 5 - 128 | GPT + LBA -34 |Entry 1|Entry 2| Entry 3| Entry 4| Backup + -------------------------------------------------- GPT + LBA -33 |Entries 5 - 128 | | | | | LBA -2 | | -------------------------------------------------- - LBA -1 |Secondary GPT Header | + LBA -1 |Backup GPT Header | ---------------------------------------------------------- For a legacy reasons, GPT's LBA 0 sector has a MBR structure. It is called @@ -86,7 +86,7 @@ It is possible to define 128 linearly placed partition entries. "LBA -1" means the last addressable block (in the mmc subsystem: "dev_desc->lba - 1") -Primary/Secondary GPT header: +Primary/Backup GPT header: ---------------------------- Offset Size Description @@ -115,7 +115,7 @@ IMPORTANT: GPT headers and partition entries are protected by CRC32 (the POSIX CRC32). -Primary GPT header and Secondary GPT header have swapped values of "Current LBA" +Primary GPT header and Backup GPT header have swapped values of "Current LBA" and "Backup LBA" and therefore different CRC32 check-sum. CRC32 for GPT headers (field "CRC of header") are calculated up till @@ -125,7 +125,7 @@ CRC32 for partition entries (field "CRC32 of partition array") is calculated for the whole array entry ( Number_of_partition_entries * sizeof(partition_entry_size (usually 128))) -Observe, how Secondary GPT is placed in the memory. It is NOT a mirror reflect +Observe, how Backup GPT is placed in the memory. It is NOT a mirror reflect of the Primary. Partition Entry Format: