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