All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Cc: Marek Vasut <marex@denx.de>,
	"NXP i.MX U-Boot Team" <uboot-imx@nxp.com>,
	Adam Ford <aford173@gmail.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	Andrejs Cainikovs <andrejs.cainikovs@toradex.com>,
	Angus Ainslie <angus@akkea.ca>,
	Emanuele Ghidoli <emanuele.ghidoli@toradex.com>,
	Fabio Estevam <festevam@gmail.com>,
	Francesco Dolcini <francesco.dolcini@toradex.com>,
	Marcel Ziswiler <marcel.ziswiler@toradex.com>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Simon Glass <sjg@chromium.org>,
	Stefan Eichenberger <stefan.eichenberger@toradex.com>,
	Stefano Babic <sbabic@denx.de>,
	Tim Harvey <tharvey@gateworks.com>, Tom Rini <trini@konsulko.com>,
	kernel@puri.sm, u-boot@dh-electronics.com
Subject: [PATCH 1/3] binman: Add nxp_imx8mimage etype
Date: Tue, 23 Apr 2024 20:31:21 +0200	[thread overview]
Message-ID: <20240423183247.335791-1-marex@denx.de> (raw)

Add new binman etype derived from mkimage etype which generates configuration
input file for mkimage -T imx8mimage, and runs the mkimage on input data. The
mkimage -T imx8mimage is used to generate combined image with SPL and DDR PHY
blobs which is bootable on i.MX8M.

The configuration file generated here is equivalent of imx8mimage.cfg, which
is the file passed to '$ mkimage -T imx8mimage -n imx8mimage.cfg ...' . The
settings generated into the imx8mimage.cfg file are configured via supported
binman DT properties, nxp,boot-from, nxp,loader-address, nxp,rom-version.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "NXP i.MX U-Boot Team" <uboot-imx@nxp.com>
Cc: Adam Ford <aford173@gmail.com>
Cc: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Cc: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
Cc: Angus Ainslie <angus@akkea.ca>
Cc: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Francesco Dolcini <francesco.dolcini@toradex.com>
Cc: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefan Eichenberger <stefan.eichenberger@toradex.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: kernel@puri.sm
Cc: u-boot@dh-electronics.com
Cc: u-boot@lists.denx.de
---
 tools/binman/etype/nxp_imx8mimage.py | 73 ++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 tools/binman/etype/nxp_imx8mimage.py

diff --git a/tools/binman/etype/nxp_imx8mimage.py b/tools/binman/etype/nxp_imx8mimage.py
new file mode 100644
index 00000000000..5a106e0a76e
--- /dev/null
+++ b/tools/binman/etype/nxp_imx8mimage.py
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023-2024 Marek Vasut <marex@denx.de>
+# Written with much help from Simon Glass <sjg@chromium.org>
+#
+# Entry-type module for generating the i.MX8M mkimage -T imx8mimage
+# configuration file and invocation of mkimage -T imx8mimage on the
+# configuration file and input data.
+#
+
+from collections import OrderedDict
+
+from binman.entry import Entry
+from binman.etype.mkimage import Entry_mkimage
+from binman import elf
+from dtoc import fdt_util
+from u_boot_pylib import tools
+
+class Entry_nxp_imx8mimage(Entry_mkimage):
+    """NXP i.MX8M imx8mimage .cfg file generator and mkimage invoker
+
+    Properties / Entry arguments:
+        - nxp,boot-from - device to boot from (e.g. 'sd')
+        - nxp,loader-address - loader address (SPL text base)
+        - nxp,rom-version - BootROM version ('2' for i.MX8M Nano and Plus)
+    """
+
+    def __init__(self, section, etype, node):
+        super().__init__(section, etype, node)
+        self.required_props = ['nxp,boot-from', 'nxp,rom-version', 'nxp,loader-address']
+
+    def ReadNode(self):
+        super().ReadNode()
+        self.boot_from = fdt_util.GetString(self._node, 'nxp,boot-from')
+        self.loader_address = fdt_util.GetInt(self._node, 'nxp,loader-address')
+        self.rom_version = fdt_util.GetInt(self._node, 'nxp,rom-version')
+        self.ReadEntries()
+
+    def BuildSectionData(self, required):
+        _, input_fname, uniq = self.collect_contents_to_file(
+            self._entries.values(), 'input')
+        # Generate mkimage configuration file similar to imx8mimage.cfg
+        # and pass it to mkimage to generate SPL image for us here.
+        cfg_fname = tools.get_output_filename('nxp.imx8mimage.cfg.%s' % uniq)
+        with open(cfg_fname, 'w') as outf:
+            print('ROM_VERSION v%d' % self.rom_version, file=outf)
+            print('BOOT_FROM %s' % self.boot_from, file=outf)
+            print('LOADER %s %#x' % (input_fname, self.loader_address), file=outf)
+
+        output_fname = tools.get_output_filename(f'cfg-out.{uniq}')
+        args = ['-d', input_fname, '-n', cfg_fname, '-T', 'imx8mimage',
+                output_fname]
+        if self.mkimage.run_cmd(*args) is not None:
+            return tools.read_file(output_fname)
+        else:
+            # Bintool is missing; just use the input data as the output
+            self.record_missing_bintool(self.mkimage)
+            return data
+
+    def SetImagePos(self, image_pos):
+        # Customized SoC specific SetImagePos which skips the mkimage etype
+        # implementation and removes the 0x48 offset introduced there. That
+        # offset is only used for uImage/fitImage, which is not the case in
+        # here.
+        upto = 0x00
+        for entry in super().GetEntries().values():
+            entry.SetOffsetSize(upto, None)
+
+            # Give up if any entries lack a size
+            if entry.size is None:
+                return
+            upto += entry.size
+
+        super(Entry_mkimage, self).SetImagePos(image_pos)
-- 
2.43.0


             reply	other threads:[~2024-04-23 18:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 18:31 Marek Vasut [this message]
2024-04-23 18:31 ` [PATCH 2/3] ARM: dts: imx: Switch Ronetix iMX8MQ-CM to imx8mq-u-boot.dtsi Marek Vasut
2024-04-23 18:31 ` [PATCH 3/3] ARM: dts: imx: Convert i.MX8M flash.bin image generation to binman Marek Vasut
2024-04-25 20:34   ` Tim Harvey
2024-04-25 20:39     ` Fabio Estevam
2024-04-25 23:33     ` Marek Vasut
2024-11-07  1:55   ` Adam Ford
2024-11-08 15:07     ` Marek Vasut
2024-11-08 16:21       ` Lukasz Majewski

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=20240423183247.335791-1-marex@denx.de \
    --to=marex@denx.de \
    --cc=aford173@gmail.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=andrejs.cainikovs@toradex.com \
    --cc=angus@akkea.ca \
    --cc=emanuele.ghidoli@toradex.com \
    --cc=festevam@gmail.com \
    --cc=francesco.dolcini@toradex.com \
    --cc=kernel@puri.sm \
    --cc=marcel.ziswiler@toradex.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sbabic@denx.de \
    --cc=sjg@chromium.org \
    --cc=stefan.eichenberger@toradex.com \
    --cc=tharvey@gateworks.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@dh-electronics.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.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.