Revision | 748da8abb0d020bedbfa4dbc7b3cafdaf9bc60f1 (tree) |
---|---|
Time | 2022-07-25 22:35:34 |
Author | Rasmus Villemoes <rasmus.villemoes@prev...> |
Commiter | Stefano Babic |
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>
@@ -178,6 +178,10 @@ enum boot_dev_type_e { | ||
178 | 178 | #define ROM_API_OKAY 0xF0 |
179 | 179 | |
180 | 180 | extern struct rom_api *g_rom_api; |
181 | + | |
182 | +u32 rom_api_download_image(u8 *dest, u32 offset, u32 size); | |
183 | +u32 rom_api_query_boot_infor(u32 info_type, u32 *info); | |
184 | + | |
181 | 185 | #endif |
182 | 186 | |
183 | 187 | /* For i.MX ULP */ |
@@ -243,3 +243,4 @@ obj-$(CONFIG_ARCH_IMX8) += imx8/ | ||
243 | 243 | obj-$(CONFIG_ARCH_IMXRT) += imxrt/ |
244 | 244 | |
245 | 245 | obj-$(CONFIG_SPL_BOOTROM_SUPPORT) += spl_imx_romapi.o |
246 | +obj-$(CONFIG_IMX8_ROMAPI) += romapi.o |
@@ -0,0 +1,30 @@ | ||
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | + | |
3 | +#include <asm/global_data.h> | |
4 | +#include <asm/arch/sys_proto.h> | |
5 | + | |
6 | +DECLARE_GLOBAL_DATA_PTR; | |
7 | + | |
8 | +u32 rom_api_download_image(u8 *dest, u32 offset, u32 size) | |
9 | +{ | |
10 | + u32 xor = (uintptr_t)dest ^ offset ^ size; | |
11 | + volatile gd_t *sgd = gd; | |
12 | + u32 ret; | |
13 | + | |
14 | + ret = g_rom_api->download_image(dest, offset, size, xor); | |
15 | + set_gd(sgd); | |
16 | + | |
17 | + return ret; | |
18 | +} | |
19 | + | |
20 | +u32 rom_api_query_boot_infor(u32 info_type, u32 *info) | |
21 | +{ | |
22 | + u32 xor = info_type ^ (uintptr_t)info; | |
23 | + volatile gd_t *sgd = gd; | |
24 | + u32 ret; | |
25 | + | |
26 | + ret = g_rom_api->query_boot_infor(info_type, info, xor); | |
27 | + set_gd(sgd); | |
28 | + | |
29 | + return ret; | |
30 | +} |