Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | f43fc16 | 2023-04-25 10:27:21 -0600 | [diff] [blame] | 4 | * |
| 5 | * NOTE: Please do not add new devicetree-reading functionality into this file. |
| 6 | * Add it to the ofnode API instead, since that is compatible with livetree. |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Heiko Schocher | 29a23f9 | 2014-03-03 12:19:30 +0100 | [diff] [blame] | 9 | #ifndef USE_HOSTCC |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 10 | #include <common.h> |
Jean-Jacques Hiblot | 035d640 | 2017-09-15 12:57:31 +0200 | [diff] [blame] | 11 | #include <boot_fit.h> |
Simon Glass | 4e4bf94 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 12 | #include <display_options.h> |
Simon Glass | fcc0a87 | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 13 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 14 | #include <hang.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 15 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <net.h> |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 19 | #include <spl.h> |
Simon Glass | 9eef56d | 2019-08-01 09:46:48 -0600 | [diff] [blame] | 20 | #include <env.h> |
Jean-Jacques Hiblot | 035d640 | 2017-09-15 12:57:31 +0200 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | #include <fdtdec.h> |
| 23 | #include <fdt_support.h> |
Simon Glass | 0c670fc | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 24 | #include <gzip.h> |
Heinrich Schuchardt | f980c99 | 2018-11-18 17:58:50 +0100 | [diff] [blame] | 25 | #include <mapmem.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 26 | #include <linux/libfdt.h> |
Jean-Jacques Hiblot | 035d640 | 2017-09-15 12:57:31 +0200 | [diff] [blame] | 27 | #include <serial.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 28 | #include <asm/global_data.h> |
Jean-Jacques Hiblot | 035d640 | 2017-09-15 12:57:31 +0200 | [diff] [blame] | 29 | #include <asm/sections.h> |
Simon Glass | ee88ba7 | 2022-09-06 20:27:19 -0600 | [diff] [blame] | 30 | #include <dm/ofnode.h> |
| 31 | #include <dm/of_extra.h> |
Simon Glass | 5c33c9f | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 32 | #include <linux/ctype.h> |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 33 | #include <linux/lzo.h> |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 34 | #include <linux/ioport.h> |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | /* |
| 39 | * Here are the type we know about. One day we might allow drivers to |
| 40 | * register. For now we just put them here. The COMPAT macro allows us to |
| 41 | * turn this into a sparse list later, and keeps the ID with the name. |
Simon Glass | 01a227d | 2016-06-19 17:33:13 -0600 | [diff] [blame] | 42 | * |
| 43 | * NOTE: This list is basically a TODO list for things that need to be |
| 44 | * converted to driver model. So don't add new things here unless there is a |
| 45 | * good reason why driver-model conversion is infeasible. Examples include |
| 46 | * things which are used before driver model is available. |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 47 | */ |
| 48 | #define COMPAT(id, name) name |
| 49 | static const char * const compat_names[COMPAT_COUNT] = { |
Simon Glass | f88fe2d | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 50 | COMPAT(UNKNOWN, "<none>"), |
Jimmy Zhang | 0e35ad0 | 2012-04-02 13:18:52 +0000 | [diff] [blame] | 51 | COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"), |
| 52 | COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"), |
Jim Lin | 312693c | 2012-07-29 20:53:29 +0000 | [diff] [blame] | 53 | COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"), |
Thierry Reding | 79c7a90 | 2014-12-09 22:25:09 -0700 | [diff] [blame] | 54 | COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"), |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 55 | COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"), |
Rajeshwari Shinde | 6abd162 | 2013-01-07 23:35:05 +0000 | [diff] [blame] | 56 | COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"), |
Vivek Gautam | 108b85b | 2013-09-14 14:02:48 +0530 | [diff] [blame] | 57 | COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"), |
Akshay Saraswat | 618766c | 2013-02-25 01:13:01 +0000 | [diff] [blame] | 58 | COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"), |
Piotr Wilczek | de461c5 | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 59 | COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"), |
Jaehoon Chung | 7d3ca0f | 2014-05-16 13:59:51 +0900 | [diff] [blame] | 60 | COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"), |
Neil Armstrong | 51e4e3e | 2019-02-10 10:16:21 +0000 | [diff] [blame] | 61 | COMPAT(GENERIC_SPI_FLASH, "jedec,spi-nor"), |
Ajay Kumar | 45c480c | 2014-09-05 16:53:33 +0530 | [diff] [blame] | 62 | COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"), |
Simon Glass | 77f9b1f | 2014-11-12 22:42:21 -0700 | [diff] [blame] | 63 | COMPAT(INTEL_MICROCODE, "intel,microcode"), |
Bin Meng | c89ada0 | 2015-02-05 23:42:26 +0800 | [diff] [blame] | 64 | COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"), |
Marek Vasut | 6ab00db | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 65 | COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"), |
Marek Vasut | 129adf5 | 2015-07-25 10:48:14 +0200 | [diff] [blame] | 66 | COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"), |
Marek Vasut | ef4b01b | 2015-12-05 19:28:44 +0100 | [diff] [blame] | 67 | COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"), |
Simon Glass | 39ea0ee | 2016-06-19 17:33:14 -0600 | [diff] [blame] | 68 | COMPAT(INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"), |
| 69 | COMPAT(INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"), |
| 70 | COMPAT(INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"), |
Ley Foon Tan | e11b5e8 | 2017-04-05 17:32:47 +0800 | [diff] [blame] | 71 | COMPAT(ALTERA_SOCFPGA_CLK, "altr,clk-mgr"), |
| 72 | COMPAT(ALTERA_SOCFPGA_PINCTRL_SINGLE, "pinctrl-single"), |
| 73 | COMPAT(ALTERA_SOCFPGA_H2F_BRG, "altr,socfpga-hps2fpga-bridge"), |
| 74 | COMPAT(ALTERA_SOCFPGA_LWH2F_BRG, "altr,socfpga-lwhps2fpga-bridge"), |
| 75 | COMPAT(ALTERA_SOCFPGA_F2H_BRG, "altr,socfpga-fpga2hps-bridge"), |
| 76 | COMPAT(ALTERA_SOCFPGA_F2SDR0, "altr,socfpga-fpga2sdram0-bridge"), |
| 77 | COMPAT(ALTERA_SOCFPGA_F2SDR1, "altr,socfpga-fpga2sdram1-bridge"), |
| 78 | COMPAT(ALTERA_SOCFPGA_F2SDR2, "altr,socfpga-fpga2sdram2-bridge"), |
Tien Fong Chee | eb57c0b | 2017-09-25 16:40:03 +0800 | [diff] [blame] | 79 | COMPAT(ALTERA_SOCFPGA_FPGA0, "altr,socfpga-a10-fpga-mgr"), |
| 80 | COMPAT(ALTERA_SOCFPGA_NOC, "altr,socfpga-a10-noc"), |
Marek Vasut | 19c8fc7 | 2018-05-12 11:56:10 +0200 | [diff] [blame] | 81 | COMPAT(ALTERA_SOCFPGA_CLK_INIT, "altr,socfpga-a10-clk-init") |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
Simon Glass | ff66e7b | 2021-12-16 20:59:34 -0700 | [diff] [blame] | 84 | static const char *const fdt_src_name[] = { |
| 85 | [FDTSRC_SEPARATE] = "separate", |
| 86 | [FDTSRC_FIT] = "fit", |
| 87 | [FDTSRC_BOARD] = "board", |
| 88 | [FDTSRC_EMBED] = "embed", |
| 89 | [FDTSRC_ENV] = "env", |
| 90 | }; |
| 91 | |
| 92 | const char *fdtdec_get_srcname(void) |
| 93 | { |
| 94 | return fdt_src_name[gd->fdt_src]; |
| 95 | } |
| 96 | |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 97 | const char *fdtdec_get_compatible(enum fdt_compat_id id) |
| 98 | { |
| 99 | /* We allow reading of the 'unknown' ID for testing purposes */ |
| 100 | assert(id >= 0 && id < COMPAT_COUNT); |
| 101 | return compat_names[id]; |
| 102 | } |
| 103 | |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 104 | fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 105 | const char *prop_name, int index, int na, |
| 106 | int ns, fdt_size_t *sizep, |
| 107 | bool translate) |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 108 | { |
| 109 | const fdt32_t *prop, *prop_end; |
| 110 | const fdt32_t *prop_addr, *prop_size, *prop_after_size; |
| 111 | int len; |
| 112 | fdt_addr_t addr; |
| 113 | |
| 114 | debug("%s: %s: ", __func__, prop_name); |
| 115 | |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 116 | prop = fdt_getprop(blob, node, prop_name, &len); |
| 117 | if (!prop) { |
| 118 | debug("(not found)\n"); |
| 119 | return FDT_ADDR_T_NONE; |
| 120 | } |
| 121 | prop_end = prop + (len / sizeof(*prop)); |
| 122 | |
| 123 | prop_addr = prop + (index * (na + ns)); |
| 124 | prop_size = prop_addr + na; |
| 125 | prop_after_size = prop_size + ns; |
| 126 | if (prop_after_size > prop_end) { |
| 127 | debug("(not enough data: expected >= %d cells, got %d cells)\n", |
| 128 | (u32)(prop_after_size - prop), ((u32)(prop_end - prop))); |
| 129 | return FDT_ADDR_T_NONE; |
| 130 | } |
| 131 | |
Vignesh R | 5efa1bf | 2017-03-20 10:04:38 +0530 | [diff] [blame] | 132 | #if CONFIG_IS_ENABLED(OF_TRANSLATE) |
Stephen Warren | 6e06acb | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 133 | if (translate) |
| 134 | addr = fdt_translate_address(blob, node, prop_addr); |
| 135 | else |
| 136 | #endif |
| 137 | addr = fdtdec_get_number(prop_addr, na); |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 138 | |
| 139 | if (sizep) { |
| 140 | *sizep = fdtdec_get_number(prop_size, ns); |
Simon Glass | fd30d2c | 2016-02-29 15:25:37 -0700 | [diff] [blame] | 141 | debug("addr=%08llx, size=%llx\n", (unsigned long long)addr, |
| 142 | (unsigned long long)*sizep); |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 143 | } else { |
Simon Glass | fd30d2c | 2016-02-29 15:25:37 -0700 | [diff] [blame] | 144 | debug("addr=%08llx\n", (unsigned long long)addr); |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return addr; |
| 148 | } |
| 149 | |
| 150 | fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 151 | int node, const char *prop_name, |
| 152 | int index, fdt_size_t *sizep, |
| 153 | bool translate) |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 154 | { |
| 155 | int na, ns; |
| 156 | |
| 157 | debug("%s: ", __func__); |
| 158 | |
| 159 | na = fdt_address_cells(blob, parent); |
| 160 | if (na < 1) { |
| 161 | debug("(bad #address-cells)\n"); |
| 162 | return FDT_ADDR_T_NONE; |
| 163 | } |
| 164 | |
| 165 | ns = fdt_size_cells(blob, parent); |
Przemyslaw Marczak | ff0a635 | 2015-09-30 13:14:50 +0200 | [diff] [blame] | 166 | if (ns < 0) { |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 167 | debug("(bad #size-cells)\n"); |
| 168 | return FDT_ADDR_T_NONE; |
| 169 | } |
| 170 | |
| 171 | debug("na=%d, ns=%d, ", na, ns); |
| 172 | |
| 173 | return fdtdec_get_addr_size_fixed(blob, node, prop_name, index, na, |
Stephen Warren | 6e06acb | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 174 | ns, sizep, translate); |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 178 | const char *prop_name, int index, |
| 179 | fdt_size_t *sizep, |
| 180 | bool translate) |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 181 | { |
| 182 | int parent; |
| 183 | |
| 184 | debug("%s: ", __func__); |
| 185 | |
| 186 | parent = fdt_parent_offset(blob, node); |
| 187 | if (parent < 0) { |
| 188 | debug("(no parent found)\n"); |
| 189 | return FDT_ADDR_T_NONE; |
| 190 | } |
| 191 | |
| 192 | return fdtdec_get_addr_size_auto_parent(blob, parent, node, prop_name, |
Stephen Warren | 6e06acb | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 193 | index, sizep, translate); |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 194 | } |
| 195 | |
Simon Glass | 4397a2a | 2013-03-19 04:58:51 +0000 | [diff] [blame] | 196 | fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 197 | const char *prop_name, fdt_size_t *sizep) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 198 | { |
Stephen Warren | d93b9a0 | 2015-09-25 10:11:41 -0600 | [diff] [blame] | 199 | int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0; |
| 200 | |
Stephen Warren | 02464e3 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 201 | return fdtdec_get_addr_size_fixed(blob, node, prop_name, 0, |
| 202 | sizeof(fdt_addr_t) / sizeof(fdt32_t), |
Stephen Warren | 6e06acb | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 203 | ns, sizep, false); |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 206 | fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name) |
Simon Glass | 4397a2a | 2013-03-19 04:58:51 +0000 | [diff] [blame] | 207 | { |
| 208 | return fdtdec_get_addr_size(blob, node, prop_name, NULL); |
| 209 | } |
| 210 | |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 211 | int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device) |
| 212 | { |
| 213 | const char *list, *end; |
| 214 | int len; |
| 215 | |
| 216 | list = fdt_getprop(blob, node, "compatible", &len); |
| 217 | if (!list) |
| 218 | return -ENOENT; |
| 219 | |
| 220 | end = list + len; |
| 221 | while (list < end) { |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 222 | len = strlen(list); |
| 223 | if (len >= strlen("pciVVVV,DDDD")) { |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 224 | char *s = strstr(list, "pci"); |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * check if the string is something like pciVVVV,DDDD.RR |
| 228 | * or just pciVVVV,DDDD |
| 229 | */ |
| 230 | if (s && s[7] == ',' && |
| 231 | (s[12] == '.' || s[12] == 0)) { |
| 232 | s += 3; |
| 233 | *vendor = simple_strtol(s, NULL, 16); |
| 234 | |
| 235 | s += 5; |
| 236 | *device = simple_strtol(s, NULL, 16); |
| 237 | |
| 238 | return 0; |
| 239 | } |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 240 | } |
Bin Meng | bc6351e | 2015-08-20 06:40:25 -0700 | [diff] [blame] | 241 | list += (len + 1); |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | return -ENOENT; |
| 245 | } |
| 246 | |
Simon Glass | 194fca9 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 247 | int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr, |
Simon Glass | fcc0a87 | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 248 | u32 *bar) |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 249 | { |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 250 | int barnum; |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 251 | |
| 252 | /* extract the bar number from fdt_pci_addr */ |
| 253 | barnum = addr->phys_hi & 0xff; |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 254 | if (barnum < PCI_BASE_ADDRESS_0 || barnum > PCI_CARDBUS_CIS) |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 255 | return -EINVAL; |
| 256 | |
| 257 | barnum = (barnum - PCI_BASE_ADDRESS_0) / 4; |
Simon Glass | b717f2f | 2021-08-01 18:54:18 -0600 | [diff] [blame] | 258 | |
Simon Glass | fcc0a87 | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 259 | *bar = dm_pci_read_bar32(dev, barnum); |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 260 | |
| 261 | return 0; |
| 262 | } |
Suneel Garapati | 1db7ee4 | 2019-10-19 15:19:35 -0700 | [diff] [blame] | 263 | |
| 264 | int fdtdec_get_pci_bus_range(const void *blob, int node, |
| 265 | struct fdt_resource *res) |
| 266 | { |
| 267 | const u32 *values; |
| 268 | int len; |
| 269 | |
| 270 | values = fdt_getprop(blob, node, "bus-range", &len); |
| 271 | if (!values || len < sizeof(*values) * 2) |
| 272 | return -EINVAL; |
| 273 | |
| 274 | res->start = fdt32_to_cpu(*values++); |
| 275 | res->end = fdt32_to_cpu(*values); |
| 276 | |
| 277 | return 0; |
| 278 | } |
Bin Meng | a62e84d | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 279 | |
Che-Liang Chiou | aadef0a | 2012-10-25 16:31:05 +0000 | [diff] [blame] | 280 | uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 281 | uint64_t default_val) |
Che-Liang Chiou | aadef0a | 2012-10-25 16:31:05 +0000 | [diff] [blame] | 282 | { |
Jean-Jacques Hiblot | d60ae4c | 2019-10-22 10:05:22 +0200 | [diff] [blame] | 283 | const unaligned_fdt64_t *cell64; |
Che-Liang Chiou | aadef0a | 2012-10-25 16:31:05 +0000 | [diff] [blame] | 284 | int length; |
| 285 | |
| 286 | cell64 = fdt_getprop(blob, node, prop_name, &length); |
| 287 | if (!cell64 || length < sizeof(*cell64)) |
| 288 | return default_val; |
| 289 | |
| 290 | return fdt64_to_cpu(*cell64); |
| 291 | } |
| 292 | |
Simon Glass | f88fe2d | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 293 | int fdtdec_get_is_enabled(const void *blob, int node) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 294 | { |
| 295 | const char *cell; |
| 296 | |
Simon Glass | f88fe2d | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 297 | /* |
| 298 | * It should say "okay", so only allow that. Some fdts use "ok" but |
| 299 | * this is a bug. Please fix your device tree source file. See here |
| 300 | * for discussion: |
| 301 | * |
| 302 | * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html |
| 303 | */ |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 304 | cell = fdt_getprop(blob, node, "status", NULL); |
| 305 | if (cell) |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 306 | return strcmp(cell, "okay") == 0; |
Simon Glass | f88fe2d | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 307 | return 1; |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Gerald Van Baren | 7cde397 | 2012-11-12 23:13:54 -0500 | [diff] [blame] | 310 | enum fdt_compat_id fdtdec_lookup(const void *blob, int node) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 311 | { |
| 312 | enum fdt_compat_id id; |
| 313 | |
| 314 | /* Search our drivers */ |
| 315 | for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++) |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 316 | if (fdt_node_check_compatible(blob, node, |
| 317 | compat_names[id]) == 0) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 318 | return id; |
| 319 | return COMPAT_UNKNOWN; |
| 320 | } |
| 321 | |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 322 | int fdtdec_next_compatible(const void *blob, int node, enum fdt_compat_id id) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 323 | { |
| 324 | return fdt_node_offset_by_compatible(blob, node, compat_names[id]); |
| 325 | } |
| 326 | |
Simon Glass | 3ddecfc | 2012-04-02 13:18:42 +0000 | [diff] [blame] | 327 | int fdtdec_next_compatible_subnode(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 328 | enum fdt_compat_id id, int *depthp) |
Simon Glass | 3ddecfc | 2012-04-02 13:18:42 +0000 | [diff] [blame] | 329 | { |
| 330 | do { |
| 331 | node = fdt_next_node(blob, node, depthp); |
| 332 | } while (*depthp > 1); |
| 333 | |
| 334 | /* If this is a direct subnode, and compatible, return it */ |
| 335 | if (*depthp == 1 && 0 == fdt_node_check_compatible( |
| 336 | blob, node, compat_names[id])) |
| 337 | return node; |
| 338 | |
| 339 | return -FDT_ERR_NOTFOUND; |
| 340 | } |
| 341 | |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 342 | int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id, |
| 343 | int *upto) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 344 | { |
| 345 | #define MAX_STR_LEN 20 |
| 346 | char str[MAX_STR_LEN + 20]; |
| 347 | int node, err; |
| 348 | |
| 349 | /* snprintf() is not available */ |
| 350 | assert(strlen(name) < MAX_STR_LEN); |
| 351 | sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto); |
Simon Glass | 0087847 | 2012-10-31 14:02:42 +0000 | [diff] [blame] | 352 | node = fdt_path_offset(blob, str); |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 353 | if (node < 0) |
| 354 | return node; |
| 355 | err = fdt_node_check_compatible(blob, node, compat_names[id]); |
| 356 | if (err < 0) |
| 357 | return err; |
Simon Glass | f88fe2d | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 358 | if (err) |
| 359 | return -FDT_ERR_NOTFOUND; |
| 360 | (*upto)++; |
| 361 | return node; |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 364 | int fdtdec_find_aliases_for_id(const void *blob, const char *name, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 365 | enum fdt_compat_id id, int *node_list, |
| 366 | int maxcount) |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 367 | { |
Simon Glass | c678227 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 368 | memset(node_list, '\0', sizeof(*node_list) * maxcount); |
| 369 | |
| 370 | return fdtdec_add_aliases_for_id(blob, name, id, node_list, maxcount); |
| 371 | } |
| 372 | |
| 373 | /* TODO: Can we tighten this code up a little? */ |
| 374 | int fdtdec_add_aliases_for_id(const void *blob, const char *name, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 375 | enum fdt_compat_id id, int *node_list, |
| 376 | int maxcount) |
Simon Glass | c678227 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 377 | { |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 378 | int name_len = strlen(name); |
| 379 | int nodes[maxcount]; |
| 380 | int num_found = 0; |
| 381 | int offset, node; |
| 382 | int alias_node; |
| 383 | int count; |
| 384 | int i, j; |
| 385 | |
| 386 | /* find the alias node if present */ |
| 387 | alias_node = fdt_path_offset(blob, "/aliases"); |
| 388 | |
| 389 | /* |
| 390 | * start with nothing, and we can assume that the root node can't |
| 391 | * match |
| 392 | */ |
| 393 | memset(nodes, '\0', sizeof(nodes)); |
| 394 | |
| 395 | /* First find all the compatible nodes */ |
| 396 | for (node = count = 0; node >= 0 && count < maxcount;) { |
| 397 | node = fdtdec_next_compatible(blob, node, id); |
| 398 | if (node >= 0) |
| 399 | nodes[count++] = node; |
| 400 | } |
| 401 | if (node >= 0) |
| 402 | debug("%s: warning: maxcount exceeded with alias '%s'\n", |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 403 | __func__, name); |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 404 | |
| 405 | /* Now find all the aliases */ |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 406 | for (offset = fdt_first_property_offset(blob, alias_node); |
| 407 | offset > 0; |
| 408 | offset = fdt_next_property_offset(blob, offset)) { |
| 409 | const struct fdt_property *prop; |
| 410 | const char *path; |
| 411 | int number; |
| 412 | int found; |
| 413 | |
| 414 | node = 0; |
| 415 | prop = fdt_get_property_by_offset(blob, offset, NULL); |
| 416 | path = fdt_string(blob, fdt32_to_cpu(prop->nameoff)); |
| 417 | if (prop->len && 0 == strncmp(path, name, name_len)) |
| 418 | node = fdt_path_offset(blob, prop->data); |
| 419 | if (node <= 0) |
| 420 | continue; |
| 421 | |
| 422 | /* Get the alias number */ |
Simon Glass | 0b1284e | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 423 | number = dectoul(path + name_len, NULL); |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 424 | if (number < 0 || number >= maxcount) { |
| 425 | debug("%s: warning: alias '%s' is out of range\n", |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 426 | __func__, path); |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 427 | continue; |
| 428 | } |
| 429 | |
| 430 | /* Make sure the node we found is actually in our list! */ |
| 431 | found = -1; |
| 432 | for (j = 0; j < count; j++) |
| 433 | if (nodes[j] == node) { |
| 434 | found = j; |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | if (found == -1) { |
| 439 | debug("%s: warning: alias '%s' points to a node " |
| 440 | "'%s' that is missing or is not compatible " |
| 441 | " with '%s'\n", __func__, path, |
| 442 | fdt_get_name(blob, node, NULL), |
| 443 | compat_names[id]); |
| 444 | continue; |
| 445 | } |
| 446 | |
| 447 | /* |
| 448 | * Add this node to our list in the right place, and mark |
| 449 | * it as done. |
| 450 | */ |
| 451 | if (fdtdec_get_is_enabled(blob, node)) { |
Simon Glass | c678227 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 452 | if (node_list[number]) { |
| 453 | debug("%s: warning: alias '%s' requires that " |
| 454 | "a node be placed in the list in a " |
| 455 | "position which is already filled by " |
| 456 | "node '%s'\n", __func__, path, |
| 457 | fdt_get_name(blob, node, NULL)); |
| 458 | continue; |
| 459 | } |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 460 | node_list[number] = node; |
| 461 | if (number >= num_found) |
| 462 | num_found = number + 1; |
| 463 | } |
Simon Glass | c678227 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 464 | nodes[found] = 0; |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* Add any nodes not mentioned by an alias */ |
| 468 | for (i = j = 0; i < maxcount; i++) { |
| 469 | if (!node_list[i]) { |
| 470 | for (; j < maxcount; j++) |
| 471 | if (nodes[j] && |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 472 | fdtdec_get_is_enabled(blob, nodes[j])) |
Simon Glass | a53f4a2 | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 473 | break; |
| 474 | |
| 475 | /* Have we run out of nodes to add? */ |
| 476 | if (j == maxcount) |
| 477 | break; |
| 478 | |
| 479 | assert(!node_list[i]); |
| 480 | node_list[i] = nodes[j++]; |
| 481 | if (i >= num_found) |
| 482 | num_found = i + 1; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return num_found; |
| 487 | } |
| 488 | |
Simon Glass | 5c33c9f | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 489 | int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, |
| 490 | int *seqp) |
| 491 | { |
| 492 | int base_len = strlen(base); |
| 493 | const char *find_name; |
| 494 | int find_namelen; |
| 495 | int prop_offset; |
| 496 | int aliases; |
| 497 | |
| 498 | find_name = fdt_get_name(blob, offset, &find_namelen); |
| 499 | debug("Looking for '%s' at %d, name %s\n", base, offset, find_name); |
| 500 | |
| 501 | aliases = fdt_path_offset(blob, "/aliases"); |
| 502 | for (prop_offset = fdt_first_property_offset(blob, aliases); |
| 503 | prop_offset > 0; |
| 504 | prop_offset = fdt_next_property_offset(blob, prop_offset)) { |
| 505 | const char *prop; |
| 506 | const char *name; |
| 507 | const char *slash; |
Simon Glass | c4af673 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 508 | int len, val; |
Simon Glass | 5c33c9f | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 509 | |
| 510 | prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len); |
| 511 | debug(" - %s, %s\n", name, prop); |
| 512 | if (len < find_namelen || *prop != '/' || prop[len - 1] || |
| 513 | strncmp(name, base, base_len)) |
| 514 | continue; |
| 515 | |
| 516 | slash = strrchr(prop, '/'); |
| 517 | if (strcmp(slash + 1, find_name)) |
| 518 | continue; |
Aswath Govindraju | c589132 | 2020-12-03 10:55:45 +0530 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * Adding an extra check to distinguish DT nodes with |
| 522 | * same name |
| 523 | */ |
Simon Glass | ebc1d50 | 2022-12-21 16:08:28 -0700 | [diff] [blame] | 524 | if (IS_ENABLED(CONFIG_PHANDLE_CHECK_SEQ)) { |
| 525 | if (fdt_get_phandle(blob, offset) != |
| 526 | fdt_get_phandle(blob, fdt_path_offset(blob, prop))) |
| 527 | continue; |
| 528 | } |
Aswath Govindraju | c589132 | 2020-12-03 10:55:45 +0530 | [diff] [blame] | 529 | |
Simon Glass | c4af673 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 530 | val = trailing_strtol(name); |
| 531 | if (val != -1) { |
| 532 | *seqp = val; |
| 533 | debug("Found seq %d\n", *seqp); |
| 534 | return 0; |
Simon Glass | 5c33c9f | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | debug("Not found\n"); |
| 539 | return -ENOENT; |
| 540 | } |
| 541 | |
Michal Simek | 003c9dc | 2019-01-31 16:30:58 +0100 | [diff] [blame] | 542 | int fdtdec_get_alias_highest_id(const void *blob, const char *base) |
| 543 | { |
| 544 | int base_len = strlen(base); |
| 545 | int prop_offset; |
| 546 | int aliases; |
| 547 | int max = -1; |
| 548 | |
| 549 | debug("Looking for highest alias id for '%s'\n", base); |
| 550 | |
| 551 | aliases = fdt_path_offset(blob, "/aliases"); |
| 552 | for (prop_offset = fdt_first_property_offset(blob, aliases); |
| 553 | prop_offset > 0; |
| 554 | prop_offset = fdt_next_property_offset(blob, prop_offset)) { |
| 555 | const char *prop; |
| 556 | const char *name; |
| 557 | int len, val; |
| 558 | |
| 559 | prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len); |
| 560 | debug(" - %s, %s\n", name, prop); |
| 561 | if (*prop != '/' || prop[len - 1] || |
| 562 | strncmp(name, base, base_len)) |
| 563 | continue; |
| 564 | |
| 565 | val = trailing_strtol(name); |
| 566 | if (val > max) { |
| 567 | debug("Found seq %d\n", val); |
| 568 | max = val; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | return max; |
| 573 | } |
| 574 | |
Simon Glass | 3bc37a5 | 2015-10-17 19:41:14 -0600 | [diff] [blame] | 575 | const char *fdtdec_get_chosen_prop(const void *blob, const char *name) |
| 576 | { |
| 577 | int chosen_node; |
| 578 | |
| 579 | if (!blob) |
| 580 | return NULL; |
| 581 | chosen_node = fdt_path_offset(blob, "/chosen"); |
| 582 | return fdt_getprop(blob, chosen_node, name, NULL); |
| 583 | } |
| 584 | |
Simon Glass | aac07d4 | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 585 | int fdtdec_get_chosen_node(const void *blob, const char *name) |
| 586 | { |
| 587 | const char *prop; |
Simon Glass | aac07d4 | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 588 | |
Simon Glass | 3bc37a5 | 2015-10-17 19:41:14 -0600 | [diff] [blame] | 589 | prop = fdtdec_get_chosen_prop(blob, name); |
Simon Glass | aac07d4 | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 590 | if (!prop) |
| 591 | return -FDT_ERR_NOTFOUND; |
| 592 | return fdt_path_offset(blob, prop); |
| 593 | } |
| 594 | |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 595 | /** |
| 596 | * fdtdec_prepare_fdt() - Check we have a valid fdt available to control U-Boot |
| 597 | * |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 598 | * @blob: Blob to check |
| 599 | * |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 600 | * If not, a message is printed to the console if the console is ready. |
| 601 | * |
| 602 | * Return: 0 if all ok, -ENOENT if not |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 603 | */ |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 604 | static int fdtdec_prepare_fdt(const void *blob) |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 605 | { |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 606 | if (!blob || ((uintptr_t)blob & 3) || fdt_check_header(blob)) { |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 607 | if (spl_phase() <= PHASE_SPL) { |
| 608 | puts("Missing DTB\n"); |
| 609 | } else { |
| 610 | printf("No valid device tree binary found at %p\n", |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 611 | blob); |
| 612 | if (_DEBUG && blob) { |
| 613 | printf("fdt_blob=%p\n", blob); |
| 614 | print_buffer((ulong)blob, blob, 4, 32, 0); |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 615 | } |
Simon Glass | cb5f97f70 | 2015-06-23 15:39:09 -0600 | [diff] [blame] | 616 | } |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 617 | return -ENOENT; |
Simon Glass | 9a263e5 | 2012-03-28 10:08:24 +0000 | [diff] [blame] | 618 | } |
Simon Glass | b62d349 | 2022-12-21 16:08:19 -0700 | [diff] [blame] | 619 | |
Simon Glass | b5220bc | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 620 | return 0; |
| 621 | } |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 622 | |
Simon Glass | c662d0b | 2022-12-21 16:08:18 -0700 | [diff] [blame] | 623 | int fdtdec_check_fdt(void) |
| 624 | { |
| 625 | /* |
| 626 | * We must have an FDT, but we cannot panic() yet since the console |
| 627 | * is not ready. So for now, just assert(). Boards which need an early |
| 628 | * FDT (prior to console ready) will need to make their own |
| 629 | * arrangements and do their own checks. |
| 630 | */ |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 631 | assert(!fdtdec_prepare_fdt(gd->fdt_blob)); |
Simon Glass | c662d0b | 2022-12-21 16:08:18 -0700 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 635 | int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) |
| 636 | { |
| 637 | const u32 *phandle; |
| 638 | int lookup; |
| 639 | |
Simon Glass | 1cb2323 | 2012-07-12 05:25:01 +0000 | [diff] [blame] | 640 | debug("%s: %s\n", __func__, prop_name); |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 641 | phandle = fdt_getprop(blob, node, prop_name, NULL); |
| 642 | if (!phandle) |
| 643 | return -FDT_ERR_NOTFOUND; |
| 644 | |
| 645 | lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle)); |
| 646 | return lookup; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Look up a property in a node and check that it has a minimum length. |
| 651 | * |
| 652 | * @param blob FDT blob |
| 653 | * @param node node to examine |
| 654 | * @param prop_name name of property to find |
| 655 | * @param min_len minimum property length in bytes |
| 656 | * @param err 0 if ok, or -FDT_ERR_NOTFOUND if the property is not |
| 657 | found, or -FDT_ERR_BADLAYOUT if not enough data |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 658 | * Return: pointer to cell, which is only valid if err == 0 |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 659 | */ |
| 660 | static const void *get_prop_check_min_len(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 661 | const char *prop_name, int min_len, |
| 662 | int *err) |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 663 | { |
| 664 | const void *cell; |
| 665 | int len; |
| 666 | |
| 667 | debug("%s: %s\n", __func__, prop_name); |
| 668 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 669 | if (!cell) |
| 670 | *err = -FDT_ERR_NOTFOUND; |
| 671 | else if (len < min_len) |
| 672 | *err = -FDT_ERR_BADLAYOUT; |
| 673 | else |
| 674 | *err = 0; |
| 675 | return cell; |
| 676 | } |
| 677 | |
| 678 | int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 679 | u32 *array, int count) |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 680 | { |
| 681 | const u32 *cell; |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 682 | int err = 0; |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 683 | |
| 684 | debug("%s: %s\n", __func__, prop_name); |
| 685 | cell = get_prop_check_min_len(blob, node, prop_name, |
| 686 | sizeof(u32) * count, &err); |
| 687 | if (!err) { |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 688 | int i; |
| 689 | |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 690 | for (i = 0; i < count; i++) |
| 691 | array[i] = fdt32_to_cpu(cell[i]); |
| 692 | } |
| 693 | return err; |
| 694 | } |
| 695 | |
Simon Glass | a9f04d4 | 2014-11-10 18:00:19 -0700 | [diff] [blame] | 696 | int fdtdec_get_int_array_count(const void *blob, int node, |
| 697 | const char *prop_name, u32 *array, int count) |
| 698 | { |
| 699 | const u32 *cell; |
| 700 | int len, elems; |
| 701 | int i; |
| 702 | |
| 703 | debug("%s: %s\n", __func__, prop_name); |
| 704 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 705 | if (!cell) |
| 706 | return -FDT_ERR_NOTFOUND; |
| 707 | elems = len / sizeof(u32); |
| 708 | if (count > elems) |
| 709 | count = elems; |
| 710 | for (i = 0; i < count; i++) |
| 711 | array[i] = fdt32_to_cpu(cell[i]); |
| 712 | |
| 713 | return count; |
| 714 | } |
| 715 | |
Simon Glass | 96875e7 | 2012-04-02 13:18:41 +0000 | [diff] [blame] | 716 | const u32 *fdtdec_locate_array(const void *blob, int node, |
| 717 | const char *prop_name, int count) |
| 718 | { |
| 719 | const u32 *cell; |
| 720 | int err; |
| 721 | |
| 722 | cell = get_prop_check_min_len(blob, node, prop_name, |
| 723 | sizeof(u32) * count, &err); |
| 724 | return err ? NULL : cell; |
| 725 | } |
| 726 | |
Simon Glass | d17da65 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 727 | int fdtdec_get_bool(const void *blob, int node, const char *prop_name) |
| 728 | { |
| 729 | const s32 *cell; |
| 730 | int len; |
| 731 | |
| 732 | debug("%s: %s\n", __func__, prop_name); |
| 733 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 734 | return cell != NULL; |
| 735 | } |
Simon Glass | ed3ee5c | 2012-02-27 10:52:36 +0000 | [diff] [blame] | 736 | |
Simon Glass | 57068a7 | 2015-01-05 20:05:26 -0700 | [diff] [blame] | 737 | int fdtdec_parse_phandle_with_args(const void *blob, int src_node, |
| 738 | const char *list_name, |
| 739 | const char *cells_name, |
| 740 | int cell_count, int index, |
| 741 | struct fdtdec_phandle_args *out_args) |
| 742 | { |
| 743 | const __be32 *list, *list_end; |
| 744 | int rc = 0, size, cur_index = 0; |
| 745 | uint32_t count = 0; |
| 746 | int node = -1; |
| 747 | int phandle; |
| 748 | |
| 749 | /* Retrieve the phandle list property */ |
| 750 | list = fdt_getprop(blob, src_node, list_name, &size); |
| 751 | if (!list) |
| 752 | return -ENOENT; |
| 753 | list_end = list + size / sizeof(*list); |
| 754 | |
| 755 | /* Loop over the phandles until all the requested entry is found */ |
| 756 | while (list < list_end) { |
| 757 | rc = -EINVAL; |
| 758 | count = 0; |
| 759 | |
| 760 | /* |
| 761 | * If phandle is 0, then it is an empty entry with no |
| 762 | * arguments. Skip forward to the next entry. |
| 763 | */ |
| 764 | phandle = be32_to_cpup(list++); |
| 765 | if (phandle) { |
| 766 | /* |
| 767 | * Find the provider node and parse the #*-cells |
| 768 | * property to determine the argument length. |
| 769 | * |
| 770 | * This is not needed if the cell count is hard-coded |
| 771 | * (i.e. cells_name not set, but cell_count is set), |
| 772 | * except when we're going to return the found node |
| 773 | * below. |
| 774 | */ |
| 775 | if (cells_name || cur_index == index) { |
| 776 | node = fdt_node_offset_by_phandle(blob, |
| 777 | phandle); |
Patrick Delaunay | cba487c | 2020-09-25 09:41:15 +0200 | [diff] [blame] | 778 | if (node < 0) { |
Simon Glass | 57068a7 | 2015-01-05 20:05:26 -0700 | [diff] [blame] | 779 | debug("%s: could not find phandle\n", |
| 780 | fdt_get_name(blob, src_node, |
| 781 | NULL)); |
| 782 | goto err; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | if (cells_name) { |
| 787 | count = fdtdec_get_int(blob, node, cells_name, |
| 788 | -1); |
| 789 | if (count == -1) { |
| 790 | debug("%s: could not get %s for %s\n", |
| 791 | fdt_get_name(blob, src_node, |
| 792 | NULL), |
| 793 | cells_name, |
| 794 | fdt_get_name(blob, node, |
| 795 | NULL)); |
| 796 | goto err; |
| 797 | } |
| 798 | } else { |
| 799 | count = cell_count; |
| 800 | } |
| 801 | |
| 802 | /* |
| 803 | * Make sure that the arguments actually fit in the |
| 804 | * remaining property data length |
| 805 | */ |
| 806 | if (list + count > list_end) { |
| 807 | debug("%s: arguments longer than property\n", |
| 808 | fdt_get_name(blob, src_node, NULL)); |
| 809 | goto err; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * All of the error cases above bail out of the loop, so at |
| 815 | * this point, the parsing is successful. If the requested |
| 816 | * index matches, then fill the out_args structure and return, |
| 817 | * or return -ENOENT for an empty entry. |
| 818 | */ |
| 819 | rc = -ENOENT; |
| 820 | if (cur_index == index) { |
| 821 | if (!phandle) |
| 822 | goto err; |
| 823 | |
| 824 | if (out_args) { |
| 825 | int i; |
| 826 | |
| 827 | if (count > MAX_PHANDLE_ARGS) { |
| 828 | debug("%s: too many arguments %d\n", |
| 829 | fdt_get_name(blob, src_node, |
| 830 | NULL), count); |
| 831 | count = MAX_PHANDLE_ARGS; |
| 832 | } |
| 833 | out_args->node = node; |
| 834 | out_args->args_count = count; |
| 835 | for (i = 0; i < count; i++) { |
| 836 | out_args->args[i] = |
| 837 | be32_to_cpup(list++); |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /* Found it! return success */ |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | node = -1; |
| 846 | list += count; |
| 847 | cur_index++; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Result will be one of: |
| 852 | * -ENOENT : index is for empty phandle |
| 853 | * -EINVAL : parsing error on data |
| 854 | * [1..n] : Number of phandle (count mode; when index = -1) |
| 855 | */ |
| 856 | rc = index < 0 ? cur_index : -ENOENT; |
| 857 | err: |
| 858 | return rc; |
| 859 | } |
| 860 | |
Anton Staff | bed4d89 | 2012-04-17 09:01:28 +0000 | [diff] [blame] | 861 | int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 862 | u8 *array, int count) |
Anton Staff | bed4d89 | 2012-04-17 09:01:28 +0000 | [diff] [blame] | 863 | { |
| 864 | const u8 *cell; |
| 865 | int err; |
| 866 | |
| 867 | cell = get_prop_check_min_len(blob, node, prop_name, count, &err); |
| 868 | if (!err) |
| 869 | memcpy(array, cell, count); |
| 870 | return err; |
| 871 | } |
| 872 | |
| 873 | const u8 *fdtdec_locate_byte_array(const void *blob, int node, |
Mario Six | 2e38662 | 2018-01-15 11:07:35 +0100 | [diff] [blame] | 874 | const char *prop_name, int count) |
Anton Staff | bed4d89 | 2012-04-17 09:01:28 +0000 | [diff] [blame] | 875 | { |
| 876 | const u8 *cell; |
| 877 | int err; |
| 878 | |
| 879 | cell = get_prop_check_min_len(blob, node, prop_name, count, &err); |
| 880 | if (err) |
| 881 | return NULL; |
| 882 | return cell; |
| 883 | } |
Abhilash Kesavan | 09258f1 | 2012-10-25 16:30:58 +0000 | [diff] [blame] | 884 | |
Simon Glass | 5f7bfdd | 2015-03-05 12:25:14 -0700 | [diff] [blame] | 885 | u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells) |
Thierry Reding | 56f4224 | 2014-08-26 17:33:53 +0200 | [diff] [blame] | 886 | { |
| 887 | u64 number = 0; |
| 888 | |
| 889 | while (cells--) |
| 890 | number = (number << 32) | fdt32_to_cpu(*ptr++); |
| 891 | |
| 892 | return number; |
| 893 | } |
| 894 | |
| 895 | int fdt_get_resource(const void *fdt, int node, const char *property, |
| 896 | unsigned int index, struct fdt_resource *res) |
| 897 | { |
| 898 | const fdt32_t *ptr, *end; |
| 899 | int na, ns, len, parent; |
| 900 | unsigned int i = 0; |
| 901 | |
| 902 | parent = fdt_parent_offset(fdt, node); |
| 903 | if (parent < 0) |
| 904 | return parent; |
| 905 | |
| 906 | na = fdt_address_cells(fdt, parent); |
| 907 | ns = fdt_size_cells(fdt, parent); |
| 908 | |
| 909 | ptr = fdt_getprop(fdt, node, property, &len); |
| 910 | if (!ptr) |
| 911 | return len; |
| 912 | |
| 913 | end = ptr + len / sizeof(*ptr); |
| 914 | |
| 915 | while (ptr + na + ns <= end) { |
| 916 | if (i == index) { |
Patrick Delaunay | feb7ac4 | 2021-04-06 09:38:06 +0200 | [diff] [blame] | 917 | if (CONFIG_IS_ENABLED(OF_TRANSLATE)) |
| 918 | res->start = fdt_translate_address(fdt, node, ptr); |
| 919 | else |
| 920 | res->start = fdtdec_get_number(ptr, na); |
| 921 | |
Mario Six | b79221a | 2018-01-15 11:07:36 +0100 | [diff] [blame] | 922 | res->end = res->start; |
Thierry Reding | 56f4224 | 2014-08-26 17:33:53 +0200 | [diff] [blame] | 923 | res->end += fdtdec_get_number(&ptr[na], ns) - 1; |
| 924 | return 0; |
| 925 | } |
| 926 | |
| 927 | ptr += na + ns; |
| 928 | i++; |
| 929 | } |
| 930 | |
| 931 | return -FDT_ERR_NOTFOUND; |
| 932 | } |
| 933 | |
| 934 | int fdt_get_named_resource(const void *fdt, int node, const char *property, |
| 935 | const char *prop_names, const char *name, |
| 936 | struct fdt_resource *res) |
| 937 | { |
| 938 | int index; |
| 939 | |
Simon Glass | b02e404 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 940 | index = fdt_stringlist_search(fdt, node, prop_names, name); |
Thierry Reding | 56f4224 | 2014-08-26 17:33:53 +0200 | [diff] [blame] | 941 | if (index < 0) |
| 942 | return index; |
| 943 | |
| 944 | return fdt_get_resource(fdt, node, property, index, res); |
| 945 | } |
Thierry Reding | 9f85eee | 2014-08-26 17:33:54 +0200 | [diff] [blame] | 946 | |
Simon Glass | 12e6711 | 2015-04-14 21:03:21 -0600 | [diff] [blame] | 947 | static int decode_timing_property(const void *blob, int node, const char *name, |
| 948 | struct timing_entry *result) |
| 949 | { |
| 950 | int length, ret = 0; |
| 951 | const u32 *prop; |
| 952 | |
| 953 | prop = fdt_getprop(blob, node, name, &length); |
| 954 | if (!prop) { |
| 955 | debug("%s: could not find property %s\n", |
| 956 | fdt_get_name(blob, node, NULL), name); |
| 957 | return length; |
| 958 | } |
| 959 | |
| 960 | if (length == sizeof(u32)) { |
| 961 | result->typ = fdtdec_get_int(blob, node, name, 0); |
| 962 | result->min = result->typ; |
| 963 | result->max = result->typ; |
| 964 | } else { |
| 965 | ret = fdtdec_get_int_array(blob, node, name, &result->min, 3); |
| 966 | } |
| 967 | |
| 968 | return ret; |
| 969 | } |
| 970 | |
| 971 | int fdtdec_decode_display_timing(const void *blob, int parent, int index, |
| 972 | struct display_timing *dt) |
| 973 | { |
| 974 | int i, node, timings_node; |
| 975 | u32 val = 0; |
| 976 | int ret = 0; |
| 977 | |
| 978 | timings_node = fdt_subnode_offset(blob, parent, "display-timings"); |
| 979 | if (timings_node < 0) |
| 980 | return timings_node; |
| 981 | |
| 982 | for (i = 0, node = fdt_first_subnode(blob, timings_node); |
| 983 | node > 0 && i != index; |
| 984 | node = fdt_next_subnode(blob, node)) |
| 985 | i++; |
| 986 | |
| 987 | if (node < 0) |
| 988 | return node; |
| 989 | |
| 990 | memset(dt, 0, sizeof(*dt)); |
| 991 | |
| 992 | ret |= decode_timing_property(blob, node, "hback-porch", |
| 993 | &dt->hback_porch); |
| 994 | ret |= decode_timing_property(blob, node, "hfront-porch", |
| 995 | &dt->hfront_porch); |
| 996 | ret |= decode_timing_property(blob, node, "hactive", &dt->hactive); |
| 997 | ret |= decode_timing_property(blob, node, "hsync-len", &dt->hsync_len); |
| 998 | ret |= decode_timing_property(blob, node, "vback-porch", |
| 999 | &dt->vback_porch); |
| 1000 | ret |= decode_timing_property(blob, node, "vfront-porch", |
| 1001 | &dt->vfront_porch); |
| 1002 | ret |= decode_timing_property(blob, node, "vactive", &dt->vactive); |
| 1003 | ret |= decode_timing_property(blob, node, "vsync-len", &dt->vsync_len); |
| 1004 | ret |= decode_timing_property(blob, node, "clock-frequency", |
| 1005 | &dt->pixelclock); |
| 1006 | |
| 1007 | dt->flags = 0; |
| 1008 | val = fdtdec_get_int(blob, node, "vsync-active", -1); |
| 1009 | if (val != -1) { |
| 1010 | dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH : |
| 1011 | DISPLAY_FLAGS_VSYNC_LOW; |
| 1012 | } |
| 1013 | val = fdtdec_get_int(blob, node, "hsync-active", -1); |
| 1014 | if (val != -1) { |
| 1015 | dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH : |
| 1016 | DISPLAY_FLAGS_HSYNC_LOW; |
| 1017 | } |
| 1018 | val = fdtdec_get_int(blob, node, "de-active", -1); |
| 1019 | if (val != -1) { |
| 1020 | dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH : |
| 1021 | DISPLAY_FLAGS_DE_LOW; |
| 1022 | } |
| 1023 | val = fdtdec_get_int(blob, node, "pixelclk-active", -1); |
| 1024 | if (val != -1) { |
| 1025 | dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE : |
| 1026 | DISPLAY_FLAGS_PIXDATA_NEGEDGE; |
| 1027 | } |
| 1028 | |
| 1029 | if (fdtdec_get_bool(blob, node, "interlaced")) |
| 1030 | dt->flags |= DISPLAY_FLAGS_INTERLACED; |
| 1031 | if (fdtdec_get_bool(blob, node, "doublescan")) |
| 1032 | dt->flags |= DISPLAY_FLAGS_DOUBLESCAN; |
| 1033 | if (fdtdec_get_bool(blob, node, "doubleclk")) |
| 1034 | dt->flags |= DISPLAY_FLAGS_DOUBLECLK; |
| 1035 | |
Simon Glass | 04b9dd1 | 2016-05-05 07:28:21 -0600 | [diff] [blame] | 1036 | return ret; |
Simon Glass | 12e6711 | 2015-04-14 21:03:21 -0600 | [diff] [blame] | 1037 | } |
| 1038 | |
Michal Simek | 50c7b72 | 2020-07-10 13:16:50 +0200 | [diff] [blame] | 1039 | int fdtdec_setup_mem_size_base(void) |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1040 | { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1041 | int ret; |
| 1042 | ofnode mem; |
| 1043 | struct resource res; |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1044 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1045 | mem = ofnode_path("/memory"); |
| 1046 | if (!ofnode_valid(mem)) { |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1047 | debug("%s: Missing /memory node\n", __func__); |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1051 | ret = ofnode_read_resource(mem, 0, &res); |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1052 | if (ret != 0) { |
| 1053 | debug("%s: Unable to decode first memory bank\n", __func__); |
| 1054 | return -EINVAL; |
| 1055 | } |
| 1056 | |
| 1057 | gd->ram_size = (phys_size_t)(res.end - res.start + 1); |
Siva Durga Prasad Paladugu | 1473b12 | 2018-07-16 15:56:10 +0530 | [diff] [blame] | 1058 | gd->ram_base = (unsigned long)res.start; |
Simon Glass | c69380f | 2017-05-27 07:38:13 -0600 | [diff] [blame] | 1059 | debug("%s: Initial DRAM size %llx\n", __func__, |
| 1060 | (unsigned long long)gd->ram_size); |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1065 | ofnode get_next_memory_node(ofnode mem) |
Jens Wiklander | 452bc12 | 2018-07-13 12:12:11 +0200 | [diff] [blame] | 1066 | { |
Jens Wiklander | 452bc12 | 2018-07-13 12:12:11 +0200 | [diff] [blame] | 1067 | do { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1068 | mem = ofnode_by_prop_value(mem, "device_type", "memory", 7); |
Simon Glass | 8909066 | 2022-09-06 20:27:17 -0600 | [diff] [blame] | 1069 | } while (!ofnode_is_enabled(mem)); |
Jens Wiklander | 452bc12 | 2018-07-13 12:12:11 +0200 | [diff] [blame] | 1070 | |
| 1071 | return mem; |
| 1072 | } |
| 1073 | |
Michal Simek | 62897c4 | 2020-07-10 13:16:49 +0200 | [diff] [blame] | 1074 | int fdtdec_setup_memory_banksize(void) |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1075 | { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1076 | int bank, ret, reg = 0; |
| 1077 | struct resource res; |
| 1078 | ofnode mem = ofnode_null(); |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1079 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1080 | mem = get_next_memory_node(mem); |
| 1081 | if (!ofnode_valid(mem)) { |
Michal Simek | 658954c | 2018-10-03 15:53:52 +0200 | [diff] [blame] | 1082 | debug("%s: Missing /memory node\n", __func__); |
| 1083 | return -EINVAL; |
| 1084 | } |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1085 | |
| 1086 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1087 | ret = ofnode_read_resource(mem, reg++, &res); |
| 1088 | if (ret < 0) { |
Marek Vasut | 942ee09 | 2017-11-27 05:32:42 +0100 | [diff] [blame] | 1089 | reg = 0; |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1090 | mem = get_next_memory_node(mem); |
Marek Vasut | 81d0cef | 2020-09-12 12:42:52 +0200 | [diff] [blame] | 1091 | if (!ofnode_valid(mem)) |
Michal Simek | 658954c | 2018-10-03 15:53:52 +0200 | [diff] [blame] | 1092 | break; |
| 1093 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1094 | ret = ofnode_read_resource(mem, reg++, &res); |
| 1095 | if (ret < 0) |
Michal Simek | 658954c | 2018-10-03 15:53:52 +0200 | [diff] [blame] | 1096 | break; |
| 1097 | } |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1098 | |
| 1099 | if (ret != 0) |
Michal Simek | 658954c | 2018-10-03 15:53:52 +0200 | [diff] [blame] | 1100 | return -EINVAL; |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1101 | |
| 1102 | gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; |
| 1103 | gd->bd->bi_dram[bank].size = |
| 1104 | (phys_size_t)(res.end - res.start + 1); |
| 1105 | |
| 1106 | debug("%s: DRAM Bank #%d: start = 0x%llx, size = 0x%llx\n", |
| 1107 | __func__, bank, |
| 1108 | (unsigned long long)gd->bd->bi_dram[bank].start, |
| 1109 | (unsigned long long)gd->bd->bi_dram[bank].size); |
| 1110 | } |
| 1111 | |
| 1112 | return 0; |
| 1113 | } |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1114 | |
| 1115 | int fdtdec_setup_mem_size_base_lowest(void) |
| 1116 | { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1117 | int bank, ret, reg = 0; |
| 1118 | struct resource res; |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1119 | unsigned long base; |
| 1120 | phys_size_t size; |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1121 | ofnode mem = ofnode_null(); |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1122 | |
| 1123 | gd->ram_base = (unsigned long)~0; |
| 1124 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1125 | mem = get_next_memory_node(mem); |
| 1126 | if (!ofnode_valid(mem)) { |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1127 | debug("%s: Missing /memory node\n", __func__); |
| 1128 | return -EINVAL; |
| 1129 | } |
| 1130 | |
| 1131 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1132 | ret = ofnode_read_resource(mem, reg++, &res); |
| 1133 | if (ret < 0) { |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1134 | reg = 0; |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1135 | mem = get_next_memory_node(mem); |
Marek Vasut | 81d0cef | 2020-09-12 12:42:52 +0200 | [diff] [blame] | 1136 | if (!ofnode_valid(mem)) |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1137 | break; |
| 1138 | |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1139 | ret = ofnode_read_resource(mem, reg++, &res); |
| 1140 | if (ret < 0) |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1141 | break; |
| 1142 | } |
Michal Simek | c2f0950 | 2020-07-10 13:34:44 +0200 | [diff] [blame] | 1143 | |
Michal Simek | 7fce739 | 2020-07-09 14:09:52 +0200 | [diff] [blame] | 1144 | if (ret != 0) |
| 1145 | return -EINVAL; |
| 1146 | |
| 1147 | base = (unsigned long)res.start; |
| 1148 | size = (phys_size_t)(res.end - res.start + 1); |
| 1149 | |
| 1150 | if (gd->ram_base > base && size) { |
| 1151 | gd->ram_base = base; |
| 1152 | gd->ram_size = size; |
| 1153 | debug("%s: Initial DRAM base %lx size %lx\n", |
| 1154 | __func__, base, (unsigned long)size); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
Nathan Rossi | 623f601 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1160 | |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1161 | static int uncompress_blob(const void *src, ulong sz_src, void **dstp) |
| 1162 | { |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1163 | #if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\ |
| 1164 | CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO) |
Marek Vasut | 95f4bbd | 2019-03-08 16:06:55 +0100 | [diff] [blame] | 1165 | size_t sz_out = CONFIG_VAL(MULTI_DTB_FIT_UNCOMPRESS_SZ); |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1166 | bool gzip = 0, lzo = 0; |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1167 | ulong sz_in = sz_src; |
| 1168 | void *dst; |
| 1169 | int rc; |
| 1170 | |
| 1171 | if (CONFIG_IS_ENABLED(GZIP)) |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1172 | if (gzip_parse_header(src, sz_in) >= 0) |
| 1173 | gzip = 1; |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1174 | if (CONFIG_IS_ENABLED(LZO)) |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1175 | if (!gzip && lzop_is_valid_header(src)) |
| 1176 | lzo = 1; |
| 1177 | |
| 1178 | if (!gzip && !lzo) |
| 1179 | return -EBADMSG; |
| 1180 | |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1181 | |
| 1182 | if (CONFIG_IS_ENABLED(MULTI_DTB_FIT_DYN_ALLOC)) { |
| 1183 | dst = malloc(sz_out); |
| 1184 | if (!dst) { |
| 1185 | puts("uncompress_blob: Unable to allocate memory\n"); |
| 1186 | return -ENOMEM; |
| 1187 | } |
| 1188 | } else { |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1189 | # if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA) |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1190 | dst = (void *)CONFIG_VAL(MULTI_DTB_FIT_USER_DEF_ADDR); |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1191 | # else |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1192 | return -ENOTSUPP; |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1193 | # endif |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1194 | } |
| 1195 | |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1196 | if (CONFIG_IS_ENABLED(GZIP) && gzip) |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1197 | rc = gunzip(dst, sz_out, (u8 *)src, &sz_in); |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1198 | else if (CONFIG_IS_ENABLED(LZO) && lzo) |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1199 | rc = lzop_decompress(src, sz_in, dst, &sz_out); |
Marek Vasut | 1fd3035 | 2019-03-13 21:11:22 +0100 | [diff] [blame] | 1200 | else |
| 1201 | hang(); |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1202 | |
| 1203 | if (rc < 0) { |
| 1204 | /* not a valid compressed blob */ |
| 1205 | puts("uncompress_blob: Unable to uncompress\n"); |
| 1206 | if (CONFIG_IS_ENABLED(MULTI_DTB_FIT_DYN_ALLOC)) |
| 1207 | free(dst); |
| 1208 | return -EBADMSG; |
| 1209 | } |
| 1210 | *dstp = dst; |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1211 | #else |
Marek Vasut | 410d9b6 | 2018-10-18 20:37:05 +0200 | [diff] [blame] | 1212 | *dstp = (void *)src; |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1213 | *dstp = (void *)src; |
| 1214 | #endif |
Marek Vasut | 410d9b6 | 2018-10-18 20:37:05 +0200 | [diff] [blame] | 1215 | return 0; |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1216 | } |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1217 | |
Simon Glass | 9855034 | 2021-12-16 20:59:31 -0700 | [diff] [blame] | 1218 | /** |
| 1219 | * fdt_find_separate() - Find a devicetree at the end of the image |
| 1220 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1221 | * Return: pointer to FDT blob |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1222 | */ |
Simon Glass | 9855034 | 2021-12-16 20:59:31 -0700 | [diff] [blame] | 1223 | static void *fdt_find_separate(void) |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1224 | { |
| 1225 | void *fdt_blob = NULL; |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 1226 | |
Simon Glass | 423cf0a | 2022-02-28 12:08:24 -0700 | [diff] [blame] | 1227 | if (IS_ENABLED(CONFIG_SANDBOX)) |
| 1228 | return NULL; |
| 1229 | |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1230 | #ifdef CONFIG_SPL_BUILD |
| 1231 | /* FDT is at end of BSS unless it is in a different memory region */ |
Andrew Abbott | 0de71bb | 2022-04-16 10:12:31 +1000 | [diff] [blame] | 1232 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
Shiji Yang | ccea96f | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 1233 | fdt_blob = (ulong *)_image_binary_end; |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1234 | else |
Shiji Yang | ccea96f | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 1235 | fdt_blob = (ulong *)__bss_end; |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1236 | #else |
| 1237 | /* FDT is at end of image */ |
Shiji Yang | ccea96f | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 1238 | fdt_blob = (ulong *)_end; |
Simon Glass | 9557592 | 2022-12-21 16:08:21 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (_DEBUG && !fdtdec_prepare_fdt(fdt_blob)) { |
| 1241 | int stack_ptr; |
| 1242 | const void *top = fdt_blob + fdt_totalsize(fdt_blob); |
| 1243 | |
| 1244 | /* |
| 1245 | * Perform a sanity check on the memory layout. If this fails, |
| 1246 | * it indicates that the device tree is positioned above the |
| 1247 | * global data pointer or the stack pointer. This should not |
| 1248 | * happen. |
| 1249 | * |
| 1250 | * If this fails, check that SYS_INIT_SP_ADDR has enough space |
| 1251 | * below it for SYS_MALLOC_F_LEN and global_data, as well as the |
| 1252 | * stack, without overwriting the device tree or U-Boot itself. |
| 1253 | * Since the device tree is sitting at _end (the start of the |
| 1254 | * BSS region), we need the top of the device tree to be below |
| 1255 | * any memory allocated by board_init_f_alloc_reserve(). |
| 1256 | */ |
| 1257 | if (top > (void *)gd || top > (void *)&stack_ptr) { |
| 1258 | printf("FDT %p gd %p\n", fdt_blob, gd); |
| 1259 | panic("FDT overlap"); |
| 1260 | } |
| 1261 | } |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1262 | #endif |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 1263 | |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1264 | return fdt_blob; |
| 1265 | } |
Rob Clark | 3b595da | 2018-01-10 11:34:37 +0100 | [diff] [blame] | 1266 | |
Thierry Reding | ebf30e8 | 2019-04-15 11:32:13 +0200 | [diff] [blame] | 1267 | int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size) |
| 1268 | { |
| 1269 | const char *path; |
| 1270 | int offset, err; |
| 1271 | |
| 1272 | if (!is_valid_ethaddr(mac)) |
| 1273 | return -EINVAL; |
| 1274 | |
| 1275 | path = fdt_get_alias(fdt, "ethernet"); |
| 1276 | if (!path) |
| 1277 | return 0; |
| 1278 | |
| 1279 | debug("ethernet alias found: %s\n", path); |
| 1280 | |
| 1281 | offset = fdt_path_offset(fdt, path); |
| 1282 | if (offset < 0) { |
| 1283 | debug("ethernet alias points to absent node %s\n", path); |
| 1284 | return -ENOENT; |
| 1285 | } |
| 1286 | |
| 1287 | err = fdt_setprop_inplace(fdt, offset, "local-mac-address", mac, size); |
| 1288 | if (err < 0) |
| 1289 | return err; |
| 1290 | |
| 1291 | debug("MAC address: %pM\n", mac); |
| 1292 | |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1296 | static int fdtdec_init_reserved_memory(void *blob) |
| 1297 | { |
| 1298 | int na, ns, node, err; |
| 1299 | fdt32_t value; |
| 1300 | |
| 1301 | /* inherit #address-cells and #size-cells from the root node */ |
| 1302 | na = fdt_address_cells(blob, 0); |
| 1303 | ns = fdt_size_cells(blob, 0); |
| 1304 | |
| 1305 | node = fdt_add_subnode(blob, 0, "reserved-memory"); |
| 1306 | if (node < 0) |
| 1307 | return node; |
| 1308 | |
| 1309 | err = fdt_setprop(blob, node, "ranges", NULL, 0); |
| 1310 | if (err < 0) |
| 1311 | return err; |
| 1312 | |
| 1313 | value = cpu_to_fdt32(ns); |
| 1314 | |
| 1315 | err = fdt_setprop(blob, node, "#size-cells", &value, sizeof(value)); |
| 1316 | if (err < 0) |
| 1317 | return err; |
| 1318 | |
| 1319 | value = cpu_to_fdt32(na); |
| 1320 | |
| 1321 | err = fdt_setprop(blob, node, "#address-cells", &value, sizeof(value)); |
| 1322 | if (err < 0) |
| 1323 | return err; |
| 1324 | |
| 1325 | return node; |
| 1326 | } |
| 1327 | |
| 1328 | int fdtdec_add_reserved_memory(void *blob, const char *basename, |
| 1329 | const struct fdt_memory *carveout, |
Thierry Reding | 46cb067 | 2021-09-03 15:16:19 +0200 | [diff] [blame] | 1330 | const char **compatibles, unsigned int count, |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1331 | uint32_t *phandlep, unsigned long flags) |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1332 | { |
| 1333 | fdt32_t cells[4] = {}, *ptr = cells; |
| 1334 | uint32_t upper, lower, phandle; |
| 1335 | int parent, node, na, ns, err; |
Thierry Reding | 3bf2f15 | 2019-04-15 10:08:21 +0200 | [diff] [blame] | 1336 | fdt_size_t size; |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1337 | char name[64]; |
| 1338 | |
| 1339 | /* create an empty /reserved-memory node if one doesn't exist */ |
| 1340 | parent = fdt_path_offset(blob, "/reserved-memory"); |
| 1341 | if (parent < 0) { |
| 1342 | parent = fdtdec_init_reserved_memory(blob); |
| 1343 | if (parent < 0) |
| 1344 | return parent; |
| 1345 | } |
| 1346 | |
| 1347 | /* only 1 or 2 #address-cells and #size-cells are supported */ |
| 1348 | na = fdt_address_cells(blob, parent); |
| 1349 | if (na < 1 || na > 2) |
| 1350 | return -FDT_ERR_BADNCELLS; |
| 1351 | |
| 1352 | ns = fdt_size_cells(blob, parent); |
| 1353 | if (ns < 1 || ns > 2) |
| 1354 | return -FDT_ERR_BADNCELLS; |
| 1355 | |
| 1356 | /* find a matching node and return the phandle to that */ |
| 1357 | fdt_for_each_subnode(node, blob, parent) { |
| 1358 | const char *name = fdt_get_name(blob, node, NULL); |
Bin Meng | a9ad113 | 2020-05-19 23:38:32 -0700 | [diff] [blame] | 1359 | fdt_addr_t addr; |
| 1360 | fdt_size_t size; |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1361 | |
Bin Meng | f6704c7 | 2020-05-19 23:38:33 -0700 | [diff] [blame] | 1362 | addr = fdtdec_get_addr_size_fixed(blob, node, "reg", 0, na, ns, |
| 1363 | &size, false); |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1364 | if (addr == FDT_ADDR_T_NONE) { |
| 1365 | debug("failed to read address/size for %s\n", name); |
| 1366 | continue; |
| 1367 | } |
| 1368 | |
Atish Patra | f614753 | 2020-04-21 11:15:00 -0700 | [diff] [blame] | 1369 | if (addr == carveout->start && (addr + size - 1) == |
| 1370 | carveout->end) { |
Heiko Stuebner | 086336a | 2019-10-23 16:46:38 +0200 | [diff] [blame] | 1371 | if (phandlep) |
| 1372 | *phandlep = fdt_get_phandle(blob, node); |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1373 | return 0; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | /* |
| 1378 | * Unpack the start address and generate the name of the new node |
| 1379 | * base on the basename and the unit-address. |
| 1380 | */ |
Thierry Reding | 3bf2f15 | 2019-04-15 10:08:21 +0200 | [diff] [blame] | 1381 | upper = upper_32_bits(carveout->start); |
| 1382 | lower = lower_32_bits(carveout->start); |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1383 | |
| 1384 | if (na > 1 && upper > 0) |
| 1385 | snprintf(name, sizeof(name), "%s@%x,%x", basename, upper, |
| 1386 | lower); |
| 1387 | else { |
| 1388 | if (upper > 0) { |
| 1389 | debug("address %08x:%08x exceeds addressable space\n", |
| 1390 | upper, lower); |
| 1391 | return -FDT_ERR_BADVALUE; |
| 1392 | } |
| 1393 | |
| 1394 | snprintf(name, sizeof(name), "%s@%x", basename, lower); |
| 1395 | } |
| 1396 | |
| 1397 | node = fdt_add_subnode(blob, parent, name); |
| 1398 | if (node < 0) |
| 1399 | return node; |
| 1400 | |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1401 | if (flags & FDTDEC_RESERVED_MEMORY_NO_MAP) { |
| 1402 | err = fdt_setprop(blob, node, "no-map", NULL, 0); |
| 1403 | if (err < 0) |
| 1404 | return err; |
| 1405 | } |
| 1406 | |
Heiko Stuebner | 357d2ce | 2019-10-23 16:46:39 +0200 | [diff] [blame] | 1407 | if (phandlep) { |
| 1408 | err = fdt_generate_phandle(blob, &phandle); |
| 1409 | if (err < 0) |
| 1410 | return err; |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1411 | |
Heiko Stuebner | 357d2ce | 2019-10-23 16:46:39 +0200 | [diff] [blame] | 1412 | err = fdtdec_set_phandle(blob, node, phandle); |
| 1413 | if (err < 0) |
| 1414 | return err; |
| 1415 | } |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1416 | |
| 1417 | /* store one or two address cells */ |
| 1418 | if (na > 1) |
| 1419 | *ptr++ = cpu_to_fdt32(upper); |
| 1420 | |
| 1421 | *ptr++ = cpu_to_fdt32(lower); |
| 1422 | |
| 1423 | /* store one or two size cells */ |
Thierry Reding | 3bf2f15 | 2019-04-15 10:08:21 +0200 | [diff] [blame] | 1424 | size = carveout->end - carveout->start + 1; |
| 1425 | upper = upper_32_bits(size); |
| 1426 | lower = lower_32_bits(size); |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1427 | |
| 1428 | if (ns > 1) |
| 1429 | *ptr++ = cpu_to_fdt32(upper); |
| 1430 | |
| 1431 | *ptr++ = cpu_to_fdt32(lower); |
| 1432 | |
| 1433 | err = fdt_setprop(blob, node, "reg", cells, (na + ns) * sizeof(*cells)); |
| 1434 | if (err < 0) |
| 1435 | return err; |
| 1436 | |
Thierry Reding | 46cb067 | 2021-09-03 15:16:19 +0200 | [diff] [blame] | 1437 | if (compatibles && count > 0) { |
| 1438 | size_t length = 0, len = 0; |
| 1439 | unsigned int i; |
| 1440 | char *buffer; |
| 1441 | |
| 1442 | for (i = 0; i < count; i++) |
| 1443 | length += strlen(compatibles[i]) + 1; |
| 1444 | |
| 1445 | buffer = malloc(length); |
| 1446 | if (!buffer) |
| 1447 | return -FDT_ERR_INTERNAL; |
| 1448 | |
| 1449 | for (i = 0; i < count; i++) |
| 1450 | len += strlcpy(buffer + len, compatibles[i], |
| 1451 | length - len) + 1; |
| 1452 | |
| 1453 | err = fdt_setprop(blob, node, "compatible", buffer, length); |
| 1454 | free(buffer); |
| 1455 | if (err < 0) |
| 1456 | return err; |
| 1457 | } |
| 1458 | |
Thierry Reding | c9222a0 | 2019-03-21 19:10:02 +0100 | [diff] [blame] | 1459 | /* return the phandle for the new node for the caller to use */ |
| 1460 | if (phandlep) |
| 1461 | *phandlep = phandle; |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Thierry Reding | 4bf88ba | 2021-09-03 15:16:18 +0200 | [diff] [blame] | 1466 | int fdtdec_get_carveout(const void *blob, const char *node, |
| 1467 | const char *prop_name, unsigned int index, |
Thierry Reding | 46cb067 | 2021-09-03 15:16:19 +0200 | [diff] [blame] | 1468 | struct fdt_memory *carveout, const char **name, |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1469 | const char ***compatiblesp, unsigned int *countp, |
| 1470 | unsigned long *flags) |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1471 | { |
| 1472 | const fdt32_t *prop; |
| 1473 | uint32_t phandle; |
| 1474 | int offset, len; |
| 1475 | fdt_size_t size; |
| 1476 | |
| 1477 | offset = fdt_path_offset(blob, node); |
| 1478 | if (offset < 0) |
| 1479 | return offset; |
| 1480 | |
Thierry Reding | 4bf88ba | 2021-09-03 15:16:18 +0200 | [diff] [blame] | 1481 | prop = fdt_getprop(blob, offset, prop_name, &len); |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1482 | if (!prop) { |
Thierry Reding | 4bf88ba | 2021-09-03 15:16:18 +0200 | [diff] [blame] | 1483 | debug("failed to get %s for %s\n", prop_name, node); |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1484 | return -FDT_ERR_NOTFOUND; |
| 1485 | } |
| 1486 | |
| 1487 | if ((len % sizeof(phandle)) != 0) { |
| 1488 | debug("invalid phandle property\n"); |
| 1489 | return -FDT_ERR_BADPHANDLE; |
| 1490 | } |
| 1491 | |
| 1492 | if (len < (sizeof(phandle) * (index + 1))) { |
| 1493 | debug("invalid phandle index\n"); |
Thierry Reding | d5598cf | 2021-09-03 15:16:17 +0200 | [diff] [blame] | 1494 | return -FDT_ERR_NOTFOUND; |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | phandle = fdt32_to_cpu(prop[index]); |
| 1498 | |
| 1499 | offset = fdt_node_offset_by_phandle(blob, phandle); |
| 1500 | if (offset < 0) { |
| 1501 | debug("failed to find node for phandle %u\n", phandle); |
| 1502 | return offset; |
| 1503 | } |
| 1504 | |
Thierry Reding | 4bf88ba | 2021-09-03 15:16:18 +0200 | [diff] [blame] | 1505 | if (name) |
| 1506 | *name = fdt_get_name(blob, offset, NULL); |
| 1507 | |
Thierry Reding | 46cb067 | 2021-09-03 15:16:19 +0200 | [diff] [blame] | 1508 | if (compatiblesp) { |
| 1509 | const char **compatibles = NULL; |
| 1510 | const char *start, *end, *ptr; |
| 1511 | unsigned int count = 0; |
| 1512 | |
| 1513 | prop = fdt_getprop(blob, offset, "compatible", &len); |
| 1514 | if (!prop) |
| 1515 | goto skip_compat; |
| 1516 | |
| 1517 | start = ptr = (const char *)prop; |
| 1518 | end = start + len; |
| 1519 | |
| 1520 | while (ptr < end) { |
| 1521 | ptr = strchrnul(ptr, '\0'); |
| 1522 | count++; |
| 1523 | ptr++; |
| 1524 | } |
| 1525 | |
| 1526 | compatibles = malloc(sizeof(ptr) * count); |
| 1527 | if (!compatibles) |
| 1528 | return -FDT_ERR_INTERNAL; |
| 1529 | |
| 1530 | ptr = start; |
| 1531 | count = 0; |
| 1532 | |
| 1533 | while (ptr < end) { |
| 1534 | compatibles[count] = ptr; |
| 1535 | ptr = strchrnul(ptr, '\0'); |
| 1536 | count++; |
| 1537 | ptr++; |
| 1538 | } |
| 1539 | |
| 1540 | skip_compat: |
| 1541 | *compatiblesp = compatibles; |
| 1542 | |
| 1543 | if (countp) |
| 1544 | *countp = count; |
| 1545 | } |
| 1546 | |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1547 | carveout->start = fdtdec_get_addr_size_auto_noparent(blob, offset, |
| 1548 | "reg", 0, &size, |
| 1549 | true); |
| 1550 | if (carveout->start == FDT_ADDR_T_NONE) { |
| 1551 | debug("failed to read address/size from \"reg\" property\n"); |
| 1552 | return -FDT_ERR_NOTFOUND; |
| 1553 | } |
| 1554 | |
| 1555 | carveout->end = carveout->start + size - 1; |
| 1556 | |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1557 | if (flags) { |
| 1558 | *flags = 0; |
| 1559 | |
| 1560 | if (fdtdec_get_bool(blob, offset, "no-map")) |
| 1561 | *flags |= FDTDEC_RESERVED_MEMORY_NO_MAP; |
| 1562 | } |
| 1563 | |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, |
Thierry Reding | 9019487 | 2021-09-03 15:16:20 +0200 | [diff] [blame] | 1568 | unsigned int index, const struct fdt_memory *carveout, |
| 1569 | const char *name, const char **compatibles, |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1570 | unsigned int count, unsigned long flags) |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1571 | { |
| 1572 | uint32_t phandle; |
Laurentiu Tudor | b9200b1 | 2020-04-03 13:43:03 +0300 | [diff] [blame] | 1573 | int err, offset, len; |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1574 | fdt32_t value; |
Laurentiu Tudor | b9200b1 | 2020-04-03 13:43:03 +0300 | [diff] [blame] | 1575 | void *prop; |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1576 | |
Thierry Reding | 46cb067 | 2021-09-03 15:16:19 +0200 | [diff] [blame] | 1577 | err = fdtdec_add_reserved_memory(blob, name, carveout, compatibles, |
Thierry Reding | b9aad37 | 2021-09-03 15:16:21 +0200 | [diff] [blame] | 1578 | count, &phandle, flags); |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1579 | if (err < 0) { |
| 1580 | debug("failed to add reserved memory: %d\n", err); |
| 1581 | return err; |
| 1582 | } |
| 1583 | |
| 1584 | offset = fdt_path_offset(blob, node); |
| 1585 | if (offset < 0) { |
| 1586 | debug("failed to find offset for node %s: %d\n", node, offset); |
| 1587 | return offset; |
| 1588 | } |
| 1589 | |
| 1590 | value = cpu_to_fdt32(phandle); |
| 1591 | |
Laurentiu Tudor | b9200b1 | 2020-04-03 13:43:03 +0300 | [diff] [blame] | 1592 | if (!fdt_getprop(blob, offset, prop_name, &len)) { |
| 1593 | if (len == -FDT_ERR_NOTFOUND) |
| 1594 | len = 0; |
| 1595 | else |
| 1596 | return len; |
| 1597 | } |
| 1598 | |
| 1599 | if ((index + 1) * sizeof(value) > len) { |
| 1600 | err = fdt_setprop_placeholder(blob, offset, prop_name, |
| 1601 | (index + 1) * sizeof(value), |
| 1602 | &prop); |
| 1603 | if (err < 0) { |
| 1604 | debug("failed to resize reserved memory property: %s\n", |
| 1605 | fdt_strerror(err)); |
| 1606 | return err; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | err = fdt_setprop_inplace_namelen_partial(blob, offset, prop_name, |
| 1611 | strlen(prop_name), |
| 1612 | index * sizeof(value), |
| 1613 | &value, sizeof(value)); |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1614 | if (err < 0) { |
Laurentiu Tudor | b9200b1 | 2020-04-03 13:43:03 +0300 | [diff] [blame] | 1615 | debug("failed to update %s property for node %s: %s\n", |
| 1616 | prop_name, node, fdt_strerror(err)); |
Thierry Reding | 16523ac | 2019-03-21 19:10:03 +0100 | [diff] [blame] | 1617 | return err; |
| 1618 | } |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Simon Glass | 275b483 | 2021-12-16 20:59:35 -0700 | [diff] [blame] | 1623 | /* TODO(sjg@chromium.org): This function should not be weak */ |
Marek Vasut | 0e2afc8 | 2020-04-11 21:18:59 +0200 | [diff] [blame] | 1624 | __weak int fdtdec_board_setup(const void *fdt_blob) |
| 1625 | { |
| 1626 | return 0; |
| 1627 | } |
| 1628 | |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1629 | /** |
| 1630 | * setup_multi_dtb_fit() - locate the correct dtb from a FIT |
| 1631 | * |
| 1632 | * This supports the CONFIG_MULTI_DTB_FIT feature, looking for the dtb in a |
| 1633 | * supplied FIT |
| 1634 | * |
| 1635 | * It accepts the current value of gd->fdt_blob, which points to the FIT, then |
| 1636 | * updates that gd->fdt_blob, to point to the chosen dtb so that U-Boot uses the |
| 1637 | * correct one |
| 1638 | */ |
| 1639 | static void setup_multi_dtb_fit(void) |
| 1640 | { |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1641 | void *blob; |
| 1642 | |
| 1643 | /* |
| 1644 | * Try and uncompress the blob. |
| 1645 | * Unfortunately there is no way to know how big the input blob really |
| 1646 | * is. So let us set the maximum input size arbitrarily high. 16MB |
| 1647 | * ought to be more than enough for packed DTBs. |
| 1648 | */ |
| 1649 | if (uncompress_blob(gd->fdt_blob, 0x1000000, &blob) == 0) |
| 1650 | gd->fdt_blob = blob; |
| 1651 | |
| 1652 | /* |
| 1653 | * Check if blob is a FIT images containings DTBs. |
| 1654 | * If so, pick the most relevant |
| 1655 | */ |
| 1656 | blob = locate_dtb_in_fit(gd->fdt_blob); |
| 1657 | if (blob) { |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1658 | gd_set_multi_dtb_fit(gd->fdt_blob); |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1659 | gd->fdt_blob = blob; |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1660 | gd->fdt_src = FDTSRC_FIT; |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1661 | } |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Simon Glass | 0879361 | 2015-02-27 22:06:35 -0700 | [diff] [blame] | 1664 | int fdtdec_setup(void) |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1665 | { |
Marek Vasut | 0e2afc8 | 2020-04-11 21:18:59 +0200 | [diff] [blame] | 1666 | int ret; |
Simon Glass | ba83d85 | 2021-12-16 20:59:30 -0700 | [diff] [blame] | 1667 | |
| 1668 | /* The devicetree is typically appended to U-Boot */ |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1669 | if (IS_ENABLED(CONFIG_OF_SEPARATE)) { |
Simon Glass | 9855034 | 2021-12-16 20:59:31 -0700 | [diff] [blame] | 1670 | gd->fdt_blob = fdt_find_separate(); |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1671 | gd->fdt_src = FDTSRC_SEPARATE; |
| 1672 | } else { /* embed dtb in ELF file for testing / development */ |
Simon Glass | 9855034 | 2021-12-16 20:59:31 -0700 | [diff] [blame] | 1673 | gd->fdt_blob = dtb_dt_embedded(); |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1674 | gd->fdt_src = FDTSRC_EMBED; |
| 1675 | } |
Simon Glass | 9855034 | 2021-12-16 20:59:31 -0700 | [diff] [blame] | 1676 | |
| 1677 | /* Allow the board to override the fdt address. */ |
| 1678 | if (IS_ENABLED(CONFIG_OF_BOARD)) { |
Simon Glass | ba83d85 | 2021-12-16 20:59:30 -0700 | [diff] [blame] | 1679 | gd->fdt_blob = board_fdt_blob_setup(&ret); |
| 1680 | if (ret) |
| 1681 | return ret; |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1682 | gd->fdt_src = FDTSRC_BOARD; |
Simon Glass | ba83d85 | 2021-12-16 20:59:30 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1685 | /* Allow the early environment to override the fdt address */ |
Simon Glass | 931511d | 2021-12-16 20:59:28 -0700 | [diff] [blame] | 1686 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) { |
Simon Glass | 39605c6 | 2021-12-16 20:59:33 -0700 | [diff] [blame] | 1687 | ulong addr; |
| 1688 | |
| 1689 | addr = env_get_hex("fdtcontroladdr", 0); |
| 1690 | if (addr) { |
| 1691 | gd->fdt_blob = map_sysmem(addr, 0); |
| 1692 | gd->fdt_src = FDTSRC_ENV; |
| 1693 | } |
Simon Glass | 931511d | 2021-12-16 20:59:28 -0700 | [diff] [blame] | 1694 | } |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1695 | |
Simon Glass | 3f51f78 | 2021-12-16 20:59:24 -0700 | [diff] [blame] | 1696 | if (CONFIG_IS_ENABLED(MULTI_DTB_FIT)) |
| 1697 | setup_multi_dtb_fit(); |
Jean-Jacques Hiblot | 2f57c95 | 2017-09-15 12:57:32 +0200 | [diff] [blame] | 1698 | |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 1699 | ret = fdtdec_prepare_fdt(gd->fdt_blob); |
Marek Vasut | 0e2afc8 | 2020-04-11 21:18:59 +0200 | [diff] [blame] | 1700 | if (!ret) |
| 1701 | ret = fdtdec_board_setup(gd->fdt_blob); |
Simon Glass | ee88ba7 | 2022-09-06 20:27:19 -0600 | [diff] [blame] | 1702 | oftree_reset(); |
| 1703 | |
Marek Vasut | 0e2afc8 | 2020-04-11 21:18:59 +0200 | [diff] [blame] | 1704 | return ret; |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Jean-Jacques Hiblot | f1d2bc9 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 1707 | int fdtdec_resetup(int *rescan) |
| 1708 | { |
| 1709 | void *fdt_blob; |
| 1710 | |
| 1711 | /* |
| 1712 | * If the current DTB is part of a compressed FIT image, |
| 1713 | * try to locate the best match from the uncompressed |
| 1714 | * FIT image stillpresent there. Save the time and space |
| 1715 | * required to uncompress it again. |
| 1716 | */ |
Simon Glass | b4b6daf | 2021-12-16 20:59:25 -0700 | [diff] [blame] | 1717 | if (gd_multi_dtb_fit()) { |
| 1718 | fdt_blob = locate_dtb_in_fit(gd_multi_dtb_fit()); |
Jean-Jacques Hiblot | f1d2bc9 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 1719 | |
| 1720 | if (fdt_blob == gd->fdt_blob) { |
| 1721 | /* |
| 1722 | * The best match did not change. no need to tear down |
| 1723 | * the DM and rescan the fdt. |
| 1724 | */ |
| 1725 | *rescan = 0; |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
| 1729 | *rescan = 1; |
| 1730 | gd->fdt_blob = fdt_blob; |
Simon Glass | ec4f327 | 2022-12-21 16:08:20 -0700 | [diff] [blame] | 1731 | return fdtdec_prepare_fdt(fdt_blob); |
Jean-Jacques Hiblot | f1d2bc9 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | /* |
| 1735 | * If multi_dtb_fit is NULL, it means that blob appended to u-boot is |
| 1736 | * not a FIT image containings DTB, but a single DTB. There is no need |
| 1737 | * to teard down DM and rescan the DT in this case. |
| 1738 | */ |
| 1739 | *rescan = 0; |
| 1740 | return 0; |
| 1741 | } |
Jean-Jacques Hiblot | f1d2bc9 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 1742 | |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1743 | int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id, |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1744 | phys_addr_t *basep, phys_size_t *sizep, |
| 1745 | struct bd_info *bd) |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1746 | { |
| 1747 | int addr_cells, size_cells; |
| 1748 | const u32 *cell, *end; |
| 1749 | u64 total_size, size, addr; |
| 1750 | int node, child; |
| 1751 | bool auto_size; |
| 1752 | int bank; |
| 1753 | int len; |
| 1754 | |
| 1755 | debug("%s: board_id=%d\n", __func__, board_id); |
| 1756 | if (!area) |
| 1757 | area = "/memory"; |
| 1758 | node = fdt_path_offset(blob, area); |
| 1759 | if (node < 0) { |
| 1760 | debug("No %s node found\n", area); |
| 1761 | return -ENOENT; |
| 1762 | } |
| 1763 | |
| 1764 | cell = fdt_getprop(blob, node, "reg", &len); |
| 1765 | if (!cell) { |
| 1766 | debug("No reg property found\n"); |
| 1767 | return -ENOENT; |
| 1768 | } |
| 1769 | |
| 1770 | addr_cells = fdt_address_cells(blob, node); |
| 1771 | size_cells = fdt_size_cells(blob, node); |
| 1772 | |
| 1773 | /* Check the board id and mask */ |
| 1774 | for (child = fdt_first_subnode(blob, node); |
| 1775 | child >= 0; |
| 1776 | child = fdt_next_subnode(blob, child)) { |
| 1777 | int match_mask, match_value; |
| 1778 | |
| 1779 | match_mask = fdtdec_get_int(blob, child, "match-mask", -1); |
| 1780 | match_value = fdtdec_get_int(blob, child, "match-value", -1); |
| 1781 | |
| 1782 | if (match_value >= 0 && |
| 1783 | ((board_id & match_mask) == match_value)) { |
| 1784 | /* Found matching mask */ |
| 1785 | debug("Found matching mask %d\n", match_mask); |
| 1786 | node = child; |
| 1787 | cell = fdt_getprop(blob, node, "reg", &len); |
| 1788 | if (!cell) { |
| 1789 | debug("No memory-banks property found\n"); |
| 1790 | return -EINVAL; |
| 1791 | } |
| 1792 | break; |
| 1793 | } |
| 1794 | } |
| 1795 | /* Note: if no matching subnode was found we use the parent node */ |
| 1796 | |
| 1797 | if (bd) { |
| 1798 | memset(bd->bi_dram, '\0', sizeof(bd->bi_dram[0]) * |
| 1799 | CONFIG_NR_DRAM_BANKS); |
| 1800 | } |
| 1801 | |
| 1802 | auto_size = fdtdec_get_bool(blob, node, "auto-size"); |
| 1803 | |
| 1804 | total_size = 0; |
| 1805 | end = cell + len / 4 - addr_cells - size_cells; |
| 1806 | debug("cell at %p, end %p\n", cell, end); |
| 1807 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 1808 | if (cell > end) |
| 1809 | break; |
| 1810 | addr = 0; |
| 1811 | if (addr_cells == 2) |
| 1812 | addr += (u64)fdt32_to_cpu(*cell++) << 32UL; |
| 1813 | addr += fdt32_to_cpu(*cell++); |
| 1814 | if (bd) |
| 1815 | bd->bi_dram[bank].start = addr; |
| 1816 | if (basep && !bank) |
| 1817 | *basep = (phys_addr_t)addr; |
| 1818 | |
| 1819 | size = 0; |
| 1820 | if (size_cells == 2) |
| 1821 | size += (u64)fdt32_to_cpu(*cell++) << 32UL; |
| 1822 | size += fdt32_to_cpu(*cell++); |
| 1823 | |
| 1824 | if (auto_size) { |
| 1825 | u64 new_size; |
| 1826 | |
Masahiro Yamada | dee37fc | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 1827 | debug("Auto-sizing %llx, size %llx: ", addr, size); |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1828 | new_size = get_ram_size((long *)(uintptr_t)addr, size); |
| 1829 | if (new_size == size) { |
| 1830 | debug("OK\n"); |
| 1831 | } else { |
Masahiro Yamada | dee37fc | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 1832 | debug("sized to %llx\n", new_size); |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1833 | size = new_size; |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | if (bd) |
| 1838 | bd->bi_dram[bank].size = size; |
| 1839 | total_size += size; |
| 1840 | } |
| 1841 | |
Masahiro Yamada | dee37fc | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 1842 | debug("Memory size %llu\n", total_size); |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1843 | if (sizep) |
| 1844 | *sizep = (phys_size_t)total_size; |
| 1845 | |
| 1846 | return 0; |
| 1847 | } |
Michael Pratt | 90c08fa | 2018-06-11 13:07:09 -0600 | [diff] [blame] | 1848 | |
Simon Glass | b45122f | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1849 | #endif /* !USE_HOSTCC */ |