From patchwork Thu Jul 15 17:00:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 477438 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp467689jao; Thu, 15 Jul 2021 10:01:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtfqm3FIxoJ4EMLFrEamoMej/N/VOO63NlB70aSdTcnVpxctJb9Pil874/O0NGi2hHomp2 X-Received: by 2002:a17:906:a0a:: with SMTP id w10mr6630795ejf.416.1626368468119; Thu, 15 Jul 2021 10:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626368468; cv=none; d=google.com; s=arc-20160816; b=scx4sgN6/wEVmFuPIAucTF4TsCQSHnoNJBAdp5zk0y6GYeWLdSW0IGBHYhDpf/ALEx VldfmXXKERAnjYIrRXJKHxf2EVjVv6GqCqXqlXqW+x+suwWe9OGtMxwZpb8pQ7bsgI9P xnIj7X8UBFJ5rs0FvorIMBG1lJYK5vAbxNuxrL5nA6JIfBGj73ksIKMmP6pcYe8s5DjB 5jO9WexhtpowIcHWGv1eOarcc78NLUfPvlne6joW+hB519qbrJsTF/wPbdiIygsmu9u4 xRdSL6Lmh4mzq8/prIdZEngTTu8kmAHIbsKdb32s4DQ82LRTEtGYWieMT0SADkKByK9j DvZQ== 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=b9BC5DWERB6vQF4lPZswMUrNGat3NYEkNtXhCkHemj0=; b=XLhmcJaXe0OLDLfNZQMBnvl9a/bl2XTk4+TQBfznmwSj19hB6Hg2Ex2dTt0wVWfflI 8vjOS2aSQdhD2/Ws9mSjtwUhjnjIM5DdkDpKQKWRehRvgisJyyxOx3NvRuGzhuXyNKnZ VYltbJujYzocY5Ih30qi3warp2ph4t882DMKO1fmUElUol70g+qe8ZxaGjn9Ha0UjBT0 fPwFXtlJcV3iJ2h6qzGM7srdtBp+xs90LHiKE8I2i11rKBMeXFUYE8HoaCsEaQQW6gxF FT3NBlRfrVFJJBmEJnNhViaLdxj1YgEOr8gA849y/UtkGNuzdsyQW9igUOBDLiJUC2iN BfBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SDvpM9UP; 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 l6si7906658edv.341.2021.07.15.10.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 10:01:08 -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=SDvpM9UP; 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 2D01F829CD; Thu, 15 Jul 2021 19:00:52 +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="SDvpM9UP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 570FA81FC6; Thu, 15 Jul 2021 19:00:50 +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-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 6A64C81FC6 for ; Thu, 15 Jul 2021 19:00:42 +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-x52c.google.com with SMTP id x17so9078975edd.12 for ; Thu, 15 Jul 2021 10:00:42 -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=b9BC5DWERB6vQF4lPZswMUrNGat3NYEkNtXhCkHemj0=; b=SDvpM9UP9LUIayPhhdHjriUMxM9fT4mlbvmKyvfkzqghwBFSrT8us0hb2sEgCtRDao bOtTXVkvarB5GyKwzPgOqC4piNzebD+5RJqqzsAtTSolyUhaCEL7vrcYWaAUmDjrwo/z 4F7w8piV+ZIcy3+gl4qilqslNILvoVEudGxZKWpS6M4dVXmtRRS4y/mG/53VAjXFNr4K JOVGcwgw9riIy5jorUiJZ6gn9vnkRzXzY76pgyVpMPqcUV0a+6tOwpz3TVEkN0mZxMLk MeI1feE6DsA1Dwox2NbluvOjPRjkGynuTmjXkOaOm/Z2oi7pFcvHxKxnVi2ptounb9jT NAZA== 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=b9BC5DWERB6vQF4lPZswMUrNGat3NYEkNtXhCkHemj0=; b=aW13rN7HCUkDQ5ykJBxVrV/T/LgcUnLL8JZz6T6d7tefmy5a5RbQTBEv7CkSTaKm3m EXc1CbTEnM+qjmY5w0/xlmz8TZy4t0nLon3+Uzo/jL1B3CyanY46VQtAj5Wvg5C7LZ0e Fqw2Nrs3PKPu2kfziQG2Uqe6545rOGGcRzZbbtWQmUxbnysauJF/kqOYeOqwH2ZAOBsO VLUn0fJ24h/k9f6x77NuHrt3yVcxnSWCy253890/k3m9U2pEp7dKaMpfQfysRlgkHYkv FXI3h21f0QOwxgG6vV372HWkswapIUQ4gmnEETgYQMuyP3ZWl4UMfjv+07ooiohy/nFE f97Q== X-Gm-Message-State: AOAM531JNRkVwoM4joCIbXdGCDwOiKuVsKZ7rPsWN9cF5sKIF90RWNI5 0xKNIyVgL8jZAA5IyKnAhLlmgA== X-Received: by 2002:a05:6402:40c4:: with SMTP id z4mr8458963edb.364.1626368442046; Thu, 15 Jul 2021 10:00:42 -0700 (PDT) Received: from localhost.localdomain (ppp-94-66-243-35.home.otenet.gr. [94.66.243.35]) by smtp.gmail.com with ESMTPSA id p3sm2129556ejy.20.2021.07.15.10.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 10:00:41 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: masami.hiramatsu@linaro.org, takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , Simon Glass , u-boot@lists.denx.de Subject: [PATCH 2/3] mkeficapsule: Remove dtb related options Date: Thu, 15 Jul 2021 20:00:25 +0300 Message-Id: <20210715170030.97758-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.32.0.rc0 In-Reply-To: <20210715170030.97758-1-ilias.apalodimas@linaro.org> References: <20210715170030.97758-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 embeded the key in U-Boot's .rodata we don't this this functionality anymore Signed-off-by: Ilias Apalodimas --- tools/mkeficapsule.c | 226 ++----------------------------------------- 1 file changed, 7 insertions(+), 219 deletions(-) -- 2.32.0.rc0 Reviewed-by: Masami Hiramatsu diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index de0a62898886..214dc38e46e3 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -4,14 +4,12 @@ * Author: AKASHI Takahiro */ -#include #include #include #include #include #include #include -#include #include #include @@ -29,9 +27,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 +47,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 +60,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 +181,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 +217,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)