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