blob: 0068cb879263f467e1f4eae6745aa10eea7b474d [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>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Michal Simek878ba362019-12-19 17:45:15 +010011#include <asm/sections.h>
Michal Simek014d3042019-01-21 15:25:02 +010012#include <dm/uclass.h>
13#include <i2c.h>
Michal Simekb90b97e2020-04-08 10:51:36 +020014#include <linux/sizes.h>
Michal Simek394ee242020-08-03 13:01:45 +020015#include <malloc.h>
Michal Simek705d44a2020-03-31 12:39:37 +020016#include "board.h"
Michal Simek394ee242020-08-03 13:01:45 +020017#include <dm.h>
18#include <i2c_eeprom.h>
19#include <net.h>
Michal Simekfe49df92020-10-26 12:26:13 +010020#include <generated/dt.h>
T Karthik Reddyc8fa40a2021-08-10 06:50:20 -060021#include <soc.h>
Michal Simeke0453512021-08-11 14:23:54 +020022#include <linux/ctype.h>
Michal Simek014d3042019-01-21 15:25:02 +010023
Michal Simek207e0622020-08-03 16:14:23 +020024#include "fru.h"
25
Michal Simekaee22b32020-08-03 12:59:28 +020026#if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
Michal Simek014d3042019-01-21 15:25:02 +010027int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
28{
Michal Simek13db6162019-01-21 16:29:07 +010029 int ret = -EINVAL;
Michal Simek13db6162019-01-21 16:29:07 +010030 struct udevice *dev;
31 ofnode eeprom;
32
33 eeprom = ofnode_get_chosen_node("xlnx,eeprom");
34 if (!ofnode_valid(eeprom))
35 return -ENODEV;
36
37 debug("%s: Path to EEPROM %s\n", __func__,
Simon Glassf3455962020-01-27 08:49:43 -070038 ofnode_read_chosen_string("xlnx,eeprom"));
Michal Simek13db6162019-01-21 16:29:07 +010039
40 ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
41 if (ret)
42 return ret;
43
44 ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
45 if (ret)
46 debug("%s: I2C EEPROM MAC address read failed\n", __func__);
47 else
48 debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
Michal Simek13db6162019-01-21 16:29:07 +010049
50 return ret;
51}
Michal Simekaee22b32020-08-03 12:59:28 +020052#endif
Ibai Erkiaga6f658202019-10-02 15:57:36 +010053
Michal Simek394ee242020-08-03 13:01:45 +020054#define EEPROM_HEADER_MAGIC 0xdaaddeed
55#define EEPROM_HDR_MANUFACTURER_LEN 16
56#define EEPROM_HDR_NAME_LEN 16
57#define EEPROM_HDR_REV_LEN 8
58#define EEPROM_HDR_SERIAL_LEN 20
59#define EEPROM_HDR_NO_OF_MAC_ADDR 4
60#define EEPROM_HDR_ETH_ALEN ETH_ALEN
61
62struct xilinx_board_description {
63 u32 header;
64 char manufacturer[EEPROM_HDR_MANUFACTURER_LEN + 1];
65 char name[EEPROM_HDR_NAME_LEN + 1];
66 char revision[EEPROM_HDR_REV_LEN + 1];
67 char serial[EEPROM_HDR_SERIAL_LEN + 1];
68 u8 mac_addr[EEPROM_HDR_NO_OF_MAC_ADDR][EEPROM_HDR_ETH_ALEN + 1];
69};
70
Michal Simek0bb24e12020-08-03 12:57:05 +020071static int highest_id = -1;
Michal Simeke98ae1d2021-08-12 12:30:36 +020072static struct xilinx_board_description *board_info;
Michal Simek394ee242020-08-03 13:01:45 +020073
Michal Simek207e0622020-08-03 16:14:23 +020074#define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr)
Michal Simek394ee242020-08-03 13:01:45 +020075
76/* Variable which stores pointer to array which stores eeprom content */
77struct xilinx_legacy_format {
78 char board_sn[18]; /* 0x0 */
79 char unused0[14]; /* 0x12 */
80 char eth_mac[6]; /* 0x20 */
81 char unused1[170]; /* 0x26 */
82 char board_name[11]; /* 0xd0 */
83 char unused2[5]; /* 0xdc */
84 char board_revision[3]; /* 0xe0 */
85 char unused3[29]; /* 0xe3 */
86};
87
88static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size)
89{
90 int i;
91 char byte;
92
93 for (i = 0; i < size; i++) {
94 byte = eeprom[i];
95
96 /* Remove all ffs and spaces */
97 if (byte == 0xff || byte == ' ')
98 eeprom[i] = 0;
99
100 /* Convert strings to lower case */
101 if (byte >= 'A' && byte <= 'Z')
102 eeprom[i] = byte + 'a' - 'A';
103 }
104}
105
106static int xilinx_read_eeprom_legacy(struct udevice *dev, char *name,
107 struct xilinx_board_description *desc)
108{
109 int ret, size;
110 struct xilinx_legacy_format *eeprom_content;
111 bool eth_valid = false;
112
113 size = sizeof(*eeprom_content);
114
115 eeprom_content = calloc(1, size);
116 if (!eeprom_content)
117 return -ENOMEM;
118
119 debug("%s: I2C EEPROM read pass data at %p\n", __func__,
120 eeprom_content);
121
122 ret = dm_i2c_read(dev, 0, (uchar *)eeprom_content, size);
123 if (ret) {
124 debug("%s: I2C EEPROM read failed\n", __func__);
125 free(eeprom_content);
126 return ret;
127 }
128
129 xilinx_eeprom_legacy_cleanup((char *)eeprom_content, size);
130
131 printf("Xilinx I2C Legacy format at %s:\n", name);
132 printf(" Board name:\t%s\n", eeprom_content->board_name);
133 printf(" Board rev:\t%s\n", eeprom_content->board_revision);
134 printf(" Board SN:\t%s\n", eeprom_content->board_sn);
135
136 eth_valid = is_valid_ethaddr((const u8 *)eeprom_content->eth_mac);
137 if (eth_valid)
138 printf(" Ethernet mac:\t%pM\n", eeprom_content->eth_mac);
139
140 /* Terminating \0 chars ensure end of string */
141 strcpy(desc->name, eeprom_content->board_name);
142 strcpy(desc->revision, eeprom_content->board_revision);
143 strcpy(desc->serial, eeprom_content->board_sn);
144 if (eth_valid)
145 memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN);
146
147 desc->header = EEPROM_HEADER_MAGIC;
148
149 free(eeprom_content);
150
151 return ret;
152}
153
154static bool xilinx_detect_legacy(u8 *buffer)
155{
156 int i;
157 char c;
158
159 for (i = 0; i < XILINX_I2C_DETECTION_BITS; i++) {
160 c = buffer[i];
161
162 if (c < '0' || c > '9')
163 return false;
164 }
165
166 return true;
167}
168
Michal Simek207e0622020-08-03 16:14:23 +0200169static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
170 struct xilinx_board_description *desc)
171{
Michal Simekbe5f5722021-08-12 11:03:49 +0200172 int i, ret, eeprom_size;
Michal Simek207e0622020-08-03 16:14:23 +0200173 u8 *fru_content;
174
175 /* FIXME this is shortcut - if eeprom type is wrong it will fail */
176 eeprom_size = i2c_eeprom_size(dev);
177
178 fru_content = calloc(1, eeprom_size);
179 if (!fru_content)
180 return -ENOMEM;
181
182 debug("%s: I2C EEPROM read pass data at %p\n", __func__,
183 fru_content);
184
185 ret = dm_i2c_read(dev, 0, (uchar *)fru_content,
186 eeprom_size);
187 if (ret) {
188 debug("%s: I2C EEPROM read failed\n", __func__);
Michal Simekaada8a62021-08-13 09:17:10 +0200189 goto end;
Michal Simek207e0622020-08-03 16:14:23 +0200190 }
191
Michal Simek207e0622020-08-03 16:14:23 +0200192 fru_capture((unsigned long)fru_content);
Michal Simeke0453512021-08-11 14:23:54 +0200193 if (gd->flags & GD_FLG_RELOC || (_DEBUG && CONFIG_IS_ENABLED(DTB_RESELECT))) {
194 printf("Xilinx I2C FRU format at %s:\n", name);
195 ret = fru_display(0);
196 if (ret) {
197 printf("FRU format decoding failed.\n");
198 goto end;
199 }
Michal Simek207e0622020-08-03 16:14:23 +0200200 }
201
202 if (desc->header == EEPROM_HEADER_MAGIC) {
203 debug("Information already filled\n");
Michal Simekaada8a62021-08-13 09:17:10 +0200204 ret = -EINVAL;
205 goto end;
Michal Simek207e0622020-08-03 16:14:23 +0200206 }
207
208 /* It is clear that FRU was captured and structures were filled */
209 strncpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name,
210 sizeof(desc->manufacturer));
211 strncpy(desc->name, (char *)fru_data.brd.product_name,
212 sizeof(desc->name));
Michal Simekbe5f5722021-08-12 11:03:49 +0200213 for (i = 0; i < sizeof(desc->name); i++) {
214 if (desc->name[i] == ' ')
215 desc->name[i] = '\0';
216 }
Michal Simek207e0622020-08-03 16:14:23 +0200217 strncpy(desc->revision, (char *)fru_data.brd.rev,
218 sizeof(desc->revision));
219 strncpy(desc->serial, (char *)fru_data.brd.serial_number,
220 sizeof(desc->serial));
221 desc->header = EEPROM_HEADER_MAGIC;
222
Michal Simekaada8a62021-08-13 09:17:10 +0200223end:
224 free(fru_content);
225 return ret;
Michal Simek207e0622020-08-03 16:14:23 +0200226}
227
228static bool xilinx_detect_fru(u8 *buffer)
229{
230 u8 checksum = 0;
231 int i;
232
233 checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr));
234 if (checksum) {
235 debug("%s Common header CRC FAIL\n", __func__);
236 return false;
237 }
238
239 bool all_zeros = true;
240 /* Checksum over all zeros is also zero that's why detect this case */
241 for (i = 0; i < sizeof(struct fru_common_hdr); i++) {
242 if (buffer[i] != 0)
243 all_zeros = false;
244 }
245
246 if (all_zeros)
247 return false;
248
249 debug("%s Common header CRC PASS\n", __func__);
250 return true;
251}
252
Michal Simek394ee242020-08-03 13:01:45 +0200253static int xilinx_read_eeprom_single(char *name,
254 struct xilinx_board_description *desc)
255{
256 int ret;
257 struct udevice *dev;
258 ofnode eeprom;
259 u8 buffer[XILINX_I2C_DETECTION_BITS];
260
261 eeprom = ofnode_get_aliases_node(name);
262 if (!ofnode_valid(eeprom))
263 return -ENODEV;
264
265 ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
266 if (ret)
267 return ret;
268
269 ret = dm_i2c_read(dev, 0, buffer, sizeof(buffer));
270 if (ret) {
271 debug("%s: I2C EEPROM read failed\n", __func__);
272 return ret;
273 }
274
275 debug("%s: i2c memory detected: %s\n", __func__, name);
276
Michal Simek207e0622020-08-03 16:14:23 +0200277 if (CONFIG_IS_ENABLED(CMD_FRU) && xilinx_detect_fru(buffer))
278 return xilinx_read_eeprom_fru(dev, name, desc);
279
Michal Simek394ee242020-08-03 13:01:45 +0200280 if (xilinx_detect_legacy(buffer))
281 return xilinx_read_eeprom_legacy(dev, name, desc);
282
283 return -ENODEV;
284}
285
286__maybe_unused int xilinx_read_eeprom(void)
287{
Michal Simeke98ae1d2021-08-12 12:30:36 +0200288 int id;
Michal Simek394ee242020-08-03 13:01:45 +0200289 char name_buf[8]; /* 8 bytes should be enough for nvmem+number */
Michal Simek0bb24e12020-08-03 12:57:05 +0200290 struct xilinx_board_description *desc;
Michal Simek394ee242020-08-03 13:01:45 +0200291
292 highest_id = dev_read_alias_highest_id("nvmem");
293 /* No nvmem aliases present */
294 if (highest_id < 0)
295 return -EINVAL;
296
Michal Simeke98ae1d2021-08-12 12:30:36 +0200297 board_info = calloc(1, sizeof(*desc) * (highest_id + 1));
Michal Simek394ee242020-08-03 13:01:45 +0200298 if (!board_info)
299 return -ENOMEM;
300
301 debug("%s: Highest ID %d, board_info %p\n", __func__,
302 highest_id, board_info);
303
304 for (id = 0; id <= highest_id; id++) {
305 snprintf(name_buf, sizeof(name_buf), "nvmem%d", id);
306
Michal Simek0bb24e12020-08-03 12:57:05 +0200307 /* Alloc structure */
Michal Simeke98ae1d2021-08-12 12:30:36 +0200308 desc = &board_info[id];
Michal Simek0bb24e12020-08-03 12:57:05 +0200309
Michal Simek394ee242020-08-03 13:01:45 +0200310 /* Ignoring return value for supporting multiple chips */
Michal Simeke98ae1d2021-08-12 12:30:36 +0200311 xilinx_read_eeprom_single(name_buf, desc);
Michal Simek394ee242020-08-03 13:01:45 +0200312 }
313
Michal Simek0bb24e12020-08-03 12:57:05 +0200314 /*
315 * Consider to clean board_info structure when board/cards are not
316 * detected.
317 */
Michal Simek394ee242020-08-03 13:01:45 +0200318
319 return 0;
320}
321
Michal Simek1a505292022-02-17 14:28:38 +0100322#if defined(CONFIG_OF_BOARD)
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300323void *board_fdt_blob_setup(int *err)
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100324{
Michal Simekddf69ae2020-09-04 16:21:47 +0200325 void *fdt_blob;
Michal Simekc89f4292020-03-19 10:23:56 +0100326
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300327 *err = 0;
Michal Simek663c1622021-01-04 11:07:28 +0100328 if (!IS_ENABLED(CONFIG_SPL_BUILD) &&
329 !IS_ENABLED(CONFIG_VERSAL_NO_DDR) &&
Michal Simek6d4317b2021-02-02 13:33:22 +0100330 !IS_ENABLED(CONFIG_ZYNQMP_NO_DDR)) {
Michal Simek9b9d01e2021-01-04 11:03:36 +0100331 fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100332
Michal Simek9b9d01e2021-01-04 11:03:36 +0100333 if (fdt_magic(fdt_blob) == FDT_MAGIC)
334 return fdt_blob;
Michal Simek878ba362019-12-19 17:45:15 +0100335
Michal Simek9b9d01e2021-01-04 11:03:36 +0100336 debug("DTB is not passed via %p\n", fdt_blob);
337 }
Michal Simek878ba362019-12-19 17:45:15 +0100338
Michal Simek9b9d01e2021-01-04 11:03:36 +0100339 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
340 /*
341 * FDT is at end of BSS unless it is in a different memory
342 * region
343 */
344 if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
345 fdt_blob = (ulong *)&_image_binary_end;
346 else
347 fdt_blob = (ulong *)&__bss_end;
348 } else {
349 /* FDT is at end of image */
350 fdt_blob = (ulong *)&_end;
351 }
Michal Simek878ba362019-12-19 17:45:15 +0100352
353 if (fdt_magic(fdt_blob) == FDT_MAGIC)
354 return fdt_blob;
355
356 debug("DTB is also not passed via %p\n", fdt_blob);
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100357
Michal Simek1a505292022-02-17 14:28:38 +0100358 *err = -EINVAL;
Michal Simek878ba362019-12-19 17:45:15 +0100359 return NULL;
Ibai Erkiaga6f658202019-10-02 15:57:36 +0100360}
361#endif
Michal Simek705d44a2020-03-31 12:39:37 +0200362
Michal Simek67ed85d2020-10-22 11:14:20 +0200363#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek0bb24e12020-08-03 12:57:05 +0200364static int env_set_by_index(const char *name, int index, char *data)
365{
366 char var[32];
367
368 if (!index)
369 sprintf(var, "board_%s", name);
370 else
371 sprintf(var, "card%d_%s", index, name);
372
373 return env_set(var, data);
374}
375
Michal Simek705d44a2020-03-31 12:39:37 +0200376int board_late_init_xilinx(void)
377{
Michal Simekbd07b5d2020-08-12 12:16:49 +0200378 u32 ret = 0;
Michal Simek0bb24e12020-08-03 12:57:05 +0200379 int i, id, macid = 0;
380 struct xilinx_board_description *desc;
Ricardo Salvetid35ccf22022-01-20 16:17:30 -0300381 phys_size_t bootm_size = gd->ram_top - gd->ram_base;
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600382
T Karthik Reddy466cdde2021-04-02 01:49:17 -0600383 if (!CONFIG_IS_ENABLED(MICROBLAZE)) {
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600384 ulong scriptaddr;
385
386 scriptaddr = env_get_hex("scriptaddr", 0);
T Karthik Reddy466cdde2021-04-02 01:49:17 -0600387 ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr);
T Karthik Reddy17b7f662020-04-01 06:01:21 -0600388 }
Michal Simekc86ce0c2020-08-12 12:17:53 +0200389
Michal Simek9ccfcae2020-10-23 07:54:18 +0200390 if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
Michal Simekc86ce0c2020-08-12 12:17:53 +0200391 bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
Michal Simekbd07b5d2020-08-12 12:16:49 +0200392
393 ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
394
395 ret |= env_set_addr("bootm_low", (void *)gd->ram_base);
Michal Simekc86ce0c2020-08-12 12:17:53 +0200396 ret |= env_set_addr("bootm_size", (void *)bootm_size);
Michal Simek705d44a2020-03-31 12:39:37 +0200397
Michal Simek0bb24e12020-08-03 12:57:05 +0200398 for (id = 0; id <= highest_id; id++) {
Michal Simeke98ae1d2021-08-12 12:30:36 +0200399 desc = &board_info[id];
Michal Simek0bb24e12020-08-03 12:57:05 +0200400 if (desc && desc->header == EEPROM_HEADER_MAGIC) {
401 if (desc->manufacturer[0])
402 ret |= env_set_by_index("manufacturer", id,
403 desc->manufacturer);
404 if (desc->name[0])
405 ret |= env_set_by_index("name", id,
406 desc->name);
407 if (desc->revision[0])
408 ret |= env_set_by_index("rev", id,
409 desc->revision);
410 if (desc->serial[0])
411 ret |= env_set_by_index("serial", id,
412 desc->serial);
Michal Simek394ee242020-08-03 13:01:45 +0200413
414 if (!CONFIG_IS_ENABLED(NET))
415 continue;
416
Michal Simek0bb24e12020-08-03 12:57:05 +0200417 for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) {
418 if (!desc->mac_addr[i])
419 continue;
420
421 if (is_valid_ethaddr((const u8 *)desc->mac_addr[i]))
422 ret |= eth_env_set_enetaddr_by_index("eth",
423 macid++, desc->mac_addr[i]);
424 }
Michal Simek394ee242020-08-03 13:01:45 +0200425 }
426 }
427
Michal Simekbd07b5d2020-08-12 12:16:49 +0200428 if (ret)
429 printf("%s: Saving run time variables FAILED\n", __func__);
Michal Simek8ba62d22020-07-09 15:57:56 +0200430
Michal Simek705d44a2020-03-31 12:39:37 +0200431 return 0;
432}
Michal Simek67ed85d2020-10-22 11:14:20 +0200433#endif
Michal Simekfe49df92020-10-26 12:26:13 +0100434
Michal Simekc88975e2021-07-23 09:55:59 +0200435static char *board_name = DEVICE_TREE;
436
Michal Simekfe49df92020-10-26 12:26:13 +0100437int __maybe_unused board_fit_config_name_match(const char *name)
438{
Michal Simekc88975e2021-07-23 09:55:59 +0200439 debug("%s: Check %s, default %s\n", __func__, name, board_name);
Michal Simekfe49df92020-10-26 12:26:13 +0100440
Michal Simekc88975e2021-07-23 09:55:59 +0200441 if (!strcmp(name, board_name))
Michal Simekfe49df92020-10-26 12:26:13 +0100442 return 0;
443
444 return -1;
445}
T Karthik Reddyc8fa40a2021-08-10 06:50:20 -0600446
447#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_ARCH_ZYNQ)
448int print_cpuinfo(void)
449{
450 struct udevice *soc;
451 char name[SOC_MAX_STR_SIZE];
452 int ret;
453
454 ret = soc_get(&soc);
455 if (ret) {
456 printf("CPU: UNKNOWN\n");
457 return 0;
458 }
459
460 ret = soc_get_family(soc, name, SOC_MAX_STR_SIZE);
461 if (ret)
462 printf("CPU: %s\n", name);
463
464 ret = soc_get_revision(soc, name, SOC_MAX_STR_SIZE);
465 if (ret)
466 printf("Silicon: %s\n", name);
467
468 return 0;
469}
470#endif
Michal Simekafb28572021-07-23 09:59:59 +0200471
472#if CONFIG_IS_ENABLED(DTB_RESELECT)
Michal Simeke0453512021-08-11 14:23:54 +0200473#define MAX_NAME_LENGTH 50
474
Michal Simekafb28572021-07-23 09:59:59 +0200475char * __maybe_unused __weak board_name_decode(void)
476{
Michal Simeke0453512021-08-11 14:23:54 +0200477 char *board_local_name;
478 struct xilinx_board_description *desc;
479 int i, id;
480
481 board_local_name = calloc(1, MAX_NAME_LENGTH);
482 if (!board_info)
483 return NULL;
484
485 for (id = 0; id <= highest_id; id++) {
486 desc = &board_info[id];
487
488 /* No board description */
489 if (!desc)
490 goto error;
491
492 /* Board is not detected */
493 if (desc->header != EEPROM_HEADER_MAGIC)
494 continue;
495
496 /* The first string should be soc name */
497 if (!id)
498 strcat(board_local_name, CONFIG_SYS_BOARD);
499
500 /*
501 * For two purpose here:
502 * soc_name- eg: zynqmp-
503 * and between base board and CC eg: ..revA-sck...
504 */
505 strcat(board_local_name, "-");
506
507 if (desc->name[0]) {
508 /* For DT composition name needs to be lowercase */
509 for (i = 0; i < sizeof(desc->name); i++)
510 desc->name[i] = tolower(desc->name[i]);
511
512 strcat(board_local_name, desc->name);
513 }
514 if (desc->revision[0]) {
515 strcat(board_local_name, "-rev");
516
517 /* And revision needs to be uppercase */
518 for (i = 0; i < sizeof(desc->revision); i++)
519 desc->revision[i] = toupper(desc->revision[i]);
520
521 strcat(board_local_name, desc->revision);
522 }
523 }
524
525 /*
526 * Longer strings will end up with buffer overflow and potential
527 * attacks that's why check it
528 */
529 if (strlen(board_local_name) >= MAX_NAME_LENGTH)
530 panic("Board name can't be determined\n");
531
532 if (strlen(board_local_name))
533 return board_local_name;
534
535error:
536 free(board_local_name);
Michal Simekafb28572021-07-23 09:59:59 +0200537 return NULL;
538}
539
540bool __maybe_unused __weak board_detection(void)
541{
Michal Simeke0453512021-08-11 14:23:54 +0200542 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) {
543 int ret;
544
545 ret = xilinx_read_eeprom();
546 return !ret ? true : false;
547 }
548
Michal Simekafb28572021-07-23 09:59:59 +0200549 return false;
550}
551
552int embedded_dtb_select(void)
553{
554 if (board_detection()) {
555 char *board_local_name;
556
557 board_local_name = board_name_decode();
558 if (board_local_name) {
559 board_name = board_local_name;
Michal Simeke0453512021-08-11 14:23:54 +0200560 printf("Detected name: %s\n", board_name);
Michal Simekafb28572021-07-23 09:59:59 +0200561
562 /* Time to change DTB on fly */
563 /* Both ways should work here */
564 /* fdtdec_resetup(&rescan); */
565 fdtdec_setup();
566 }
567 }
568 return 0;
569}
570#endif