Rasmus Villemoes | ae1a848 | 2022-06-20 10:53:19 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | #include <asm/global_data.h> |
| 4 | #include <asm/arch/sys_proto.h> |
Peng Fan | 4decaa2 | 2022-07-26 16:40:37 +0800 | [diff] [blame] | 5 | #include <asm/mach-imx/boot_mode.h> |
Rasmus Villemoes | ae1a848 | 2022-06-20 10:53:19 +0200 | [diff] [blame] | 6 | |
| 7 | DECLARE_GLOBAL_DATA_PTR; |
| 8 | |
| 9 | u32 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 | |
| 21 | u32 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 Fan | 4decaa2 | 2022-07-26 16:40:37 +0800 | [diff] [blame] | 32 | |
| 33 | extern struct rom_api *g_rom_api; |
| 34 | |
| 35 | enum 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 Vasut | 1f81b28 | 2022-12-10 02:29:52 +0100 | [diff] [blame] | 69 | case BT_DEV_TYPE_SPI_NOR: |
| 70 | boot_dev = SPI_NOR_BOOT; |
| 71 | break; |
Peng Fan | 4decaa2 | 2022-07-26 16:40:37 +0800 | [diff] [blame] | 72 | case BT_DEV_TYPE_USB: |
Tim Harvey | 68883f1 | 2023-04-24 09:33:44 -0700 | [diff] [blame] | 73 | if (!is_imx8ulp() && !is_imx9()) |
| 74 | boot_instance = 0; |
Peng Fan | 4f3099b | 2022-07-26 16:40:38 +0800 | [diff] [blame] | 75 | boot_dev = boot_instance + USB_BOOT; |
Peng Fan | 4decaa2 | 2022-07-26 16:40:37 +0800 | [diff] [blame] | 76 | break; |
| 77 | default: |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | return boot_dev; |
| 82 | } |