From patchwork Fri Dec 1 15:10:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 120350 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1260538qgn; Fri, 1 Dec 2017 07:10:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMagdB9aDrVHIXH5jfzVyWMt6bqmQ0E6526Z/pHS/oIQ9wlPZb7F7WEPBtB+YuZRAXKBznbQ X-Received: by 10.80.172.197 with SMTP id x63mr18775820edc.3.1512141043263; Fri, 01 Dec 2017 07:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512141043; cv=none; d=google.com; s=arc-20160816; b=oMf1Tli4DZ/syzfEMjJxqjBV94/N479N7Czs60POysB+vdK25vtPcKQuI5OBPstP3A z53RTqfnbQnNPW5pERYpQg+YT+hKC2rZVc/YmMKaeDi+bbjtw5hG3ltNU+Z7Q4GE2b9H H+LqNJcx9gTOQr0ouJ9uJCuzyz9PrnCHgm0Tq5pl/XzsQMFRaVxhtMIdcoYYtecJDduS M+z28RdFjkyBkjh9BCjv3oQSkBXcDh3Xc/FYAe7idZqEmrwp0SJ6OL56f+MMjA6b/biL Dq6z424iMiNcTbOdByRF3oCr12gvGd6bEm1PBonVBiM5Zn8/2/GIWtKuAA2aFrrAG0Ww /ZQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=qbnX8NILAF8NOfH3gKTblm7B8D9qb0RpTlyzYyAPmWs=; b=Gwx3CPO5tK1SyjvvD/Tsza7QgESbnukE8/EWwoUb9s5UHtiTq+yx6+XRlDahNQXkaL Ol4Tal6FadSjurrs5+I8DX3lxTeqpBtEkcgGS3ANI6UALt/HAm4/968+UAR2I7y6R+2O 3s1esx/UzwvbxLlH1/jEiM3fi9fDVz+2/sSK++a1lPAJVqJ/2aj7XQc4Jjc+WpCi7yjb ApZd/2cCLKjgKOOYhZANFeJbdNg2QDyCWpdAk6JE/34LKhAm+KRBbWWO+tNqIMT+yVDc prFxe0oqdKQemjrgWLSW/WJ79pCZsOCrsSp+SMVo1jywG2jyXNoq51WVAXJWNW5GujCH icmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c27si1070782ede.367.2017.12.01.07.10.43; Fri, 01 Dec 2017 07:10:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id BDF1FC21FE3; Fri, 1 Dec 2017 15:10: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=none 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 62115C21E73; Fri, 1 Dec 2017 15:10:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6B70DC21E73; Fri, 1 Dec 2017 15:10:36 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id E2EBAC21D6A for ; Fri, 1 Dec 2017 15:10:35 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6D5D4AE97; Fri, 1 Dec 2017 15:10:34 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 1 Dec 2017 16:10:33 +0100 Message-Id: <20171201151033.88189-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt , Yousaf Kaukab Subject: [U-Boot] [PATCH] efi_loader: Fix partition offsets 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" Commit 884bcf6f65 (efi_loader: use proper device-paths for partitions) tried to introduce the el torito scheme to all partition table types: Spawn individual disk objects for each partition on a disk. Unfortunately, that code ended up creating partitions with offset=0 which meant that anyone accessing these objects gets data from the raw block device instead of the partition. Furthermore, all the el torito logic to spawn devices for partitions was duplicated. So let's merge the two code paths and give partition disk objects good offsets to work from, so that payloads can actually make use of them. Fixes: 884bcf6f65 (efi_loader: use proper device-paths for partitions) Reported-by: Yousaf Kaukab Signed-off-by: Alexander Graf --- lib/efi_loader/efi_disk.c | 60 ++++++++++------------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 68ba2cf7b2..4e457a841b 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -264,21 +264,17 @@ out_of_memory: printf("ERROR: Out of memory\n"); } -static int efi_disk_create_eltorito(struct blk_desc *desc, - const char *if_typename, - int diskid, - const char *pdevname) +static int efi_disk_create_partitions(struct blk_desc *desc, + const char *if_typename, + int diskid, + const char *pdevname) { int disks = 0; -#if CONFIG_IS_ENABLED(ISO_PARTITION) char devname[32] = { 0 }; /* dp->str is u16[32] long */ disk_partition_t info; int part; - if (desc->part_type != PART_TYPE_ISO) - return 0; - - /* and devices for each partition: */ + /* Add devices for each partition */ for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { if (part_get_info(desc, part, &info)) continue; @@ -289,10 +285,6 @@ static int efi_disk_create_eltorito(struct blk_desc *desc, disks++; } - /* ... and add block device: */ - efi_disk_add_dev(devname, if_typename, desc, diskid, 0, 0); -#endif - return disks; } @@ -318,31 +310,18 @@ int efi_disk_register(void) uclass_next_device_check(&dev)) { struct blk_desc *desc = dev_get_uclass_platdata(dev); const char *if_typename = dev->driver->name; - disk_partition_t info; - int part; printf("Scanning disk %s...\n", dev->name); - /* add devices for each partition: */ - for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { - if (part_get_info(desc, part, &info)) - continue; - efi_disk_add_dev(dev->name, if_typename, desc, - desc->devnum, 0, part); - } - - /* ... and add block device: */ + /* Add block device for the full device */ efi_disk_add_dev(dev->name, if_typename, desc, desc->devnum, 0, 0); disks++; - /* - * El Torito images show up as block devices in an EFI world, - * so let's create them here - */ - disks += efi_disk_create_eltorito(desc, if_typename, - desc->devnum, dev->name); + /* Partitions show up as block devices in EFI */ + disks += efi_disk_create_partitions(desc, if_typename, + desc->devnum, dev->name); } #else int i, if_type; @@ -361,8 +340,6 @@ int efi_disk_register(void) for (i = 0; i < 4; i++) { struct blk_desc *desc; char devname[32] = { 0 }; /* dp->str is u16[32] long */ - disk_partition_t info; - int part; desc = blk_get_devnum_by_type(if_type, i); if (!desc) @@ -373,24 +350,13 @@ int efi_disk_register(void) snprintf(devname, sizeof(devname), "%s%d", if_typename, i); - /* add devices for each partition: */ - for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { - if (part_get_info(desc, part, &info)) - continue; - efi_disk_add_dev(devname, if_typename, desc, - i, 0, part); - } - - /* ... and add block device: */ + /* Add block device for the full device */ efi_disk_add_dev(devname, if_typename, desc, i, 0, 0); disks++; - /* - * El Torito images show up as block devices - * in an EFI world, so let's create them here - */ - disks += efi_disk_create_eltorito(desc, if_typename, - i, devname); + /* Partitions show up as block devices in EFI */ + disks += efi_disk_create_partitions(desc, if_typename, + i, devname); } } #endif