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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D67FFC433F5 for ; Sat, 15 Jan 2022 09:46:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 39FE6831CA; Sat, 15 Jan 2022 10:46:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1642240013; bh=TRIZjS0ubLfX4LyXWJet0tXvZUUdcqTpu9Wn7oL0Vk8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MEZQNYxo/YxFmgCITtrV/juDdzU5yVdYrHDFAUNbZUvz13Jk0e0ecyLfDs5HNuZyq g+P6BMHFzDNyMmGNlvwQEA0p+VLh8XebYLVMYnkV2prv/spvzdobIxUDvTVBp8zmg3 H2uwMUZIoPhP0af5WRQ7uiqJ3JEODJeoorE64i6ixy6O8BahdlNlHq51aktwqahued XaDH0cS2WqXj8n/XzIGwnfYchQs8dVWzvdCGxpHgTglwi7gXnPPOH7h+HBtyK73VI0 bB8wVZacBhnSkg4KcFtW+D3ZlaYTh5zaNEpKjUl7l8CR8DTi+tEZUnWXI/kvitNSv8 S+Rb/oR5IjEVw== Received: by phobos.denx.de (Postfix, from userid 109) id 5E3CD83394; Sat, 15 Jan 2022 10:46:51 +0100 (CET) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:1::465:204]) (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 EFFF9811BA for ; Sat, 15 Jan 2022 10:46:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:105:465:1:3:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4JbYGc2cfCzQjgn; Sat, 15 Jan 2022 10:46:48 +0100 (CET) Message-ID: <0f1261ba-a863-17cf-b95f-709234403b8c@denx.de> Date: Sat, 15 Jan 2022 10:46:43 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v2] tools: mkimage: Call verify_header after writing image to disk Content-Language: en-US To: =?UTF-8?Q?Pali_Roh=c3=a1r?= , Simon Glass , Alexandru Gagniuc , Yann Dirson , =?UTF-8?Q?Marek_Beh=c3=ban?= Cc: u-boot@lists.denx.de References: <20220114173443.9877-1-pali@kernel.org> From: Stefan Roese In-Reply-To: <20220114173443.9877-1-pali@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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 1/14/22 18:34, Pali Rohár wrote: > If image backend provides verify_header callback then call it after writing > image to disk. This ensures that written image is correct. > > Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese Thanks, Stefan > --- > tools/mkimage.c | 41 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/tools/mkimage.c b/tools/mkimage.c > index fbe883ce3620..d5ad0925225c 100644 > --- a/tools/mkimage.c > +++ b/tools/mkimage.c > @@ -336,6 +336,44 @@ static void process_args(int argc, char **argv) > usage("Missing output filename"); > } > > +static void verify_image(const struct image_type_params *tparams) > +{ > + struct stat sbuf; > + void *ptr; > + int ifd; > + > + ifd = open(params.imagefile, O_RDONLY | O_BINARY); > + if (ifd < 0) { > + fprintf(stderr, "%s: Can't open %s: %s\n", > + params.cmdname, params.imagefile, > + strerror(errno)); > + exit(EXIT_FAILURE); > + } > + > + if (fstat(ifd, &sbuf) < 0) { > + fprintf(stderr, "%s: Can't stat %s: %s\n", > + params.cmdname, params.imagefile, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + params.file_size = sbuf.st_size; > + > + ptr = mmap(0, params.file_size, PROT_READ, MAP_SHARED, ifd, 0); > + if (ptr == MAP_FAILED) { > + fprintf(stderr, "%s: Can't map %s: %s\n", > + params.cmdname, params.imagefile, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + > + if (tparams->verify_header((unsigned char *)ptr, params.file_size, ¶ms) != 0) { > + fprintf(stderr, "%s: Failed to verify header of %s\n", > + params.cmdname, params.imagefile); > + exit(EXIT_FAILURE); > + } > + > + (void)munmap(ptr, params.file_size); > + (void)close(ifd); > +} > + > int main(int argc, char **argv) > { > int ifd = -1; > @@ -698,6 +736,9 @@ int main(int argc, char **argv) > exit (EXIT_FAILURE); > } > > + if (tparams->verify_header) > + verify_image(tparams); > + > exit (EXIT_SUCCESS); > } > > Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de