mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 2/2] ARM: i.MX: Add bootm handler for i.MX flash header v3 images
Date: Wed, 30 Oct 2024 16:00:01 +0100	[thread overview]
Message-ID: <20241030-imx-flash-header-v3-v1-2-1ae28b3b8947@pengutronix.de> (raw)
In-Reply-To: <20241030-imx-flash-header-v3-v1-0-1ae28b3b8947@pengutronix.de>

This adds support for chainloading barebox images in the i.MX flash
header v3 format as found on i.MX9 and some i.MX8 SoCs,

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/Makefile       |  2 +-
 arch/arm/mach-imx/imx-v3-image.c | 50 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 22ea48a833..23f51fc660 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -19,7 +19,7 @@ obj-$(CONFIG_ARCH_IMX7) += imx7.o
 obj-$(CONFIG_ARCH_VF610) += vf610.o
 obj-pbl-$(CONFIG_ARCH_IMX8M) += imx8m.o
 obj-pbl-$(CONFIG_ARCH_IMX_SCRATCHMEM) += scratch.o
-obj-$(CONFIG_ARCH_IMX9) += imx9.o
+obj-$(CONFIG_ARCH_IMX9) += imx9.o imx-v3-image.o
 lwl-$(CONFIG_ARCH_IMX_ATF) += atf.o
 obj-pbl-$(CONFIG_ARCH_IMX8M) += tzasc.o
 obj-pbl-$(CONFIG_ARCH_IMX_ROMAPI) += romapi.o
diff --git a/arch/arm/mach-imx/imx-v3-image.c b/arch/arm/mach-imx/imx-v3-image.c
new file mode 100644
index 0000000000..e5df5fdb81
--- /dev/null
+++ b/arch/arm/mach-imx/imx-v3-image.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <bootm.h>
+#include <memory.h>
+#include <init.h>
+#include <soc/imx9/flash_header.h>
+
+static int do_bootm_imx_image_v3(struct image_data *data)
+{
+	void (*bb)(void);
+	resource_size_t start, end;
+	struct flash_header_v3 *hdr;
+	u32 offset;
+	int ret;
+
+	ret = memory_bank_first_find_space(&start, &end);
+	if (ret)
+		return ret;
+
+	ret = bootm_load_os(data, start);
+	if (ret)
+		return ret;
+
+	hdr = (void *)start;
+	offset = hdr->img[0].offset;
+
+	if (data->verbose)
+		printf("Loaded barebox image to 0x%08llx\n", start);
+
+	shutdown_barebox();
+
+	bb = (void *)start + offset;
+
+	bb();
+
+	return -EIO;
+}
+
+static struct image_handler imx_image_v3_handler = {
+	.name = "",
+	.bootm = do_bootm_imx_image_v3,
+	.filetype = filetype_imx_image_v3,
+};
+
+static int imx_register_image_v3_handler(void)
+{
+	return register_image_handler(&imx_image_v3_handler);
+}
+late_initcall(imx_register_image_v3_handler);

-- 
2.39.5




  parent reply	other threads:[~2024-10-30 15:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 14:59 [PATCH 0/2] ARM: i.MX: Add bootm support " Sascha Hauer
2024-10-30 15:00 ` [PATCH 1/2] filetype: detect i.MX flash header v3 Sascha Hauer
2024-10-30 15:00 ` Sascha Hauer [this message]
2024-11-08 10:57 ` [PATCH 0/2] ARM: i.MX: Add bootm support for i.MX flash header v3 images Sascha Hauer

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=20241030-imx-flash-header-v3-v1-2-1ae28b3b8947@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox