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 E31C1C25B50 for ; Mon, 23 Jan 2023 18:45:30 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2083F857A7; Mon, 23 Jan 2023 19:44:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lfee+Dg+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0511D85799; Mon, 23 Jan 2023 19:44:16 +0100 (CET) Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) (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 3DF7D8579C for ; Mon, 23 Jan 2023 19:44:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-yb1-xb31.google.com with SMTP id p188so16037459yba.5 for ; Mon, 23 Jan 2023 10:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jE5+zaj4JqNTi2ooGOwY3uVFVYLerJu1x4jmNxr/9oc=; b=lfee+Dg+/UuZ5BXT74rnSAMoNr8tnnANbI1ELnXuTJTV6pLQt2ZipVL/8mGBhZ7nTO +9f9MNvKTvJFjFG2m8nybvdlIi9fcmBO2NVSxvIfahEjwVxt9NZzJ2pjIs+s13wAvXzY kGJOcbJSsJJ9SUQFtGvEj1l8vdE0tUeYChd1E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jE5+zaj4JqNTi2ooGOwY3uVFVYLerJu1x4jmNxr/9oc=; b=pIwDYuBkTFAQwwehFtsOwickxBq/PJGLsWzMaPP0LMlftNb5O6MPXuhM9ly2EainCV VZ54k6oaJpF+oz5wcFnz9dv2HcpRESMHdxDJ+1RPiwABLlw1P8BOGN3h0A1/dGG8qk3i 2V0ky+/0J+/xXRLAaL3mrrxIQuFArWfQ83HcHG8E5fXi3b93+Ghbt6x5klzu0s8Sn4W1 dCGPJy5lMKSuuPAARteWlyWFf9yWfiZcn590y73hF/J7VRsbIxlW4Q32o+FAnBoCLpNN VtxHZwaWJcJzVjQJKSt9zYhpvx3Ehv/0xG2u5wu+ZJuxeOp/wEDOG+nDVAbCi6680iAu foYw== X-Gm-Message-State: AFqh2kriUwxrwrBHmuQ/eWyUxpibloqe8YBy/w4GoMyQN+qED39Rvgxe uTTqMndLKyLEBP7fhsXAWi5akoB7bYFhb6xaKkzVmQ== X-Google-Smtp-Source: AMrXdXsryZSc7AUtCxyAS7gBinE4bUIUAgAxk6wgWjXs3qLk9CbH+NRrZKG21yG/f/sTZKX3kRacDdkGqLCWKLsu67U= X-Received: by 2002:a25:e808:0:b0:7f1:de22:7e7c with SMTP id k8-20020a25e808000000b007f1de227e7cmr2314474ybd.330.1674499448671; Mon, 23 Jan 2023 10:44:08 -0800 (PST) MIME-Version: 1.0 References: <20230120101903.179959-1-n-francis@ti.com> <20230120101903.179959-3-n-francis@ti.com> <0d8bfd55-f0aa-4ead-820f-c7ea6f46225e@ti.com> In-Reply-To: <0d8bfd55-f0aa-4ead-820f-c7ea6f46225e@ti.com> From: Simon Glass Date: Mon, 23 Jan 2023 11:42:29 -0700 Message-ID: Subject: Re: [PATCH 02/21] tools: sysfw: Add script for generating configuration blobs To: Neha Malcom Francis Cc: alpernebiyasak@gmail.com, nm@ti.com, bb@ti.com, u-boot@lists.denx.de, trini@konsulko.com, afd@ti.com, vigneshr@ti.com, rogerq@kernel.org Content-Type: text/plain; charset="UTF-8" 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 Hi Neha, On Mon, 23 Jan 2023 at 07:19, Neha Malcom Francis wrote: > > Hi Simon, > > On 20/01/23 15:48, Neha Malcom Francis wrote: > > Certain devices in the K3 architecture such as AM64x require board > > configuration binaries packed along with their descriptions into a > > sysfw_data binary. The final binary is required to be packed into the > > final system firmware images. > > > > Signed-off-by: Neha Malcom Francis > > --- > > tools/k3_sysfw_boardcfg_blob_creator.py | 116 ++++++++++++++++++++++++ > > 1 file changed, 116 insertions(+) > > create mode 100755 tools/k3_sysfw_boardcfg_blob_creator.py > > > > diff --git a/tools/k3_sysfw_boardcfg_blob_creator.py b/tools/k3_sysfw_boardcfg_blob_creator.py > > new file mode 100755 > > index 0000000000..da99808521 > > --- /dev/null > > +++ b/tools/k3_sysfw_boardcfg_blob_creator.py > > @@ -0,0 +1,116 @@ > > +# SPDX-License-Identifier: GPL-2.0+ > > +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ > > +# > > +# TI Script for Board Configuration Packaging > > +# > > + > > +import argparse > > +import logging > > +import os > > +import struct > > +import tempfile > > +from shutil import copyfileobj > > +from shutil import rmtree > > + > > +BOARDCFG = 0xB > > +BOARDCFG_SEC = 0xD > > +BOARDCFG_PM = 0xE > > +BOARDCFG_RM = 0xC > > +BOARDCFG_NUM_ELEMS = 4 > > + > > +class BoardCfgDesc(): > > + """Get board config descriptor for a given file """ > > + > > + fmt = ' > + index = 0 > > + offset = 0 > > + > > + def __init__(self, outfile, devgrp, > > + sw_rev = 0, > > + num_elems = BOARDCFG_NUM_ELEMS): > > + self.devgrp = devgrp > > + try: > > + self.fh = open(outfile, 'wb') > > + bytes = self.fh.write(struct.pack(' > + self.offset += bytes > > + self.offset += num_elems * struct.calcsize(self.fmt) > > + self.tmpdir = tempfile.mkdtemp() > > + descfile = os.path.join(self.tmpdir, "desc") > > + bcfgfile = os.path.join(self.tmpdir, "bcfg") > > + self.desc_fh = open(descfile, "wb+") > > + self.bcfg_fh = open(bcfgfile, "wb+") > > + except: > > + raise Exception("File Error") > > + > > + def add_boardcfg(self, bcfgtype, bcfgfile): > > + with open(bcfgfile, 'rb') as bfh: > > + bcfg = bfh.read() > > + size = len(bcfg) > > + desc = struct.pack(self.fmt, bcfgtype, self.offset, size, self.devgrp, 0) > > + self.desc_fh.write(desc) > > + self.bcfg_fh.write(bcfg) > > + logging.debug("Packing boardcfg data of size [%d bytes] from file %s", size, bcfgfile) > > + self.offset += size > > + self.index += 1 > > + > > + def finalize(self): > > + try: > > + self.desc_fh.seek(0) > > + self.bcfg_fh.seek(0) > > + copyfileobj(self.desc_fh, self.fh) > > + copyfileobj(self.bcfg_fh, self.fh) > > + except: > > + logging.error("**** Error in finalizing boardcfg file ****") > > + raise Exception("File Error") > > + finally: > > + self.fh.close() > > + self.desc_fh.close() > > + self.bcfg_fh.close() > > + rmtree(self.tmpdir) > > + > > +def create_sysfw_blob(args): > > + """Create a SYSFW data blob to be used as a component in combined image """ > > + > > + logging.info("#### Creating SYSFW data blob - %s ####", args.output_file.name) > > + logging.info("#### SW Rev = %d", args.sw_rev) > > + logging.info("#### Device Group = %d", args.devgrp) > > + > > + cnt = 0 > > + if args.boardcfg is not None: cnt = cnt + 1 > > + if args.boardcfg_sec is not None: cnt = cnt + 1 > > + if args.boardcfg_pm is not None: cnt = cnt + 1 > > + if args.boardcfg_rm is not None: cnt = cnt + 1 > > + > > + blob = BoardCfgDesc(args.output_file.name, args.devgrp, args.sw_rev, cnt) > > + if args.boardcfg is not None: > > + logging.info("#### Board config binary - %s", args.boardcfg.name) > > + blob.add_boardcfg(BOARDCFG, args.boardcfg.name) > > + if args.boardcfg_sec is not None: > > + logging.info("#### Board config security binary - %s", args.boardcfg_sec.name) > > + blob.add_boardcfg(BOARDCFG_SEC, args.boardcfg_sec.name) > > + if args.boardcfg_pm is not None: > > + logging.info("#### Board config PM binary - %s", args.boardcfg_pm.name) > > + blob.add_boardcfg(BOARDCFG_PM, args.boardcfg_pm.name) > > + if args.boardcfg_rm is not None: > > + logging.info("#### Board config RM binary - %s", args.boardcfg_rm.name) > > + blob.add_boardcfg(BOARDCFG_RM, args.boardcfg_rm.name) > > + > > + blob.finalize() > > + > > +# options -> device, sw_rev, boardcfg, security boardcfg, pm boardcfg, rm boardcfg, output file > > + > > +# parser for mandatory arguments > > +pp = argparse.ArgumentParser(add_help=False) > > +pp.add_argument('-l', '--log-level', type=str, default="INFO", choices=["INFO", "DEBUG"]) > > +pp.add_argument('--sw-rev', type=int, default=1) > > +pp.add_argument('-o', '--output-file', type=argparse.FileType('wb'), default="./sysfw-data.bin") > > +pp.add_argument('-d', '--devgrp', type=int, default=0) > > +pp.add_argument('-b', '--boardcfg', type=argparse.FileType('rb')) > > +pp.add_argument('-s', '--boardcfg-sec', type=argparse.FileType('rb')) > > +pp.add_argument('-p', '--boardcfg-pm', type=argparse.FileType('rb')) > > +pp.add_argument('-r', '--boardcfg-rm', type=argparse.FileType('rb')) > > + > > +args = pp.parse_args() > > +logging.getLogger().setLevel(args.log_level) > > +logging.debug(args) > > +create_sysfw_blob(args) > > Working on your reviews, I'm trying to get rid of all external scripts > and putting them into btools/etypes which seems fit. > * ti_secure_path can be nicely put into a btool > * ti_boardcfg can also be an etype that outputs -cfg.bins > > But... I am not sure about this script above > k3_sysfw_boardcfg_blob_creator.py. This script essentially does a more > detailed packing of the -cfg.bins that have been generated by > binman. Since binman doesn't account for dependencies as of now; I am > not sure how to go about it. Any pointers? > > I could have something like > > combined-sysfw-cfg.bin { > sysfw-boardcfg { > ti-boardcfg { > config = "board-cfg.yaml"; > schema = "schema.yaml"; > } > ti-boardcfg { > config = "sec-cfg.yaml"; > ... > > But is there any way to not have to implement this entry within entry > coupled with packaging, which I think might get a little messy? Yes you can have entries within entries and it should work fine. See [1] for an example of that. It is a correct description of how the image is put together, so I don't really see a better way. BTW perhaps 'config' and 'schema' are a bit too generic, but we can worry about that later. There is no schema validation for binman at present but I suspect I'll be looking at later in the year. Regarding accounting for dependencies, it is possible to put a 'filename' property in a section such that binman outputs the contents of the section to a separate file. Regards, SImon [1] https://patchwork.ozlabs.org/project/uboot/patch/20220110031413.1970836-39-sjg@chromium.org/