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