blob: 29a6e3675f3c745dcc1658a5aaaa7a1b0d3c676b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek84c72042015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek84c72042015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Simon Glass62270f42019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simekc0adba52020-01-07 09:02:52 +010010#include <debug_uart.h>
Michal Simekb86f43d2021-07-27 16:19:18 +020011#include <dfu.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060012#include <env.h>
Michal Simek1025bd02020-07-30 13:37:49 +020013#include <env_internal.h>
Simon Glass52559322019-11-14 12:57:46 -070014#include <init.h>
Michal Simekce39ee22021-05-31 11:03:19 +020015#include <image.h>
16#include <lmb.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060017#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060018#include <net.h>
Michal Simek679b9942015-09-30 17:26:55 +020019#include <sata.h>
Michal Simek6fe6f132015-07-23 13:27:40 +020020#include <ahci.h>
21#include <scsi.h>
Stefan Herbrechtsmeiera1e618a2022-06-20 18:36:43 +020022#include <soc.h>
Michal Simekb72894f2016-04-22 14:28:54 +020023#include <malloc.h>
Michal Simekb86f43d2021-07-27 16:19:18 +020024#include <memalign.h>
Michal Simek4490e012018-04-19 15:43:38 +020025#include <wdt.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010026#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010027#include <asm/arch/hardware.h>
28#include <asm/arch/sys_proto.h>
Michal Simek2ad341e2018-01-10 09:36:09 +010029#include <asm/arch/psu_init_gpl.h>
Simon Glass90526e92020-05-10 11:39:56 -060030#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060031#include <asm/global_data.h>
Michal Simek84c72042015-01-15 10:01:51 +010032#include <asm/io.h>
Simon Glass25a58182020-05-10 11:40:06 -060033#include <asm/ptrace.h>
Michal Simek2882b392018-04-25 11:20:43 +020034#include <dm/device.h>
Michal Simek4490e012018-04-19 15:43:38 +020035#include <dm/uclass.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053036#include <usb.h>
37#include <dwc3-uboot.h>
Michal Simek47e60cb2016-02-01 15:05:58 +010038#include <zynqmppl.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010039#include <zynqmp_firmware.h>
Michal Simek9feff382016-09-01 11:16:40 +020040#include <g_dnl.h>
Simon Glasscd93d622020-05-10 11:40:13 -060041#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060042#include <linux/delay.h>
43#include <linux/sizes.h>
Michal Simek80fdef12020-03-31 12:39:37 +020044#include "../common/board.h"
Michal Simek84c72042015-01-15 10:01:51 +010045
Luca Ceresolic28a9cf2019-05-21 18:06:43 +020046#include "pm_cfg_obj.h"
47
Michal Simek84c72042015-01-15 10:01:51 +010048DECLARE_GLOBAL_DATA_PTR;
49
Michal Simek29bd8ad2020-09-09 14:41:56 +020050#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Oleksandr Suvorovd7fcbfc2022-07-22 17:16:04 +030051static xilinx_desc zynqmppl = {
52 xilinx_zynqmp, csu_dma, 1, &zynqmp_op, 0, &zynqmp_op, NULL,
53 ZYNQMP_FPGA_FLAGS
54};
Michal Simek47e60cb2016-02-01 15:05:58 +010055#endif
56
Michal Simek11381fb2022-02-17 14:28:42 +010057int __maybe_unused psu_uboot_init(void)
Michal Simekfb4000e2017-02-07 14:32:26 +010058{
Michal Simekc0adba52020-01-07 09:02:52 +010059 int ret;
60
Michal Simekf32e79f2018-01-10 11:48:48 +010061 ret = psu_init();
Michal Simekc0adba52020-01-07 09:02:52 +010062 if (ret)
63 return ret;
Michal Simekf8451f12020-03-20 08:59:02 +010064
Adrian Fiergolski3414712b2021-06-08 12:37:23 +020065 /*
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 Simekf8451f12020-03-20 08:59:02 +010076 /* Delay is required for clocks to be propagated */
77 udelay(1000000);
Michal Simek11381fb2022-02-17 14:28:42 +010078
Michal Simekc0adba52020-01-07 09:02:52 +010079 return 0;
Michal Simekfb4000e2017-02-07 14:32:26 +010080}
Michal Simek11381fb2022-02-17 14:28:42 +010081
82#if !defined(CONFIG_SPL_BUILD)
83# if defined(CONFIG_DEBUG_UART_BOARD_INIT)
84void board_debug_uart_init(void)
85{
86# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
87 psu_uboot_init();
88# endif
89}
90# endif
91
92# if defined(CONFIG_BOARD_EARLY_INIT_F)
93int 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;
100}
101# endif
Michal Simek83d29412022-02-17 14:28:40 +0100102#endif
Michal Simekfb4000e2017-02-07 14:32:26 +0100103
Michal Simekc5143012020-02-11 12:43:14 +0100104static int multi_boot(void)
105{
Michal Simek3d238432021-07-27 16:17:31 +0200106 u32 multiboot = 0;
107 int ret;
Michal Simekc5143012020-02-11 12:43:14 +0100108
Michal Simek3d238432021-07-27 16:17:31 +0200109 ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot);
110 if (ret)
111 return -EINVAL;
Michal Simekc5143012020-02-11 12:43:14 +0100112
Michal Simeke49f2a72021-07-27 14:05:27 +0200113 return multiboot;
Michal Simekc5143012020-02-11 12:43:14 +0100114}
115
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200116#if defined(CONFIG_SPL_BUILD)
117static 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-Ortiz25a91f32021-10-13 19:04:47 +0200131static 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 Simek84c72042015-01-15 10:01:51 +0100143int board_init(void)
144{
Stefan Herbrechtsmeiera1e618a2022-06-20 18:36:43 +0200145#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 Simek66ef85d2020-03-04 08:48:16 +0100150#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100151 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 Simek66ef85d2020-03-04 08:48:16 +0100156#endif
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100157
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200158#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 Simek98757d82021-02-02 16:34:48 +0100163 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200164
165 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti11c02552021-11-04 16:28:02 -0300166 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200167 restore_jtag();
Michal Simekd61728c2020-08-03 13:01:45 +0200168#else
169 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
170 xilinx_read_eeprom();
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200171#endif
172
Michal Simeka0736ef2015-06-22 14:31:06 +0200173 printf("EL Level:\tEL%d\n", current_el());
174
Michal Simek29bd8ad2020-09-09 14:41:56 +0200175#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Stefan Herbrechtsmeiera1e618a2022-06-20 18:36:43 +0200176 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 Simek47e60cb2016-02-01 15:05:58 +0100185#endif
186
Jorge Ramirez-Ortiz25a91f32021-10-13 19:04:47 +0200187 /* display secure boot information */
188 print_secure_boot();
Michal Simekc5143012020-02-11 12:43:14 +0100189 if (current_el() == 3)
Michal Simeke49f2a72021-07-27 14:05:27 +0200190 printf("Multiboot:\t%d\n", multi_boot());
Michal Simekc5143012020-02-11 12:43:14 +0100191
Michal Simek84c72042015-01-15 10:01:51 +0100192 return 0;
193}
194
195int board_early_init_r(void)
196{
197 u32 val;
198
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530199 if (current_el() != 3)
200 return 0;
201
Michal Simek90a35db2017-07-12 10:32:18 +0200202 val = readl(&crlapb_base->timestamp_ref_ctrl);
203 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
204
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530205 if (!val) {
Michal Simek0785dfd2015-11-05 08:34:35 +0100206 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 Simek84c72042015-01-15 10:01:51 +0100209
Michal Simek0785dfd2015-11-05 08:34:35 +0100210 /* 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 Simek84c72042015-01-15 10:01:51 +0100217 return 0;
218}
219
Nitin Jain51916862018-02-16 12:56:17 +0530220unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glass09140112020-05-10 11:40:03 -0600221 char *const argv[])
Nitin Jain51916862018-02-16 12:56:17 +0530222{
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 Simek8d59d7f2016-02-08 09:34:53 +0100237#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -0600238int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -0500239{
Nitin Jain06789412018-04-20 12:30:40 +0530240 int ret;
241
242 ret = fdtdec_setup_memory_banksize();
243 if (ret)
244 return ret;
245
246 mem_map_fill();
247
248 return 0;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100249}
250
251int dram_init(void)
252{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530253 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi950f86c2016-12-19 00:03:34 +1000254 return -EINVAL;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100255
256 return 0;
257}
Michal Simekce39ee22021-05-31 11:03:19 +0200258
Ashok Reddy Soma65168912022-07-07 10:45:37 +0200259#if defined(CONFIG_LMB)
Michal Simekce39ee22021-05-31 11:03:19 +0200260ulong 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 Simek9c563e92022-04-29 11:52:27 +0200266 if (!total_size)
267 return gd->ram_top;
268
Michal Simek5bd5ee02021-08-19 11:07:59 +0200269 if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8))
270 panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob);
271
Michal Simekce39ee22021-05-31 11:03:19 +0200272 /* 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 Simek412ab132021-10-21 08:58:50 +0200276 size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
Michal Simekce39ee22021-05-31 11:03:19 +0200277 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 Soma65168912022-07-07 10:45:37 +0200284#endif
285
Michal Simek8d59d7f2016-02-08 09:34:53 +0100286#else
Nitin Jain06789412018-04-20 12:30:40 +0530287int dram_init_banksize(void)
288{
Nitin Jain06789412018-04-20 12:30:40 +0530289 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
290 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain06789412018-04-20 12:30:40 +0530291
292 mem_map_fill();
293
294 return 0;
295}
296
Michal Simek84c72042015-01-15 10:01:51 +0100297int dram_init(void)
298{
Michal Simek61dc92a2018-04-11 16:12:28 +0200299 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
300 CONFIG_SYS_SDRAM_SIZE);
Michal Simek84c72042015-01-15 10:01:51 +0100301
302 return 0;
303}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100304#endif
Michal Simek84c72042015-01-15 10:01:51 +0100305
Michal Simekf1bc2142021-07-13 16:39:26 +0200306#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler35b65dd2020-12-15 16:47:52 +0100307void reset_cpu(void)
Michal Simek84c72042015-01-15 10:01:51 +0100308{
309}
Michal Simekf1bc2142021-07-13 16:39:26 +0200310#endif
Michal Simek84c72042015-01-15 10:01:51 +0100311
Michal Simek4d9bc792020-08-20 10:54:45 +0200312static 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, &reg);
319 if (ret)
320 return -EINVAL;
321
Michal Simekafb08a82021-07-28 12:25:49 +0200322 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
323 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
324
Michal Simek4d9bc792020-08-20 10:54:45 +0200325 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 Simek0bf3f9c2018-12-20 09:33:38 +0100333#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simekd348bea2018-05-17 14:06:06 +0200334static 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 Reddybe523722019-03-13 20:24:18 +0530348static int reset_reason(void)
Michal Simekd348bea2018-05-17 14:06:06 +0200349{
T Karthik Reddybe523722019-03-13 20:24:18 +0530350 u32 reg;
351 int i, ret;
Michal Simekd348bea2018-05-17 14:06:06 +0200352 const char *reason = NULL;
353
T Karthik Reddybe523722019-03-13 20:24:18 +0530354 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
355 if (ret)
356 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200357
358 puts("Reset reason:\t");
359
360 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddybe523722019-03-13 20:24:18 +0530361 if (reg & reset_reasons[i].bit) {
Michal Simekd348bea2018-05-17 14:06:06 +0200362 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 Simek3aba25b2021-02-09 08:50:22 +0100372 return 0;
Michal Simekd348bea2018-05-17 14:06:06 +0200373}
374
Michal Simek91d7e0c2019-02-14 13:14:30 +0100375static int set_fdtfile(void)
376{
377 char *compatible, *fdtfile;
378 const char *suffix = ".dtb";
379 const char *vendor = "xilinx/";
Igor Lantsman1b208d52020-06-24 14:33:46 +0200380 int fdt_compat_len;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100381
382 if (env_get("fdtfile"))
383 return 0;
384
Igor Lantsman1b208d52020-06-24 14:33:46 +0200385 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
386 &fdt_compat_len);
387 if (compatible && fdt_compat_len) {
388 char *name;
389
Michal Simek91d7e0c2019-02-14 13:14:30 +0100390 debug("Compatible: %s\n", compatible);
391
Igor Lantsman1b208d52020-06-24 14:33:46 +0200392 name = strchr(compatible, ',');
393 if (!name)
394 return -EINVAL;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100395
Igor Lantsman1b208d52020-06-24 14:33:46 +0200396 name++;
397
398 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek91d7e0c2019-02-14 13:14:30 +0100399 strlen(suffix) + 1);
400 if (!fdtfile)
401 return -ENOMEM;
402
Igor Lantsman1b208d52020-06-24 14:33:46 +0200403 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek91d7e0c2019-02-14 13:14:30 +0100404
405 env_set("fdtfile", fdtfile);
406 free(fdtfile);
407 }
408
409 return 0;
410}
411
Michal Simek84c72042015-01-15 10:01:51 +0100412int board_late_init(void)
413{
Michal Simek84c72042015-01-15 10:01:51 +0100414 u8 bootmode;
Michal Simek2882b392018-04-25 11:20:43 +0200415 struct udevice *dev;
416 int bootseq = -1;
417 int bootseq_len = 0;
Michal Simek0478b0b2018-04-25 11:10:34 +0200418 int env_targets_len = 0;
Michal Simekb72894f2016-04-22 14:28:54 +0200419 const char *mode;
420 char *new_targets;
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530421 char *env_targets;
Michal Simeke8b43c62021-10-25 10:10:52 +0200422 int ret, multiboot;
Michal Simekb72894f2016-04-22 14:28:54 +0200423
Michal Simeke615f392018-10-05 08:55:16 +0200424#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
425 usb_ether_init();
426#endif
427
Michal Simekb72894f2016-04-22 14:28:54 +0200428 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
429 debug("Saved variables - Skipping\n");
430 return 0;
431 }
Michal Simek84c72042015-01-15 10:01:51 +0100432
Michal Simek62b96262020-07-28 12:45:47 +0200433 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
434 return 0;
435
Michal Simek91d7e0c2019-02-14 13:14:30 +0100436 ret = set_fdtfile();
437 if (ret)
438 return ret;
439
Michal Simeke8b43c62021-10-25 10:10:52 +0200440 multiboot = multi_boot();
441 if (multiboot >= 0)
442 env_set_hex("multiboot", multiboot);
443
Michal Simek51f6c522020-04-08 11:04:41 +0200444 bootmode = zynqmp_get_bootmode();
Michal Simek84c72042015-01-15 10:01:51 +0100445
Michal Simekfb909172015-09-20 17:20:42 +0200446 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100447 switch (bootmode) {
Michal Simekd58fc122016-08-19 14:14:52 +0200448 case USB_MODE:
449 puts("USB_MODE\n");
T Karthik Reddyef1be3e2021-03-24 23:37:57 -0600450 mode = "usb_dfu0 usb_dfu1";
Michal Simek07656ba2017-12-01 15:18:24 +0100451 env_set("modeboot", "usb_dfu_spl");
Michal Simekd58fc122016-08-19 14:14:52 +0200452 break;
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530453 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200454 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu5d2274c2019-06-25 17:41:09 +0530455 mode = "jtag pxe dhcp";
Michal Simek07656ba2017-12-01 15:18:24 +0100456 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530457 break;
458 case QSPI_MODE_24BIT:
459 case QSPI_MODE_32BIT:
Michal Simekb72894f2016-04-22 14:28:54 +0200460 mode = "qspi0";
Michal Simekfb909172015-09-20 17:20:42 +0200461 puts("QSPI_MODE\n");
Michal Simek07656ba2017-12-01 15:18:24 +0100462 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530463 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200464 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200465 puts("EMMC_MODE\n");
T Karthik Reddy18be60b2019-12-17 06:41:42 -0700466 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 Glass8b85dfc2020-12-16 21:20:07 -0700473 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy18be60b2019-12-17 06:41:42 -0700474
475 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700476 bootseq = dev_seq(dev);
Ashok Reddy Soma5d498a12021-09-15 08:52:17 +0200477 env_set("modeboot", "emmcboot");
Michal Simek78678fe2015-10-05 15:59:38 +0200478 break;
479 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200480 puts("SD_MODE\n");
Michal Simek2882b392018-04-25 11:20:43 +0200481 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530482 "mmc@ff160000", &dev) &&
483 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200484 "sdhci@ff160000", &dev)) {
485 puts("Boot from SD0 but without SD0 enabled!\n");
486 return -1;
487 }
Simon Glass8b85dfc2020-12-16 21:20:07 -0700488 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simek2882b392018-04-25 11:20:43 +0200489
490 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700491 bootseq = dev_seq(dev);
Michal Simek07656ba2017-12-01 15:18:24 +0100492 env_set("modeboot", "sdboot");
Michal Simek84c72042015-01-15 10:01:51 +0100493 break;
Siva Durga Prasad Paladugue1992272016-09-21 11:45:05 +0530494 case SD1_LSHFT_MODE:
495 puts("LVL_SHFT_");
Michal Simekf5109272021-10-18 13:30:04 +0200496 fallthrough;
Michal Simekaf813ac2015-10-05 10:51:12 +0200497 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200498 puts("SD_MODE1\n");
Michal Simek2882b392018-04-25 11:20:43 +0200499 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530500 "mmc@ff170000", &dev) &&
501 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200502 "sdhci@ff170000", &dev)) {
503 puts("Boot from SD1 but without SD1 enabled!\n");
504 return -1;
505 }
Simon Glass8b85dfc2020-12-16 21:20:07 -0700506 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simek2882b392018-04-25 11:20:43 +0200507
508 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700509 bootseq = dev_seq(dev);
Michal Simek07656ba2017-12-01 15:18:24 +0100510 env_set("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200511 break;
512 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200513 puts("NAND_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200514 mode = "nand0";
Michal Simek07656ba2017-12-01 15:18:24 +0100515 env_set("modeboot", "nandboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200516 break;
Michal Simek84c72042015-01-15 10:01:51 +0100517 default:
Michal Simekb72894f2016-04-22 14:28:54 +0200518 mode = "";
Michal Simek84c72042015-01-15 10:01:51 +0100519 printf("Invalid Boot Mode:0x%x\n", bootmode);
520 break;
521 }
522
Michal Simek2882b392018-04-25 11:20:43 +0200523 if (bootseq >= 0) {
524 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
525 debug("Bootseq len: %x\n", bootseq_len);
Michal Simek2784bef2021-01-11 13:46:58 +0100526 env_set_hex("bootseq", bootseq);
Michal Simek2882b392018-04-25 11:20:43 +0200527 }
528
Michal Simekb72894f2016-04-22 14:28:54 +0200529 /*
530 * One terminating char + one byte for space between mode
531 * and default boot_targets
532 */
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530533 env_targets = env_get("boot_targets");
Michal Simek0478b0b2018-04-25 11:10:34 +0200534 if (env_targets)
535 env_targets_len = strlen(env_targets);
536
Michal Simek2882b392018-04-25 11:20:43 +0200537 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
538 bootseq_len);
Michal Simek1e3e68f2018-06-13 09:42:41 +0200539 if (!new_targets)
540 return -ENOMEM;
Michal Simek0478b0b2018-04-25 11:10:34 +0200541
Michal Simek2882b392018-04-25 11:20:43 +0200542 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 Simekb72894f2016-04-22 14:28:54 +0200548
Simon Glass382bee52017-08-03 12:22:09 -0600549 env_set("boot_targets", new_targets);
Michal Simekf83cfaa2021-07-28 12:46:39 +0200550 free(new_targets);
Michal Simekb72894f2016-04-22 14:28:54 +0200551
Michal Simekd348bea2018-05-17 14:06:06 +0200552 reset_reason();
553
Michal Simek80fdef12020-03-31 12:39:37 +0200554 return board_late_init_xilinx();
Michal Simek84c72042015-01-15 10:01:51 +0100555}
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100556#endif
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530557
558int checkboard(void)
559{
Michal Simek5af08552016-01-25 11:04:21 +0100560 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530561 return 0;
562}
Michal Simek1025bd02020-07-30 13:37:49 +0200563
Michal Simek476588c2021-05-19 15:16:19 +0200564int 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 Simek1025bd02020-07-30 13:37:49 +0200599enum 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 Looijmans50918d02021-07-02 10:28:36 +0200615 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200616 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 Looijmans50918d02021-07-02 10:28:36 +0200621 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200622 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 Looijmans50918d02021-07-02 10:28:36 +0200626 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200627 case JTAG_MODE:
628 default:
629 return ENVL_NOWHERE;
630 }
631}
Michal Simekb86f43d2021-07-27 16:19:18 +0200632
633#if defined(CONFIG_SET_DFU_ALT_INFO)
634
635#define DFU_ALT_BUF_LEN SZ_1K
636
637void 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
Michal Simekce183fd2022-08-09 16:32:52 +0200644 if (env_get("dfu_alt_info"))
Michal Simekb86f43d2021-07-27 16:19:18 +0200645 return;
646
647 memset(buf, 0, sizeof(buf));
648
649 multiboot = multi_boot();
Michal Simeke8b43c62021-10-25 10:10:52 +0200650 if (multiboot < 0)
651 multiboot = 0;
652
653 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekb86f43d2021-07-27 16:19:18 +0200654 debug("Multiboot: %d\n", multiboot);
655
656 switch (zynqmp_get_bootmode()) {
657 case EMMC_MODE:
658 case SD_MODE:
659 case SD1_LSHFT_MODE:
660 case SD_MODE1:
661 bootseq = mmc_get_env_dev();
662 if (!multiboot)
663 snprintf(buf, DFU_ALT_BUF_LEN,
664 "mmc %d:1=boot.bin fat %d 1;"
Michal Simek60705882021-10-18 14:02:15 +0200665 "%s fat %d 1",
666 bootseq, bootseq,
667 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekb86f43d2021-07-27 16:19:18 +0200668 else
669 snprintf(buf, DFU_ALT_BUF_LEN,
670 "mmc %d:1=boot%04d.bin fat %d 1;"
Michal Simek60705882021-10-18 14:02:15 +0200671 "%s fat %d 1",
672 bootseq, multiboot, bootseq,
673 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekb86f43d2021-07-27 16:19:18 +0200674 break;
Stefan Herbrechtsmeierf93c1c82022-06-20 18:36:46 +0200675#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
Michal Simekb86f43d2021-07-27 16:19:18 +0200676 case QSPI_MODE_24BIT:
677 case QSPI_MODE_32BIT:
678 snprintf(buf, DFU_ALT_BUF_LEN,
679 "sf 0:0=boot.bin raw %x 0x1500000;"
Michal Simek60705882021-10-18 14:02:15 +0200680 "%s raw 0x%x 0x500000",
681 multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
682 CONFIG_SYS_SPI_U_BOOT_OFFS);
Michal Simekb86f43d2021-07-27 16:19:18 +0200683 break;
Stefan Herbrechtsmeierf93c1c82022-06-20 18:36:46 +0200684#endif
Michal Simekb86f43d2021-07-27 16:19:18 +0200685 default:
686 return;
687 }
688
689 env_set("dfu_alt_info", buf);
690 puts("DFU alt info setting: done\n");
691}
692#endif