From patchwork Sun Sep 10 11:21:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812100 X-Patchwork-Delegate: trini@ti.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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="orpQzgyM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqpdT6KWTz9sDB for ; Sun, 10 Sep 2017 21:25:33 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4E0BAC21EFC; Sun, 10 Sep 2017 11:24:39 +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_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 8E417C21E3C; Sun, 10 Sep 2017 11:23:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 65C4AC21DC0; Sun, 10 Sep 2017 11:22:17 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by lists.denx.de (Postfix) with ESMTPS id 04505C21E8C for ; Sun, 10 Sep 2017 11:22:17 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id u48so1198296qtc.4 for ; Sun, 10 Sep 2017 04:22:16 -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; bh=N/1LcwQBUoQENr/+iFWcEOcDPh1ttcWhW5ycw5XCRxU=; b=orpQzgyMiXsmEXHWwRw7C/iNs5RgQp8NiaxpwjLJXvBgJXlnl++VgDqG0M+a3+shEH +yieLdy1tpz5kIFZsRsbO1WDROfyvn432sXVTDj6MV1inB9DlocCpsRi+thPT87cqUNZ k3sepI81nmDrh3RJVvDs4O92H7O4MB7FqSh7JZrcnL5zb1/+4FyJsAPoRNzTD7J++0Wi xciqxsThh1u3HqDVqtz8Q5y+lLae2TjS+ZKJJp64ZJhT6dxGvICkIZTTpqBbJVxdGXtL OgLuQGXkqan4Bu6bb5CTkzRg4fDG42P/6XT5JbdA6l4y1W+2/1krNqZCjQEQXo6Lfl52 9bWw== 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; bh=N/1LcwQBUoQENr/+iFWcEOcDPh1ttcWhW5ycw5XCRxU=; b=tvY8c9u4IZ/EEcMHUOOchgkAPd4R+Np/Uv7J/N1ZAjbkihYbn08c6NCvYtynOZhahk binM9bI37ALX7SAI5AtnZ2DMoCb4H5BF9tPIPFa+Gqv21PMOaoI6XWB2I7ucEI8Elh7i H3tXNaWser50vXgA+faiLkeSWnsooLEw/QQQDPWUsH3nipeEs8hoxv/rvUJZOw4TwZn1 l8gVRlYgQzTmF3WuwFtEYfiwpex7a9qt0BcqpYymI/mcJwZOFtq765gpVKH6utbukz8X uj1CIbxVTCHG6wcg6Vzlrrett/aTajjZy2Ngs42D+F1qvZP2z0+h1Mx1OxA2hAcJPZkr Z42Q== X-Gm-Message-State: AHPjjUj4TNoxPoYxqzcsb/fkZxHfOsm04j3MLw13b7s+GZm+rsXkA7gB jpsmborBgCRmnMgEds0= X-Google-Smtp-Source: AOwi7QDgm6FaXodRU53i8jBXEJNfeyKKlGiGJITn7cy1hUI1knasnzcbGkWzODAjdSRbWJS1JkqtuA== X-Received: by 10.200.45.195 with SMTP id q3mr11246721qta.43.1505042535745; Sun, 10 Sep 2017 04:22:15 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id g132sm4083884qke.11.2017.09.10.04.22.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:22:14 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:21 -0400 Message-Id: <20170910112149.21358-5-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com> References: <20170910112149.21358-1-robdclark@gmail.com> Cc: Petr Kulhavy , Heinrich Schuchardt , Wenbin Song , Alison Chaiken , Peter Jones , Zhikang Zhang , Vincent Tinelli , Steve Rae , Maxime Ripard Subject: [U-Boot] [PATCH v2 02/21] part: extract MBR signature from partitions 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Peter Jones EFI client programs need the signature information from the partition table to determine the disk a partition is on, so we need to fill that in here. Signed-off-by: Peter Jones [separated from efi_loader part, and fixed build-errors for non- CONFIG_EFI_PARTITION case] Signed-off-by: Rob Clark Reviewed-by: Simon Glass --- disk/part_dos.c | 12 +++++++++--- disk/part_efi.c | 20 ++++++++++++++++++++ include/blk.h | 15 +++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/disk/part_dos.c b/disk/part_dos.c index 7ede15ec26..850a538e83 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -89,14 +89,20 @@ static int test_block_type(unsigned char *buffer) static int part_test_dos(struct blk_desc *dev_desc) { - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz); - if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1) + if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) return -1; - if (test_block_type(buffer) != DOS_MBR) + if (test_block_type((unsigned char *)mbr) != DOS_MBR) return -1; + if (dev_desc->sig_type == SIG_TYPE_NONE && + mbr->unique_mbr_signature != 0) { + dev_desc->sig_type = SIG_TYPE_MBR; + dev_desc->mbr_sig = mbr->unique_mbr_signature; + } + return 0; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 2973d52f6a..208bb14ee8 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -923,11 +923,19 @@ static int is_pmbr_valid(legacy_mbr * mbr) static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, gpt_header *pgpt_head, gpt_entry **pgpt_pte) { + ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz); + if (!dev_desc || !pgpt_head) { printf("%s: Invalid Argument(s)\n", __func__); return 0; } + /* Read MBR Header from device */ + if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) { + printf("*** ERROR: Can't read MBR header ***\n"); + return 0; + } + /* Read GPT Header from device */ if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) { printf("*** ERROR: Can't read GPT header ***\n"); @@ -937,6 +945,18 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) return 0; + if (dev_desc->sig_type == SIG_TYPE_NONE) { + efi_guid_t empty = {}; + if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) { + dev_desc->sig_type = SIG_TYPE_GUID; + memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, + sizeof(empty)); + } else if (mbr->unique_mbr_signature != 0) { + dev_desc->sig_type = SIG_TYPE_MBR; + dev_desc->mbr_sig = mbr->unique_mbr_signature; + } + } + /* Read and allocate Partition Table Entries */ *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); if (*pgpt_pte == NULL) { diff --git a/include/blk.h b/include/blk.h index a106f9ca0e..3c59fdb3d4 100644 --- a/include/blk.h +++ b/include/blk.h @@ -8,6 +8,8 @@ #ifndef BLK_H #define BLK_H +#include + #ifdef CONFIG_SYS_64BIT_LBA typedef uint64_t lbaint_t; #define LBAFlength "ll" @@ -36,6 +38,14 @@ enum if_type { IF_TYPE_COUNT, /* Number of interface types */ }; +enum sig_type { + SIG_TYPE_NONE, + SIG_TYPE_MBR, + SIG_TYPE_GUID, + + SIG_TYPE_COUNT /* Number of signature types */ +}; + /* * With driver model (CONFIG_BLK) this is uclass platform data, accessible * with dev_get_uclass_platdata(dev) @@ -63,6 +73,11 @@ struct blk_desc { char vendor[40+1]; /* IDE model, SCSI Vendor */ char product[20+1]; /* IDE Serial no, SCSI product */ char revision[8+1]; /* firmware revision */ + enum sig_type sig_type; /* Partition table signature type */ + union { + uint32_t mbr_sig; /* MBR integer signature */ + efi_guid_t guid_sig; /* GPT GUID Signature */ + }; #if CONFIG_IS_ENABLED(BLK) /* * For now we have a few functions which take struct blk_desc as a