Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | 62270f4 | 2019-11-14 12:57:35 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Michal Simek | c0adba5 | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 10 | #include <debug_uart.h> |
Michal Simek | b86f43d | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 11 | #include <dfu.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 12 | #include <env.h> |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 13 | #include <env_internal.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Michal Simek | ce39ee2 | 2021-05-31 11:03:19 +0200 | [diff] [blame] | 15 | #include <image.h> |
| 16 | #include <lmb.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 17 | #include <log.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <net.h> |
Michal Simek | 679b994 | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 19 | #include <sata.h> |
Michal Simek | 6fe6f13 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 20 | #include <ahci.h> |
| 21 | #include <scsi.h> |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 22 | #include <malloc.h> |
Michal Simek | b86f43d | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 23 | #include <memalign.h> |
Michal Simek | 4490e01 | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 24 | #include <wdt.h> |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 25 | #include <asm/arch/clk.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 26 | #include <asm/arch/hardware.h> |
| 27 | #include <asm/arch/sys_proto.h> |
Michal Simek | 2ad341e | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 28 | #include <asm/arch/psu_init_gpl.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 29 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 30 | #include <asm/global_data.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 31 | #include <asm/io.h> |
Simon Glass | 25a5818 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 32 | #include <asm/ptrace.h> |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 33 | #include <dm/device.h> |
Michal Simek | 4490e01 | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 34 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 35 | #include <usb.h> |
| 36 | #include <dwc3-uboot.h> |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 37 | #include <zynqmppl.h> |
Ibai Erkiaga | 009ab7b | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 38 | #include <zynqmp_firmware.h> |
Michal Simek | 9feff38 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 39 | #include <g_dnl.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 40 | #include <linux/bitops.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 41 | #include <linux/delay.h> |
| 42 | #include <linux/sizes.h> |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 43 | #include "../common/board.h" |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 44 | |
Luca Ceresoli | c28a9cf | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 45 | #include "pm_cfg_obj.h" |
| 46 | |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 47 | #define ZYNQMP_VERSION_SIZE 7 |
Michal Simek | 2fbdbee | 2020-10-21 12:23:17 +0200 | [diff] [blame] | 48 | #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 Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 54 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 55 | DECLARE_GLOBAL_DATA_PTR; |
| 56 | |
Michal Simek | 29bd8ad | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 57 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 58 | static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC; |
| 59 | |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 60 | enum { |
| 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 Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 67 | static const struct { |
Michal Simek | 8ebdf9e | 2017-11-06 12:55:59 +0100 | [diff] [blame] | 68 | u32 id; |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 69 | u8 device; |
| 70 | u8 variants; |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 71 | } zynqmp_devices[] = { |
| 72 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 73 | .id = 0x04711093, |
| 74 | .device = 2, |
| 75 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 76 | }, |
| 77 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 78 | .id = 0x04710093, |
| 79 | .device = 3, |
| 80 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 81 | }, |
| 82 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 83 | .id = 0x04721093, |
| 84 | .device = 4, |
| 85 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 86 | ZYNQMP_VARIANT_EV, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 87 | }, |
| 88 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 89 | .id = 0x04720093, |
| 90 | .device = 5, |
| 91 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 92 | ZYNQMP_VARIANT_EV, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 93 | }, |
| 94 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 95 | .id = 0x04739093, |
| 96 | .device = 6, |
| 97 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 98 | }, |
| 99 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 100 | .id = 0x04730093, |
| 101 | .device = 7, |
| 102 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 103 | ZYNQMP_VARIANT_EV, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 104 | }, |
| 105 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 106 | .id = 0x04738093, |
| 107 | .device = 9, |
Michal Simek | bbe086a | 2020-10-02 14:42:05 +0200 | [diff] [blame] | 108 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 109 | }, |
| 110 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 111 | .id = 0x04740093, |
| 112 | .device = 11, |
| 113 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 114 | }, |
| 115 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 116 | .id = 0x04750093, |
| 117 | .device = 15, |
| 118 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 119 | }, |
| 120 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 121 | .id = 0x04759093, |
| 122 | .device = 17, |
| 123 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 124 | }, |
| 125 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 126 | .id = 0x04758093, |
| 127 | .device = 19, |
| 128 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 129 | }, |
| 130 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 131 | .id = 0x047E1093, |
| 132 | .device = 21, |
| 133 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 134 | }, |
| 135 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 136 | .id = 0x047E3093, |
| 137 | .device = 23, |
| 138 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 139 | }, |
| 140 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 141 | .id = 0x047E5093, |
| 142 | .device = 25, |
| 143 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 144 | }, |
| 145 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 146 | .id = 0x047E4093, |
| 147 | .device = 27, |
| 148 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 149 | }, |
| 150 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 151 | .id = 0x047E0093, |
| 152 | .device = 28, |
| 153 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 154 | }, |
| 155 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 156 | .id = 0x047E2093, |
| 157 | .device = 29, |
| 158 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 159 | }, |
| 160 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 161 | .id = 0x047E6093, |
| 162 | .device = 39, |
| 163 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 164 | }, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 165 | { |
Michal Simek | e17c5ec | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 166 | .id = 0x047FD093, |
| 167 | .device = 43, |
| 168 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 169 | }, |
| 170 | { |
Michal Simek | e17c5ec | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 171 | .id = 0x047F8093, |
| 172 | .device = 46, |
| 173 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 174 | }, |
| 175 | { |
Michal Simek | e17c5ec | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 176 | .id = 0x047FF093, |
| 177 | .device = 47, |
| 178 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 179 | }, |
Michal Simek | b030fed | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 180 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 181 | .id = 0x047FB093, |
| 182 | .device = 48, |
| 183 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b030fed | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 184 | }, |
| 185 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 186 | .id = 0x047FE093, |
| 187 | .device = 49, |
| 188 | .variants = ZYNQMP_VARIANT_DR, |
Siva Durga Prasad Paladugu | 134b0c8 | 2019-07-23 11:56:17 +0530 | [diff] [blame] | 189 | }, |
T Karthik Reddy | 4557627 | 2021-05-13 07:13:25 -0600 | [diff] [blame] | 190 | { |
| 191 | .id = 0x046d0093, |
| 192 | .device = 67, |
| 193 | .variants = ZYNQMP_VARIANT_DR, |
| 194 | }, |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 195 | }; |
| 196 | |
Michal Simek | ddf8dea | 2020-10-05 09:35:40 +0200 | [diff] [blame] | 197 | static 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 | |
| 211 | static 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 Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 223 | static char *zynqmp_get_silicon_idcode_name(void) |
| 224 | { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 225 | u32 i; |
| 226 | u32 idcode, idcode2; |
Michal Simek | ced4d46 | 2020-08-05 12:41:35 +0200 | [diff] [blame] | 227 | char name[ZYNQMP_VERSION_SIZE]; |
Ibai Erkiaga | 050f10f | 2020-08-04 23:17:30 +0100 | [diff] [blame] | 228 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
Michal Simek | 0d76b71 | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 229 | int ret; |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 230 | |
Michal Simek | d026aa1 | 2020-10-21 12:16:02 +0200 | [diff] [blame] | 231 | 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 Erkiaga | 050f10f | 2020-08-04 23:17:30 +0100 | [diff] [blame] | 236 | |
| 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 Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 246 | idcode = ret_payload[1]; |
| 247 | idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT; |
Michal Simek | 16df2f1 | 2020-10-21 12:16:50 +0200 | [diff] [blame] | 248 | debug("%s, IDCODE: 0x%0x, IDCODE2: 0x%0x\r\n", __func__, idcode, |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 249 | idcode2); |
Michal Simek | 494fffe | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 250 | |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 251 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 252 | if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF)) |
| 253 | break; |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 254 | } |
Siva Durga Prasad Paladugu | 83bf2ff | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 255 | |
| 256 | if (i >= ARRAY_SIZE(zynqmp_devices)) |
Michal Simek | ddf8dea | 2020-10-05 09:35:40 +0200 | [diff] [blame] | 257 | return zynqmp_detect_svd_name(idcode); |
Siva Durga Prasad Paladugu | 83bf2ff | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 258 | |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 259 | /* Add device prefix to the name */ |
Michal Simek | 0d76b71 | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 260 | ret = snprintf(name, ZYNQMP_VERSION_SIZE, "zu%d", |
| 261 | zynqmp_devices[i].device); |
Michal Simek | 07499da | 2020-10-21 12:17:44 +0200 | [diff] [blame] | 262 | if (ret < 0) |
Michal Simek | 0d76b71 | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 263 | return "unknown"; |
Siva Durga Prasad Paladugu | 83bf2ff | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 264 | |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 265 | 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 Paladugu | 5473f24 | 2018-10-26 17:47:55 +0530 | [diff] [blame] | 300 | } |
Ibai Erkiaga | fa79316 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 301 | } 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 Paladugu | 5473f24 | 2018-10-26 17:47:55 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Michal Simek | ced4d46 | 2020-08-05 12:41:35 +0200 | [diff] [blame] | 312 | return strdup(name); |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 313 | } |
| 314 | #endif |
| 315 | |
Michal Simek | fb4000e | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 316 | int board_early_init_f(void) |
| 317 | { |
Michal Simek | 88f05a9 | 2018-01-15 12:52:59 +0100 | [diff] [blame] | 318 | #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
Michal Simek | c0adba5 | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 319 | int ret; |
| 320 | |
Michal Simek | f32e79f | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 321 | ret = psu_init(); |
Michal Simek | c0adba5 | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 322 | if (ret) |
| 323 | return ret; |
Michal Simek | f8451f1 | 2020-03-20 08:59:02 +0100 | [diff] [blame] | 324 | |
Adrian Fiergolski | 3414712 | 2021-06-08 12:37:23 +0200 | [diff] [blame] | 325 | /* |
| 326 | * PS_SYSMON_ANALOG_BUS register determines mapping between SysMon |
| 327 | * supply sense channel to SysMon supply registers inside the IP. |
| 328 | * This register must be programmed to complete SysMon IP |
| 329 | * configuration. The default register configuration after |
| 330 | * power-up is incorrect. Hence, fix this by writing the |
| 331 | * correct value - 0x3210. |
| 332 | */ |
| 333 | writel(ZYNQMP_PS_SYSMON_ANALOG_BUS_VAL, |
| 334 | ZYNQMP_AMS_PS_SYSMON_ANALOG_BUS); |
| 335 | |
Michal Simek | f8451f1 | 2020-03-20 08:59:02 +0100 | [diff] [blame] | 336 | /* Delay is required for clocks to be propagated */ |
| 337 | udelay(1000000); |
Michal Simek | 55de092 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 338 | #endif |
| 339 | |
Michal Simek | c0adba5 | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 340 | #ifdef CONFIG_DEBUG_UART |
| 341 | /* Uart debug for sure */ |
| 342 | debug_uart_init(); |
| 343 | puts("Debug uart enabled\n"); /* or printch() */ |
| 344 | #endif |
| 345 | |
| 346 | return 0; |
Michal Simek | fb4000e | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 349 | static int multi_boot(void) |
| 350 | { |
Michal Simek | 3d23843 | 2021-07-27 16:17:31 +0200 | [diff] [blame] | 351 | u32 multiboot = 0; |
| 352 | int ret; |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 353 | |
Michal Simek | 3d23843 | 2021-07-27 16:17:31 +0200 | [diff] [blame] | 354 | ret = zynqmp_mmio_read((ulong)&csu_base->multi_boot, &multiboot); |
| 355 | if (ret) |
| 356 | return -EINVAL; |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 357 | |
Michal Simek | e49f2a7 | 2021-07-27 14:05:27 +0200 | [diff] [blame] | 358 | return multiboot; |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Mike Looijmans | dfbe492 | 2019-10-18 07:34:13 +0200 | [diff] [blame] | 361 | #define PS_SYSMON_ANALOG_BUS_VAL 0x3210 |
| 362 | #define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914 |
| 363 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 364 | int board_init(void) |
| 365 | { |
Michal Simek | 66ef85d | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 366 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
Ibai Erkiaga | 325a22d | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 367 | struct udevice *dev; |
| 368 | |
| 369 | uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev); |
| 370 | if (!dev) |
| 371 | panic("PMU Firmware device not found - Enable it"); |
Michal Simek | 66ef85d | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 372 | #endif |
Ibai Erkiaga | 325a22d | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 373 | |
Luca Ceresoli | c28a9cf | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 374 | #if defined(CONFIG_SPL_BUILD) |
| 375 | /* Check *at build time* if the filename is an non-empty string */ |
| 376 | if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1) |
| 377 | zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj, |
| 378 | zynqmp_pm_cfg_obj_size); |
Michal Simek | 98757d8 | 2021-02-02 16:34:48 +0100 | [diff] [blame] | 379 | printf("Silicon version:\t%d\n", zynqmp_get_silicon_version()); |
Michal Simek | d61728c | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 380 | #else |
| 381 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) |
| 382 | xilinx_read_eeprom(); |
Luca Ceresoli | c28a9cf | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 383 | #endif |
| 384 | |
Michal Simek | a0736ef | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 385 | printf("EL Level:\tEL%d\n", current_el()); |
| 386 | |
Mike Looijmans | dfbe492 | 2019-10-18 07:34:13 +0200 | [diff] [blame] | 387 | /* Bug in ROM sets wrong value in this register */ |
| 388 | writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG); |
| 389 | |
Michal Simek | 29bd8ad | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 390 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Ibai Erkiaga | 4b2ad7b | 2020-08-04 23:17:29 +0100 | [diff] [blame] | 391 | zynqmppl.name = zynqmp_get_silicon_idcode_name(); |
| 392 | printf("Chip ID:\t%s\n", zynqmppl.name); |
| 393 | fpga_init(); |
| 394 | fpga_add(fpga_xilinx, &zynqmppl); |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 395 | #endif |
| 396 | |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 397 | if (current_el() == 3) |
Michal Simek | e49f2a7 | 2021-07-27 14:05:27 +0200 | [diff] [blame] | 398 | printf("Multiboot:\t%d\n", multi_boot()); |
Michal Simek | c514301 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 399 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | int board_early_init_r(void) |
| 404 | { |
| 405 | u32 val; |
| 406 | |
Siva Durga Prasad Paladugu | ec60a27 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 407 | if (current_el() != 3) |
| 408 | return 0; |
| 409 | |
Michal Simek | 90a35db | 2017-07-12 10:32:18 +0200 | [diff] [blame] | 410 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 411 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 412 | |
Siva Durga Prasad Paladugu | ec60a27 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 413 | if (!val) { |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 414 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 415 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 416 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 417 | |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 418 | /* Program freq register in System counter */ |
| 419 | writel(zynqmp_get_system_timer_freq(), |
| 420 | &iou_scntr_secure->base_frequency_id_register); |
| 421 | /* And enable system counter */ |
| 422 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 423 | &iou_scntr_secure->counter_control_register); |
| 424 | } |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
Nitin Jain | 5191686 | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 428 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 429 | char *const argv[]) |
Nitin Jain | 5191686 | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 430 | { |
| 431 | int ret = 0; |
| 432 | |
| 433 | if (current_el() > 1) { |
| 434 | smp_kick_all_cpus(); |
| 435 | dcache_disable(); |
| 436 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 437 | ES_TO_AARCH64); |
| 438 | } else { |
| 439 | printf("FAIL: current EL is not above EL1\n"); |
| 440 | ret = EINVAL; |
| 441 | } |
| 442 | return ret; |
| 443 | } |
| 444 | |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 445 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 446 | int dram_init_banksize(void) |
Tom Rini | 361a879 | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 447 | { |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 448 | int ret; |
| 449 | |
| 450 | ret = fdtdec_setup_memory_banksize(); |
| 451 | if (ret) |
| 452 | return ret; |
| 453 | |
| 454 | mem_map_fill(); |
| 455 | |
| 456 | return 0; |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | int dram_init(void) |
| 460 | { |
Siva Durga Prasad Paladugu | 12308b1 | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 461 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | 950f86c | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 462 | return -EINVAL; |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
Michal Simek | ce39ee2 | 2021-05-31 11:03:19 +0200 | [diff] [blame] | 466 | |
| 467 | ulong board_get_usable_ram_top(ulong total_size) |
| 468 | { |
| 469 | phys_size_t size; |
| 470 | phys_addr_t reg; |
| 471 | struct lmb lmb; |
| 472 | |
Michal Simek | 5bd5ee0 | 2021-08-19 11:07:59 +0200 | [diff] [blame] | 473 | if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8)) |
| 474 | panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob); |
| 475 | |
Michal Simek | ce39ee2 | 2021-05-31 11:03:19 +0200 | [diff] [blame] | 476 | /* found enough not-reserved memory to relocated U-Boot */ |
| 477 | lmb_init(&lmb); |
| 478 | lmb_add(&lmb, gd->ram_base, gd->ram_size); |
| 479 | boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob); |
| 480 | size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE), |
| 481 | reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE); |
| 482 | |
| 483 | if (!reg) |
| 484 | reg = gd->ram_top - size; |
| 485 | |
| 486 | return reg + size; |
| 487 | } |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 488 | #else |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 489 | int dram_init_banksize(void) |
| 490 | { |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 491 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 492 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 493 | |
| 494 | mem_map_fill(); |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 499 | int dram_init(void) |
| 500 | { |
Michal Simek | 61dc92a | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 501 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 502 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 503 | |
| 504 | return 0; |
| 505 | } |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 506 | #endif |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 507 | |
Michal Simek | f1bc214 | 2021-07-13 16:39:26 +0200 | [diff] [blame] | 508 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Harald Seiler | 35b65dd | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 509 | void reset_cpu(void) |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 510 | { |
| 511 | } |
Michal Simek | f1bc214 | 2021-07-13 16:39:26 +0200 | [diff] [blame] | 512 | #endif |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 513 | |
Michal Simek | 4d9bc79 | 2020-08-20 10:54:45 +0200 | [diff] [blame] | 514 | static u8 __maybe_unused zynqmp_get_bootmode(void) |
| 515 | { |
| 516 | u8 bootmode; |
| 517 | u32 reg = 0; |
| 518 | int ret; |
| 519 | |
| 520 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
| 521 | if (ret) |
| 522 | return -EINVAL; |
| 523 | |
Michal Simek | afb08a8 | 2021-07-28 12:25:49 +0200 | [diff] [blame] | 524 | debug("HW boot mode: %x\n", reg & BOOT_MODES_MASK); |
| 525 | debug("ALT boot mode: %x\n", reg >> BOOT_MODE_ALT_SHIFT); |
| 526 | |
Michal Simek | 4d9bc79 | 2020-08-20 10:54:45 +0200 | [diff] [blame] | 527 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 528 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 529 | |
| 530 | bootmode = reg & BOOT_MODES_MASK; |
| 531 | |
| 532 | return bootmode; |
| 533 | } |
| 534 | |
Michal Simek | 0bf3f9c | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 535 | #if defined(CONFIG_BOARD_LATE_INIT) |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 536 | static const struct { |
| 537 | u32 bit; |
| 538 | const char *name; |
| 539 | } reset_reasons[] = { |
| 540 | { RESET_REASON_DEBUG_SYS, "DEBUG" }, |
| 541 | { RESET_REASON_SOFT, "SOFT" }, |
| 542 | { RESET_REASON_SRST, "SRST" }, |
| 543 | { RESET_REASON_PSONLY, "PS-ONLY" }, |
| 544 | { RESET_REASON_PMU, "PMU" }, |
| 545 | { RESET_REASON_INTERNAL, "INTERNAL" }, |
| 546 | { RESET_REASON_EXTERNAL, "EXTERNAL" }, |
| 547 | {} |
| 548 | }; |
| 549 | |
T Karthik Reddy | be52372 | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 550 | static int reset_reason(void) |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 551 | { |
T Karthik Reddy | be52372 | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 552 | u32 reg; |
| 553 | int i, ret; |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 554 | const char *reason = NULL; |
| 555 | |
T Karthik Reddy | be52372 | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 556 | ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®); |
| 557 | if (ret) |
| 558 | return -EINVAL; |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 559 | |
| 560 | puts("Reset reason:\t"); |
| 561 | |
| 562 | for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) { |
T Karthik Reddy | be52372 | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 563 | if (reg & reset_reasons[i].bit) { |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 564 | reason = reset_reasons[i].name; |
| 565 | printf("%s ", reset_reasons[i].name); |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | puts("\n"); |
| 571 | |
| 572 | env_set("reset_reason", reason); |
| 573 | |
Michal Simek | 3aba25b | 2021-02-09 08:50:22 +0100 | [diff] [blame] | 574 | return 0; |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 577 | static int set_fdtfile(void) |
| 578 | { |
| 579 | char *compatible, *fdtfile; |
| 580 | const char *suffix = ".dtb"; |
| 581 | const char *vendor = "xilinx/"; |
Igor Lantsman | 1b208d5 | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 582 | int fdt_compat_len; |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 583 | |
| 584 | if (env_get("fdtfile")) |
| 585 | return 0; |
| 586 | |
Igor Lantsman | 1b208d5 | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 587 | compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 588 | &fdt_compat_len); |
| 589 | if (compatible && fdt_compat_len) { |
| 590 | char *name; |
| 591 | |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 592 | debug("Compatible: %s\n", compatible); |
| 593 | |
Igor Lantsman | 1b208d5 | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 594 | name = strchr(compatible, ','); |
| 595 | if (!name) |
| 596 | return -EINVAL; |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 597 | |
Igor Lantsman | 1b208d5 | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 598 | name++; |
| 599 | |
| 600 | fdtfile = calloc(1, strlen(vendor) + strlen(name) + |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 601 | strlen(suffix) + 1); |
| 602 | if (!fdtfile) |
| 603 | return -ENOMEM; |
| 604 | |
Igor Lantsman | 1b208d5 | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 605 | sprintf(fdtfile, "%s%s%s", vendor, name, suffix); |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 606 | |
| 607 | env_set("fdtfile", fdtfile); |
| 608 | free(fdtfile); |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 614 | int board_late_init(void) |
| 615 | { |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 616 | u8 bootmode; |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 617 | struct udevice *dev; |
| 618 | int bootseq = -1; |
| 619 | int bootseq_len = 0; |
Michal Simek | 0478b0b | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 620 | int env_targets_len = 0; |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 621 | const char *mode; |
| 622 | char *new_targets; |
Siva Durga Prasad Paladugu | 01c42d3 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 623 | char *env_targets; |
Siva Durga Prasad Paladugu | d1db89f | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 624 | int ret; |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 625 | |
Michal Simek | e615f39 | 2018-10-05 08:55:16 +0200 | [diff] [blame] | 626 | #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD) |
| 627 | usb_ether_init(); |
| 628 | #endif |
| 629 | |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 630 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 631 | debug("Saved variables - Skipping\n"); |
| 632 | return 0; |
| 633 | } |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 634 | |
Michal Simek | 62b9626 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 635 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 636 | return 0; |
| 637 | |
Michal Simek | 91d7e0c | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 638 | ret = set_fdtfile(); |
| 639 | if (ret) |
| 640 | return ret; |
| 641 | |
Michal Simek | 51f6c52 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 642 | bootmode = zynqmp_get_bootmode(); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 643 | |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 644 | puts("Bootmode: "); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 645 | switch (bootmode) { |
Michal Simek | d58fc12 | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 646 | case USB_MODE: |
| 647 | puts("USB_MODE\n"); |
T Karthik Reddy | ef1be3e | 2021-03-24 23:37:57 -0600 | [diff] [blame] | 648 | mode = "usb_dfu0 usb_dfu1"; |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 649 | env_set("modeboot", "usb_dfu_spl"); |
Michal Simek | d58fc12 | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 650 | break; |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 651 | case JTAG_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 652 | puts("JTAG_MODE\n"); |
Siva Durga Prasad Paladugu | 5d2274c | 2019-06-25 17:41:09 +0530 | [diff] [blame] | 653 | mode = "jtag pxe dhcp"; |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 654 | env_set("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 655 | break; |
| 656 | case QSPI_MODE_24BIT: |
| 657 | case QSPI_MODE_32BIT: |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 658 | mode = "qspi0"; |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 659 | puts("QSPI_MODE\n"); |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 660 | env_set("modeboot", "qspiboot"); |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 661 | break; |
Michal Simek | 39c56f5 | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 662 | case EMMC_MODE: |
Michal Simek | 78678fe | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 663 | puts("EMMC_MODE\n"); |
T Karthik Reddy | 18be60b | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 664 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 665 | "mmc@ff160000", &dev) && |
| 666 | uclass_get_device_by_name(UCLASS_MMC, |
| 667 | "sdhci@ff160000", &dev)) { |
| 668 | puts("Boot from EMMC but without SD0 enabled!\n"); |
| 669 | return -1; |
| 670 | } |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 671 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
T Karthik Reddy | 18be60b | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 672 | |
| 673 | mode = "mmc"; |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 674 | bootseq = dev_seq(dev); |
Ashok Reddy Soma | 5d498a1 | 2021-09-15 08:52:17 +0200 | [diff] [blame] | 675 | env_set("modeboot", "emmcboot"); |
Michal Simek | 78678fe | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 676 | break; |
| 677 | case SD_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 678 | puts("SD_MODE\n"); |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 679 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e7c9de6 | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 680 | "mmc@ff160000", &dev) && |
| 681 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 682 | "sdhci@ff160000", &dev)) { |
| 683 | puts("Boot from SD0 but without SD0 enabled!\n"); |
| 684 | return -1; |
| 685 | } |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 686 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 687 | |
| 688 | mode = "mmc"; |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 689 | bootseq = dev_seq(dev); |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 690 | env_set("modeboot", "sdboot"); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 691 | break; |
Siva Durga Prasad Paladugu | e199227 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 692 | case SD1_LSHFT_MODE: |
| 693 | puts("LVL_SHFT_"); |
| 694 | /* fall through */ |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 695 | case SD_MODE1: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 696 | puts("SD_MODE1\n"); |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 697 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e7c9de6 | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 698 | "mmc@ff170000", &dev) && |
| 699 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 700 | "sdhci@ff170000", &dev)) { |
| 701 | puts("Boot from SD1 but without SD1 enabled!\n"); |
| 702 | return -1; |
| 703 | } |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 704 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 705 | |
| 706 | mode = "mmc"; |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 707 | bootseq = dev_seq(dev); |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 708 | env_set("modeboot", "sdboot"); |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 709 | break; |
| 710 | case NAND_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 711 | puts("NAND_MODE\n"); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 712 | mode = "nand0"; |
Michal Simek | 07656ba | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 713 | env_set("modeboot", "nandboot"); |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 714 | break; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 715 | default: |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 716 | mode = ""; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 717 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 718 | break; |
| 719 | } |
| 720 | |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 721 | if (bootseq >= 0) { |
| 722 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 723 | debug("Bootseq len: %x\n", bootseq_len); |
Michal Simek | 2784bef | 2021-01-11 13:46:58 +0100 | [diff] [blame] | 724 | env_set_hex("bootseq", bootseq); |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 725 | } |
| 726 | |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 727 | /* |
| 728 | * One terminating char + one byte for space between mode |
| 729 | * and default boot_targets |
| 730 | */ |
Siva Durga Prasad Paladugu | 01c42d3 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 731 | env_targets = env_get("boot_targets"); |
Michal Simek | 0478b0b | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 732 | if (env_targets) |
| 733 | env_targets_len = strlen(env_targets); |
| 734 | |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 735 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 736 | bootseq_len); |
Michal Simek | 1e3e68f | 2018-06-13 09:42:41 +0200 | [diff] [blame] | 737 | if (!new_targets) |
| 738 | return -ENOMEM; |
Michal Simek | 0478b0b | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 739 | |
Michal Simek | 2882b39 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 740 | if (bootseq >= 0) |
| 741 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 742 | env_targets ? env_targets : ""); |
| 743 | else |
| 744 | sprintf(new_targets, "%s %s", mode, |
| 745 | env_targets ? env_targets : ""); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 746 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 747 | env_set("boot_targets", new_targets); |
Michal Simek | f83cfaa | 2021-07-28 12:46:39 +0200 | [diff] [blame] | 748 | free(new_targets); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 749 | |
Michal Simek | d348bea | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 750 | reset_reason(); |
| 751 | |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 752 | return board_late_init_xilinx(); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 753 | } |
Michal Simek | 0bf3f9c | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 754 | #endif |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 755 | |
| 756 | int checkboard(void) |
| 757 | { |
Michal Simek | 5af0855 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 758 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 759 | return 0; |
| 760 | } |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 761 | |
Michal Simek | 476588c | 2021-05-19 15:16:19 +0200 | [diff] [blame] | 762 | int mmc_get_env_dev(void) |
| 763 | { |
| 764 | struct udevice *dev; |
| 765 | int bootseq = 0; |
| 766 | |
| 767 | switch (zynqmp_get_bootmode()) { |
| 768 | case EMMC_MODE: |
| 769 | case SD_MODE: |
| 770 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 771 | "mmc@ff160000", &dev) && |
| 772 | uclass_get_device_by_name(UCLASS_MMC, |
| 773 | "sdhci@ff160000", &dev)) { |
| 774 | return -1; |
| 775 | } |
| 776 | bootseq = dev_seq(dev); |
| 777 | break; |
| 778 | case SD1_LSHFT_MODE: |
| 779 | case SD_MODE1: |
| 780 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 781 | "mmc@ff170000", &dev) && |
| 782 | uclass_get_device_by_name(UCLASS_MMC, |
| 783 | "sdhci@ff170000", &dev)) { |
| 784 | return -1; |
| 785 | } |
| 786 | bootseq = dev_seq(dev); |
| 787 | break; |
| 788 | default: |
| 789 | break; |
| 790 | } |
| 791 | |
| 792 | debug("bootseq %d\n", bootseq); |
| 793 | |
| 794 | return bootseq; |
| 795 | } |
| 796 | |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 797 | enum env_location env_get_location(enum env_operation op, int prio) |
| 798 | { |
| 799 | u32 bootmode = zynqmp_get_bootmode(); |
| 800 | |
| 801 | if (prio) |
| 802 | return ENVL_UNKNOWN; |
| 803 | |
| 804 | switch (bootmode) { |
| 805 | case EMMC_MODE: |
| 806 | case SD_MODE: |
| 807 | case SD1_LSHFT_MODE: |
| 808 | case SD_MODE1: |
| 809 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 810 | return ENVL_FAT; |
| 811 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 812 | return ENVL_EXT4; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 813 | return ENVL_NOWHERE; |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 814 | case NAND_MODE: |
| 815 | if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) |
| 816 | return ENVL_NAND; |
| 817 | if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) |
| 818 | return ENVL_UBI; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 819 | return ENVL_NOWHERE; |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 820 | case QSPI_MODE_24BIT: |
| 821 | case QSPI_MODE_32BIT: |
| 822 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 823 | return ENVL_SPI_FLASH; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 824 | return ENVL_NOWHERE; |
Michal Simek | 1025bd0 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 825 | case JTAG_MODE: |
| 826 | default: |
| 827 | return ENVL_NOWHERE; |
| 828 | } |
| 829 | } |
Michal Simek | b86f43d | 2021-07-27 16:19:18 +0200 | [diff] [blame] | 830 | |
| 831 | #if defined(CONFIG_SET_DFU_ALT_INFO) |
| 832 | |
| 833 | #define DFU_ALT_BUF_LEN SZ_1K |
| 834 | |
| 835 | void set_dfu_alt_info(char *interface, char *devstr) |
| 836 | { |
| 837 | u8 multiboot; |
| 838 | int bootseq = 0; |
| 839 | |
| 840 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); |
| 841 | |
| 842 | if (env_get("dfu_alt_info")) |
| 843 | return; |
| 844 | |
| 845 | memset(buf, 0, sizeof(buf)); |
| 846 | |
| 847 | multiboot = multi_boot(); |
| 848 | debug("Multiboot: %d\n", multiboot); |
| 849 | |
| 850 | switch (zynqmp_get_bootmode()) { |
| 851 | case EMMC_MODE: |
| 852 | case SD_MODE: |
| 853 | case SD1_LSHFT_MODE: |
| 854 | case SD_MODE1: |
| 855 | bootseq = mmc_get_env_dev(); |
| 856 | if (!multiboot) |
| 857 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 858 | "mmc %d:1=boot.bin fat %d 1;" |
| 859 | "u-boot.itb fat %d 1", |
| 860 | bootseq, bootseq, bootseq); |
| 861 | else |
| 862 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 863 | "mmc %d:1=boot%04d.bin fat %d 1;" |
| 864 | "u-boot.itb fat %d 1", |
| 865 | bootseq, multiboot, bootseq, bootseq); |
| 866 | break; |
| 867 | case QSPI_MODE_24BIT: |
| 868 | case QSPI_MODE_32BIT: |
| 869 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 870 | "sf 0:0=boot.bin raw %x 0x1500000;" |
| 871 | "u-boot.itb raw 0x%x 0x500000", |
| 872 | multiboot * SZ_32K, CONFIG_SYS_SPI_U_BOOT_OFFS); |
| 873 | break; |
| 874 | default: |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | env_set("dfu_alt_info", buf); |
| 879 | puts("DFU alt info setting: done\n"); |
| 880 | } |
| 881 | #endif |