Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Michal Simek | 53f4436 | 2023-01-06 09:38:52 +0100 | [diff] [blame] | 3 | * (C) Copyright 2014 - 2022, Xilinx, Inc. |
| 4 | * (C) Copyright 2022 - 2023, Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * Michal Simek <michal.simek@amd.com> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 10 | #include <efi.h> |
| 11 | #include <efi_loader.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | #include <env.h> |
Michal Simek | aa97561 | 2022-08-25 14:23:10 +0200 | [diff] [blame] | 13 | #include <image.h> |
Algapally Santosh Sagar | d1c1b1e | 2023-01-19 22:36:14 -0700 | [diff] [blame] | 14 | #include <init.h> |
Michal Simek | aa97561 | 2022-08-25 14:23:10 +0200 | [diff] [blame] | 15 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 18 | #include <asm/sections.h> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 19 | #include <dm/uclass.h> |
| 20 | #include <i2c.h> |
Michal Simek | b90b97e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 21 | #include <linux/sizes.h> |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 22 | #include <malloc.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 23 | #include "board.h" |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 24 | #include <dm.h> |
| 25 | #include <i2c_eeprom.h> |
| 26 | #include <net.h> |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 27 | #include <generated/dt.h> |
Venkatesh Yadav Abbarapu | e8e3c90 | 2024-01-17 08:50:13 +0530 | [diff] [blame] | 28 | #include <rng.h> |
Michal Simek | 53f4436 | 2023-01-06 09:38:52 +0100 | [diff] [blame] | 29 | #include <slre.h> |
T Karthik Reddy | c8fa40a | 2021-08-10 06:50:20 -0600 | [diff] [blame] | 30 | #include <soc.h> |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 31 | #include <linux/ctype.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 32 | #include <linux/kernel.h> |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 33 | #include <uuid.h> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 34 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 35 | #include "fru.h" |
| 36 | |
Simon Glass | b819621 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 38 | struct efi_fw_image fw_images[] = { |
| 39 | #if defined(XILINX_BOOT_IMAGE_GUID) |
| 40 | { |
| 41 | .image_type_id = XILINX_BOOT_IMAGE_GUID, |
| 42 | .fw_name = u"XILINX-BOOT", |
| 43 | .image_index = 1, |
| 44 | }, |
| 45 | #endif |
| 46 | #if defined(XILINX_UBOOT_IMAGE_GUID) |
| 47 | { |
| 48 | .image_type_id = XILINX_UBOOT_IMAGE_GUID, |
| 49 | .fw_name = u"XILINX-UBOOT", |
| 50 | .image_index = 2, |
| 51 | }, |
| 52 | #endif |
| 53 | }; |
| 54 | |
| 55 | struct efi_capsule_update_info update_info = { |
Masahisa Kojima | 5d2438b | 2023-06-07 14:41:51 +0900 | [diff] [blame] | 56 | .num_images = ARRAY_SIZE(fw_images), |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 57 | .images = fw_images, |
| 58 | }; |
| 59 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 60 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 61 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 62 | #define EEPROM_HEADER_MAGIC 0xdaaddeed |
| 63 | #define EEPROM_HDR_MANUFACTURER_LEN 16 |
| 64 | #define EEPROM_HDR_NAME_LEN 16 |
| 65 | #define EEPROM_HDR_REV_LEN 8 |
| 66 | #define EEPROM_HDR_SERIAL_LEN 20 |
| 67 | #define EEPROM_HDR_NO_OF_MAC_ADDR 4 |
| 68 | #define EEPROM_HDR_ETH_ALEN ETH_ALEN |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 69 | #define EEPROM_HDR_UUID_LEN 16 |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 70 | |
| 71 | struct xilinx_board_description { |
| 72 | u32 header; |
| 73 | char manufacturer[EEPROM_HDR_MANUFACTURER_LEN + 1]; |
| 74 | char name[EEPROM_HDR_NAME_LEN + 1]; |
| 75 | char revision[EEPROM_HDR_REV_LEN + 1]; |
| 76 | char serial[EEPROM_HDR_SERIAL_LEN + 1]; |
| 77 | u8 mac_addr[EEPROM_HDR_NO_OF_MAC_ADDR][EEPROM_HDR_ETH_ALEN + 1]; |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 78 | char uuid[EEPROM_HDR_UUID_LEN + 1]; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 81 | static int highest_id = -1; |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 82 | static struct xilinx_board_description *board_info; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 83 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 84 | #define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr) |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 85 | |
| 86 | /* Variable which stores pointer to array which stores eeprom content */ |
| 87 | struct xilinx_legacy_format { |
| 88 | char board_sn[18]; /* 0x0 */ |
| 89 | char unused0[14]; /* 0x12 */ |
Michal Simek | b2df1df | 2023-01-24 16:19:26 +0100 | [diff] [blame] | 90 | char eth_mac[ETH_ALEN]; /* 0x20 */ |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 91 | char unused1[170]; /* 0x26 */ |
| 92 | char board_name[11]; /* 0xd0 */ |
| 93 | char unused2[5]; /* 0xdc */ |
| 94 | char board_revision[3]; /* 0xe0 */ |
| 95 | char unused3[29]; /* 0xe3 */ |
| 96 | }; |
| 97 | |
| 98 | static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size) |
| 99 | { |
| 100 | int i; |
Venkatesh Yadav Abbarapu | 3be370d | 2022-09-26 12:22:42 +0530 | [diff] [blame] | 101 | unsigned char byte; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 102 | |
| 103 | for (i = 0; i < size; i++) { |
| 104 | byte = eeprom[i]; |
| 105 | |
Michal Simek | d432cbb | 2023-01-24 16:19:27 +0100 | [diff] [blame] | 106 | /* Remove all non printable chars but ignore MAC address */ |
| 107 | if ((i < offsetof(struct xilinx_legacy_format, eth_mac) || |
| 108 | i >= offsetof(struct xilinx_legacy_format, unused1)) && |
| 109 | (byte < '!' || byte > '~')) { |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 110 | eeprom[i] = 0; |
Michal Simek | d432cbb | 2023-01-24 16:19:27 +0100 | [diff] [blame] | 111 | continue; |
| 112 | } |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 113 | |
| 114 | /* Convert strings to lower case */ |
| 115 | if (byte >= 'A' && byte <= 'Z') |
| 116 | eeprom[i] = byte + 'a' - 'A'; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static int xilinx_read_eeprom_legacy(struct udevice *dev, char *name, |
| 121 | struct xilinx_board_description *desc) |
| 122 | { |
| 123 | int ret, size; |
| 124 | struct xilinx_legacy_format *eeprom_content; |
| 125 | bool eth_valid = false; |
| 126 | |
| 127 | size = sizeof(*eeprom_content); |
| 128 | |
| 129 | eeprom_content = calloc(1, size); |
| 130 | if (!eeprom_content) |
| 131 | return -ENOMEM; |
| 132 | |
| 133 | debug("%s: I2C EEPROM read pass data at %p\n", __func__, |
| 134 | eeprom_content); |
| 135 | |
| 136 | ret = dm_i2c_read(dev, 0, (uchar *)eeprom_content, size); |
| 137 | if (ret) { |
| 138 | debug("%s: I2C EEPROM read failed\n", __func__); |
| 139 | free(eeprom_content); |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | xilinx_eeprom_legacy_cleanup((char *)eeprom_content, size); |
| 144 | |
Michal Simek | daccab2 | 2023-01-24 16:19:28 +0100 | [diff] [blame] | 145 | /* Terminating \0 chars are the part of desc fields already */ |
| 146 | strlcpy(desc->name, eeprom_content->board_name, |
| 147 | sizeof(eeprom_content->board_name) + 1); |
| 148 | strlcpy(desc->revision, eeprom_content->board_revision, |
| 149 | sizeof(eeprom_content->board_revision) + 1); |
| 150 | strlcpy(desc->serial, eeprom_content->board_sn, |
| 151 | sizeof(eeprom_content->board_sn) + 1); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 152 | |
| 153 | eth_valid = is_valid_ethaddr((const u8 *)eeprom_content->eth_mac); |
| 154 | if (eth_valid) |
Michal Simek | daccab2 | 2023-01-24 16:19:28 +0100 | [diff] [blame] | 155 | memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 156 | |
Michal Simek | daccab2 | 2023-01-24 16:19:28 +0100 | [diff] [blame] | 157 | printf("Xilinx I2C Legacy format at %s:\n", name); |
| 158 | printf(" Board name:\t%s\n", desc->name); |
| 159 | printf(" Board rev:\t%s\n", desc->revision); |
| 160 | printf(" Board SN:\t%s\n", desc->serial); |
| 161 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 162 | if (eth_valid) |
Michal Simek | daccab2 | 2023-01-24 16:19:28 +0100 | [diff] [blame] | 163 | printf(" Ethernet mac:\t%pM\n", desc->mac_addr); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 164 | |
| 165 | desc->header = EEPROM_HEADER_MAGIC; |
| 166 | |
| 167 | free(eeprom_content); |
| 168 | |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | static bool xilinx_detect_legacy(u8 *buffer) |
| 173 | { |
| 174 | int i; |
| 175 | char c; |
| 176 | |
| 177 | for (i = 0; i < XILINX_I2C_DETECTION_BITS; i++) { |
| 178 | c = buffer[i]; |
| 179 | |
| 180 | if (c < '0' || c > '9') |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | return true; |
| 185 | } |
| 186 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 187 | static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, |
| 188 | struct xilinx_board_description *desc) |
| 189 | { |
Michal Simek | be5f572 | 2021-08-12 11:03:49 +0200 | [diff] [blame] | 190 | int i, ret, eeprom_size; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 191 | u8 *fru_content; |
Ashok Reddy Soma | 9f60e44 | 2022-02-23 15:00:59 +0100 | [diff] [blame] | 192 | u8 id = 0; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 193 | |
| 194 | /* FIXME this is shortcut - if eeprom type is wrong it will fail */ |
| 195 | eeprom_size = i2c_eeprom_size(dev); |
| 196 | |
| 197 | fru_content = calloc(1, eeprom_size); |
| 198 | if (!fru_content) |
| 199 | return -ENOMEM; |
| 200 | |
| 201 | debug("%s: I2C EEPROM read pass data at %p\n", __func__, |
| 202 | fru_content); |
| 203 | |
| 204 | ret = dm_i2c_read(dev, 0, (uchar *)fru_content, |
| 205 | eeprom_size); |
| 206 | if (ret) { |
| 207 | debug("%s: I2C EEPROM read failed\n", __func__); |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 208 | goto end; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 211 | fru_capture((unsigned long)fru_content); |
Simon Glass | d2c5a3d | 2023-02-05 15:39:38 -0700 | [diff] [blame] | 212 | if (gd->flags & GD_FLG_RELOC || (_DEBUG && IS_ENABLED(CONFIG_DTB_RESELECT))) { |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 213 | printf("Xilinx I2C FRU format at %s:\n", name); |
| 214 | ret = fru_display(0); |
| 215 | if (ret) { |
| 216 | printf("FRU format decoding failed.\n"); |
| 217 | goto end; |
| 218 | } |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | if (desc->header == EEPROM_HEADER_MAGIC) { |
| 222 | debug("Information already filled\n"); |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 223 | ret = -EINVAL; |
| 224 | goto end; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* It is clear that FRU was captured and structures were filled */ |
Michal Simek | b5f206e | 2022-07-21 16:19:18 +0200 | [diff] [blame] | 228 | strlcpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name, |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 229 | sizeof(desc->manufacturer)); |
Michal Simek | b5f206e | 2022-07-21 16:19:18 +0200 | [diff] [blame] | 230 | strlcpy(desc->uuid, (char *)fru_data.brd.uuid, |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 231 | sizeof(desc->uuid)); |
Michal Simek | b5f206e | 2022-07-21 16:19:18 +0200 | [diff] [blame] | 232 | strlcpy(desc->name, (char *)fru_data.brd.product_name, |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 233 | sizeof(desc->name)); |
Michal Simek | be5f572 | 2021-08-12 11:03:49 +0200 | [diff] [blame] | 234 | for (i = 0; i < sizeof(desc->name); i++) { |
| 235 | if (desc->name[i] == ' ') |
| 236 | desc->name[i] = '\0'; |
| 237 | } |
Michal Simek | b5f206e | 2022-07-21 16:19:18 +0200 | [diff] [blame] | 238 | strlcpy(desc->revision, (char *)fru_data.brd.rev, |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 239 | sizeof(desc->revision)); |
Michal Simek | 904fb97 | 2022-06-06 09:31:27 +0200 | [diff] [blame] | 240 | for (i = 0; i < sizeof(desc->revision); i++) { |
| 241 | if (desc->revision[i] == ' ') |
| 242 | desc->revision[i] = '\0'; |
| 243 | } |
Michal Simek | b5f206e | 2022-07-21 16:19:18 +0200 | [diff] [blame] | 244 | strlcpy(desc->serial, (char *)fru_data.brd.serial_number, |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 245 | sizeof(desc->serial)); |
Ashok Reddy Soma | 9f60e44 | 2022-02-23 15:00:59 +0100 | [diff] [blame] | 246 | |
| 247 | while (id < EEPROM_HDR_NO_OF_MAC_ADDR) { |
| 248 | if (is_valid_ethaddr((const u8 *)fru_data.mac.macid[id])) |
| 249 | memcpy(&desc->mac_addr[id], |
| 250 | (char *)fru_data.mac.macid[id], ETH_ALEN); |
| 251 | id++; |
| 252 | } |
| 253 | |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 254 | desc->header = EEPROM_HEADER_MAGIC; |
| 255 | |
Michal Simek | aada8a6 | 2021-08-13 09:17:10 +0200 | [diff] [blame] | 256 | end: |
| 257 | free(fru_content); |
| 258 | return ret; |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static bool xilinx_detect_fru(u8 *buffer) |
| 262 | { |
| 263 | u8 checksum = 0; |
| 264 | int i; |
| 265 | |
| 266 | checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr)); |
| 267 | if (checksum) { |
| 268 | debug("%s Common header CRC FAIL\n", __func__); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | bool all_zeros = true; |
| 273 | /* Checksum over all zeros is also zero that's why detect this case */ |
| 274 | for (i = 0; i < sizeof(struct fru_common_hdr); i++) { |
| 275 | if (buffer[i] != 0) |
| 276 | all_zeros = false; |
| 277 | } |
| 278 | |
| 279 | if (all_zeros) |
| 280 | return false; |
| 281 | |
| 282 | debug("%s Common header CRC PASS\n", __func__); |
| 283 | return true; |
| 284 | } |
| 285 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 286 | static int xilinx_read_eeprom_single(char *name, |
| 287 | struct xilinx_board_description *desc) |
| 288 | { |
| 289 | int ret; |
| 290 | struct udevice *dev; |
| 291 | ofnode eeprom; |
| 292 | u8 buffer[XILINX_I2C_DETECTION_BITS]; |
| 293 | |
| 294 | eeprom = ofnode_get_aliases_node(name); |
| 295 | if (!ofnode_valid(eeprom)) |
| 296 | return -ENODEV; |
| 297 | |
| 298 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 299 | if (ret) |
| 300 | return ret; |
| 301 | |
| 302 | ret = dm_i2c_read(dev, 0, buffer, sizeof(buffer)); |
| 303 | if (ret) { |
| 304 | debug("%s: I2C EEPROM read failed\n", __func__); |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | debug("%s: i2c memory detected: %s\n", __func__, name); |
| 309 | |
Simon Glass | 631bec2 | 2023-02-05 15:36:31 -0700 | [diff] [blame] | 310 | if (IS_ENABLED(CONFIG_CMD_FRU) && xilinx_detect_fru(buffer)) |
Michal Simek | 207e062 | 2020-08-03 16:14:23 +0200 | [diff] [blame] | 311 | return xilinx_read_eeprom_fru(dev, name, desc); |
| 312 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 313 | if (xilinx_detect_legacy(buffer)) |
| 314 | return xilinx_read_eeprom_legacy(dev, name, desc); |
| 315 | |
| 316 | return -ENODEV; |
| 317 | } |
| 318 | |
| 319 | __maybe_unused int xilinx_read_eeprom(void) |
| 320 | { |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 321 | int id; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 322 | char name_buf[8]; /* 8 bytes should be enough for nvmem+number */ |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 323 | struct xilinx_board_description *desc; |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 324 | |
| 325 | highest_id = dev_read_alias_highest_id("nvmem"); |
| 326 | /* No nvmem aliases present */ |
| 327 | if (highest_id < 0) |
| 328 | return -EINVAL; |
| 329 | |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 330 | board_info = calloc(1, sizeof(*desc) * (highest_id + 1)); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 331 | if (!board_info) |
| 332 | return -ENOMEM; |
| 333 | |
| 334 | debug("%s: Highest ID %d, board_info %p\n", __func__, |
| 335 | highest_id, board_info); |
| 336 | |
| 337 | for (id = 0; id <= highest_id; id++) { |
| 338 | snprintf(name_buf, sizeof(name_buf), "nvmem%d", id); |
| 339 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 340 | /* Alloc structure */ |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 341 | desc = &board_info[id]; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 342 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 343 | /* Ignoring return value for supporting multiple chips */ |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 344 | xilinx_read_eeprom_single(name_buf, desc); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 347 | /* |
| 348 | * Consider to clean board_info structure when board/cards are not |
| 349 | * detected. |
| 350 | */ |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Michal Simek | 1a50529 | 2022-02-17 14:28:38 +0100 | [diff] [blame] | 355 | #if defined(CONFIG_OF_BOARD) |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 356 | void *board_fdt_blob_setup(int *err) |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 357 | { |
Michal Simek | ddf69ae | 2020-09-04 16:21:47 +0200 | [diff] [blame] | 358 | void *fdt_blob; |
Michal Simek | c89f429 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 359 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 360 | *err = 0; |
Michal Simek | 663c162 | 2021-01-04 11:07:28 +0100 | [diff] [blame] | 361 | if (!IS_ENABLED(CONFIG_SPL_BUILD) && |
| 362 | !IS_ENABLED(CONFIG_VERSAL_NO_DDR) && |
Michal Simek | 6d4317b | 2021-02-02 13:33:22 +0100 | [diff] [blame] | 363 | !IS_ENABLED(CONFIG_ZYNQMP_NO_DDR)) { |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 364 | fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 365 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 366 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 367 | return fdt_blob; |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 368 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 369 | debug("DTB is not passed via %p\n", fdt_blob); |
| 370 | } |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 371 | |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 372 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 373 | /* |
| 374 | * FDT is at end of BSS unless it is in a different memory |
| 375 | * region |
| 376 | */ |
| 377 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 378 | fdt_blob = (ulong *)_image_binary_end; |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 379 | else |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 380 | fdt_blob = (ulong *)__bss_end; |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 381 | } else { |
| 382 | /* FDT is at end of image */ |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 383 | fdt_blob = (ulong *)_end; |
Michal Simek | 9b9d01e | 2021-01-04 11:03:36 +0100 | [diff] [blame] | 384 | } |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 385 | |
| 386 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 387 | return fdt_blob; |
| 388 | |
| 389 | debug("DTB is also not passed via %p\n", fdt_blob); |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 390 | |
Michal Simek | 1a50529 | 2022-02-17 14:28:38 +0100 | [diff] [blame] | 391 | *err = -EINVAL; |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 392 | return NULL; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 393 | } |
| 394 | #endif |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 395 | |
Michal Simek | 67ed85d | 2020-10-22 11:14:20 +0200 | [diff] [blame] | 396 | #if defined(CONFIG_BOARD_LATE_INIT) |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 397 | static int env_set_by_index(const char *name, int index, char *data) |
| 398 | { |
| 399 | char var[32]; |
| 400 | |
| 401 | if (!index) |
| 402 | sprintf(var, "board_%s", name); |
| 403 | else |
| 404 | sprintf(var, "card%d_%s", index, name); |
| 405 | |
| 406 | return env_set(var, data); |
| 407 | } |
| 408 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 409 | int board_late_init_xilinx(void) |
| 410 | { |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 411 | u32 ret = 0; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 412 | int i, id, macid = 0; |
| 413 | struct xilinx_board_description *desc; |
Ricardo Salveti | d35ccf2 | 2022-01-20 16:17:30 -0300 | [diff] [blame] | 414 | phys_size_t bootm_size = gd->ram_top - gd->ram_base; |
Michal Simek | bb70b77 | 2023-08-31 09:04:28 +0200 | [diff] [blame] | 415 | u64 bootscr_flash_offset, bootscr_flash_size; |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 416 | |
Simon Glass | 117038a | 2023-02-05 15:40:14 -0700 | [diff] [blame] | 417 | if (!IS_ENABLED(CONFIG_MICROBLAZE)) { |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 418 | ulong scriptaddr; |
Algapally Santosh Sagar | 473705e | 2023-08-31 08:59:06 +0200 | [diff] [blame] | 419 | u64 bootscr_address; |
| 420 | u64 bootscr_offset; |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 421 | |
Algapally Santosh Sagar | 473705e | 2023-08-31 08:59:06 +0200 | [diff] [blame] | 422 | /* Fetch bootscr_address/bootscr_offset from DT and update */ |
| 423 | if (!ofnode_read_bootscript_address(&bootscr_address, |
| 424 | &bootscr_offset)) { |
| 425 | if (bootscr_offset) |
| 426 | ret |= env_set_hex("scriptaddr", |
| 427 | gd->ram_base + |
| 428 | bootscr_offset); |
| 429 | else |
| 430 | ret |= env_set_hex("scriptaddr", |
| 431 | bootscr_address); |
| 432 | } else { |
| 433 | /* Update scriptaddr(bootscr offset) from env */ |
| 434 | scriptaddr = env_get_hex("scriptaddr", 0); |
| 435 | ret |= env_set_hex("scriptaddr", |
| 436 | gd->ram_base + scriptaddr); |
| 437 | } |
T Karthik Reddy | 17b7f66 | 2020-04-01 06:01:21 -0600 | [diff] [blame] | 438 | } |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 439 | |
Michal Simek | bb70b77 | 2023-08-31 09:04:28 +0200 | [diff] [blame] | 440 | if (!ofnode_read_bootscript_flash(&bootscr_flash_offset, |
| 441 | &bootscr_flash_size)) { |
| 442 | ret |= env_set_hex("script_offset_f", bootscr_flash_offset); |
| 443 | ret |= env_set_hex("script_size_f", bootscr_flash_size); |
| 444 | } else { |
| 445 | debug("!!! Please define bootscr-flash-offset via DT !!!\n"); |
| 446 | ret |= env_set_hex("script_offset_f", |
| 447 | CONFIG_BOOT_SCRIPT_OFFSET); |
| 448 | } |
| 449 | |
Simon Glass | 117038a | 2023-02-05 15:40:14 -0700 | [diff] [blame] | 450 | if (IS_ENABLED(CONFIG_ARCH_ZYNQ) || IS_ENABLED(CONFIG_MICROBLAZE)) |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 451 | bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M)); |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 452 | |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 453 | ret |= env_set_addr("bootm_low", (void *)gd->ram_base); |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame] | 454 | ret |= env_set_addr("bootm_size", (void *)bootm_size); |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 455 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 456 | for (id = 0; id <= highest_id; id++) { |
Michal Simek | e98ae1d | 2021-08-12 12:30:36 +0200 | [diff] [blame] | 457 | desc = &board_info[id]; |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 458 | if (desc && desc->header == EEPROM_HEADER_MAGIC) { |
| 459 | if (desc->manufacturer[0]) |
| 460 | ret |= env_set_by_index("manufacturer", id, |
| 461 | desc->manufacturer); |
| 462 | if (desc->name[0]) |
| 463 | ret |= env_set_by_index("name", id, |
| 464 | desc->name); |
| 465 | if (desc->revision[0]) |
| 466 | ret |= env_set_by_index("rev", id, |
| 467 | desc->revision); |
| 468 | if (desc->serial[0]) |
| 469 | ret |= env_set_by_index("serial", id, |
| 470 | desc->serial); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 471 | |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 472 | if (desc->uuid[0]) { |
Venkatesh Yadav Abbarapu | 3be370d | 2022-09-26 12:22:42 +0530 | [diff] [blame] | 473 | unsigned char uuid[UUID_STR_LEN + 1]; |
| 474 | unsigned char *t = desc->uuid; |
Michal Simek | 7459d4a | 2022-07-21 16:19:17 +0200 | [diff] [blame] | 475 | |
| 476 | memset(uuid, 0, UUID_STR_LEN + 1); |
| 477 | |
| 478 | sprintf(uuid, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 479 | t[0], t[1], t[2], t[3], t[4], t[5], |
| 480 | t[6], t[7], t[8], t[9], t[10], t[11], |
| 481 | t[12], t[13], t[14], t[15]); |
| 482 | ret |= env_set_by_index("uuid", id, uuid); |
| 483 | } |
| 484 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 485 | if (!CONFIG_IS_ENABLED(NET)) |
| 486 | continue; |
| 487 | |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 488 | for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) { |
Michal Simek | 0bb24e1 | 2020-08-03 12:57:05 +0200 | [diff] [blame] | 489 | if (is_valid_ethaddr((const u8 *)desc->mac_addr[i])) |
| 490 | ret |= eth_env_set_enetaddr_by_index("eth", |
| 491 | macid++, desc->mac_addr[i]); |
| 492 | } |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 496 | if (ret) |
| 497 | printf("%s: Saving run time variables FAILED\n", __func__); |
Michal Simek | 8ba62d2 | 2020-07-09 15:57:56 +0200 | [diff] [blame] | 498 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 499 | return 0; |
| 500 | } |
Michal Simek | 67ed85d | 2020-10-22 11:14:20 +0200 | [diff] [blame] | 501 | #endif |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 502 | |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 503 | static char *board_name = DEVICE_TREE; |
| 504 | |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 505 | int __maybe_unused board_fit_config_name_match(const char *name) |
| 506 | { |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 507 | debug("%s: Check %s, default %s\n", __func__, name, board_name); |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 508 | |
Michal Simek | 53f4436 | 2023-01-06 09:38:52 +0100 | [diff] [blame] | 509 | #if !defined(CONFIG_SPL_BUILD) |
Simon Glass | f34ccae | 2023-02-05 15:40:37 -0700 | [diff] [blame] | 510 | if (IS_ENABLED(CONFIG_REGEX)) { |
Michal Simek | 53f4436 | 2023-01-06 09:38:52 +0100 | [diff] [blame] | 511 | struct slre slre; |
| 512 | int ret; |
| 513 | |
| 514 | ret = slre_compile(&slre, name); |
| 515 | if (ret) { |
| 516 | ret = slre_match(&slre, board_name, strlen(board_name), |
| 517 | NULL); |
| 518 | debug("%s: name match ret = %d\n", __func__, ret); |
| 519 | return !ret; |
| 520 | } |
| 521 | } |
| 522 | #endif |
| 523 | |
Michal Simek | c88975e | 2021-07-23 09:55:59 +0200 | [diff] [blame] | 524 | if (!strcmp(name, board_name)) |
Michal Simek | fe49df9 | 2020-10-26 12:26:13 +0100 | [diff] [blame] | 525 | return 0; |
| 526 | |
| 527 | return -1; |
| 528 | } |
T Karthik Reddy | c8fa40a | 2021-08-10 06:50:20 -0600 | [diff] [blame] | 529 | |
Simon Glass | d2c5a3d | 2023-02-05 15:39:38 -0700 | [diff] [blame] | 530 | #if IS_ENABLED(CONFIG_DTB_RESELECT) |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 531 | #define MAX_NAME_LENGTH 50 |
| 532 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 533 | char * __maybe_unused __weak board_name_decode(void) |
| 534 | { |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 535 | char *board_local_name; |
| 536 | struct xilinx_board_description *desc; |
| 537 | int i, id; |
| 538 | |
| 539 | board_local_name = calloc(1, MAX_NAME_LENGTH); |
| 540 | if (!board_info) |
| 541 | return NULL; |
| 542 | |
| 543 | for (id = 0; id <= highest_id; id++) { |
| 544 | desc = &board_info[id]; |
| 545 | |
| 546 | /* No board description */ |
| 547 | if (!desc) |
| 548 | goto error; |
| 549 | |
| 550 | /* Board is not detected */ |
| 551 | if (desc->header != EEPROM_HEADER_MAGIC) |
| 552 | continue; |
| 553 | |
| 554 | /* The first string should be soc name */ |
| 555 | if (!id) |
| 556 | strcat(board_local_name, CONFIG_SYS_BOARD); |
| 557 | |
| 558 | /* |
| 559 | * For two purpose here: |
| 560 | * soc_name- eg: zynqmp- |
| 561 | * and between base board and CC eg: ..revA-sck... |
| 562 | */ |
| 563 | strcat(board_local_name, "-"); |
| 564 | |
| 565 | if (desc->name[0]) { |
| 566 | /* For DT composition name needs to be lowercase */ |
| 567 | for (i = 0; i < sizeof(desc->name); i++) |
| 568 | desc->name[i] = tolower(desc->name[i]); |
| 569 | |
| 570 | strcat(board_local_name, desc->name); |
| 571 | } |
| 572 | if (desc->revision[0]) { |
| 573 | strcat(board_local_name, "-rev"); |
| 574 | |
| 575 | /* And revision needs to be uppercase */ |
| 576 | for (i = 0; i < sizeof(desc->revision); i++) |
| 577 | desc->revision[i] = toupper(desc->revision[i]); |
| 578 | |
| 579 | strcat(board_local_name, desc->revision); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Longer strings will end up with buffer overflow and potential |
| 585 | * attacks that's why check it |
| 586 | */ |
| 587 | if (strlen(board_local_name) >= MAX_NAME_LENGTH) |
| 588 | panic("Board name can't be determined\n"); |
| 589 | |
| 590 | if (strlen(board_local_name)) |
| 591 | return board_local_name; |
| 592 | |
| 593 | error: |
| 594 | free(board_local_name); |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | bool __maybe_unused __weak board_detection(void) |
| 599 | { |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 600 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) { |
| 601 | int ret; |
| 602 | |
| 603 | ret = xilinx_read_eeprom(); |
| 604 | return !ret ? true : false; |
| 605 | } |
| 606 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Michal Simek | 4c8e4ee | 2022-09-06 12:40:41 +0200 | [diff] [blame] | 610 | bool __maybe_unused __weak soc_detection(void) |
| 611 | { |
| 612 | return false; |
| 613 | } |
| 614 | |
| 615 | char * __maybe_unused __weak soc_name_decode(void) |
| 616 | { |
| 617 | return NULL; |
| 618 | } |
| 619 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 620 | int embedded_dtb_select(void) |
| 621 | { |
Michal Simek | 4c8e4ee | 2022-09-06 12:40:41 +0200 | [diff] [blame] | 622 | if (soc_detection()) { |
| 623 | char *soc_local_name; |
| 624 | |
| 625 | soc_local_name = soc_name_decode(); |
| 626 | if (soc_local_name) { |
| 627 | board_name = soc_local_name; |
| 628 | printf("Detected SOC name: %s\n", board_name); |
| 629 | |
| 630 | /* Time to change DTB on fly */ |
| 631 | /* Both ways should work here */ |
| 632 | /* fdtdec_resetup(&rescan); */ |
| 633 | return fdtdec_setup(); |
| 634 | } |
| 635 | } |
| 636 | |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 637 | if (board_detection()) { |
| 638 | char *board_local_name; |
| 639 | |
| 640 | board_local_name = board_name_decode(); |
| 641 | if (board_local_name) { |
| 642 | board_name = board_local_name; |
Michal Simek | e045351 | 2021-08-11 14:23:54 +0200 | [diff] [blame] | 643 | printf("Detected name: %s\n", board_name); |
Michal Simek | afb2857 | 2021-07-23 09:59:59 +0200 | [diff] [blame] | 644 | |
| 645 | /* Time to change DTB on fly */ |
| 646 | /* Both ways should work here */ |
| 647 | /* fdtdec_resetup(&rescan); */ |
| 648 | fdtdec_setup(); |
| 649 | } |
| 650 | } |
| 651 | return 0; |
| 652 | } |
| 653 | #endif |
Michal Simek | aa97561 | 2022-08-25 14:23:10 +0200 | [diff] [blame] | 654 | |
| 655 | #if defined(CONFIG_LMB) |
Michal Simek | 962c10a | 2023-11-06 12:56:47 +0100 | [diff] [blame] | 656 | |
| 657 | #ifndef MMU_SECTION_SIZE |
| 658 | #define MMU_SECTION_SIZE (1 * 1024 * 1024) |
| 659 | #endif |
| 660 | |
Heinrich Schuchardt | 51a9aac | 2023-08-12 20:16:58 +0200 | [diff] [blame] | 661 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
Michal Simek | aa97561 | 2022-08-25 14:23:10 +0200 | [diff] [blame] | 662 | { |
| 663 | phys_size_t size; |
| 664 | phys_addr_t reg; |
| 665 | struct lmb lmb; |
| 666 | |
| 667 | if (!total_size) |
| 668 | return gd->ram_top; |
| 669 | |
| 670 | if (!IS_ALIGNED((ulong)gd->fdt_blob, 0x8)) |
| 671 | panic("Not 64bit aligned DT location: %p\n", gd->fdt_blob); |
| 672 | |
| 673 | /* found enough not-reserved memory to relocated U-Boot */ |
| 674 | lmb_init(&lmb); |
| 675 | lmb_add(&lmb, gd->ram_base, gd->ram_size); |
| 676 | boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob); |
| 677 | size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE); |
| 678 | reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE); |
| 679 | |
| 680 | if (!reg) |
| 681 | reg = gd->ram_top - size; |
| 682 | |
| 683 | return reg + size; |
| 684 | } |
| 685 | #endif |
Venkatesh Yadav Abbarapu | e8e3c90 | 2024-01-17 08:50:13 +0530 | [diff] [blame] | 686 | |
| 687 | #ifdef CONFIG_OF_BOARD_SETUP |
| 688 | #define MAX_RAND_SIZE 8 |
| 689 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 690 | { |
| 691 | size_t n = MAX_RAND_SIZE; |
| 692 | struct udevice *dev; |
| 693 | u8 buf[MAX_RAND_SIZE]; |
| 694 | int nodeoffset, ret; |
| 695 | |
| 696 | if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { |
| 697 | debug("No RNG device\n"); |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | if (dm_rng_read(dev, buf, n)) { |
| 702 | debug("Reading RNG failed\n"); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | if (!blob) { |
| 707 | debug("No FDT memory address configured. Please configure\n" |
| 708 | "the FDT address via \"fdt addr <address>\" command.\n" |
| 709 | "Aborting!\n"); |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | ret = fdt_check_header(blob); |
| 714 | if (ret < 0) { |
| 715 | debug("fdt_chosen: %s\n", fdt_strerror(ret)); |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen"); |
| 720 | if (nodeoffset < 0) { |
| 721 | debug("Reading chosen node failed\n"); |
| 722 | return nodeoffset; |
| 723 | } |
| 724 | |
| 725 | ret = fdt_setprop(blob, nodeoffset, "kaslr-seed", buf, sizeof(buf)); |
| 726 | if (ret < 0) { |
| 727 | debug("Unable to set kaslr-seed on chosen node: %s\n", fdt_strerror(ret)); |
| 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | #endif |