blob: 41ecc9559c4b693d92211a3f3f343d8ece291dcf [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek04b7e622015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek04b7e622015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simek09a7d7d2020-01-07 09:02:52 +010010#include <debug_uart.h>
Michal Simekcfb37602021-07-27 16:19:18 +020011#include <dfu.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Michal Simek8d4a8d42020-07-30 13:37:49 +020013#include <env_internal.h>
Simon Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Michal Simek97ab9612021-05-31 11:03:19 +020015#include <image.h>
16#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020019#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020020#include <ahci.h>
21#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020022#include <malloc.h>
Michal Simekcfb37602021-07-27 16:19:18 +020023#include <memalign.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020024#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010025#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010026#include <asm/arch/hardware.h>
27#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010028#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060029#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060030#include <asm/global_data.h>
Michal Simek04b7e622015-01-15 10:01:51 +010031#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060032#include <asm/ptrace.h>
Michal Simekf183a982018-04-25 11:20:43 +020033#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020034#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053035#include <usb.h>
36#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010037#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010038#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020039#include <g_dnl.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060040#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060041#include <linux/delay.h>
42#include <linux/sizes.h>
Michal Simek705d44a2020-03-31 12:39:37 +020043#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010044
Luca Ceresoli23e65002019-05-21 18:06:43 +020045#include "pm_cfg_obj.h"
46
Ibai Erkiaga4f736182020-08-04 23:17:31 +010047#define ZYNQMP_VERSION_SIZE 7
Michal Simekc702a742020-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 Erkiaga4f736182020-08-04 23:17:31 +010054
Michal Simek04b7e622015-01-15 10:01:51 +010055DECLARE_GLOBAL_DATA_PTR;
56
Michal Simek1aab1142020-09-09 14:41:56 +020057#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Michal Simek8111aff2016-02-01 15:05:58 +010058static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
59
Ibai Erkiaga4f736182020-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 Simek8111aff2016-02-01 15:05:58 +010067static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010068 u32 id;
Ibai Erkiaga4f736182020-08-04 23:17:31 +010069 u8 device;
70 u8 variants;
Michal Simek8111aff2016-02-01 15:05:58 +010071} zynqmp_devices[] = {
72 {
Michal Simek40f56ad2022-03-30 07:51:58 +020073 .id = 0x04688093,
74 .device = 1,
75 .variants = ZYNQMP_VARIANT_EG,
76 },
77 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010078 .id = 0x04711093,
79 .device = 2,
80 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek50d8cef2017-08-22 14:58:53 +020081 },
82 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010083 .id = 0x04710093,
84 .device = 3,
85 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek8111aff2016-02-01 15:05:58 +010086 },
87 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010088 .id = 0x04721093,
89 .device = 4,
90 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
91 ZYNQMP_VARIANT_EV,
Michal Simek50d8cef2017-08-22 14:58:53 +020092 },
93 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010094 .id = 0x04720093,
95 .device = 5,
96 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
97 ZYNQMP_VARIANT_EV,
Michal Simek50d8cef2017-08-22 14:58:53 +020098 },
99 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100100 .id = 0x04739093,
101 .device = 6,
102 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek8111aff2016-02-01 15:05:58 +0100103 },
104 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100105 .id = 0x04730093,
106 .device = 7,
107 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
108 ZYNQMP_VARIANT_EV,
Michal Simek50d8cef2017-08-22 14:58:53 +0200109 },
110 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100111 .id = 0x04738093,
112 .device = 9,
Michal Simek3626f2c2020-10-02 14:42:05 +0200113 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek50d8cef2017-08-22 14:58:53 +0200114 },
115 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100116 .id = 0x04740093,
117 .device = 11,
118 .variants = ZYNQMP_VARIANT_EG,
Michal Simek8111aff2016-02-01 15:05:58 +0100119 },
120 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100121 .id = 0x04750093,
122 .device = 15,
123 .variants = ZYNQMP_VARIANT_EG,
Michal Simek50d8cef2017-08-22 14:58:53 +0200124 },
125 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100126 .id = 0x04759093,
127 .device = 17,
128 .variants = ZYNQMP_VARIANT_EG,
Michal Simek50d8cef2017-08-22 14:58:53 +0200129 },
130 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100131 .id = 0x04758093,
132 .device = 19,
133 .variants = ZYNQMP_VARIANT_EG,
Michal Simek8111aff2016-02-01 15:05:58 +0100134 },
135 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100136 .id = 0x047E1093,
137 .device = 21,
138 .variants = ZYNQMP_VARIANT_DR,
Michal Simek50d8cef2017-08-22 14:58:53 +0200139 },
140 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100141 .id = 0x047E3093,
142 .device = 23,
143 .variants = ZYNQMP_VARIANT_DR,
Michal Simek8111aff2016-02-01 15:05:58 +0100144 },
145 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100146 .id = 0x047E5093,
147 .device = 25,
148 .variants = ZYNQMP_VARIANT_DR,
Michal Simek50d8cef2017-08-22 14:58:53 +0200149 },
150 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100151 .id = 0x047E4093,
152 .device = 27,
153 .variants = ZYNQMP_VARIANT_DR,
Michal Simek8111aff2016-02-01 15:05:58 +0100154 },
155 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100156 .id = 0x047E0093,
157 .device = 28,
158 .variants = ZYNQMP_VARIANT_DR,
Michal Simek8111aff2016-02-01 15:05:58 +0100159 },
160 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100161 .id = 0x047E2093,
162 .device = 29,
163 .variants = ZYNQMP_VARIANT_DR,
Michal Simek8111aff2016-02-01 15:05:58 +0100164 },
Michal Simekb510e532017-06-02 08:08:59 +0200165 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100166 .id = 0x047E6093,
167 .device = 39,
168 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200169 },
170 {
Michal Simek3fd2ed32020-09-11 09:22:15 +0200171 .id = 0x047FD093,
172 .device = 43,
173 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200174 },
175 {
Michal Simek3fd2ed32020-09-11 09:22:15 +0200176 .id = 0x047F8093,
177 .device = 46,
178 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200179 },
180 {
Michal Simek3fd2ed32020-09-11 09:22:15 +0200181 .id = 0x047FF093,
182 .device = 47,
183 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200184 },
185 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100186 .id = 0x047FB093,
187 .device = 48,
188 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200189 },
190 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100191 .id = 0x047FE093,
192 .device = 49,
193 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530194 },
T Karthik Reddy83df2cb2021-05-13 07:13:25 -0600195 {
196 .id = 0x046d0093,
197 .device = 67,
198 .variants = ZYNQMP_VARIANT_DR,
199 },
Michal Simek8111aff2016-02-01 15:05:58 +0100200};
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530201
Michal Simek005cac02020-10-05 09:35:40 +0200202static const struct {
203 u32 id;
204 char *name;
205} zynqmp_svd_devices[] = {
206 {
207 .id = 0x04714093,
208 .name = "xck24"
209 },
210 {
211 .id = 0x04724093,
212 .name = "xck26",
213 },
214};
215
216static char *zynqmp_detect_svd_name(u32 idcode)
217{
218 u32 i;
219
220 for (i = 0; i < ARRAY_SIZE(zynqmp_svd_devices); i++) {
221 if (zynqmp_svd_devices[i].id == (idcode & 0x0FFFFFFF))
222 return zynqmp_svd_devices[i].name;
223 }
224
225 return "unknown";
226}
227
Michal Simek8111aff2016-02-01 15:05:58 +0100228static char *zynqmp_get_silicon_idcode_name(void)
229{
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100230 u32 i;
231 u32 idcode, idcode2;
Michal Simek051b8bc2020-08-05 12:41:35 +0200232 char name[ZYNQMP_VERSION_SIZE];
Ibai Erkiagac318ecb2020-08-04 23:17:30 +0100233 u32 ret_payload[PAYLOAD_ARG_CNT];
Michal Simekb5c3b0d2020-10-07 15:13:17 +0200234 int ret;
Ibai Erkiagac318ecb2020-08-04 23:17:30 +0100235
Michal Simek23c0def2020-10-21 12:16:02 +0200236 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
237 if (ret) {
238 debug("%s: Getting chipid failed\n", __func__);
239 return "unknown";
240 }
Ibai Erkiagac318ecb2020-08-04 23:17:30 +0100241
242 /*
243 * Firmware returns:
244 * payload[0][31:0] = status of the operation
245 * payload[1]] = IDCODE
246 * payload[2][19:0] = Version
247 * payload[2][28:20] = EXTENDED_IDCODE
248 * payload[2][29] = PL_INIT
249 */
250
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100251 idcode = ret_payload[1];
252 idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
Michal Simekc76c96f2020-10-21 12:16:50 +0200253 debug("%s, IDCODE: 0x%0x, IDCODE2: 0x%0x\r\n", __func__, idcode,
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100254 idcode2);
Michal Simek50d8cef2017-08-22 14:58:53 +0200255
Michal Simek8111aff2016-02-01 15:05:58 +0100256 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100257 if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF))
258 break;
Michal Simek8111aff2016-02-01 15:05:58 +0100259 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530260
261 if (i >= ARRAY_SIZE(zynqmp_devices))
Michal Simek005cac02020-10-05 09:35:40 +0200262 return zynqmp_detect_svd_name(idcode);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530263
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100264 /* Add device prefix to the name */
Michal Simekb5c3b0d2020-10-07 15:13:17 +0200265 ret = snprintf(name, ZYNQMP_VERSION_SIZE, "zu%d",
266 zynqmp_devices[i].device);
Michal Simekd2281672020-10-21 12:17:44 +0200267 if (ret < 0)
Michal Simekb5c3b0d2020-10-07 15:13:17 +0200268 return "unknown";
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530269
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100270 if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
271 /* Devices with EV variant might be EG/CG/EV family */
272 if (idcode2 & IDCODE2_PL_INIT_MASK) {
273 u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >>
274 EFUSE_VCU_DIS_SHIFT) << 1 |
275 ((idcode2 & EFUSE_GPU_DIS_MASK) >>
276 EFUSE_GPU_DIS_SHIFT);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530277
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100278 /*
279 * Get family name based on extended idcode values as
280 * determined on UG1087, EXTENDED_IDCODE register
281 * description
282 */
283 switch (family) {
284 case 0x00:
285 strncat(name, "ev", 2);
286 break;
287 case 0x10:
288 strncat(name, "eg", 2);
289 break;
290 case 0x11:
291 strncat(name, "cg", 2);
292 break;
293 default:
294 /* Do not append family name*/
295 break;
296 }
297 } else {
298 /*
299 * When PL powered down the VCU Disable efuse cannot be
300 * read. So, ignore the bit and just findout if it is CG
301 * or EG/EV variant.
302 */
303 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" :
304 "e", 2);
305 }
306 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_CG) {
307 /* Devices with CG variant might be EG or CG family */
308 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : "eg", 2);
309 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EG) {
310 strncat(name, "eg", 2);
311 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_DR) {
312 strncat(name, "dr", 2);
313 } else {
314 debug("Variant not identified\n");
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530315 }
316
Michal Simek051b8bc2020-08-05 12:41:35 +0200317 return strdup(name);
Michal Simek8111aff2016-02-01 15:05:58 +0100318}
319#endif
320
Michal Simeke5710e32022-02-17 14:28:42 +0100321int __maybe_unused psu_uboot_init(void)
Michal Simek8b353302017-02-07 14:32:26 +0100322{
Michal Simek09a7d7d2020-01-07 09:02:52 +0100323 int ret;
324
Michal Simekc8785f22018-01-10 11:48:48 +0100325 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +0100326 if (ret)
327 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +0100328
Adrian Fiergolski8e87ecf2021-06-08 12:37:23 +0200329 /*
330 * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon
331 * supply sense channel to SysMon supply registers inside the IP.
332 * This register must be programmed to complete SysMon IP
333 * configuration. The default register configuration after
334 * power-up is incorrect. Hence, fix this by writing the
335 * correct value - 0x3210.
336 */
337 writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL,
338 ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS);
339
Michal Simek1f55e572020-03-20 08:59:02 +0100340 /* Delay is required for clocks to be propagated */
341 udelay(1000000);
Michal Simeke5710e32022-02-17 14:28:42 +0100342
343 return 0;
344}
Michal Simeke0f36102017-07-12 13:08:41 +0200345
Michal Simeke5710e32022-02-17 14:28:42 +0100346#if !defined(CONFIG_SPL_BUILD)
347# if defined(CONFIG_DEBUG_UART_BOARD_INIT)
348void board_debug_uart_init(void)
349{
350# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
351 psu_uboot_init();
352# endif
353}
354# endif
Michal Simek09a7d7d2020-01-07 09:02:52 +0100355
Michal Simeke5710e32022-02-17 14:28:42 +0100356# if defined(CONFIG_BOARD_EARLY_INIT_F)
357int board_early_init_f(void)
358{
359 int ret = 0;
360# if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) && !defined(CONFIG_DEBUG_UART_BOARD_INIT)
361 ret = psu_uboot_init();
362# endif
363 return ret;
Michal Simek8b353302017-02-07 14:32:26 +0100364}
Michal Simeke5710e32022-02-17 14:28:42 +0100365# endif
Michal Simekba6fb832022-02-17 14:28:40 +0100366#endif
Michal Simek8b353302017-02-07 14:32:26 +0100367
Michal Simek46900462020-02-11 12:43:14 +0100368static int multi_boot(void)
369{
Michal Simek6aca2832021-07-27 16:17:31 +0200370 u32 multiboot = 0;
371 int ret;
Michal Simek46900462020-02-11 12:43:14 +0100372
Michal Simek6aca2832021-07-27 16:17:31 +0200373 ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot);
374 if (ret)
375 return -EINVAL;
Michal Simek46900462020-02-11 12:43:14 +0100376
Michal Simek21e5c322021-07-27 14:05:27 +0200377 return multiboot;
Michal Simek46900462020-02-11 12:43:14 +0100378}
379
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200380#if defined(CONFIG_SPL_BUILD)
381static void restore_jtag(void)
382{
383 if (current_el() != 3)
384 return;
385
386 writel(CSU_JTAG_SEC_GATE_DISABLE, &csu_base->jtag_sec);
387 writel(CSU_JTAG_DAP_ENABLE_DEBUG, &csu_base->jtag_dap_cfg);
388 writel(CSU_JTAG_CHAIN_WR_SETUP, &csu_base->jtag_chain_status_wr);
389 writel(CRLAPB_DBG_LPD_CTRL_SETUP_CLK, &crlapb_base->dbg_lpd_ctrl);
390 writel(CRLAPB_RST_LPD_DBG_RESET, &crlapb_base->rst_lpd_dbg);
391 writel(CSU_PCAP_PROG_RELEASE_PL, &csu_base->pcap_prog);
392}
393#endif
394
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200395static void print_secure_boot(void)
396{
397 u32 status = 0;
398
399 if (zynqmp_mmio_read((ulong)&csu_base->status, &status))
400 return;
401
402 printf("Secure Boot:\t%sauthenticated, %sencrypted\n",
403 status & ZYNQMP_CSU_STATUS_AUTHENTICATED ? "" : "not ",
404 status & ZYNQMP_CSU_STATUS_ENCRYPTED ? "" : "not ");
405}
406
Michal Simek04b7e622015-01-15 10:01:51 +0100407int board_init(void)
408{
Michal Simek826d7eca2020-03-04 08:48:16 +0100409#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100410 struct udevice *dev;
411
412 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
413 if (!dev)
414 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100415#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100416
Luca Ceresoli23e65002019-05-21 18:06:43 +0200417#if defined(CONFIG_SPL_BUILD)
418 /* Check *at build time* if the filename is an non-empty string */
419 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
420 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
421 zynqmp_pm_cfg_obj_size);
Michal Simekae9dc112021-02-02 16:34:48 +0100422 printf("Silicon version:\t%d\n", zynqmp_get_silicon_version());
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200423
424 /* the CSU disables the JTAG interface when secure boot is enabled */
Ricardo Salveti5b774f02021-11-04 16:28:02 -0300425 if (CONFIG_IS_ENABLED(ZYNQMP_RESTORE_JTAG))
Jorge Ramirez-Ortiz34deca52021-10-13 15:48:00 +0200426 restore_jtag();
Michal Simek394ee242020-08-03 13:01:45 +0200427#else
428 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
429 xilinx_read_eeprom();
Luca Ceresoli23e65002019-05-21 18:06:43 +0200430#endif
431
Michal Simekfb7242d2015-06-22 14:31:06 +0200432 printf("EL Level:\tEL%d\n", current_el());
433
Michal Simek1aab1142020-09-09 14:41:56 +0200434#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Ibai Erkiagae91ca7c2020-08-04 23:17:29 +0100435 zynqmppl.name = zynqmp_get_silicon_idcode_name();
436 printf("Chip ID:\t%s\n", zynqmppl.name);
437 fpga_init();
438 fpga_add(fpga_xilinx, &zynqmppl);
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200439#endif
440
Jorge Ramirez-Ortizb0e388a2021-10-13 19:04:47 +0200441 /* display secure boot information */
442 print_secure_boot();
Michal Simek46900462020-02-11 12:43:14 +0100443 if (current_el() == 3)
Michal Simek21e5c322021-07-27 14:05:27 +0200444 printf("Multiboot:\t%d\n", multi_boot());
Michal Simek46900462020-02-11 12:43:14 +0100445
Michal Simek04b7e622015-01-15 10:01:51 +0100446 return 0;
447}
448
449int board_early_init_r(void)
450{
451 u32 val;
452
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530453 if (current_el() != 3)
454 return 0;
455
Michal Simek245d5282017-07-12 10:32:18 +0200456 val = readl(&crlapb_base->timestamp_ref_ctrl);
457 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
458
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530459 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100460 val = readl(&crlapb_base->timestamp_ref_ctrl);
461 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
462 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100463
Michal Simekc23d3f82015-11-05 08:34:35 +0100464 /* Program freq register in System counter */
465 writel(zynqmp_get_system_timer_freq(),
466 &iou_scntr_secure->base_frequency_id_register);
467 /* And enable system counter */
468 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
469 &iou_scntr_secure->counter_control_register);
470 }
Michal Simek04b7e622015-01-15 10:01:51 +0100471 return 0;
472}
473
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530474unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600475 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530476{
477 int ret = 0;
478
479 if (current_el() > 1) {
480 smp_kick_all_cpus();
481 dcache_disable();
482 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
483 ES_TO_AARCH64);
484 } else {
485 printf("FAIL: current EL is not above EL1\n");
486 ret = EINVAL;
487 }
488 return ret;
489}
490
Michal Simek8faa66a2016-02-08 09:34:53 +0100491#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600492int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100493{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530494 int ret;
495
496 ret = fdtdec_setup_memory_banksize();
497 if (ret)
498 return ret;
499
500 mem_map_fill();
501
502 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500503}
Michal Simek8faa66a2016-02-08 09:34:53 +0100504
Tom Riniedcfdbd2016-12-09 07:56:54 -0500505int dram_init(void)
506{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530507 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000508 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500509
510 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100511}
Michal Simek97ab9612021-05-31 11:03:19 +0200512
513ulong board_get_usable_ram_top(ulong total_size)
514{
515 phys_size_t size;
516 phys_addr_t reg;
517 struct lmb lmb;
518
Michal Simekf14a4f22021-08-19 11:07:59 +0200519 if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8))
520 panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob);
521
Michal Simek97ab9612021-05-31 11:03:19 +0200522 /* found enough not-reserved memory to relocated U-Boot */
523 lmb_init(&lmb);
524 lmb_add(&lmb, gd->ram_base, gd->ram_size);
525 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
Michal Simek770264e2021-10-21 08:58:50 +0200526 size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
Michal Simek97ab9612021-05-31 11:03:19 +0200527 reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
528
529 if (!reg)
530 reg = gd->ram_top - size;
531
532 return reg + size;
533}
Michal Simek8faa66a2016-02-08 09:34:53 +0100534#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530535int dram_init_banksize(void)
536{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530537 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
538 gd->bd->bi_dram[0].size = get_effective_memsize();
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530539
540 mem_map_fill();
541
542 return 0;
543}
544
Michal Simek04b7e622015-01-15 10:01:51 +0100545int dram_init(void)
546{
Michal Simek1b846212018-04-11 16:12:28 +0200547 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
548 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100549
550 return 0;
551}
Michal Simek8faa66a2016-02-08 09:34:53 +0100552#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100553
Michal Simek2a220332021-07-13 16:39:26 +0200554#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100555void reset_cpu(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100556{
557}
Michal Simek2a220332021-07-13 16:39:26 +0200558#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100559
Michal Simek8ec30042020-08-20 10:54:45 +0200560static u8 __maybe_unused zynqmp_get_bootmode(void)
561{
562 u8 bootmode;
563 u32 reg = 0;
564 int ret;
565
566 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
567 if (ret)
568 return -EINVAL;
569
Michal Simek58cc08c2021-07-28 12:25:49 +0200570 debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK);
571 debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT);
572
Michal Simek8ec30042020-08-20 10:54:45 +0200573 if (reg >> BOOT_MODE_ALT_SHIFT)
574 reg >>= BOOT_MODE_ALT_SHIFT;
575
576 bootmode = reg & BOOT_MODES_MASK;
577
578 return bootmode;
579}
580
Michal Simek342edfe2018-12-20 09:33:38 +0100581#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200582static const struct {
583 u32 bit;
584 const char *name;
585} reset_reasons[] = {
586 { RESET_REASON_DEBUG_SYS, "DEBUG" },
587 { RESET_REASON_SOFT, "SOFT" },
588 { RESET_REASON_SRST, "SRST" },
589 { RESET_REASON_PSONLY, "PS-ONLY" },
590 { RESET_REASON_PMU, "PMU" },
591 { RESET_REASON_INTERNAL, "INTERNAL" },
592 { RESET_REASON_EXTERNAL, "EXTERNAL" },
593 {}
594};
595
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530596static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200597{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530598 u32 reg;
599 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200600 const char *reason = NULL;
601
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530602 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
603 if (ret)
604 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200605
606 puts("Reset reason:\t");
607
608 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530609 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200610 reason = reset_reasons[i].name;
611 printf("%s ", reset_reasons[i].name);
612 break;
613 }
614 }
615
616 puts("\n");
617
618 env_set("reset_reason", reason);
619
Michal Simek0954c8c2021-02-09 08:50:22 +0100620 return 0;
Michal Simek29b9b712018-05-17 14:06:06 +0200621}
622
Michal Simek1ca66d72019-02-14 13:14:30 +0100623static int set_fdtfile(void)
624{
625 char *compatible, *fdtfile;
626 const char *suffix = ".dtb";
627 const char *vendor = "xilinx/";
Igor Lantsmane167bac2020-06-24 14:33:46 +0200628 int fdt_compat_len;
Michal Simek1ca66d72019-02-14 13:14:30 +0100629
630 if (env_get("fdtfile"))
631 return 0;
632
Igor Lantsmane167bac2020-06-24 14:33:46 +0200633 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
634 &fdt_compat_len);
635 if (compatible && fdt_compat_len) {
636 char *name;
637
Michal Simek1ca66d72019-02-14 13:14:30 +0100638 debug("Compatible: %s\n", compatible);
639
Igor Lantsmane167bac2020-06-24 14:33:46 +0200640 name = strchr(compatible, ',');
641 if (!name)
642 return -EINVAL;
Michal Simek1ca66d72019-02-14 13:14:30 +0100643
Igor Lantsmane167bac2020-06-24 14:33:46 +0200644 name++;
645
646 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek1ca66d72019-02-14 13:14:30 +0100647 strlen(suffix) + 1);
648 if (!fdtfile)
649 return -ENOMEM;
650
Igor Lantsmane167bac2020-06-24 14:33:46 +0200651 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek1ca66d72019-02-14 13:14:30 +0100652
653 env_set("fdtfile", fdtfile);
654 free(fdtfile);
655 }
656
657 return 0;
658}
659
Michal Simek9c91e612020-04-08 11:04:41 +0200660int board_late_init(void)
661{
Michal Simek04b7e622015-01-15 10:01:51 +0100662 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200663 struct udevice *dev;
664 int bootseq = -1;
665 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200666 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200667 const char *mode;
668 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530669 char *env_targets;
Michal Simek7cb4cca2021-10-25 10:10:52 +0200670 int ret, multiboot;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200671
Michal Simek482f5492018-10-05 08:55:16 +0200672#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
673 usb_ether_init();
674#endif
675
Michal Simekecfb6dc2016-04-22 14:28:54 +0200676 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
677 debug("Saved variables - Skipping\n");
678 return 0;
679 }
Michal Simek04b7e622015-01-15 10:01:51 +0100680
Michal Simekbab07b62020-07-28 12:45:47 +0200681 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
682 return 0;
683
Michal Simek1ca66d72019-02-14 13:14:30 +0100684 ret = set_fdtfile();
685 if (ret)
686 return ret;
687
Michal Simek7cb4cca2021-10-25 10:10:52 +0200688 multiboot = multi_boot();
689 if (multiboot >= 0)
690 env_set_hex("multiboot", multiboot);
691
Michal Simek9c91e612020-04-08 11:04:41 +0200692 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100693
Michal Simekc5d95232015-09-20 17:20:42 +0200694 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100695 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200696 case USB_MODE:
697 puts("USB_MODE\n");
T Karthik Reddy9eee8e32021-03-24 23:37:57 -0600698 mode = "usb_dfu0 usb_dfu1";
Michal Simek43380352017-12-01 15:18:24 +0100699 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200700 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530701 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200702 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530703 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100704 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530705 break;
706 case QSPI_MODE_24BIT:
707 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200708 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200709 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100710 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530711 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200712 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200713 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700714 if (uclass_get_device_by_name(UCLASS_MMC,
715 "mmc@ff160000", &dev) &&
716 uclass_get_device_by_name(UCLASS_MMC,
717 "sdhci@ff160000", &dev)) {
718 puts("Boot from EMMC but without SD0 enabled!\n");
719 return -1;
720 }
Simon Glass75e534b2020-12-16 21:20:07 -0700721 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
T Karthik Reddy19735c32019-12-17 06:41:42 -0700722
723 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700724 bootseq = dev_seq(dev);
Ashok Reddy Somaa10be052021-09-15 08:52:17 +0200725 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200726 break;
727 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200728 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200729 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530730 "mmc@ff160000", &dev) &&
731 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200732 "sdhci@ff160000", &dev)) {
733 puts("Boot from SD0 but without SD0 enabled!\n");
734 return -1;
735 }
Simon Glass75e534b2020-12-16 21:20:07 -0700736 debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200737
738 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700739 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100740 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100741 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530742 case SD1_LSHFT_MODE:
743 puts("LVL_SHFT_");
Michal Simek293f47b2021-10-18 13:30:04 +0200744 fallthrough;
Michal Simek108e1842015-10-05 10:51:12 +0200745 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200746 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200747 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530748 "mmc@ff170000", &dev) &&
749 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200750 "sdhci@ff170000", &dev)) {
751 puts("Boot from SD1 but without SD1 enabled!\n");
752 return -1;
753 }
Simon Glass75e534b2020-12-16 21:20:07 -0700754 debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
Michal Simekf183a982018-04-25 11:20:43 +0200755
756 mode = "mmc";
Simon Glass75e534b2020-12-16 21:20:07 -0700757 bootseq = dev_seq(dev);
Michal Simek43380352017-12-01 15:18:24 +0100758 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200759 break;
760 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200761 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200762 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100763 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200764 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100765 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200766 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100767 printf("Invalid Boot Mode:0x%x\n", bootmode);
768 break;
769 }
770
Michal Simekf183a982018-04-25 11:20:43 +0200771 if (bootseq >= 0) {
772 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
773 debug("Bootseq len: %x\n", bootseq_len);
Michal Simek7a117c72021-01-11 13:46:58 +0100774 env_set_hex("bootseq", bootseq);
Michal Simekf183a982018-04-25 11:20:43 +0200775 }
776
Michal Simekecfb6dc2016-04-22 14:28:54 +0200777 /*
778 * One terminating char + one byte for space between mode
779 * and default boot_targets
780 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530781 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200782 if (env_targets)
783 env_targets_len = strlen(env_targets);
784
Michal Simekf183a982018-04-25 11:20:43 +0200785 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
786 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200787 if (!new_targets)
788 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200789
Michal Simekf183a982018-04-25 11:20:43 +0200790 if (bootseq >= 0)
791 sprintf(new_targets, "%s%x %s", mode, bootseq,
792 env_targets ? env_targets : "");
793 else
794 sprintf(new_targets, "%s %s", mode,
795 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200796
Simon Glass6a38e412017-08-03 12:22:09 -0600797 env_set("boot_targets", new_targets);
Michal Simek77488232021-07-28 12:46:39 +0200798 free(new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200799
Michal Simek29b9b712018-05-17 14:06:06 +0200800 reset_reason();
801
Michal Simek705d44a2020-03-31 12:39:37 +0200802 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100803}
Michal Simek342edfe2018-12-20 09:33:38 +0100804#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530805
806int checkboard(void)
807{
Michal Simek47ce9362016-01-25 11:04:21 +0100808 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530809 return 0;
810}
Michal Simek8d4a8d42020-07-30 13:37:49 +0200811
Michal Simeke0026bf2021-05-19 15:16:19 +0200812int mmc_get_env_dev(void)
813{
814 struct udevice *dev;
815 int bootseq = 0;
816
817 switch (zynqmp_get_bootmode()) {
818 case EMMC_MODE:
819 case SD_MODE:
820 if (uclass_get_device_by_name(UCLASS_MMC,
821 "mmc@ff160000", &dev) &&
822 uclass_get_device_by_name(UCLASS_MMC,
823 "sdhci@ff160000", &dev)) {
824 return -1;
825 }
826 bootseq = dev_seq(dev);
827 break;
828 case SD1_LSHFT_MODE:
829 case SD_MODE1:
830 if (uclass_get_device_by_name(UCLASS_MMC,
831 "mmc@ff170000", &dev) &&
832 uclass_get_device_by_name(UCLASS_MMC,
833 "sdhci@ff170000", &dev)) {
834 return -1;
835 }
836 bootseq = dev_seq(dev);
837 break;
838 default:
839 break;
840 }
841
842 debug("bootseq %d\n", bootseq);
843
844 return bootseq;
845}
846
Michal Simek8d4a8d42020-07-30 13:37:49 +0200847enum env_location env_get_location(enum env_operation op, int prio)
848{
849 u32 bootmode = zynqmp_get_bootmode();
850
851 if (prio)
852 return ENVL_UNKNOWN;
853
854 switch (bootmode) {
855 case EMMC_MODE:
856 case SD_MODE:
857 case SD1_LSHFT_MODE:
858 case SD_MODE1:
859 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
860 return ENVL_FAT;
861 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
862 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200863 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200864 case NAND_MODE:
865 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
866 return ENVL_NAND;
867 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
868 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200869 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200870 case QSPI_MODE_24BIT:
871 case QSPI_MODE_32BIT:
872 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
873 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200874 return ENVL_NOWHERE;
Michal Simek8d4a8d42020-07-30 13:37:49 +0200875 case JTAG_MODE:
876 default:
877 return ENVL_NOWHERE;
878 }
879}
Michal Simekcfb37602021-07-27 16:19:18 +0200880
881#if defined(CONFIG_SET_DFU_ALT_INFO)
882
883#define DFU_ALT_BUF_LEN SZ_1K
884
885void set_dfu_alt_info(char *interface, char *devstr)
886{
887 u8 multiboot;
888 int bootseq = 0;
889
890 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
891
Sughosh Ganuccb36462022-04-15 11:29:34 +0530892 if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
893 env_get("dfu_alt_info"))
Michal Simekcfb37602021-07-27 16:19:18 +0200894 return;
895
896 memset(buf, 0, sizeof(buf));
897
898 multiboot = multi_boot();
Michal Simek7cb4cca2021-10-25 10:10:52 +0200899 if (multiboot < 0)
900 multiboot = 0;
901
902 multiboot = env_get_hex("multiboot", multiboot);
Michal Simekcfb37602021-07-27 16:19:18 +0200903 debug("Multiboot: %d\n", multiboot);
904
905 switch (zynqmp_get_bootmode()) {
906 case EMMC_MODE:
907 case SD_MODE:
908 case SD1_LSHFT_MODE:
909 case SD_MODE1:
910 bootseq = mmc_get_env_dev();
911 if (!multiboot)
912 snprintf(buf, DFU_ALT_BUF_LEN,
913 "mmc %d:1=boot.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200914 "%s fat %d 1",
915 bootseq, bootseq,
916 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200917 else
918 snprintf(buf, DFU_ALT_BUF_LEN,
919 "mmc %d:1=boot%04d.bin fat %d 1;"
Michal Simek69103192021-10-18 14:02:15 +0200920 "%s fat %d 1",
921 bootseq, multiboot, bootseq,
922 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, bootseq);
Michal Simekcfb37602021-07-27 16:19:18 +0200923 break;
924 case QSPI_MODE_24BIT:
925 case QSPI_MODE_32BIT:
926 snprintf(buf, DFU_ALT_BUF_LEN,
927 "sf 0:0=boot.bin raw %x 0x1500000;"
Michal Simek69103192021-10-18 14:02:15 +0200928 "%s raw 0x%x 0x500000",
929 multiboot * SZ_32K, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
930 CONFIG_SYS_SPI_U_BOOT_OFFS);
Michal Simekcfb37602021-07-27 16:19:18 +0200931 break;
932 default:
933 return;
934 }
935
936 env_set("dfu_alt_info", buf);
937 puts("DFU alt info setting: done\n");
938}
939#endif