summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2022-06-20 10:53:19 +0200
committerStefano Babic <sbabic@denx.de>2022-07-25 15:35:34 +0200
commit748da8abb0d020bedbfa4dbc7b3cafdaf9bc60f1 (patch)
tree7c4d901c63072ec40119b90cd99ea90df65e232e /arch
parentde20c5d405a39cd4560495c342412e388fa73a52 (diff)
imx8: add rom api wrappers
The ROM API is thoroughly undocumented, but apparently passing the xor of the real arguments as an extra argument is required [1]. Also, we need to do the "save gd/restore gd" dance. These are both error-prone, and lead to a lot of code duplication. Since both imx8m[np] and imx8ulp SOCs have this, add a separate translation unit which is included precisely when the new CONFIG_IMX8_ROMAPI symbol is set, which provide convenience wrappers that take care of computing the xor value as well as doing the gd dance, and that thus have a more intuitive API. Subsequent patches will make use of these to reduce boilerplate. [1] One wonders, for example, if the check is only applied to the lower 32 bits, or if we're implicitly relying on all 64-bit pointer values we're passing effectively have 0 in the upper 32 bits. Reviewed-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/mach-imx/sys_proto.h4
-rw-r--r--arch/arm/mach-imx/Makefile1
-rw-r--r--arch/arm/mach-imx/romapi.c30
3 files changed, 35 insertions, 0 deletions
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h
index 02816197c10..fadb67d04a2 100644
--- a/arch/arm/include/asm/mach-imx/sys_proto.h
+++ b/arch/arm/include/asm/mach-imx/sys_proto.h
@@ -178,6 +178,10 @@ enum boot_dev_type_e {
#define ROM_API_OKAY 0xF0
extern struct rom_api *g_rom_api;
+
+u32 rom_api_download_image(u8 *dest, u32 offset, u32 size);
+u32 rom_api_query_boot_infor(u32 info_type, u32 *info);
+
#endif
/* For i.MX ULP */
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index aa0b6447f14..3cbcb151b86 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -243,3 +243,4 @@ obj-$(CONFIG_ARCH_IMX8) += imx8/
obj-$(CONFIG_ARCH_IMXRT) += imxrt/
obj-$(CONFIG_SPL_BOOTROM_SUPPORT) += spl_imx_romapi.o
+obj-$(CONFIG_IMX8_ROMAPI) += romapi.o
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
new file mode 100644
index 00000000000..0e7b1d1a001
--- /dev/null
+++ b/arch/arm/mach-imx/romapi.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <asm/global_data.h>
+#include <asm/arch/sys_proto.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+u32 rom_api_download_image(u8 *dest, u32 offset, u32 size)
+{
+ u32 xor = (uintptr_t)dest ^ offset ^ size;
+ volatile gd_t *sgd = gd;
+ u32 ret;
+
+ ret = g_rom_api->download_image(dest, offset, size, xor);
+ set_gd(sgd);
+
+ return ret;
+}
+
+u32 rom_api_query_boot_infor(u32 info_type, u32 *info)
+{
+ u32 xor = info_type ^ (uintptr_t)info;
+ volatile gd_t *sgd = gd;
+ u32 ret;
+
+ ret = g_rom_api->query_boot_infor(info_type, info, xor);
+ set_gd(sgd);
+
+ return ret;
+}