From patchwork Wed Apr 3 12:25:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Urja Rannikko X-Patchwork-Id: 1075875 X-Patchwork-Delegate: philipp.tomsich@theobroma-systems.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DgLAUBCf"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Z4zh4l0Dz9sSQ for ; Wed, 3 Apr 2019 23:25:36 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4FC98C21EC2; Wed, 3 Apr 2019 12:25:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0D718C21E2C; Wed, 3 Apr 2019 12:25:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B340BC21E2C; Wed, 3 Apr 2019 12:25:27 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by lists.denx.de (Postfix) with ESMTPS id 5CDFFC21E07 for ; Wed, 3 Apr 2019 12:25:27 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id w1so21100819wrp.2 for ; Wed, 03 Apr 2019 05:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=14hLZH/JN2oVyP+2Tc3zmxM3fdVzaVP56fJI/nIhCCQ=; b=DgLAUBCfUE3n8fvHLydFIzkMEFYhfC2tfYN635ROCRQUM7DXkhug67lJC5T667RFdh 3lOKxdlBYmj4cwiftAhGB+0NyYItnczzy6zG2dfcrSSBnMhzoGMArF8ncYe4eZW7gQyi c+MAnjp2obZAUTZ2LOlFY+Qn/3OzXsjacJbWN0nrFGiScJXDDjAffJ0/GVriNis9f2DO dbAHTt1G+bz7Y0MsrE9jMmaqcicOqakNsnDRsnx+A6guWyHErKXTr0URrhUgSa4vc9CX 9Q79/ASHukpBTfeUuUuVev8XTVb6V47o8RxFYlFqYqTmin8jvotZgXp+mC7O7s/yHrJs 8x6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=14hLZH/JN2oVyP+2Tc3zmxM3fdVzaVP56fJI/nIhCCQ=; b=YIqNQeqYolF5w0/bK5QBk0iPqW4f8kFda9VWsBUqKI9QRqOvmTHjcOk/0Pjomh1C+g Oz4m6ml39/1VdtDkLfiDP8BgBQETj5XVUwFWu8N1H0FNPm7tQEFtdHx8GsddwSXVr+p3 V5ZvgBt5McY945CCxnZ6FmTbESwLMVV0IhWEHke3tTT1TsUpB7haP3kpMjneWXUlxxng 5BkajBK3MNjtl8MPnuZNGEN40CAb3LRr9Clx+JyNg3dGCdZs9/BbUVs+HxadicPQ0EIa O3mGsKgtrqf8f2nf1OGaVtBbAFdIZoX006T46siUd0jh2CEC1zaUEvQuq0s0zFuv/nz9 fTZw== X-Gm-Message-State: APjAAAWApd1NbWrZOvh0/lnFCYMDlFocSCJ4ZuZYjGe9pqrvktZgdycx n8w4dqqJgnujl4yXJzeENo4fvOyUdA== X-Google-Smtp-Source: APXvYqxRRRXaZeU+v3txulg2Z3mq58UgFZIaUhry8junEcaLm0w1mpLJ8sYMznU5/F3ouZ3XwSY0xA== X-Received: by 2002:adf:e951:: with SMTP id m17mr31001920wrn.287.1554294326847; Wed, 03 Apr 2019 05:25:26 -0700 (PDT) Received: from localhost.localdomain (esm-84-240-79-214.netplaza.fi. [84.240.79.214]) by smtp.gmail.com with ESMTPSA id u189sm9146673wme.25.2019.04.03.05.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 05:25:26 -0700 (PDT) From: Urja Rannikko To: u-boot@lists.denx.de Date: Wed, 3 Apr 2019 12:25:21 +0000 Message-Id: <20190403122522.1307-1-urjaman@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: xypron.glpk@gmx.de Subject: [U-Boot] [PATCH 1/2] disk: efi: unify code for finding a valid gpt X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" There were 3 copies of the same sequence, make it into a function. Signed-off-by: Urja Rannikko Reviewed-by: Simon Glass --- disk/part_efi.c | 73 +++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 239455b816..5f935da4c2 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -51,6 +51,8 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, gpt_header *pgpt_head); static int is_pte_valid(gpt_entry * pte); +static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, + gpt_entry **pgpt_pte); static char *print_efiname(gpt_entry *pte) { @@ -192,19 +194,8 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid) unsigned char *guid_bin; /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - if (is_gpt_valid(dev_desc, dev_desc->lba - 1, - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid Backup GPT ***\n", - __func__); - return -EINVAL; - } else { - printf("%s: *** Using Backup GPT ***\n", - __func__); - } - } + if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + return -EINVAL; guid_bin = gpt_head->disk_guid.b; uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID); @@ -221,19 +212,8 @@ void part_print_efi(struct blk_desc *dev_desc) unsigned char *uuid_bin; /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - 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__); - } - } + if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + return; debug("%s: gpt-entry at %p\n", __func__, gpt_pte); @@ -282,19 +262,8 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, } /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, &gpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - 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 (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + return -1; if (part > le32_to_cpu(gpt_head->num_partition_entries) || !is_pte_valid(&gpt_pte[part - 1])) { @@ -981,6 +950,32 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, return 1; } +/** + * find_valid_gpt() - finds a valid GPT header and PTEs + * + * gpt is a GPT header ptr, filled on return. + * ptes is a PTEs ptr, filled on return. + * + * Description: returns 1 if found a valid gpt, 0 on error. + * If valid, returns pointers to PTEs. + */ +static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, + gpt_entry **pgpt_pte) +{ + if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, + gpt_head, pgpt_pte) != 1) { + printf("%s: *** ERROR: Invalid GPT ***\n", __func__); + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), + gpt_head, pgpt_pte) != 1) { + printf("%s: *** ERROR: Invalid Backup GPT ***\n", + __func__); + return 0; + } + printf("%s: *** Using Backup GPT ***\n", __func__); + } + return 1; +} + /** * alloc_read_gpt_entries(): reads partition entries from disk * @dev_desc From patchwork Wed Apr 3 12:25:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Urja Rannikko X-Patchwork-Id: 1075876 X-Patchwork-Delegate: philipp.tomsich@theobroma-systems.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EhIf/HQR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Z50B2Zffz9sSQ for ; Wed, 3 Apr 2019 23:26:02 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D7BE7C21F19; Wed, 3 Apr 2019 12:25:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 71D20C21EC3; Wed, 3 Apr 2019 12:25:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 917BDC21F20; Wed, 3 Apr 2019 12:25:38 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by lists.denx.de (Postfix) with ESMTPS id B36DAC21F32 for ; Wed, 3 Apr 2019 12:25:34 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id c1so7164973wml.4 for ; Wed, 03 Apr 2019 05:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZudtQ9HZBUJQnkeMmtrc4pax0aAy/Bh2ubeMCetiMfo=; b=EhIf/HQRGEYG24FTKZl5m8oILmfHN+hbIgf6NFmKmm/YX/S020L91GhkuN58GIhHdH A5SNlC2bUCDQ75n2tUT3JVr7T0FfqMVmSJexkg9cWukbvZ9pnJcKkFBGJvZ2p5ZFmkcu rhCmDxhw7TnSbxo6Mq8UVgV7lxWaijAVg9Uxu9LrNP8e+s8k4MNoDwDLCJtd1p/D6bxN d7YEnu5Jwyi9tsXTkJWt4Fp2m1BTqy/YomiOHOX3QE99zEvVDjRfJ/7IaWFGSi7UWR6H CVSslDFjKrKmE+Yhfd/irYoxEY9Ql2rEDmSWINBX66zD5NPYssT6zdCskNUXUpDqs+mK cc2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZudtQ9HZBUJQnkeMmtrc4pax0aAy/Bh2ubeMCetiMfo=; b=WhDFBH3860uQCwSPGfa9+5YrY7hLXSFefzkAzybdJ620rAN4NGLov/PqDoeiY7D3vj 5F3aMu7KWwRbFc4pyCsgCyr2TPf8C4AiQWxJIVYziwbwqjRMB9ikGqnio5WlzP21J8Cf 6XSlXarAY2cWPZhKy+QQDMV+oHXQ2KuEudM2lP1TWRZgGMC34MD4EVRvcrMIVXxr6AuZ i4b5pBJQgjKHhEuhX6trVH6QZNav60mbeIHJ/gWa5OJGnG3rghk6lWu8AdQPI0B9WPmm nn4NHksnGd3aYrABDSxIeMRzeWZ3vUS2RMlup9MAgFXdGErRCsMOOELdts9adS+pKrLJ K/eQ== X-Gm-Message-State: APjAAAWCbax6ozsBf/HxTTp+XVaSEiib5pjpzPrF0q1XGSwbjjdVqJqZ 1mtBLcZl2Vlt9fyndmkdTcvYX0d+4w== X-Google-Smtp-Source: APXvYqzrhoHDVgHLw6JRmWNaIZDNfI0p5xLINB0FTYovO9vHvk0gsyYT3xLlBJcs6Ypp88HI0gazDg== X-Received: by 2002:a1c:1d4:: with SMTP id 203mr1999018wmb.101.1554294334211; Wed, 03 Apr 2019 05:25:34 -0700 (PDT) Received: from localhost.localdomain (esm-84-240-79-214.netplaza.fi. [84.240.79.214]) by smtp.gmail.com with ESMTPSA id u189sm9146673wme.25.2019.04.03.05.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 05:25:33 -0700 (PDT) From: Urja Rannikko To: u-boot@lists.denx.de Date: Wed, 3 Apr 2019 12:25:22 +0000 Message-Id: <20190403122522.1307-2-urjaman@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190403122522.1307-1-urjaman@gmail.com> References: <20190403122522.1307-1-urjaman@gmail.com> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de Subject: [U-Boot] [PATCH 2/2] disk: efi: ignore 'IGNOREME' GPT header found on cros eMMCs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some ChromeOS devices (atleast veyron speedy) have the first 8MiB of the eMMC write protected and equipped with a dummy 'IGNOREME' GPT header - instead of spewing error messages about it, just silently try the backup GPT. Note: this does not touch the gpt cmd writing/verifying functions, those will still complain. Signed-off-by: Urja Rannikko --- disk/part_efi.c | 28 +++++++++++++++++++++------- include/part_efi.h | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 5f935da4c2..83ba7db665 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -893,7 +893,7 @@ static int is_pmbr_valid(legacy_mbr * mbr) * gpt is a GPT header ptr, filled on return. * ptes is a PTEs ptr, filled on return. * - * Description: returns 1 if valid, 0 on error. + * Description: returns 1 if valid, 0 on error, 2 if ignored header * If valid, returns pointers to PTEs. */ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, @@ -919,6 +919,12 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, return 0; } + /* Invalid but nothing to yell about. */ + if (le64_to_cpu(pgpt_head->signature) == GPT_HEADER_CHROMEOS_IGNORE) { + debug("ChromeOS 'IGNOREME' GPT header found and ignored\n"); + return 2; + } + if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) return 0; @@ -962,16 +968,24 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, gpt_entry **pgpt_pte) { - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - gpt_head, pgpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __func__); - if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), - gpt_head, pgpt_pte) != 1) { + int r; + + r = is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, + pgpt_pte); + + if (r != 1) { + if (r != 2) + printf("%s: *** ERROR: Invalid GPT ***\n", __func__); + + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), gpt_head, + pgpt_pte) != 1) { printf("%s: *** ERROR: Invalid Backup GPT ***\n", __func__); return 0; } - printf("%s: *** Using Backup GPT ***\n", __func__); + if (r != 2) + printf("%s: *** Using Backup GPT ***\n", + __func__); } return 1; } diff --git a/include/part_efi.h b/include/part_efi.h index 7170b61c95..eb5797af74 100644 --- a/include/part_efi.h +++ b/include/part_efi.h @@ -25,6 +25,8 @@ #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE #define GPT_HEADER_SIGNATURE_UBOOT 0x5452415020494645ULL +#define GPT_HEADER_CHROMEOS_IGNORE 0x454d45524f4e4749ULL // 'IGNOREME' + #define GPT_HEADER_REVISION_V1 0x00010000 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL #define GPT_ENTRY_NUMBERS CONFIG_EFI_PARTITION_ENTRIES_NUMBERS