From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC02BC07E95 for ; Fri, 16 Jul 2021 13:54:02 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E78B4613BB for ; Fri, 16 Jul 2021 13:54:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E78B4613BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3E6FC8296F; Fri, 16 Jul 2021 15:53:59 +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="cGi+QBHr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B759E82A01; Fri, 16 Jul 2021 15:53:57 +0200 (CEST) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 D54B08296A for ; Fri, 16 Jul 2021 15:53:53 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x535.google.com with SMTP id d12so10023261pgd.9 for ; Fri, 16 Jul 2021 06:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=foy9JAFoe27h5B9wKPFRKtH0uq2Z2r/qe7ETGvp66/c=; b=cGi+QBHr0UvhIZVhsRjUR7eI1DrqU50JX4UpoUk8TqAjGj/BSx6pw4gY1SZ7UhpooB OxR1SET90vS7Jjui+OE8XYFc5QiN/zHg1aQUEKeW/Q7ZoTow45sV2LNjdhUMr3sDZxXS a5fchpeel8DeXsWf7T2gBtOJkUPW05bLgu1wBtLQL44fz89qSrxSAAiByqKlj14Ha8X6 D9Sr+gXuRPJ+WhBqL9NHGaEOc+HX9HV1QieSp4MIbttwq60w7R7Yuu9SubN21it5Gro/ qVHX/L3OgKDTj27v5ex9wrxi2YKboTy4MNsDYzQaPZeAjHIqZ5Y3aFNyOTIU+IWpxbWl O5Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=foy9JAFoe27h5B9wKPFRKtH0uq2Z2r/qe7ETGvp66/c=; b=g3X3evldWX6UJOWLRLn4ktvUcGIsgvlLGadLQQNp8SjQBUPxHK09KezshXB1WmNPBN ZuPyRnWWisq+S45MafXQJ5Ic8CzpbIWZx9Vu24btLy/1e4NgbbIq7Xbupob7sGjnX6wz 7ERm4OjH41s4c+hl2D+GsJp0WQB7+7l/fl2oP3b+QJXNp2CEZXUtegLcXh1DGKVQ7Zcd KJASW9PwWokNtR6lVsw+mCdYgg0ekVKtnEK1/zzNRAOYYvegC00KC5lMF+f0YhqNOSEB uAYDt/+QjtJI79sWbxtpBDybceAVUOX/i8LPNsHsFTlKPoU2QQ8WC+GDeYFCs1IWsY8g rsPg== X-Gm-Message-State: AOAM532eRXwUaO30KfzjARPPD9iz7g59y4N9hIkC00G80f4g4SPZiwWX 3ZUaSnovNtu0ZALZ63TrO23AvQ== X-Google-Smtp-Source: ABdhPJxMs3Y2FslsCdi+LGb/5V+1VsXcqlRBgwF521QFIILax3kAbt0mhxY172ADCWndODMvrlqPtg== X-Received: by 2002:a05:6a00:1ac7:b029:32b:a408:939b with SMTP id f7-20020a056a001ac7b029032ba408939bmr10745408pfv.58.1626443631994; Fri, 16 Jul 2021 06:53:51 -0700 (PDT) Received: from laputa (p3dd30549.tkyea130.ap.so-net.ne.jp. [61.211.5.73]) by smtp.gmail.com with ESMTPSA id y28sm3936205pff.137.2021.07.16.06.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 06:53:47 -0700 (PDT) Date: Fri, 16 Jul 2021 22:53:37 +0900 From: Takahiro Akashi To: Masami Hiramatsu Cc: Ilias Apalodimas , Heinrich Schuchardt , Alexander Graf , Sughosh Ganu , Simon Glass , U-Boot Mailing List Subject: Re: [PATCH 2/3] mkeficapsule: Remove dtb related options Message-ID: <20210716135337.GC68948@laputa> Mail-Followup-To: Takahiro Akashi , Masami Hiramatsu , Ilias Apalodimas , Heinrich Schuchardt , Alexander Graf , Sughosh Ganu , Simon Glass , U-Boot Mailing List References: <20210715170030.97758-1-ilias.apalodimas@linaro.org> <20210715170030.97758-2-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 On Fri, Jul 16, 2021 at 02:57:54PM +0900, Masami Hiramatsu wrote: > 2021年7月16日(金) 2:00 Ilias Apalodimas : > > > > 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 > > This looks good to me. > > Reviewed-by: Masami Hiramatsu > > Thanks, > > > > > Signed-off-by: Ilias Apalodimas > > --- > > tools/mkeficapsule.c | 226 ++----------------------------------------- > > 1 file changed, 7 insertions(+), 219 deletions(-) > > > > 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 I didn't try the compilation, but I don't think we need neither nor "fdt_host.h". -Takahiro Akashi > > @@ -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) > > -- > > 2.32.0.rc0 > > > > > -- > Masami Hiramatsu