Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | 370382c | 2019-11-14 12:57:35 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 10 | #include <debug_uart.h> |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 11 | #include <dfu.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 12 | #include <env.h> |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 13 | #include <env_internal.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 16 | #include <net.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 17 | #include <sata.h> |
Michal Simek | b216cc1 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 18 | #include <ahci.h> |
| 19 | #include <scsi.h> |
Stefan Herbrechtsmeier | 3ff3bd4 | 2022-06-20 18:36:43 +0200 | [diff] [blame] | 20 | #include <soc.h> |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 21 | #include <malloc.h> |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 22 | #include <memalign.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 23 | #include <wdt.h> |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 24 | #include <asm/arch/clk.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 25 | #include <asm/arch/hardware.h> |
| 26 | #include <asm/arch/sys_proto.h> |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 27 | #include <asm/arch/psu_init_gpl.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 28 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 29 | #include <asm/global_data.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 30 | #include <asm/io.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 31 | #include <asm/ptrace.h> |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 32 | #include <dm/device.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 33 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 34 | #include <usb.h> |
| 35 | #include <dwc3-uboot.h> |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 36 | #include <zynqmppl.h> |
Ibai Erkiaga | c8a3efa | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 37 | #include <zynqmp_firmware.h> |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 38 | #include <g_dnl.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 39 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 40 | #include <linux/delay.h> |
| 41 | #include <linux/sizes.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 42 | #include "../common/board.h" |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 43 | |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 44 | #include "pm_cfg_obj.h" |
| 45 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
Michal Simek | 1aab114 | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 48 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Oleksandr Suvorov | dae95a4 | 2022-07-22 17:16:04 +0300 | [diff] [blame] | 49 | static xilinx_desc zynqmppl = { |
| 50 | xilinx_zynqmp, csu_dma, 1, &zynqmp_op, 0, &zynqmp_op, NULL, |
| 51 | ZYNQMP_FPGA_FLAGS |
| 52 | }; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 53 | #endif |
| 54 | |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 55 | int __maybe_unused psu_uboot_init(void) |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 56 | { |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 57 | int ret; |
| 58 | |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 59 | ret = psu_init(); |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 60 | if (ret) |
| 61 | return ret; |
Michal Simek | 1f55e57 | 2020-03-20 08:59:02 +0100 | [diff] [blame] | 62 | |
Adrian Fiergolski | 8e87ecf | 2021-06-08 12:37:23 +0200 | [diff] [blame] | 63 | /* |
| 64 | * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon |
| 65 | * supply sense channel to SysMon supply registers inside the IP. |
| 66 | * This register must be programmed to complete SysMon IP |
| 67 | * configuration. The default register configuration after |
| 68 | * power-up is incorrect. Hence, fix this by writing the |
| 69 | * correct value - 0x3210. |
| 70 | */ |
| 71 | writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL, |
| 72 | ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS); |
| 73 | |
Michal Simek | 1f55e57 | 2020-03-20 08:59:02 +0100 | [diff] [blame] | 74 | /* Delay is required for clocks to be propagated */ |
| 75 | udelay(1000000); |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 79 | |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 80 | #if !defined(CONFIG_SPL_BUILD) |
| 81 | # if defined(CONFIG_DEBUG_UART_BOARD_INIT) |
| 82 | void board_debug_uart_init(void) |
| 83 | { |
| 84 | # if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
| 85 | psu_uboot_init(); |
| 86 | # endif |
| 87 | } |
| 88 | # endif |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 89 | |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 90 | # if defined(CONFIG_BOARD_EARLY_INIT_F) |
| 91 | int board_early_init_f(void) |
| 92 | { |
| 93 | int ret = 0; |
| 94 | # if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) && !defined(CONFIG_DEBUG_UART_BOARD_INIT) |
| 95 | ret = psu_uboot_init(); |
| 96 | # endif |
| 97 | return ret; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 98 | } |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 99 | # endif |
Michal Simek | ba6fb83 | 2022-02-17 14:28:40 +0100 | [diff] [blame] | 100 | #endif |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 101 | |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 102 | static int multi_boot(void) |
| 103 | { |
Michal Simek | 6aca283 | 2021-07-27 16:17:31 +0200 | [diff] [blame] | 104 | u32 multiboot = 0; |
| 105 | int ret; |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 106 | |
Michal Simek | 6aca283 | 2021-07-27 16:17:31 +0200 | [diff] [blame] | 107 | ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot); |
| 108 | if (ret) |
| 109 | return -EINVAL; |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 110 | |
Michal Simek | 21e5c32 | 2021-07-27 14:05:27 +0200 | [diff] [blame] | 111 | return multiboot; |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Jorge Ramirez-Ortiz | 34deca5 | 2021-10-13 15:48:00 +0200 | [diff] [blame] | 114 | #if defined(CONFIG_SPL_BUILD) |
| 115 | static void restore_jtag(void) |
| 116 | { |
| 117 | if (current_el() != 3) |
| 118 | return; |
| 119 | |
| 120 | writel(CSU_JTAG_SEC_GATE_DISABLE, &csu_base->jtag_sec); |
| 121 | writel(CSU_JTAG_DAP_ENABLE_DEBUG, &csu_base->jtag_dap_cfg); |
| 122 | writel(CSU_JTAG_CHAIN_WR_SETUP, &csu_base->jtag_chain_status_wr); |
| 123 | writel(CRLAPB_DBG_LPD_CTRL_SETUP_CLK, &crlapb_base->dbg_lpd_ctrl); |
| 124 | writel(CRLAPB_RST_LPD_DBG_RESET, &crlapb_base->rst_lpd_dbg); |
| 125 | writel(CSU_PCAP_PROG_RELEASE_PL, &csu_base->pcap_prog); |
| 126 | } |
| 127 | #endif |
| 128 | |
Jorge Ramirez-Ortiz | b0e388a | 2021-10-13 19:04:47 +0200 | [diff] [blame] | 129 | static void print_secure_boot(void) |
| 130 | { |
| 131 | u32 status = 0; |
| 132 | |
| 133 | if (zynqmp_mmio_read((ulong)&csu_base->status, &status)) |
| 134 | return; |
| 135 | |
| 136 | printf("Secure Boot:\t%sauthenticated, %sencrypted\n", |
| 137 | status & ZYNQMP_CSU_STATUS_AUTHENTICATED ? "" : "not ", |
| 138 | status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not "); |
| 139 | } |
| 140 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 141 | int board_init(void) |
| 142 | { |
Stefan Herbrechtsmeier | 3ff3bd4 | 2022-06-20 18:36:43 +0200 | [diff] [blame] | 143 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
| 144 | struct udevice *soc; |
| 145 | char name[SOC_MAX_STR_SIZE]; |
| 146 | int ret; |
| 147 | #endif |
Michal Simek | 3d49c95 | 2022-10-05 11:39:27 +0200 | [diff] [blame^] | 148 | |
| 149 | #if defined(CONFIG_SPL_BUILD) |
| 150 | /* Check *at build time* if the filename is an non-empty string */ |
| 151 | if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1) |
| 152 | zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj, |
| 153 | zynqmp_pm_cfg_obj_size); |
| 154 | #endif |
| 155 | |
Michal Simek | 826d7eca | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 156 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
Ibai Erkiaga | 2d9b95b | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 157 | struct udevice *dev; |
| 158 | |
| 159 | uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev); |
| 160 | if (!dev) |
| 161 | panic("PMU Firmware device not found - Enable it"); |
Michal Simek | 826d7eca | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 162 | #endif |
Ibai Erkiaga | 2d9b95b | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 163 | |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 164 | #if defined(CONFIG_SPL_BUILD) |
Michal Simek | ae9dc11 | 2021-02-02 16:34:48 +0100 | [diff] [blame] | 165 | printf("Silicon version:\t%d\n", zynqmp_get_silicon_version()); |
Jorge Ramirez-Ortiz | 34deca5 | 2021-10-13 15:48:00 +0200 | [diff] [blame] | 166 | |
| 167 | /* the CSU disables the JTAG interface when secure boot is enabled */ |
Ricardo Salveti | 5b774f0 | 2021-11-04 16:28:02 -0300 | [diff] [blame] | 168 | if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG)) |
Jorge Ramirez-Ortiz | 34deca5 | 2021-10-13 15:48:00 +0200 | [diff] [blame] | 169 | restore_jtag(); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 170 | #else |
| 171 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) |
| 172 | xilinx_read_eeprom(); |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 173 | #endif |
| 174 | |
Michal Simek | fb7242d | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 175 | printf("EL Level:\tEL%d\n", current_el()); |
| 176 | |
Michal Simek | 1aab114 | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 177 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Stefan Herbrechtsmeier | 3ff3bd4 | 2022-06-20 18:36:43 +0200 | [diff] [blame] | 178 | ret = soc_get(&soc); |
| 179 | if (!ret) { |
| 180 | ret = soc_get_machine(soc, name, sizeof(name)); |
| 181 | if (ret >= 0) { |
| 182 | zynqmppl.name = strdup(name); |
| 183 | fpga_init(); |
| 184 | fpga_add(fpga_xilinx, &zynqmppl); |
| 185 | } |
| 186 | } |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 187 | #endif |
| 188 | |
Jorge Ramirez-Ortiz | b0e388a | 2021-10-13 19:04:47 +0200 | [diff] [blame] | 189 | /* display secure boot information */ |
| 190 | print_secure_boot(); |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 191 | if (current_el() == 3) |
Michal Simek | 21e5c32 | 2021-07-27 14:05:27 +0200 | [diff] [blame] | 192 | printf("Multiboot:\t%d\n", multi_boot()); |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 193 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | int board_early_init_r(void) |
| 198 | { |
| 199 | u32 val; |
| 200 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 201 | if (current_el() != 3) |
| 202 | return 0; |
| 203 | |
Michal Simek | 245d528 | 2017-07-12 10:32:18 +0200 | [diff] [blame] | 204 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 205 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 206 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 207 | if (!val) { |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 208 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 209 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 210 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 211 | |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 212 | /* Program freq register in System counter */ |
| 213 | writel(zynqmp_get_system_timer_freq(), |
| 214 | &iou_scntr_secure->base_frequency_id_register); |
| 215 | /* And enable system counter */ |
| 216 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 217 | &iou_scntr_secure->counter_control_register); |
| 218 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 222 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 223 | char *const argv[]) |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 224 | { |
| 225 | int ret = 0; |
| 226 | |
| 227 | if (current_el() > 1) { |
| 228 | smp_kick_all_cpus(); |
| 229 | dcache_disable(); |
| 230 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 231 | ES_TO_AARCH64); |
| 232 | } else { |
| 233 | printf("FAIL: current EL is not above EL1\n"); |
| 234 | ret = EINVAL; |
| 235 | } |
| 236 | return ret; |
| 237 | } |
| 238 | |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 239 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 240 | int dram_init_banksize(void) |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 241 | { |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 242 | int ret; |
| 243 | |
| 244 | ret = fdtdec_setup_memory_banksize(); |
| 245 | if (ret) |
| 246 | return ret; |
| 247 | |
| 248 | mem_map_fill(); |
| 249 | |
| 250 | return 0; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 251 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 252 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 253 | int dram_init(void) |
| 254 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 255 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | ac04bfa | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 256 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 257 | |
| 258 | return 0; |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 259 | } |
Michal Simek | 97ab961 | 2021-05-31 11:03:19 +0200 | [diff] [blame] | 260 | |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 261 | #else |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 262 | int dram_init_banksize(void) |
| 263 | { |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 264 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 265 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 266 | |
| 267 | mem_map_fill(); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 272 | int dram_init(void) |
| 273 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 274 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 275 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 276 | |
| 277 | return 0; |
| 278 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 279 | #endif |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 280 | |
Michal Simek | 2a22033 | 2021-07-13 16:39:26 +0200 | [diff] [blame] | 281 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 282 | void reset_cpu(void) |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 283 | { |
| 284 | } |
Michal Simek | 2a22033 | 2021-07-13 16:39:26 +0200 | [diff] [blame] | 285 | #endif |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 286 | |
Michal Simek | 8ec3004 | 2020-08-20 10:54:45 +0200 | [diff] [blame] | 287 | static u8 __maybe_unused zynqmp_get_bootmode(void) |
| 288 | { |
| 289 | u8 bootmode; |
| 290 | u32 reg = 0; |
| 291 | int ret; |
| 292 | |
| 293 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
| 294 | if (ret) |
| 295 | return -EINVAL; |
| 296 | |
Michal Simek | 58cc08c | 2021-07-28 12:25:49 +0200 | [diff] [blame] | 297 | debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK); |
| 298 | debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT); |
| 299 | |
Michal Simek | 8ec3004 | 2020-08-20 10:54:45 +0200 | [diff] [blame] | 300 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 301 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 302 | |
| 303 | bootmode = reg & BOOT_MODES_MASK; |
| 304 | |
| 305 | return bootmode; |
| 306 | } |
| 307 | |
Michal Simek | 342edfe | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 308 | #if defined(CONFIG_BOARD_LATE_INIT) |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 309 | static const struct { |
| 310 | u32 bit; |
| 311 | const char *name; |
| 312 | } reset_reasons[] = { |
| 313 | { RESET_REASON_DEBUG_SYS, "DEBUG" }, |
| 314 | { RESET_REASON_SOFT, "SOFT" }, |
| 315 | { RESET_REASON_SRST, "SRST" }, |
| 316 | { RESET_REASON_PSONLY, "PS-ONLY" }, |
| 317 | { RESET_REASON_PMU, "PMU" }, |
| 318 | { RESET_REASON_INTERNAL, "INTERNAL" }, |
| 319 | { RESET_REASON_EXTERNAL, "EXTERNAL" }, |
| 320 | {} |
| 321 | }; |
| 322 | |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 323 | static int reset_reason(void) |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 324 | { |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 325 | u32 reg; |
| 326 | int i, ret; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 327 | const char *reason = NULL; |
| 328 | |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 329 | ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®); |
| 330 | if (ret) |
| 331 | return -EINVAL; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 332 | |
| 333 | puts("Reset reason:\t"); |
| 334 | |
| 335 | for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) { |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 336 | if (reg & reset_reasons[i].bit) { |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 337 | reason = reset_reasons[i].name; |
| 338 | printf("%s ", reset_reasons[i].name); |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | puts("\n"); |
| 344 | |
| 345 | env_set("reset_reason", reason); |
| 346 | |
Michal Simek | 0954c8c | 2021-02-09 08:50:22 +0100 | [diff] [blame] | 347 | return 0; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 350 | static int set_fdtfile(void) |
| 351 | { |
| 352 | char *compatible, *fdtfile; |
| 353 | const char *suffix = ".dtb"; |
| 354 | const char *vendor = "xilinx/"; |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 355 | int fdt_compat_len; |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 356 | |
| 357 | if (env_get("fdtfile")) |
| 358 | return 0; |
| 359 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 360 | compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 361 | &fdt_compat_len); |
| 362 | if (compatible && fdt_compat_len) { |
| 363 | char *name; |
| 364 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 365 | debug("Compatible: %s\n", compatible); |
| 366 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 367 | name = strchr(compatible, ','); |
| 368 | if (!name) |
| 369 | return -EINVAL; |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 370 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 371 | name++; |
| 372 | |
| 373 | fdtfile = calloc(1, strlen(vendor) + strlen(name) + |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 374 | strlen(suffix) + 1); |
| 375 | if (!fdtfile) |
| 376 | return -ENOMEM; |
| 377 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 378 | sprintf(fdtfile, "%s%s%s", vendor, name, suffix); |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 379 | |
| 380 | env_set("fdtfile", fdtfile); |
| 381 | free(fdtfile); |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 387 | int board_late_init(void) |
| 388 | { |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 389 | u8 bootmode; |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 390 | struct udevice *dev; |
| 391 | int bootseq = -1; |
| 392 | int bootseq_len = 0; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 393 | int env_targets_len = 0; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 394 | const char *mode; |
| 395 | char *new_targets; |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 396 | char *env_targets; |
Michal Simek | 7cb4cca | 2021-10-25 10:10:52 +0200 | [diff] [blame] | 397 | int ret, multiboot; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 398 | |
Michal Simek | 482f549 | 2018-10-05 08:55:16 +0200 | [diff] [blame] | 399 | #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD) |
| 400 | usb_ether_init(); |
| 401 | #endif |
| 402 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 403 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 404 | debug("Saved variables - Skipping\n"); |
| 405 | return 0; |
| 406 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 407 | |
Michal Simek | bab07b6 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 408 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 409 | return 0; |
| 410 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 411 | ret = set_fdtfile(); |
| 412 | if (ret) |
| 413 | return ret; |
| 414 | |
Michal Simek | 7cb4cca | 2021-10-25 10:10:52 +0200 | [diff] [blame] | 415 | multiboot = multi_boot(); |
| 416 | if (multiboot >= 0) |
| 417 | env_set_hex("multiboot", multiboot); |
| 418 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 419 | bootmode = zynqmp_get_bootmode(); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 420 | |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 421 | puts("Bootmode: "); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 422 | switch (bootmode) { |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 423 | case USB_MODE: |
| 424 | puts("USB_MODE\n"); |
T Karthik Reddy | 9eee8e3 | 2021-03-24 23:37:57 -0600 | [diff] [blame] | 425 | mode = "usb_dfu0 usb_dfu1"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 426 | env_set("modeboot", "usb_dfu_spl"); |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 427 | break; |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 428 | case JTAG_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 429 | puts("JTAG_MODE\n"); |
Siva Durga Prasad Paladugu | 9c44170 | 2019-06-25 17:41:09 +0530 | [diff] [blame] | 430 | mode = "jtag pxe dhcp"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 431 | env_set("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 432 | break; |
| 433 | case QSPI_MODE_24BIT: |
| 434 | case QSPI_MODE_32BIT: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 435 | mode = "qspi0"; |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 436 | puts("QSPI_MODE\n"); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 437 | env_set("modeboot", "qspiboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 438 | break; |
Michal Simek | 02d66cd | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 439 | case EMMC_MODE: |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 440 | puts("EMMC_MODE\n"); |
T Karthik Reddy | 19735c3 | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 441 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 442 | "mmc@ff160000", &dev) && |
| 443 | uclass_get_device_by_name(UCLASS_MMC, |
| 444 | "sdhci@ff160000", &dev)) { |
| 445 | puts("Boot from EMMC but without SD0 enabled!\n"); |
| 446 | return -1; |
| 447 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 448 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
T Karthik Reddy | 19735c3 | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 449 | |
| 450 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 451 | bootseq = dev_seq(dev); |
Ashok Reddy Soma | a10be05 | 2021-09-15 08:52:17 +0200 | [diff] [blame] | 452 | env_set("modeboot", "emmcboot"); |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 453 | break; |
| 454 | case SD_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 455 | puts("SD_MODE\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 456 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e91778d | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 457 | "mmc@ff160000", &dev) && |
| 458 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 459 | "sdhci@ff160000", &dev)) { |
| 460 | puts("Boot from SD0 but without SD0 enabled!\n"); |
| 461 | return -1; |
| 462 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 463 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 464 | |
| 465 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 466 | bootseq = dev_seq(dev); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 467 | env_set("modeboot", "sdboot"); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 468 | break; |
Siva Durga Prasad Paladugu | 29a77d2 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 469 | case SD1_LSHFT_MODE: |
| 470 | puts("LVL_SHFT_"); |
Michal Simek | 293f47b | 2021-10-18 13:30:04 +0200 | [diff] [blame] | 471 | fallthrough; |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 472 | case SD_MODE1: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 473 | puts("SD_MODE1\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 474 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e91778d | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 475 | "mmc@ff170000", &dev) && |
| 476 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 477 | "sdhci@ff170000", &dev)) { |
| 478 | puts("Boot from SD1 but without SD1 enabled!\n"); |
| 479 | return -1; |
| 480 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 481 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 482 | |
| 483 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 484 | bootseq = dev_seq(dev); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 485 | env_set("modeboot", "sdboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 486 | break; |
| 487 | case NAND_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 488 | puts("NAND_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 489 | mode = "nand0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 490 | env_set("modeboot", "nandboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 491 | break; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 492 | default: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 493 | mode = ""; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 494 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 495 | break; |
| 496 | } |
| 497 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 498 | if (bootseq >= 0) { |
| 499 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 500 | debug("Bootseq len: %x\n", bootseq_len); |
Michal Simek | 7a117c7 | 2021-01-11 13:46:58 +0100 | [diff] [blame] | 501 | env_set_hex("bootseq", bootseq); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 502 | } |
| 503 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 504 | /* |
| 505 | * One terminating char + one byte for space between mode |
| 506 | * and default boot_targets |
| 507 | */ |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 508 | env_targets = env_get("boot_targets"); |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 509 | if (env_targets) |
| 510 | env_targets_len = strlen(env_targets); |
| 511 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 512 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 513 | bootseq_len); |
Michal Simek | 089b84d | 2018-06-13 09:42:41 +0200 | [diff] [blame] | 514 | if (!new_targets) |
| 515 | return -ENOMEM; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 516 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 517 | if (bootseq >= 0) |
| 518 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 519 | env_targets ? env_targets : ""); |
| 520 | else |
| 521 | sprintf(new_targets, "%s %s", mode, |
| 522 | env_targets ? env_targets : ""); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 523 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 524 | env_set("boot_targets", new_targets); |
Michal Simek | 7748823 | 2021-07-28 12:46:39 +0200 | [diff] [blame] | 525 | free(new_targets); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 526 | |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 527 | reset_reason(); |
| 528 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 529 | return board_late_init_xilinx(); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 530 | } |
Michal Simek | 342edfe | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 531 | #endif |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 532 | |
| 533 | int checkboard(void) |
| 534 | { |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 535 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 536 | return 0; |
| 537 | } |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 538 | |
Michal Simek | e0026bf | 2021-05-19 15:16:19 +0200 | [diff] [blame] | 539 | int mmc_get_env_dev(void) |
| 540 | { |
| 541 | struct udevice *dev; |
| 542 | int bootseq = 0; |
| 543 | |
| 544 | switch (zynqmp_get_bootmode()) { |
| 545 | case EMMC_MODE: |
| 546 | case SD_MODE: |
| 547 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 548 | "mmc@ff160000", &dev) && |
| 549 | uclass_get_device_by_name(UCLASS_MMC, |
| 550 | "sdhci@ff160000", &dev)) { |
| 551 | return -1; |
| 552 | } |
| 553 | bootseq = dev_seq(dev); |
| 554 | break; |
| 555 | case SD1_LSHFT_MODE: |
| 556 | case SD_MODE1: |
| 557 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 558 | "mmc@ff170000", &dev) && |
| 559 | uclass_get_device_by_name(UCLASS_MMC, |
| 560 | "sdhci@ff170000", &dev)) { |
| 561 | return -1; |
| 562 | } |
| 563 | bootseq = dev_seq(dev); |
| 564 | break; |
| 565 | default: |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | debug("bootseq %d\n", bootseq); |
| 570 | |
| 571 | return bootseq; |
| 572 | } |
| 573 | |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 574 | enum env_location env_get_location(enum env_operation op, int prio) |
| 575 | { |
| 576 | u32 bootmode = zynqmp_get_bootmode(); |
| 577 | |
| 578 | if (prio) |
| 579 | return ENVL_UNKNOWN; |
| 580 | |
| 581 | switch (bootmode) { |
| 582 | case EMMC_MODE: |
| 583 | case SD_MODE: |
| 584 | case SD1_LSHFT_MODE: |
| 585 | case SD_MODE1: |
| 586 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 587 | return ENVL_FAT; |
| 588 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 589 | return ENVL_EXT4; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 590 | return ENVL_NOWHERE; |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 591 | case NAND_MODE: |
| 592 | if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) |
| 593 | return ENVL_NAND; |
| 594 | if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) |
| 595 | return ENVL_UBI; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 596 | return ENVL_NOWHERE; |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 597 | case QSPI_MODE_24BIT: |
| 598 | case QSPI_MODE_32BIT: |
| 599 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 600 | return ENVL_SPI_FLASH; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 601 | return ENVL_NOWHERE; |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 602 | case JTAG_MODE: |
| 603 | default: |
| 604 | return ENVL_NOWHERE; |
| 605 | } |
| 606 | } |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 607 | |
| 608 | #if defined(CONFIG_SET_DFU_ALT_INFO) |
| 609 | |
| 610 | #define DFU_ALT_BUF_LEN SZ_1K |
| 611 | |
| 612 | void set_dfu_alt_info(char *interface, char *devstr) |
| 613 | { |
Venkatesh Yadav Abbarapu | 50a8f8e | 2022-10-04 11:22:54 +0530 | [diff] [blame] | 614 | int multiboot; |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 615 | int bootseq = 0; |
| 616 | |
| 617 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); |
| 618 | |
Michal Simek | f0d6f46 | 2022-08-09 16:32:52 +0200 | [diff] [blame] | 619 | if (env_get("dfu_alt_info")) |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 620 | return; |
| 621 | |
| 622 | memset(buf, 0, sizeof(buf)); |
| 623 | |
| 624 | multiboot = multi_boot(); |
Michal Simek | 7cb4cca | 2021-10-25 10:10:52 +0200 | [diff] [blame] | 625 | if (multiboot < 0) |
| 626 | multiboot = 0; |
| 627 | |
| 628 | multiboot = env_get_hex("multiboot", multiboot); |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 629 | debug("Multiboot: %d\n", multiboot); |
| 630 | |
| 631 | switch (zynqmp_get_bootmode()) { |
| 632 | case EMMC_MODE: |
| 633 | case SD_MODE: |
| 634 | case SD1_LSHFT_MODE: |
| 635 | case SD_MODE1: |
| 636 | bootseq = mmc_get_env_dev(); |
| 637 | if (!multiboot) |
| 638 | snprintf(buf, DFU_ALT_BUF_LEN, |
Michal Simek | 3e09d19 | 2022-08-09 16:32:54 +0200 | [diff] [blame] | 639 | "mmc %d=boot.bin fat %d 1;" |
Michal Simek | 6910319 | 2021-10-18 14:02:15 +0200 | [diff] [blame] | 640 | "%s fat %d 1", |
| 641 | bootseq, bootseq, |
| 642 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq); |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 643 | else |
| 644 | snprintf(buf, DFU_ALT_BUF_LEN, |
Michal Simek | 3e09d19 | 2022-08-09 16:32:54 +0200 | [diff] [blame] | 645 | "mmc %d=boot%04d.bin fat %d 1;" |
Michal Simek | 6910319 | 2021-10-18 14:02:15 +0200 | [diff] [blame] | 646 | "%s fat %d 1", |
| 647 | bootseq, multiboot, bootseq, |
| 648 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq); |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 649 | break; |
Stefan Herbrechtsmeier | fb027cd | 2022-06-20 18:36:46 +0200 | [diff] [blame] | 650 | #if defined(CONFIG_SYS_SPI_U_BOOT_OFFS) |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 651 | case QSPI_MODE_24BIT: |
| 652 | case QSPI_MODE_32BIT: |
| 653 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 654 | "sf 0:0=boot.bin raw %x 0x1500000;" |
Michal Simek | 6910319 | 2021-10-18 14:02:15 +0200 | [diff] [blame] | 655 | "%s raw 0x%x 0x500000", |
| 656 | multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, |
| 657 | CONFIG_SYS_SPI_U_BOOT_OFFS); |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 658 | break; |
Stefan Herbrechtsmeier | fb027cd | 2022-06-20 18:36:46 +0200 | [diff] [blame] | 659 | #endif |
Michal Simek | cfb3760 | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 660 | default: |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | env_set("dfu_alt_info", buf); |
| 665 | puts("DFU alt info setting: done\n"); |
| 666 | } |
| 667 | #endif |