blob: 3a10ed859d2c61d2f2da24cf6b3a1df8c747b233 [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>
Michal Simekb72894f2016-04-22 14:28:54 +020022#include <malloc.h>
Michal Simekb86f43d2021-07-27 16:19:18 +020023#include <memalign.h>
Michal Simek4490e012018-04-19 15:43:38 +020024#include <wdt.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010025#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010026#include <asm/arch/hardware.h>
27#include <asm/arch/sys_proto.h>
Michal Simek2ad341e2018-01-10 09:36:09 +010028#include <asm/arch/psu_init_gpl.h>
Simon Glass90526e92020-05-10 11:39:56 -060029#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060030#include <asm/global_data.h>
Michal Simek84c72042015-01-15 10:01:51 +010031#include <asm/io.h>
Simon Glass25a58182020-05-10 11:40:06 -060032#include <asm/ptrace.h>
Michal Simek2882b392018-04-25 11:20:43 +020033#include <dm/device.h>
Michal Simek4490e012018-04-19 15:43:38 +020034#include <dm/uclass.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053035#include <usb.h>
36#include <dwc3-uboot.h>
Michal Simek47e60cb2016-02-01 15:05:58 +010037#include <zynqmppl.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010038#include <zynqmp_firmware.h>
Michal Simek9feff382016-09-01 11:16:40 +020039#include <g_dnl.h>
Simon Glasscd93d622020-05-10 11:40:13 -060040#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060041#include <linux/delay.h>
42#include <linux/sizes.h>
Michal Simek80fdef12020-03-31 12:39:37 +020043#include "../common/board.h"
Michal Simek84c72042015-01-15 10:01:51 +010044
Luca Ceresolic28a9cf2019-05-21 18:06:43 +020045#include "pm_cfg_obj.h"
46
Ibai Erkiagafa793162020-08-04 23:17:31 +010047#define ZYNQMP_VERSION_SIZE 7
Michal Simek2fbdbee2020-10-21 12:23:17 +020048#define EFUSE_VCU_DIS_MASK 0x100
49#define EFUSE_VCU_DIS_SHIFT 8
50#define EFUSE_GPU_DIS_MASK 0x20
51#define EFUSE_GPU_DIS_SHIFT 5
52#define IDCODE2_PL_INIT_MASK 0x200
53#define IDCODE2_PL_INIT_SHIFT 9
Ibai Erkiagafa793162020-08-04 23:17:31 +010054
Michal Simek84c72042015-01-15 10:01:51 +010055DECLARE_GLOBAL_DATA_PTR;
56
Michal Simek29bd8ad2020-09-09 14:41:56 +020057#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Michal Simek47e60cb2016-02-01 15:05:58 +010058static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
59
Ibai Erkiagafa793162020-08-04 23:17:31 +010060enum {
61 ZYNQMP_VARIANT_EG = BIT(0U),
62 ZYNQMP_VARIANT_EV = BIT(1U),
63 ZYNQMP_VARIANT_CG = BIT(2U),
64 ZYNQMP_VARIANT_DR = BIT(3U),
65};
66
Michal Simek47e60cb2016-02-01 15:05:58 +010067static const struct {
Michal Simek8ebdf9e2017-11-06 12:55:59 +010068 u32 id;
Ibai Erkiagafa793162020-08-04 23:17:31 +010069 u8 device;
70 u8 variants;
Michal Simek47e60cb2016-02-01 15:05:58 +010071} zynqmp_devices[] = {
72 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010073 .id = 0x04711093,
74 .device = 2,
75 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek47e60cb2016-02-01 15:05:58 +010076 },
77 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010078 .id = 0x04710093,
79 .device = 3,
80 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek494fffe2017-08-22 14:58:53 +020081 },
82 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010083 .id = 0x04721093,
84 .device = 4,
85 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
86 ZYNQMP_VARIANT_EV,
Michal Simek47e60cb2016-02-01 15:05:58 +010087 },
88 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010089 .id = 0x04720093,
90 .device = 5,
91 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
92 ZYNQMP_VARIANT_EV,
Michal Simek494fffe2017-08-22 14:58:53 +020093 },
94 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010095 .id = 0x04739093,
96 .device = 6,
97 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek47e60cb2016-02-01 15:05:58 +010098 },
99 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100100 .id = 0x04730093,
101 .device = 7,
102 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
103 ZYNQMP_VARIANT_EV,
Michal Simek494fffe2017-08-22 14:58:53 +0200104 },
105 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100106 .id = 0x04738093,
107 .device = 9,
Michal Simekbbe086a2020-10-02 14:42:05 +0200108 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek494fffe2017-08-22 14:58:53 +0200109 },
110 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100111 .id = 0x04740093,
112 .device = 11,
113 .variants = ZYNQMP_VARIANT_EG,
Michal Simek47e60cb2016-02-01 15:05:58 +0100114 },
115 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100116 .id = 0x04750093,
117 .device = 15,
118 .variants = ZYNQMP_VARIANT_EG,
Michal Simek494fffe2017-08-22 14:58:53 +0200119 },
120 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100121 .id = 0x04759093,
122 .device = 17,
123 .variants = ZYNQMP_VARIANT_EG,
Michal Simek494fffe2017-08-22 14:58:53 +0200124 },
125 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100126 .id = 0x04758093,
127 .device = 19,
128 .variants = ZYNQMP_VARIANT_EG,
Michal Simek47e60cb2016-02-01 15:05:58 +0100129 },
130 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100131 .id = 0x047E1093,
132 .device = 21,
133 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200134 },
135 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100136 .id = 0x047E3093,
137 .device = 23,
138 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200139 },
140 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100141 .id = 0x047E5093,
142 .device = 25,
143 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100144 },
145 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100146 .id = 0x047E4093,
147 .device = 27,
148 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200149 },
150 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100151 .id = 0x047E0093,
152 .device = 28,
153 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100154 },
155 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100156 .id = 0x047E2093,
157 .device = 29,
158 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200159 },
160 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100161 .id = 0x047E6093,
162 .device = 39,
163 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200164 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100165 {
Michal Simeke17c5ec2020-09-11 09:22:15 +0200166 .id = 0x047FD093,
167 .device = 43,
168 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100169 },
170 {
Michal Simeke17c5ec2020-09-11 09:22:15 +0200171 .id = 0x047F8093,
172 .device = 46,
173 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100174 },
175 {
Michal Simeke17c5ec2020-09-11 09:22:15 +0200176 .id = 0x047FF093,
177 .device = 47,
178 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100179 },
Michal Simekb030fed2017-06-02 08:08:59 +0200180 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100181 .id = 0x047FB093,
182 .device = 48,
183 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb030fed2017-06-02 08:08:59 +0200184 },
185 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100186 .id = 0x047FE093,
187 .device = 49,
188 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu134b0c82019-07-23 11:56:17 +0530189 },
T Karthik Reddy45576272021-05-13 07:13:25 -0600190 {
191 .id = 0x046d0093,
192 .device = 67,
193 .variants = ZYNQMP_VARIANT_DR,
194 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100195};
196
Michal Simekddf8dea2020-10-05 09:35:40 +0200197static const struct {
198 u32 id;
199 char *name;
200} zynqmp_svd_devices[] = {
201 {
202 .id = 0x04714093,
203 .name = "xck24"
204 },
205 {
206 .id = 0x04724093,
207 .name = "xck26",
208 },
209};
210
211static char *zynqmp_detect_svd_name(u32 idcode)
212{
213 u32 i;
214
215 for (i = 0; i < ARRAY_SIZE(zynqmp_svd_devices); i++) {
216 if (zynqmp_svd_devices[i].id == (idcode & 0x0FFFFFFF))
217 return zynqmp_svd_devices[i].name;
218 }
219
220 return "unknown";
221}
222
Michal Simek47e60cb2016-02-01 15:05:58 +0100223static char *zynqmp_get_silicon_idcode_name(void)
224{
Ibai Erkiagafa793162020-08-04 23:17:31 +0100225 u32 i;
226 u32 idcode, idcode2;
Michal Simekced4d462020-08-05 12:41:35 +0200227 char name[ZYNQMP_VERSION_SIZE];
Ibai Erkiaga050f10f2020-08-04 23:17:30 +0100228 u32 ret_payload[PAYLOAD_ARG_CNT];
Michal Simek0d76b712020-10-07 15:13:17 +0200229 int ret;
Michal Simek47e60cb2016-02-01 15:05:58 +0100230
Michal Simekd026aa12020-10-21 12:16:02 +0200231 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
232 if (ret) {
233 debug("%s: Getting chipid failed\n", __func__);
234 return "unknown";
235 }
Ibai Erkiaga050f10f2020-08-04 23:17:30 +0100236
237 /*
238 * Firmware returns:
239 * payload[0][31:0] = status of the operation
240 * payload[1]] = IDCODE
241 * payload[2][19:0] = Version
242 * payload[2][28:20] = EXTENDED_IDCODE
243 * payload[2][29] = PL_INIT
244 */
245
Ibai Erkiagafa793162020-08-04 23:17:31 +0100246 idcode = ret_payload[1];
247 idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
Michal Simek16df2f12020-10-21 12:16:50 +0200248 debug("%s, IDCODE: 0x%0x, IDCODE2: 0x%0x\r\n", __func__, idcode,
Ibai Erkiagafa793162020-08-04 23:17:31 +0100249 idcode2);
Michal Simek494fffe2017-08-22 14:58:53 +0200250
Michal Simek47e60cb2016-02-01 15:05:58 +0100251 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100252 if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF))
253 break;
Michal Simek47e60cb2016-02-01 15:05:58 +0100254 }
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530255
256 if (i >= ARRAY_SIZE(zynqmp_devices))
Michal Simekddf8dea2020-10-05 09:35:40 +0200257 return zynqmp_detect_svd_name(idcode);
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530258
Ibai Erkiagafa793162020-08-04 23:17:31 +0100259 /* Add device prefix to the name */
Michal Simek0d76b712020-10-07 15:13:17 +0200260 ret = snprintf(name, ZYNQMP_VERSION_SIZE, "zu%d",
261 zynqmp_devices[i].device);
Michal Simek07499da2020-10-21 12:17:44 +0200262 if (ret < 0)
Michal Simek0d76b712020-10-07 15:13:17 +0200263 return "unknown";
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530264
Ibai Erkiagafa793162020-08-04 23:17:31 +0100265 if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
266 /* Devices with EV variant might be EG/CG/EV family */
267 if (idcode2 & IDCODE2_PL_INIT_MASK) {
268 u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >>
269 EFUSE_VCU_DIS_SHIFT) << 1 |
270 ((idcode2 & EFUSE_GPU_DIS_MASK) >>
271 EFUSE_GPU_DIS_SHIFT);
272
273 /*
274 * Get family name based on extended idcode values as
275 * determined on UG1087, EXTENDED_IDCODE register
276 * description
277 */
278 switch (family) {
279 case 0x00:
280 strncat(name, "ev", 2);
281 break;
282 case 0x10:
283 strncat(name, "eg", 2);
284 break;
285 case 0x11:
286 strncat(name, "cg", 2);
287 break;
288 default:
289 /* Do not append family name*/
290 break;
291 }
292 } else {
293 /*
294 * When PL powered down the VCU Disable efuse cannot be
295 * read. So, ignore the bit and just findout if it is CG
296 * or EG/EV variant.
297 */
298 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" :
299 "e", 2);
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530300 }
Ibai Erkiagafa793162020-08-04 23:17:31 +0100301 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_CG) {
302 /* Devices with CG variant might be EG or CG family */
303 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : "eg", 2);
304 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EG) {
305 strncat(name, "eg", 2);
306 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_DR) {
307 strncat(name, "dr", 2);
308 } else {
309 debug("Variant not identified\n");
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530310 }
311
Michal Simekced4d462020-08-05 12:41:35 +0200312 return strdup(name);
Michal Simek47e60cb2016-02-01 15:05:58 +0100313}
314#endif
315
Michal Simek83d29412022-02-17 14:28:40 +0100316#if defined(CONFIG_BOARD_EARLY_INIT_F)
Michal Simekfb4000e2017-02-07 14:32:26 +0100317int board_early_init_f(void)
318{
Michal Simek88f05a92018-01-15 12:52:59 +0100319#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekc0adba52020-01-07 09:02:52 +0100320 int ret;
321
Michal Simekf32e79f2018-01-10 11:48:48 +0100322 ret = psu_init();
Michal Simekc0adba52020-01-07 09:02:52 +0100323 if (ret)
324 return ret;
Michal Simekf8451f12020-03-20 08:59:02 +0100325
Adrian Fiergolski3414712b2021-06-08 12:37:23 +0200326 /*
327 * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon
328 * supply sense channel to SysMon supply registers inside the IP.
329 * This register must be programmed to complete SysMon IP
330 * configuration. The default register configuration after
331 * power-up is incorrect. Hence, fix this by writing the
332 * correct value - 0x3210.
333 */
334 writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL,
335 ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS);
336
Michal Simekf8451f12020-03-20 08:59:02 +0100337 /* Delay is required for clocks to be propagated */
338 udelay(1000000);
Michal Simek55de0922017-07-12 13:08:41 +0200339#endif
340
Michal Simekc0adba52020-01-07 09:02:52 +0100341#ifdef CONFIG_DEBUG_UART
342 /* Uart debug for sure */
343 debug_uart_init();
344 puts("Debug uart enabled\n"); /* or printch() */
345#endif
346
347 return 0;
Michal Simekfb4000e2017-02-07 14:32:26 +0100348}
Michal Simek83d29412022-02-17 14:28:40 +0100349#endif
Michal Simekfb4000e2017-02-07 14:32:26 +0100350
Michal Simekc5143012020-02-11 12:43:14 +0100351static int multi_boot(void)
352{
Michal Simek3d238432021-07-27 16:17:31 +0200353 u32 multiboot = 0;
354 int ret;
Michal Simekc5143012020-02-11 12:43:14 +0100355
Michal Simek3d238432021-07-27 16:17:31 +0200356 ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot);
357 if (ret)
358 return -EINVAL;
Michal Simekc5143012020-02-11 12:43:14 +0100359
Michal Simeke49f2a72021-07-27 14:05:27 +0200360 return multiboot;
Michal Simekc5143012020-02-11 12:43:14 +0100361}
362
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200363#if defined(CONFIG_SPL_BUILD)
364static void restore_jtag(void)
365{
366 if (current_el() != 3)
367 return;
368
369 writel(CSU_JTAG_SEC_GATE_DISABLE, &csu_base->jtag_sec);
370 writel(CSU_JTAG_DAP_ENABLE_DEBUG, &csu_base->jtag_dap_cfg);
371 writel(CSU_JTAG_CHAIN_WR_SETUP, &csu_base->jtag_chain_status_wr);
372 writel(CRLAPB_DBG_LPD_CTRL_SETUP_CLK, &crlapb_base->dbg_lpd_ctrl);
373 writel(CRLAPB_RST_LPD_DBG_RESET, &crlapb_base->rst_lpd_dbg);
374 writel(CSU_PCAP_PROG_RELEASE_PL, &csu_base->pcap_prog);
375}
376#endif
377
Jorge Ramirez-Ortiz25a91f32021-10-13 19:04:47 +0200378static void print_secure_boot(void)
379{
380 u32 status = 0;
381
382 if (zynqmp_mmio_read((ulong)&csu_base->status, &status))
383 return;
384
385 printf("Secure Boot:\t%sauthenticated, %sencrypted\n",
386 status & ZYNQMP_CSU_STATUS_AUTHENTICATED ? "" : "not ",
387 status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
388}
389
Mike Looijmansdfbe4922019-10-18 07:34:13 +0200390#define PS_SYSMON_ANALOG_BUS_VAL 0x3210
391#define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914
392
Michal Simek84c72042015-01-15 10:01:51 +0100393int board_init(void)
394{
Michal Simek66ef85d2020-03-04 08:48:16 +0100395#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100396 struct udevice *dev;
397
398 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
399 if (!dev)
400 panic("PMU Firmware device not found - Enable it");
Michal Simek66ef85d2020-03-04 08:48:16 +0100401#endif
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100402
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200403#if defined(CONFIG_SPL_BUILD)
404 /* Check *at build time* if the filename is an non-empty string */
405 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
406 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
407 zynqmp_pm_cfg_obj_size);
Michal Simek98757d82021-02-02 16:34:48 +0100408 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200409
410 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti11c02552021-11-04 16:28:02 -0300411 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz398a74a2021-10-13 15:48:00 +0200412 restore_jtag();
Michal Simekd61728c2020-08-03 13:01:45 +0200413#else
414 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
415 xilinx_read_eeprom();
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200416#endif
417
Michal Simeka0736ef2015-06-22 14:31:06 +0200418 printf("EL Level:\tEL%d\n", current_el());
419
Mike Looijmansdfbe4922019-10-18 07:34:13 +0200420 /* Bug in ROM sets wrong value in this register */
421 writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG);
422
Michal Simek29bd8ad2020-09-09 14:41:56 +0200423#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Ibai Erkiaga4b2ad7b2020-08-04 23:17:29 +0100424 zynqmppl.name = zynqmp_get_silicon_idcode_name();
425 printf("Chip ID:\t%s\n", zynqmppl.name);
426 fpga_init();
427 fpga_add(fpga_xilinx, &zynqmppl);
Michal Simek47e60cb2016-02-01 15:05:58 +0100428#endif
429
Jorge Ramirez-Ortiz25a91f32021-10-13 19:04:47 +0200430 /* display secure boot information */
431 print_secure_boot();
Michal Simekc5143012020-02-11 12:43:14 +0100432 if (current_el() == 3)
Michal Simeke49f2a72021-07-27 14:05:27 +0200433 printf("Multiboot:\t%d\n", multi_boot());
Michal Simekc5143012020-02-11 12:43:14 +0100434
Michal Simek84c72042015-01-15 10:01:51 +0100435 return 0;
436}
437
438int board_early_init_r(void)
439{
440 u32 val;
441
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530442 if (current_el() != 3)
443 return 0;
444
Michal Simek90a35db2017-07-12 10:32:18 +0200445 val = readl(&crlapb_base->timestamp_ref_ctrl);
446 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
447
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530448 if (!val) {
Michal Simek0785dfd2015-11-05 08:34:35 +0100449 val = readl(&crlapb_base->timestamp_ref_ctrl);
450 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
451 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek84c72042015-01-15 10:01:51 +0100452
Michal Simek0785dfd2015-11-05 08:34:35 +0100453 /* Program freq register in System counter */
454 writel(zynqmp_get_system_timer_freq(),
455 &iou_scntr_secure->base_frequency_id_register);
456 /* And enable system counter */
457 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
458 &iou_scntr_secure->counter_control_register);
459 }
Michal Simek84c72042015-01-15 10:01:51 +0100460 return 0;
461}
462
Nitin Jain51916862018-02-16 12:56:17 +0530463unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glass09140112020-05-10 11:40:03 -0600464 char *const argv[])
Nitin Jain51916862018-02-16 12:56:17 +0530465{
466 int ret = 0;
467
468 if (current_el() > 1) {
469 smp_kick_all_cpus();
470 dcache_disable();
471 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
472 ES_TO_AARCH64);
473 } else {
474 printf("FAIL: current EL is not above EL1\n");
475 ret = EINVAL;
476 }
477 return ret;
478}
479
Michal Simek8d59d7f2016-02-08 09:34:53 +0100480#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -0600481int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -0500482{
Nitin Jain06789412018-04-20 12:30:40 +0530483 int ret;
484
485 ret = fdtdec_setup_memory_banksize();
486 if (ret)
487 return ret;
488
489 mem_map_fill();
490
491 return 0;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100492}
493
494int dram_init(void)
495{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530496 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi950f86c2016-12-19 00:03:34 +1000497 return -EINVAL;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100498
499 return 0;
500}
Michal Simekce39ee22021-05-31 11:03:19 +0200501
502ulong board_get_usable_ram_top(ulong total_size)
503{
504 phys_size_t size;
505 phys_addr_t reg;
506 struct lmb lmb;
507
Michal Simek5bd5ee02021-08-19 11:07:59 +0200508 if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8))
509 panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob);
510
Michal Simekce39ee22021-05-31 11:03:19 +0200511 /* found enough not-reserved memory to relocated U-Boot */
512 lmb_init(&lmb);
513 lmb_add(&lmb, gd->ram_base, gd->ram_size);
514 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
Michal Simek412ab132021-10-21 08:58:50 +0200515 size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
Michal Simekce39ee22021-05-31 11:03:19 +0200516 reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
517
518 if (!reg)
519 reg = gd->ram_top - size;
520
521 return reg + size;
522}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100523#else
Nitin Jain06789412018-04-20 12:30:40 +0530524int dram_init_banksize(void)
525{
Nitin Jain06789412018-04-20 12:30:40 +0530526 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
527 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain06789412018-04-20 12:30:40 +0530528
529 mem_map_fill();
530
531 return 0;
532}
533
Michal Simek84c72042015-01-15 10:01:51 +0100534int dram_init(void)
535{
Michal Simek61dc92a2018-04-11 16:12:28 +0200536 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
537 CONFIG_SYS_SDRAM_SIZE);
Michal Simek84c72042015-01-15 10:01:51 +0100538
539 return 0;
540}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100541#endif
Michal Simek84c72042015-01-15 10:01:51 +0100542
Michal Simekf1bc2142021-07-13 16:39:26 +0200543#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler35b65dd2020-12-15 16:47:52 +0100544void reset_cpu(void)
Michal Simek84c72042015-01-15 10:01:51 +0100545{
546}
Michal Simekf1bc2142021-07-13 16:39:26 +0200547#endif
Michal Simek84c72042015-01-15 10:01:51 +0100548
Michal Simek4d9bc792020-08-20 10:54:45 +0200549static u8 __maybe_unused zynqmp_get_bootmode(void)
550{
551 u8 bootmode;
552 u32 reg = 0;
553 int ret;
554
555 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
556 if (ret)
557 return -EINVAL;
558
Michal Simekafb08a82021-07-28 12:25:49 +0200559 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
560 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
561
Michal Simek4d9bc792020-08-20 10:54:45 +0200562 if (reg >> BOOT_MODE_ALT_SHIFT)
563 reg >>= BOOT_MODE_ALT_SHIFT;
564
565 bootmode = reg & BOOT_MODES_MASK;
566
567 return bootmode;
568}
569
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100570#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simekd348bea2018-05-17 14:06:06 +0200571static const struct {
572 u32 bit;
573 const char *name;
574} reset_reasons[] = {
575 { RESET_REASON_DEBUG_SYS, "DEBUG" },
576 { RESET_REASON_SOFT, "SOFT" },
577 { RESET_REASON_SRST, "SRST" },
578 { RESET_REASON_PSONLY, "PS-ONLY" },
579 { RESET_REASON_PMU, "PMU" },
580 { RESET_REASON_INTERNAL, "INTERNAL" },
581 { RESET_REASON_EXTERNAL, "EXTERNAL" },
582 {}
583};
584
T Karthik Reddybe523722019-03-13 20:24:18 +0530585static int reset_reason(void)
Michal Simekd348bea2018-05-17 14:06:06 +0200586{
T Karthik Reddybe523722019-03-13 20:24:18 +0530587 u32 reg;
588 int i, ret;
Michal Simekd348bea2018-05-17 14:06:06 +0200589 const char *reason = NULL;
590
T Karthik Reddybe523722019-03-13 20:24:18 +0530591 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
592 if (ret)
593 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200594
595 puts("Reset reason:\t");
596
597 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddybe523722019-03-13 20:24:18 +0530598 if (reg & reset_reasons[i].bit) {
Michal Simekd348bea2018-05-17 14:06:06 +0200599 reason = reset_reasons[i].name;
600 printf("%s ", reset_reasons[i].name);
601 break;
602 }
603 }
604
605 puts("\n");
606
607 env_set("reset_reason", reason);
608
Michal Simek3aba25b2021-02-09 08:50:22 +0100609 return 0;
Michal Simekd348bea2018-05-17 14:06:06 +0200610}
611
Michal Simek91d7e0c2019-02-14 13:14:30 +0100612static int set_fdtfile(void)
613{
614 char *compatible, *fdtfile;
615 const char *suffix = ".dtb";
616 const char *vendor = "xilinx/";
Igor Lantsman1b208d52020-06-24 14:33:46 +0200617 int fdt_compat_len;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100618
619 if (env_get("fdtfile"))
620 return 0;
621
Igor Lantsman1b208d52020-06-24 14:33:46 +0200622 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
623 &fdt_compat_len);
624 if (compatible && fdt_compat_len) {
625 char *name;
626
Michal Simek91d7e0c2019-02-14 13:14:30 +0100627 debug("Compatible: %s\n", compatible);
628
Igor Lantsman1b208d52020-06-24 14:33:46 +0200629 name = strchr(compatible, ',');
630 if (!name)
631 return -EINVAL;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100632
Igor Lantsman1b208d52020-06-24 14:33:46 +0200633 name++;
634
635 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek91d7e0c2019-02-14 13:14:30 +0100636 strlen(suffix) + 1);
637 if (!fdtfile)
638 return -ENOMEM;
639
Igor Lantsman1b208d52020-06-24 14:33:46 +0200640 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek91d7e0c2019-02-14 13:14:30 +0100641
642 env_set("fdtfile", fdtfile);
643 free(fdtfile);
644 }
645
646 return 0;
647}
648
Michal Simek84c72042015-01-15 10:01:51 +0100649int board_late_init(void)
650{
Michal Simek84c72042015-01-15 10:01:51 +0100651 u8 bootmode;
Michal Simek2882b392018-04-25 11:20:43 +0200652 struct udevice *dev;
653 int bootseq = -1;
654 int bootseq_len = 0;
Michal Simek0478b0b2018-04-25 11:10:34 +0200655 int env_targets_len = 0;
Michal Simekb72894f2016-04-22 14:28:54 +0200656 const char *mode;
657 char *new_targets;
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530658 char *env_targets;
Michal Simeke8b43c62021-10-25 10:10:52 +0200659 int ret, multiboot;
Michal Simekb72894f2016-04-22 14:28:54 +0200660
Michal Simeke615f392018-10-05 08:55:16 +0200661#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
662 usb_ether_init();
663#endif
664
Michal Simekb72894f2016-04-22 14:28:54 +0200665 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
666 debug("Saved variables - Skipping\n");
667 return 0;
668 }
Michal Simek84c72042015-01-15 10:01:51 +0100669
Michal Simek62b96262020-07-28 12:45:47 +0200670 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
671 return 0;
672
Michal Simek91d7e0c2019-02-14 13:14:30 +0100673 ret = set_fdtfile();
674 if (ret)
675 return ret;
676
Michal Simeke8b43c62021-10-25 10:10:52 +0200677 multiboot = multi_boot();
678 if (multiboot >= 0)
679 env_set_hex("multiboot", multiboot);
680
Michal Simek51f6c522020-04-08 11:04:41 +0200681 bootmode = zynqmp_get_bootmode();
Michal Simek84c72042015-01-15 10:01:51 +0100682
Michal Simekfb909172015-09-20 17:20:42 +0200683 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100684 switch (bootmode) {
Michal Simekd58fc122016-08-19 14:14:52 +0200685 case USB_MODE:
686 puts("USB_MODE\n");
T Karthik Reddyef1be3e2021-03-24 23:37:57 -0600687 mode = "usb_dfu0 usb_dfu1";
Michal Simek07656ba2017-12-01 15:18:24 +0100688 env_set("modeboot", "usb_dfu_spl");
Michal Simekd58fc122016-08-19 14:14:52 +0200689 break;
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530690 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200691 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu5d2274c2019-06-25 17:41:09 +0530692 mode = "jtag pxe dhcp";
Michal Simek07656ba2017-12-01 15:18:24 +0100693 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530694 break;
695 case QSPI_MODE_24BIT:
696 case QSPI_MODE_32BIT:
Michal Simekb72894f2016-04-22 14:28:54 +0200697 mode = "qspi0";
Michal Simekfb909172015-09-20 17:20:42 +0200698 puts("QSPI_MODE\n");
Michal Simek07656ba2017-12-01 15:18:24 +0100699 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530700 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200701 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200702 puts("EMMC_MODE\n");
T Karthik Reddy18be60b2019-12-17 06:41:42 -0700703 if (uclass_get_device_by_name(UCLASS_MMC,
704 "mmc@ff160000", &dev) &&
705 uclass_get_device_by_name(UCLASS_MMC,
706 "sdhci@ff160000", &dev)) {
707 puts("Boot from EMMC but without SD0 enabled!\n");
708 return -1;
709 }
Simon Glass8b85dfc2020-12-16 21:20:07 -0700710 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy18be60b2019-12-17 06:41:42 -0700711
712 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700713 bootseq = dev_seq(dev);
Ashok Reddy Soma5d498a12021-09-15 08:52:17 +0200714 env_set("modeboot", "emmcboot");
Michal Simek78678fe2015-10-05 15:59:38 +0200715 break;
716 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200717 puts("SD_MODE\n");
Michal Simek2882b392018-04-25 11:20:43 +0200718 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530719 "mmc@ff160000", &dev) &&
720 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200721 "sdhci@ff160000", &dev)) {
722 puts("Boot from SD0 but without SD0 enabled!\n");
723 return -1;
724 }
Simon Glass8b85dfc2020-12-16 21:20:07 -0700725 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simek2882b392018-04-25 11:20:43 +0200726
727 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700728 bootseq = dev_seq(dev);
Michal Simek07656ba2017-12-01 15:18:24 +0100729 env_set("modeboot", "sdboot");
Michal Simek84c72042015-01-15 10:01:51 +0100730 break;
Siva Durga Prasad Paladugue1992272016-09-21 11:45:05 +0530731 case SD1_LSHFT_MODE:
732 puts("LVL_SHFT_");
Michal Simekf5109272021-10-18 13:30:04 +0200733 fallthrough;
Michal Simekaf813ac2015-10-05 10:51:12 +0200734 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200735 puts("SD_MODE1\n");
Michal Simek2882b392018-04-25 11:20:43 +0200736 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530737 "mmc@ff170000", &dev) &&
738 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200739 "sdhci@ff170000", &dev)) {
740 puts("Boot from SD1 but without SD1 enabled!\n");
741 return -1;
742 }
Simon Glass8b85dfc2020-12-16 21:20:07 -0700743 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simek2882b392018-04-25 11:20:43 +0200744
745 mode = "mmc";
Simon Glass8b85dfc2020-12-16 21:20:07 -0700746 bootseq = dev_seq(dev);
Michal Simek07656ba2017-12-01 15:18:24 +0100747 env_set("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200748 break;
749 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200750 puts("NAND_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200751 mode = "nand0";
Michal Simek07656ba2017-12-01 15:18:24 +0100752 env_set("modeboot", "nandboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200753 break;
Michal Simek84c72042015-01-15 10:01:51 +0100754 default:
Michal Simekb72894f2016-04-22 14:28:54 +0200755 mode = "";
Michal Simek84c72042015-01-15 10:01:51 +0100756 printf("Invalid Boot Mode:0x%x\n", bootmode);
757 break;
758 }
759
Michal Simek2882b392018-04-25 11:20:43 +0200760 if (bootseq >= 0) {
761 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
762 debug("Bootseq len: %x\n", bootseq_len);
Michal Simek2784bef2021-01-11 13:46:58 +0100763 env_set_hex("bootseq", bootseq);
Michal Simek2882b392018-04-25 11:20:43 +0200764 }
765
Michal Simekb72894f2016-04-22 14:28:54 +0200766 /*
767 * One terminating char + one byte for space between mode
768 * and default boot_targets
769 */
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530770 env_targets = env_get("boot_targets");
Michal Simek0478b0b2018-04-25 11:10:34 +0200771 if (env_targets)
772 env_targets_len = strlen(env_targets);
773
Michal Simek2882b392018-04-25 11:20:43 +0200774 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
775 bootseq_len);
Michal Simek1e3e68f2018-06-13 09:42:41 +0200776 if (!new_targets)
777 return -ENOMEM;
Michal Simek0478b0b2018-04-25 11:10:34 +0200778
Michal Simek2882b392018-04-25 11:20:43 +0200779 if (bootseq >= 0)
780 sprintf(new_targets, "%s%x %s", mode, bootseq,
781 env_targets ? env_targets : "");
782 else
783 sprintf(new_targets, "%s %s", mode,
784 env_targets ? env_targets : "");
Michal Simekb72894f2016-04-22 14:28:54 +0200785
Simon Glass382bee52017-08-03 12:22:09 -0600786 env_set("boot_targets", new_targets);
Michal Simekf83cfaa2021-07-28 12:46:39 +0200787 free(new_targets);
Michal Simekb72894f2016-04-22 14:28:54 +0200788
Michal Simekd348bea2018-05-17 14:06:06 +0200789 reset_reason();
790
Michal Simek80fdef12020-03-31 12:39:37 +0200791 return board_late_init_xilinx();
Michal Simek84c72042015-01-15 10:01:51 +0100792}
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100793#endif
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530794
795int checkboard(void)
796{
Michal Simek5af08552016-01-25 11:04:21 +0100797 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530798 return 0;
799}
Michal Simek1025bd02020-07-30 13:37:49 +0200800
Michal Simek476588c2021-05-19 15:16:19 +0200801int mmc_get_env_dev(void)
802{
803 struct udevice *dev;
804 int bootseq = 0;
805
806 switch (zynqmp_get_bootmode()) {
807 case EMMC_MODE:
808 case SD_MODE:
809 if (uclass_get_device_by_name(UCLASS_MMC,
810 "mmc@ff160000", &dev) &&
811 uclass_get_device_by_name(UCLASS_MMC,
812 "sdhci@ff160000", &dev)) {
813 return -1;
814 }
815 bootseq = dev_seq(dev);
816 break;
817 case SD1_LSHFT_MODE:
818 case SD_MODE1:
819 if (uclass_get_device_by_name(UCLASS_MMC,
820 "mmc@ff170000", &dev) &&
821 uclass_get_device_by_name(UCLASS_MMC,
822 "sdhci@ff170000", &dev)) {
823 return -1;
824 }
825 bootseq = dev_seq(dev);
826 break;
827 default:
828 break;
829 }
830
831 debug("bootseq %d\n", bootseq);
832
833 return bootseq;
834}
835
Michal Simek1025bd02020-07-30 13:37:49 +0200836enum env_location env_get_location(enum env_operation op, int prio)
837{
838 u32 bootmode = zynqmp_get_bootmode();
839
840 if (prio)
841 return ENVL_UNKNOWN;
842
843 switch (bootmode) {
844 case EMMC_MODE:
845 case SD_MODE:
846 case SD1_LSHFT_MODE:
847 case SD_MODE1:
848 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
849 return ENVL_FAT;
850 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
851 return ENVL_EXT4;
Mike Looijmans50918d02021-07-02 10:28:36 +0200852 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200853 case NAND_MODE:
854 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
855 return ENVL_NAND;
856 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
857 return ENVL_UBI;
Mike Looijmans50918d02021-07-02 10:28:36 +0200858 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200859 case QSPI_MODE_24BIT:
860 case QSPI_MODE_32BIT:
861 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
862 return ENVL_SPI_FLASH;
Mike Looijmans50918d02021-07-02 10:28:36 +0200863 return ENVL_NOWHERE;
Michal Simek1025bd02020-07-30 13:37:49 +0200864 case JTAG_MODE:
865 default:
866 return ENVL_NOWHERE;
867 }
868}
Michal Simekb86f43d2021-07-27 16:19:18 +0200869
870#if defined(CONFIG_SET_DFU_ALT_INFO)
871
872#define DFU_ALT_BUF_LEN SZ_1K
873
874void set_dfu_alt_info(char *interface, char *devstr)
875{
876 u8 multiboot;
877 int bootseq = 0;
878
879 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
880
881 if (env_get("dfu_alt_info"))
882 return;
883
884 memset(buf, 0, sizeof(buf));
885
886 multiboot = multi_boot();
Michal Simeke8b43c62021-10-25 10:10:52 +0200887 if (multiboot < 0)
888 multiboot = 0;
889
890 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekb86f43d2021-07-27 16:19:18 +0200891 debug("Multiboot: %d\n", multiboot);
892
893 switch (zynqmp_get_bootmode()) {
894 case EMMC_MODE:
895 case SD_MODE:
896 case SD1_LSHFT_MODE:
897 case SD_MODE1:
898 bootseq = mmc_get_env_dev();
899 if (!multiboot)
900 snprintf(buf, DFU_ALT_BUF_LEN,
901 "mmc %d:1=boot.bin fat %d 1;"
Michal Simek60705882021-10-18 14:02:15 +0200902 "%s fat %d 1",
903 bootseq, bootseq,
904 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekb86f43d2021-07-27 16:19:18 +0200905 else
906 snprintf(buf, DFU_ALT_BUF_LEN,
907 "mmc %d:1=boot%04d.bin fat %d 1;"
Michal Simek60705882021-10-18 14:02:15 +0200908 "%s fat %d 1",
909 bootseq, multiboot, bootseq,
910 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekb86f43d2021-07-27 16:19:18 +0200911 break;
912 case QSPI_MODE_24BIT:
913 case QSPI_MODE_32BIT:
914 snprintf(buf, DFU_ALT_BUF_LEN,
915 "sf 0:0=boot.bin raw %x 0x1500000;"
Michal Simek60705882021-10-18 14:02:15 +0200916 "%s raw 0x%x 0x500000",
917 multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
918 CONFIG_SYS_SPI_U_BOOT_OFFS);
Michal Simekb86f43d2021-07-27 16:19:18 +0200919 break;
920 default:
921 return;
922 }
923
924 env_set("dfu_alt_info", buf);
925 puts("DFU alt info setting: done\n");
926}
927#endif