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