Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 3 | * (C) Copyright 2014 - 2020 Xilinx, Inc. |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 4 | * Michal Simek <michal.simek@xilinx.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 8 | #include <efi.h> |
| 9 | #include <efi_loader.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 13 | #include <asm/sections.h> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 14 | #include <dm/uclass.h> |
| 15 | #include <i2c.h> |
Michal Simek | b90b97e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 16 | #include <linux/sizes.h> |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 17 | #include <malloc.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 18 | #include "board.h" |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 19 | #include <dm.h> |
| 20 | #include <i2c_eeprom.h> |
| 21 | #include <net.h> |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 22 | #include <generated/dt.h> |
T Karthik Reddy | c8fa40a | 2021-08-10 06:50:20 -0600 | [diff] [blame] | 23 | #include <soc.h> |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 24 | #include <linux/ctype.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 25 | #include <linux/kernel.h> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 26 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 27 | #include "fru.h" |
| 28 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 29 | #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) |
| 30 | struct efi_fw_image fw_images[] = { |
| 31 | #if defined(XILINX_BOOT_IMAGE_GUID) |
| 32 | { |
| 33 | .image_type_id = XILINX_BOOT_IMAGE_GUID, |
| 34 | .fw_name = u"XILINX-BOOT", |
| 35 | .image_index = 1, |
| 36 | }, |
| 37 | #endif |
| 38 | #if defined(XILINX_UBOOT_IMAGE_GUID) |
| 39 | { |
| 40 | .image_type_id = XILINX_UBOOT_IMAGE_GUID, |
| 41 | .fw_name = u"XILINX-UBOOT", |
| 42 | .image_index = 2, |
| 43 | }, |
| 44 | #endif |
| 45 | }; |
| 46 | |
| 47 | struct efi_capsule_update_info update_info = { |
| 48 | .images = fw_images, |
| 49 | }; |
| 50 | |
| 51 | u8 num_image_type_guids = ARRAY_SIZE(fw_images); |
| 52 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 53 | |
Michal Simek | aee22b3 | 2020-08-03 12:59:28 +0200 | [diff] [blame] | 54 | #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 55 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 56 | { |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 57 | int ret = -EINVAL; |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 58 | struct udevice *dev; |
| 59 | ofnode eeprom; |
| 60 | |
| 61 | eeprom = ofnode_get_chosen_node("xlnx,eeprom"); |
| 62 | if (!ofnode_valid(eeprom)) |
| 63 | return -ENODEV; |
| 64 | |
| 65 | debug("%s: Path to EEPROM %s\n", __func__, |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 66 | ofnode_read_chosen_string("xlnx,eeprom")); |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 67 | |
| 68 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 69 | if (ret) |
| 70 | return ret; |
| 71 | |
| 72 | ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6); |
| 73 | if (ret) |
| 74 | debug("%s: I2C EEPROM MAC address read failed\n", __func__); |
| 75 | else |
| 76 | debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr); |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 77 | |
| 78 | return ret; |
| 79 | } |
Michal Simek | aee22b3 | 2020-08-03 12:59:28 +0200 | [diff] [blame] | 80 | #endif |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 81 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 82 | #define EEPROM_HEADER_MAGIC 0xdaaddeed |
| 83 | #define EEPROM_HDR_MANUFACTURER_LEN 16 |
| 84 | #define EEPROM_HDR_NAME_LEN 16 |
| 85 | #define EEPROM_HDR_REV_LEN 8 |
| 86 | #define EEPROM_HDR_SERIAL_LEN 20 |
| 87 | #define EEPROM_HDR_NO_OF_MAC_ADDR 4 |
| 88 | #define EEPROM_HDR_ETH_ALEN ETH_ALEN |
| 89 | |
| 90 | struct xilinx_board_description { |
| 91 | u32 header; |
| 92 | char manufacturer[EEPROM_HDR_MANUFACTURER_LEN + 1]; |
| 93 | char name[EEPROM_HDR_NAME_LEN + 1]; |
| 94 | char revision[EEPROM_HDR_REV_LEN + 1]; |
| 95 | char serial[EEPROM_HDR_SERIAL_LEN + 1]; |
| 96 | u8 mac_addr[EEPROM_HDR_NO_OF_MAC_ADDR][EEPROM_HDR_ETH_ALEN + 1]; |
| 97 | }; |
| 98 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 99 | static int highest_id = -1; |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 100 | static struct xilinx_board_description *board_info; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 101 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 102 | #define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr) |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 103 | |
| 104 | /* Variable which stores pointer to array which stores eeprom content */ |
| 105 | struct xilinx_legacy_format { |
| 106 | char board_sn[18]; /* 0x0 */ |
| 107 | char unused0[14]; /* 0x12 */ |
| 108 | char eth_mac[6]; /* 0x20 */ |
| 109 | char unused1[170]; /* 0x26 */ |
| 110 | char board_name[11]; /* 0xd0 */ |
| 111 | char unused2[5]; /* 0xdc */ |
| 112 | char board_revision[3]; /* 0xe0 */ |
| 113 | char unused3[29]; /* 0xe3 */ |
| 114 | }; |
| 115 | |
| 116 | static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size) |
| 117 | { |
| 118 | int i; |
| 119 | char byte; |
| 120 | |
| 121 | for (i = 0; i < size; i++) { |
| 122 | byte = eeprom[i]; |
| 123 | |
| 124 | /* Remove all ffs and spaces */ |
| 125 | if (byte == 0xff || byte == ' ') |
| 126 | eeprom[i] = 0; |
| 127 | |
| 128 | /* Convert strings to lower case */ |
| 129 | if (byte >= 'A' && byte <= 'Z') |
| 130 | eeprom[i] = byte + 'a' - 'A'; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | static int xilinx_read_eeprom_legacy(struct udevice *dev, char *name, |
| 135 | struct xilinx_board_description *desc) |
| 136 | { |
| 137 | int ret, size; |
| 138 | struct xilinx_legacy_format *eeprom_content; |
| 139 | bool eth_valid = false; |
| 140 | |
| 141 | size = sizeof(*eeprom_content); |
| 142 | |
| 143 | eeprom_content = calloc(1, size); |
| 144 | if (!eeprom_content) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | debug("%s: I2C EEPROM read pass data at %p\n", __func__, |
| 148 | eeprom_content); |
| 149 | |
| 150 | ret = dm_i2c_read(dev, 0, (uchar *)eeprom_content, size); |
| 151 | if (ret) { |
| 152 | debug("%s: I2C EEPROM read failed\n", __func__); |
| 153 | free(eeprom_content); |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | xilinx_eeprom_legacy_cleanup((char *)eeprom_content, size); |
| 158 | |
| 159 | printf("Xilinx I2C Legacy format at %s:\n", name); |
| 160 | printf(" Board name:\t%s\n", eeprom_content->board_name); |
| 161 | printf(" Board rev:\t%s\n", eeprom_content->board_revision); |
| 162 | printf(" Board SN:\t%s\n", eeprom_content->board_sn); |
| 163 | |
| 164 | eth_valid = is_valid_ethaddr((const u8 *)eeprom_content->eth_mac); |
| 165 | if (eth_valid) |
| 166 | printf(" Ethernet mac:\t%pM\n", eeprom_content->eth_mac); |
| 167 | |
| 168 | /* Terminating \0 chars ensure end of string */ |
| 169 | strcpy(desc->name, eeprom_content->board_name); |
| 170 | strcpy(desc->revision, eeprom_content->board_revision); |
| 171 | strcpy(desc->serial, eeprom_content->board_sn); |
| 172 | if (eth_valid) |
| 173 | memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN); |
| 174 | |
| 175 | desc->header = EEPROM_HEADER_MAGIC; |
| 176 | |
| 177 | free(eeprom_content); |
| 178 | |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | static bool xilinx_detect_legacy(u8 *buffer) |
| 183 | { |
| 184 | int i; |
| 185 | char c; |
| 186 | |
| 187 | for (i = 0; i < XILINX_I2C_DETECTION_BITS; i++) { |
| 188 | c = buffer[i]; |
| 189 | |
| 190 | if (c < '0' || c > '9') |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | return true; |
| 195 | } |
| 196 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 197 | static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, |
| 198 | struct xilinx_board_description *desc) |
| 199 | { |
Michal Simek | be5f572 | 2021-08-12 11:03:49 +0200 | [diff] [blame] | 200 | int i, ret, eeprom_size; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 201 | u8 *fru_content; |
Ashok Reddy Soma | 9f60e44 | 2022-02-23 15:00:59 +0100 | [diff] [blame] | 202 | u8 id = 0; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 203 | |
| 204 | /* FIXME this is shortcut - if eeprom type is wrong it will fail */ |
| 205 | eeprom_size = i2c_eeprom_size(dev); |
| 206 | |
| 207 | fru_content = calloc(1, eeprom_size); |
| 208 | if (!fru_content) |
| 209 | return -ENOMEM; |
| 210 | |
| 211 | debug("%s: I2C EEPROM read pass data at %p\n", __func__, |
| 212 | fru_content); |
| 213 | |
| 214 | ret = dm_i2c_read(dev, 0, (uchar *)fru_content, |
| 215 | eeprom_size); |
| 216 | if (ret) { |
| 217 | debug("%s: I2C EEPROM read failed\n", __func__); |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 218 | goto end; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 221 | fru_capture((unsigned long)fru_content); |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 222 | if (gd->flags & GD_FLG_RELOC || (_DEBUG && CONFIG_IS_ENABLED(DTB_RESELECT))) { |
| 223 | printf("Xilinx I2C FRU format at %s:\n", name); |
| 224 | ret = fru_display(0); |
| 225 | if (ret) { |
| 226 | printf("FRU format decoding failed.\n"); |
| 227 | goto end; |
| 228 | } |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | if (desc->header == EEPROM_HEADER_MAGIC) { |
| 232 | debug("Information already filled\n"); |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 233 | ret = -EINVAL; |
| 234 | goto end; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* It is clear that FRU was captured and structures were filled */ |
| 238 | strncpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name, |
| 239 | sizeof(desc->manufacturer)); |
| 240 | strncpy(desc->name, (char *)fru_data.brd.product_name, |
| 241 | sizeof(desc->name)); |
Michal Simek | be5f572 | 2021-08-12 11:03:49 +0200 | [diff] [blame] | 242 | for (i = 0; i < sizeof(desc->name); i++) { |
| 243 | if (desc->name[i] == ' ') |
| 244 | desc->name[i] = '\0'; |
| 245 | } |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 246 | strncpy(desc->revision, (char *)fru_data.brd.rev, |
| 247 | sizeof(desc->revision)); |
Michal Simek | 904fb97 | 2022-06-06 09:31:27 +0200 | [diff] [blame] | 248 | for (i = 0; i < sizeof(desc->revision); i++) { |
| 249 | if (desc->revision[i] == ' ') |
| 250 | desc->revision[i] = '\0'; |
| 251 | } |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 252 | strncpy(desc->serial, (char *)fru_data.brd.serial_number, |
| 253 | sizeof(desc->serial)); |
Ashok Reddy Soma | 9f60e44 | 2022-02-23 15:00:59 +0100 | [diff] [blame] | 254 | |
| 255 | while (id < EEPROM_HDR_NO_OF_MAC_ADDR) { |
| 256 | if (is_valid_ethaddr((const u8 *)fru_data.mac.macid[id])) |
| 257 | memcpy(&desc->mac_addr[id], |
| 258 | (char *)fru_data.mac.macid[id], ETH_ALEN); |
| 259 | id++; |
| 260 | } |
| 261 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 262 | desc->header = EEPROM_HEADER_MAGIC; |
| 263 | |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 264 | end: |
| 265 | free(fru_content); |
| 266 | return ret; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static bool xilinx_detect_fru(u8 *buffer) |
| 270 | { |
| 271 | u8 checksum = 0; |
| 272 | int i; |
| 273 | |
| 274 | checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr)); |
| 275 | if (checksum) { |
| 276 | debug("%s Common header CRC FAIL\n", __func__); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | bool all_zeros = true; |
| 281 | /* Checksum over all zeros is also zero that's why detect this case */ |
| 282 | for (i = 0; i < sizeof(struct fru_common_hdr); i++) { |
| 283 | if (buffer[i] != 0) |
| 284 | all_zeros = false; |
| 285 | } |
| 286 | |
| 287 | if (all_zeros) |
| 288 | return false; |
| 289 | |
| 290 | debug("%s Common header CRC PASS\n", __func__); |
| 291 | return true; |
| 292 | } |
| 293 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 294 | static int xilinx_read_eeprom_single(char *name, |
| 295 | struct xilinx_board_description *desc) |
| 296 | { |
| 297 | int ret; |
| 298 | struct udevice *dev; |
| 299 | ofnode eeprom; |
| 300 | u8 buffer[XILINX_I2C_DETECTION_BITS]; |
| 301 | |
| 302 | eeprom = ofnode_get_aliases_node(name); |
| 303 | if (!ofnode_valid(eeprom)) |
| 304 | return -ENODEV; |
| 305 | |
| 306 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | |
| 310 | ret = dm_i2c_read(dev, 0, buffer, sizeof(buffer)); |
| 311 | if (ret) { |
| 312 | debug("%s: I2C EEPROM read failed\n", __func__); |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | debug("%s: i2c memory detected: %s\n", __func__, name); |
| 317 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 318 | if (CONFIG_IS_ENABLED(CMD_FRU) && xilinx_detect_fru(buffer)) |
| 319 | return xilinx_read_eeprom_fru(dev, name, desc); |
| 320 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 321 | if (xilinx_detect_legacy(buffer)) |
| 322 | return xilinx_read_eeprom_legacy(dev, name, desc); |
| 323 | |
| 324 | return -ENODEV; |
| 325 | } |
| 326 | |
| 327 | __maybe_unused int xilinx_read_eeprom(void) |
| 328 | { |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 329 | int id; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 330 | char name_buf[8]; /* 8 bytes should be enough for nvmem+number */ |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 331 | struct xilinx_board_description *desc; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 332 | |
| 333 | highest_id = dev_read_alias_highest_id("nvmem"); |
| 334 | /* No nvmem aliases present */ |
| 335 | if (highest_id < 0) |
| 336 | return -EINVAL; |
| 337 | |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 338 | board_info = calloc(1, sizeof(*desc) * (highest_id + 1)); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 339 | if (!board_info) |
| 340 | return -ENOMEM; |
| 341 | |
| 342 | debug("%s: Highest ID %d, board_info %p\n", __func__, |
| 343 | highest_id, board_info); |
| 344 | |
| 345 | for (id = 0; id <= highest_id; id++) { |
| 346 | snprintf(name_buf, sizeof(name_buf), "nvmem%d", id); |
| 347 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 348 | /* Alloc structure */ |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 349 | desc = &board_info[id]; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 350 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 351 | /* Ignoring return value for supporting multiple chips */ |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 352 | xilinx_read_eeprom_single(name_buf, desc); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 355 | /* |
| 356 | * Consider to clean board_info structure when board/cards are not |
| 357 | * detected. |
| 358 | */ |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
Michal Simek | 1a50529 | 2022-02-17 14:28:38 +0100 | [diff] [blame] | 363 | #if defined(CONFIG_OF_BOARD) |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 364 | void *board_fdt_blob_setup(int *err) |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 365 | { |
Michal Simek | ddf69ae | 2020-09-04 16:21:47 +0200 | [diff] [blame] | 366 | void *fdt_blob; |
Michal Simek | c89f429 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 367 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 368 | *err = 0; |
Michal Simek | 663c162 | 2021-01-04 11:07:28 +0100 | [diff] [blame] | 369 | if (!IS_ENABLED(CONFIG_SPL_BUILD) && |
| 370 | !IS_ENABLED(CONFIG_VERSAL_NO_DDR) && |
Michal Simek | 6d4317b | 2021-02-02 13:33:22 +0100 | [diff] [blame] | 371 | !IS_ENABLED(CONFIG_ZYNQMP_NO_DDR)) { |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 372 | fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 373 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 374 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 375 | return fdt_blob; |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 376 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 377 | debug("DTB is not passed via %p\n", fdt_blob); |
| 378 | } |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 379 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 380 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 381 | /* |
| 382 | * FDT is at end of BSS unless it is in a different memory |
| 383 | * region |
| 384 | */ |
| 385 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
| 386 | fdt_blob = (ulong *)&_image_binary_end; |
| 387 | else |
| 388 | fdt_blob = (ulong *)&__bss_end; |
| 389 | } else { |
| 390 | /* FDT is at end of image */ |
| 391 | fdt_blob = (ulong *)&_end; |
| 392 | } |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 393 | |
| 394 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 395 | return fdt_blob; |
| 396 | |
| 397 | debug("DTB is also not passed via %p\n", fdt_blob); |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 398 | |
Michal Simek | 1a50529 | 2022-02-17 14:28:38 +0100 | [diff] [blame] | 399 | *err = -EINVAL; |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 400 | return NULL; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 401 | } |
| 402 | #endif |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 403 | |
Michal Simek | 67ed85d | 2020-10-22 11:14:20 +0200 | [diff] [blame] | 404 | #if defined(CONFIG_BOARD_LATE_INIT) |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 405 | static int env_set_by_index(const char *name, int index, char *data) |
| 406 | { |
| 407 | char var[32]; |
| 408 | |
| 409 | if (!index) |
| 410 | sprintf(var, "board_%s", name); |
| 411 | else |
| 412 | sprintf(var, "card%d_%s", index, name); |
| 413 | |
| 414 | return env_set(var, data); |
| 415 | } |
| 416 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 417 | int board_late_init_xilinx(void) |
| 418 | { |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 419 | u32 ret = 0; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 420 | int i, id, macid = 0; |
| 421 | struct xilinx_board_description *desc; |
Ricardo Salveti | d35ccf2 | 2022-01-20 16:17:30 -0300 | [diff] [blame] | 422 | phys_size_t bootm_size = gd->ram_top - gd->ram_base; |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 423 | |
T Karthik Reddy | 466cdde | 2021-04-02 01:49:17 -0600 | [diff] [blame] | 424 | if (!CONFIG_IS_ENABLED(MICROBLAZE)) { |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 425 | ulong scriptaddr; |
| 426 | |
| 427 | scriptaddr = env_get_hex("scriptaddr", 0); |
T Karthik Reddy | 466cdde | 2021-04-02 01:49:17 -0600 | [diff] [blame] | 428 | ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr); |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 429 | } |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 430 | |
Michal Simek | 9ccfcae | 2020-10-23 07:54:18 +0200 | [diff] [blame] | 431 | if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE)) |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 432 | bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M)); |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 433 | |
| 434 | ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET); |
| 435 | |
| 436 | ret |= env_set_addr("bootm_low", (void *)gd->ram_base); |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 437 | ret |= env_set_addr("bootm_size", (void *)bootm_size); |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 438 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 439 | for (id = 0; id <= highest_id; id++) { |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 440 | desc = &board_info[id]; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 441 | if (desc && desc->header == EEPROM_HEADER_MAGIC) { |
| 442 | if (desc->manufacturer[0]) |
| 443 | ret |= env_set_by_index("manufacturer", id, |
| 444 | desc->manufacturer); |
| 445 | if (desc->name[0]) |
| 446 | ret |= env_set_by_index("name", id, |
| 447 | desc->name); |
| 448 | if (desc->revision[0]) |
| 449 | ret |= env_set_by_index("rev", id, |
| 450 | desc->revision); |
| 451 | if (desc->serial[0]) |
| 452 | ret |= env_set_by_index("serial", id, |
| 453 | desc->serial); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 454 | |
| 455 | if (!CONFIG_IS_ENABLED(NET)) |
| 456 | continue; |
| 457 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 458 | for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) { |
| 459 | if (!desc->mac_addr[i]) |
Ashok Reddy Soma | 2d3b1b7 | 2022-02-23 15:00:58 +0100 | [diff] [blame] | 460 | break; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 461 | |
| 462 | if (is_valid_ethaddr((const u8 *)desc->mac_addr[i])) |
| 463 | ret |= eth_env_set_enetaddr_by_index("eth", |
| 464 | macid++, desc->mac_addr[i]); |
| 465 | } |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 469 | if (ret) |
| 470 | printf("%s: Saving run time variables FAILED\n", __func__); |
Michal Simek | 8ba62d2 | 2020-07-09 15:57:56 +0200 | [diff] [blame] | 471 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 472 | return 0; |
| 473 | } |
Michal Simek | 67ed85d | 2020-10-22 11:14:20 +0200 | [diff] [blame] | 474 | #endif |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 475 | |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 476 | static char *board_name = DEVICE_TREE; |
| 477 | |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 478 | int __maybe_unused board_fit_config_name_match(const char *name) |
| 479 | { |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 480 | debug("%s: Check %s, default %s\n", __func__, name, board_name); |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 481 | |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 482 | if (!strcmp(name, board_name)) |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 483 | return 0; |
| 484 | |
| 485 | return -1; |
| 486 | } |
T Karthik Reddy | c8fa40a | 2021-08-10 06:50:20 -0600 | [diff] [blame] | 487 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 488 | #if CONFIG_IS_ENABLED(DTB_RESELECT) |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 489 | #define MAX_NAME_LENGTH 50 |
| 490 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 491 | char * __maybe_unused __weak board_name_decode(void) |
| 492 | { |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 493 | char *board_local_name; |
| 494 | struct xilinx_board_description *desc; |
| 495 | int i, id; |
| 496 | |
| 497 | board_local_name = calloc(1, MAX_NAME_LENGTH); |
| 498 | if (!board_info) |
| 499 | return NULL; |
| 500 | |
| 501 | for (id = 0; id <= highest_id; id++) { |
| 502 | desc = &board_info[id]; |
| 503 | |
| 504 | /* No board description */ |
| 505 | if (!desc) |
| 506 | goto error; |
| 507 | |
| 508 | /* Board is not detected */ |
| 509 | if (desc->header != EEPROM_HEADER_MAGIC) |
| 510 | continue; |
| 511 | |
| 512 | /* The first string should be soc name */ |
| 513 | if (!id) |
| 514 | strcat(board_local_name, CONFIG_SYS_BOARD); |
| 515 | |
| 516 | /* |
| 517 | * For two purpose here: |
| 518 | * soc_name- eg: zynqmp- |
| 519 | * and between base board and CC eg: ..revA-sck... |
| 520 | */ |
| 521 | strcat(board_local_name, "-"); |
| 522 | |
| 523 | if (desc->name[0]) { |
| 524 | /* For DT composition name needs to be lowercase */ |
| 525 | for (i = 0; i < sizeof(desc->name); i++) |
| 526 | desc->name[i] = tolower(desc->name[i]); |
| 527 | |
| 528 | strcat(board_local_name, desc->name); |
| 529 | } |
| 530 | if (desc->revision[0]) { |
| 531 | strcat(board_local_name, "-rev"); |
| 532 | |
| 533 | /* And revision needs to be uppercase */ |
| 534 | for (i = 0; i < sizeof(desc->revision); i++) |
| 535 | desc->revision[i] = toupper(desc->revision[i]); |
| 536 | |
| 537 | strcat(board_local_name, desc->revision); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Longer strings will end up with buffer overflow and potential |
| 543 | * attacks that's why check it |
| 544 | */ |
| 545 | if (strlen(board_local_name) >= MAX_NAME_LENGTH) |
| 546 | panic("Board name can't be determined\n"); |
| 547 | |
| 548 | if (strlen(board_local_name)) |
| 549 | return board_local_name; |
| 550 | |
| 551 | error: |
| 552 | free(board_local_name); |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 553 | return NULL; |
| 554 | } |
| 555 | |
| 556 | bool __maybe_unused __weak board_detection(void) |
| 557 | { |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 558 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) { |
| 559 | int ret; |
| 560 | |
| 561 | ret = xilinx_read_eeprom(); |
| 562 | return !ret ? true : false; |
| 563 | } |
| 564 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 565 | return false; |
| 566 | } |
| 567 | |
| 568 | int embedded_dtb_select(void) |
| 569 | { |
| 570 | if (board_detection()) { |
| 571 | char *board_local_name; |
| 572 | |
| 573 | board_local_name = board_name_decode(); |
| 574 | if (board_local_name) { |
| 575 | board_name = board_local_name; |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 576 | printf("Detected name: %s\n", board_name); |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 577 | |
| 578 | /* Time to change DTB on fly */ |
| 579 | /* Both ways should work here */ |
| 580 | /* fdtdec_resetup(&rescan); */ |
| 581 | fdtdec_setup(); |
| 582 | } |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | #endif |