From patchwork Sat Jul 17 14:26:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 479239 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2425803jao; Sat, 17 Jul 2021 07:27:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoVYfk9WxmvgGAJoQH7blkn1usgpgvtrZ2rWRFx9JZZBOsgDHd3Smr0YytkBE8bOh2PQs+ X-Received: by 2002:a17:906:9742:: with SMTP id o2mr17936054ejy.532.1626532039947; Sat, 17 Jul 2021 07:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626532039; cv=none; d=google.com; s=arc-20160816; b=qSqHaD+GQvFNMInP47w2CuPBb0iXsgUv8IftKox2UF5bQBPxxGaMr393XnE/Cqy+JV 3ESjwTOPDecpvVzM1yvQLbFF6NFW9y3rqvw76VqkuojfjKkQVq0wZL/jSd+3+jwD2G8V +180hLNSfwo89SlHp0HNfgoJaurxazEdzvNpvwDKBd080p0bqEf7Vtqb+Wecy6PFvZgT N+HWFOHGg4ElvGJqCGNfnegNHWdpe0NVk32u/kKzod69hf72NWvPVFJVKJObd5dT4mdM J4nRzi2n9AK2dlAI1TZCI6JZd/tY5p9cIMHZQux1KfBT3ow+mc5snXcTTq8B2NLkXO/0 MI0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FqIKycfnWebpnXzRB8b8HdDSaBWPoo3y5R5tTkDAQYE=; b=AWSV7kZiWTscR+8XW4gkLOZZGoXxsi0tEXctHVDZahbEK6bjSpWvah8cL9Mk4XLblH 45BNd6vMH2qTcoPXqfcm7TuJV5CjHU547RDoCydIDq6nLj76Ng2adilcAFJ+LBUwoQuu Iv24qMq0xZneB5dyfelqvVL9iYLiucKupWZDgY/x3F0sSjg2+3sAXqxiXP6LFTnBbCzP WXk9gWmkSStRUYuOmp2DL1GioyXR4+K+tnQeUVk6CWN0NvkD1FkT4Ln7kcWdqfkUlM7b CufuylfaI2XeF+kDoikXdlO6ncqlVsowbp2LrByPY5fhYlnNVNJx/H3HghTqvr3FpE4c k9+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tlmJQ0Ru; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id z5si15851005edx.165.2021.07.17.07.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 07:27:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tlmJQ0Ru; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FBDC82C1C; Sat, 17 Jul 2021 16:27:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tlmJQ0Ru"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F65082C1C; Sat, 17 Jul 2021 16:27:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1440F828EB for ; Sat, 17 Jul 2021 16:27:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x533.google.com with SMTP id k27so16822038edk.9 for ; Sat, 17 Jul 2021 07:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FqIKycfnWebpnXzRB8b8HdDSaBWPoo3y5R5tTkDAQYE=; b=tlmJQ0RuMBteWd6hSGRnjDM7FS52R6CfvsvBAKonv+jXfboJFx3bVy+F8u5kYYCJv3 ndCE+2ZrDltL+cWilHwN6NLnfDbtpMLo7+Oiw3vGDSrmU9BmyucvKemulhcIpbQAPr+5 tI3ZZWwnd2m4c4QX2NHk/t6i5+ZbQgO0kr95xPVmU0j9cY+2OHCQng0VeXOf0LjGP8tg 6OZ5wV93NBor705A9BUfyhDgS06HKX1A8XOZ1Qy21g7dlncBdy5cMOSXhmZE2iDHlI8x bXlx8NHUX8MoYoH7z1caPCix/ggQDbwyWACI6D9rDFSOanObnXbCjJMlQ+rG/9gywW1Q o4pw== 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=FqIKycfnWebpnXzRB8b8HdDSaBWPoo3y5R5tTkDAQYE=; b=IFeNFrdCDYq5FVXeH9EDDRiNBXarHcZyxlcq6tPHL4nL7UgpTV+iR6bjF6i0sWQj01 XiWM1kp0XzScwZY0Debwkmb7D+wiGTltjcn0A6eosWphoUh0dVeqV/DsNPw6mq2Y3RbJ qpJkih/OKWpa5g/RXcIEwc4KFGLzHb/CQEGVb1+4IS3qnhIcZfEPTwKQokoWXnf13iyx c+FfmG2t6Fe24BEPplLtzOpXf3TgbZ8BJvz1RyO99kI7uOWVVf5/i6mgOOI8vblBxdLM LDS/S9IQMk/ln0kuJLy5iDmBbh3ugij5BewLwLkpUAQZ8m4gClc7fyeYgryB7m8zJoyU NV9A== X-Gm-Message-State: AOAM533xx4jy/+lIyZOLGVHolPhAbsRT+HVXuwCKYW6v0WT1y3w6x8SR YMORyrg3P8CyJoW/DSRriulUlA== X-Received: by 2002:a05:6402:152:: with SMTP id s18mr22097883edu.221.1626532025664; Sat, 17 Jul 2021 07:27:05 -0700 (PDT) Received: from apalos.home ([2a02:587:4679:5aa9:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id y9sm3983263ejd.52.2021.07.17.07.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 07:27:05 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , Masami Hiramatsu , Simon Glass , u-boot@lists.denx.de Subject: [PATCH 2/3] mkeficapsule: Remove dtb related options Date: Sat, 17 Jul 2021 17:26:45 +0300 Message-Id: <20210717142648.26588-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210717142648.26588-1-ilias.apalodimas@linaro.org> References: <20210717142648.26588-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean commit 322c813f4bec ("mkeficapsule: Add support for embedding public key in a dtb") added a bunch of options enabling the addition of the capsule public key in a dtb. Since now we embedded the key in U-Boot's .rodata we don't this this functionality anymore Signed-off-by: Ilias Apalodimas --- changes since v1: - removed 2 unused includes tools/mkeficapsule.c | 229 ++----------------------------------------- 1 file changed, 7 insertions(+), 222 deletions(-) -- 2.31.1 diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index de0a62898886..1c0d597a4b07 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -4,22 +4,17 @@ * Author: AKASHI Takahiro */ -#include #include #include #include #include #include #include -#include #include -#include #include #include -#include "fdt_host.h" - typedef __u8 u8; typedef __u16 u16; typedef __u32 u32; @@ -29,9 +24,6 @@ typedef __s32 s32; #define aligned_u64 __aligned_u64 -#define SIGNATURE_NODENAME "signature" -#define OVERLAY_NODENAME "__overlay__" - #ifndef __packed #define __packed __attribute__((packed)) #endif @@ -52,9 +44,6 @@ static struct option options[] = { {"raw", required_argument, NULL, 'r'}, {"index", required_argument, NULL, 'i'}, {"instance", required_argument, NULL, 'I'}, - {"dtb", required_argument, NULL, 'D'}, - {"public key", required_argument, NULL, 'K'}, - {"overlay", no_argument, NULL, 'O'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, }; @@ -68,187 +57,10 @@ static void print_usage(void) "\t-r, --raw new raw image file\n" "\t-i, --index update image index\n" "\t-I, --instance update hardware instance\n" - "\t-K, --public-key public key esl file\n" - "\t-D, --dtb dtb file\n" - "\t-O, --overlay the dtb file is an overlay\n" "\t-h, --help print a help message\n", tool_name); } -static int fdt_add_pub_key_data(void *sptr, void *dptr, size_t key_size, - bool overlay) -{ - int parent; - int ov_node; - int frag_node; - int ret = 0; - - if (overlay) { - /* - * The signature would be stored in the - * first fragment node of the overlay - */ - frag_node = fdt_first_subnode(dptr, 0); - if (frag_node == -FDT_ERR_NOTFOUND) { - fprintf(stderr, - "Couldn't find the fragment node: %s\n", - fdt_strerror(frag_node)); - goto done; - } - - ov_node = fdt_subnode_offset(dptr, frag_node, OVERLAY_NODENAME); - if (ov_node == -FDT_ERR_NOTFOUND) { - fprintf(stderr, - "Couldn't find the __overlay__ node: %s\n", - fdt_strerror(ov_node)); - goto done; - } - } else { - ov_node = 0; - } - - parent = fdt_subnode_offset(dptr, ov_node, SIGNATURE_NODENAME); - if (parent == -FDT_ERR_NOTFOUND) { - parent = fdt_add_subnode(dptr, ov_node, SIGNATURE_NODENAME); - if (parent < 0) { - ret = parent; - if (ret != -FDT_ERR_NOSPACE) { - fprintf(stderr, - "Couldn't create signature node: %s\n", - fdt_strerror(parent)); - } - } - } - if (ret) - goto done; - - /* Write the key to the FDT node */ - ret = fdt_setprop(dptr, parent, "capsule-key", - sptr, key_size); - -done: - if (ret) - ret = ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO; - - return ret; -} - -static int add_public_key(const char *pkey_file, const char *dtb_file, - bool overlay) -{ - int ret; - int srcfd = -1; - int destfd = -1; - void *sptr = NULL; - void *dptr = NULL; - off_t src_size; - struct stat pub_key; - struct stat dtb; - - /* Find out the size of the public key */ - srcfd = open(pkey_file, O_RDONLY); - if (srcfd == -1) { - fprintf(stderr, "%s: Can't open %s: %s\n", - __func__, pkey_file, strerror(errno)); - ret = -1; - goto err; - } - - ret = fstat(srcfd, &pub_key); - if (ret == -1) { - fprintf(stderr, "%s: Can't stat %s: %s\n", - __func__, pkey_file, strerror(errno)); - ret = -1; - goto err; - } - - src_size = pub_key.st_size; - - /* mmap the public key esl file */ - sptr = mmap(0, src_size, PROT_READ, MAP_SHARED, srcfd, 0); - if (sptr == MAP_FAILED) { - fprintf(stderr, "%s: Failed to mmap %s:%s\n", - __func__, pkey_file, strerror(errno)); - ret = -1; - goto err; - } - - /* Open the dest FDT */ - destfd = open(dtb_file, O_RDWR); - if (destfd == -1) { - fprintf(stderr, "%s: Can't open %s: %s\n", - __func__, dtb_file, strerror(errno)); - ret = -1; - goto err; - } - - ret = fstat(destfd, &dtb); - if (ret == -1) { - fprintf(stderr, "%s: Can't stat %s: %s\n", - __func__, dtb_file, strerror(errno)); - goto err; - } - - dtb.st_size += src_size + 0x30; - if (ftruncate(destfd, dtb.st_size)) { - fprintf(stderr, "%s: Can't expand %s: %s\n", - __func__, dtb_file, strerror(errno)); - ret = -1; - goto err; - } - - errno = 0; - /* mmap the dtb file */ - dptr = mmap(0, dtb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, - destfd, 0); - if (dptr == MAP_FAILED) { - fprintf(stderr, "%s: Failed to mmap %s:%s\n", - __func__, dtb_file, strerror(errno)); - ret = -1; - goto err; - } - - if (fdt_check_header(dptr)) { - fprintf(stderr, "%s: Invalid FDT header\n", __func__); - ret = -1; - goto err; - } - - ret = fdt_open_into(dptr, dptr, dtb.st_size); - if (ret) { - fprintf(stderr, "%s: Cannot expand FDT: %s\n", - __func__, fdt_strerror(ret)); - ret = -1; - goto err; - } - - /* Copy the esl file to the expanded FDT */ - ret = fdt_add_pub_key_data(sptr, dptr, src_size, overlay); - if (ret < 0) { - fprintf(stderr, "%s: Unable to add public key to the FDT\n", - __func__); - ret = -1; - goto err; - } - - ret = 0; - -err: - if (sptr) - munmap(sptr, src_size); - - if (dptr) - munmap(dptr, dtb.st_size); - - if (srcfd != -1) - close(srcfd); - - if (destfd != -1) - close(destfd); - - return ret; -} - static int create_fwbin(char *path, char *bin, efi_guid_t *guid, unsigned long index, unsigned long instance) { @@ -366,22 +178,16 @@ err_1: int main(int argc, char **argv) { char *file; - char *pkey_file; - char *dtb_file; efi_guid_t *guid; unsigned long index, instance; int c, idx; - int ret; - bool overlay = false; file = NULL; - pkey_file = NULL; - dtb_file = NULL; guid = NULL; index = 0; instance = 0; for (;;) { - c = getopt_long(argc, argv, "f:r:i:I:v:D:K:Oh", options, &idx); + c = getopt_long(argc, argv, "f:r:i:I:v:h", options, &idx); if (c == -1) break; @@ -408,43 +214,22 @@ int main(int argc, char **argv) case 'I': instance = strtoul(optarg, NULL, 0); break; - case 'K': - if (pkey_file) { - printf("Public Key already specified\n"); - return -1; - } - pkey_file = optarg; - break; - case 'D': - if (dtb_file) { - printf("DTB file already specified\n"); - return -1; - } - dtb_file = optarg; - break; - case 'O': - overlay = true; - break; case 'h': print_usage(); return 0; } } - /* need a fit image file or raw image file */ - if (!file && !pkey_file && !dtb_file) { + /* need a output file */ + if (argc != optind + 1) { print_usage(); exit(EXIT_FAILURE); } - if (pkey_file && dtb_file) { - ret = add_public_key(pkey_file, dtb_file, overlay); - if (ret == -1) { - printf("Adding public key to the dtb failed\n"); - exit(EXIT_FAILURE); - } else { - exit(EXIT_SUCCESS); - } + /* need a fit image file or raw image file */ + if (!file) { + print_usage(); + exit(EXIT_SUCCESS); } if (create_fwbin(argv[optind], file, guid, index, instance)