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