All of lore.kernel.org
 help / color / mirror / Atom feed
From: Neha Malcom Francis <n-francis@ti.com>
To: Simon Glass <sjg@chromium.org>
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>
Subject: Re: [PATCH 02/21] tools: sysfw: Add script for generating configuration blobs
Date: Mon, 23 Jan 2023 19:49:05 +0530	[thread overview]
Message-ID: <0d8bfd55-f0aa-4ead-820f-c7ea6f46225e@ti.com> (raw)
In-Reply-To: <20230120101903.179959-3-n-francis@ti.com>

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 <n-francis@ti.com>
> ---
>   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 = '<HHHBB'
> +    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('<BB', num_elems, sw_rev))
> +            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 <type>-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 <type>-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?

-- 
Thanking You
Neha Malcom Francis

  reply	other threads:[~2023-01-23 17:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 10:18 [PATCH 00/21] Migration to using binman to generate bootloader Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 01/21] ti: tools: config: Add board config class to generate config binaries Neha Malcom Francis
2023-01-20 19:46   ` Simon Glass
2023-01-20 10:18 ` [PATCH 02/21] tools: sysfw: Add script for generating configuration blobs Neha Malcom Francis
2023-01-23 14:19   ` Neha Malcom Francis [this message]
2023-01-23 18:42     ` Simon Glass
2023-01-24 10:04       ` Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 03/21] tools: binman: add ti-secure entry type Neha Malcom Francis
2023-01-20 19:46   ` Simon Glass
2023-01-20 10:18 ` [PATCH 04/21] ti: sysfw: tiboot3: Add support for packaging sysfw.itb and tiboot3.bin Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 05/21] j721e: schema: yaml: Add general schema and J721E board config files Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 06/21] j721e: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin, u-boot.img Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 07/21] j7200: yaml: Add J7200 board config files Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 08/21] j7200: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 09/21] am65x: yaml: Add AM65x board config files Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 10/21] am65: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin, u-boot.img Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 11/21] config: am64x: Add board config for AM64x Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 12/21] am64x: dts: binman: Package tiboot3.bin, tispl.bin u-boot.img Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 13/21] Makefile: Add DM, SYSFW_PATH, SYSFW_HS_INNER_CERT_PATH to BINMAN_INDIRS Neha Malcom Francis
2023-01-20 19:46   ` Simon Glass
2023-01-20 10:18 ` [PATCH 14/21] j721s2: yaml: Add board config for J721S2 Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 15/21] j721s2: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img Neha Malcom Francis
2023-01-20 19:46   ` Simon Glass
2023-01-20 10:18 ` [PATCH 16/21] am62: yaml: Add board config for AM62 Neha Malcom Francis
2023-01-20 10:18 ` [PATCH 17/21] am625: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img Neha Malcom Francis
2023-01-20 10:19 ` [PATCH 18/21] am62a: yaml: Add board config for AM62ax Neha Malcom Francis
2023-01-20 10:19 ` [PATCH 19/21] am62a: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img Neha Malcom Francis
2023-01-20 10:19 ` [PATCH 20/21] k3: tools: config.mk: Update makefile and remove scripts Neha Malcom Francis
2023-01-20 10:19 ` [PATCH 21/21] doc: board: ti: Update documentation for binman flow Neha Malcom Francis
2023-01-20 19:46 ` [PATCH 00/21] Migration to using binman to generate bootloader Simon Glass
2023-01-23 12:31   ` Neha Malcom Francis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d8bfd55-f0aa-4ead-820f-c7ea6f46225e@ti.com \
    --to=n-francis@ti.com \
    --cc=afd@ti.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=bb@ti.com \
    --cc=nm@ti.com \
    --cc=rogerq@kernel.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.