blob: 8188e76dd84462402d74a4b02225907f70f3184e [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>
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 Simek826d7eca2020-03-04 08:48:16 +0100148#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100149 struct udevice *dev;
150
151 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
152 if (!dev)
153 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100154#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100155
Luca Ceresoli23e65002019-05-21 18:06:43 +0200156#if defined(CONFIG_SPL_BUILD)
157 /* Check *at build time* if the filename is an non-empty string */
158 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
159 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
160 zynqmp_pm_cfg_obj_size);
Michal Simekae9dc112021-02-02 16:34:48 +0100161 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200162
163 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti5b774f02021-11-04 16:28:02 -0300164 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200165 restore_jtag();
Michal Simek394ee242020-08-03 13:01:45 +0200166#else
167 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
168 xilinx_read_eeprom();
Luca Ceresoli23e65002019-05-21 18:06:43 +0200169#endif
170
Michal Simekfb7242d2015-06-22 14:31:06 +0200171 printf("EL Level:\tEL%d\n", current_el());
172
Michal Simek1aab1142020-09-09 14:41:56 +0200173#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200174 ret = soc_get(&soc);
175 if (!ret) {
176 ret = soc_get_machine(soc, name, sizeof(name));
177 if (ret >= 0) {
178 zynqmppl.name = strdup(name);
179 fpga_init();
180 fpga_add(fpga_xilinx, &zynqmppl);
181 }
182 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200183#endif
184
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200185 /* display secure boot information */
186 print_secure_boot();
Michal Simek46900462020-02-11 12:43:14 +0100187 if (current_el() == 3)
Michal Simek21e5c322021-07-27 14:05:27 +0200188 printf("Multiboot:\t%d\n", multi_boot());
Michal Simek46900462020-02-11 12:43:14 +0100189
Michal Simek04b7e622015-01-15 10:01:51 +0100190 return 0;
191}
192
193int board_early_init_r(void)
194{
195 u32 val;
196
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530197 if (current_el() != 3)
198 return 0;
199
Michal Simek245d5282017-07-12 10:32:18 +0200200 val = readl(&crlapb_base->timestamp_ref_ctrl);
201 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
202
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530203 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100204 val = readl(&crlapb_base->timestamp_ref_ctrl);
205 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
206 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100207
Michal Simekc23d3f82015-11-05 08:34:35 +0100208 /* Program freq register in System counter */
209 writel(zynqmp_get_system_timer_freq(),
210 &iou_scntr_secure->base_frequency_id_register);
211 /* And enable system counter */
212 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
213 &iou_scntr_secure->counter_control_register);
214 }
Michal Simek04b7e622015-01-15 10:01:51 +0100215 return 0;
216}
217
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530218unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600219 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530220{
221 int ret = 0;
222
223 if (current_el() > 1) {
224 smp_kick_all_cpus();
225 dcache_disable();
226 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
227 ES_TO_AARCH64);
228 } else {
229 printf("FAIL: current EL is not above EL1\n");
230 ret = EINVAL;
231 }
232 return ret;
233}
234
Michal Simek8faa66a2016-02-08 09:34:53 +0100235#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600236int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100237{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530238 int ret;
239
240 ret = fdtdec_setup_memory_banksize();
241 if (ret)
242 return ret;
243
244 mem_map_fill();
245
246 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500247}
Michal Simek8faa66a2016-02-08 09:34:53 +0100248
Tom Riniedcfdbd2016-12-09 07:56:54 -0500249int dram_init(void)
250{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530251 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000252 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500253
254 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100255}
Michal Simek97ab9612021-05-31 11:03:19 +0200256
Michal Simek8faa66a2016-02-08 09:34:53 +0100257#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530258int dram_init_banksize(void)
259{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530260 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
261 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530262
263 mem_map_fill();
264
265 return 0;
266}
267
Michal Simek04b7e622015-01-15 10:01:51 +0100268int dram_init(void)
269{
Michal Simek1b846212018-04-11 16:12:28 +0200270 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
271 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100272
273 return 0;
274}
Michal Simek8faa66a2016-02-08 09:34:53 +0100275#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100276
Michal Simek2a220332021-07-13 16:39:26 +0200277#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100278void reset_cpu(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100279{
280}
Michal Simek2a220332021-07-13 16:39:26 +0200281#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100282
Michal Simek8ec30042020-08-20 10:54:45 +0200283static u8 __maybe_unused zynqmp_get_bootmode(void)
284{
285 u8 bootmode;
286 u32 reg = 0;
287 int ret;
288
289 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
290 if (ret)
291 return -EINVAL;
292
Michal Simek58cc08c2021-07-28 12:25:49 +0200293 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
294 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
295
Michal Simek8ec30042020-08-20 10:54:45 +0200296 if (reg >> BOOT_MODE_ALT_SHIFT)
297 reg >>= BOOT_MODE_ALT_SHIFT;
298
299 bootmode = reg & BOOT_MODES_MASK;
300
301 return bootmode;
302}
303
Michal Simek342edfe2018-12-20 09:33:38 +0100304#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200305static const struct {
306 u32 bit;
307 const char *name;
308} reset_reasons[] = {
309 { RESET_REASON_DEBUG_SYS, "DEBUG" },
310 { RESET_REASON_SOFT, "SOFT" },
311 { RESET_REASON_SRST, "SRST" },
312 { RESET_REASON_PSONLY, "PS-ONLY" },
313 { RESET_REASON_PMU, "PMU" },
314 { RESET_REASON_INTERNAL, "INTERNAL" },
315 { RESET_REASON_EXTERNAL, "EXTERNAL" },
316 {}
317};
318
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530319static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200320{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530321 u32 reg;
322 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200323 const char *reason = NULL;
324
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530325 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
326 if (ret)
327 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200328
329 puts("Reset reason:\t");
330
331 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530332 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200333 reason = reset_reasons[i].name;
334 printf("%s ", reset_reasons[i].name);
335 break;
336 }
337 }
338
339 puts("\n");
340
341 env_set("reset_reason", reason);
342
Michal Simek0954c8c2021-02-09 08:50:22 +0100343 return 0;
Michal Simek29b9b712018-05-17 14:06:06 +0200344}
345
Michal Simek1ca66d72019-02-14 13:14:30 +0100346static int set_fdtfile(void)
347{
348 char *compatible, *fdtfile;
349 const char *suffix = ".dtb";
350 const char *vendor = "xilinx/";
Igor Lantsmane167bac2020-06-24 14:33:46 +0200351 int fdt_compat_len;
Michal Simek1ca66d72019-02-14 13:14:30 +0100352
353 if (env_get("fdtfile"))
354 return 0;
355
Igor Lantsmane167bac2020-06-24 14:33:46 +0200356 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
357 &fdt_compat_len);
358 if (compatible && fdt_compat_len) {
359 char *name;
360
Michal Simek1ca66d72019-02-14 13:14:30 +0100361 debug("Compatible: %s\n", compatible);
362
Igor Lantsmane167bac2020-06-24 14:33:46 +0200363 name = strchr(compatible, ',');
364 if (!name)
365 return -EINVAL;
Michal Simek1ca66d72019-02-14 13:14:30 +0100366
Igor Lantsmane167bac2020-06-24 14:33:46 +0200367 name++;
368
369 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek1ca66d72019-02-14 13:14:30 +0100370 strlen(suffix) + 1);
371 if (!fdtfile)
372 return -ENOMEM;
373
Igor Lantsmane167bac2020-06-24 14:33:46 +0200374 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek1ca66d72019-02-14 13:14:30 +0100375
376 env_set("fdtfile", fdtfile);
377 free(fdtfile);
378 }
379
380 return 0;
381}
382
Michal Simek9c91e612020-04-08 11:04:41 +0200383int board_late_init(void)
384{
Michal Simek04b7e622015-01-15 10:01:51 +0100385 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200386 struct udevice *dev;
387 int bootseq = -1;
388 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200389 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200390 const char *mode;
391 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530392 char *env_targets;
Michal Simek7cb4cca2021-10-25 10:10:52 +0200393 int ret, multiboot;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200394
Michal Simek482f5492018-10-05 08:55:16 +0200395#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
396 usb_ether_init();
397#endif
398
Michal Simekecfb6dc2016-04-22 14:28:54 +0200399 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
400 debug("Saved variables - Skipping\n");
401 return 0;
402 }
Michal Simek04b7e622015-01-15 10:01:51 +0100403
Michal Simekbab07b62020-07-28 12:45:47 +0200404 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
405 return 0;
406
Michal Simek1ca66d72019-02-14 13:14:30 +0100407 ret = set_fdtfile();
408 if (ret)
409 return ret;
410
Michal Simek7cb4cca2021-10-25 10:10:52 +0200411 multiboot = multi_boot();
412 if (multiboot >= 0)
413 env_set_hex("multiboot", multiboot);
414
Michal Simek9c91e612020-04-08 11:04:41 +0200415 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100416
Michal Simekc5d95232015-09-20 17:20:42 +0200417 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100418 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200419 case USB_MODE:
420 puts("USB_MODE\n");
T Karthik Reddy9eee8e32021-03-24 23:37:57 -0600421 mode = "usb_dfu0 usb_dfu1";
Michal Simek43380352017-12-01 15:18:24 +0100422 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200423 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530424 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200425 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530426 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100427 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530428 break;
429 case QSPI_MODE_24BIT:
430 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200431 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200432 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100433 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530434 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200435 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200436 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700437 if (uclass_get_device_by_name(UCLASS_MMC,
438 "mmc@ff160000", &dev) &&
439 uclass_get_device_by_name(UCLASS_MMC,
440 "sdhci@ff160000", &dev)) {
441 puts("Boot from EMMC but without SD0 enabled!\n");
442 return -1;
443 }
Simon Glass75e534b2020-12-16 21:20:07 -0700444 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy19735c32019-12-17 06:41:42 -0700445
446 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700447 bootseq = dev_seq(dev);
Ashok Reddy Somaa10be052021-09-15 08:52:17 +0200448 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200449 break;
450 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200451 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200452 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530453 "mmc@ff160000", &dev) &&
454 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200455 "sdhci@ff160000", &dev)) {
456 puts("Boot from SD0 but without SD0 enabled!\n");
457 return -1;
458 }
Simon Glass75e534b2020-12-16 21:20:07 -0700459 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200460
461 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700462 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100463 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100464 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530465 case SD1_LSHFT_MODE:
466 puts("LVL_SHFT_");
Michal Simek293f47b2021-10-18 13:30:04 +0200467 fallthrough;
Michal Simek108e1842015-10-05 10:51:12 +0200468 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200469 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200470 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530471 "mmc@ff170000", &dev) &&
472 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200473 "sdhci@ff170000", &dev)) {
474 puts("Boot from SD1 but without SD1 enabled!\n");
475 return -1;
476 }
Simon Glass75e534b2020-12-16 21:20:07 -0700477 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200478
479 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700480 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100481 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200482 break;
483 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200484 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200485 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100486 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200487 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100488 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200489 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100490 printf("Invalid Boot Mode:0x%x\n", bootmode);
491 break;
492 }
493
Michal Simekf183a982018-04-25 11:20:43 +0200494 if (bootseq >= 0) {
495 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
496 debug("Bootseq len: %x\n", bootseq_len);
Michal Simek7a117c72021-01-11 13:46:58 +0100497 env_set_hex("bootseq", bootseq);
Michal Simekf183a982018-04-25 11:20:43 +0200498 }
499
Michal Simekecfb6dc2016-04-22 14:28:54 +0200500 /*
501 * One terminating char + one byte for space between mode
502 * and default boot_targets
503 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530504 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200505 if (env_targets)
506 env_targets_len = strlen(env_targets);
507
Michal Simekf183a982018-04-25 11:20:43 +0200508 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
509 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200510 if (!new_targets)
511 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200512
Michal Simekf183a982018-04-25 11:20:43 +0200513 if (bootseq >= 0)
514 sprintf(new_targets, "%s%x %s", mode, bootseq,
515 env_targets ? env_targets : "");
516 else
517 sprintf(new_targets, "%s %s", mode,
518 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200519
Simon Glass6a38e412017-08-03 12:22:09 -0600520 env_set("boot_targets", new_targets);
Michal Simek77488232021-07-28 12:46:39 +0200521 free(new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200522
Michal Simek29b9b712018-05-17 14:06:06 +0200523 reset_reason();
524
Michal Simek705d44a2020-03-31 12:39:37 +0200525 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100526}
Michal Simek342edfe2018-12-20 09:33:38 +0100527#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530528
529int checkboard(void)
530{
Michal Simek47ce9362016-01-25 11:04:21 +0100531 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530532 return 0;
533}
Michal Simek8d4a8d42020-07-30 13:37:49 +0200534
Michal Simeke0026bf2021-05-19 15:16:19 +0200535int mmc_get_env_dev(void)
536{
537 struct udevice *dev;
538 int bootseq = 0;
539
540 switch (zynqmp_get_bootmode()) {
541 case EMMC_MODE:
542 case SD_MODE:
543 if (uclass_get_device_by_name(UCLASS_MMC,
544 "mmc@ff160000", &dev) &&
545 uclass_get_device_by_name(UCLASS_MMC,
546 "sdhci@ff160000", &dev)) {
547 return -1;
548 }
549 bootseq = dev_seq(dev);
550 break;
551 case SD1_LSHFT_MODE:
552 case SD_MODE1:
553 if (uclass_get_device_by_name(UCLASS_MMC,
554 "mmc@ff170000", &dev) &&
555 uclass_get_device_by_name(UCLASS_MMC,
556 "sdhci@ff170000", &dev)) {
557 return -1;
558 }
559 bootseq = dev_seq(dev);
560 break;
561 default:
562 break;
563 }
564
565 debug("bootseq %d\n", bootseq);
566
567 return bootseq;
568}
569
Michal Simek8d4a8d42020-07-30 13:37:49 +0200570enum env_location env_get_location(enum env_operation op, int prio)
571{
572 u32 bootmode = zynqmp_get_bootmode();
573
574 if (prio)
575 return ENVL_UNKNOWN;
576
577 switch (bootmode) {
578 case EMMC_MODE:
579 case SD_MODE:
580 case SD1_LSHFT_MODE:
581 case SD_MODE1:
582 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
583 return ENVL_FAT;
584 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
585 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200586 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200587 case NAND_MODE:
588 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
589 return ENVL_NAND;
590 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
591 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200592 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200593 case QSPI_MODE_24BIT:
594 case QSPI_MODE_32BIT:
595 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
596 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200597 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200598 case JTAG_MODE:
599 default:
600 return ENVL_NOWHERE;
601 }
602}
Michal Simekcfb37602021-07-27 16:19:18 +0200603
604#if defined(CONFIG_SET_DFU_ALT_INFO)
605
606#define DFU_ALT_BUF_LEN SZ_1K
607
608void set_dfu_alt_info(char *interface, char *devstr)
609{
Venkatesh Yadav Abbarapu50a8f8e2022-10-04 11:22:54 +0530610 int multiboot;
Michal Simekcfb37602021-07-27 16:19:18 +0200611 int bootseq = 0;
612
613 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
614
Michal Simekf0d6f462022-08-09 16:32:52 +0200615 if (env_get("dfu_alt_info"))
Michal Simekcfb37602021-07-27 16:19:18 +0200616 return;
617
618 memset(buf, 0, sizeof(buf));
619
620 multiboot = multi_boot();
Michal Simek7cb4cca2021-10-25 10:10:52 +0200621 if (multiboot < 0)
622 multiboot = 0;
623
624 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekcfb37602021-07-27 16:19:18 +0200625 debug("Multiboot: %d\n", multiboot);
626
627 switch (zynqmp_get_bootmode()) {
628 case EMMC_MODE:
629 case SD_MODE:
630 case SD1_LSHFT_MODE:
631 case SD_MODE1:
632 bootseq = mmc_get_env_dev();
633 if (!multiboot)
634 snprintf(buf, DFU_ALT_BUF_LEN,
Michal Simek3e09d192022-08-09 16:32:54 +0200635 "mmc %d=boot.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200636 "%s fat %d 1",
637 bootseq, bootseq,
638 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200639 else
640 snprintf(buf, DFU_ALT_BUF_LEN,
Michal Simek3e09d192022-08-09 16:32:54 +0200641 "mmc %d=boot%04d.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200642 "%s fat %d 1",
643 bootseq, multiboot, bootseq,
644 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200645 break;
Stefan Herbrechtsmeierfb027cd2022-06-20 18:36:46 +0200646#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
Michal Simekcfb37602021-07-27 16:19:18 +0200647 case QSPI_MODE_24BIT:
648 case QSPI_MODE_32BIT:
649 snprintf(buf, DFU_ALT_BUF_LEN,
650 "sf 0:0=boot.bin raw %x 0x1500000;"
Michal Simek69103192021-10-18 14:02:15 +0200651 "%s raw 0x%x 0x500000",
652 multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
653 CONFIG_SYS_SPI_U_BOOT_OFFS);
Michal Simekcfb37602021-07-27 16:19:18 +0200654 break;
Stefan Herbrechtsmeierfb027cd2022-06-20 18:36:46 +0200655#endif
Michal Simekcfb37602021-07-27 16:19:18 +0200656 default:
657 return;
658 }
659
660 env_set("dfu_alt_info", buf);
661 puts("DFU alt info setting: done\n");
662}
663#endif