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 08674C433EF for ; Mon, 18 Apr 2022 19:58:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B63C83B1B; Mon, 18 Apr 2022 21:58:21 +0200 (CEST) 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="CYoojoSa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3283B839A7; Mon, 18 Apr 2022 21:58:17 +0200 (CEST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (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 92C1383AE2 for ; Mon, 18 Apr 2022 21:58:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x62b.google.com with SMTP id y20so8620825eju.7 for ; Mon, 18 Apr 2022 12:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :references:content-language:in-reply-to:content-transfer-encoding; bh=0kWO00+3Kkxn0Etu+/XELzjIkAOAbjksZ8otpEOfkLk=; b=CYoojoSaz5UoK0Y1LT6WETqSWGlstlV9YpG+HBXcAemt8XnagNlmISii0N1Yp7LziQ Ll0cNiwUNWSG8wsxPwCp0B6EKGAaoURwRKrWMdbRJ4hMtO3tX/jv9hhO6C505gTvfaCi xbs/tZ4C/pjMI7nCCp5keUvY2yCz90f2hUHC26JWMf3IkJAowFbAIZRPhXwGA6LxYQTx 7kxWq4xORxbrkG3FN5e0YJwDm9PwhtyPurpcjJDmYzYgG7Qxwvkr/F7hNgQBZWrDCuGC B3kAmcf122cH117XUAWIK/6qQWr0PubNTSXzMBjvlntjRruVFI+c/TcK5uIsLmveROTY /JBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=0kWO00+3Kkxn0Etu+/XELzjIkAOAbjksZ8otpEOfkLk=; b=1XiSKySz1oXzAhYKsDq8f+LDeqNCPYMOzN2BasMUCJtjK35T8A3vDEyLAgtqB8KHDP 6nshx9eJAasb1MdH1ZNeEcT9KtVJofTexQiR6kv+Bc3n9wHbY5PtRsFPEba8q9ED4L6m DHTKpc3dpF/Byahku2qrCEaB/zsy3BhJjAy5dx7qygOfeaU+sMAYWrGdEuYyU76XcEZA 68d8laJbNXTy8DAwAV1Ps6qu97GR8Whtm/derBz1hsHZcab5CvWf17RZ8GkvmyaBMIfj YpJKdKwgF8kfeGuUcBiLVMThFF7AQ/r029pXBaZPJ8VYotlGF4os4fvYfyZcAb/pTl2n qxEA== X-Gm-Message-State: AOAM530nWSuGzeuWct8YVexMFOsMque1rNvisyCxoOQ5GGBkGSe4ZoEq qJ6obT6p7kdwoCoduqcyXm8= X-Google-Smtp-Source: ABdhPJwsJlgXuyTe9O93+nyiZxokYP8Srif2HhQRH2mSOy4JUpUGrDi1EGxUS6xLNT27OvsbY8DIjw== X-Received: by 2002:a17:906:846b:b0:6ef:af54:f2cc with SMTP id hx11-20020a170906846b00b006efaf54f2ccmr5539532ejc.662.1650311890140; Mon, 18 Apr 2022 12:58:10 -0700 (PDT) Received: from [192.168.0.74] ([178.233.178.185]) by smtp.gmail.com with ESMTPSA id j10-20020aa7de8a000000b004215209b077sm6846791edv.37.2022.04.18.12.58.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Apr 2022 12:58:09 -0700 (PDT) Message-ID: Date: Mon, 18 Apr 2022 22:56:15 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 From: Alper Nebi Yasak Subject: Re: [RESEND, RFC 2/8] binman: etype: sysfw: Add entry type for sysfw To: Neha Malcom Francis Cc: sjg@chromium.org, marek.behun@nic.cz, xypron.glpk@gmx.de, vigneshr@ti.com, a-govindraju@ti.com, kristo@kernel.org, s-anna@ti.com, kishon@ti.com, joel.peshkin@broadcom.com, patrick.delaunay@foss.st.com, mr.nuke.me@gmail.com, nm@ti.com, u-boot@lists.denx.de References: <20220406122919.6104-1-n-francis@ti.com> <20220406122919.6104-3-n-francis@ti.com> Content-Language: en-US In-Reply-To: <20220406122919.6104-3-n-francis@ti.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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.5 at phobos.denx.de X-Virus-Status: Clean On 06/04/2022 15:29, Neha Malcom Francis wrote: > For K3 devices that require a sysfw image, add entry for SYSFW. It can > contain system firmware image that can be packaged into sysfw.itb by > binman. The method ReadBlobContents in sysfw.py runs the TI K3 > certificate generation script to create the signed sysfw image that can > be used for packaging by binman into sysfw.bin. > > Signed-off-by: Tarun Sahu > [n-francis@ti.com: added tests for addition of etype] > Signed-off-by: Neha Malcom Francis > --- > tools/binman/entries.rst | 11 ++++++ > tools/binman/etype/sysfw.py | 60 +++++++++++++++++++++++++++++++++ > tools/binman/ftest.py | 7 ++++ > tools/binman/test/226_sysfw.dts | 13 +++++++ > 4 files changed, 91 insertions(+) > create mode 100644 tools/binman/etype/sysfw.py > create mode 100644 tools/binman/test/226_sysfw.dts > > diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst > index 484cde5c80..7c95bbfbec 100644 > --- a/tools/binman/entries.rst > +++ b/tools/binman/entries.rst > @@ -1019,6 +1019,17 @@ This entry holds firmware for an external platform-specific coprocessor. > > > > +Entry: sysfw: Texas Instruments System Firmware (SYSFW) blob > +------------------------------------------------------------ This title should match the first line of the docstring, normally this entire file is regenerated from those by running `binman entry-docs`. I like this title better than the one in docstring though, because of the explicit TI mention. 'System Firmware' and 'sysfw' sound awfully generic to me, consider renaming the entry to ti-sysfw (like ti-dm) or even ti-k3-sysfw (and ti-k3-dm) if these are K3-specific. > + > +Properties / Entry arguments: > + - sysfw-path: Filename of file to read into the entry, typically sysfw.bin > + > +This entry contains system firmware necessary for booting of K3 architecture > +devices. > + > + > + > Entry: section: Entry that contains other entries > ------------------------------------------------- > > diff --git a/tools/binman/etype/sysfw.py b/tools/binman/etype/sysfw.py > new file mode 100644 > index 0000000000..c73300400b > --- /dev/null > +++ b/tools/binman/etype/sysfw.py > @@ -0,0 +1,60 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ > +# > +# Entry type module for TI SYSFW binary blob > +# > + > +import struct > +import zlib > +import os > +import sys Alphabetical order here would be nicer. > + > +from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg > +from dtoc import fdt_util > +from patman import tools > + > + > +class Entry_sysfw(Entry_blob_named_by_arg): > + """Entry containing System Firmware (SYSFW) blob > + > + Properties / Entry arguments: > + - sysfw-path: Filename of file to read into the entry, typically sysfw.bin > + > +This entry contains system firmware necessary for booting of K3 architecture devices. Should be indented same as the triple-quote marks. Also, the node properties this uses should be documented (load, core?). > + """ > + > + def __init__(self, section, etype, node): > + super().__init__(section, etype, node, 'scp') 'scp' -> 'sysfw' And I think you need to add '-a sysfw-path=...' to Makefile, like you do for ti-dm. > + self.core = "0" Is this useful enough to be read from dtb like the load address? > + self.missing_msg = "sysfw" > + > + def ReadNode(self): > + self._load_addr = fdt_util.GetInt(self._node, 'load', 0) > + self._args = [] This self._args looks unused. > + > + def _SignSysfw(self, out): > + """Sign the sysfw image and write it to the output directory""" > + # Try running the K3 x509 certificate signing script I think this entry should just be the sysfw.bin data passed into binman. You can add a second entry that can sign arbitrary content (this entry), preferably by mostly converting that script to python. I imagine things might look a bit like this in the binman description: ti-k3-x509-sign { key = "key.pem"; load = <0x41c00000>; core = <0>; ti-sysfw { }; }; The script doesn't seem too specialized to me (except the x509 certificate template details) so maybe it could be done as some generalized x509-cert entry? I'm guessing something vblock-ish: sysfw { type = "section"; x509-cert { content = <&sysfw_bin>; key = "key.pem"; config = "x509-config.txt"; outform = "DER"; digest = "sha512"; }; sysfw_bin: ti-sysfw { }; }; But I don't know the x509 details, never looked into it. ... or you can require the sysfw.bin to be pre-signed with that script before passing it to binman (wouldn't be my favourite solution.) > + try: > + args = [ > + '-c', "0", > + '-b', self._filename, > + '-l', str(self._load_addr), > + '-o', out > + ] > + k3_cert_gen_path = os.environ['srctree'] + \ > + "/tools/k3_gen_x509_cert.sh" > + tools.run(k3_cert_gen_path, *args) You'd normally implement a 'bintool' for executables instead of calling them like this. That also lets you mock it in the tests for coverage. > + self.SetContents(tools.read_file(out)) > + return True > + # If not available (example, in the case of binman tests, set entry contents as dummy binary) > + except KeyError: > + self.missing = True > + self.SetContents(b'sysfw') > + return True > + > + def ObtainContents(self): It might be better to override ReadBlobContents() instead of this. I can't really tell. It could let you avoid handling 'missing' manually. > + self.missing = False > + out = tools.get_output_filename("sysfwint") Usually a name prefixed with self.GetUniqueName() (and a dot) is used for these intermediate files. > + self._SignSysfw(out) > + return True > diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py > index 8f00db6945..7c12058fe4 100644 > --- a/tools/binman/ftest.py > +++ b/tools/binman/ftest.py > @@ -87,6 +87,7 @@ ATF_BL31_DATA = b'bl31' > TEE_OS_DATA = b'this is some tee OS data' > ATF_BL2U_DATA = b'bl2u' > OPENSBI_DATA = b'opensbi' > +SYSFW_DATA = b'sysfw' > SCP_DATA = b'scp' > TEST_FDT1_DATA = b'fdt1' > TEST_FDT2_DATA = b'test-fdt2' > @@ -192,6 +193,7 @@ class TestFunctional(unittest.TestCase): > TestFunctional._MakeInputFile('tee-pager.bin', TEE_OS_DATA) > TestFunctional._MakeInputFile('bl2u.bin', ATF_BL2U_DATA) > TestFunctional._MakeInputFile('fw_dynamic.bin', OPENSBI_DATA) > + TestFunctional._MakeInputFile('sysfw.bin', SYSFW_DATA) > TestFunctional._MakeInputFile('scp.bin', SCP_DATA) > > # Add a few .dtb files for testing > @@ -5321,6 +5323,11 @@ fdt fdtmap Extract the devicetree blob from the fdtmap > self.assertIn("Node '/binman/fit': Unknown operation 'unknown'", > str(exc.exception)) > > + def testPackSysfw(self): > + """Test that an image with a SYSFW binary can be created""" > + data = self._DoReadFile('226_sysfw.dts') > + self.assertEqual(SYSFW_DATA, data[:len(SYSFW_DATA)]) > + > > if __name__ == "__main__": > unittest.main() > diff --git a/tools/binman/test/226_sysfw.dts b/tools/binman/test/226_sysfw.dts > new file mode 100644 > index 0000000000..23d64d3688 > --- /dev/null > +++ b/tools/binman/test/226_sysfw.dts > @@ -0,0 +1,13 @@ > +// SPDX-License-Identifier: GPL-2.0+ > + > +/dts-v1/; > + > +/ { > + #address-cells = <1>; > + #size-cells = <1>; > + binman { > + sysfw { > + filename = "sysfw.bin"; > + }; > + }; > +};