Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 3 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Heiko Schocher | d7b4232 | 2014-03-03 12:19:30 +0100 | [diff] [blame] | 6 | #ifndef USE_HOSTCC |
Cooper Jr., Franklin | 7900ce8 | 2017-06-16 17:25:07 -0500 | [diff] [blame] | 7 | #include <boot_fit.h> |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | f1037ad | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 9908ad4 | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 11 | #include <serial.h> |
| 12 | #include <libfdt.h> |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 13 | #include <fdt_support.h> |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 14 | #include <fdtdec.h> |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 15 | #include <asm/sections.h> |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 16 | #include <dm/of_extra.h> |
Simon Glass | 9908ad4 | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 17 | #include <linux/ctype.h> |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | /* |
| 22 | * Here are the type we know about. One day we might allow drivers to |
| 23 | * register. For now we just put them here. The COMPAT macro allows us to |
| 24 | * turn this into a sparse list later, and keeps the ID with the name. |
Simon Glass | 7c38030 | 2016-06-19 17:33:13 -0600 | [diff] [blame] | 25 | * |
| 26 | * NOTE: This list is basically a TODO list for things that need to be |
| 27 | * converted to driver model. So don't add new things here unless there is a |
| 28 | * good reason why driver-model conversion is infeasible. Examples include |
| 29 | * things which are used before driver model is available. |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 30 | */ |
| 31 | #define COMPAT(id, name) name |
| 32 | static const char * const compat_names[COMPAT_COUNT] = { |
Simon Glass | 6544498 | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 33 | COMPAT(UNKNOWN, "<none>"), |
Jimmy Zhang | 5983ef8 | 2012-04-02 13:18:52 +0000 | [diff] [blame] | 34 | COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"), |
| 35 | COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"), |
Jim Lin | 5d309e6 | 2012-07-29 20:53:29 +0000 | [diff] [blame] | 36 | COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"), |
Thierry Reding | f202e02 | 2014-12-09 22:25:09 -0700 | [diff] [blame] | 37 | COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"), |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 38 | COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"), |
Hatim RV | be5ad5a | 2012-12-11 00:52:46 +0000 | [diff] [blame] | 39 | COMPAT(SMSC_LAN9215, "smsc,lan9215"), |
| 40 | COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"), |
Rajeshwari Shinde | 2b71e9d | 2012-12-26 20:03:10 +0000 | [diff] [blame] | 41 | COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"), |
Rajeshwari Shinde | 9d11673 | 2012-12-26 20:03:16 +0000 | [diff] [blame] | 42 | COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"), |
| 43 | COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"), |
Rajeshwari Shinde | d6e9f44 | 2013-01-07 23:35:05 +0000 | [diff] [blame] | 44 | COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"), |
Vivek Gautam | f874523 | 2013-09-14 14:02:48 +0530 | [diff] [blame] | 45 | COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"), |
Akshay Saraswat | aa77318 | 2013-02-25 01:13:01 +0000 | [diff] [blame] | 46 | COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"), |
Piotr Wilczek | 24e368a | 2014-03-07 14:59:39 +0100 | [diff] [blame] | 47 | COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"), |
Jaehoon Chung | e3fb6fa | 2014-05-16 13:59:51 +0900 | [diff] [blame] | 48 | COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"), |
Piotr Wilczek | 12cf19e | 2014-03-07 14:59:41 +0100 | [diff] [blame] | 49 | COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"), |
Przemyslaw Marczak | ff0e22b | 2015-04-20 20:07:45 +0200 | [diff] [blame] | 50 | COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686"), |
Simon Glass | 60956094 | 2013-03-11 06:08:08 +0000 | [diff] [blame] | 51 | COMPAT(GENERIC_SPI_FLASH, "spi-flash"), |
Rajeshwari Shinde | 003c28c | 2013-02-14 19:46:15 +0000 | [diff] [blame] | 52 | COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"), |
naveen krishna chatradhi | 0734bae | 2013-04-29 15:58:52 -0700 | [diff] [blame] | 53 | COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"), |
Ajay Kumar | e24c502 | 2014-09-05 16:53:33 +0530 | [diff] [blame] | 54 | COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"), |
Simon Glass | f79d538 | 2014-11-12 22:42:21 -0700 | [diff] [blame] | 55 | COMPAT(INTEL_MICROCODE, "intel,microcode"), |
Thierry Reding | 09c0cf2 | 2014-12-09 22:25:05 -0700 | [diff] [blame] | 56 | COMPAT(AMS_AS3722, "ams,as3722"), |
Bin Meng | 2bfd264 | 2015-02-05 23:42:26 +0800 | [diff] [blame] | 57 | COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"), |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 58 | COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"), |
Marek Vasut | 1749723 | 2015-07-25 10:48:14 +0200 | [diff] [blame] | 59 | COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"), |
Marek Vasut | f26c1ae | 2015-12-05 19:28:44 +0100 | [diff] [blame] | 60 | COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"), |
Simon Glass | 6f70c11 | 2016-06-19 17:33:14 -0600 | [diff] [blame] | 61 | COMPAT(INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"), |
| 62 | COMPAT(INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"), |
| 63 | COMPAT(INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"), |
Boris Brezillon | 57f2038 | 2016-06-15 21:09:23 +0200 | [diff] [blame] | 64 | COMPAT(COMPAT_SUNXI_NAND, "allwinner,sun4i-a10-nand"), |
Ley Foon Tan | b25ae72 | 2017-04-05 17:32:47 +0800 | [diff] [blame] | 65 | COMPAT(ALTERA_SOCFPGA_CLK, "altr,clk-mgr"), |
| 66 | COMPAT(ALTERA_SOCFPGA_PINCTRL_SINGLE, "pinctrl-single"), |
| 67 | COMPAT(ALTERA_SOCFPGA_H2F_BRG, "altr,socfpga-hps2fpga-bridge"), |
| 68 | COMPAT(ALTERA_SOCFPGA_LWH2F_BRG, "altr,socfpga-lwhps2fpga-bridge"), |
| 69 | COMPAT(ALTERA_SOCFPGA_F2H_BRG, "altr,socfpga-fpga2hps-bridge"), |
| 70 | COMPAT(ALTERA_SOCFPGA_F2SDR0, "altr,socfpga-fpga2sdram0-bridge"), |
| 71 | COMPAT(ALTERA_SOCFPGA_F2SDR1, "altr,socfpga-fpga2sdram1-bridge"), |
| 72 | COMPAT(ALTERA_SOCFPGA_F2SDR2, "altr,socfpga-fpga2sdram2-bridge"), |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 75 | const char *fdtdec_get_compatible(enum fdt_compat_id id) |
| 76 | { |
| 77 | /* We allow reading of the 'unknown' ID for testing purposes */ |
| 78 | assert(id >= 0 && id < COMPAT_COUNT); |
| 79 | return compat_names[id]; |
| 80 | } |
| 81 | |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 82 | fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node, |
| 83 | const char *prop_name, int index, int na, int ns, |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 84 | fdt_size_t *sizep, bool translate) |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 85 | { |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 86 | const fdt32_t *prop, *prop_end; |
| 87 | const fdt32_t *prop_addr, *prop_size, *prop_after_size; |
Simon Glass | 04c50d1 | 2015-08-02 18:13:50 -0600 | [diff] [blame] | 88 | int len; |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 89 | fdt_addr_t addr; |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 90 | |
Simon Glass | c8c86dd | 2012-07-12 05:25:01 +0000 | [diff] [blame] | 91 | debug("%s: %s: ", __func__, prop_name); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 92 | |
| 93 | if (na > (sizeof(fdt_addr_t) / sizeof(fdt32_t))) { |
| 94 | debug("(na too large for fdt_addr_t type)\n"); |
| 95 | return FDT_ADDR_T_NONE; |
| 96 | } |
| 97 | |
| 98 | if (ns > (sizeof(fdt_size_t) / sizeof(fdt32_t))) { |
| 99 | debug("(ns too large for fdt_size_t type)\n"); |
| 100 | return FDT_ADDR_T_NONE; |
| 101 | } |
| 102 | |
| 103 | prop = fdt_getprop(blob, node, prop_name, &len); |
| 104 | if (!prop) { |
| 105 | debug("(not found)\n"); |
| 106 | return FDT_ADDR_T_NONE; |
| 107 | } |
| 108 | prop_end = prop + (len / sizeof(*prop)); |
Simon Glass | c8c86dd | 2012-07-12 05:25:01 +0000 | [diff] [blame] | 109 | |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 110 | prop_addr = prop + (index * (na + ns)); |
| 111 | prop_size = prop_addr + na; |
| 112 | prop_after_size = prop_size + ns; |
| 113 | if (prop_after_size > prop_end) { |
| 114 | debug("(not enough data: expected >= %d cells, got %d cells)\n", |
| 115 | (u32)(prop_after_size - prop), ((u32)(prop_end - prop))); |
| 116 | return FDT_ADDR_T_NONE; |
Simon Glass | c8c86dd | 2012-07-12 05:25:01 +0000 | [diff] [blame] | 117 | } |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 118 | |
Vignesh R | 621cc09 | 2017-03-20 10:04:38 +0530 | [diff] [blame] | 119 | #if CONFIG_IS_ENABLED(OF_TRANSLATE) |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 120 | if (translate) |
| 121 | addr = fdt_translate_address(blob, node, prop_addr); |
| 122 | else |
| 123 | #endif |
| 124 | addr = fdtdec_get_number(prop_addr, na); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 125 | |
| 126 | if (sizep) { |
| 127 | *sizep = fdtdec_get_number(prop_size, ns); |
Simon Glass | 0b14dc7 | 2016-02-29 15:25:37 -0700 | [diff] [blame] | 128 | debug("addr=%08llx, size=%llx\n", (unsigned long long)addr, |
| 129 | (unsigned long long)*sizep); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 130 | } else { |
Simon Glass | 0b14dc7 | 2016-02-29 15:25:37 -0700 | [diff] [blame] | 131 | debug("addr=%08llx\n", (unsigned long long)addr); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | return addr; |
| 135 | } |
| 136 | |
| 137 | fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent, |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 138 | int node, const char *prop_name, int index, fdt_size_t *sizep, |
| 139 | bool translate) |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 140 | { |
| 141 | int na, ns; |
| 142 | |
| 143 | debug("%s: ", __func__); |
| 144 | |
| 145 | na = fdt_address_cells(blob, parent); |
| 146 | if (na < 1) { |
| 147 | debug("(bad #address-cells)\n"); |
| 148 | return FDT_ADDR_T_NONE; |
| 149 | } |
| 150 | |
| 151 | ns = fdt_size_cells(blob, parent); |
Przemyslaw Marczak | 7b42f4d | 2015-09-30 13:14:50 +0200 | [diff] [blame] | 152 | if (ns < 0) { |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 153 | debug("(bad #size-cells)\n"); |
| 154 | return FDT_ADDR_T_NONE; |
| 155 | } |
| 156 | |
| 157 | debug("na=%d, ns=%d, ", na, ns); |
| 158 | |
| 159 | return fdtdec_get_addr_size_fixed(blob, node, prop_name, index, na, |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 160 | ns, sizep, translate); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 164 | const char *prop_name, int index, fdt_size_t *sizep, |
| 165 | bool translate) |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 166 | { |
| 167 | int parent; |
| 168 | |
| 169 | debug("%s: ", __func__); |
| 170 | |
| 171 | parent = fdt_parent_offset(blob, node); |
| 172 | if (parent < 0) { |
| 173 | debug("(no parent found)\n"); |
| 174 | return FDT_ADDR_T_NONE; |
| 175 | } |
| 176 | |
| 177 | return fdtdec_get_addr_size_auto_parent(blob, parent, node, prop_name, |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 178 | index, sizep, translate); |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, |
| 182 | const char *prop_name, fdt_size_t *sizep) |
| 183 | { |
Stephen Warren | fda5916 | 2015-09-25 10:11:41 -0600 | [diff] [blame] | 184 | int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0; |
| 185 | |
Stephen Warren | 6dfe618 | 2015-08-06 15:31:02 -0600 | [diff] [blame] | 186 | return fdtdec_get_addr_size_fixed(blob, node, prop_name, 0, |
| 187 | sizeof(fdt_addr_t) / sizeof(fdt32_t), |
Stephen Warren | 7d30e10 | 2016-08-05 09:47:51 -0600 | [diff] [blame] | 188 | ns, sizep, false); |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Simon Glass | f429955 | 2013-03-19 04:58:51 +0000 | [diff] [blame] | 191 | fdt_addr_t fdtdec_get_addr(const void *blob, int node, |
| 192 | const char *prop_name) |
| 193 | { |
| 194 | return fdtdec_get_addr_size(blob, node, prop_name, NULL); |
| 195 | } |
| 196 | |
Simon Glass | f1037ad | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 197 | #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI) |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 198 | int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, |
| 199 | const char *prop_name, struct fdt_pci_addr *addr) |
| 200 | { |
| 201 | const u32 *cell; |
| 202 | int len; |
| 203 | int ret = -ENOENT; |
| 204 | |
| 205 | debug("%s: %s: ", __func__, prop_name); |
| 206 | |
| 207 | /* |
| 208 | * If we follow the pci bus bindings strictly, we should check |
| 209 | * the value of the node's parent node's #address-cells and |
| 210 | * #size-cells. They need to be 3 and 2 accordingly. However, |
| 211 | * for simplicity we skip the check here. |
| 212 | */ |
| 213 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 214 | if (!cell) |
| 215 | goto fail; |
| 216 | |
| 217 | if ((len % FDT_PCI_REG_SIZE) == 0) { |
| 218 | int num = len / FDT_PCI_REG_SIZE; |
| 219 | int i; |
| 220 | |
| 221 | for (i = 0; i < num; i++) { |
| 222 | debug("pci address #%d: %08lx %08lx %08lx\n", i, |
Stephen Warren | fed69ad | 2015-10-02 17:44:06 -0600 | [diff] [blame] | 223 | (ulong)fdt32_to_cpu(cell[0]), |
| 224 | (ulong)fdt32_to_cpu(cell[1]), |
| 225 | (ulong)fdt32_to_cpu(cell[2])); |
| 226 | if ((fdt32_to_cpu(*cell) & type) == type) { |
| 227 | addr->phys_hi = fdt32_to_cpu(cell[0]); |
| 228 | addr->phys_mid = fdt32_to_cpu(cell[1]); |
| 229 | addr->phys_lo = fdt32_to_cpu(cell[1]); |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 230 | break; |
| 231 | } else { |
| 232 | cell += (FDT_PCI_ADDR_CELLS + |
| 233 | FDT_PCI_SIZE_CELLS); |
| 234 | } |
| 235 | } |
| 236 | |
Simon Glass | 2eb77f1 | 2015-03-05 12:25:19 -0700 | [diff] [blame] | 237 | if (i == num) { |
| 238 | ret = -ENXIO; |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 239 | goto fail; |
Simon Glass | 2eb77f1 | 2015-03-05 12:25:19 -0700 | [diff] [blame] | 240 | } |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } else { |
| 244 | ret = -EINVAL; |
| 245 | } |
| 246 | |
| 247 | fail: |
| 248 | debug("(not found)\n"); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device) |
| 253 | { |
| 254 | const char *list, *end; |
| 255 | int len; |
| 256 | |
| 257 | list = fdt_getprop(blob, node, "compatible", &len); |
| 258 | if (!list) |
| 259 | return -ENOENT; |
| 260 | |
| 261 | end = list + len; |
| 262 | while (list < end) { |
| 263 | char *s; |
| 264 | |
| 265 | len = strlen(list); |
| 266 | if (len >= strlen("pciVVVV,DDDD")) { |
| 267 | s = strstr(list, "pci"); |
| 268 | |
| 269 | /* |
| 270 | * check if the string is something like pciVVVV,DDDD.RR |
| 271 | * or just pciVVVV,DDDD |
| 272 | */ |
| 273 | if (s && s[7] == ',' && |
| 274 | (s[12] == '.' || s[12] == 0)) { |
| 275 | s += 3; |
| 276 | *vendor = simple_strtol(s, NULL, 16); |
| 277 | |
| 278 | s += 5; |
| 279 | *device = simple_strtol(s, NULL, 16); |
| 280 | |
| 281 | return 0; |
| 282 | } |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 283 | } |
Bin Meng | a2822b8 | 2015-08-20 06:40:25 -0700 | [diff] [blame] | 284 | list += (len + 1); |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return -ENOENT; |
| 288 | } |
| 289 | |
Simon Glass | f1037ad | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 290 | int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, |
| 291 | u32 *bar) |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 292 | { |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 293 | int barnum; |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 294 | |
| 295 | /* extract the bar number from fdt_pci_addr */ |
| 296 | barnum = addr->phys_hi & 0xff; |
| 297 | if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS)) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | barnum = (barnum - PCI_BASE_ADDRESS_0) / 4; |
Simon Glass | f1037ad | 2015-11-29 13:17:54 -0700 | [diff] [blame] | 301 | *bar = dm_pci_read_bar32(dev, barnum); |
Bin Meng | 779847e | 2014-12-31 16:05:11 +0800 | [diff] [blame] | 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | #endif |
| 306 | |
Che-Liang Chiou | d81d017 | 2012-10-25 16:31:05 +0000 | [diff] [blame] | 307 | uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, |
| 308 | uint64_t default_val) |
| 309 | { |
| 310 | const uint64_t *cell64; |
| 311 | int length; |
| 312 | |
| 313 | cell64 = fdt_getprop(blob, node, prop_name, &length); |
| 314 | if (!cell64 || length < sizeof(*cell64)) |
| 315 | return default_val; |
| 316 | |
| 317 | return fdt64_to_cpu(*cell64); |
| 318 | } |
| 319 | |
Simon Glass | 6544498 | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 320 | int fdtdec_get_is_enabled(const void *blob, int node) |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 321 | { |
| 322 | const char *cell; |
| 323 | |
Simon Glass | 6544498 | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 324 | /* |
| 325 | * It should say "okay", so only allow that. Some fdts use "ok" but |
| 326 | * this is a bug. Please fix your device tree source file. See here |
| 327 | * for discussion: |
| 328 | * |
| 329 | * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html |
| 330 | */ |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 331 | cell = fdt_getprop(blob, node, "status", NULL); |
| 332 | if (cell) |
Simon Glass | 6544498 | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 333 | return 0 == strcmp(cell, "okay"); |
| 334 | return 1; |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Gerald Van Baren | cdac339 | 2012-11-12 23:13:54 -0500 | [diff] [blame] | 337 | enum fdt_compat_id fdtdec_lookup(const void *blob, int node) |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 338 | { |
| 339 | enum fdt_compat_id id; |
| 340 | |
| 341 | /* Search our drivers */ |
| 342 | for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++) |
| 343 | if (0 == fdt_node_check_compatible(blob, node, |
| 344 | compat_names[id])) |
| 345 | return id; |
| 346 | return COMPAT_UNKNOWN; |
| 347 | } |
| 348 | |
| 349 | int fdtdec_next_compatible(const void *blob, int node, |
| 350 | enum fdt_compat_id id) |
| 351 | { |
| 352 | return fdt_node_offset_by_compatible(blob, node, compat_names[id]); |
| 353 | } |
| 354 | |
Simon Glass | 2e979b1 | 2012-04-02 13:18:42 +0000 | [diff] [blame] | 355 | int fdtdec_next_compatible_subnode(const void *blob, int node, |
| 356 | enum fdt_compat_id id, int *depthp) |
| 357 | { |
| 358 | do { |
| 359 | node = fdt_next_node(blob, node, depthp); |
| 360 | } while (*depthp > 1); |
| 361 | |
| 362 | /* If this is a direct subnode, and compatible, return it */ |
| 363 | if (*depthp == 1 && 0 == fdt_node_check_compatible( |
| 364 | blob, node, compat_names[id])) |
| 365 | return node; |
| 366 | |
| 367 | return -FDT_ERR_NOTFOUND; |
| 368 | } |
| 369 | |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 370 | int fdtdec_next_alias(const void *blob, const char *name, |
| 371 | enum fdt_compat_id id, int *upto) |
| 372 | { |
| 373 | #define MAX_STR_LEN 20 |
| 374 | char str[MAX_STR_LEN + 20]; |
| 375 | int node, err; |
| 376 | |
| 377 | /* snprintf() is not available */ |
| 378 | assert(strlen(name) < MAX_STR_LEN); |
| 379 | sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto); |
Simon Glass | e1d15ca | 2012-10-31 14:02:42 +0000 | [diff] [blame] | 380 | node = fdt_path_offset(blob, str); |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 381 | if (node < 0) |
| 382 | return node; |
| 383 | err = fdt_node_check_compatible(blob, node, compat_names[id]); |
| 384 | if (err < 0) |
| 385 | return err; |
Simon Glass | 6544498 | 2012-02-27 10:52:34 +0000 | [diff] [blame] | 386 | if (err) |
| 387 | return -FDT_ERR_NOTFOUND; |
| 388 | (*upto)++; |
| 389 | return node; |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 392 | int fdtdec_find_aliases_for_id(const void *blob, const char *name, |
| 393 | enum fdt_compat_id id, int *node_list, int maxcount) |
| 394 | { |
Simon Glass | 1f77266 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 395 | memset(node_list, '\0', sizeof(*node_list) * maxcount); |
| 396 | |
| 397 | return fdtdec_add_aliases_for_id(blob, name, id, node_list, maxcount); |
| 398 | } |
| 399 | |
| 400 | /* TODO: Can we tighten this code up a little? */ |
| 401 | int fdtdec_add_aliases_for_id(const void *blob, const char *name, |
| 402 | enum fdt_compat_id id, int *node_list, int maxcount) |
| 403 | { |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 404 | int name_len = strlen(name); |
| 405 | int nodes[maxcount]; |
| 406 | int num_found = 0; |
| 407 | int offset, node; |
| 408 | int alias_node; |
| 409 | int count; |
| 410 | int i, j; |
| 411 | |
| 412 | /* find the alias node if present */ |
| 413 | alias_node = fdt_path_offset(blob, "/aliases"); |
| 414 | |
| 415 | /* |
| 416 | * start with nothing, and we can assume that the root node can't |
| 417 | * match |
| 418 | */ |
| 419 | memset(nodes, '\0', sizeof(nodes)); |
| 420 | |
| 421 | /* First find all the compatible nodes */ |
| 422 | for (node = count = 0; node >= 0 && count < maxcount;) { |
| 423 | node = fdtdec_next_compatible(blob, node, id); |
| 424 | if (node >= 0) |
| 425 | nodes[count++] = node; |
| 426 | } |
| 427 | if (node >= 0) |
| 428 | debug("%s: warning: maxcount exceeded with alias '%s'\n", |
| 429 | __func__, name); |
| 430 | |
| 431 | /* Now find all the aliases */ |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 432 | for (offset = fdt_first_property_offset(blob, alias_node); |
| 433 | offset > 0; |
| 434 | offset = fdt_next_property_offset(blob, offset)) { |
| 435 | const struct fdt_property *prop; |
| 436 | const char *path; |
| 437 | int number; |
| 438 | int found; |
| 439 | |
| 440 | node = 0; |
| 441 | prop = fdt_get_property_by_offset(blob, offset, NULL); |
| 442 | path = fdt_string(blob, fdt32_to_cpu(prop->nameoff)); |
| 443 | if (prop->len && 0 == strncmp(path, name, name_len)) |
| 444 | node = fdt_path_offset(blob, prop->data); |
| 445 | if (node <= 0) |
| 446 | continue; |
| 447 | |
| 448 | /* Get the alias number */ |
| 449 | number = simple_strtoul(path + name_len, NULL, 10); |
| 450 | if (number < 0 || number >= maxcount) { |
| 451 | debug("%s: warning: alias '%s' is out of range\n", |
| 452 | __func__, path); |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | /* Make sure the node we found is actually in our list! */ |
| 457 | found = -1; |
| 458 | for (j = 0; j < count; j++) |
| 459 | if (nodes[j] == node) { |
| 460 | found = j; |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | if (found == -1) { |
| 465 | debug("%s: warning: alias '%s' points to a node " |
| 466 | "'%s' that is missing or is not compatible " |
| 467 | " with '%s'\n", __func__, path, |
| 468 | fdt_get_name(blob, node, NULL), |
| 469 | compat_names[id]); |
| 470 | continue; |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * Add this node to our list in the right place, and mark |
| 475 | * it as done. |
| 476 | */ |
| 477 | if (fdtdec_get_is_enabled(blob, node)) { |
Simon Glass | 1f77266 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 478 | if (node_list[number]) { |
| 479 | debug("%s: warning: alias '%s' requires that " |
| 480 | "a node be placed in the list in a " |
| 481 | "position which is already filled by " |
| 482 | "node '%s'\n", __func__, path, |
| 483 | fdt_get_name(blob, node, NULL)); |
| 484 | continue; |
| 485 | } |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 486 | node_list[number] = node; |
| 487 | if (number >= num_found) |
| 488 | num_found = number + 1; |
| 489 | } |
Simon Glass | 1f77266 | 2012-02-03 15:13:53 +0000 | [diff] [blame] | 490 | nodes[found] = 0; |
Simon Glass | b022ead | 2012-01-17 08:20:50 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* Add any nodes not mentioned by an alias */ |
| 494 | for (i = j = 0; i < maxcount; i++) { |
| 495 | if (!node_list[i]) { |
| 496 | for (; j < maxcount; j++) |
| 497 | if (nodes[j] && |
| 498 | fdtdec_get_is_enabled(blob, nodes[j])) |
| 499 | break; |
| 500 | |
| 501 | /* Have we run out of nodes to add? */ |
| 502 | if (j == maxcount) |
| 503 | break; |
| 504 | |
| 505 | assert(!node_list[i]); |
| 506 | node_list[i] = nodes[j++]; |
| 507 | if (i >= num_found) |
| 508 | num_found = i + 1; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | return num_found; |
| 513 | } |
| 514 | |
Simon Glass | 9908ad4 | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 515 | int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, |
| 516 | int *seqp) |
| 517 | { |
| 518 | int base_len = strlen(base); |
| 519 | const char *find_name; |
| 520 | int find_namelen; |
| 521 | int prop_offset; |
| 522 | int aliases; |
| 523 | |
| 524 | find_name = fdt_get_name(blob, offset, &find_namelen); |
| 525 | debug("Looking for '%s' at %d, name %s\n", base, offset, find_name); |
| 526 | |
| 527 | aliases = fdt_path_offset(blob, "/aliases"); |
| 528 | for (prop_offset = fdt_first_property_offset(blob, aliases); |
| 529 | prop_offset > 0; |
| 530 | prop_offset = fdt_next_property_offset(blob, prop_offset)) { |
| 531 | const char *prop; |
| 532 | const char *name; |
| 533 | const char *slash; |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 534 | int len, val; |
Simon Glass | 9908ad4 | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 535 | |
| 536 | prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len); |
| 537 | debug(" - %s, %s\n", name, prop); |
| 538 | if (len < find_namelen || *prop != '/' || prop[len - 1] || |
| 539 | strncmp(name, base, base_len)) |
| 540 | continue; |
| 541 | |
| 542 | slash = strrchr(prop, '/'); |
| 543 | if (strcmp(slash + 1, find_name)) |
| 544 | continue; |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 545 | val = trailing_strtol(name); |
| 546 | if (val != -1) { |
| 547 | *seqp = val; |
| 548 | debug("Found seq %d\n", *seqp); |
| 549 | return 0; |
Simon Glass | 9908ad4 | 2014-07-23 06:55:09 -0600 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | debug("Not found\n"); |
| 554 | return -ENOENT; |
| 555 | } |
| 556 | |
Simon Glass | 088dccb | 2015-10-17 19:41:14 -0600 | [diff] [blame] | 557 | const char *fdtdec_get_chosen_prop(const void *blob, const char *name) |
Simon Glass | 1e374fb | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 558 | { |
Simon Glass | 1e374fb | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 559 | int chosen_node; |
Simon Glass | 1e374fb | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 560 | |
| 561 | if (!blob) |
Simon Glass | 088dccb | 2015-10-17 19:41:14 -0600 | [diff] [blame] | 562 | return NULL; |
Simon Glass | 1e374fb | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 563 | chosen_node = fdt_path_offset(blob, "/chosen"); |
Simon Glass | 088dccb | 2015-10-17 19:41:14 -0600 | [diff] [blame] | 564 | return fdt_getprop(blob, chosen_node, name, NULL); |
| 565 | } |
| 566 | |
| 567 | int fdtdec_get_chosen_node(const void *blob, const char *name) |
| 568 | { |
| 569 | const char *prop; |
| 570 | |
| 571 | prop = fdtdec_get_chosen_prop(blob, name); |
Simon Glass | 1e374fb | 2014-09-04 16:27:24 -0600 | [diff] [blame] | 572 | if (!prop) |
| 573 | return -FDT_ERR_NOTFOUND; |
| 574 | return fdt_path_offset(blob, prop); |
| 575 | } |
| 576 | |
Simon Glass | 1691f69 | 2012-03-28 10:08:24 +0000 | [diff] [blame] | 577 | int fdtdec_check_fdt(void) |
| 578 | { |
| 579 | /* |
| 580 | * We must have an FDT, but we cannot panic() yet since the console |
| 581 | * is not ready. So for now, just assert(). Boards which need an early |
| 582 | * FDT (prior to console ready) will need to make their own |
| 583 | * arrangements and do their own checks. |
| 584 | */ |
| 585 | assert(!fdtdec_prepare_fdt()); |
| 586 | return 0; |
| 587 | } |
| 588 | |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 589 | /* |
| 590 | * This function is a little odd in that it accesses global data. At some |
| 591 | * point if the architecture board.c files merge this will make more sense. |
| 592 | * Even now, it is common code. |
| 593 | */ |
Simon Glass | 1691f69 | 2012-03-28 10:08:24 +0000 | [diff] [blame] | 594 | int fdtdec_prepare_fdt(void) |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 595 | { |
Simon Glass | 7113685 | 2013-04-20 08:42:46 +0000 | [diff] [blame] | 596 | if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) || |
| 597 | fdt_check_header(gd->fdt_blob)) { |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 598 | #ifdef CONFIG_SPL_BUILD |
| 599 | puts("Missing DTB\n"); |
| 600 | #else |
| 601 | puts("No valid device tree binary found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n"); |
Simon Glass | 63884ec | 2015-06-23 15:39:09 -0600 | [diff] [blame] | 602 | # ifdef DEBUG |
| 603 | if (gd->fdt_blob) { |
| 604 | printf("fdt_blob=%p\n", gd->fdt_blob); |
| 605 | print_buffer((ulong)gd->fdt_blob, gd->fdt_blob, 4, |
| 606 | 32, 0); |
| 607 | } |
| 608 | # endif |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 609 | #endif |
Simon Glass | 1691f69 | 2012-03-28 10:08:24 +0000 | [diff] [blame] | 610 | return -1; |
| 611 | } |
Simon Glass | 2d2af85 | 2011-10-24 19:15:32 +0000 | [diff] [blame] | 612 | return 0; |
| 613 | } |
Simon Glass | c469736 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 614 | |
| 615 | int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) |
| 616 | { |
| 617 | const u32 *phandle; |
| 618 | int lookup; |
| 619 | |
Simon Glass | c8c86dd | 2012-07-12 05:25:01 +0000 | [diff] [blame] | 620 | debug("%s: %s\n", __func__, prop_name); |
Simon Glass | c469736 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 621 | phandle = fdt_getprop(blob, node, prop_name, NULL); |
| 622 | if (!phandle) |
| 623 | return -FDT_ERR_NOTFOUND; |
| 624 | |
| 625 | lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle)); |
| 626 | return lookup; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Look up a property in a node and check that it has a minimum length. |
| 631 | * |
| 632 | * @param blob FDT blob |
| 633 | * @param node node to examine |
| 634 | * @param prop_name name of property to find |
| 635 | * @param min_len minimum property length in bytes |
| 636 | * @param err 0 if ok, or -FDT_ERR_NOTFOUND if the property is not |
| 637 | found, or -FDT_ERR_BADLAYOUT if not enough data |
| 638 | * @return pointer to cell, which is only valid if err == 0 |
| 639 | */ |
| 640 | static const void *get_prop_check_min_len(const void *blob, int node, |
| 641 | const char *prop_name, int min_len, int *err) |
| 642 | { |
| 643 | const void *cell; |
| 644 | int len; |
| 645 | |
| 646 | debug("%s: %s\n", __func__, prop_name); |
| 647 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 648 | if (!cell) |
| 649 | *err = -FDT_ERR_NOTFOUND; |
| 650 | else if (len < min_len) |
| 651 | *err = -FDT_ERR_BADLAYOUT; |
| 652 | else |
| 653 | *err = 0; |
| 654 | return cell; |
| 655 | } |
| 656 | |
| 657 | int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, |
| 658 | u32 *array, int count) |
| 659 | { |
| 660 | const u32 *cell; |
| 661 | int i, err = 0; |
| 662 | |
| 663 | debug("%s: %s\n", __func__, prop_name); |
| 664 | cell = get_prop_check_min_len(blob, node, prop_name, |
| 665 | sizeof(u32) * count, &err); |
| 666 | if (!err) { |
| 667 | for (i = 0; i < count; i++) |
| 668 | array[i] = fdt32_to_cpu(cell[i]); |
| 669 | } |
| 670 | return err; |
| 671 | } |
| 672 | |
Simon Glass | eda0c3f | 2014-11-10 18:00:19 -0700 | [diff] [blame] | 673 | int fdtdec_get_int_array_count(const void *blob, int node, |
| 674 | const char *prop_name, u32 *array, int count) |
| 675 | { |
| 676 | const u32 *cell; |
| 677 | int len, elems; |
| 678 | int i; |
| 679 | |
| 680 | debug("%s: %s\n", __func__, prop_name); |
| 681 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 682 | if (!cell) |
| 683 | return -FDT_ERR_NOTFOUND; |
| 684 | elems = len / sizeof(u32); |
| 685 | if (count > elems) |
| 686 | count = elems; |
| 687 | for (i = 0; i < count; i++) |
| 688 | array[i] = fdt32_to_cpu(cell[i]); |
| 689 | |
| 690 | return count; |
| 691 | } |
| 692 | |
Simon Glass | 744ec23 | 2012-04-02 13:18:41 +0000 | [diff] [blame] | 693 | const u32 *fdtdec_locate_array(const void *blob, int node, |
| 694 | const char *prop_name, int count) |
| 695 | { |
| 696 | const u32 *cell; |
| 697 | int err; |
| 698 | |
| 699 | cell = get_prop_check_min_len(blob, node, prop_name, |
| 700 | sizeof(u32) * count, &err); |
| 701 | return err ? NULL : cell; |
| 702 | } |
| 703 | |
Simon Glass | c469736 | 2012-02-27 10:52:35 +0000 | [diff] [blame] | 704 | int fdtdec_get_bool(const void *blob, int node, const char *prop_name) |
| 705 | { |
| 706 | const s32 *cell; |
| 707 | int len; |
| 708 | |
| 709 | debug("%s: %s\n", __func__, prop_name); |
| 710 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 711 | return cell != NULL; |
| 712 | } |
Simon Glass | 0d83c4d | 2012-02-27 10:52:36 +0000 | [diff] [blame] | 713 | |
Simon Glass | b491e9c | 2015-01-05 20:05:26 -0700 | [diff] [blame] | 714 | int fdtdec_parse_phandle_with_args(const void *blob, int src_node, |
| 715 | const char *list_name, |
| 716 | const char *cells_name, |
| 717 | int cell_count, int index, |
| 718 | struct fdtdec_phandle_args *out_args) |
| 719 | { |
| 720 | const __be32 *list, *list_end; |
| 721 | int rc = 0, size, cur_index = 0; |
| 722 | uint32_t count = 0; |
| 723 | int node = -1; |
| 724 | int phandle; |
| 725 | |
| 726 | /* Retrieve the phandle list property */ |
| 727 | list = fdt_getprop(blob, src_node, list_name, &size); |
| 728 | if (!list) |
| 729 | return -ENOENT; |
| 730 | list_end = list + size / sizeof(*list); |
| 731 | |
| 732 | /* Loop over the phandles until all the requested entry is found */ |
| 733 | while (list < list_end) { |
| 734 | rc = -EINVAL; |
| 735 | count = 0; |
| 736 | |
| 737 | /* |
| 738 | * If phandle is 0, then it is an empty entry with no |
| 739 | * arguments. Skip forward to the next entry. |
| 740 | */ |
| 741 | phandle = be32_to_cpup(list++); |
| 742 | if (phandle) { |
| 743 | /* |
| 744 | * Find the provider node and parse the #*-cells |
| 745 | * property to determine the argument length. |
| 746 | * |
| 747 | * This is not needed if the cell count is hard-coded |
| 748 | * (i.e. cells_name not set, but cell_count is set), |
| 749 | * except when we're going to return the found node |
| 750 | * below. |
| 751 | */ |
| 752 | if (cells_name || cur_index == index) { |
| 753 | node = fdt_node_offset_by_phandle(blob, |
| 754 | phandle); |
| 755 | if (!node) { |
| 756 | debug("%s: could not find phandle\n", |
| 757 | fdt_get_name(blob, src_node, |
| 758 | NULL)); |
| 759 | goto err; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | if (cells_name) { |
| 764 | count = fdtdec_get_int(blob, node, cells_name, |
| 765 | -1); |
| 766 | if (count == -1) { |
| 767 | debug("%s: could not get %s for %s\n", |
| 768 | fdt_get_name(blob, src_node, |
| 769 | NULL), |
| 770 | cells_name, |
| 771 | fdt_get_name(blob, node, |
| 772 | NULL)); |
| 773 | goto err; |
| 774 | } |
| 775 | } else { |
| 776 | count = cell_count; |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * Make sure that the arguments actually fit in the |
| 781 | * remaining property data length |
| 782 | */ |
| 783 | if (list + count > list_end) { |
| 784 | debug("%s: arguments longer than property\n", |
| 785 | fdt_get_name(blob, src_node, NULL)); |
| 786 | goto err; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | /* |
| 791 | * All of the error cases above bail out of the loop, so at |
| 792 | * this point, the parsing is successful. If the requested |
| 793 | * index matches, then fill the out_args structure and return, |
| 794 | * or return -ENOENT for an empty entry. |
| 795 | */ |
| 796 | rc = -ENOENT; |
| 797 | if (cur_index == index) { |
| 798 | if (!phandle) |
| 799 | goto err; |
| 800 | |
| 801 | if (out_args) { |
| 802 | int i; |
| 803 | |
| 804 | if (count > MAX_PHANDLE_ARGS) { |
| 805 | debug("%s: too many arguments %d\n", |
| 806 | fdt_get_name(blob, src_node, |
| 807 | NULL), count); |
| 808 | count = MAX_PHANDLE_ARGS; |
| 809 | } |
| 810 | out_args->node = node; |
| 811 | out_args->args_count = count; |
| 812 | for (i = 0; i < count; i++) { |
| 813 | out_args->args[i] = |
| 814 | be32_to_cpup(list++); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | /* Found it! return success */ |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | node = -1; |
| 823 | list += count; |
| 824 | cur_index++; |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | * Result will be one of: |
| 829 | * -ENOENT : index is for empty phandle |
| 830 | * -EINVAL : parsing error on data |
| 831 | * [1..n] : Number of phandle (count mode; when index = -1) |
| 832 | */ |
| 833 | rc = index < 0 ? cur_index : -ENOENT; |
| 834 | err: |
| 835 | return rc; |
| 836 | } |
| 837 | |
Peng Fan | 23dd3a0 | 2016-02-01 13:31:15 +0800 | [diff] [blame] | 838 | int fdtdec_get_child_count(const void *blob, int node) |
| 839 | { |
| 840 | int subnode; |
| 841 | int num = 0; |
| 842 | |
Simon Glass | 499c29e | 2016-10-02 17:59:29 -0600 | [diff] [blame] | 843 | fdt_for_each_subnode(subnode, blob, node) |
Peng Fan | 23dd3a0 | 2016-02-01 13:31:15 +0800 | [diff] [blame] | 844 | num++; |
| 845 | |
| 846 | return num; |
| 847 | } |
| 848 | |
Anton Staff | f2305ec | 2012-04-17 09:01:28 +0000 | [diff] [blame] | 849 | int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, |
| 850 | u8 *array, int count) |
| 851 | { |
| 852 | const u8 *cell; |
| 853 | int err; |
| 854 | |
| 855 | cell = get_prop_check_min_len(blob, node, prop_name, count, &err); |
| 856 | if (!err) |
| 857 | memcpy(array, cell, count); |
| 858 | return err; |
| 859 | } |
| 860 | |
| 861 | const u8 *fdtdec_locate_byte_array(const void *blob, int node, |
| 862 | const char *prop_name, int count) |
| 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 | return NULL; |
| 870 | return cell; |
| 871 | } |
Abhilash Kesavan | 67217af | 2012-10-25 16:30:58 +0000 | [diff] [blame] | 872 | |
Abhilash Kesavan | 67217af | 2012-10-25 16:30:58 +0000 | [diff] [blame] | 873 | int fdtdec_get_config_int(const void *blob, const char *prop_name, |
| 874 | int default_val) |
| 875 | { |
| 876 | int config_node; |
| 877 | |
| 878 | debug("%s: %s\n", __func__, prop_name); |
| 879 | config_node = fdt_path_offset(blob, "/config"); |
| 880 | if (config_node < 0) |
| 881 | return default_val; |
| 882 | return fdtdec_get_int(blob, config_node, prop_name, default_val); |
| 883 | } |
Simon Glass | b049447 | 2012-10-25 16:30:59 +0000 | [diff] [blame] | 884 | |
Gabe Black | 3e1c151 | 2012-10-25 16:31:04 +0000 | [diff] [blame] | 885 | int fdtdec_get_config_bool(const void *blob, const char *prop_name) |
| 886 | { |
| 887 | int config_node; |
| 888 | const void *prop; |
| 889 | |
| 890 | debug("%s: %s\n", __func__, prop_name); |
| 891 | config_node = fdt_path_offset(blob, "/config"); |
| 892 | if (config_node < 0) |
| 893 | return 0; |
| 894 | prop = fdt_get_property(blob, config_node, prop_name, NULL); |
| 895 | |
| 896 | return prop != NULL; |
| 897 | } |
| 898 | |
Simon Glass | b049447 | 2012-10-25 16:30:59 +0000 | [diff] [blame] | 899 | char *fdtdec_get_config_string(const void *blob, const char *prop_name) |
| 900 | { |
| 901 | const char *nodep; |
| 902 | int nodeoffset; |
| 903 | int len; |
| 904 | |
| 905 | debug("%s: %s\n", __func__, prop_name); |
| 906 | nodeoffset = fdt_path_offset(blob, "/config"); |
| 907 | if (nodeoffset < 0) |
| 908 | return NULL; |
| 909 | |
| 910 | nodep = fdt_getprop(blob, nodeoffset, prop_name, &len); |
| 911 | if (!nodep) |
| 912 | return NULL; |
| 913 | |
| 914 | return (char *)nodep; |
| 915 | } |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 916 | |
Simon Glass | a28f8ba | 2014-10-23 18:58:51 -0600 | [diff] [blame] | 917 | int fdtdec_decode_region(const void *blob, int node, const char *prop_name, |
| 918 | fdt_addr_t *basep, fdt_size_t *sizep) |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 919 | { |
| 920 | const fdt_addr_t *cell; |
| 921 | int len; |
| 922 | |
Simon Glass | a28f8ba | 2014-10-23 18:58:51 -0600 | [diff] [blame] | 923 | debug("%s: %s: %s\n", __func__, fdt_get_name(blob, node, NULL), |
| 924 | prop_name); |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 925 | cell = fdt_getprop(blob, node, prop_name, &len); |
Simon Glass | a28f8ba | 2014-10-23 18:58:51 -0600 | [diff] [blame] | 926 | if (!cell || (len < sizeof(fdt_addr_t) * 2)) { |
| 927 | debug("cell=%p, len=%d\n", cell, len); |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 928 | return -1; |
Simon Glass | a28f8ba | 2014-10-23 18:58:51 -0600 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | *basep = fdt_addr_to_cpu(*cell); |
| 932 | *sizep = fdt_size_to_cpu(cell[1]); |
| 933 | debug("%s: base=%08lx, size=%lx\n", __func__, (ulong)*basep, |
| 934 | (ulong)*sizep); |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 935 | |
Simon Glass | f909b9c | 2012-10-25 16:31:00 +0000 | [diff] [blame] | 936 | return 0; |
| 937 | } |
Simon Glass | 9f78372 | 2014-02-27 13:26:01 -0700 | [diff] [blame] | 938 | |
Simon Glass | 9ffbe33 | 2015-03-05 12:25:14 -0700 | [diff] [blame] | 939 | u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells) |
Thierry Reding | a937b80 | 2014-08-26 17:33:53 +0200 | [diff] [blame] | 940 | { |
| 941 | u64 number = 0; |
| 942 | |
| 943 | while (cells--) |
| 944 | number = (number << 32) | fdt32_to_cpu(*ptr++); |
| 945 | |
| 946 | return number; |
| 947 | } |
| 948 | |
| 949 | int fdt_get_resource(const void *fdt, int node, const char *property, |
| 950 | unsigned int index, struct fdt_resource *res) |
| 951 | { |
| 952 | const fdt32_t *ptr, *end; |
| 953 | int na, ns, len, parent; |
| 954 | unsigned int i = 0; |
| 955 | |
| 956 | parent = fdt_parent_offset(fdt, node); |
| 957 | if (parent < 0) |
| 958 | return parent; |
| 959 | |
| 960 | na = fdt_address_cells(fdt, parent); |
| 961 | ns = fdt_size_cells(fdt, parent); |
| 962 | |
| 963 | ptr = fdt_getprop(fdt, node, property, &len); |
| 964 | if (!ptr) |
| 965 | return len; |
| 966 | |
| 967 | end = ptr + len / sizeof(*ptr); |
| 968 | |
| 969 | while (ptr + na + ns <= end) { |
| 970 | if (i == index) { |
| 971 | res->start = res->end = fdtdec_get_number(ptr, na); |
| 972 | res->end += fdtdec_get_number(&ptr[na], ns) - 1; |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | ptr += na + ns; |
| 977 | i++; |
| 978 | } |
| 979 | |
| 980 | return -FDT_ERR_NOTFOUND; |
| 981 | } |
| 982 | |
| 983 | int fdt_get_named_resource(const void *fdt, int node, const char *property, |
| 984 | const char *prop_names, const char *name, |
| 985 | struct fdt_resource *res) |
| 986 | { |
| 987 | int index; |
| 988 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 989 | index = fdt_stringlist_search(fdt, node, prop_names, name); |
Thierry Reding | a937b80 | 2014-08-26 17:33:53 +0200 | [diff] [blame] | 990 | if (index < 0) |
| 991 | return index; |
| 992 | |
| 993 | return fdt_get_resource(fdt, node, property, index, res); |
| 994 | } |
Thierry Reding | 2485631 | 2014-08-26 17:33:54 +0200 | [diff] [blame] | 995 | |
Simon Glass | 6894186 | 2014-10-23 18:58:56 -0600 | [diff] [blame] | 996 | int fdtdec_decode_memory_region(const void *blob, int config_node, |
| 997 | const char *mem_type, const char *suffix, |
| 998 | fdt_addr_t *basep, fdt_size_t *sizep) |
| 999 | { |
| 1000 | char prop_name[50]; |
| 1001 | const char *mem; |
| 1002 | fdt_size_t size, offset_size; |
| 1003 | fdt_addr_t base, offset; |
| 1004 | int node; |
| 1005 | |
| 1006 | if (config_node == -1) { |
| 1007 | config_node = fdt_path_offset(blob, "/config"); |
| 1008 | if (config_node < 0) { |
| 1009 | debug("%s: Cannot find /config node\n", __func__); |
| 1010 | return -ENOENT; |
| 1011 | } |
| 1012 | } |
| 1013 | if (!suffix) |
| 1014 | suffix = ""; |
| 1015 | |
| 1016 | snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type, |
| 1017 | suffix); |
| 1018 | mem = fdt_getprop(blob, config_node, prop_name, NULL); |
| 1019 | if (!mem) { |
| 1020 | debug("%s: No memory type for '%s', using /memory\n", __func__, |
| 1021 | prop_name); |
| 1022 | mem = "/memory"; |
| 1023 | } |
| 1024 | |
| 1025 | node = fdt_path_offset(blob, mem); |
| 1026 | if (node < 0) { |
| 1027 | debug("%s: Failed to find node '%s': %s\n", __func__, mem, |
| 1028 | fdt_strerror(node)); |
| 1029 | return -ENOENT; |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * Not strictly correct - the memory may have multiple banks. We just |
| 1034 | * use the first |
| 1035 | */ |
| 1036 | if (fdtdec_decode_region(blob, node, "reg", &base, &size)) { |
| 1037 | debug("%s: Failed to decode memory region %s\n", __func__, |
| 1038 | mem); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | |
| 1042 | snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type, |
| 1043 | suffix); |
| 1044 | if (fdtdec_decode_region(blob, config_node, prop_name, &offset, |
| 1045 | &offset_size)) { |
| 1046 | debug("%s: Failed to decode memory region '%s'\n", __func__, |
| 1047 | prop_name); |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
| 1051 | *basep = base + offset; |
| 1052 | *sizep = offset_size; |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1056 | |
Simon Glass | b24e864 | 2015-04-14 21:03:21 -0600 | [diff] [blame] | 1057 | static int decode_timing_property(const void *blob, int node, const char *name, |
| 1058 | struct timing_entry *result) |
| 1059 | { |
| 1060 | int length, ret = 0; |
| 1061 | const u32 *prop; |
| 1062 | |
| 1063 | prop = fdt_getprop(blob, node, name, &length); |
| 1064 | if (!prop) { |
| 1065 | debug("%s: could not find property %s\n", |
| 1066 | fdt_get_name(blob, node, NULL), name); |
| 1067 | return length; |
| 1068 | } |
| 1069 | |
| 1070 | if (length == sizeof(u32)) { |
| 1071 | result->typ = fdtdec_get_int(blob, node, name, 0); |
| 1072 | result->min = result->typ; |
| 1073 | result->max = result->typ; |
| 1074 | } else { |
| 1075 | ret = fdtdec_get_int_array(blob, node, name, &result->min, 3); |
| 1076 | } |
| 1077 | |
| 1078 | return ret; |
| 1079 | } |
| 1080 | |
| 1081 | int fdtdec_decode_display_timing(const void *blob, int parent, int index, |
| 1082 | struct display_timing *dt) |
| 1083 | { |
| 1084 | int i, node, timings_node; |
| 1085 | u32 val = 0; |
| 1086 | int ret = 0; |
| 1087 | |
| 1088 | timings_node = fdt_subnode_offset(blob, parent, "display-timings"); |
| 1089 | if (timings_node < 0) |
| 1090 | return timings_node; |
| 1091 | |
| 1092 | for (i = 0, node = fdt_first_subnode(blob, timings_node); |
| 1093 | node > 0 && i != index; |
| 1094 | node = fdt_next_subnode(blob, node)) |
| 1095 | i++; |
| 1096 | |
| 1097 | if (node < 0) |
| 1098 | return node; |
| 1099 | |
| 1100 | memset(dt, 0, sizeof(*dt)); |
| 1101 | |
| 1102 | ret |= decode_timing_property(blob, node, "hback-porch", |
| 1103 | &dt->hback_porch); |
| 1104 | ret |= decode_timing_property(blob, node, "hfront-porch", |
| 1105 | &dt->hfront_porch); |
| 1106 | ret |= decode_timing_property(blob, node, "hactive", &dt->hactive); |
| 1107 | ret |= decode_timing_property(blob, node, "hsync-len", &dt->hsync_len); |
| 1108 | ret |= decode_timing_property(blob, node, "vback-porch", |
| 1109 | &dt->vback_porch); |
| 1110 | ret |= decode_timing_property(blob, node, "vfront-porch", |
| 1111 | &dt->vfront_porch); |
| 1112 | ret |= decode_timing_property(blob, node, "vactive", &dt->vactive); |
| 1113 | ret |= decode_timing_property(blob, node, "vsync-len", &dt->vsync_len); |
| 1114 | ret |= decode_timing_property(blob, node, "clock-frequency", |
| 1115 | &dt->pixelclock); |
| 1116 | |
| 1117 | dt->flags = 0; |
| 1118 | val = fdtdec_get_int(blob, node, "vsync-active", -1); |
| 1119 | if (val != -1) { |
| 1120 | dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH : |
| 1121 | DISPLAY_FLAGS_VSYNC_LOW; |
| 1122 | } |
| 1123 | val = fdtdec_get_int(blob, node, "hsync-active", -1); |
| 1124 | if (val != -1) { |
| 1125 | dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH : |
| 1126 | DISPLAY_FLAGS_HSYNC_LOW; |
| 1127 | } |
| 1128 | val = fdtdec_get_int(blob, node, "de-active", -1); |
| 1129 | if (val != -1) { |
| 1130 | dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH : |
| 1131 | DISPLAY_FLAGS_DE_LOW; |
| 1132 | } |
| 1133 | val = fdtdec_get_int(blob, node, "pixelclk-active", -1); |
| 1134 | if (val != -1) { |
| 1135 | dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE : |
| 1136 | DISPLAY_FLAGS_PIXDATA_NEGEDGE; |
| 1137 | } |
| 1138 | |
| 1139 | if (fdtdec_get_bool(blob, node, "interlaced")) |
| 1140 | dt->flags |= DISPLAY_FLAGS_INTERLACED; |
| 1141 | if (fdtdec_get_bool(blob, node, "doublescan")) |
| 1142 | dt->flags |= DISPLAY_FLAGS_DOUBLESCAN; |
| 1143 | if (fdtdec_get_bool(blob, node, "doubleclk")) |
| 1144 | dt->flags |= DISPLAY_FLAGS_DOUBLECLK; |
| 1145 | |
Simon Glass | 6eb90e1 | 2016-05-05 07:28:21 -0600 | [diff] [blame] | 1146 | return ret; |
Simon Glass | b24e864 | 2015-04-14 21:03:21 -0600 | [diff] [blame] | 1147 | } |
| 1148 | |
Nathan Rossi | ba97b72 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1149 | int fdtdec_setup_memory_size(void) |
| 1150 | { |
| 1151 | int ret, mem; |
| 1152 | struct fdt_resource res; |
| 1153 | |
| 1154 | mem = fdt_path_offset(gd->fdt_blob, "/memory"); |
| 1155 | if (mem < 0) { |
| 1156 | debug("%s: Missing /memory node\n", __func__); |
| 1157 | return -EINVAL; |
| 1158 | } |
| 1159 | |
| 1160 | ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res); |
| 1161 | if (ret != 0) { |
| 1162 | debug("%s: Unable to decode first memory bank\n", __func__); |
| 1163 | return -EINVAL; |
| 1164 | } |
| 1165 | |
| 1166 | gd->ram_size = (phys_size_t)(res.end - res.start + 1); |
Simon Glass | 640b78f | 2017-05-27 07:38:13 -0600 | [diff] [blame] | 1167 | debug("%s: Initial DRAM size %llx\n", __func__, |
| 1168 | (unsigned long long)gd->ram_size); |
Nathan Rossi | ba97b72 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | #if defined(CONFIG_NR_DRAM_BANKS) |
| 1174 | int fdtdec_setup_memory_banksize(void) |
| 1175 | { |
| 1176 | int bank, ret, mem; |
| 1177 | struct fdt_resource res; |
| 1178 | |
| 1179 | mem = fdt_path_offset(gd->fdt_blob, "/memory"); |
| 1180 | if (mem < 0) { |
| 1181 | debug("%s: Missing /memory node\n", __func__); |
| 1182 | return -EINVAL; |
| 1183 | } |
| 1184 | |
| 1185 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 1186 | ret = fdt_get_resource(gd->fdt_blob, mem, "reg", bank, &res); |
| 1187 | if (ret == -FDT_ERR_NOTFOUND) |
| 1188 | break; |
| 1189 | if (ret != 0) |
| 1190 | return -EINVAL; |
| 1191 | |
| 1192 | gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; |
| 1193 | gd->bd->bi_dram[bank].size = |
| 1194 | (phys_size_t)(res.end - res.start + 1); |
| 1195 | |
| 1196 | debug("%s: DRAM Bank #%d: start = 0x%llx, size = 0x%llx\n", |
| 1197 | __func__, bank, |
| 1198 | (unsigned long long)gd->bd->bi_dram[bank].start, |
| 1199 | (unsigned long long)gd->bd->bi_dram[bank].size); |
| 1200 | } |
| 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | #endif |
| 1205 | |
Simon Glass | a087767 | 2015-02-27 22:06:35 -0700 | [diff] [blame] | 1206 | int fdtdec_setup(void) |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1207 | { |
Masahiro Yamada | 366b24f | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 1208 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1209 | # ifdef CONFIG_OF_EMBED |
| 1210 | /* Get a pointer to the FDT */ |
| 1211 | gd->fdt_blob = __dtb_dt_begin; |
| 1212 | # elif defined CONFIG_OF_SEPARATE |
| 1213 | # ifdef CONFIG_SPL_BUILD |
Simon Glass | 77ec34e | 2015-10-17 19:41:19 -0600 | [diff] [blame] | 1214 | /* FDT is at end of BSS unless it is in a different memory region */ |
| 1215 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
| 1216 | gd->fdt_blob = (ulong *)&_image_binary_end; |
| 1217 | else |
| 1218 | gd->fdt_blob = (ulong *)&__bss_end; |
Cooper Jr., Franklin | 7900ce8 | 2017-06-16 17:25:07 -0500 | [diff] [blame] | 1219 | |
| 1220 | # elif defined CONFIG_FIT_EMBED |
| 1221 | gd->fdt_blob = locate_dtb_in_fit(&_end); |
| 1222 | |
| 1223 | if (gd->fdt_blob == NULL || gd->fdt_blob <= ((void *)&_end)) { |
| 1224 | puts("Failed to find proper dtb in embedded FIT Image\n"); |
| 1225 | return -1; |
| 1226 | } |
| 1227 | |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1228 | # else |
| 1229 | /* FDT is at end of image */ |
| 1230 | gd->fdt_blob = (ulong *)&_end; |
Masahiro Yamada | 6cd571b | 2015-08-01 16:03:25 +0900 | [diff] [blame] | 1231 | # endif |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 1232 | # elif defined(CONFIG_OF_BOARD) |
| 1233 | /* Allow the board to override the fdt address. */ |
| 1234 | gd->fdt_blob = board_fdt_blob_setup(); |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1235 | # elif defined(CONFIG_OF_HOSTFILE) |
| 1236 | if (sandbox_read_fdt_from_file()) { |
| 1237 | puts("Failed to read control FDT\n"); |
| 1238 | return -1; |
| 1239 | } |
| 1240 | # endif |
| 1241 | # ifndef CONFIG_SPL_BUILD |
| 1242 | /* Allow the early environment to override the fdt address */ |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 1243 | gd->fdt_blob = (void *)env_get_ulong("fdtcontroladdr", 16, |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1244 | (uintptr_t)gd->fdt_blob); |
| 1245 | # endif |
Heiko Schocher | d7b4232 | 2014-03-03 12:19:30 +0100 | [diff] [blame] | 1246 | #endif |
Simon Glass | a087767 | 2015-02-27 22:06:35 -0700 | [diff] [blame] | 1247 | return fdtdec_prepare_fdt(); |
Simon Glass | 26b78b2 | 2015-02-27 22:06:34 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | #endif /* !USE_HOSTCC */ |