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 3DC6BC4332F for ; Tue, 13 Dec 2022 20:36:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 59A9385013; Tue, 13 Dec 2022 21:36:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="MkLpiKNh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4BEE5850CC; Tue, 13 Dec 2022 19:51:22 +0100 (CET) Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) (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 EC6688453A for ; Tue, 13 Dec 2022 19:51:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=fr0st61te@gmail.com Received: by mail-lf1-x12f.google.com with SMTP id 1so6474445lfz.4 for ; Tue, 13 Dec 2022 10:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=4rodj7icp3MoUYSkL88tU/1njtk2k7hGeO4yUcBaqFI=; b=MkLpiKNhpKAuwg+COO870k8sGRIY2fY45phsxvKfOkv5WthgD7GCmfaGrQUCEBzscr d9rI7LOIygymYub0S0ICpiaDymf8qzOxu5mudDrYkKro6iVlOMagruShpSfsGH/SlSoz ZJXqeR7NGCOZVhm8pSuKcuzV+qjMSjTFy4+TLklNNropVcqpUVni6G4fzct1oL+D6Y6k iYi2sUnVPFWnvZxo3TOKz96nbU3AINpvul65cAU5dKT49OueaqQXJkp4zPhQa+5BVXXZ FjAP6Y+dfxUHJpAHVmtjX0vUnNtjMN2/caUBUia9XdaZmquhhtv3/Nre11c6fHZ/k9MT GEkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4rodj7icp3MoUYSkL88tU/1njtk2k7hGeO4yUcBaqFI=; b=aQ0uHkdSlX2GXzKgh3WPnR54+p8HXHn8p/rffYyscHSHaQTpBaD3VdSWtCq85Y6PwY disGh6uj/oZwgOT11A1MNxfqZK/TEnLmZzJRynbsGdYt6BbOF6a/jeQfRrKwoTcl03ZO aheyl8EOpUX7m1MuXIMi9uSz/c9onIO8KVu99nYEQxq7HVilLNZb8ilGEEgxlmhierBi 2+eQWUynwRLHyyWpw7Ehou5iuJwWTdQ7yWQ0T0GQ84qkmYmunt/ZoztbPz2MMQquOkqY nCl5DLq4osgnAhPNjrlPbu4mLTRgwGEXbsmRh0w2o0kt6H+AI919FJI1dOuKlApmhJ+G jXTg== X-Gm-Message-State: ANoB5plbbZHqKQWNI8cAWTLhMmjPIBPKSTDzU2MYOL8veHC78wsOdbiE lbApx/I2Ql9kAaCpg+vS7tk= X-Google-Smtp-Source: AA0mqf5W2iPed0ruVV6QSnNO4C7Pzh57p6gv7omTssyNVN9Jv8nFLVdGP9hbymV7nCeCaH5LOJvXrQ== X-Received: by 2002:a05:6512:c1f:b0:4b6:eaed:f18f with SMTP id z31-20020a0565120c1f00b004b6eaedf18fmr3735018lfu.38.1670957478161; Tue, 13 Dec 2022 10:51:18 -0800 (PST) Received: from [100.119.147.210] (93-80-66-29.broadband.corbina.ru. [93.80.66.29]) by smtp.gmail.com with ESMTPSA id j2-20020a056512344200b004b4f2a30e6csm477368lfr.0.2022.12.13.10.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 10:51:17 -0800 (PST) Message-ID: Subject: Re: [PATCH 1/3] binman: add sign option for binman From: Ivan Mikhaylov To: Simon Glass Cc: Alper Nebi Yasak , U-Boot Mailing List , Ivan Mikhaylov , Jan Kiszka Date: Tue, 13 Dec 2022 21:51:15 +0000 In-Reply-To: References: <20220321214319.33254-1-fr0st61te@gmail.com> <20220321214319.33254-2-fr0st61te@gmail.com> <8bf99a710da222864dd608f9cd05dc0f1c5dbda1.camel@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.1 MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 13 Dec 2022 21:36:01 +0100 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.6 at phobos.denx.de X-Virus-Status: Clean On Fri, 2022-11-18 at 13:50 -0700, Simon Glass wrote: > Hi Ivan, >=20 > On Thu, 15 Sept 2022 at 13:44, Ivan Mikhaylov > wrote: > >=20 > > On Wed, 2022-09-07 at 15:10 -0600, Simon Glass wrote: > > > Hi Ivan, > > >=20 > > > Section data comes from the BuildSectionData() method, so you > > > could > > > try calling that. > > >=20 > > > See also collect_contents_to_file() > > >=20 > > > Regards, > > > Simon > >=20 > > Simon, I've tried both these ways and they both don't work to me. > > What > > I've got: > >=20 > > def SignEntries(image_fname, input_fname, privatekey_fname, algo, > > entry_paths): > > =C2=A0=C2=A0=C2=A0 image_fname =3D os.path.abspath(image_fname) > > =C2=A0=C2=A0=C2=A0 image =3D Image.FromFile(image_fname) > > =C2=A0=C2=A0=C2=A0 state.PrepareFromLoadedData(image) > > =C2=A0=C2=A0=C2=A0 image.LoadData() > >=20 > > 1. BuildSectionData > >=20 > > =C2=A0=C2=A0=C2=A0 for entry_path in entry_paths: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 entry =3D image.FindEntryPat= h(entry_path) > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 entr= y.BuildSectionData(True) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 except Exception as e: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 logg= ing.error(traceback.format_exc()) > >=20 > >=20 > > ERROR:root:AttributeError: 'NoneType' object has no attribute 'run' Hi Simon, sorry for long delay. binman: 'NoneType' object has no attribute 'run' Traceback (most recent call last): File "/home/fr/upstream_uboot/tools/binman/binman", line 133, in RunBinman ret_code =3D control.Binman(args) File "/home/fr/upstream_uboot/tools/binman/control.py", line 684, in Binman SignEntries(args.image, args.file, args.key, args.algo, args.paths) File "/home/fr/upstream_uboot/tools/binman/control.py", line 469, in SignEntries entry.BuildSectionData(True) File "/home/fr/upstream_uboot/tools/binman/etype/fit.py", line 426, in BuildSectionData if self.mkimage.run(reset_timestamp=3DTrue, output_fname=3Doutput_fname, AttributeError: 'NoneType' object has no attribute 'run' > >=20 > > 2. collect_contents_to_file > >=20 > > =C2=A0=C2=A0=C2=A0 for entry_path in entry_paths: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 entry =3D image.FindEntryPat= h(entry_path) > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 entr= y.collect_contents_to_file([entry.name], "prefix", > > 1024) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 except Exception as e: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 logg= ing.error(traceback.format_exc()) > >=20 > > ERROR:root:AttributeError: 'str' object has no attribute > > 'ObtainContents' >=20 > This seems to be getting a string instead of an entry object. Can you > try -D to see? See 'Writing new entries and debugging'. Yea, you're right, seems I've added here entry.name instead of entry but result still messy. entry here is FIT container which is 'fit': binman: [Errno 2] No such file or directory: 'u-boot.bin' Traceback (most recent call last): File "/home/fr/upstream_uboot/tools/binman/binman", line 133, in RunBinman ret_code =3D control.Binman(args) File "/home/fr/upstream_uboot/tools/binman/control.py", line 686, in Binman SignEntries(args.image, args.file, args.key, args.algo, args.paths) File "/home/fr/upstream_uboot/tools/binman/control.py", line 471, in SignEntries entry.collect_contents_to_file([entry], "prefix", 1024) File "/home/fr/upstream_uboot/tools/binman/entry.py", line 1253, in collect_contents_to_file if not entry.ObtainContents(fake_size=3Dfake_size): File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 250, in ObtainContents return self.GetEntryContents(skip_entry=3Dskip_entry) File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 696, in GetEntryContents job.result() File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result return self.__get_result() File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result raise self._exception File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result =3D self.fn(*self.args, **self.kwargs) File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 668, in _CheckDone if not entry.ObtainContents(): File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 250, in ObtainContents return self.GetEntryContents(skip_entry=3Dskip_entry) File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 696, in GetEntryContents job.result() File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result return self.__get_result() File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result raise self._exception File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result =3D self.fn(*self.args, **self.kwargs) File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 668, in _CheckDone if not entry.ObtainContents(): File "/home/fr/upstream_uboot/tools/binman/etype/blob.py", line 52, in ObtainContents self.ReadBlobContents() File "/home/fr/upstream_uboot/tools/binman/etype/blob.py", line 82, in ReadBlobContents data =3D self.ReadFileContents(self._pathname) File "/home/fr/upstream_uboot/tools/binman/etype/blob.py", line 74, in ReadFileContents indata =3D tools.read_file(pathname) File "/home/fr/upstream_uboot/tools/patman/tools.py", line 467, in read_file with open(filename(fname), binary and 'rb' or 'r') as fd: FileNotFoundError: [Errno 2] No such file or directory: 'u-boot.bin' >=20 > >=20 > > 3. GetData > >=20 > > =C2=A0=C2=A0=C2=A0 for entry_path in entry_paths: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 entry =3D image.FindEntryPat= h(entry_path) > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print("--- DATA ---") > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D entry.GetData(True) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print(data) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print("~~~ DATA ~~~") > >=20 > > --- DATA --- > > Node '/fit/images/u-boot-1/u-boot': GetData: size 0x4 > > =C2=A0=C2=A0 Node '/fit/images/u-boot-1': GetPaddedDataForEntry: size N= one > > =C2=A0=C2=A0 Node '/fit/images/u-boot-1': GetData: 1 entries, total siz= e 0x4 > > Node '/fit/images/fdt-1/u-boot-spl-dtb': GetData: size 0x4f7 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Node '/fit/images/fdt-1': GetPaddedDataF= orEntry: size None > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Node '/fit/images/fdt-1': GetData: 1 ent= ries, total size > > 0x4f7 > > Deleted temporary directory '/tmp/binman.z81eqcfz' > > binman: 'NoneType' object has no attribute 'run' >=20 > This might be trying to call tools.run() so use -D to see where the > error is. >=20 --- DATA --- Node '/fit/images/u-boot-1/u-boot': GetData: size 0x4 Node '/fit/images/u-boot-1': GetPaddedDataForEntry: size None Node '/fit/images/u-boot-1': GetData: 1 entries, total size 0x4 Node '/fit/images/fdt-1/u-boot-spl-dtb': GetData: size 0x4f7 Node '/fit/images/fdt-1': GetPaddedDataForEntry: size None Node '/fit/images/fdt-1': GetData: 1 entries, total size 0x4f7 Deleted temporary directory '/tmp/binman.0x74lr_s' binman: 'NoneType' object has no attribute 'run' Traceback (most recent call last): File "/home/fr/upstream_uboot/tools/binman/binman", line 133, in RunBinman ret_code =3D control.Binman(args) File "/home/fr/upstream_uboot/tools/binman/control.py", line 684, in Binman SignEntries(args.image, args.file, args.key, args.algo, args.paths) File "/home/fr/upstream_uboot/tools/binman/control.py", line 468, in SignEntries print(entry.GetData()) File "/home/fr/upstream_uboot/tools/binman/etype/section.py", line 362, in GetData data =3D self.BuildSectionData(required) File "/home/fr/upstream_uboot/tools/binman/etype/fit.py", line 426, in BuildSectionData if self.mkimage.run(reset_timestamp=3DTrue, output_fname=3Doutput_fname, AttributeError: 'NoneType' object has no attribute 'run' This one strange to me because mkimage exists in tools directory and has the symbolic link to /usr/local. > >=20 > > There is no problem with getting data from GetData around start of > > the > > year. Maybe some regression? > >=20 > > All this ran with this: > > binman -v5 sign -i image.bin -k test_key.key -a sha256,rsa4096 fit > >=20 > > `fit` in entry_paths and image contains FIT section with name > > `fit`. > >=20 > > binman ls -i image.bin > > Name=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Image-pos=C2=A0 Size=C2=A0=C2=A0=C2=A0= =C2=A0 Entry-type=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Offset > > Uncomp-size > > ------------------------------------------------------------------- > > ---- > > -------- > > main-section=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0=C2=A0=C2=A0 100000=C2=A0 se= ction=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 0 > > =C2=A0 fit=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 10000=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 c0a=C2=A0 fit=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 10000 > > =C2=A0=C2=A0=C2=A0 u-boot-1=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 10104=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 4=C2=A0 section=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 104 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u-boot=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 10104=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 4=C2=A0 u-boot=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0 > > =C2=A0=C2=A0=C2=A0 fdt-1=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 101c8=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 4f7=C2=A0 section=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 1c8 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u-boot-spl-dtb=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 101c8=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 4f7=C2=A0 u-boot-spl-dtb=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0 > > =C2=A0 fdtmap=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 10c0a=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 4f5=C2=A0 fdtmap=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 10c0a > >=20 > >=20 > > Seems something went wrong, any ideas? Or did I misuse? >=20 > Can you please push a tree somewhere so I can try this? Sure, https://github.com/fr0st61te/u-boot/tree/signfit , rebased to current master. Thanks.