blob: ff0522c2d117bd7caf8c72606871221937aee9c6 [file] [log] [blame]
Rasmus Villemoesae1a8482022-06-20 10:53:19 +02001// SPDX-License-Identifier: GPL-2.0+
2
3#include <asm/global_data.h>
4#include <asm/arch/sys_proto.h>
Peng Fan4decaa22022-07-26 16:40:37 +08005#include <asm/mach-imx/boot_mode.h>
Rasmus Villemoesae1a8482022-06-20 10:53:19 +02006
7DECLARE_GLOBAL_DATA_PTR;
8
9u32 rom_api_download_image(u8 *dest, u32 offset, u32 size)
10{
11 u32 xor = (uintptr_t)dest ^ offset ^ size;
12 volatile gd_t *sgd = gd;
13 u32 ret;
14
15 ret = g_rom_api->download_image(dest, offset, size, xor);
16 set_gd(sgd);
17
18 return ret;
19}
20
21u32 rom_api_query_boot_infor(u32 info_type, u32 *info)
22{
23 u32 xor = info_type ^ (uintptr_t)info;
24 volatile gd_t *sgd = gd;
25 u32 ret;
26
27 ret = g_rom_api->query_boot_infor(info_type, info, xor);
28 set_gd(sgd);
29
30 return ret;
31}
Peng Fan4decaa22022-07-26 16:40:37 +080032
33extern struct rom_api *g_rom_api;
34
35enum boot_device get_boot_device(void)
36{
37 volatile gd_t *pgd = gd;
38 int ret;
39 u32 boot;
40 u16 boot_type;
41 u8 boot_instance;
42 enum boot_device boot_dev = SD1_BOOT;
43
44 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
45 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
46 set_gd(pgd);
47
48 if (ret != ROM_API_OKAY) {
49 puts("ROMAPI: failure at query_boot_info\n");
50 return -1;
51 }
52
53 boot_type = boot >> 16;
54 boot_instance = (boot >> 8) & 0xff;
55
56 switch (boot_type) {
57 case BT_DEV_TYPE_SD:
58 boot_dev = boot_instance + SD1_BOOT;
59 break;
60 case BT_DEV_TYPE_MMC:
61 boot_dev = boot_instance + MMC1_BOOT;
62 break;
63 case BT_DEV_TYPE_NAND:
64 boot_dev = NAND_BOOT;
65 break;
66 case BT_DEV_TYPE_FLEXSPINOR:
67 boot_dev = QSPI_BOOT;
68 break;
Marek Vasut1f81b282022-12-10 02:29:52 +010069 case BT_DEV_TYPE_SPI_NOR:
70 boot_dev = SPI_NOR_BOOT;
71 break;
Peng Fan4decaa22022-07-26 16:40:37 +080072 case BT_DEV_TYPE_USB:
Tim Harvey68883f12023-04-24 09:33:44 -070073 if (!is_imx8ulp() && !is_imx9())
74 boot_instance = 0;
Peng Fan4f3099b2022-07-26 16:40:38 +080075 boot_dev = boot_instance + USB_BOOT;
Peng Fan4decaa22022-07-26 16:40:37 +080076 break;
77 default:
78 break;
79 }
80
81 return boot_dev;
82}