mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 02/12] ARM: i.MX8M: Add romapi support
Date: Thu, 14 Jul 2022 09:27:12 +0200	[thread overview]
Message-ID: <20220714072722.2863571-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220714072722.2863571-1-s.hauer@pengutronix.de>

The i.MX8MP and i.MX8MN have a C API to the bootrom to chainload images
for example via USB. This patch adds support for the API based on the
corresponding U-Boot code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/Makefile              |  2 +-
 arch/arm/mach-imx/include/mach/romapi.h | 37 +++++++++++++++++++++
 arch/arm/mach-imx/romapi.c              | 44 +++++++++++++++++++++++++
 include/asm-generic/sections.h          |  1 +
 4 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/include/mach/romapi.h
 create mode 100644 arch/arm/mach-imx/romapi.c

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 2cafcd77e0..fa5133a229 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -18,7 +18,7 @@ lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o
 obj-$(CONFIG_ARCH_IMX7) += imx7.o
 obj-$(CONFIG_ARCH_VF610) += vf610.o
 obj-pbl-$(CONFIG_ARCH_IMX8M) += imx8m.o
-lwl-$(CONFIG_ARCH_IMX8M) += atf.o
+lwl-$(CONFIG_ARCH_IMX8M) += atf.o romapi.o
 obj-$(CONFIG_IMX_IIM)	+= iim.o
 obj-$(CONFIG_NAND_IMX) += nand.o
 lwl-$(CONFIG_ARCH_IMX_EXTERNAL_BOOT_NAND) += external-nand-boot.o
diff --git a/arch/arm/mach-imx/include/mach/romapi.h b/arch/arm/mach-imx/include/mach/romapi.h
new file mode 100644
index 0000000000..8022fc411e
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/romapi.h
@@ -0,0 +1,37 @@
+#ifndef __MACH_IMX_ROMAPI_H
+#define __MACH_IMX_ROMAPI_H
+
+struct rom_api {
+	u16 ver;
+	u16 tag;
+	u32 reserved1;
+	u32 (*download_image)(u8 *dest, u32 offset, u32 size,  u32 xor);
+	u32 (*query_boot_infor)(u32 info_type, u32 *info, u32 xor);
+};
+
+enum boot_dev_type_e {
+	BT_DEV_TYPE_SD = 1,
+	BT_DEV_TYPE_MMC = 2,
+	BT_DEV_TYPE_NAND = 3,
+	BT_DEV_TYPE_FLEXSPINOR = 4,
+	BT_DEV_TYPE_SPI_NOR = 6,
+
+	BT_DEV_TYPE_USB = 0xE,
+	BT_DEV_TYPE_MEM_DEV = 0xF,
+
+	BT_DEV_TYPE_INVALID = 0xFF
+};
+
+#define QUERY_ROM_VER		1
+#define QUERY_BT_DEV		2
+#define QUERY_PAGE_SZ		3
+#define QUERY_IVT_OFF		4
+#define QUERY_BT_STAGE		5
+#define QUERY_IMG_OFF		6
+
+#define ROM_API_OKAY		0xF0
+
+int imx8mp_bootrom_load_image(void);
+int imx8mn_bootrom_load_image(void);
+
+#endif /* __MACH_IMX_ROMAPI_H */
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
new file mode 100644
index 0000000000..f7d421d737
--- /dev/null
+++ b/arch/arm/mach-imx/romapi.c
@@ -0,0 +1,44 @@
+#include <common.h>
+#include <asm/sections.h>
+#include <mach/romapi.h>
+#include <mach/atf.h>
+
+static int imx8m_bootrom_load(struct rom_api *rom_api, void *adr, size_t size)
+{
+	while (size) {
+		size_t chunksize = min(size, (size_t)1024);
+		int ret;
+
+		ret = rom_api->download_image(adr, 0, chunksize,
+					      (uintptr_t)adr ^ chunksize);
+		if (ret != ROM_API_OKAY) {
+			pr_err("Failed to load piggy data (ret = %x)\n", ret);
+			return -EIO;
+		}
+
+		adr += chunksize;
+		size -= chunksize;
+	}
+
+	return 0;
+}
+
+/* read piggydata via a bootrom callback and place it behind our copy in SDRAM */
+static int imx8m_bootrom_load_image(struct rom_api *rom_api)
+{
+	return imx8m_bootrom_load(rom_api,
+				  (void *)MX8M_ATF_BL33_BASE_ADDR + barebox_pbl_size,
+				  __piggydata_end - __piggydata_start);
+}
+
+int imx8mp_bootrom_load_image(void)
+{
+	struct rom_api *rom_api = (void *)0x980;
+
+	return imx8m_bootrom_load_image(rom_api);
+}
+
+int imx8mn_bootrom_load_image(void)
+{
+	return imx8mp_bootrom_load_image();
+}
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 0b2ed5615b..e54123de0e 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -11,6 +11,7 @@ extern char _end[];
 extern char __image_start[];
 extern char __image_end[];
 extern char __piggydata_start[];
+extern char __piggydata_end[];
 extern void *_barebox_image_size;
 extern void *_barebox_bare_init_size;
 extern void *_barebox_pbl_size;
-- 
2.30.2




  parent reply	other threads:[~2022-07-14  7:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  7:27 [PATCH 00/12] imx-usb-loader support for i.MX8MP Sascha Hauer
2022-07-14  7:27 ` [PATCH 01/12] ARM: i.MX8MM: Prepare loading only piggydata in imx-usb-loader Sascha Hauer
2022-07-14  7:27 ` Sascha Hauer [this message]
2022-07-14  7:27 ` [PATCH 03/12] ARM: i.MX8MP: Add common code to load image and jump to it via TF-A Sascha Hauer
2022-07-14  7:27 ` [PATCH 04/12] ARM: i.MX8MP-EVK: Use imx8mp_load_and_start_image_via_tfa() Sascha Hauer
2022-07-14  7:27 ` [PATCH 05/12] imx-usb-loader: Factor out common code to function Sascha Hauer
2022-07-14  7:27 ` [PATCH 06/12] imx-usb-loader: rename mxs functions Sascha Hauer
2022-07-14  7:27 ` [PATCH 07/12] imx-usb-loader: Add i.MX8MP support Sascha Hauer
2022-07-29  9:33   ` Marco Felsch
2022-08-08 12:20     ` Sascha Hauer
2022-07-14  7:27 ` [PATCH 08/12] imx-usb-loader: drop some casting Sascha Hauer
2022-07-14  7:27 ` [PATCH 09/12] imx-usb-loader: Fix first stage length Sascha Hauer
2022-07-14  7:27 ` [PATCH 10/12] imx-usb-loader: simplify read_memory() Sascha Hauer
2022-07-14  7:27 ` [PATCH 11/12] imx-usb-loader: verify correct image length Sascha Hauer
2022-07-14  7:27 ` [PATCH 12/12] imx-usb-loader: drop some unnecessary casting 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=20220714072722.2863571-3-s.hauer@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