blob: 5be3090c318632b7c81da47d19cd20595289185a [file] [log] [blame]
Michal Simek014d3042019-01-21 15:25:02 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
Michal Simek394ee242020-08-03 13:01:45 +02003 * (C) Copyright 2014 - 2020 Xilinx, Inc.
Michal Simek014d3042019-01-21 15:25:02 +01004 * Michal Simek <michal.simek@xilinx.com>
5 */
6
7#include <common.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +05308#include <efi.h>
9#include <efi_loader.h>
Simon Glassed38aef2020-05-10 11:40:03 -060010#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Michal Simek878ba362019-12-19 17:45:15 +010013#include <asm/sections.h>
Michal Simek014d3042019-01-21 15:25:02 +010014#include <dm/uclass.h>
15#include <i2c.h>
Michal Simekb90b97e2020-04-08 10:51:36 +020016#include <linux/sizes.h>
Michal Simek394ee242020-08-03 13:01:45 +020017#include <malloc.h>
Michal Simek705d44a2020-03-31 12:39:37 +020018#include "board.h"
Michal Simek394ee242020-08-03 13:01:45 +020019#include <dm.h>
20#include <i2c_eeprom.h>
21#include <net.h>
Michal Simekfe49df92020-10-26 12:26:13 +010022#include <generated/dt.h>
T Karthik Reddyc8fa40a2021-08-10 06:50:20 -060023#include <soc.h>
Michal Simeke0453512021-08-11 14:23:54 +020024#include <linux/ctype.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053025#include <linux/kernel.h>
Michal Simek014d3042019-01-21 15:25:02 +010026
Michal Simek207e0622020-08-03 16:14:23 +020027#include "fru.h"
28
Sughosh Ganuccb36462022-04-15 11:29:34 +053029#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
30struct 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
47struct efi_capsule_update_info update_info = {
48 .images = fw_images,
49};
50
51u8 num_image_type_guids = ARRAY_SIZE(fw_images);
52#endif /* EFI_HAVE_CAPSULE_SUPPORT */
53
Michal Simekaee22b32020-08-03 12:59:28 +020054#if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
Michal Simek014d3042019-01-21 15:25:02 +010055int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
56{
Michal Simek13db6162019-01-21 16:29:07 +010057 int ret = -EINVAL;
Michal Simek13db6162019-01-21 16:29:07 +010058 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 Glassf3455962020-01-27 08:49:43 -070066 ofnode_read_chosen_string("xlnx,eeprom"));
Michal Simek13db6162019-01-21 16:29:07 +010067
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 Simek13db6162019-01-21 16:29:07 +010077
78 return ret;
79}
Michal Simekaee22b32020-08-03 12:59:28 +020080#endif
Ibai Erkiaga6f658202019-10-02 15:57:36 +010081
Michal Simek394ee242020-08-03 13:01:45 +020082#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
90struct 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 Simek0bb24e12020-08-03 12:57:05 +020099static int highest_id = -1;
Michal Simeke98ae1d2021-08-12 12:30:36 +0200100static struct xilinx_board_description *board_info;
Michal Simek394ee242020-08-03 13:01:45 +0200101
Michal Simek207e0622020-08-03 16:14:23 +0200102#define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr)
Michal Simek394ee242020-08-03 13:01:45 +0200103
104/* Variable which stores pointer to array which stores eeprom content */
105struct 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
116static 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
134static 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
182static 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 Simek207e0622020-08-03 16:14:23 +0200197static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
198 struct xilinx_board_description *desc)
199{
Michal Simekbe5f5722021-08-12 11:03:49 +0200200 int i, ret, eeprom_size;
Michal Simek207e0622020-08-03 16:14:23 +0200201 u8 *fru_content;
Ashok Reddy Soma9f60e442022-02-23 15:00:59 +0100202 u8 id = 0;
Michal Simek207e0622020-08-03 16:14:23 +0200203
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 Simekaada8a62021-08-13 09:17:10 +0200218 goto end;
Michal Simek207e0622020-08-03 16:14:23 +0200219 }
220
Michal Simek207e0622020-08-03 16:14:23 +0200221 fru_capture((unsigned long)fru_content);
Michal Simeke0453512021-08-11 14:23:54 +0200222 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 Simek207e0622020-08-03 16:14:23 +0200229 }
230
231 if (desc->header == EEPROM_HEADER_MAGIC) {
232 debug("Information already filled\n");
Michal Simekaada8a62021-08-13 09:17:10 +0200233 ret = -EINVAL;
234 goto end;
Michal Simek207e0622020-08-03 16:14:23 +0200235 }
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 Simekbe5f5722021-08-12 11:03:49 +0200242 for (i = 0; i < sizeof(desc->name); i++) {
243 if (desc->name[i] == ' ')
244 desc->name[i] = '\0';
245 }
Michal Simek207e0622020-08-03 16:14:23 +0200246 strncpy(desc->revision, (char *)fru_data.brd.rev,
247 sizeof(desc->revision));
248 strncpy(desc->serial, (char *)fru_data.brd.serial_number,
249 sizeof(desc->serial));
Ashok Reddy Soma9f60e442022-02-23 15:00:59 +0100250
251 while (id < EEPROM_HDR_NO_OF_MAC_ADDR) {
252 if (is_valid_ethaddr((const u8 *)fru_data.mac.macid[id]))
253 memcpy(&desc->mac_addr[id],
254 (char *)fru_data.mac.macid[id], ETH_ALEN);
255 id++;
256 }
257
Michal Simek207e0622020-08-03 16:14:23 +0200258 desc->header = EEPROM_HEADER_MAGIC;
259
Michal Simekaada8a62021-08-13 09:17:10 +0200260end:
261 free(fru_content);
262 return ret;
Michal Simek207e0622020-08-03 16:14:23 +0200263}
264
265static bool xilinx_detect_fru(u8 *buffer)
266{
267 u8 checksum = 0;
268 int i;
269
270 checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr));
271 if (checksum) {
272 debug("%s Common header CRC FAIL\n", __func__);
273 return false;
274 }
275
276 bool all_zeros = true;
277 /* Checksum over all zeros is also zero that's why detect this case */
278 for (i = 0; i < sizeof(struct fru_common_hdr); i++) {
279 if (buffer[i] != 0)
280 all_zeros = false;
281 }
282
283 if (all_zeros)
284 return false;
285
286 debug("%s Common header CRC PASS\n", __func__);
287 return true;
288}
289
Michal Simek394ee242020-08-03 13:01:45 +0200290static int xilinx_read_eeprom_single(char *name,
291 struct xilinx_board_description *desc)
292{
293 int ret;
294 struct udevice *dev;
295 ofnode eeprom;
296 u8 buffer[XILINX_I2C_DETECTION_BITS];
297
298 eeprom = ofnode_get_aliases_node(name);
299 if (!ofnode_valid(eeprom))
300 return -ENODEV;
301
302 ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
303 if (ret)
304 return ret;
305
306 ret = dm_i2c_read(dev, 0, buffer, sizeof(buffer));
307 if (ret) {
308 debug("%s: I2C EEPROM read failed\n", __func__);
309 return ret;
310 }
311
312 debug("%s: i2c memory detected: %s\n", __func__, name);
313
Michal Simek207e0622020-08-03 16:14:23 +0200314 if (CONFIG_IS_ENABLED(CMD_FRU) && xilinx_detect_fru(buffer))
315 return xilinx_read_eeprom_fru(dev, name, desc);
316
Michal Simek394ee242020-08-03 13:01:45 +0200317 if (xilinx_detect_legacy(buffer))
318 return xilinx_read_eeprom_legacy(dev, name, desc);
319
320 return -ENODEV;
321}
322
323__maybe_unused int xilinx_read_eeprom(void)
324{
Michal Simeke98ae1d2021-08-12 12:30:36 +0200325 int id;
Michal Simek394ee242020-08-03 13:01:45 +0200326 char name_buf[8]; /* 8 bytes should be enough for nvmem+number */
Michal Simek0bb24e12020-08-03 12:57:05 +0200327 struct xilinx_board_description *desc;
Michal Simek394ee242020-08-03 13:01:45 +0200328
329 highest_id = dev_read_alias_highest_id("nvmem");
330 /* No nvmem aliases present */
331 if (highest_id < 0)
332 return -EINVAL;
333
Michal Simeke98ae1d2021-08-12 12:30:36 +0200334 board_info = calloc(1, sizeof(*desc) * (highest_id + 1));
Michal Simek394ee242020-08-03 13:01:45 +0200335 if (!board_info)
336 return -ENOMEM;
337
338 debug("%s: Highest ID %d, board_info %p\n", __func__,
339 highest_id, board_info);
340
341 for (id = 0; id <= highest_id; id++) {
342 snprintf(name_buf, sizeof(name_buf), "nvmem%d", id);
343
Michal Simek0bb24e12020-08-03 12:57:05 +0200344 /* Alloc structure */
Michal Simeke98ae1d2021-08-12 12:30:36 +0200345 desc = &board_info[id];
Michal Simek0bb24e12020-08-03 12:57:05 +0200346
Michal Simek394ee242020-08-03 13:01:45 +0200347 /* Ignoring return value for supporting multiple chips */
Michal Simeke98ae1d2021-08-12 12:30:36 +0200348 xilinx_read_eeprom_single(name_buf, desc);
Michal Simek394ee242020-08-03 13:01:45 +0200349 }
350
Michal Simek0bb24e12020-08-03 12:57:05 +0200351 /*
352 * Consider to clean board_info structure when board/cards are not
353 * detected.
354 */
Michal Simek394ee242020-08-03 13:01:45 +0200355
356 return 0;
357}
358
Michal Simek1a505292022-02-17 14:28:38 +0100359#if defined(CONFIG_OF_BOARD)
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300360void *board_fdt_blob_setup(int *err)
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100361{
Michal Simekddf69ae2020-09-04 16:21:47 +0200362 void *fdt_blob;
Michal Simekc89f4292020-03-19 10:23:56 +0100363
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300364 *err = 0;
Michal Simek663c1622021-01-04 11:07:28 +0100365 if (!IS_ENABLED(CONFIG_SPL_BUILD) &&
366 !IS_ENABLED(CONFIG_VERSAL_NO_DDR) &&
Michal Simek6d4317b2021-02-02 13:33:22 +0100367 !IS_ENABLED(CONFIG_ZYNQMP_NO_DDR)) {
Michal Simek9b9d01e2021-01-04 11:03:36 +0100368 fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100369
Michal Simek9b9d01e2021-01-04 11:03:36 +0100370 if (fdt_magic(fdt_blob) == FDT_MAGIC)
371 return fdt_blob;
Michal Simek878ba362019-12-19 17:45:15 +0100372
Michal Simek9b9d01e2021-01-04 11:03:36 +0100373 debug("DTB is not passed via %p\n", fdt_blob);
374 }
Michal Simek878ba362019-12-19 17:45:15 +0100375
Michal Simek9b9d01e2021-01-04 11:03:36 +0100376 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
377 /*
378 * FDT is at end of BSS unless it is in a different memory
379 * region
380 */
381 if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
382 fdt_blob = (ulong *)&_image_binary_end;
383 else
384 fdt_blob = (ulong *)&__bss_end;
385 } else {
386 /* FDT is at end of image */
387 fdt_blob = (ulong *)&_end;
388 }
Michal Simek878ba362019-12-19 17:45:15 +0100389
390 if (fdt_magic(fdt_blob) == FDT_MAGIC)
391 return fdt_blob;
392
393 debug("DTB is also not passed via %p\n", fdt_blob);
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100394
Michal Simek1a505292022-02-17 14:28:38 +0100395 *err = -EINVAL;
Michal Simek878ba362019-12-19 17:45:15 +0100396 return NULL;
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100397}
398#endif
Michal Simek705d44a2020-03-31 12:39:37 +0200399
Michal Simek67ed85d2020-10-22 11:14:20 +0200400#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek0bb24e12020-08-03 12:57:05 +0200401static int env_set_by_index(const char *name, int index, char *data)
402{
403 char var[32];
404
405 if (!index)
406 sprintf(var, "board_%s", name);
407 else
408 sprintf(var, "card%d_%s", index, name);
409
410 return env_set(var, data);
411}
412
Michal Simek705d44a2020-03-31 12:39:37 +0200413int board_late_init_xilinx(void)
414{
Michal Simekbd07b5d2020-08-12 12:16:49 +0200415 u32 ret = 0;
Michal Simek0bb24e12020-08-03 12:57:05 +0200416 int i, id, macid = 0;
417 struct xilinx_board_description *desc;
Ricardo Salvetid35ccf22022-01-20 16:17:30 -0300418 phys_size_t bootm_size = gd->ram_top - gd->ram_base;
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600419
T Karthik Reddy466cdde2021-04-02 01:49:17 -0600420 if (!CONFIG_IS_ENABLED(MICROBLAZE)) {
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600421 ulong scriptaddr;
422
423 scriptaddr = env_get_hex("scriptaddr", 0);
T Karthik Reddy466cdde2021-04-02 01:49:17 -0600424 ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr);
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600425 }
Michal Simekc86ce0c2020-08-12 12:17:53 +0200426
Michal Simek9ccfcae2020-10-23 07:54:18 +0200427 if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
Michal Simekc86ce0c2020-08-12 12:17:53 +0200428 bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
Michal Simekbd07b5d2020-08-12 12:16:49 +0200429
430 ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
431
432 ret |= env_set_addr("bootm_low", (void *)gd->ram_base);
Michal Simekc86ce0c2020-08-12 12:17:53 +0200433 ret |= env_set_addr("bootm_size", (void *)bootm_size);
Michal Simek705d44a2020-03-31 12:39:37 +0200434
Michal Simek0bb24e12020-08-03 12:57:05 +0200435 for (id = 0; id <= highest_id; id++) {
Michal Simeke98ae1d2021-08-12 12:30:36 +0200436 desc = &board_info[id];
Michal Simek0bb24e12020-08-03 12:57:05 +0200437 if (desc && desc->header == EEPROM_HEADER_MAGIC) {
438 if (desc->manufacturer[0])
439 ret |= env_set_by_index("manufacturer", id,
440 desc->manufacturer);
441 if (desc->name[0])
442 ret |= env_set_by_index("name", id,
443 desc->name);
444 if (desc->revision[0])
445 ret |= env_set_by_index("rev", id,
446 desc->revision);
447 if (desc->serial[0])
448 ret |= env_set_by_index("serial", id,
449 desc->serial);
Michal Simek394ee242020-08-03 13:01:45 +0200450
451 if (!CONFIG_IS_ENABLED(NET))
452 continue;
453
Michal Simek0bb24e12020-08-03 12:57:05 +0200454 for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) {
455 if (!desc->mac_addr[i])
Ashok Reddy Soma2d3b1b72022-02-23 15:00:58 +0100456 break;
Michal Simek0bb24e12020-08-03 12:57:05 +0200457
458 if (is_valid_ethaddr((const u8 *)desc->mac_addr[i]))
459 ret |= eth_env_set_enetaddr_by_index("eth",
460 macid++, desc->mac_addr[i]);
461 }
Michal Simek394ee242020-08-03 13:01:45 +0200462 }
463 }
464
Michal Simekbd07b5d2020-08-12 12:16:49 +0200465 if (ret)
466 printf("%s: Saving run time variables FAILED\n", __func__);
Michal Simek8ba62d22020-07-09 15:57:56 +0200467
Michal Simek705d44a2020-03-31 12:39:37 +0200468 return 0;
469}
Michal Simek67ed85d2020-10-22 11:14:20 +0200470#endif
Michal Simekfe49df92020-10-26 12:26:13 +0100471
Michal Simekc88975e2021-07-23 09:55:59 +0200472static char *board_name = DEVICE_TREE;
473
Michal Simekfe49df92020-10-26 12:26:13 +0100474int __maybe_unused board_fit_config_name_match(const char *name)
475{
Michal Simekc88975e2021-07-23 09:55:59 +0200476 debug("%s: Check %s, default %s\n", __func__, name, board_name);
Michal Simekfe49df92020-10-26 12:26:13 +0100477
Michal Simekc88975e2021-07-23 09:55:59 +0200478 if (!strcmp(name, board_name))
Michal Simekfe49df92020-10-26 12:26:13 +0100479 return 0;
480
481 return -1;
482}
T Karthik Reddyc8fa40a2021-08-10 06:50:20 -0600483
484#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_ARCH_ZYNQ)
485int print_cpuinfo(void)
486{
487 struct udevice *soc;
488 char name[SOC_MAX_STR_SIZE];
489 int ret;
490
491 ret = soc_get(&soc);
492 if (ret) {
493 printf("CPU: UNKNOWN\n");
494 return 0;
495 }
496
497 ret = soc_get_family(soc, name, SOC_MAX_STR_SIZE);
498 if (ret)
499 printf("CPU: %s\n", name);
500
501 ret = soc_get_revision(soc, name, SOC_MAX_STR_SIZE);
502 if (ret)
503 printf("Silicon: %s\n", name);
504
505 return 0;
506}
507#endif
Michal Simekafb28572021-07-23 09:59:59 +0200508
509#if CONFIG_IS_ENABLED(DTB_RESELECT)
Michal Simeke0453512021-08-11 14:23:54 +0200510#define MAX_NAME_LENGTH 50
511
Michal Simekafb28572021-07-23 09:59:59 +0200512char * __maybe_unused __weak board_name_decode(void)
513{
Michal Simeke0453512021-08-11 14:23:54 +0200514 char *board_local_name;
515 struct xilinx_board_description *desc;
516 int i, id;
517
518 board_local_name = calloc(1, MAX_NAME_LENGTH);
519 if (!board_info)
520 return NULL;
521
522 for (id = 0; id <= highest_id; id++) {
523 desc = &board_info[id];
524
525 /* No board description */
526 if (!desc)
527 goto error;
528
529 /* Board is not detected */
530 if (desc->header != EEPROM_HEADER_MAGIC)
531 continue;
532
533 /* The first string should be soc name */
534 if (!id)
535 strcat(board_local_name, CONFIG_SYS_BOARD);
536
537 /*
538 * For two purpose here:
539 * soc_name- eg: zynqmp-
540 * and between base board and CC eg: ..revA-sck...
541 */
542 strcat(board_local_name, "-");
543
544 if (desc->name[0]) {
545 /* For DT composition name needs to be lowercase */
546 for (i = 0; i < sizeof(desc->name); i++)
547 desc->name[i] = tolower(desc->name[i]);
548
549 strcat(board_local_name, desc->name);
550 }
551 if (desc->revision[0]) {
552 strcat(board_local_name, "-rev");
553
554 /* And revision needs to be uppercase */
555 for (i = 0; i < sizeof(desc->revision); i++)
556 desc->revision[i] = toupper(desc->revision[i]);
557
558 strcat(board_local_name, desc->revision);
559 }
560 }
561
562 /*
563 * Longer strings will end up with buffer overflow and potential
564 * attacks that's why check it
565 */
566 if (strlen(board_local_name) >= MAX_NAME_LENGTH)
567 panic("Board name can't be determined\n");
568
569 if (strlen(board_local_name))
570 return board_local_name;
571
572error:
573 free(board_local_name);
Michal Simekafb28572021-07-23 09:59:59 +0200574 return NULL;
575}
576
577bool __maybe_unused __weak board_detection(void)
578{
Michal Simeke0453512021-08-11 14:23:54 +0200579 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) {
580 int ret;
581
582 ret = xilinx_read_eeprom();
583 return !ret ? true : false;
584 }
585
Michal Simekafb28572021-07-23 09:59:59 +0200586 return false;
587}
588
589int embedded_dtb_select(void)
590{
591 if (board_detection()) {
592 char *board_local_name;
593
594 board_local_name = board_name_decode();
595 if (board_local_name) {
596 board_name = board_local_name;
Michal Simeke0453512021-08-11 14:23:54 +0200597 printf("Detected name: %s\n", board_name);
Michal Simekafb28572021-07-23 09:59:59 +0200598
599 /* Time to change DTB on fly */
600 /* Both ways should work here */
601 /* fdtdec_resetup(&rescan); */
602 fdtdec_setup();
603 }
604 }
605 return 0;
606}
607#endif