From patchwork Thu Mar 19 16:56:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1258328 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=cpPsb0lw; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jtPW3CNXz9sPR for ; Fri, 20 Mar 2020 03:57:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1199081717; Thu, 19 Mar 2020 17:57:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="cpPsb0lw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BDEF81286; Thu, 19 Mar 2020 17:57:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0EC5481286 for ; Thu, 19 Mar 2020 17:56:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584637001; bh=Tm6SKiFL8BkZpr8MgBOKQ/9US0lx2Ny8WjBuqqAv7Cw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cpPsb0lwvlkoGkn+fNV14qu5o1FRiL83oSbYEbFDtLiK96L+BHsWLRauTJuXNszp3 t/WHmUKv/QSIlb/EpF77f0ohaVMxhh+XkzIWZhtW1e4KbW7DxlzNgTtW56+tRmWKP/ cf0aEYVoztYDQgQpF0e8iJvL/2qAdIRX/24rdeXU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from rpi3.fritz.box ([84.119.33.226]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MXGr8-1imz4g3B1i-00YhHa; Thu, 19 Mar 2020 17:56:40 +0100 From: Heinrich Schuchardt To: AKASHI Takahiro Cc: Alexander Graf , Ilias Apalodimas , Paul Emge , Faiz Abbas , Alexey Brodkin , Eugeniu Rosca , Kever Yang , Urja Rannikko , Sam Protsenko , Ruslan Trofymenko , Igor Opaniuk , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/2] part: detect EFI system partition Date: Thu, 19 Mar 2020 16:56:31 +0000 Message-Id: <20200319165632.14014-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200319165632.14014-1-xypron.glpk@gmx.de> References: <20200319165632.14014-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:uL6d2Jriz17XQk3kjC7PzZV/IICNkD70s6OxGRVzxoqoSL0Dj6V qv/jssKzdFKz2MkCN23UX7D+igeuop7V6Z6v7h8AS3T7ZgEkT7kH4b/mTmPbZ06bLxm7wiS G8DF/ey0dt0VyM9cB7nzzi8townhGzPfkEAZzuqJRhvviRVdD+SpxxLgBOC5tCnDh5vZIhv +Z+jTC4AkBrLmUBvqmGAA== X-UI-Out-Filterresults: notjunk:1; V03:K0:TK/C/ulZGBw=:mH5nKzXzfNHJl654wYXNNK AYE0/4T7AJ7q36SvCHrORoXccPxV58ZvHZmCflyYdqzti+rp4hKvog0E28llUovacqK7qCyYK CHT5xyK7W+riPU+yrKu/MKNi4zDj8bbaQWEp0t2L1jcrxFJaCmT08GsYT6CmpHDzxdz67pwEB HgiyNbtkmg/eqhEqBO5b6KAwt//naxd6RwhvhIm9AdIBbWKZUMX5T/V2o4MYN/JgeAZ1GW1AV LG4dyYIm+Aoys5HuhsGwHlw+FcfY4TNo2C31NdMVPrEHNl1UXsB+W4V1hCMFzK8CCu62HaWea FQF051hX43umIwUMGxa0tf5fGWlxTMlJEKGHymi9JAgSeovGpRw6DQp/UOmOFudhfkP6v8SW/ 64qCYzIuGjX3sGEGO1477UxF0huM2zXts6XQ3gVps30h/zjRy0jeLxOSvg5vyAAB75SFBlX2F 6FsWSQluDc/iB2Ly1XB2l95W5Gqv94rcZbuAz7t4gDbEP5AqrNbaada4I9wghP4pp6YN9TFeU khVKCwHpzTFH6NNr0qYl7+4xLo4+d0v9MjYrWUoH9xTvTeQVK8wMKnot6nq3VQyvQ3jUPrnjd fyX7ZwLufHkahPwIA+82o7fs+qw2FIIY5scHgYqeYspTTceSkShg+dX+pHbOdj2/sD6XQyYOc EsSjUVUnmmJT2fOM+2eS9vqYXhEJbazcYJmEmYcmelR5QZvh6ghfDizbiH4JiGTuBPhxC1T/8 fL15CYMI3l7WTe0ZvdfjhaXKXZaMZ6NG6am4c/Lg9GUux/J7JVuHLxyyrxrP1tvS/FNm4GNgz fuvMujPnyKWCB2p5BcnGgwPBtNKO/jVBYQM52jIBvNFPnY8EdQAKTqB0AsBFS8EMNQgSYFYVN 65WOJNCsfLVENvdtRHce2gb25Hxnkuz21UX300iwKOCxmZyyx16eZjeKLFZh4ld19G1LHbklZ wotiLvq9quIA9E43QrXAGFt7U12u6ZP43Uh6wDrcQVWU8bPhbIjuCAlPNbaQQXrEc05kPp5oO gvXAtOSiT1ChxxTl8gFxFEkuy7x+3N8N/fdg5aFTVV23UuvKspbOwz8iBLFEcDG2oYj/chxSV CghLmRTIJFUmH9DWxIsAaqGXxTT4nP8mkkgOhieDt1Fhfb403HvxgjKWWvJaeAPP450s6sRzP 94eVmAAwIv3yWak0IUxYwKgVouscy/4UdBUXbDUAAuIHi9A2kP2CfFkXTyQSnalchcgXdEKNt 7XwwKcxSTBlpUQVqH X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean Up to now for MBR and GPT partitions the info field 'bootable' was set to 1 if either the partition was an EFI system partition or the bootable flag was set. Turn info field 'bootable' into a bit mask with separate bits for bootable and EFI system partition. This will allow us to identify the EFI system partition in the UEFI sub-system. Signed-off-by: Heinrich Schuchardt --- disk/part_dos.c | 10 ++++++++-- disk/part_efi.c | 12 ++++++++---- include/part.h | 11 ++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/disk/part_dos.c b/disk/part_dos.c index 83ff40d310..0ec7f1628e 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -45,9 +45,15 @@ static inline int is_extended(int part_type) part_type == 0x85); } -static inline int is_bootable(dos_partition_t *p) +static int is_bootable(dos_partition_t *p) { - return (p->sys_ind == 0xef) || (p->boot_ind == 0x80); + int ret = 0; + + if (p->sys_ind == 0xef) + ret |= PART_EFI_SYSTEM_PARTITION; + if (p->boot_ind == 0x80) + ret |= PART_BOOTABLE; + return ret; } static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector, diff --git a/disk/part_efi.c b/disk/part_efi.c index b2e157d9c1..19f1f43f4e 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -71,11 +71,15 @@ static char *print_efiname(gpt_entry *pte) static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID; -static inline int is_bootable(gpt_entry *p) +static int is_bootable(gpt_entry *p) { - return p->attributes.fields.legacy_bios_bootable || - !memcmp(&(p->partition_type_guid), &system_guid, - sizeof(efi_guid_t)); + int ret = 0; + + if (!memcmp(&p->partition_type_guid, &system_guid, sizeof(efi_guid_t))) + ret |= PART_EFI_SYSTEM_PARTITION; + if (p->attributes.fields.legacy_bios_bootable) + ret |= PART_BOOTABLE; + return ret; } static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, diff --git a/include/part.h b/include/part.h index 0b5cf3d5e8..a63d1d0cda 100644 --- a/include/part.h +++ b/include/part.h @@ -51,13 +51,22 @@ struct block_drvr { #define PART_TYPE_LEN 32 #define MAX_SEARCH_PARTITIONS 64 +#define PART_BOOTABLE 1 +#define PART_EFI_SYSTEM_PARTITION 2 + typedef struct disk_partition { lbaint_t start; /* # of first block in partition */ lbaint_t size; /* number of blocks in partition */ ulong blksz; /* block size in bytes */ uchar name[PART_NAME_LEN]; /* partition name */ uchar type[PART_TYPE_LEN]; /* string type description */ - int bootable; /* Active/Bootable flag is set */ + /* + * The bootable is a bitmask with the following fields: + * + * PART_BOOTABLE the MBR bootable flag is set + * PART_EFI_SYSTEM_PARTITION the partition is an EFI system partition + */ + int bootable; #if CONFIG_IS_ENABLED(PARTITION_UUIDS) char uuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists */ #endif From patchwork Thu Mar 19 16:56:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1258327 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=gbSytNxi; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jtPJ3ptbz9sPk for ; Fri, 20 Mar 2020 03:57:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 62E1C81286; Thu, 19 Mar 2020 17:57:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="gbSytNxi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 952A881183; Thu, 19 Mar 2020 17:57:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CF3D6801D2 for ; Thu, 19 Mar 2020 17:56:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584637001; bh=ON5G5Oc3QzpE0IOYzRnqASBb7j8fdw5fhVrUCbAzCQA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=gbSytNxiOozlDJ0CeJrh8xs8iCBN4ljObItgPCPL7uYYMu9T/3jYHnFngPKHyWUOO GTIUnBEhTLMcXsblJKucrNU/OX97p6QPRC3I3iFoaTlmn65vAeTCxYA5LMHaCjhIRW Kwyswt0MhEGrHaH+9eTC3qLBo/KQWZq8WnrgYRs8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from rpi3.fritz.box ([84.119.33.226]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mnaof-1jg1V61qej-00jdO1; Thu, 19 Mar 2020 17:56:41 +0100 From: Heinrich Schuchardt To: AKASHI Takahiro Cc: Alexander Graf , Ilias Apalodimas , Paul Emge , Faiz Abbas , Alexey Brodkin , Eugeniu Rosca , Kever Yang , Urja Rannikko , Sam Protsenko , Ruslan Trofymenko , Igor Opaniuk , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 2/2] efi_loader: identify EFI system partition Date: Thu, 19 Mar 2020 16:56:32 +0000 Message-Id: <20200319165632.14014-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200319165632.14014-1-xypron.glpk@gmx.de> References: <20200319165632.14014-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+/BivCh4WjIyMlVaK9edueQvhrrW8kYfR5Ry9vb8aGiEO+6KWrt 3rTw4rJJVgDkjCDunpoWZzSjESBGv44t5qwYJGONM8TsU+VzMOXUBvineQX2pdADOQItntU s5jKgP9QiieBokTBkBk0QAxS6qqL5K8zfvnM9/qk5mS++HC9OpskgI3dhYkzTAvn0+zYAaL 1yfKj5Aq7KQuoJ/TKcojg== X-UI-Out-Filterresults: notjunk:1; V03:K0:zP9Ucdi/GUI=:eEBAt+rfZUknpl9YdncSUV R8gag+umw8zdNNX3KvbgtNWbkDwmh47BOL9g1xdDitrBry6Y1dwTqZdCvjqy0ascj9xAN/dC6 oXTG7wqdvxTF59FNpc6bRym4zCSs/y9PqOTlIz8RuTqduChBfoA1jncWjKhhUi1Yp8HbKS84Y cEHN4BrQ+qrsHq2cAFGVKXUIRKxaneOfPzHfgmGjfjbI9u/Fnzk1LFnuL0vvToCwYmXVRc5qs enLAuvpgNkRRyzCpXMzMEZcmTXKRtx/tXXSetsqf09xyhglUUqf+FrAueqbrmi7RYOg8tKp6J pPPlmBhb/1AWi+ggK8/8wBaNW7iNO39UiQk2Cr+7QMaA6Qjwd5wphWGDQUC4jEXTy0Z3TtAXK f+B2BAvb9FeO04jPlhMrzVCsY7MTuyIUWlJ/5JIVH5B//Dez9+66AfufDbmTp6O63vtCL0kDQ MH/QPBa/oJ25QDWm/YzKeNxu6hVxQmInZyB2ds/qa4rcGMVGcZuOvX+RTVNRJfR9rkdCb6OZ/ r5CDBsRibEacGw+sDzOBfCSWWLAIzP5z9m5com4DEbiFqvsZuQjoDKs9Eaapd1wA2Uct5ttLK N56WIVJUf9nfa/0c/zcMU7CC3TvvMvkFgX1X+lqQUFRSG1S8rfeaQC7yvdZf3Mvyups/IWs97 pEewjgeaDgtkSxBGcvrkd4gUHODj+C+jEenA98QU4aPSnI0Rxqu18E11h4C+4UD1UtO+LxfUn TsMLqQqbXZ9mVKixLMu0Zd4cnP/i4fsX3MM0DWHNokdoJVXrCrsXqMQaXcvPNOKT4NxF6luKt BoA0GSsmX9ihWC9vNPWAdNYlTvcpzdQRD8JqXNu+X3eUiOob6Ij2kbjS+eHtUnzSJ9smRfCc2 2Q627GQAHjqRE+MGRppvQAvwPPtg7t6BaweIFAE2Ty1h82SIla43akdbiMu8/s6Us2JNIeycJ S3VFK7EF2FDX93Wv0JPO6p4SIzThje0RuFqrIizOVNUy/imCLGQlBteCoEF8xq8OVJb+FCEZ5 dnTsGO57cVCuxGfre1QXBh114/RHknx5N9B1lFZm+oWeH09eLhBUvX9otdvljxHSWEBmoFTYt anHRju+gI5Sn89WbHgBvum31wDAymeQ9Irlm8Oenrt0rnXMF2SYC9v6zjxPJDCUqTR+V/mWsa lE5RHB70glPpP2UWfr/OdWmhGw+PQ3cooejvCtuDw5Xin99PI6sDrlaMK3j2efXcuWzeolCHI YjVvwGy5kg4WX9aim X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean For capsule updates we need to identify the EFI system partition. Signed-off-by: Heinrich Schuchardt --- include/efi_loader.h | 7 +++++++ lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) -- 2.20.1 diff --git a/include/efi_loader.h b/include/efi_loader.h index 37c3f15da1..536ef84cb5 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src) /* Root node */ extern efi_handle_t efi_root; +/* EFI system partition */ +extern struct efi_system_partition { + enum if_type if_type; + int devnum; + u8 part; +} efi_system_partition; + int __efi_entry_check(void); int __efi_exit_check(void); const char *__efi_nesting(void); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index fc0682bc48..2f752a5e99 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -13,6 +13,8 @@ #include #include +struct efi_system_partition efi_system_partition; + const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID; /** @@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev( diskobj->ops.media = &diskobj->media; if (disk) *disk = diskobj; + + /* Store first EFI system partition */ + if (part && !efi_system_partition.if_type) { + int r; + disk_partition_t info; + + r = part_get_info(desc, part, &info); + if (r) + return EFI_DEVICE_ERROR; + if (info.bootable & PART_EFI_SYSTEM_PARTITION) { + efi_system_partition.if_type = desc->if_type; + efi_system_partition.devnum = desc->devnum; + efi_system_partition.part = part; + EFI_PRINT("EFI system partition: %s %d:%d\n", + blk_get_if_type_name(desc->if_type), + desc->devnum, part); + } + } return EFI_SUCCESS; }