blob: f16280308483153e14dba863fc177f97a3a0cc6f [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.
Michal Simeka8c94362023-07-10 14:35:49 +02004 * Michal Simek <michal.simek@amd.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>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020017#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020018#include <ahci.h>
19#include <scsi.h>
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020020#include <soc.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020021#include <malloc.h>
Michal Simekcfb37602021-07-27 16:19:18 +020022#include <memalign.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020023#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010024#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010025#include <asm/arch/hardware.h>
26#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010027#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060028#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060029#include <asm/global_data.h>
Michal Simek04b7e622015-01-15 10:01:51 +010030#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060031#include <asm/ptrace.h>
Michal Simekf183a982018-04-25 11:20:43 +020032#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020033#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053034#include <usb.h>
35#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010036#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010037#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020038#include <g_dnl.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060039#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060040#include <linux/delay.h>
41#include <linux/sizes.h>
Michal Simek705d44a2020-03-31 12:39:37 +020042#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010043
Luca Ceresoli23e65002019-05-21 18:06:43 +020044#include "pm_cfg_obj.h"
45
Michal Simek04b7e622015-01-15 10:01:51 +010046DECLARE_GLOBAL_DATA_PTR;
47
Michal Simek1aab1142020-09-09 14:41:56 +020048#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Oleksandr Suvorovdae95a42022-07-22 17:16:04 +030049static xilinx_desc zynqmppl = {
50 xilinx_zynqmp, csu_dma, 1, &zynqmp_op, 0, &zynqmp_op, NULL,
51 ZYNQMP_FPGA_FLAGS
52};
Michal Simek8111aff2016-02-01 15:05:58 +010053#endif
54
Michal Simeke5710e32022-02-17 14:28:42 +010055int __maybe_unused psu_uboot_init(void)
Michal Simek8b353302017-02-07 14:32:26 +010056{
Michal Simek09a7d7d2020-01-07 09:02:52 +010057 int ret;
58
Michal Simekc8785f22018-01-10 11:48:48 +010059 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +010060 if (ret)
61 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +010062
Adrian Fiergolski8e87ecf2021-06-08 12:37:23 +020063 /*
64 * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon
65 * supply sense channel to SysMon supply registers inside the IP.
66 * This register must be programmed to complete SysMon IP
67 * configuration. The default register configuration after
68 * power-up is incorrect. Hence, fix this by writing the
69 * correct value - 0x3210.
70 */
71 writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL,
72 ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS);
73
Michal Simek1f55e572020-03-20 08:59:02 +010074 /* Delay is required for clocks to be propagated */
75 udelay(1000000);
Michal Simeke5710e32022-02-17 14:28:42 +010076
77 return 0;
78}
Michal Simeke0f36102017-07-12 13:08:41 +020079
Michal Simeke5710e32022-02-17 14:28:42 +010080#if !defined(CONFIG_SPL_BUILD)
81# if defined(CONFIG_DEBUG_UART_BOARD_INIT)
82void board_debug_uart_init(void)
83{
84# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
85 psu_uboot_init();
86# endif
87}
88# endif
Michal Simek09a7d7d2020-01-07 09:02:52 +010089
Michal Simeke5710e32022-02-17 14:28:42 +010090# if defined(CONFIG_BOARD_EARLY_INIT_F)
91int board_early_init_f(void)
92{
93 int ret = 0;
94# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) && !defined(CONFIG_DEBUG_UART_BOARD_INIT)
95 ret = psu_uboot_init();
96# endif
97 return ret;
Michal Simek8b353302017-02-07 14:32:26 +010098}
Michal Simeke5710e32022-02-17 14:28:42 +010099# endif
Michal Simekba6fb832022-02-17 14:28:40 +0100100#endif
Michal Simek8b353302017-02-07 14:32:26 +0100101
Michal Simek46900462020-02-11 12:43:14 +0100102static int multi_boot(void)
103{
Michal Simek6aca2832021-07-27 16:17:31 +0200104 u32 multiboot = 0;
105 int ret;
Michal Simek46900462020-02-11 12:43:14 +0100106
Michal Simek6aca2832021-07-27 16:17:31 +0200107 ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot);
108 if (ret)
109 return -EINVAL;
Michal Simek46900462020-02-11 12:43:14 +0100110
Michal Simek21e5c322021-07-27 14:05:27 +0200111 return multiboot;
Michal Simek46900462020-02-11 12:43:14 +0100112}
113
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200114#if defined(CONFIG_SPL_BUILD)
115static void restore_jtag(void)
116{
117 if (current_el() != 3)
118 return;
119
120 writel(CSU_JTAG_SEC_GATE_DISABLE, &csu_base->jtag_sec);
121 writel(CSU_JTAG_DAP_ENABLE_DEBUG, &csu_base->jtag_dap_cfg);
122 writel(CSU_JTAG_CHAIN_WR_SETUP, &csu_base->jtag_chain_status_wr);
123 writel(CRLAPB_DBG_LPD_CTRL_SETUP_CLK, &crlapb_base->dbg_lpd_ctrl);
124 writel(CRLAPB_RST_LPD_DBG_RESET, &crlapb_base->rst_lpd_dbg);
125 writel(CSU_PCAP_PROG_RELEASE_PL, &csu_base->pcap_prog);
126}
127#endif
128
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200129static void print_secure_boot(void)
130{
131 u32 status = 0;
132
133 if (zynqmp_mmio_read((ulong)&csu_base->status, &status))
134 return;
135
136 printf("Secure Boot:\t%sauthenticated, %sencrypted\n",
137 status & ZYNQMP_CSU_STATUS_AUTHENTICATED ? "" : "not ",
138 status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
139}
140
Michal Simek04b7e622015-01-15 10:01:51 +0100141int board_init(void)
142{
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200143#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
144 struct udevice *soc;
145 char name[SOC_MAX_STR_SIZE];
146 int ret;
147#endif
Michal Simek3d49c952022-10-05 11:39:27 +0200148
149#if defined(CONFIG_SPL_BUILD)
150 /* Check *at build time* if the filename is an non-empty string */
151 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
152 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
153 zynqmp_pm_cfg_obj_size);
154#endif
155
Michal Simek826d7eca2020-03-04 08:48:16 +0100156#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100157 struct udevice *dev;
158
159 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
160 if (!dev)
161 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100162#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100163
Luca Ceresoli23e65002019-05-21 18:06:43 +0200164#if defined(CONFIG_SPL_BUILD)
Michal Simekae9dc112021-02-02 16:34:48 +0100165 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200166
167 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti5b774f02021-11-04 16:28:02 -0300168 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200169 restore_jtag();
Michal Simek394ee242020-08-03 13:01:45 +0200170#else
171 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
172 xilinx_read_eeprom();
Luca Ceresoli23e65002019-05-21 18:06:43 +0200173#endif
174
Michal Simekfb7242d2015-06-22 14:31:06 +0200175 printf("EL Level:\tEL%d\n", current_el());
176
Michal Simek1aab1142020-09-09 14:41:56 +0200177#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200178 ret = soc_get(&soc);
179 if (!ret) {
180 ret = soc_get_machine(soc, name, sizeof(name));
181 if (ret >= 0) {
182 zynqmppl.name = strdup(name);
183 fpga_init();
184 fpga_add(fpga_xilinx, &zynqmppl);
185 }
186 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200187#endif
188
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200189 /* display secure boot information */
190 print_secure_boot();
Michal Simek46900462020-02-11 12:43:14 +0100191 if (current_el() == 3)
Michal Simek21e5c322021-07-27 14:05:27 +0200192 printf("Multiboot:\t%d\n", multi_boot());
Michal Simek46900462020-02-11 12:43:14 +0100193
Michal Simek04b7e622015-01-15 10:01:51 +0100194 return 0;
195}
196
197int board_early_init_r(void)
198{
199 u32 val;
200
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530201 if (current_el() != 3)
202 return 0;
203
Michal Simek245d5282017-07-12 10:32:18 +0200204 val = readl(&crlapb_base->timestamp_ref_ctrl);
205 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
206
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530207 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100208 val = readl(&crlapb_base->timestamp_ref_ctrl);
209 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
210 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100211
Michal Simekc23d3f82015-11-05 08:34:35 +0100212 /* Program freq register in System counter */
213 writel(zynqmp_get_system_timer_freq(),
214 &iou_scntr_secure->base_frequency_id_register);
215 /* And enable system counter */
216 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
217 &iou_scntr_secure->counter_control_register);
218 }
Michal Simek04b7e622015-01-15 10:01:51 +0100219 return 0;
220}
221
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530222unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600223 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530224{
225 int ret = 0;
226
227 if (current_el() > 1) {
228 smp_kick_all_cpus();
229 dcache_disable();
230 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
231 ES_TO_AARCH64);
232 } else {
233 printf("FAIL: current EL is not above EL1\n");
234 ret = EINVAL;
235 }
236 return ret;
237}
238
Tom Rinibb4dd962022-11-16 13:10:37 -0500239#if !defined(CFG_SYS_SDRAM_BASE) && !defined(CFG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600240int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100241{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530242 int ret;
243
244 ret = fdtdec_setup_memory_banksize();
245 if (ret)
246 return ret;
247
248 mem_map_fill();
249
250 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500251}
Michal Simek8faa66a2016-02-08 09:34:53 +0100252
Tom Riniedcfdbd2016-12-09 07:56:54 -0500253int dram_init(void)
254{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530255 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000256 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500257
258 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100259}
Michal Simek97ab9612021-05-31 11:03:19 +0200260
Michal Simek8faa66a2016-02-08 09:34:53 +0100261#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530262int dram_init_banksize(void)
263{
Tom Rinibb4dd962022-11-16 13:10:37 -0500264 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530265 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530266
267 mem_map_fill();
268
269 return 0;
270}
271
Michal Simek04b7e622015-01-15 10:01:51 +0100272int dram_init(void)
273{
Tom Rinibb4dd962022-11-16 13:10:37 -0500274 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE,
275 CFG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100276
277 return 0;
278}
Michal Simek8faa66a2016-02-08 09:34:53 +0100279#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100280
Michal Simek2a220332021-07-13 16:39:26 +0200281#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100282void reset_cpu(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100283{
284}
Michal Simek2a220332021-07-13 16:39:26 +0200285#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100286
Michal Simek8ec30042020-08-20 10:54:45 +0200287static u8 __maybe_unused zynqmp_get_bootmode(void)
288{
289 u8 bootmode;
290 u32 reg = 0;
291 int ret;
292
293 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
294 if (ret)
295 return -EINVAL;
296
Michal Simek58cc08c2021-07-28 12:25:49 +0200297 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
298 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
299
Michal Simek8ec30042020-08-20 10:54:45 +0200300 if (reg >> BOOT_MODE_ALT_SHIFT)
301 reg >>= BOOT_MODE_ALT_SHIFT;
302
303 bootmode = reg & BOOT_MODES_MASK;
304
305 return bootmode;
306}
307
Michal Simek342edfe2018-12-20 09:33:38 +0100308#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200309static const struct {
310 u32 bit;
311 const char *name;
312} reset_reasons[] = {
313 { RESET_REASON_DEBUG_SYS, "DEBUG" },
314 { RESET_REASON_SOFT, "SOFT" },
315 { RESET_REASON_SRST, "SRST" },
316 { RESET_REASON_PSONLY, "PS-ONLY" },
317 { RESET_REASON_PMU, "PMU" },
318 { RESET_REASON_INTERNAL, "INTERNAL" },
319 { RESET_REASON_EXTERNAL, "EXTERNAL" },
320 {}
321};
322
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530323static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200324{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530325 u32 reg;
326 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200327 const char *reason = NULL;
328
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530329 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
330 if (ret)
331 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200332
333 puts("Reset reason:\t");
334
335 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530336 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200337 reason = reset_reasons[i].name;
338 printf("%s ", reset_reasons[i].name);
339 break;
340 }
341 }
342
343 puts("\n");
344
345 env_set("reset_reason", reason);
346
Michal Simek0954c8c2021-02-09 08:50:22 +0100347 return 0;
Michal Simek29b9b712018-05-17 14:06:06 +0200348}
349
Michal Simek1ca66d72019-02-14 13:14:30 +0100350static int set_fdtfile(void)
351{
352 char *compatible, *fdtfile;
353 const char *suffix = ".dtb";
354 const char *vendor = "xilinx/";
Igor Lantsmane167bac2020-06-24 14:33:46 +0200355 int fdt_compat_len;
Michal Simek1ca66d72019-02-14 13:14:30 +0100356
357 if (env_get("fdtfile"))
358 return 0;
359
Igor Lantsmane167bac2020-06-24 14:33:46 +0200360 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
361 &fdt_compat_len);
362 if (compatible && fdt_compat_len) {
363 char *name;
364
Michal Simek1ca66d72019-02-14 13:14:30 +0100365 debug("Compatible: %s\n", compatible);
366
Igor Lantsmane167bac2020-06-24 14:33:46 +0200367 name = strchr(compatible, ',');
368 if (!name)
369 return -EINVAL;
Michal Simek1ca66d72019-02-14 13:14:30 +0100370
Igor Lantsmane167bac2020-06-24 14:33:46 +0200371 name++;
372
373 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek1ca66d72019-02-14 13:14:30 +0100374 strlen(suffix) + 1);
375 if (!fdtfile)
376 return -ENOMEM;
377
Igor Lantsmane167bac2020-06-24 14:33:46 +0200378 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek1ca66d72019-02-14 13:14:30 +0100379
380 env_set("fdtfile", fdtfile);
381 free(fdtfile);
382 }
383
384 return 0;
385}
386
Michal Simekb1634762023-09-05 13:30:07 +0200387static int boot_targets_setup(void)
Michal Simek9c91e612020-04-08 11:04:41 +0200388{
Michal Simek04b7e622015-01-15 10:01:51 +0100389 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200390 struct udevice *dev;
391 int bootseq = -1;
392 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200393 int env_targets_len = 0;
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530394 const char *mode = NULL;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200395 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530396 char *env_targets;
Michal Simek7cb4cca2021-10-25 10:10:52 +0200397
Michal Simek9c91e612020-04-08 11:04:41 +0200398 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100399
Michal Simekc5d95232015-09-20 17:20:42 +0200400 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100401 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200402 case USB_MODE:
403 puts("USB_MODE\n");
T Karthik Reddy9eee8e32021-03-24 23:37:57 -0600404 mode = "usb_dfu0 usb_dfu1";
Michal Simek43380352017-12-01 15:18:24 +0100405 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200406 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530407 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200408 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530409 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100410 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530411 break;
412 case QSPI_MODE_24BIT:
413 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200414 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200415 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100416 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530417 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200418 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200419 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700420 if (uclass_get_device_by_name(UCLASS_MMC,
421 "mmc@ff160000", &dev) &&
422 uclass_get_device_by_name(UCLASS_MMC,
423 "sdhci@ff160000", &dev)) {
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530424 debug("SD0 driver for SD0 device is not present\n");
425 break;
T Karthik Reddy19735c32019-12-17 06:41:42 -0700426 }
Simon Glass75e534b2020-12-16 21:20:07 -0700427 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy19735c32019-12-17 06:41:42 -0700428
429 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700430 bootseq = dev_seq(dev);
Ashok Reddy Somaa10be052021-09-15 08:52:17 +0200431 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200432 break;
433 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200434 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200435 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530436 "mmc@ff160000", &dev) &&
437 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200438 "sdhci@ff160000", &dev)) {
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530439 debug("SD0 driver for SD0 device is not present\n");
440 break;
Michal Simekf183a982018-04-25 11:20:43 +0200441 }
Simon Glass75e534b2020-12-16 21:20:07 -0700442 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200443
444 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700445 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100446 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100447 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530448 case SD1_LSHFT_MODE:
449 puts("LVL_SHFT_");
Michal Simek293f47b2021-10-18 13:30:04 +0200450 fallthrough;
Michal Simek108e1842015-10-05 10:51:12 +0200451 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200452 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200453 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530454 "mmc@ff170000", &dev) &&
455 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200456 "sdhci@ff170000", &dev)) {
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530457 debug("SD1 driver for SD1 device is not present\n");
458 break;
Michal Simekf183a982018-04-25 11:20:43 +0200459 }
Simon Glass75e534b2020-12-16 21:20:07 -0700460 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200461
462 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700463 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100464 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200465 break;
466 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200467 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200468 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100469 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200470 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100471 default:
472 printf("Invalid Boot Mode:0x%x\n", bootmode);
473 break;
474 }
475
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530476 if (mode) {
477 if (bootseq >= 0) {
478 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
479 debug("Bootseq len: %x\n", bootseq_len);
480 env_set_hex("bootseq", bootseq);
481 }
Michal Simekf183a982018-04-25 11:20:43 +0200482
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530483 /*
484 * One terminating char + one byte for space between mode
485 * and default boot_targets
486 */
487 env_targets = env_get("boot_targets");
488 if (env_targets)
489 env_targets_len = strlen(env_targets);
Michal Simek7410b142018-04-25 11:10:34 +0200490
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530491 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
492 bootseq_len);
493 if (!new_targets)
494 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200495
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530496 if (bootseq >= 0)
497 sprintf(new_targets, "%s%x %s", mode, bootseq,
498 env_targets ? env_targets : "");
499 else
500 sprintf(new_targets, "%s %s", mode,
501 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200502
Venkatesh Yadav Abbarapu6555dcc2023-09-04 08:50:35 +0530503 env_set("boot_targets", new_targets);
504 free(new_targets);
505 }
Michal Simekecfb6dc2016-04-22 14:28:54 +0200506
Michal Simekb1634762023-09-05 13:30:07 +0200507 return 0;
508}
509
510int board_late_init(void)
511{
512 int ret, multiboot;
513
514#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
515 usb_ether_init();
516#endif
517
518 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
519 debug("Saved variables - Skipping\n");
520 return 0;
521 }
522
523 if (!IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG))
524 return 0;
525
526 ret = set_fdtfile();
527 if (ret)
528 return ret;
529
530 multiboot = multi_boot();
531 if (multiboot >= 0)
532 env_set_hex("multiboot", multiboot);
533
534 if (IS_ENABLED(CONFIG_DISTRO_DEFAULTS)) {
535 ret = boot_targets_setup();
536 if (ret)
537 return ret;
538 }
539
Michal Simek29b9b712018-05-17 14:06:06 +0200540 reset_reason();
541
Michal Simek705d44a2020-03-31 12:39:37 +0200542 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100543}
Michal Simek342edfe2018-12-20 09:33:38 +0100544#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530545
546int checkboard(void)
547{
Michal Simek47ce9362016-01-25 11:04:21 +0100548 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530549 return 0;
550}
Michal Simek8d4a8d42020-07-30 13:37:49 +0200551
Michal Simeke0026bf2021-05-19 15:16:19 +0200552int mmc_get_env_dev(void)
553{
554 struct udevice *dev;
555 int bootseq = 0;
556
557 switch (zynqmp_get_bootmode()) {
558 case EMMC_MODE:
559 case SD_MODE:
560 if (uclass_get_device_by_name(UCLASS_MMC,
561 "mmc@ff160000", &dev) &&
562 uclass_get_device_by_name(UCLASS_MMC,
563 "sdhci@ff160000", &dev)) {
564 return -1;
565 }
566 bootseq = dev_seq(dev);
567 break;
568 case SD1_LSHFT_MODE:
569 case SD_MODE1:
570 if (uclass_get_device_by_name(UCLASS_MMC,
571 "mmc@ff170000", &dev) &&
572 uclass_get_device_by_name(UCLASS_MMC,
573 "sdhci@ff170000", &dev)) {
574 return -1;
575 }
576 bootseq = dev_seq(dev);
577 break;
578 default:
579 break;
580 }
581
582 debug("bootseq %d\n", bootseq);
583
584 return bootseq;
585}
586
Michal Simek8d4a8d42020-07-30 13:37:49 +0200587enum env_location env_get_location(enum env_operation op, int prio)
588{
589 u32 bootmode = zynqmp_get_bootmode();
590
591 if (prio)
592 return ENVL_UNKNOWN;
593
594 switch (bootmode) {
595 case EMMC_MODE:
596 case SD_MODE:
597 case SD1_LSHFT_MODE:
598 case SD_MODE1:
599 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
600 return ENVL_FAT;
601 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
602 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200603 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200604 case NAND_MODE:
605 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
606 return ENVL_NAND;
607 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
608 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200609 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200610 case QSPI_MODE_24BIT:
611 case QSPI_MODE_32BIT:
612 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
613 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200614 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200615 case JTAG_MODE:
616 default:
617 return ENVL_NOWHERE;
618 }
619}
Michal Simekcfb37602021-07-27 16:19:18 +0200620
621#if defined(CONFIG_SET_DFU_ALT_INFO)
622
623#define DFU_ALT_BUF_LEN SZ_1K
624
625void set_dfu_alt_info(char *interface, char *devstr)
626{
Michal Simek9fced422022-12-02 14:06:15 +0100627 int multiboot, bootseq = 0, len = 0;
Michal Simekcfb37602021-07-27 16:19:18 +0200628
629 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
630
Michal Simekf0d6f462022-08-09 16:32:52 +0200631 if (env_get("dfu_alt_info"))
Michal Simekcfb37602021-07-27 16:19:18 +0200632 return;
633
634 memset(buf, 0, sizeof(buf));
635
636 multiboot = multi_boot();
Michal Simek7cb4cca2021-10-25 10:10:52 +0200637 if (multiboot < 0)
638 multiboot = 0;
639
640 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekcfb37602021-07-27 16:19:18 +0200641 debug("Multiboot: %d\n", multiboot);
642
643 switch (zynqmp_get_bootmode()) {
644 case EMMC_MODE:
645 case SD_MODE:
646 case SD1_LSHFT_MODE:
647 case SD_MODE1:
648 bootseq = mmc_get_env_dev();
Michal Simek9fced422022-12-02 14:06:15 +0100649
650 len += snprintf(buf + len, DFU_ALT_BUF_LEN, "mmc %d=boot",
651 bootseq);
652
653 if (multiboot)
654 len += snprintf(buf + len, DFU_ALT_BUF_LEN,
655 "%04d", multiboot);
656
657 len += snprintf(buf + len, DFU_ALT_BUF_LEN, ".bin fat %d 1",
658 bootseq);
659#if defined(CONFIG_SPL_FS_LOAD_PAYLOAD_NAME)
660 len += snprintf(buf + len, DFU_ALT_BUF_LEN, ";%s fat %d 1",
661 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
662#endif
Michal Simekcfb37602021-07-27 16:19:18 +0200663 break;
664 case QSPI_MODE_24BIT:
665 case QSPI_MODE_32BIT:
Michal Simek9fced422022-12-02 14:06:15 +0100666 len += snprintf(buf + len, DFU_ALT_BUF_LEN,
667 "sf 0:0=boot.bin raw %x 0x1500000",
668 multiboot * SZ_32K);
669#if defined(CONFIG_SPL_FS_LOAD_PAYLOAD_NAME) && defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
670 len += snprintf(buf + len, DFU_ALT_BUF_LEN,
671 ";%s raw 0x%x 0x500000",
672 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
673 CONFIG_SYS_SPI_U_BOOT_OFFS);
Stefan Herbrechtsmeierfb027cd2022-06-20 18:36:46 +0200674#endif
Michal Simek9fced422022-12-02 14:06:15 +0100675 break;
Michal Simekcfb37602021-07-27 16:19:18 +0200676 default:
677 return;
678 }
679
680 env_set("dfu_alt_info", buf);
681 puts("DFU alt info setting: done\n");
682}
683#endif