2019-01-21 14:25:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2023-01-06 08:38:52 +00:00
|
|
|
* (C) Copyright 2014 - 2022, Xilinx, Inc.
|
|
|
|
* (C) Copyright 2022 - 2023, Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Michal Simek <michal.simek@amd.com>
|
2019-01-21 14:25:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2022-04-15 05:59:34 +00:00
|
|
|
#include <efi.h>
|
|
|
|
#include <efi_loader.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <env.h>
|
2022-08-25 12:23:10 +00:00
|
|
|
#include <image.h>
|
|
|
|
#include <lmb.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2019-12-19 16:45:15 +00:00
|
|
|
#include <asm/sections.h>
|
2019-01-21 14:25:02 +00:00
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <i2c.h>
|
2020-04-08 08:51:36 +00:00
|
|
|
#include <linux/sizes.h>
|
2020-08-03 11:01:45 +00:00
|
|
|
#include <malloc.h>
|
2020-03-31 10:39:37 +00:00
|
|
|
#include "board.h"
|
2020-08-03 11:01:45 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <i2c_eeprom.h>
|
|
|
|
#include <net.h>
|
2020-10-26 11:26:13 +00:00
|
|
|
#include <generated/dt.h>
|
2023-01-06 08:38:52 +00:00
|
|
|
#include <slre.h>
|
2021-08-10 12:50:20 +00:00
|
|
|
#include <soc.h>
|
2021-08-11 12:23:54 +00:00
|
|
|
#include <linux/ctype.h>
|
2022-04-15 05:59:34 +00:00
|
|
|
#include <linux/kernel.h>
|
2022-07-21 14:19:17 +00:00
|
|
|
#include <uuid.h>
|
2019-01-21 14:25:02 +00:00
|
|
|
|
2020-08-03 14:14:23 +00:00
|
|
|
#include "fru.h"
|
|
|
|
|
2022-04-15 05:59:34 +00:00
|
|
|
#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
|
|
|
|
struct efi_fw_image fw_images[] = {
|
|
|
|
#if defined(XILINX_BOOT_IMAGE_GUID)
|
|
|
|
{
|
|
|
|
.image_type_id = XILINX_BOOT_IMAGE_GUID,
|
|
|
|
.fw_name = u"XILINX-BOOT",
|
|
|
|
.image_index = 1,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(XILINX_UBOOT_IMAGE_GUID)
|
|
|
|
{
|
|
|
|
.image_type_id = XILINX_UBOOT_IMAGE_GUID,
|
|
|
|
.fw_name = u"XILINX-UBOOT",
|
|
|
|
.image_index = 2,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct efi_capsule_update_info update_info = {
|
|
|
|
.images = fw_images,
|
|
|
|
};
|
|
|
|
|
|
|
|
u8 num_image_type_guids = ARRAY_SIZE(fw_images);
|
|
|
|
#endif /* EFI_HAVE_CAPSULE_SUPPORT */
|
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
#define EEPROM_HEADER_MAGIC 0xdaaddeed
|
|
|
|
#define EEPROM_HDR_MANUFACTURER_LEN 16
|
|
|
|
#define EEPROM_HDR_NAME_LEN 16
|
|
|
|
#define EEPROM_HDR_REV_LEN 8
|
|
|
|
#define EEPROM_HDR_SERIAL_LEN 20
|
|
|
|
#define EEPROM_HDR_NO_OF_MAC_ADDR 4
|
|
|
|
#define EEPROM_HDR_ETH_ALEN ETH_ALEN
|
2022-07-21 14:19:17 +00:00
|
|
|
#define EEPROM_HDR_UUID_LEN 16
|
2020-08-03 11:01:45 +00:00
|
|
|
|
|
|
|
struct xilinx_board_description {
|
|
|
|
u32 header;
|
|
|
|
char manufacturer[EEPROM_HDR_MANUFACTURER_LEN + 1];
|
|
|
|
char name[EEPROM_HDR_NAME_LEN + 1];
|
|
|
|
char revision[EEPROM_HDR_REV_LEN + 1];
|
|
|
|
char serial[EEPROM_HDR_SERIAL_LEN + 1];
|
|
|
|
u8 mac_addr[EEPROM_HDR_NO_OF_MAC_ADDR][EEPROM_HDR_ETH_ALEN + 1];
|
2022-07-21 14:19:17 +00:00
|
|
|
char uuid[EEPROM_HDR_UUID_LEN + 1];
|
2020-08-03 11:01:45 +00:00
|
|
|
};
|
|
|
|
|
2020-08-03 10:57:05 +00:00
|
|
|
static int highest_id = -1;
|
2021-08-12 10:30:36 +00:00
|
|
|
static struct xilinx_board_description *board_info;
|
2020-08-03 11:01:45 +00:00
|
|
|
|
2020-08-03 14:14:23 +00:00
|
|
|
#define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr)
|
2020-08-03 11:01:45 +00:00
|
|
|
|
|
|
|
/* Variable which stores pointer to array which stores eeprom content */
|
|
|
|
struct xilinx_legacy_format {
|
|
|
|
char board_sn[18]; /* 0x0 */
|
|
|
|
char unused0[14]; /* 0x12 */
|
|
|
|
char eth_mac[6]; /* 0x20 */
|
|
|
|
char unused1[170]; /* 0x26 */
|
|
|
|
char board_name[11]; /* 0xd0 */
|
|
|
|
char unused2[5]; /* 0xdc */
|
|
|
|
char board_revision[3]; /* 0xe0 */
|
|
|
|
char unused3[29]; /* 0xe3 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size)
|
|
|
|
{
|
|
|
|
int i;
|
2022-09-26 06:52:42 +00:00
|
|
|
unsigned char byte;
|
2020-08-03 11:01:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
byte = eeprom[i];
|
|
|
|
|
|
|
|
/* Remove all ffs and spaces */
|
|
|
|
if (byte == 0xff || byte == ' ')
|
|
|
|
eeprom[i] = 0;
|
|
|
|
|
|
|
|
/* Convert strings to lower case */
|
|
|
|
if (byte >= 'A' && byte <= 'Z')
|
|
|
|
eeprom[i] = byte + 'a' - 'A';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xilinx_read_eeprom_legacy(struct udevice *dev, char *name,
|
|
|
|
struct xilinx_board_description *desc)
|
|
|
|
{
|
|
|
|
int ret, size;
|
|
|
|
struct xilinx_legacy_format *eeprom_content;
|
|
|
|
bool eth_valid = false;
|
|
|
|
|
|
|
|
size = sizeof(*eeprom_content);
|
|
|
|
|
|
|
|
eeprom_content = calloc(1, size);
|
|
|
|
if (!eeprom_content)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
debug("%s: I2C EEPROM read pass data at %p\n", __func__,
|
|
|
|
eeprom_content);
|
|
|
|
|
|
|
|
ret = dm_i2c_read(dev, 0, (uchar *)eeprom_content, size);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: I2C EEPROM read failed\n", __func__);
|
|
|
|
free(eeprom_content);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
xilinx_eeprom_legacy_cleanup((char *)eeprom_content, size);
|
|
|
|
|
|
|
|
printf("Xilinx I2C Legacy format at %s:\n", name);
|
|
|
|
printf(" Board name:\t%s\n", eeprom_content->board_name);
|
|
|
|
printf(" Board rev:\t%s\n", eeprom_content->board_revision);
|
|
|
|
printf(" Board SN:\t%s\n", eeprom_content->board_sn);
|
|
|
|
|
|
|
|
eth_valid = is_valid_ethaddr((const u8 *)eeprom_content->eth_mac);
|
|
|
|
if (eth_valid)
|
|
|
|
printf(" Ethernet mac:\t%pM\n", eeprom_content->eth_mac);
|
|
|
|
|
|
|
|
/* Terminating \0 chars ensure end of string */
|
|
|
|
strcpy(desc->name, eeprom_content->board_name);
|
|
|
|
strcpy(desc->revision, eeprom_content->board_revision);
|
|
|
|
strcpy(desc->serial, eeprom_content->board_sn);
|
|
|
|
if (eth_valid)
|
|
|
|
memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN);
|
|
|
|
|
|
|
|
desc->header = EEPROM_HEADER_MAGIC;
|
|
|
|
|
|
|
|
free(eeprom_content);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool xilinx_detect_legacy(u8 *buffer)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
for (i = 0; i < XILINX_I2C_DETECTION_BITS; i++) {
|
|
|
|
c = buffer[i];
|
|
|
|
|
|
|
|
if (c < '0' || c > '9')
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-03 14:14:23 +00:00
|
|
|
static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
|
|
|
|
struct xilinx_board_description *desc)
|
|
|
|
{
|
2021-08-12 09:03:49 +00:00
|
|
|
int i, ret, eeprom_size;
|
2020-08-03 14:14:23 +00:00
|
|
|
u8 *fru_content;
|
2022-02-23 14:00:59 +00:00
|
|
|
u8 id = 0;
|
2020-08-03 14:14:23 +00:00
|
|
|
|
|
|
|
/* FIXME this is shortcut - if eeprom type is wrong it will fail */
|
|
|
|
eeprom_size = i2c_eeprom_size(dev);
|
|
|
|
|
|
|
|
fru_content = calloc(1, eeprom_size);
|
|
|
|
if (!fru_content)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
debug("%s: I2C EEPROM read pass data at %p\n", __func__,
|
|
|
|
fru_content);
|
|
|
|
|
|
|
|
ret = dm_i2c_read(dev, 0, (uchar *)fru_content,
|
|
|
|
eeprom_size);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: I2C EEPROM read failed\n", __func__);
|
2021-08-13 07:17:10 +00:00
|
|
|
goto end;
|
2020-08-03 14:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fru_capture((unsigned long)fru_content);
|
2021-08-11 12:23:54 +00:00
|
|
|
if (gd->flags & GD_FLG_RELOC || (_DEBUG && CONFIG_IS_ENABLED(DTB_RESELECT))) {
|
|
|
|
printf("Xilinx I2C FRU format at %s:\n", name);
|
|
|
|
ret = fru_display(0);
|
|
|
|
if (ret) {
|
|
|
|
printf("FRU format decoding failed.\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2020-08-03 14:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->header == EEPROM_HEADER_MAGIC) {
|
|
|
|
debug("Information already filled\n");
|
2021-08-13 07:17:10 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
2020-08-03 14:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* It is clear that FRU was captured and structures were filled */
|
2022-07-21 14:19:18 +00:00
|
|
|
strlcpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name,
|
2020-08-03 14:14:23 +00:00
|
|
|
sizeof(desc->manufacturer));
|
2022-07-21 14:19:18 +00:00
|
|
|
strlcpy(desc->uuid, (char *)fru_data.brd.uuid,
|
2022-07-21 14:19:17 +00:00
|
|
|
sizeof(desc->uuid));
|
2022-07-21 14:19:18 +00:00
|
|
|
strlcpy(desc->name, (char *)fru_data.brd.product_name,
|
2020-08-03 14:14:23 +00:00
|
|
|
sizeof(desc->name));
|
2021-08-12 09:03:49 +00:00
|
|
|
for (i = 0; i < sizeof(desc->name); i++) {
|
|
|
|
if (desc->name[i] == ' ')
|
|
|
|
desc->name[i] = '\0';
|
|
|
|
}
|
2022-07-21 14:19:18 +00:00
|
|
|
strlcpy(desc->revision, (char *)fru_data.brd.rev,
|
2020-08-03 14:14:23 +00:00
|
|
|
sizeof(desc->revision));
|
2022-06-06 07:31:27 +00:00
|
|
|
for (i = 0; i < sizeof(desc->revision); i++) {
|
|
|
|
if (desc->revision[i] == ' ')
|
|
|
|
desc->revision[i] = '\0';
|
|
|
|
}
|
2022-07-21 14:19:18 +00:00
|
|
|
strlcpy(desc->serial, (char *)fru_data.brd.serial_number,
|
2020-08-03 14:14:23 +00:00
|
|
|
sizeof(desc->serial));
|
2022-02-23 14:00:59 +00:00
|
|
|
|
|
|
|
while (id < EEPROM_HDR_NO_OF_MAC_ADDR) {
|
|
|
|
if (is_valid_ethaddr((const u8 *)fru_data.mac.macid[id]))
|
|
|
|
memcpy(&desc->mac_addr[id],
|
|
|
|
(char *)fru_data.mac.macid[id], ETH_ALEN);
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
|
2020-08-03 14:14:23 +00:00
|
|
|
desc->header = EEPROM_HEADER_MAGIC;
|
|
|
|
|
2021-08-13 07:17:10 +00:00
|
|
|
end:
|
|
|
|
free(fru_content);
|
|
|
|
return ret;
|
2020-08-03 14:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool xilinx_detect_fru(u8 *buffer)
|
|
|
|
{
|
|
|
|
u8 checksum = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr));
|
|
|
|
if (checksum) {
|
|
|
|
debug("%s Common header CRC FAIL\n", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool all_zeros = true;
|
|
|
|
/* Checksum over all zeros is also zero that's why detect this case */
|
|
|
|
for (i = 0; i < sizeof(struct fru_common_hdr); i++) {
|
|
|
|
if (buffer[i] != 0)
|
|
|
|
all_zeros = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_zeros)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
debug("%s Common header CRC PASS\n", __func__);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
static int xilinx_read_eeprom_single(char *name,
|
|
|
|
struct xilinx_board_description *desc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
ofnode eeprom;
|
|
|
|
u8 buffer[XILINX_I2C_DETECTION_BITS];
|
|
|
|
|
|
|
|
eeprom = ofnode_get_aliases_node(name);
|
|
|
|
if (!ofnode_valid(eeprom))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = dm_i2c_read(dev, 0, buffer, sizeof(buffer));
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: I2C EEPROM read failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("%s: i2c memory detected: %s\n", __func__, name);
|
|
|
|
|
2020-08-03 14:14:23 +00:00
|
|
|
if (CONFIG_IS_ENABLED(CMD_FRU) && xilinx_detect_fru(buffer))
|
|
|
|
return xilinx_read_eeprom_fru(dev, name, desc);
|
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
if (xilinx_detect_legacy(buffer))
|
|
|
|
return xilinx_read_eeprom_legacy(dev, name, desc);
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
__maybe_unused int xilinx_read_eeprom(void)
|
|
|
|
{
|
2021-08-12 10:30:36 +00:00
|
|
|
int id;
|
2020-08-03 11:01:45 +00:00
|
|
|
char name_buf[8]; /* 8 bytes should be enough for nvmem+number */
|
2020-08-03 10:57:05 +00:00
|
|
|
struct xilinx_board_description *desc;
|
2020-08-03 11:01:45 +00:00
|
|
|
|
|
|
|
highest_id = dev_read_alias_highest_id("nvmem");
|
|
|
|
/* No nvmem aliases present */
|
|
|
|
if (highest_id < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-08-12 10:30:36 +00:00
|
|
|
board_info = calloc(1, sizeof(*desc) * (highest_id + 1));
|
2020-08-03 11:01:45 +00:00
|
|
|
if (!board_info)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
debug("%s: Highest ID %d, board_info %p\n", __func__,
|
|
|
|
highest_id, board_info);
|
|
|
|
|
|
|
|
for (id = 0; id <= highest_id; id++) {
|
|
|
|
snprintf(name_buf, sizeof(name_buf), "nvmem%d", id);
|
|
|
|
|
2020-08-03 10:57:05 +00:00
|
|
|
/* Alloc structure */
|
2021-08-12 10:30:36 +00:00
|
|
|
desc = &board_info[id];
|
2020-08-03 10:57:05 +00:00
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
/* Ignoring return value for supporting multiple chips */
|
2021-08-12 10:30:36 +00:00
|
|
|
xilinx_read_eeprom_single(name_buf, desc);
|
2020-08-03 11:01:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-03 10:57:05 +00:00
|
|
|
/*
|
|
|
|
* Consider to clean board_info structure when board/cards are not
|
|
|
|
* detected.
|
|
|
|
*/
|
2020-08-03 11:01:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-17 13:28:38 +00:00
|
|
|
#if defined(CONFIG_OF_BOARD)
|
2021-10-26 06:12:33 +00:00
|
|
|
void *board_fdt_blob_setup(int *err)
|
2019-10-02 14:57:36 +00:00
|
|
|
{
|
2020-09-04 14:21:47 +00:00
|
|
|
void *fdt_blob;
|
2020-03-19 09:23:56 +00:00
|
|
|
|
2021-10-26 06:12:33 +00:00
|
|
|
*err = 0;
|
2021-01-04 10:07:28 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_SPL_BUILD) &&
|
|
|
|
!IS_ENABLED(CONFIG_VERSAL_NO_DDR) &&
|
2021-02-02 12:33:22 +00:00
|
|
|
!IS_ENABLED(CONFIG_ZYNQMP_NO_DDR)) {
|
2021-01-04 10:03:36 +00:00
|
|
|
fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
|
2019-10-02 14:57:36 +00:00
|
|
|
|
2021-01-04 10:03:36 +00:00
|
|
|
if (fdt_magic(fdt_blob) == FDT_MAGIC)
|
|
|
|
return fdt_blob;
|
2019-10-02 14:57:36 +00:00
|
|
|
|
2021-01-04 10:03:36 +00:00
|
|
|
debug("DTB is not passed via %p\n", fdt_blob);
|
|
|
|
}
|
2019-12-19 16:45:15 +00:00
|
|
|
|
2021-01-04 10:03:36 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD)) {
|
|
|
|
/*
|
|
|
|
* FDT is at end of BSS unless it is in a different memory
|
|
|
|
* region
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
|
|
|
|
fdt_blob = (ulong *)&_image_binary_end;
|
|
|
|
else
|
|
|
|
fdt_blob = (ulong *)&__bss_end;
|
|
|
|
} else {
|
|
|
|
/* FDT is at end of image */
|
|
|
|
fdt_blob = (ulong *)&_end;
|
|
|
|
}
|
2019-12-19 16:45:15 +00:00
|
|
|
|
|
|
|
if (fdt_magic(fdt_blob) == FDT_MAGIC)
|
|
|
|
return fdt_blob;
|
|
|
|
|
|
|
|
debug("DTB is also not passed via %p\n", fdt_blob);
|
|
|
|
|
2022-02-17 13:28:38 +00:00
|
|
|
*err = -EINVAL;
|
2019-12-19 16:45:15 +00:00
|
|
|
return NULL;
|
2019-10-02 14:57:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-03-31 10:39:37 +00:00
|
|
|
|
2020-10-22 09:14:20 +00:00
|
|
|
#if defined(CONFIG_BOARD_LATE_INIT)
|
2020-08-03 10:57:05 +00:00
|
|
|
static int env_set_by_index(const char *name, int index, char *data)
|
|
|
|
{
|
|
|
|
char var[32];
|
|
|
|
|
|
|
|
if (!index)
|
|
|
|
sprintf(var, "board_%s", name);
|
|
|
|
else
|
|
|
|
sprintf(var, "card%d_%s", index, name);
|
|
|
|
|
|
|
|
return env_set(var, data);
|
|
|
|
}
|
|
|
|
|
2020-03-31 10:39:37 +00:00
|
|
|
int board_late_init_xilinx(void)
|
|
|
|
{
|
2020-08-12 10:16:49 +00:00
|
|
|
u32 ret = 0;
|
2020-08-03 10:57:05 +00:00
|
|
|
int i, id, macid = 0;
|
|
|
|
struct xilinx_board_description *desc;
|
2022-01-20 19:17:30 +00:00
|
|
|
phys_size_t bootm_size = gd->ram_top - gd->ram_base;
|
2020-04-01 12:01:21 +00:00
|
|
|
|
2021-04-02 07:49:17 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(MICROBLAZE)) {
|
2020-04-01 12:01:21 +00:00
|
|
|
ulong scriptaddr;
|
|
|
|
|
|
|
|
scriptaddr = env_get_hex("scriptaddr", 0);
|
2021-04-02 07:49:17 +00:00
|
|
|
ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr);
|
2020-04-01 12:01:21 +00:00
|
|
|
}
|
2020-08-12 10:17:53 +00:00
|
|
|
|
2020-10-23 05:54:18 +00:00
|
|
|
if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
|
2020-08-12 10:17:53 +00:00
|
|
|
bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
|
2020-03-31 10:39:37 +00:00
|
|
|
|
2020-08-12 10:16:49 +00:00
|
|
|
ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
|
|
|
|
|
|
|
|
ret |= env_set_addr("bootm_low", (void *)gd->ram_base);
|
2020-08-12 10:17:53 +00:00
|
|
|
ret |= env_set_addr("bootm_size", (void *)bootm_size);
|
2020-08-12 10:16:49 +00:00
|
|
|
|
2020-08-03 10:57:05 +00:00
|
|
|
for (id = 0; id <= highest_id; id++) {
|
2021-08-12 10:30:36 +00:00
|
|
|
desc = &board_info[id];
|
2020-08-03 10:57:05 +00:00
|
|
|
if (desc && desc->header == EEPROM_HEADER_MAGIC) {
|
|
|
|
if (desc->manufacturer[0])
|
|
|
|
ret |= env_set_by_index("manufacturer", id,
|
|
|
|
desc->manufacturer);
|
|
|
|
if (desc->name[0])
|
|
|
|
ret |= env_set_by_index("name", id,
|
|
|
|
desc->name);
|
|
|
|
if (desc->revision[0])
|
|
|
|
ret |= env_set_by_index("rev", id,
|
|
|
|
desc->revision);
|
|
|
|
if (desc->serial[0])
|
|
|
|
ret |= env_set_by_index("serial", id,
|
|
|
|
desc->serial);
|
2020-08-03 11:01:45 +00:00
|
|
|
|
2022-07-21 14:19:17 +00:00
|
|
|
if (desc->uuid[0]) {
|
2022-09-26 06:52:42 +00:00
|
|
|
unsigned char uuid[UUID_STR_LEN + 1];
|
|
|
|
unsigned char *t = desc->uuid;
|
2022-07-21 14:19:17 +00:00
|
|
|
|
|
|
|
memset(uuid, 0, UUID_STR_LEN + 1);
|
|
|
|
|
|
|
|
sprintf(uuid, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
t[0], t[1], t[2], t[3], t[4], t[5],
|
|
|
|
t[6], t[7], t[8], t[9], t[10], t[11],
|
|
|
|
t[12], t[13], t[14], t[15]);
|
|
|
|
ret |= env_set_by_index("uuid", id, uuid);
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(NET))
|
|
|
|
continue;
|
|
|
|
|
2020-08-03 10:57:05 +00:00
|
|
|
for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) {
|
|
|
|
if (is_valid_ethaddr((const u8 *)desc->mac_addr[i]))
|
|
|
|
ret |= eth_env_set_enetaddr_by_index("eth",
|
|
|
|
macid++, desc->mac_addr[i]);
|
|
|
|
}
|
2020-08-03 11:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 10:16:49 +00:00
|
|
|
if (ret)
|
|
|
|
printf("%s: Saving run time variables FAILED\n", __func__);
|
2020-07-09 13:57:56 +00:00
|
|
|
|
2020-03-31 10:39:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-10-22 09:14:20 +00:00
|
|
|
#endif
|
2020-10-26 11:26:13 +00:00
|
|
|
|
2021-07-23 07:55:59 +00:00
|
|
|
static char *board_name = DEVICE_TREE;
|
|
|
|
|
2020-10-26 11:26:13 +00:00
|
|
|
int __maybe_unused board_fit_config_name_match(const char *name)
|
|
|
|
{
|
2021-07-23 07:55:59 +00:00
|
|
|
debug("%s: Check %s, default %s\n", __func__, name, board_name);
|
2020-10-26 11:26:13 +00:00
|
|
|
|
2023-01-06 08:38:52 +00:00
|
|
|
#if !defined(CONFIG_SPL_BUILD)
|
|
|
|
if (CONFIG_IS_ENABLED(REGEX)) {
|
|
|
|
struct slre slre;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = slre_compile(&slre, name);
|
|
|
|
if (ret) {
|
|
|
|
ret = slre_match(&slre, board_name, strlen(board_name),
|
|
|
|
NULL);
|
|
|
|
debug("%s: name match ret = %d\n", __func__, ret);
|
|
|
|
return !ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-23 07:55:59 +00:00
|
|
|
if (!strcmp(name, board_name))
|
2020-10-26 11:26:13 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2021-08-10 12:50:20 +00:00
|
|
|
|
2021-07-23 07:59:59 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DTB_RESELECT)
|
2021-08-11 12:23:54 +00:00
|
|
|
#define MAX_NAME_LENGTH 50
|
|
|
|
|
2021-07-23 07:59:59 +00:00
|
|
|
char * __maybe_unused __weak board_name_decode(void)
|
|
|
|
{
|
2021-08-11 12:23:54 +00:00
|
|
|
char *board_local_name;
|
|
|
|
struct xilinx_board_description *desc;
|
|
|
|
int i, id;
|
|
|
|
|
|
|
|
board_local_name = calloc(1, MAX_NAME_LENGTH);
|
|
|
|
if (!board_info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (id = 0; id <= highest_id; id++) {
|
|
|
|
desc = &board_info[id];
|
|
|
|
|
|
|
|
/* No board description */
|
|
|
|
if (!desc)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Board is not detected */
|
|
|
|
if (desc->header != EEPROM_HEADER_MAGIC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* The first string should be soc name */
|
|
|
|
if (!id)
|
|
|
|
strcat(board_local_name, CONFIG_SYS_BOARD);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For two purpose here:
|
|
|
|
* soc_name- eg: zynqmp-
|
|
|
|
* and between base board and CC eg: ..revA-sck...
|
|
|
|
*/
|
|
|
|
strcat(board_local_name, "-");
|
|
|
|
|
|
|
|
if (desc->name[0]) {
|
|
|
|
/* For DT composition name needs to be lowercase */
|
|
|
|
for (i = 0; i < sizeof(desc->name); i++)
|
|
|
|
desc->name[i] = tolower(desc->name[i]);
|
|
|
|
|
|
|
|
strcat(board_local_name, desc->name);
|
|
|
|
}
|
|
|
|
if (desc->revision[0]) {
|
|
|
|
strcat(board_local_name, "-rev");
|
|
|
|
|
|
|
|
/* And revision needs to be uppercase */
|
|
|
|
for (i = 0; i < sizeof(desc->revision); i++)
|
|
|
|
desc->revision[i] = toupper(desc->revision[i]);
|
|
|
|
|
|
|
|
strcat(board_local_name, desc->revision);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Longer strings will end up with buffer overflow and potential
|
|
|
|
* attacks that's why check it
|
|
|
|
*/
|
|
|
|
if (strlen(board_local_name) >= MAX_NAME_LENGTH)
|
|
|
|
panic("Board name can't be determined\n");
|
|
|
|
|
|
|
|
if (strlen(board_local_name))
|
|
|
|
return board_local_name;
|
|
|
|
|
|
|
|
error:
|
|
|
|
free(board_local_name);
|
2021-07-23 07:59:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool __maybe_unused __weak board_detection(void)
|
|
|
|
{
|
2021-08-11 12:23:54 +00:00
|
|
|
if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = xilinx_read_eeprom();
|
|
|
|
return !ret ? true : false;
|
|
|
|
}
|
|
|
|
|
2021-07-23 07:59:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-06 10:40:41 +00:00
|
|
|
bool __maybe_unused __weak soc_detection(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * __maybe_unused __weak soc_name_decode(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-07-23 07:59:59 +00:00
|
|
|
int embedded_dtb_select(void)
|
|
|
|
{
|
2022-09-06 10:40:41 +00:00
|
|
|
if (soc_detection()) {
|
|
|
|
char *soc_local_name;
|
|
|
|
|
|
|
|
soc_local_name = soc_name_decode();
|
|
|
|
if (soc_local_name) {
|
|
|
|
board_name = soc_local_name;
|
|
|
|
printf("Detected SOC name: %s\n", board_name);
|
|
|
|
|
|
|
|
/* Time to change DTB on fly */
|
|
|
|
/* Both ways should work here */
|
|
|
|
/* fdtdec_resetup(&rescan); */
|
|
|
|
return fdtdec_setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 07:59:59 +00:00
|
|
|
if (board_detection()) {
|
|
|
|
char *board_local_name;
|
|
|
|
|
|
|
|
board_local_name = board_name_decode();
|
|
|
|
if (board_local_name) {
|
|
|
|
board_name = board_local_name;
|
2021-08-11 12:23:54 +00:00
|
|
|
printf("Detected name: %s\n", board_name);
|
2021-07-23 07:59:59 +00:00
|
|
|
|
|
|
|
/* Time to change DTB on fly */
|
|
|
|
/* Both ways should work here */
|
|
|
|
/* fdtdec_resetup(&rescan); */
|
|
|
|
fdtdec_setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2022-08-25 12:23:10 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_LMB)
|
2022-09-09 15:32:40 +00:00
|
|
|
phys_size_t board_get_usable_ram_top(phys_size_t total_size)
|
2022-08-25 12:23:10 +00:00
|
|
|
{
|
|
|
|
phys_size_t size;
|
|
|
|
phys_addr_t reg;
|
|
|
|
struct lmb lmb;
|
|
|
|
|
|
|
|
if (!total_size)
|
|
|
|
return gd->ram_top;
|
|
|
|
|
|
|
|
if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8))
|
|
|
|
panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob);
|
|
|
|
|
|
|
|
/* found enough not-reserved memory to relocated U-Boot */
|
|
|
|
lmb_init(&lmb);
|
|
|
|
lmb_add(&lmb, gd->ram_base, gd->ram_size);
|
|
|
|
boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
|
|
|
|
size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
|
|
|
|
reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
|
|
|
|
|
|
|
|
if (!reg)
|
|
|
|
reg = gd->ram_top - size;
|
|
|
|
|
|
|
|
return reg + size;
|
|
|
|
}
|
|
|
|
#endif
|