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