blob: f7c6e3ed4e3f6a3ac3353f2a86f96b14837bf7de [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek04b7e622015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek04b7e622015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simek09a7d7d2020-01-07 09:02:52 +010010#include <debug_uart.h>
Michal Simekcfb37602021-07-27 16:19:18 +020011#include <dfu.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Michal Simek8d4a8d42020-07-30 13:37:49 +020013#include <env_internal.h>
Simon Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Michal Simek97ab9612021-05-31 11:03:19 +020015#include <image.h>
16#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020019#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020020#include <ahci.h>
21#include <scsi.h>
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020022#include <soc.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020023#include <malloc.h>
Michal Simekcfb37602021-07-27 16:19:18 +020024#include <memalign.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020025#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010026#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010027#include <asm/arch/hardware.h>
28#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010029#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060030#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060031#include <asm/global_data.h>
Michal Simek04b7e622015-01-15 10:01:51 +010032#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060033#include <asm/ptrace.h>
Michal Simekf183a982018-04-25 11:20:43 +020034#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020035#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053036#include <usb.h>
37#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010038#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010039#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020040#include <g_dnl.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060041#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060042#include <linux/delay.h>
43#include <linux/sizes.h>
Michal Simek705d44a2020-03-31 12:39:37 +020044#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010045
Luca Ceresoli23e65002019-05-21 18:06:43 +020046#include "pm_cfg_obj.h"
47
Michal Simek04b7e622015-01-15 10:01:51 +010048DECLARE_GLOBAL_DATA_PTR;
49
Michal Simek1aab1142020-09-09 14:41:56 +020050#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Michal Simek8111aff2016-02-01 15:05:58 +010051static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
Michal Simek8111aff2016-02-01 15:05:58 +010052#endif
53
Michal Simeke5710e32022-02-17 14:28:42 +010054int __maybe_unused psu_uboot_init(void)
Michal Simek8b353302017-02-07 14:32:26 +010055{
Michal Simek09a7d7d2020-01-07 09:02:52 +010056 int ret;
57
Michal Simekc8785f22018-01-10 11:48:48 +010058 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +010059 if (ret)
60 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +010061
Adrian Fiergolski8e87ecf2021-06-08 12:37:23 +020062 /*
63 * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon
64 * supply sense channel to SysMon supply registers inside the IP.
65 * This register must be programmed to complete SysMon IP
66 * configuration. The default register configuration after
67 * power-up is incorrect. Hence, fix this by writing the
68 * correct value - 0x3210.
69 */
70 writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL,
71 ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS);
72
Michal Simek1f55e572020-03-20 08:59:02 +010073 /* Delay is required for clocks to be propagated */
74 udelay(1000000);
Michal Simeke5710e32022-02-17 14:28:42 +010075
76 return 0;
77}
Michal Simeke0f36102017-07-12 13:08:41 +020078
Michal Simeke5710e32022-02-17 14:28:42 +010079#if !defined(CONFIG_SPL_BUILD)
80# if defined(CONFIG_DEBUG_UART_BOARD_INIT)
81void board_debug_uart_init(void)
82{
83# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
84 psu_uboot_init();
85# endif
86}
87# endif
Michal Simek09a7d7d2020-01-07 09:02:52 +010088
Michal Simeke5710e32022-02-17 14:28:42 +010089# if defined(CONFIG_BOARD_EARLY_INIT_F)
90int board_early_init_f(void)
91{
92 int ret = 0;
93# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) && !defined(CONFIG_DEBUG_UART_BOARD_INIT)
94 ret = psu_uboot_init();
95# endif
96 return ret;
Michal Simek8b353302017-02-07 14:32:26 +010097}
Michal Simeke5710e32022-02-17 14:28:42 +010098# endif
Michal Simekba6fb832022-02-17 14:28:40 +010099#endif
Michal Simek8b353302017-02-07 14:32:26 +0100100
Michal Simek46900462020-02-11 12:43:14 +0100101static int multi_boot(void)
102{
Michal Simek6aca2832021-07-27 16:17:31 +0200103 u32 multiboot = 0;
104 int ret;
Michal Simek46900462020-02-11 12:43:14 +0100105
Michal Simek6aca2832021-07-27 16:17:31 +0200106 ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot);
107 if (ret)
108 return -EINVAL;
Michal Simek46900462020-02-11 12:43:14 +0100109
Michal Simek21e5c322021-07-27 14:05:27 +0200110 return multiboot;
Michal Simek46900462020-02-11 12:43:14 +0100111}
112
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200113#if defined(CONFIG_SPL_BUILD)
114static void restore_jtag(void)
115{
116 if (current_el() != 3)
117 return;
118
119 writel(CSU_JTAG_SEC_GATE_DISABLE, &csu_base->jtag_sec);
120 writel(CSU_JTAG_DAP_ENABLE_DEBUG, &csu_base->jtag_dap_cfg);
121 writel(CSU_JTAG_CHAIN_WR_SETUP, &csu_base->jtag_chain_status_wr);
122 writel(CRLAPB_DBG_LPD_CTRL_SETUP_CLK, &crlapb_base->dbg_lpd_ctrl);
123 writel(CRLAPB_RST_LPD_DBG_RESET, &crlapb_base->rst_lpd_dbg);
124 writel(CSU_PCAP_PROG_RELEASE_PL, &csu_base->pcap_prog);
125}
126#endif
127
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200128static void print_secure_boot(void)
129{
130 u32 status = 0;
131
132 if (zynqmp_mmio_read((ulong)&csu_base->status, &status))
133 return;
134
135 printf("Secure Boot:\t%sauthenticated, %sencrypted\n",
136 status & ZYNQMP_CSU_STATUS_AUTHENTICATED ? "" : "not ",
137 status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
138}
139
Michal Simek04b7e622015-01-15 10:01:51 +0100140int board_init(void)
141{
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200142#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
143 struct udevice *soc;
144 char name[SOC_MAX_STR_SIZE];
145 int ret;
146#endif
Michal Simek826d7eca2020-03-04 08:48:16 +0100147#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100148 struct udevice *dev;
149
150 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
151 if (!dev)
152 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100153#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100154
Luca Ceresoli23e65002019-05-21 18:06:43 +0200155#if defined(CONFIG_SPL_BUILD)
156 /* Check *at build time* if the filename is an non-empty string */
157 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
158 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
159 zynqmp_pm_cfg_obj_size);
Michal Simekae9dc112021-02-02 16:34:48 +0100160 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200161
162 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti5b774f02021-11-04 16:28:02 -0300163 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200164 restore_jtag();
Michal Simek394ee242020-08-03 13:01:45 +0200165#else
166 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
167 xilinx_read_eeprom();
Luca Ceresoli23e65002019-05-21 18:06:43 +0200168#endif
169
Michal Simekfb7242d2015-06-22 14:31:06 +0200170 printf("EL Level:\tEL%d\n", current_el());
171
Michal Simek1aab1142020-09-09 14:41:56 +0200172#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200173 ret = soc_get(&soc);
174 if (!ret) {
175 ret = soc_get_machine(soc, name, sizeof(name));
176 if (ret >= 0) {
177 zynqmppl.name = strdup(name);
178 fpga_init();
179 fpga_add(fpga_xilinx, &zynqmppl);
180 }
181 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200182#endif
183
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200184 /* display secure boot information */
185 print_secure_boot();
Michal Simek46900462020-02-11 12:43:14 +0100186 if (current_el() == 3)
Michal Simek21e5c322021-07-27 14:05:27 +0200187 printf("Multiboot:\t%d\n", multi_boot());
Michal Simek46900462020-02-11 12:43:14 +0100188
Michal Simek04b7e622015-01-15 10:01:51 +0100189 return 0;
190}
191
192int board_early_init_r(void)
193{
194 u32 val;
195
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530196 if (current_el() != 3)
197 return 0;
198
Michal Simek245d5282017-07-12 10:32:18 +0200199 val = readl(&crlapb_base->timestamp_ref_ctrl);
200 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
201
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530202 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100203 val = readl(&crlapb_base->timestamp_ref_ctrl);
204 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
205 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100206
Michal Simekc23d3f82015-11-05 08:34:35 +0100207 /* Program freq register in System counter */
208 writel(zynqmp_get_system_timer_freq(),
209 &iou_scntr_secure->base_frequency_id_register);
210 /* And enable system counter */
211 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
212 &iou_scntr_secure->counter_control_register);
213 }
Michal Simek04b7e622015-01-15 10:01:51 +0100214 return 0;
215}
216
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530217unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600218 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530219{
220 int ret = 0;
221
222 if (current_el() > 1) {
223 smp_kick_all_cpus();
224 dcache_disable();
225 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
226 ES_TO_AARCH64);
227 } else {
228 printf("FAIL: current EL is not above EL1\n");
229 ret = EINVAL;
230 }
231 return ret;
232}
233
Michal Simek8faa66a2016-02-08 09:34:53 +0100234#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600235int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100236{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530237 int ret;
238
239 ret = fdtdec_setup_memory_banksize();
240 if (ret)
241 return ret;
242
243 mem_map_fill();
244
245 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500246}
Michal Simek8faa66a2016-02-08 09:34:53 +0100247
Tom Riniedcfdbd2016-12-09 07:56:54 -0500248int dram_init(void)
249{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530250 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000251 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500252
253 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100254}
Michal Simek97ab9612021-05-31 11:03:19 +0200255
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +0200256#if defined(CONFIG_LMB)
Michal Simek97ab9612021-05-31 11:03:19 +0200257ulong board_get_usable_ram_top(ulong total_size)
258{
259 phys_size_t size;
260 phys_addr_t reg;
261 struct lmb lmb;
262
Michal Simek1b8da4a2022-04-29 11:52:27 +0200263 if (!total_size)
264 return gd->ram_top;
265
Michal Simekf14a4f22021-08-19 11:07:59 +0200266 if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8))
267 panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob);
268
Michal Simek97ab9612021-05-31 11:03:19 +0200269 /* found enough not-reserved memory to relocated U-Boot */
270 lmb_init(&lmb);
271 lmb_add(&lmb, gd->ram_base, gd->ram_size);
272 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
Michal Simek770264e2021-10-21 08:58:50 +0200273 size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
Michal Simek97ab9612021-05-31 11:03:19 +0200274 reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
275
276 if (!reg)
277 reg = gd->ram_top - size;
278
279 return reg + size;
280}
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +0200281#endif
282
Michal Simek8faa66a2016-02-08 09:34:53 +0100283#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530284int dram_init_banksize(void)
285{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530286 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
287 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530288
289 mem_map_fill();
290
291 return 0;
292}
293
Michal Simek04b7e622015-01-15 10:01:51 +0100294int dram_init(void)
295{
Michal Simek1b846212018-04-11 16:12:28 +0200296 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
297 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100298
299 return 0;
300}
Michal Simek8faa66a2016-02-08 09:34:53 +0100301#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100302
Michal Simek2a220332021-07-13 16:39:26 +0200303#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100304void reset_cpu(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100305{
306}
Michal Simek2a220332021-07-13 16:39:26 +0200307#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100308
Michal Simek8ec30042020-08-20 10:54:45 +0200309static u8 __maybe_unused zynqmp_get_bootmode(void)
310{
311 u8 bootmode;
312 u32 reg = 0;
313 int ret;
314
315 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
316 if (ret)
317 return -EINVAL;
318
Michal Simek58cc08c2021-07-28 12:25:49 +0200319 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
320 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
321
Michal Simek8ec30042020-08-20 10:54:45 +0200322 if (reg >> BOOT_MODE_ALT_SHIFT)
323 reg >>= BOOT_MODE_ALT_SHIFT;
324
325 bootmode = reg & BOOT_MODES_MASK;
326
327 return bootmode;
328}
329
Michal Simek342edfe2018-12-20 09:33:38 +0100330#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200331static const struct {
332 u32 bit;
333 const char *name;
334} reset_reasons[] = {
335 { RESET_REASON_DEBUG_SYS, "DEBUG" },
336 { RESET_REASON_SOFT, "SOFT" },
337 { RESET_REASON_SRST, "SRST" },
338 { RESET_REASON_PSONLY, "PS-ONLY" },
339 { RESET_REASON_PMU, "PMU" },
340 { RESET_REASON_INTERNAL, "INTERNAL" },
341 { RESET_REASON_EXTERNAL, "EXTERNAL" },
342 {}
343};
344
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530345static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200346{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530347 u32 reg;
348 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200349 const char *reason = NULL;
350
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530351 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
352 if (ret)
353 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200354
355 puts("Reset reason:\t");
356
357 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530358 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200359 reason = reset_reasons[i].name;
360 printf("%s ", reset_reasons[i].name);
361 break;
362 }
363 }
364
365 puts("\n");
366
367 env_set("reset_reason", reason);
368
Michal Simek0954c8c2021-02-09 08:50:22 +0100369 return 0;
Michal Simek29b9b712018-05-17 14:06:06 +0200370}
371
Michal Simek1ca66d72019-02-14 13:14:30 +0100372static int set_fdtfile(void)
373{
374 char *compatible, *fdtfile;
375 const char *suffix = ".dtb";
376 const char *vendor = "xilinx/";
Igor Lantsmane167bac2020-06-24 14:33:46 +0200377 int fdt_compat_len;
Michal Simek1ca66d72019-02-14 13:14:30 +0100378
379 if (env_get("fdtfile"))
380 return 0;
381
Igor Lantsmane167bac2020-06-24 14:33:46 +0200382 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
383 &fdt_compat_len);
384 if (compatible && fdt_compat_len) {
385 char *name;
386
Michal Simek1ca66d72019-02-14 13:14:30 +0100387 debug("Compatible: %s\n", compatible);
388
Igor Lantsmane167bac2020-06-24 14:33:46 +0200389 name = strchr(compatible, ',');
390 if (!name)
391 return -EINVAL;
Michal Simek1ca66d72019-02-14 13:14:30 +0100392
Igor Lantsmane167bac2020-06-24 14:33:46 +0200393 name++;
394
395 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek1ca66d72019-02-14 13:14:30 +0100396 strlen(suffix) + 1);
397 if (!fdtfile)
398 return -ENOMEM;
399
Igor Lantsmane167bac2020-06-24 14:33:46 +0200400 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek1ca66d72019-02-14 13:14:30 +0100401
402 env_set("fdtfile", fdtfile);
403 free(fdtfile);
404 }
405
406 return 0;
407}
408
Michal Simek9c91e612020-04-08 11:04:41 +0200409int board_late_init(void)
410{
Michal Simek04b7e622015-01-15 10:01:51 +0100411 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200412 struct udevice *dev;
413 int bootseq = -1;
414 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200415 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200416 const char *mode;
417 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530418 char *env_targets;
Michal Simek7cb4cca2021-10-25 10:10:52 +0200419 int ret, multiboot;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200420
Michal Simek482f5492018-10-05 08:55:16 +0200421#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
422 usb_ether_init();
423#endif
424
Michal Simekecfb6dc2016-04-22 14:28:54 +0200425 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
426 debug("Saved variables - Skipping\n");
427 return 0;
428 }
Michal Simek04b7e622015-01-15 10:01:51 +0100429
Michal Simekbab07b62020-07-28 12:45:47 +0200430 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
431 return 0;
432
Michal Simek1ca66d72019-02-14 13:14:30 +0100433 ret = set_fdtfile();
434 if (ret)
435 return ret;
436
Michal Simek7cb4cca2021-10-25 10:10:52 +0200437 multiboot = multi_boot();
438 if (multiboot >= 0)
439 env_set_hex("multiboot", multiboot);
440
Michal Simek9c91e612020-04-08 11:04:41 +0200441 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100442
Michal Simekc5d95232015-09-20 17:20:42 +0200443 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100444 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200445 case USB_MODE:
446 puts("USB_MODE\n");
T Karthik Reddy9eee8e32021-03-24 23:37:57 -0600447 mode = "usb_dfu0 usb_dfu1";
Michal Simek43380352017-12-01 15:18:24 +0100448 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200449 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530450 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200451 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530452 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100453 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530454 break;
455 case QSPI_MODE_24BIT:
456 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200457 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200458 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100459 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530460 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200461 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200462 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700463 if (uclass_get_device_by_name(UCLASS_MMC,
464 "mmc@ff160000", &dev) &&
465 uclass_get_device_by_name(UCLASS_MMC,
466 "sdhci@ff160000", &dev)) {
467 puts("Boot from EMMC but without SD0 enabled!\n");
468 return -1;
469 }
Simon Glass75e534b2020-12-16 21:20:07 -0700470 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy19735c32019-12-17 06:41:42 -0700471
472 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700473 bootseq = dev_seq(dev);
Ashok Reddy Somaa10be052021-09-15 08:52:17 +0200474 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200475 break;
476 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200477 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200478 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530479 "mmc@ff160000", &dev) &&
480 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200481 "sdhci@ff160000", &dev)) {
482 puts("Boot from SD0 but without SD0 enabled!\n");
483 return -1;
484 }
Simon Glass75e534b2020-12-16 21:20:07 -0700485 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200486
487 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700488 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100489 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100490 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530491 case SD1_LSHFT_MODE:
492 puts("LVL_SHFT_");
Michal Simek293f47b2021-10-18 13:30:04 +0200493 fallthrough;
Michal Simek108e1842015-10-05 10:51:12 +0200494 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200495 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200496 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530497 "mmc@ff170000", &dev) &&
498 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200499 "sdhci@ff170000", &dev)) {
500 puts("Boot from SD1 but without SD1 enabled!\n");
501 return -1;
502 }
Simon Glass75e534b2020-12-16 21:20:07 -0700503 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200504
505 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700506 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100507 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200508 break;
509 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200510 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200511 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100512 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200513 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100514 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200515 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100516 printf("Invalid Boot Mode:0x%x\n", bootmode);
517 break;
518 }
519
Michal Simekf183a982018-04-25 11:20:43 +0200520 if (bootseq >= 0) {
521 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
522 debug("Bootseq len: %x\n", bootseq_len);
Michal Simek7a117c72021-01-11 13:46:58 +0100523 env_set_hex("bootseq", bootseq);
Michal Simekf183a982018-04-25 11:20:43 +0200524 }
525
Michal Simekecfb6dc2016-04-22 14:28:54 +0200526 /*
527 * One terminating char + one byte for space between mode
528 * and default boot_targets
529 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530530 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200531 if (env_targets)
532 env_targets_len = strlen(env_targets);
533
Michal Simekf183a982018-04-25 11:20:43 +0200534 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
535 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200536 if (!new_targets)
537 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200538
Michal Simekf183a982018-04-25 11:20:43 +0200539 if (bootseq >= 0)
540 sprintf(new_targets, "%s%x %s", mode, bootseq,
541 env_targets ? env_targets : "");
542 else
543 sprintf(new_targets, "%s %s", mode,
544 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200545
Simon Glass6a38e412017-08-03 12:22:09 -0600546 env_set("boot_targets", new_targets);
Michal Simek77488232021-07-28 12:46:39 +0200547 free(new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200548
Michal Simek29b9b712018-05-17 14:06:06 +0200549 reset_reason();
550
Michal Simek705d44a2020-03-31 12:39:37 +0200551 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100552}
Michal Simek342edfe2018-12-20 09:33:38 +0100553#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530554
555int checkboard(void)
556{
Michal Simek47ce9362016-01-25 11:04:21 +0100557 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530558 return 0;
559}
Michal Simek8d4a8d42020-07-30 13:37:49 +0200560
Michal Simeke0026bf2021-05-19 15:16:19 +0200561int mmc_get_env_dev(void)
562{
563 struct udevice *dev;
564 int bootseq = 0;
565
566 switch (zynqmp_get_bootmode()) {
567 case EMMC_MODE:
568 case SD_MODE:
569 if (uclass_get_device_by_name(UCLASS_MMC,
570 "mmc@ff160000", &dev) &&
571 uclass_get_device_by_name(UCLASS_MMC,
572 "sdhci@ff160000", &dev)) {
573 return -1;
574 }
575 bootseq = dev_seq(dev);
576 break;
577 case SD1_LSHFT_MODE:
578 case SD_MODE1:
579 if (uclass_get_device_by_name(UCLASS_MMC,
580 "mmc@ff170000", &dev) &&
581 uclass_get_device_by_name(UCLASS_MMC,
582 "sdhci@ff170000", &dev)) {
583 return -1;
584 }
585 bootseq = dev_seq(dev);
586 break;
587 default:
588 break;
589 }
590
591 debug("bootseq %d\n", bootseq);
592
593 return bootseq;
594}
595
Michal Simek8d4a8d42020-07-30 13:37:49 +0200596enum env_location env_get_location(enum env_operation op, int prio)
597{
598 u32 bootmode = zynqmp_get_bootmode();
599
600 if (prio)
601 return ENVL_UNKNOWN;
602
603 switch (bootmode) {
604 case EMMC_MODE:
605 case SD_MODE:
606 case SD1_LSHFT_MODE:
607 case SD_MODE1:
608 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
609 return ENVL_FAT;
610 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
611 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200612 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200613 case NAND_MODE:
614 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
615 return ENVL_NAND;
616 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
617 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200618 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200619 case QSPI_MODE_24BIT:
620 case QSPI_MODE_32BIT:
621 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
622 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200623 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200624 case JTAG_MODE:
625 default:
626 return ENVL_NOWHERE;
627 }
628}
Michal Simekcfb37602021-07-27 16:19:18 +0200629
630#if defined(CONFIG_SET_DFU_ALT_INFO)
631
632#define DFU_ALT_BUF_LEN SZ_1K
633
634void set_dfu_alt_info(char *interface, char *devstr)
635{
636 u8 multiboot;
637 int bootseq = 0;
638
639 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
640
Sughosh Ganuccb36462022-04-15 11:29:34 +0530641 if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
642 env_get("dfu_alt_info"))
Michal Simekcfb37602021-07-27 16:19:18 +0200643 return;
644
645 memset(buf, 0, sizeof(buf));
646
647 multiboot = multi_boot();
Michal Simek7cb4cca2021-10-25 10:10:52 +0200648 if (multiboot < 0)
649 multiboot = 0;
650
651 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekcfb37602021-07-27 16:19:18 +0200652 debug("Multiboot: %d\n", multiboot);
653
654 switch (zynqmp_get_bootmode()) {
655 case EMMC_MODE:
656 case SD_MODE:
657 case SD1_LSHFT_MODE:
658 case SD_MODE1:
659 bootseq = mmc_get_env_dev();
660 if (!multiboot)
661 snprintf(buf, DFU_ALT_BUF_LEN,
662 "mmc %d:1=boot.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200663 "%s fat %d 1",
664 bootseq, bootseq,
665 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200666 else
667 snprintf(buf, DFU_ALT_BUF_LEN,
668 "mmc %d:1=boot%04d.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200669 "%s fat %d 1",
670 bootseq, multiboot, bootseq,
671 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200672 break;
Stefan Herbrechtsmeierfb027cd2022-06-20 18:36:46 +0200673#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
Michal Simekcfb37602021-07-27 16:19:18 +0200674 case QSPI_MODE_24BIT:
675 case QSPI_MODE_32BIT:
676 snprintf(buf, DFU_ALT_BUF_LEN,
677 "sf 0:0=boot.bin raw %x 0x1500000;"
Michal Simek69103192021-10-18 14:02:15 +0200678 "%s raw 0x%x 0x500000",
679 multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
680 CONFIG_SYS_SPI_U_BOOT_OFFS);
Michal Simekcfb37602021-07-27 16:19:18 +0200681 break;
Stefan Herbrechtsmeierfb027cd2022-06-20 18:36:46 +0200682#endif
Michal Simekcfb37602021-07-27 16:19:18 +0200683 default:
684 return;
685 }
686
687 env_set("dfu_alt_info", buf);
688 puts("DFU alt info setting: done\n");
689}
690#endif