Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 NXP |
| 4 | */ |
| 5 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 6 | #include <asm/io.h> |
| 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx-regs.h> |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 9 | #include <asm/arch/sys_proto.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 10 | #include <asm/armv8/mmu.h> |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 11 | #include <asm/mach-imx/boot_mode.h> |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 13 | #include <efi_loader.h> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 14 | #include <event.h> |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 15 | #include <spl.h> |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 16 | #include <asm/arch/rdc.h> |
Ye Li | c408ed3 | 2022-07-26 16:40:49 +0800 | [diff] [blame] | 17 | #include <asm/mach-imx/s400_api.h> |
| 18 | #include <asm/mach-imx/mu_hal.h> |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 19 | #include <cpu_func.h> |
| 20 | #include <asm/setup.h> |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 21 | #include <dm.h> |
| 22 | #include <dm/device-internal.h> |
| 23 | #include <dm/lists.h> |
| 24 | #include <dm/uclass.h> |
| 25 | #include <dm/device.h> |
| 26 | #include <dm/uclass-internal.h> |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 27 | #include <fuse.h> |
Alice Guo | f2c4a39 | 2021-10-29 09:46:32 +0800 | [diff] [blame] | 28 | #include <thermal.h> |
Ye Li | 2e9f15c | 2022-04-06 14:30:08 +0800 | [diff] [blame] | 29 | #include <linux/iopoll.h> |
Ye Li | 48836ae | 2022-04-06 14:30:30 +0800 | [diff] [blame] | 30 | #include <env.h> |
| 31 | #include <env_internal.h> |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 32 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 35 | struct rom_api *g_rom_api = (struct rom_api *)0x1980; |
| 36 | |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 37 | bool is_usb_boot(void) |
| 38 | { |
| 39 | return get_boot_device() == USB_BOOT; |
| 40 | } |
| 41 | |
| 42 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 43 | __weak int board_mmc_get_env_dev(int devno) |
| 44 | { |
| 45 | return devno; |
| 46 | } |
| 47 | |
| 48 | int mmc_get_env_dev(void) |
| 49 | { |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 50 | int ret; |
| 51 | u32 boot; |
| 52 | u16 boot_type; |
| 53 | u8 boot_instance; |
| 54 | |
Rasmus Villemoes | b06f5a4 | 2022-06-20 10:53:22 +0200 | [diff] [blame] | 55 | ret = rom_api_query_boot_infor(QUERY_BT_DEV, &boot); |
Ye Li | 88044c7 | 2021-08-07 16:01:01 +0800 | [diff] [blame] | 56 | |
| 57 | if (ret != ROM_API_OKAY) { |
| 58 | puts("ROMAPI: failure at query_boot_info\n"); |
| 59 | return CONFIG_SYS_MMC_ENV_DEV; |
| 60 | } |
| 61 | |
| 62 | boot_type = boot >> 16; |
| 63 | boot_instance = (boot >> 8) & 0xff; |
| 64 | |
| 65 | /* If not boot from sd/mmc, use default value */ |
| 66 | if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC) |
| 67 | return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV); |
| 68 | |
| 69 | return board_mmc_get_env_dev(boot_instance); |
| 70 | } |
| 71 | #endif |
| 72 | |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 73 | static void set_cpu_info(struct sentinel_get_info_data *info) |
| 74 | { |
| 75 | gd->arch.soc_rev = info->soc; |
| 76 | gd->arch.lifecycle = info->lc; |
| 77 | memcpy((void *)&gd->arch.uid, &info->uid, 4 * sizeof(u32)); |
| 78 | } |
| 79 | |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 80 | u32 get_cpu_rev(void) |
| 81 | { |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 82 | u32 rev = (gd->arch.soc_rev >> 24) - 0xa0; |
| 83 | |
| 84 | return (MXC_CPU_IMX8ULP << 12) | (CHIP_REV_1_0 + rev); |
Peng Fan | 5c2218a | 2021-08-07 16:00:31 +0800 | [diff] [blame] | 85 | } |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 86 | |
| 87 | enum bt_mode get_boot_mode(void) |
| 88 | { |
| 89 | u32 bt0_cfg = 0; |
| 90 | |
Ye Li | 0e35805 | 2021-08-07 16:01:07 +0800 | [diff] [blame] | 91 | bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24); |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 92 | bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK); |
| 93 | |
| 94 | if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) { |
| 95 | /* No low power boot */ |
| 96 | if (bt0_cfg & BT0CFG_DUALBOOT_MASK) |
| 97 | return DUAL_BOOT; |
| 98 | else |
| 99 | return SINGLE_BOOT; |
| 100 | } |
| 101 | |
| 102 | return LOW_POWER_BOOT; |
| 103 | } |
| 104 | |
Ye Li | 2e9f15c | 2022-04-06 14:30:08 +0800 | [diff] [blame] | 105 | bool m33_image_booted(void) |
| 106 | { |
| 107 | u32 gp6; |
| 108 | |
| 109 | /* DGO_GP6 */ |
| 110 | gp6 = readl(SIM_SEC_BASE_ADDR + 0x28); |
| 111 | if (gp6 & BIT(5)) |
| 112 | return true; |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | int m33_image_handshake(ulong timeout_ms) |
| 118 | { |
| 119 | u32 fsr; |
| 120 | int ret; |
| 121 | ulong timeout_us = timeout_ms * 1000; |
| 122 | |
Ye Li | 2e9f15c | 2022-04-06 14:30:08 +0800 | [diff] [blame] | 123 | /* Notify m33 that it's ready to do init srtm(enable mu receive interrupt and so on) */ |
| 124 | setbits_le32(MU0_B_BASE_ADDR + 0x100, BIT(0)); /* set FCR F0 flag of MU0_MUB */ |
| 125 | |
| 126 | /* |
| 127 | * Wait m33 to set FCR F0 flag of MU0_MUA |
| 128 | * Clear FCR F0 flag of MU0_MUB after m33 has set FCR F0 flag of MU0_MUA |
| 129 | */ |
| 130 | ret = readl_poll_sleep_timeout(MU0_B_BASE_ADDR + 0x104, fsr, fsr & BIT(0), 10, timeout_us); |
| 131 | if (!ret) |
| 132 | clrbits_le32(MU0_B_BASE_ADDR + 0x100, BIT(0)); |
| 133 | |
| 134 | return ret; |
| 135 | } |
| 136 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 137 | #define CMC_SRS_TAMPER BIT(31) |
| 138 | #define CMC_SRS_SECURITY BIT(30) |
| 139 | #define CMC_SRS_TZWDG BIT(29) |
| 140 | #define CMC_SRS_JTAG_RST BIT(28) |
| 141 | #define CMC_SRS_CORE1 BIT(16) |
| 142 | #define CMC_SRS_LOCKUP BIT(15) |
| 143 | #define CMC_SRS_SW BIT(14) |
| 144 | #define CMC_SRS_WDG BIT(13) |
| 145 | #define CMC_SRS_PIN_RESET BIT(8) |
| 146 | #define CMC_SRS_WARM BIT(4) |
| 147 | #define CMC_SRS_HVD BIT(3) |
| 148 | #define CMC_SRS_LVD BIT(2) |
| 149 | #define CMC_SRS_POR BIT(1) |
| 150 | #define CMC_SRS_WUP BIT(0) |
| 151 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 152 | static char *get_reset_cause(char *ret) |
| 153 | { |
| 154 | u32 cause1, cause = 0, srs = 0; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 155 | void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88); |
| 156 | void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 157 | |
| 158 | if (!ret) |
| 159 | return "null"; |
| 160 | |
| 161 | srs = readl(reg_srs); |
| 162 | cause1 = readl(reg_ssrs); |
| 163 | |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 164 | cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 165 | |
| 166 | switch (cause) { |
| 167 | case CMC_SRS_POR: |
| 168 | sprintf(ret, "%s", "POR"); |
| 169 | break; |
| 170 | case CMC_SRS_WUP: |
| 171 | sprintf(ret, "%s", "WUP"); |
| 172 | break; |
| 173 | case CMC_SRS_WARM: |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 174 | cause = srs & (CMC_SRS_WDG | CMC_SRS_SW | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 175 | CMC_SRS_JTAG_RST); |
| 176 | switch (cause) { |
| 177 | case CMC_SRS_WDG: |
| 178 | sprintf(ret, "%s", "WARM-WDG"); |
| 179 | break; |
| 180 | case CMC_SRS_SW: |
| 181 | sprintf(ret, "%s", "WARM-SW"); |
| 182 | break; |
| 183 | case CMC_SRS_JTAG_RST: |
| 184 | sprintf(ret, "%s", "WARM-JTAG"); |
| 185 | break; |
| 186 | default: |
| 187 | sprintf(ret, "%s", "WARM-UNKN"); |
| 188 | break; |
| 189 | } |
| 190 | break; |
| 191 | default: |
Peng Fan | 0d720e2 | 2021-08-07 16:01:06 +0800 | [diff] [blame] | 192 | sprintf(ret, "%s-%X", "UNKN", srs); |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | |
| 196 | debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1); |
| 197 | return ret; |
| 198 | } |
| 199 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 200 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 201 | const char *get_imx_type(u32 imxtype) |
| 202 | { |
| 203 | return "8ULP"; |
| 204 | } |
| 205 | |
| 206 | int print_cpuinfo(void) |
| 207 | { |
| 208 | u32 cpurev; |
| 209 | char cause[18]; |
| 210 | |
| 211 | cpurev = get_cpu_rev(); |
| 212 | |
Ye Li | f012ceb | 2021-10-29 09:46:24 +0800 | [diff] [blame] | 213 | printf("CPU: i.MX%s rev%d.%d at %d MHz\n", |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 214 | get_imx_type((cpurev & 0xFF000) >> 12), |
| 215 | (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0, |
| 216 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 217 | |
Alice Guo | f2c4a39 | 2021-10-29 09:46:32 +0800 | [diff] [blame] | 218 | #if defined(CONFIG_IMX_PMC_TEMPERATURE) |
| 219 | struct udevice *udev; |
| 220 | int ret, temp; |
| 221 | |
| 222 | ret = uclass_get_device(UCLASS_THERMAL, 0, &udev); |
| 223 | if (!ret) { |
| 224 | ret = thermal_get_temp(udev, &temp); |
| 225 | if (!ret) |
| 226 | printf("CPU current temperature: %d\n", temp); |
| 227 | else |
| 228 | debug(" - failed to get CPU current temperature\n"); |
| 229 | } else { |
| 230 | debug(" - failed to get CPU current temperature\n"); |
| 231 | } |
| 232 | #endif |
| 233 | |
Peng Fan | af4f3b3 | 2021-08-07 16:00:34 +0800 | [diff] [blame] | 234 | printf("Reset cause: %s\n", get_reset_cause(cause)); |
| 235 | |
Peng Fan | 7253016 | 2021-08-07 16:00:33 +0800 | [diff] [blame] | 236 | printf("Boot mode: "); |
| 237 | switch (get_boot_mode()) { |
| 238 | case LOW_POWER_BOOT: |
| 239 | printf("Low power boot\n"); |
| 240 | break; |
| 241 | case DUAL_BOOT: |
| 242 | printf("Dual boot\n"); |
| 243 | break; |
| 244 | case SINGLE_BOOT: |
| 245 | default: |
| 246 | printf("Single boot\n"); |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | #endif |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 253 | |
Peng Fan | c84bc10 | 2021-08-07 16:00:49 +0800 | [diff] [blame] | 254 | #define UNLOCK_WORD0 0xC520 /* 1st unlock word */ |
| 255 | #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */ |
| 256 | #define REFRESH_WORD0 0xA602 /* 1st refresh word */ |
| 257 | #define REFRESH_WORD1 0xB480 /* 2nd refresh word */ |
| 258 | |
| 259 | static void disable_wdog(void __iomem *wdog_base) |
| 260 | { |
| 261 | u32 val_cs = readl(wdog_base + 0x00); |
| 262 | |
| 263 | if (!(val_cs & 0x80)) |
| 264 | return; |
| 265 | |
| 266 | dmb(); |
| 267 | __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */ |
| 268 | __raw_writel(REFRESH_WORD1, (wdog_base + 0x04)); |
| 269 | dmb(); |
| 270 | |
| 271 | if (!(val_cs & 800)) { |
| 272 | dmb(); |
| 273 | __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04)); |
| 274 | __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04)); |
| 275 | dmb(); |
| 276 | |
| 277 | while (!(readl(wdog_base + 0x00) & 0x800)) |
| 278 | ; |
| 279 | } |
| 280 | writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */ |
| 281 | writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */ |
| 282 | writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */ |
| 283 | |
| 284 | while (!(readl(wdog_base + 0x00) & 0x400)) |
| 285 | ; |
| 286 | } |
| 287 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 288 | void init_wdog(void) |
| 289 | { |
Peng Fan | c84bc10 | 2021-08-07 16:00:49 +0800 | [diff] [blame] | 290 | disable_wdog((void __iomem *)WDG3_RBASE); |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static struct mm_region imx8ulp_arm64_mem_map[] = { |
| 294 | { |
| 295 | /* ROM */ |
| 296 | .virt = 0x0, |
| 297 | .phys = 0x0, |
| 298 | .size = 0x40000UL, |
| 299 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 300 | PTE_BLOCK_OUTER_SHARE |
| 301 | }, |
| 302 | { |
| 303 | /* FLEXSPI0 */ |
| 304 | .virt = 0x04000000, |
| 305 | .phys = 0x04000000, |
| 306 | .size = 0x08000000UL, |
| 307 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 308 | PTE_BLOCK_NON_SHARE | |
| 309 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 310 | }, |
| 311 | { |
| 312 | /* SSRAM (align with 2M) */ |
| 313 | .virt = 0x1FE00000UL, |
| 314 | .phys = 0x1FE00000UL, |
| 315 | .size = 0x400000UL, |
| 316 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 317 | PTE_BLOCK_OUTER_SHARE | |
| 318 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 319 | }, { |
| 320 | /* SRAM1 (align with 2M) */ |
| 321 | .virt = 0x21000000UL, |
| 322 | .phys = 0x21000000UL, |
| 323 | .size = 0x200000UL, |
| 324 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 325 | PTE_BLOCK_OUTER_SHARE | |
| 326 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 327 | }, { |
| 328 | /* SRAM0 (align with 2M) */ |
| 329 | .virt = 0x22000000UL, |
| 330 | .phys = 0x22000000UL, |
| 331 | .size = 0x200000UL, |
| 332 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 333 | PTE_BLOCK_OUTER_SHARE | |
| 334 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 335 | }, { |
| 336 | /* Peripherals */ |
| 337 | .virt = 0x27000000UL, |
| 338 | .phys = 0x27000000UL, |
| 339 | .size = 0x3000000UL, |
| 340 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 341 | PTE_BLOCK_NON_SHARE | |
| 342 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 343 | }, { |
| 344 | /* Peripherals */ |
| 345 | .virt = 0x2D000000UL, |
| 346 | .phys = 0x2D000000UL, |
| 347 | .size = 0x1600000UL, |
| 348 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 349 | PTE_BLOCK_NON_SHARE | |
| 350 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 351 | }, { |
| 352 | /* FLEXSPI1-2 */ |
| 353 | .virt = 0x40000000UL, |
| 354 | .phys = 0x40000000UL, |
| 355 | .size = 0x40000000UL, |
| 356 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 357 | PTE_BLOCK_NON_SHARE | |
| 358 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 359 | }, { |
| 360 | /* DRAM1 */ |
| 361 | .virt = 0x80000000UL, |
| 362 | .phys = 0x80000000UL, |
| 363 | .size = PHYS_SDRAM_SIZE, |
| 364 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 365 | PTE_BLOCK_OUTER_SHARE |
| 366 | }, { |
| 367 | /* |
| 368 | * empty entrie to split table entry 5 |
| 369 | * if needed when TEEs are used |
| 370 | */ |
| 371 | 0, |
| 372 | }, { |
| 373 | /* List terminator */ |
| 374 | 0, |
| 375 | } |
| 376 | }; |
| 377 | |
| 378 | struct mm_region *mem_map = imx8ulp_arm64_mem_map; |
| 379 | |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 380 | static unsigned int imx8ulp_find_dram_entry_in_mem_map(void) |
| 381 | { |
| 382 | int i; |
| 383 | |
| 384 | for (i = 0; i < ARRAY_SIZE(imx8ulp_arm64_mem_map); i++) |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 385 | if (imx8ulp_arm64_mem_map[i].phys == CFG_SYS_SDRAM_BASE) |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 386 | return i; |
| 387 | |
| 388 | hang(); /* Entry not found, this must never happen. */ |
| 389 | } |
| 390 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 391 | /* simplify the page table size to enhance boot speed */ |
| 392 | #define MAX_PTE_ENTRIES 512 |
| 393 | #define MAX_MEM_MAP_REGIONS 16 |
| 394 | u64 get_page_table_size(void) |
| 395 | { |
| 396 | u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64); |
| 397 | u64 size = 0; |
| 398 | |
| 399 | /* |
| 400 | * For each memory region, the max table size: |
| 401 | * 2 level 3 tables + 2 level 2 tables + 1 level 1 table |
| 402 | */ |
| 403 | size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt; |
| 404 | |
| 405 | /* |
| 406 | * We need to duplicate our page table once to have an emergency pt to |
| 407 | * resort to when splitting page tables later on |
| 408 | */ |
| 409 | size *= 2; |
| 410 | |
| 411 | /* |
| 412 | * We may need to split page tables later on if dcache settings change, |
| 413 | * so reserve up to 4 (random pick) page tables for that. |
| 414 | */ |
| 415 | size += one_pt * 4; |
| 416 | |
| 417 | return size; |
| 418 | } |
| 419 | |
| 420 | void enable_caches(void) |
| 421 | { |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 422 | /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch */ |
| 423 | if (rom_pointer[1]) { |
| 424 | /* |
| 425 | * TEE are loaded, So the ddr bank structures |
| 426 | * have been modified update mmu table accordingly |
| 427 | */ |
| 428 | int i = 0; |
| 429 | int entry = imx8ulp_find_dram_entry_in_mem_map(); |
| 430 | u64 attrs = imx8ulp_arm64_mem_map[entry].attrs; |
| 431 | |
| 432 | while (i < CONFIG_NR_DRAM_BANKS && |
| 433 | entry < ARRAY_SIZE(imx8ulp_arm64_mem_map)) { |
| 434 | if (gd->bd->bi_dram[i].start == 0) |
| 435 | break; |
| 436 | imx8ulp_arm64_mem_map[entry].phys = gd->bd->bi_dram[i].start; |
| 437 | imx8ulp_arm64_mem_map[entry].virt = gd->bd->bi_dram[i].start; |
| 438 | imx8ulp_arm64_mem_map[entry].size = gd->bd->bi_dram[i].size; |
| 439 | imx8ulp_arm64_mem_map[entry].attrs = attrs; |
| 440 | debug("Added memory mapping (%d): %llx %llx\n", entry, |
| 441 | imx8ulp_arm64_mem_map[entry].phys, imx8ulp_arm64_mem_map[entry].size); |
| 442 | i++; entry++; |
| 443 | } |
| 444 | } |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 445 | |
| 446 | icache_enable(); |
| 447 | dcache_enable(); |
| 448 | } |
| 449 | |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 450 | __weak int board_phys_sdram_size(phys_size_t *size) |
| 451 | { |
| 452 | if (!size) |
| 453 | return -EINVAL; |
| 454 | |
| 455 | *size = PHYS_SDRAM_SIZE; |
| 456 | return 0; |
| 457 | } |
| 458 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 459 | int dram_init(void) |
| 460 | { |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 461 | unsigned int entry = imx8ulp_find_dram_entry_in_mem_map(); |
| 462 | phys_size_t sdram_size; |
| 463 | int ret; |
| 464 | |
| 465 | ret = board_phys_sdram_size(&sdram_size); |
| 466 | if (ret) |
| 467 | return ret; |
| 468 | |
| 469 | /* rom_pointer[1] contains the size of TEE occupies */ |
| 470 | if (rom_pointer[1]) |
| 471 | gd->ram_size = sdram_size - rom_pointer[1]; |
| 472 | else |
| 473 | gd->ram_size = sdram_size; |
| 474 | |
| 475 | /* also update the SDRAM size in the mem_map used externally */ |
| 476 | imx8ulp_arm64_mem_map[entry].size = sdram_size; |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | int dram_init_banksize(void) |
| 481 | { |
| 482 | int bank = 0; |
| 483 | int ret; |
| 484 | phys_size_t sdram_size; |
| 485 | |
| 486 | ret = board_phys_sdram_size(&sdram_size); |
| 487 | if (ret) |
| 488 | return ret; |
| 489 | |
| 490 | gd->bd->bi_dram[bank].start = PHYS_SDRAM; |
| 491 | if (rom_pointer[1]) { |
| 492 | phys_addr_t optee_start = (phys_addr_t)rom_pointer[0]; |
| 493 | phys_size_t optee_size = (size_t)rom_pointer[1]; |
| 494 | |
| 495 | gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start; |
| 496 | if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_size)) { |
| 497 | if (++bank >= CONFIG_NR_DRAM_BANKS) { |
| 498 | puts("CONFIG_NR_DRAM_BANKS is not enough\n"); |
| 499 | return -1; |
| 500 | } |
| 501 | |
| 502 | gd->bd->bi_dram[bank].start = optee_start + optee_size; |
| 503 | gd->bd->bi_dram[bank].size = PHYS_SDRAM + |
| 504 | sdram_size - gd->bd->bi_dram[bank].start; |
| 505 | } |
| 506 | } else { |
| 507 | gd->bd->bi_dram[bank].size = sdram_size; |
| 508 | } |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
Ji Luo | 2fd258c | 2022-04-06 14:30:28 +0800 | [diff] [blame] | 513 | phys_size_t get_effective_memsize(void) |
| 514 | { |
| 515 | /* return the first bank as effective memory */ |
| 516 | if (rom_pointer[1]) |
| 517 | return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM); |
| 518 | |
| 519 | return gd->ram_size; |
| 520 | } |
| 521 | |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 522 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 523 | void get_board_serial(struct tag_serialnr *serialnr) |
| 524 | { |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 525 | u32 uid[4]; |
| 526 | u32 res; |
| 527 | int ret; |
| 528 | |
| 529 | ret = ahab_read_common_fuse(1, uid, 4, &res); |
| 530 | if (ret) |
| 531 | printf("ahab read fuse failed %d, 0x%x\n", ret, res); |
| 532 | else |
| 533 | printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]); |
| 534 | |
| 535 | serialnr->low = uid[0]; |
| 536 | serialnr->high = uid[3]; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 537 | } |
| 538 | #endif |
| 539 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 540 | static void set_core0_reset_vector(u32 entry) |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 541 | { |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 542 | /* Update SIM1 DGO8 for reset vector base */ |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 543 | writel(entry, SIM1_BASE_ADDR + 0x5c); |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 544 | |
| 545 | /* set update bit */ |
| 546 | setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24); |
| 547 | |
| 548 | /* polling the ack */ |
| 549 | while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0) |
| 550 | ; |
| 551 | |
| 552 | /* clear the update */ |
| 553 | clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24)); |
| 554 | |
| 555 | /* clear the ack by set 1 */ |
| 556 | setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26)); |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 557 | } |
| 558 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 559 | static int trdc_set_access(void) |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 560 | { |
| 561 | /* |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 562 | * TRDC mgr + 4 MBC + 2 MRC. |
| 563 | * S400 should already configure when release RDC |
| 564 | * A35 only map non-secure region for pbridge0 and 1, set sec_access to false |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 565 | */ |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 566 | trdc_mbc_set_access(2, 7, 0, 49, false); |
| 567 | trdc_mbc_set_access(2, 7, 0, 50, false); |
| 568 | trdc_mbc_set_access(2, 7, 0, 51, false); |
| 569 | trdc_mbc_set_access(2, 7, 0, 52, false); |
| 570 | trdc_mbc_set_access(2, 7, 0, 53, false); |
| 571 | trdc_mbc_set_access(2, 7, 0, 54, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 572 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 573 | /* CGC0: PBridge0 slot 47 */ |
| 574 | trdc_mbc_set_access(2, 7, 0, 47, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 575 | |
Peng Fan | 9c87e46 | 2021-08-07 16:00:59 +0800 | [diff] [blame] | 576 | /* Iomuxc0: : PBridge1 slot 33 */ |
| 577 | trdc_mbc_set_access(2, 7, 1, 33, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 578 | |
Ye Li | d325d37 | 2021-10-29 09:46:20 +0800 | [diff] [blame] | 579 | /* flexspi0 */ |
| 580 | trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false); |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 581 | |
| 582 | /* tpm0: PBridge1 slot 21 */ |
| 583 | trdc_mbc_set_access(2, 7, 1, 21, false); |
| 584 | /* lpi2c0: PBridge1 slot 24 */ |
| 585 | trdc_mbc_set_access(2, 7, 1, 24, false); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
Ye Li | ec10a80 | 2022-04-06 14:30:17 +0800 | [diff] [blame] | 589 | void lpav_configure(bool lpav_to_m33) |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 590 | { |
Ye Li | ec10a80 | 2022-04-06 14:30:17 +0800 | [diff] [blame] | 591 | if (!lpav_to_m33) |
| 592 | setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7)); /* LPAV to APD */ |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 593 | |
Peng Fan | fa609b4 | 2021-10-29 09:46:17 +0800 | [diff] [blame] | 594 | /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */ |
| 595 | setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F); |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 596 | |
| 597 | /* LPAV slave/dma2 ch allocation and request allocation to APD */ |
| 598 | writel(0x1f, SIM_SEC_BASE_ADDR + 0x50); |
| 599 | writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54); |
| 600 | writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58); |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 601 | } |
Ye Li | a031155 | 2021-10-29 09:46:22 +0800 | [diff] [blame] | 602 | |
Ye Li | 133f8b8 | 2021-10-29 09:46:25 +0800 | [diff] [blame] | 603 | void load_lposc_fuse(void) |
| 604 | { |
| 605 | int ret; |
| 606 | u32 val = 0, val2 = 0, reg; |
| 607 | |
| 608 | ret = fuse_read(25, 0, &val); |
| 609 | if (ret) |
| 610 | return; /* failed */ |
| 611 | |
| 612 | ret = fuse_read(25, 1, &val2); |
| 613 | if (ret) |
| 614 | return; /* failed */ |
| 615 | |
| 616 | /* LPOSCCTRL */ |
| 617 | reg = readl(0x2802f304); |
| 618 | reg &= ~0xff; |
| 619 | reg |= (val & 0xff); |
| 620 | writel(reg, 0x2802f304); |
| 621 | } |
| 622 | |
Ye Li | 715cfa0 | 2021-10-29 09:46:23 +0800 | [diff] [blame] | 623 | void set_lpav_qos(void) |
| 624 | { |
Ye Li | a031155 | 2021-10-29 09:46:22 +0800 | [diff] [blame] | 625 | /* Set read QoS of dcnano on LPAV NIC */ |
| 626 | writel(0xf, 0x2e447100); |
Ye Li | 43819eb | 2021-10-29 09:46:16 +0800 | [diff] [blame] | 627 | } |
| 628 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 629 | int arch_cpu_init(void) |
| 630 | { |
| 631 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 632 | u32 val = 0; |
| 633 | int ret; |
| 634 | bool rdc_en = true; /* Default assume DBD_EN is set */ |
| 635 | |
Peng Fan | 21bda43 | 2022-04-06 14:30:27 +0800 | [diff] [blame] | 636 | /* Enable System Reset Interrupt using WDOG_AD */ |
| 637 | setbits_le32(CMC1_BASE_ADDR + 0x8C, BIT(13)); |
| 638 | /* Clear AD_PERIPH Power switch domain out of reset interrupt flag */ |
| 639 | setbits_le32(CMC1_BASE_ADDR + 0x70, BIT(4)); |
| 640 | |
| 641 | if (readl(CMC1_BASE_ADDR + 0x90) & BIT(13)) { |
| 642 | /* Clear System Reset Interrupt Flag Register of WDOG_AD */ |
| 643 | setbits_le32(CMC1_BASE_ADDR + 0x90, BIT(13)); |
| 644 | /* Reset WDOG to clear reset request */ |
| 645 | pcc_reset_peripheral(3, WDOG3_PCC3_SLOT, true); |
| 646 | pcc_reset_peripheral(3, WDOG3_PCC3_SLOT, false); |
| 647 | } |
| 648 | |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 649 | /* Disable wdog */ |
| 650 | init_wdog(); |
| 651 | |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 652 | /* Read DBD_EN fuse */ |
| 653 | ret = fuse_read(8, 1, &val); |
| 654 | if (!ret) |
| 655 | rdc_en = !!(val & 0x4000); |
| 656 | |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 657 | if (get_boot_mode() == SINGLE_BOOT) { |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 658 | if (rdc_en) |
| 659 | release_rdc(RDC_TRDC); |
| 660 | |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 661 | trdc_set_access(); |
Ye Li | ec10a80 | 2022-04-06 14:30:17 +0800 | [diff] [blame] | 662 | lpav_configure(false); |
| 663 | } else { |
| 664 | lpav_configure(true); |
Peng Fan | b5c41b1 | 2021-08-07 16:00:58 +0800 | [diff] [blame] | 665 | } |
Peng Fan | fa55b21 | 2021-08-07 16:00:57 +0800 | [diff] [blame] | 666 | |
Ye Li | 7201262 | 2021-10-29 09:46:15 +0800 | [diff] [blame] | 667 | /* Release xrdc, then allow A35 to write SRAM2 */ |
| 668 | if (rdc_en) |
| 669 | release_rdc(RDC_XRDC); |
| 670 | |
Ye Li | 853cc9d | 2021-08-07 16:00:55 +0800 | [diff] [blame] | 671 | xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00); |
| 672 | |
Peng Fan | 4cdb3a3 | 2022-04-06 14:30:12 +0800 | [diff] [blame] | 673 | clock_init_early(); |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 674 | } else { |
| 675 | /* reconfigure core0 reset vector to ROM */ |
| 676 | set_core0_reset_vector(0x1000); |
| 677 | } |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 682 | int imx8ulp_dm_post_init(void) |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 683 | { |
| 684 | struct udevice *devp; |
Ye Li | 2ec75c5 | 2023-01-31 16:42:12 +0800 | [diff] [blame] | 685 | int ret; |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 686 | u32 res; |
| 687 | struct sentinel_get_info_data *info = (struct sentinel_get_info_data *)SRAM0_BASE; |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 688 | |
Ye Li | 2ec75c5 | 2023-01-31 16:42:12 +0800 | [diff] [blame] | 689 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(imx8ulp_mu), &devp); |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 690 | if (ret) { |
| 691 | printf("could not get S400 mu %d\n", ret); |
| 692 | return ret; |
| 693 | } |
| 694 | |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 695 | ret = ahab_get_info(info, &res); |
| 696 | if (ret) { |
| 697 | printf("ahab_get_info failed %d\n", ret); |
| 698 | /* fallback to A0.1 revision */ |
| 699 | memset((void *)info, 0, sizeof(struct sentinel_get_info_data)); |
| 700 | info->soc = 0xa000084d; |
| 701 | } |
| 702 | |
| 703 | set_cpu_info(info); |
| 704 | |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 705 | return 0; |
| 706 | } |
Ye Li | d5ffe55 | 2023-01-31 16:42:13 +0800 | [diff] [blame^] | 707 | |
| 708 | static int imx8ulp_evt_dm_post_init(void *ctx, struct event *event) |
| 709 | { |
| 710 | return imx8ulp_dm_post_init(); |
| 711 | } |
| 712 | EVENT_SPY(EVT_DM_POST_INIT, imx8ulp_evt_dm_post_init); |
Ye Li | 7bea5b0 | 2021-08-07 16:01:00 +0800 | [diff] [blame] | 713 | |
Ye Li | 6ee435eb | 2021-08-07 16:00:50 +0800 | [diff] [blame] | 714 | #if defined(CONFIG_SPL_BUILD) |
| 715 | __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 716 | { |
| 717 | debug("image entry point: 0x%lx\n", spl_image->entry_point); |
| 718 | |
| 719 | set_core0_reset_vector((u32)spl_image->entry_point); |
Ye Li | 6dd4302 | 2021-08-07 16:00:48 +0800 | [diff] [blame] | 720 | |
| 721 | /* Enable the 512KB cache */ |
| 722 | setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4)); |
| 723 | |
| 724 | /* reset core */ |
| 725 | setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16)); |
| 726 | |
| 727 | while (1) |
| 728 | ; |
| 729 | } |
| 730 | #endif |
Peng Fan | fa6ae05 | 2021-08-07 16:01:03 +0800 | [diff] [blame] | 731 | |
| 732 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 733 | { |
Ye Li | 992b0ae | 2021-10-29 09:46:28 +0800 | [diff] [blame] | 734 | u32 val[2] = {}; |
| 735 | int ret; |
| 736 | |
| 737 | ret = fuse_read(5, 3, &val[0]); |
| 738 | if (ret) |
| 739 | goto err; |
| 740 | |
| 741 | ret = fuse_read(5, 4, &val[1]); |
| 742 | if (ret) |
| 743 | goto err; |
| 744 | |
| 745 | mac[0] = val[0]; |
| 746 | mac[1] = val[0] >> 8; |
| 747 | mac[2] = val[0] >> 16; |
| 748 | mac[3] = val[0] >> 24; |
| 749 | mac[4] = val[1]; |
| 750 | mac[5] = val[1] >> 8; |
| 751 | |
| 752 | debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n", |
| 753 | __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 754 | return; |
| 755 | err: |
Peng Fan | fa6ae05 | 2021-08-07 16:01:03 +0800 | [diff] [blame] | 756 | memset(mac, 0, 6); |
Ye Li | 992b0ae | 2021-10-29 09:46:28 +0800 | [diff] [blame] | 757 | printf("%s: fuse read err: %d\n", __func__, ret); |
Peng Fan | fa6ae05 | 2021-08-07 16:01:03 +0800 | [diff] [blame] | 758 | } |
Ye Li | 479fd4a | 2021-08-07 16:01:08 +0800 | [diff] [blame] | 759 | |
| 760 | int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc; |
| 761 | u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev) |
| 762 | { |
| 763 | /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */ |
| 764 | if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en()) |
| 765 | image_offset = 0; |
| 766 | |
| 767 | return image_offset; |
| 768 | } |
Ye Li | 48836ae | 2022-04-06 14:30:30 +0800 | [diff] [blame] | 769 | |
| 770 | enum env_location env_get_location(enum env_operation op, int prio) |
| 771 | { |
| 772 | enum boot_device dev = get_boot_device(); |
| 773 | enum env_location env_loc = ENVL_UNKNOWN; |
| 774 | |
| 775 | if (prio) |
| 776 | return env_loc; |
| 777 | |
| 778 | switch (dev) { |
| 779 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
| 780 | case QSPI_BOOT: |
| 781 | env_loc = ENVL_SPI_FLASH; |
| 782 | break; |
| 783 | #endif |
| 784 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 785 | case SD1_BOOT: |
| 786 | case SD2_BOOT: |
| 787 | case SD3_BOOT: |
| 788 | case MMC1_BOOT: |
| 789 | case MMC2_BOOT: |
| 790 | case MMC3_BOOT: |
| 791 | env_loc = ENVL_MMC; |
| 792 | break; |
| 793 | #endif |
| 794 | default: |
| 795 | #if defined(CONFIG_ENV_IS_NOWHERE) |
| 796 | env_loc = ENVL_NOWHERE; |
| 797 | #endif |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | return env_loc; |
| 802 | } |