1b5220bc6SSimon Glass /* 2b5220bc6SSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 31a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 4b5220bc6SSimon Glass */ 5b5220bc6SSimon Glass 629a23f9dSHeiko Schocher #ifndef USE_HOSTCC 7b5220bc6SSimon Glass #include <common.h> 8fcc0a877SSimon Glass #include <dm.h> 95c33c9fdSSimon Glass #include <errno.h> 10b5220bc6SSimon Glass #include <serial.h> 11b5220bc6SSimon Glass #include <libfdt.h> 12b5220bc6SSimon Glass #include <fdtdec.h> 13b45122fdSSimon Glass #include <asm/sections.h> 145c33c9fdSSimon Glass #include <linux/ctype.h> 15b5220bc6SSimon Glass 16b5220bc6SSimon Glass DECLARE_GLOBAL_DATA_PTR; 17b5220bc6SSimon Glass 18b5220bc6SSimon Glass /* 19b5220bc6SSimon Glass * Here are the type we know about. One day we might allow drivers to 20b5220bc6SSimon Glass * register. For now we just put them here. The COMPAT macro allows us to 21b5220bc6SSimon Glass * turn this into a sparse list later, and keeps the ID with the name. 22*01a227dfSSimon Glass * 23*01a227dfSSimon Glass * NOTE: This list is basically a TODO list for things that need to be 24*01a227dfSSimon Glass * converted to driver model. So don't add new things here unless there is a 25*01a227dfSSimon Glass * good reason why driver-model conversion is infeasible. Examples include 26*01a227dfSSimon Glass * things which are used before driver model is available. 27b5220bc6SSimon Glass */ 28b5220bc6SSimon Glass #define COMPAT(id, name) name 29b5220bc6SSimon Glass static const char * const compat_names[COMPAT_COUNT] = { 30f88fe2deSSimon Glass COMPAT(UNKNOWN, "<none>"), 310e35ad05SJimmy Zhang COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"), 320e35ad05SJimmy Zhang COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"), 33312693c3SJim Lin COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"), 3400f37327SSimon Glass COMPAT(NVIDIA_TEGRA124_PMC, "nvidia,tegra124-pmc"), 3539f63332SStephen Warren COMPAT(NVIDIA_TEGRA186_SDMMC, "nvidia,tegra186-sdhci"), 367aaa5a60STom Warren COMPAT(NVIDIA_TEGRA210_SDMMC, "nvidia,tegra210-sdhci"), 37a73ca478SStephen Warren COMPAT(NVIDIA_TEGRA124_SDMMC, "nvidia,tegra124-sdhci"), 38f4e4e0b0STom Warren COMPAT(NVIDIA_TEGRA30_SDMMC, "nvidia,tegra30-sdhci"), 39c9aa831eSTom Warren COMPAT(NVIDIA_TEGRA20_SDMMC, "nvidia,tegra20-sdhci"), 4079c7a90fSThierry Reding COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"), 417aaa5a60STom Warren COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"), 42cc9fe33aSHatim RV COMPAT(SMSC_LAN9215, "smsc,lan9215"), 43cc9fe33aSHatim RV COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"), 44c34253d1SRajeshwari Shinde COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"), 4572dbff12SRajeshwari Shinde COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"), 4672dbff12SRajeshwari Shinde COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"), 47713cb680SHung-ying Tyan COMPAT(GOOGLE_CROS_EC_KEYB, "google,cros-ec-keyb"), 486abd1620SRajeshwari Shinde COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"), 49108b85beSVivek Gautam COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"), 50618766c0SAkshay Saraswat COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"), 51de461c52SPiotr Wilczek COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"), 527d3ca0f8SJaehoon Chung COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"), 533577fe8bSPiotr Wilczek COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"), 54f37df0f8SPrzemyslaw Marczak COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686"), 55bb8215f4SSimon Glass COMPAT(GENERIC_SPI_FLASH, "spi-flash"), 567772bb78SRajeshwari Shinde COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"), 57ecbd7e1eSnaveen krishna chatradhi COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"), 5845c480c9SAjay Kumar COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"), 5977f9b1fbSSimon Glass COMPAT(INTEL_MICROCODE, "intel,microcode"), 606173c45bSThierry Reding COMPAT(AMS_AS3722, "ams,as3722"), 61c89ada01SBin Meng COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"), 626462cdedSMasahiro Yamada COMPAT(SOCIONEXT_XHCI, "socionext,uniphier-xhci"), 636ab00db2SMarek Vasut COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"), 64129adf5bSMarek Vasut COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"), 65ef4b01b2SMarek Vasut COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"), 66f3b84a30SAndrew Bradford COMPAT(COMPAT_INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"), 67f3b84a30SAndrew Bradford COMPAT(COMPAT_INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"), 68394e0b66SBin Meng COMPAT(COMPAT_INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"), 69b5220bc6SSimon Glass }; 70b5220bc6SSimon Glass 71a53f4a29SSimon Glass const char *fdtdec_get_compatible(enum fdt_compat_id id) 72a53f4a29SSimon Glass { 73a53f4a29SSimon Glass /* We allow reading of the 'unknown' ID for testing purposes */ 74a53f4a29SSimon Glass assert(id >= 0 && id < COMPAT_COUNT); 75a53f4a29SSimon Glass return compat_names[id]; 76a53f4a29SSimon Glass } 77a53f4a29SSimon Glass 7802464e38SStephen Warren fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node, 7902464e38SStephen Warren const char *prop_name, int index, int na, int ns, 8002464e38SStephen Warren fdt_size_t *sizep) 8102464e38SStephen Warren { 8202464e38SStephen Warren const fdt32_t *prop, *prop_end; 8302464e38SStephen Warren const fdt32_t *prop_addr, *prop_size, *prop_after_size; 8402464e38SStephen Warren int len; 8502464e38SStephen Warren fdt_addr_t addr; 8602464e38SStephen Warren 8702464e38SStephen Warren debug("%s: %s: ", __func__, prop_name); 8802464e38SStephen Warren 8902464e38SStephen Warren if (na > (sizeof(fdt_addr_t) / sizeof(fdt32_t))) { 9002464e38SStephen Warren debug("(na too large for fdt_addr_t type)\n"); 9102464e38SStephen Warren return FDT_ADDR_T_NONE; 9202464e38SStephen Warren } 9302464e38SStephen Warren 9402464e38SStephen Warren if (ns > (sizeof(fdt_size_t) / sizeof(fdt32_t))) { 9502464e38SStephen Warren debug("(ns too large for fdt_size_t type)\n"); 9602464e38SStephen Warren return FDT_ADDR_T_NONE; 9702464e38SStephen Warren } 9802464e38SStephen Warren 9902464e38SStephen Warren prop = fdt_getprop(blob, node, prop_name, &len); 10002464e38SStephen Warren if (!prop) { 10102464e38SStephen Warren debug("(not found)\n"); 10202464e38SStephen Warren return FDT_ADDR_T_NONE; 10302464e38SStephen Warren } 10402464e38SStephen Warren prop_end = prop + (len / sizeof(*prop)); 10502464e38SStephen Warren 10602464e38SStephen Warren prop_addr = prop + (index * (na + ns)); 10702464e38SStephen Warren prop_size = prop_addr + na; 10802464e38SStephen Warren prop_after_size = prop_size + ns; 10902464e38SStephen Warren if (prop_after_size > prop_end) { 11002464e38SStephen Warren debug("(not enough data: expected >= %d cells, got %d cells)\n", 11102464e38SStephen Warren (u32)(prop_after_size - prop), ((u32)(prop_end - prop))); 11202464e38SStephen Warren return FDT_ADDR_T_NONE; 11302464e38SStephen Warren } 11402464e38SStephen Warren 11502464e38SStephen Warren addr = fdtdec_get_number(prop_addr, na); 11602464e38SStephen Warren 11702464e38SStephen Warren if (sizep) { 11802464e38SStephen Warren *sizep = fdtdec_get_number(prop_size, ns); 119fd30d2c6SSimon Glass debug("addr=%08llx, size=%llx\n", (unsigned long long)addr, 120fd30d2c6SSimon Glass (unsigned long long)*sizep); 12102464e38SStephen Warren } else { 122fd30d2c6SSimon Glass debug("addr=%08llx\n", (unsigned long long)addr); 12302464e38SStephen Warren } 12402464e38SStephen Warren 12502464e38SStephen Warren return addr; 12602464e38SStephen Warren } 12702464e38SStephen Warren 12802464e38SStephen Warren fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent, 12902464e38SStephen Warren int node, const char *prop_name, int index, fdt_size_t *sizep) 13002464e38SStephen Warren { 13102464e38SStephen Warren int na, ns; 13202464e38SStephen Warren 13302464e38SStephen Warren debug("%s: ", __func__); 13402464e38SStephen Warren 13502464e38SStephen Warren na = fdt_address_cells(blob, parent); 13602464e38SStephen Warren if (na < 1) { 13702464e38SStephen Warren debug("(bad #address-cells)\n"); 13802464e38SStephen Warren return FDT_ADDR_T_NONE; 13902464e38SStephen Warren } 14002464e38SStephen Warren 14102464e38SStephen Warren ns = fdt_size_cells(blob, parent); 142ff0a6358SPrzemyslaw Marczak if (ns < 0) { 14302464e38SStephen Warren debug("(bad #size-cells)\n"); 14402464e38SStephen Warren return FDT_ADDR_T_NONE; 14502464e38SStephen Warren } 14602464e38SStephen Warren 14702464e38SStephen Warren debug("na=%d, ns=%d, ", na, ns); 14802464e38SStephen Warren 14902464e38SStephen Warren return fdtdec_get_addr_size_fixed(blob, node, prop_name, index, na, 15002464e38SStephen Warren ns, sizep); 15102464e38SStephen Warren } 15202464e38SStephen Warren 15302464e38SStephen Warren fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, 15402464e38SStephen Warren const char *prop_name, int index, fdt_size_t *sizep) 15502464e38SStephen Warren { 15602464e38SStephen Warren int parent; 15702464e38SStephen Warren 15802464e38SStephen Warren debug("%s: ", __func__); 15902464e38SStephen Warren 16002464e38SStephen Warren parent = fdt_parent_offset(blob, node); 16102464e38SStephen Warren if (parent < 0) { 16202464e38SStephen Warren debug("(no parent found)\n"); 16302464e38SStephen Warren return FDT_ADDR_T_NONE; 16402464e38SStephen Warren } 16502464e38SStephen Warren 16602464e38SStephen Warren return fdtdec_get_addr_size_auto_parent(blob, parent, node, prop_name, 16702464e38SStephen Warren index, sizep); 16802464e38SStephen Warren } 16902464e38SStephen Warren 1704397a2a8SSimon Glass fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, 1714397a2a8SSimon Glass const char *prop_name, fdt_size_t *sizep) 172b5220bc6SSimon Glass { 173d93b9a07SStephen Warren int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0; 174d93b9a07SStephen Warren 17502464e38SStephen Warren return fdtdec_get_addr_size_fixed(blob, node, prop_name, 0, 17602464e38SStephen Warren sizeof(fdt_addr_t) / sizeof(fdt32_t), 177d93b9a07SStephen Warren ns, sizep); 178b5220bc6SSimon Glass } 179b5220bc6SSimon Glass 1804397a2a8SSimon Glass fdt_addr_t fdtdec_get_addr(const void *blob, int node, 1814397a2a8SSimon Glass const char *prop_name) 1824397a2a8SSimon Glass { 1834397a2a8SSimon Glass return fdtdec_get_addr_size(blob, node, prop_name, NULL); 1844397a2a8SSimon Glass } 1854397a2a8SSimon Glass 186fcc0a877SSimon Glass #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI) 187a62e84d7SBin Meng int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, 188a62e84d7SBin Meng const char *prop_name, struct fdt_pci_addr *addr) 189a62e84d7SBin Meng { 190a62e84d7SBin Meng const u32 *cell; 191a62e84d7SBin Meng int len; 192a62e84d7SBin Meng int ret = -ENOENT; 193a62e84d7SBin Meng 194a62e84d7SBin Meng debug("%s: %s: ", __func__, prop_name); 195a62e84d7SBin Meng 196a62e84d7SBin Meng /* 197a62e84d7SBin Meng * If we follow the pci bus bindings strictly, we should check 198a62e84d7SBin Meng * the value of the node's parent node's #address-cells and 199a62e84d7SBin Meng * #size-cells. They need to be 3 and 2 accordingly. However, 200a62e84d7SBin Meng * for simplicity we skip the check here. 201a62e84d7SBin Meng */ 202a62e84d7SBin Meng cell = fdt_getprop(blob, node, prop_name, &len); 203a62e84d7SBin Meng if (!cell) 204a62e84d7SBin Meng goto fail; 205a62e84d7SBin Meng 206a62e84d7SBin Meng if ((len % FDT_PCI_REG_SIZE) == 0) { 207a62e84d7SBin Meng int num = len / FDT_PCI_REG_SIZE; 208a62e84d7SBin Meng int i; 209a62e84d7SBin Meng 210a62e84d7SBin Meng for (i = 0; i < num; i++) { 211a62e84d7SBin Meng debug("pci address #%d: %08lx %08lx %08lx\n", i, 2124ea5243aSStephen Warren (ulong)fdt32_to_cpu(cell[0]), 2134ea5243aSStephen Warren (ulong)fdt32_to_cpu(cell[1]), 2144ea5243aSStephen Warren (ulong)fdt32_to_cpu(cell[2])); 2154ea5243aSStephen Warren if ((fdt32_to_cpu(*cell) & type) == type) { 2164ea5243aSStephen Warren addr->phys_hi = fdt32_to_cpu(cell[0]); 2174ea5243aSStephen Warren addr->phys_mid = fdt32_to_cpu(cell[1]); 2184ea5243aSStephen Warren addr->phys_lo = fdt32_to_cpu(cell[1]); 219a62e84d7SBin Meng break; 220a62e84d7SBin Meng } else { 221a62e84d7SBin Meng cell += (FDT_PCI_ADDR_CELLS + 222a62e84d7SBin Meng FDT_PCI_SIZE_CELLS); 223a62e84d7SBin Meng } 224a62e84d7SBin Meng } 225a62e84d7SBin Meng 226106cce96SSimon Glass if (i == num) { 227106cce96SSimon Glass ret = -ENXIO; 228a62e84d7SBin Meng goto fail; 229106cce96SSimon Glass } 230a62e84d7SBin Meng 231a62e84d7SBin Meng return 0; 232a62e84d7SBin Meng } else { 233a62e84d7SBin Meng ret = -EINVAL; 234a62e84d7SBin Meng } 235a62e84d7SBin Meng 236a62e84d7SBin Meng fail: 237a62e84d7SBin Meng debug("(not found)\n"); 238a62e84d7SBin Meng return ret; 239a62e84d7SBin Meng } 240a62e84d7SBin Meng 241a62e84d7SBin Meng int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device) 242a62e84d7SBin Meng { 243a62e84d7SBin Meng const char *list, *end; 244a62e84d7SBin Meng int len; 245a62e84d7SBin Meng 246a62e84d7SBin Meng list = fdt_getprop(blob, node, "compatible", &len); 247a62e84d7SBin Meng if (!list) 248a62e84d7SBin Meng return -ENOENT; 249a62e84d7SBin Meng 250a62e84d7SBin Meng end = list + len; 251a62e84d7SBin Meng while (list < end) { 252a62e84d7SBin Meng char *s; 253a62e84d7SBin Meng 254a62e84d7SBin Meng len = strlen(list); 255a62e84d7SBin Meng if (len >= strlen("pciVVVV,DDDD")) { 256a62e84d7SBin Meng s = strstr(list, "pci"); 257a62e84d7SBin Meng 258a62e84d7SBin Meng /* 259a62e84d7SBin Meng * check if the string is something like pciVVVV,DDDD.RR 260a62e84d7SBin Meng * or just pciVVVV,DDDD 261a62e84d7SBin Meng */ 262a62e84d7SBin Meng if (s && s[7] == ',' && 263a62e84d7SBin Meng (s[12] == '.' || s[12] == 0)) { 264a62e84d7SBin Meng s += 3; 265a62e84d7SBin Meng *vendor = simple_strtol(s, NULL, 16); 266a62e84d7SBin Meng 267a62e84d7SBin Meng s += 5; 268a62e84d7SBin Meng *device = simple_strtol(s, NULL, 16); 269a62e84d7SBin Meng 270a62e84d7SBin Meng return 0; 271a62e84d7SBin Meng } 272a62e84d7SBin Meng } 273bc6351ebSBin Meng list += (len + 1); 274a62e84d7SBin Meng } 275a62e84d7SBin Meng 276a62e84d7SBin Meng return -ENOENT; 277a62e84d7SBin Meng } 278a62e84d7SBin Meng 279fcc0a877SSimon Glass int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, 280fcc0a877SSimon Glass u32 *bar) 281a62e84d7SBin Meng { 282a62e84d7SBin Meng int barnum; 283a62e84d7SBin Meng 284a62e84d7SBin Meng /* extract the bar number from fdt_pci_addr */ 285a62e84d7SBin Meng barnum = addr->phys_hi & 0xff; 286a62e84d7SBin Meng if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS)) 287a62e84d7SBin Meng return -EINVAL; 288a62e84d7SBin Meng 289a62e84d7SBin Meng barnum = (barnum - PCI_BASE_ADDRESS_0) / 4; 290fcc0a877SSimon Glass *bar = dm_pci_read_bar32(dev, barnum); 291a62e84d7SBin Meng 292a62e84d7SBin Meng return 0; 293a62e84d7SBin Meng } 294a62e84d7SBin Meng #endif 295a62e84d7SBin Meng 296aadef0a1SChe-Liang Chiou uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, 297aadef0a1SChe-Liang Chiou uint64_t default_val) 298aadef0a1SChe-Liang Chiou { 299aadef0a1SChe-Liang Chiou const uint64_t *cell64; 300aadef0a1SChe-Liang Chiou int length; 301aadef0a1SChe-Liang Chiou 302aadef0a1SChe-Liang Chiou cell64 = fdt_getprop(blob, node, prop_name, &length); 303aadef0a1SChe-Liang Chiou if (!cell64 || length < sizeof(*cell64)) 304aadef0a1SChe-Liang Chiou return default_val; 305aadef0a1SChe-Liang Chiou 306aadef0a1SChe-Liang Chiou return fdt64_to_cpu(*cell64); 307aadef0a1SChe-Liang Chiou } 308aadef0a1SChe-Liang Chiou 309f88fe2deSSimon Glass int fdtdec_get_is_enabled(const void *blob, int node) 310b5220bc6SSimon Glass { 311b5220bc6SSimon Glass const char *cell; 312b5220bc6SSimon Glass 313f88fe2deSSimon Glass /* 314f88fe2deSSimon Glass * It should say "okay", so only allow that. Some fdts use "ok" but 315f88fe2deSSimon Glass * this is a bug. Please fix your device tree source file. See here 316f88fe2deSSimon Glass * for discussion: 317f88fe2deSSimon Glass * 318f88fe2deSSimon Glass * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html 319f88fe2deSSimon Glass */ 320b5220bc6SSimon Glass cell = fdt_getprop(blob, node, "status", NULL); 321b5220bc6SSimon Glass if (cell) 322f88fe2deSSimon Glass return 0 == strcmp(cell, "okay"); 323f88fe2deSSimon Glass return 1; 324b5220bc6SSimon Glass } 325b5220bc6SSimon Glass 3267cde397bSGerald Van Baren enum fdt_compat_id fdtdec_lookup(const void *blob, int node) 327b5220bc6SSimon Glass { 328b5220bc6SSimon Glass enum fdt_compat_id id; 329b5220bc6SSimon Glass 330b5220bc6SSimon Glass /* Search our drivers */ 331b5220bc6SSimon Glass for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++) 332b5220bc6SSimon Glass if (0 == fdt_node_check_compatible(blob, node, 333b5220bc6SSimon Glass compat_names[id])) 334b5220bc6SSimon Glass return id; 335b5220bc6SSimon Glass return COMPAT_UNKNOWN; 336b5220bc6SSimon Glass } 337b5220bc6SSimon Glass 338b5220bc6SSimon Glass int fdtdec_next_compatible(const void *blob, int node, 339b5220bc6SSimon Glass enum fdt_compat_id id) 340b5220bc6SSimon Glass { 341b5220bc6SSimon Glass return fdt_node_offset_by_compatible(blob, node, compat_names[id]); 342b5220bc6SSimon Glass } 343b5220bc6SSimon Glass 3443ddecfc7SSimon Glass int fdtdec_next_compatible_subnode(const void *blob, int node, 3453ddecfc7SSimon Glass enum fdt_compat_id id, int *depthp) 3463ddecfc7SSimon Glass { 3473ddecfc7SSimon Glass do { 3483ddecfc7SSimon Glass node = fdt_next_node(blob, node, depthp); 3493ddecfc7SSimon Glass } while (*depthp > 1); 3503ddecfc7SSimon Glass 3513ddecfc7SSimon Glass /* If this is a direct subnode, and compatible, return it */ 3523ddecfc7SSimon Glass if (*depthp == 1 && 0 == fdt_node_check_compatible( 3533ddecfc7SSimon Glass blob, node, compat_names[id])) 3543ddecfc7SSimon Glass return node; 3553ddecfc7SSimon Glass 3563ddecfc7SSimon Glass return -FDT_ERR_NOTFOUND; 3573ddecfc7SSimon Glass } 3583ddecfc7SSimon Glass 359b5220bc6SSimon Glass int fdtdec_next_alias(const void *blob, const char *name, 360b5220bc6SSimon Glass enum fdt_compat_id id, int *upto) 361b5220bc6SSimon Glass { 362b5220bc6SSimon Glass #define MAX_STR_LEN 20 363b5220bc6SSimon Glass char str[MAX_STR_LEN + 20]; 364b5220bc6SSimon Glass int node, err; 365b5220bc6SSimon Glass 366b5220bc6SSimon Glass /* snprintf() is not available */ 367b5220bc6SSimon Glass assert(strlen(name) < MAX_STR_LEN); 368b5220bc6SSimon Glass sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto); 36900878476SSimon Glass node = fdt_path_offset(blob, str); 370b5220bc6SSimon Glass if (node < 0) 371b5220bc6SSimon Glass return node; 372b5220bc6SSimon Glass err = fdt_node_check_compatible(blob, node, compat_names[id]); 373b5220bc6SSimon Glass if (err < 0) 374b5220bc6SSimon Glass return err; 375f88fe2deSSimon Glass if (err) 376f88fe2deSSimon Glass return -FDT_ERR_NOTFOUND; 377f88fe2deSSimon Glass (*upto)++; 378f88fe2deSSimon Glass return node; 379b5220bc6SSimon Glass } 380b5220bc6SSimon Glass 381a53f4a29SSimon Glass int fdtdec_find_aliases_for_id(const void *blob, const char *name, 382a53f4a29SSimon Glass enum fdt_compat_id id, int *node_list, int maxcount) 383a53f4a29SSimon Glass { 384c6782270SSimon Glass memset(node_list, '\0', sizeof(*node_list) * maxcount); 385c6782270SSimon Glass 386c6782270SSimon Glass return fdtdec_add_aliases_for_id(blob, name, id, node_list, maxcount); 387c6782270SSimon Glass } 388c6782270SSimon Glass 389c6782270SSimon Glass /* TODO: Can we tighten this code up a little? */ 390c6782270SSimon Glass int fdtdec_add_aliases_for_id(const void *blob, const char *name, 391c6782270SSimon Glass enum fdt_compat_id id, int *node_list, int maxcount) 392c6782270SSimon Glass { 393a53f4a29SSimon Glass int name_len = strlen(name); 394a53f4a29SSimon Glass int nodes[maxcount]; 395a53f4a29SSimon Glass int num_found = 0; 396a53f4a29SSimon Glass int offset, node; 397a53f4a29SSimon Glass int alias_node; 398a53f4a29SSimon Glass int count; 399a53f4a29SSimon Glass int i, j; 400a53f4a29SSimon Glass 401a53f4a29SSimon Glass /* find the alias node if present */ 402a53f4a29SSimon Glass alias_node = fdt_path_offset(blob, "/aliases"); 403a53f4a29SSimon Glass 404a53f4a29SSimon Glass /* 405a53f4a29SSimon Glass * start with nothing, and we can assume that the root node can't 406a53f4a29SSimon Glass * match 407a53f4a29SSimon Glass */ 408a53f4a29SSimon Glass memset(nodes, '\0', sizeof(nodes)); 409a53f4a29SSimon Glass 410a53f4a29SSimon Glass /* First find all the compatible nodes */ 411a53f4a29SSimon Glass for (node = count = 0; node >= 0 && count < maxcount;) { 412a53f4a29SSimon Glass node = fdtdec_next_compatible(blob, node, id); 413a53f4a29SSimon Glass if (node >= 0) 414a53f4a29SSimon Glass nodes[count++] = node; 415a53f4a29SSimon Glass } 416a53f4a29SSimon Glass if (node >= 0) 417a53f4a29SSimon Glass debug("%s: warning: maxcount exceeded with alias '%s'\n", 418a53f4a29SSimon Glass __func__, name); 419a53f4a29SSimon Glass 420a53f4a29SSimon Glass /* Now find all the aliases */ 421a53f4a29SSimon Glass for (offset = fdt_first_property_offset(blob, alias_node); 422a53f4a29SSimon Glass offset > 0; 423a53f4a29SSimon Glass offset = fdt_next_property_offset(blob, offset)) { 424a53f4a29SSimon Glass const struct fdt_property *prop; 425a53f4a29SSimon Glass const char *path; 426a53f4a29SSimon Glass int number; 427a53f4a29SSimon Glass int found; 428a53f4a29SSimon Glass 429a53f4a29SSimon Glass node = 0; 430a53f4a29SSimon Glass prop = fdt_get_property_by_offset(blob, offset, NULL); 431a53f4a29SSimon Glass path = fdt_string(blob, fdt32_to_cpu(prop->nameoff)); 432a53f4a29SSimon Glass if (prop->len && 0 == strncmp(path, name, name_len)) 433a53f4a29SSimon Glass node = fdt_path_offset(blob, prop->data); 434a53f4a29SSimon Glass if (node <= 0) 435a53f4a29SSimon Glass continue; 436a53f4a29SSimon Glass 437a53f4a29SSimon Glass /* Get the alias number */ 438a53f4a29SSimon Glass number = simple_strtoul(path + name_len, NULL, 10); 439a53f4a29SSimon Glass if (number < 0 || number >= maxcount) { 440a53f4a29SSimon Glass debug("%s: warning: alias '%s' is out of range\n", 441a53f4a29SSimon Glass __func__, path); 442a53f4a29SSimon Glass continue; 443a53f4a29SSimon Glass } 444a53f4a29SSimon Glass 445a53f4a29SSimon Glass /* Make sure the node we found is actually in our list! */ 446a53f4a29SSimon Glass found = -1; 447a53f4a29SSimon Glass for (j = 0; j < count; j++) 448a53f4a29SSimon Glass if (nodes[j] == node) { 449a53f4a29SSimon Glass found = j; 450a53f4a29SSimon Glass break; 451a53f4a29SSimon Glass } 452a53f4a29SSimon Glass 453a53f4a29SSimon Glass if (found == -1) { 454a53f4a29SSimon Glass debug("%s: warning: alias '%s' points to a node " 455a53f4a29SSimon Glass "'%s' that is missing or is not compatible " 456a53f4a29SSimon Glass " with '%s'\n", __func__, path, 457a53f4a29SSimon Glass fdt_get_name(blob, node, NULL), 458a53f4a29SSimon Glass compat_names[id]); 459a53f4a29SSimon Glass continue; 460a53f4a29SSimon Glass } 461a53f4a29SSimon Glass 462a53f4a29SSimon Glass /* 463a53f4a29SSimon Glass * Add this node to our list in the right place, and mark 464a53f4a29SSimon Glass * it as done. 465a53f4a29SSimon Glass */ 466a53f4a29SSimon Glass if (fdtdec_get_is_enabled(blob, node)) { 467c6782270SSimon Glass if (node_list[number]) { 468c6782270SSimon Glass debug("%s: warning: alias '%s' requires that " 469c6782270SSimon Glass "a node be placed in the list in a " 470c6782270SSimon Glass "position which is already filled by " 471c6782270SSimon Glass "node '%s'\n", __func__, path, 472c6782270SSimon Glass fdt_get_name(blob, node, NULL)); 473c6782270SSimon Glass continue; 474c6782270SSimon Glass } 475a53f4a29SSimon Glass node_list[number] = node; 476a53f4a29SSimon Glass if (number >= num_found) 477a53f4a29SSimon Glass num_found = number + 1; 478a53f4a29SSimon Glass } 479c6782270SSimon Glass nodes[found] = 0; 480a53f4a29SSimon Glass } 481a53f4a29SSimon Glass 482a53f4a29SSimon Glass /* Add any nodes not mentioned by an alias */ 483a53f4a29SSimon Glass for (i = j = 0; i < maxcount; i++) { 484a53f4a29SSimon Glass if (!node_list[i]) { 485a53f4a29SSimon Glass for (; j < maxcount; j++) 486a53f4a29SSimon Glass if (nodes[j] && 487a53f4a29SSimon Glass fdtdec_get_is_enabled(blob, nodes[j])) 488a53f4a29SSimon Glass break; 489a53f4a29SSimon Glass 490a53f4a29SSimon Glass /* Have we run out of nodes to add? */ 491a53f4a29SSimon Glass if (j == maxcount) 492a53f4a29SSimon Glass break; 493a53f4a29SSimon Glass 494a53f4a29SSimon Glass assert(!node_list[i]); 495a53f4a29SSimon Glass node_list[i] = nodes[j++]; 496a53f4a29SSimon Glass if (i >= num_found) 497a53f4a29SSimon Glass num_found = i + 1; 498a53f4a29SSimon Glass } 499a53f4a29SSimon Glass } 500a53f4a29SSimon Glass 501a53f4a29SSimon Glass return num_found; 502a53f4a29SSimon Glass } 503a53f4a29SSimon Glass 5045c33c9fdSSimon Glass int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, 5055c33c9fdSSimon Glass int *seqp) 5065c33c9fdSSimon Glass { 5075c33c9fdSSimon Glass int base_len = strlen(base); 5085c33c9fdSSimon Glass const char *find_name; 5095c33c9fdSSimon Glass int find_namelen; 5105c33c9fdSSimon Glass int prop_offset; 5115c33c9fdSSimon Glass int aliases; 5125c33c9fdSSimon Glass 5135c33c9fdSSimon Glass find_name = fdt_get_name(blob, offset, &find_namelen); 5145c33c9fdSSimon Glass debug("Looking for '%s' at %d, name %s\n", base, offset, find_name); 5155c33c9fdSSimon Glass 5165c33c9fdSSimon Glass aliases = fdt_path_offset(blob, "/aliases"); 5175c33c9fdSSimon Glass for (prop_offset = fdt_first_property_offset(blob, aliases); 5185c33c9fdSSimon Glass prop_offset > 0; 5195c33c9fdSSimon Glass prop_offset = fdt_next_property_offset(blob, prop_offset)) { 5205c33c9fdSSimon Glass const char *prop; 5215c33c9fdSSimon Glass const char *name; 5225c33c9fdSSimon Glass const char *slash; 523c4af6732SSimon Glass int len, val; 5245c33c9fdSSimon Glass 5255c33c9fdSSimon Glass prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len); 5265c33c9fdSSimon Glass debug(" - %s, %s\n", name, prop); 5275c33c9fdSSimon Glass if (len < find_namelen || *prop != '/' || prop[len - 1] || 5285c33c9fdSSimon Glass strncmp(name, base, base_len)) 5295c33c9fdSSimon Glass continue; 5305c33c9fdSSimon Glass 5315c33c9fdSSimon Glass slash = strrchr(prop, '/'); 5325c33c9fdSSimon Glass if (strcmp(slash + 1, find_name)) 5335c33c9fdSSimon Glass continue; 534c4af6732SSimon Glass val = trailing_strtol(name); 535c4af6732SSimon Glass if (val != -1) { 536c4af6732SSimon Glass *seqp = val; 5375c33c9fdSSimon Glass debug("Found seq %d\n", *seqp); 5385c33c9fdSSimon Glass return 0; 5395c33c9fdSSimon Glass } 5405c33c9fdSSimon Glass } 5415c33c9fdSSimon Glass 5425c33c9fdSSimon Glass debug("Not found\n"); 5435c33c9fdSSimon Glass return -ENOENT; 5445c33c9fdSSimon Glass } 5455c33c9fdSSimon Glass 5463bc37a50SSimon Glass const char *fdtdec_get_chosen_prop(const void *blob, const char *name) 5473bc37a50SSimon Glass { 5483bc37a50SSimon Glass int chosen_node; 5493bc37a50SSimon Glass 5503bc37a50SSimon Glass if (!blob) 5513bc37a50SSimon Glass return NULL; 5523bc37a50SSimon Glass chosen_node = fdt_path_offset(blob, "/chosen"); 5533bc37a50SSimon Glass return fdt_getprop(blob, chosen_node, name, NULL); 5543bc37a50SSimon Glass } 5553bc37a50SSimon Glass 556aac07d49SSimon Glass int fdtdec_get_chosen_node(const void *blob, const char *name) 557aac07d49SSimon Glass { 558aac07d49SSimon Glass const char *prop; 559aac07d49SSimon Glass 5603bc37a50SSimon Glass prop = fdtdec_get_chosen_prop(blob, name); 561aac07d49SSimon Glass if (!prop) 562aac07d49SSimon Glass return -FDT_ERR_NOTFOUND; 563aac07d49SSimon Glass return fdt_path_offset(blob, prop); 564aac07d49SSimon Glass } 565aac07d49SSimon Glass 5669a263e55SSimon Glass int fdtdec_check_fdt(void) 5679a263e55SSimon Glass { 5689a263e55SSimon Glass /* 5699a263e55SSimon Glass * We must have an FDT, but we cannot panic() yet since the console 5709a263e55SSimon Glass * is not ready. So for now, just assert(). Boards which need an early 5719a263e55SSimon Glass * FDT (prior to console ready) will need to make their own 5729a263e55SSimon Glass * arrangements and do their own checks. 5739a263e55SSimon Glass */ 5749a263e55SSimon Glass assert(!fdtdec_prepare_fdt()); 5759a263e55SSimon Glass return 0; 5769a263e55SSimon Glass } 5779a263e55SSimon Glass 578b5220bc6SSimon Glass /* 579b5220bc6SSimon Glass * This function is a little odd in that it accesses global data. At some 580b5220bc6SSimon Glass * point if the architecture board.c files merge this will make more sense. 581b5220bc6SSimon Glass * Even now, it is common code. 582b5220bc6SSimon Glass */ 5839a263e55SSimon Glass int fdtdec_prepare_fdt(void) 584b5220bc6SSimon Glass { 585c309c2daSSimon Glass if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) || 586c309c2daSSimon Glass fdt_check_header(gd->fdt_blob)) { 58766312374SSimon Glass #ifdef CONFIG_SPL_BUILD 58866312374SSimon Glass puts("Missing DTB\n"); 58966312374SSimon Glass #else 59066312374SSimon Glass 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"); 591cb5f97f7SSimon Glass # ifdef DEBUG 592cb5f97f7SSimon Glass if (gd->fdt_blob) { 593cb5f97f7SSimon Glass printf("fdt_blob=%p\n", gd->fdt_blob); 594cb5f97f7SSimon Glass print_buffer((ulong)gd->fdt_blob, gd->fdt_blob, 4, 595cb5f97f7SSimon Glass 32, 0); 596cb5f97f7SSimon Glass } 597cb5f97f7SSimon Glass # endif 59866312374SSimon Glass #endif 5999a263e55SSimon Glass return -1; 6009a263e55SSimon Glass } 601b5220bc6SSimon Glass return 0; 602b5220bc6SSimon Glass } 603d17da655SSimon Glass 604d17da655SSimon Glass int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) 605d17da655SSimon Glass { 606d17da655SSimon Glass const u32 *phandle; 607d17da655SSimon Glass int lookup; 608d17da655SSimon Glass 6091cb2323bSSimon Glass debug("%s: %s\n", __func__, prop_name); 610d17da655SSimon Glass phandle = fdt_getprop(blob, node, prop_name, NULL); 611d17da655SSimon Glass if (!phandle) 612d17da655SSimon Glass return -FDT_ERR_NOTFOUND; 613d17da655SSimon Glass 614d17da655SSimon Glass lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle)); 615d17da655SSimon Glass return lookup; 616d17da655SSimon Glass } 617d17da655SSimon Glass 618d17da655SSimon Glass /** 619d17da655SSimon Glass * Look up a property in a node and check that it has a minimum length. 620d17da655SSimon Glass * 621d17da655SSimon Glass * @param blob FDT blob 622d17da655SSimon Glass * @param node node to examine 623d17da655SSimon Glass * @param prop_name name of property to find 624d17da655SSimon Glass * @param min_len minimum property length in bytes 625d17da655SSimon Glass * @param err 0 if ok, or -FDT_ERR_NOTFOUND if the property is not 626d17da655SSimon Glass found, or -FDT_ERR_BADLAYOUT if not enough data 627d17da655SSimon Glass * @return pointer to cell, which is only valid if err == 0 628d17da655SSimon Glass */ 629d17da655SSimon Glass static const void *get_prop_check_min_len(const void *blob, int node, 630d17da655SSimon Glass const char *prop_name, int min_len, int *err) 631d17da655SSimon Glass { 632d17da655SSimon Glass const void *cell; 633d17da655SSimon Glass int len; 634d17da655SSimon Glass 635d17da655SSimon Glass debug("%s: %s\n", __func__, prop_name); 636d17da655SSimon Glass cell = fdt_getprop(blob, node, prop_name, &len); 637d17da655SSimon Glass if (!cell) 638d17da655SSimon Glass *err = -FDT_ERR_NOTFOUND; 639d17da655SSimon Glass else if (len < min_len) 640d17da655SSimon Glass *err = -FDT_ERR_BADLAYOUT; 641d17da655SSimon Glass else 642d17da655SSimon Glass *err = 0; 643d17da655SSimon Glass return cell; 644d17da655SSimon Glass } 645d17da655SSimon Glass 646d17da655SSimon Glass int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, 647d17da655SSimon Glass u32 *array, int count) 648d17da655SSimon Glass { 649d17da655SSimon Glass const u32 *cell; 650d17da655SSimon Glass int i, err = 0; 651d17da655SSimon Glass 652d17da655SSimon Glass debug("%s: %s\n", __func__, prop_name); 653d17da655SSimon Glass cell = get_prop_check_min_len(blob, node, prop_name, 654d17da655SSimon Glass sizeof(u32) * count, &err); 655d17da655SSimon Glass if (!err) { 656d17da655SSimon Glass for (i = 0; i < count; i++) 657d17da655SSimon Glass array[i] = fdt32_to_cpu(cell[i]); 658d17da655SSimon Glass } 659d17da655SSimon Glass return err; 660d17da655SSimon Glass } 661d17da655SSimon Glass 662a9f04d49SSimon Glass int fdtdec_get_int_array_count(const void *blob, int node, 663a9f04d49SSimon Glass const char *prop_name, u32 *array, int count) 664a9f04d49SSimon Glass { 665a9f04d49SSimon Glass const u32 *cell; 666a9f04d49SSimon Glass int len, elems; 667a9f04d49SSimon Glass int i; 668a9f04d49SSimon Glass 669a9f04d49SSimon Glass debug("%s: %s\n", __func__, prop_name); 670a9f04d49SSimon Glass cell = fdt_getprop(blob, node, prop_name, &len); 671a9f04d49SSimon Glass if (!cell) 672a9f04d49SSimon Glass return -FDT_ERR_NOTFOUND; 673a9f04d49SSimon Glass elems = len / sizeof(u32); 674a9f04d49SSimon Glass if (count > elems) 675a9f04d49SSimon Glass count = elems; 676a9f04d49SSimon Glass for (i = 0; i < count; i++) 677a9f04d49SSimon Glass array[i] = fdt32_to_cpu(cell[i]); 678a9f04d49SSimon Glass 679a9f04d49SSimon Glass return count; 680a9f04d49SSimon Glass } 681a9f04d49SSimon Glass 68296875e7dSSimon Glass const u32 *fdtdec_locate_array(const void *blob, int node, 68396875e7dSSimon Glass const char *prop_name, int count) 68496875e7dSSimon Glass { 68596875e7dSSimon Glass const u32 *cell; 68696875e7dSSimon Glass int err; 68796875e7dSSimon Glass 68896875e7dSSimon Glass cell = get_prop_check_min_len(blob, node, prop_name, 68996875e7dSSimon Glass sizeof(u32) * count, &err); 69096875e7dSSimon Glass return err ? NULL : cell; 69196875e7dSSimon Glass } 69296875e7dSSimon Glass 693d17da655SSimon Glass int fdtdec_get_bool(const void *blob, int node, const char *prop_name) 694d17da655SSimon Glass { 695d17da655SSimon Glass const s32 *cell; 696d17da655SSimon Glass int len; 697d17da655SSimon Glass 698d17da655SSimon Glass debug("%s: %s\n", __func__, prop_name); 699d17da655SSimon Glass cell = fdt_getprop(blob, node, prop_name, &len); 700d17da655SSimon Glass return cell != NULL; 701d17da655SSimon Glass } 702ed3ee5cdSSimon Glass 70357068a7aSSimon Glass int fdtdec_parse_phandle_with_args(const void *blob, int src_node, 70457068a7aSSimon Glass const char *list_name, 70557068a7aSSimon Glass const char *cells_name, 70657068a7aSSimon Glass int cell_count, int index, 70757068a7aSSimon Glass struct fdtdec_phandle_args *out_args) 70857068a7aSSimon Glass { 70957068a7aSSimon Glass const __be32 *list, *list_end; 71057068a7aSSimon Glass int rc = 0, size, cur_index = 0; 71157068a7aSSimon Glass uint32_t count = 0; 71257068a7aSSimon Glass int node = -1; 71357068a7aSSimon Glass int phandle; 71457068a7aSSimon Glass 71557068a7aSSimon Glass /* Retrieve the phandle list property */ 71657068a7aSSimon Glass list = fdt_getprop(blob, src_node, list_name, &size); 71757068a7aSSimon Glass if (!list) 71857068a7aSSimon Glass return -ENOENT; 71957068a7aSSimon Glass list_end = list + size / sizeof(*list); 72057068a7aSSimon Glass 72157068a7aSSimon Glass /* Loop over the phandles until all the requested entry is found */ 72257068a7aSSimon Glass while (list < list_end) { 72357068a7aSSimon Glass rc = -EINVAL; 72457068a7aSSimon Glass count = 0; 72557068a7aSSimon Glass 72657068a7aSSimon Glass /* 72757068a7aSSimon Glass * If phandle is 0, then it is an empty entry with no 72857068a7aSSimon Glass * arguments. Skip forward to the next entry. 72957068a7aSSimon Glass */ 73057068a7aSSimon Glass phandle = be32_to_cpup(list++); 73157068a7aSSimon Glass if (phandle) { 73257068a7aSSimon Glass /* 73357068a7aSSimon Glass * Find the provider node and parse the #*-cells 73457068a7aSSimon Glass * property to determine the argument length. 73557068a7aSSimon Glass * 73657068a7aSSimon Glass * This is not needed if the cell count is hard-coded 73757068a7aSSimon Glass * (i.e. cells_name not set, but cell_count is set), 73857068a7aSSimon Glass * except when we're going to return the found node 73957068a7aSSimon Glass * below. 74057068a7aSSimon Glass */ 74157068a7aSSimon Glass if (cells_name || cur_index == index) { 74257068a7aSSimon Glass node = fdt_node_offset_by_phandle(blob, 74357068a7aSSimon Glass phandle); 74457068a7aSSimon Glass if (!node) { 74557068a7aSSimon Glass debug("%s: could not find phandle\n", 74657068a7aSSimon Glass fdt_get_name(blob, src_node, 74757068a7aSSimon Glass NULL)); 74857068a7aSSimon Glass goto err; 74957068a7aSSimon Glass } 75057068a7aSSimon Glass } 75157068a7aSSimon Glass 75257068a7aSSimon Glass if (cells_name) { 75357068a7aSSimon Glass count = fdtdec_get_int(blob, node, cells_name, 75457068a7aSSimon Glass -1); 75557068a7aSSimon Glass if (count == -1) { 75657068a7aSSimon Glass debug("%s: could not get %s for %s\n", 75757068a7aSSimon Glass fdt_get_name(blob, src_node, 75857068a7aSSimon Glass NULL), 75957068a7aSSimon Glass cells_name, 76057068a7aSSimon Glass fdt_get_name(blob, node, 76157068a7aSSimon Glass NULL)); 76257068a7aSSimon Glass goto err; 76357068a7aSSimon Glass } 76457068a7aSSimon Glass } else { 76557068a7aSSimon Glass count = cell_count; 76657068a7aSSimon Glass } 76757068a7aSSimon Glass 76857068a7aSSimon Glass /* 76957068a7aSSimon Glass * Make sure that the arguments actually fit in the 77057068a7aSSimon Glass * remaining property data length 77157068a7aSSimon Glass */ 77257068a7aSSimon Glass if (list + count > list_end) { 77357068a7aSSimon Glass debug("%s: arguments longer than property\n", 77457068a7aSSimon Glass fdt_get_name(blob, src_node, NULL)); 77557068a7aSSimon Glass goto err; 77657068a7aSSimon Glass } 77757068a7aSSimon Glass } 77857068a7aSSimon Glass 77957068a7aSSimon Glass /* 78057068a7aSSimon Glass * All of the error cases above bail out of the loop, so at 78157068a7aSSimon Glass * this point, the parsing is successful. If the requested 78257068a7aSSimon Glass * index matches, then fill the out_args structure and return, 78357068a7aSSimon Glass * or return -ENOENT for an empty entry. 78457068a7aSSimon Glass */ 78557068a7aSSimon Glass rc = -ENOENT; 78657068a7aSSimon Glass if (cur_index == index) { 78757068a7aSSimon Glass if (!phandle) 78857068a7aSSimon Glass goto err; 78957068a7aSSimon Glass 79057068a7aSSimon Glass if (out_args) { 79157068a7aSSimon Glass int i; 79257068a7aSSimon Glass 79357068a7aSSimon Glass if (count > MAX_PHANDLE_ARGS) { 79457068a7aSSimon Glass debug("%s: too many arguments %d\n", 79557068a7aSSimon Glass fdt_get_name(blob, src_node, 79657068a7aSSimon Glass NULL), count); 79757068a7aSSimon Glass count = MAX_PHANDLE_ARGS; 79857068a7aSSimon Glass } 79957068a7aSSimon Glass out_args->node = node; 80057068a7aSSimon Glass out_args->args_count = count; 80157068a7aSSimon Glass for (i = 0; i < count; i++) { 80257068a7aSSimon Glass out_args->args[i] = 80357068a7aSSimon Glass be32_to_cpup(list++); 80457068a7aSSimon Glass } 80557068a7aSSimon Glass } 80657068a7aSSimon Glass 80757068a7aSSimon Glass /* Found it! return success */ 80857068a7aSSimon Glass return 0; 80957068a7aSSimon Glass } 81057068a7aSSimon Glass 81157068a7aSSimon Glass node = -1; 81257068a7aSSimon Glass list += count; 81357068a7aSSimon Glass cur_index++; 81457068a7aSSimon Glass } 81557068a7aSSimon Glass 81657068a7aSSimon Glass /* 81757068a7aSSimon Glass * Result will be one of: 81857068a7aSSimon Glass * -ENOENT : index is for empty phandle 81957068a7aSSimon Glass * -EINVAL : parsing error on data 82057068a7aSSimon Glass * [1..n] : Number of phandle (count mode; when index = -1) 82157068a7aSSimon Glass */ 82257068a7aSSimon Glass rc = index < 0 ? cur_index : -ENOENT; 82357068a7aSSimon Glass err: 82457068a7aSSimon Glass return rc; 82557068a7aSSimon Glass } 82657068a7aSSimon Glass 8271889a7e2SPeng Fan int fdtdec_get_child_count(const void *blob, int node) 8281889a7e2SPeng Fan { 8291889a7e2SPeng Fan int subnode; 8301889a7e2SPeng Fan int num = 0; 8311889a7e2SPeng Fan 8321889a7e2SPeng Fan fdt_for_each_subnode(blob, subnode, node) 8331889a7e2SPeng Fan num++; 8341889a7e2SPeng Fan 8351889a7e2SPeng Fan return num; 8361889a7e2SPeng Fan } 8371889a7e2SPeng Fan 838bed4d892SAnton Staff int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, 839bed4d892SAnton Staff u8 *array, int count) 840bed4d892SAnton Staff { 841bed4d892SAnton Staff const u8 *cell; 842bed4d892SAnton Staff int err; 843bed4d892SAnton Staff 844bed4d892SAnton Staff cell = get_prop_check_min_len(blob, node, prop_name, count, &err); 845bed4d892SAnton Staff if (!err) 846bed4d892SAnton Staff memcpy(array, cell, count); 847bed4d892SAnton Staff return err; 848bed4d892SAnton Staff } 849bed4d892SAnton Staff 850bed4d892SAnton Staff const u8 *fdtdec_locate_byte_array(const void *blob, int node, 851bed4d892SAnton Staff const char *prop_name, int count) 852bed4d892SAnton Staff { 853bed4d892SAnton Staff const u8 *cell; 854bed4d892SAnton Staff int err; 855bed4d892SAnton Staff 856bed4d892SAnton Staff cell = get_prop_check_min_len(blob, node, prop_name, count, &err); 857bed4d892SAnton Staff if (err) 858bed4d892SAnton Staff return NULL; 859bed4d892SAnton Staff return cell; 860bed4d892SAnton Staff } 86109258f1eSAbhilash Kesavan 86209258f1eSAbhilash Kesavan int fdtdec_get_config_int(const void *blob, const char *prop_name, 86309258f1eSAbhilash Kesavan int default_val) 86409258f1eSAbhilash Kesavan { 86509258f1eSAbhilash Kesavan int config_node; 86609258f1eSAbhilash Kesavan 86709258f1eSAbhilash Kesavan debug("%s: %s\n", __func__, prop_name); 86809258f1eSAbhilash Kesavan config_node = fdt_path_offset(blob, "/config"); 86909258f1eSAbhilash Kesavan if (config_node < 0) 87009258f1eSAbhilash Kesavan return default_val; 87109258f1eSAbhilash Kesavan return fdtdec_get_int(blob, config_node, prop_name, default_val); 87209258f1eSAbhilash Kesavan } 873332ab0d5SSimon Glass 87479289c0bSGabe Black int fdtdec_get_config_bool(const void *blob, const char *prop_name) 87579289c0bSGabe Black { 87679289c0bSGabe Black int config_node; 87779289c0bSGabe Black const void *prop; 87879289c0bSGabe Black 87979289c0bSGabe Black debug("%s: %s\n", __func__, prop_name); 88079289c0bSGabe Black config_node = fdt_path_offset(blob, "/config"); 88179289c0bSGabe Black if (config_node < 0) 88279289c0bSGabe Black return 0; 88379289c0bSGabe Black prop = fdt_get_property(blob, config_node, prop_name, NULL); 88479289c0bSGabe Black 88579289c0bSGabe Black return prop != NULL; 88679289c0bSGabe Black } 88779289c0bSGabe Black 888332ab0d5SSimon Glass char *fdtdec_get_config_string(const void *blob, const char *prop_name) 889332ab0d5SSimon Glass { 890332ab0d5SSimon Glass const char *nodep; 891332ab0d5SSimon Glass int nodeoffset; 892332ab0d5SSimon Glass int len; 893332ab0d5SSimon Glass 894332ab0d5SSimon Glass debug("%s: %s\n", __func__, prop_name); 895332ab0d5SSimon Glass nodeoffset = fdt_path_offset(blob, "/config"); 896332ab0d5SSimon Glass if (nodeoffset < 0) 897332ab0d5SSimon Glass return NULL; 898332ab0d5SSimon Glass 899332ab0d5SSimon Glass nodep = fdt_getprop(blob, nodeoffset, prop_name, &len); 900332ab0d5SSimon Glass if (!nodep) 901332ab0d5SSimon Glass return NULL; 902332ab0d5SSimon Glass 903332ab0d5SSimon Glass return (char *)nodep; 904332ab0d5SSimon Glass } 905f20c4619SSimon Glass 90676489832SSimon Glass int fdtdec_decode_region(const void *blob, int node, const char *prop_name, 90776489832SSimon Glass fdt_addr_t *basep, fdt_size_t *sizep) 908f20c4619SSimon Glass { 909f20c4619SSimon Glass const fdt_addr_t *cell; 910f20c4619SSimon Glass int len; 911f20c4619SSimon Glass 91276489832SSimon Glass debug("%s: %s: %s\n", __func__, fdt_get_name(blob, node, NULL), 91376489832SSimon Glass prop_name); 914f20c4619SSimon Glass cell = fdt_getprop(blob, node, prop_name, &len); 91576489832SSimon Glass if (!cell || (len < sizeof(fdt_addr_t) * 2)) { 91676489832SSimon Glass debug("cell=%p, len=%d\n", cell, len); 917f20c4619SSimon Glass return -1; 91876489832SSimon Glass } 919f20c4619SSimon Glass 92076489832SSimon Glass *basep = fdt_addr_to_cpu(*cell); 92176489832SSimon Glass *sizep = fdt_size_to_cpu(cell[1]); 92276489832SSimon Glass debug("%s: base=%08lx, size=%lx\n", __func__, (ulong)*basep, 92376489832SSimon Glass (ulong)*sizep); 92476489832SSimon Glass 925f20c4619SSimon Glass return 0; 926f20c4619SSimon Glass } 927006e73b9SSimon Glass 928006e73b9SSimon Glass /** 929006e73b9SSimon Glass * Read a flash entry from the fdt 930006e73b9SSimon Glass * 931006e73b9SSimon Glass * @param blob FDT blob 932006e73b9SSimon Glass * @param node Offset of node to read 933006e73b9SSimon Glass * @param name Name of node being read 934006e73b9SSimon Glass * @param entry Place to put offset and size of this node 935006e73b9SSimon Glass * @return 0 if ok, -ve on error 936006e73b9SSimon Glass */ 937006e73b9SSimon Glass int fdtdec_read_fmap_entry(const void *blob, int node, const char *name, 938006e73b9SSimon Glass struct fmap_entry *entry) 939006e73b9SSimon Glass { 940f3cc44f9SSimon Glass const char *prop; 941006e73b9SSimon Glass u32 reg[2]; 942006e73b9SSimon Glass 943006e73b9SSimon Glass if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) { 944006e73b9SSimon Glass debug("Node '%s' has bad/missing 'reg' property\n", name); 945006e73b9SSimon Glass return -FDT_ERR_NOTFOUND; 946006e73b9SSimon Glass } 947006e73b9SSimon Glass entry->offset = reg[0]; 948006e73b9SSimon Glass entry->length = reg[1]; 949f3cc44f9SSimon Glass entry->used = fdtdec_get_int(blob, node, "used", entry->length); 950f3cc44f9SSimon Glass prop = fdt_getprop(blob, node, "compress", NULL); 951f3cc44f9SSimon Glass entry->compress_algo = prop && !strcmp(prop, "lzo") ? 952f3cc44f9SSimon Glass FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE; 953f3cc44f9SSimon Glass prop = fdt_getprop(blob, node, "hash", &entry->hash_size); 954f3cc44f9SSimon Glass entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE; 955f3cc44f9SSimon Glass entry->hash = (uint8_t *)prop; 956006e73b9SSimon Glass 957006e73b9SSimon Glass return 0; 958006e73b9SSimon Glass } 95956f42242SThierry Reding 9605f7bfdd6SSimon Glass u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells) 96156f42242SThierry Reding { 96256f42242SThierry Reding u64 number = 0; 96356f42242SThierry Reding 96456f42242SThierry Reding while (cells--) 96556f42242SThierry Reding number = (number << 32) | fdt32_to_cpu(*ptr++); 96656f42242SThierry Reding 96756f42242SThierry Reding return number; 96856f42242SThierry Reding } 96956f42242SThierry Reding 97056f42242SThierry Reding int fdt_get_resource(const void *fdt, int node, const char *property, 97156f42242SThierry Reding unsigned int index, struct fdt_resource *res) 97256f42242SThierry Reding { 97356f42242SThierry Reding const fdt32_t *ptr, *end; 97456f42242SThierry Reding int na, ns, len, parent; 97556f42242SThierry Reding unsigned int i = 0; 97656f42242SThierry Reding 97756f42242SThierry Reding parent = fdt_parent_offset(fdt, node); 97856f42242SThierry Reding if (parent < 0) 97956f42242SThierry Reding return parent; 98056f42242SThierry Reding 98156f42242SThierry Reding na = fdt_address_cells(fdt, parent); 98256f42242SThierry Reding ns = fdt_size_cells(fdt, parent); 98356f42242SThierry Reding 98456f42242SThierry Reding ptr = fdt_getprop(fdt, node, property, &len); 98556f42242SThierry Reding if (!ptr) 98656f42242SThierry Reding return len; 98756f42242SThierry Reding 98856f42242SThierry Reding end = ptr + len / sizeof(*ptr); 98956f42242SThierry Reding 99056f42242SThierry Reding while (ptr + na + ns <= end) { 99156f42242SThierry Reding if (i == index) { 99256f42242SThierry Reding res->start = res->end = fdtdec_get_number(ptr, na); 99356f42242SThierry Reding res->end += fdtdec_get_number(&ptr[na], ns) - 1; 99456f42242SThierry Reding return 0; 99556f42242SThierry Reding } 99656f42242SThierry Reding 99756f42242SThierry Reding ptr += na + ns; 99856f42242SThierry Reding i++; 99956f42242SThierry Reding } 100056f42242SThierry Reding 100156f42242SThierry Reding return -FDT_ERR_NOTFOUND; 100256f42242SThierry Reding } 100356f42242SThierry Reding 100456f42242SThierry Reding int fdt_get_named_resource(const void *fdt, int node, const char *property, 100556f42242SThierry Reding const char *prop_names, const char *name, 100656f42242SThierry Reding struct fdt_resource *res) 100756f42242SThierry Reding { 100856f42242SThierry Reding int index; 100956f42242SThierry Reding 101056f42242SThierry Reding index = fdt_find_string(fdt, node, prop_names, name); 101156f42242SThierry Reding if (index < 0) 101256f42242SThierry Reding return index; 101356f42242SThierry Reding 101456f42242SThierry Reding return fdt_get_resource(fdt, node, property, index, res); 101556f42242SThierry Reding } 10169f85eee7SThierry Reding 101726403871SSimon Glass int fdtdec_decode_memory_region(const void *blob, int config_node, 101826403871SSimon Glass const char *mem_type, const char *suffix, 101926403871SSimon Glass fdt_addr_t *basep, fdt_size_t *sizep) 102026403871SSimon Glass { 102126403871SSimon Glass char prop_name[50]; 102226403871SSimon Glass const char *mem; 102326403871SSimon Glass fdt_size_t size, offset_size; 102426403871SSimon Glass fdt_addr_t base, offset; 102526403871SSimon Glass int node; 102626403871SSimon Glass 102726403871SSimon Glass if (config_node == -1) { 102826403871SSimon Glass config_node = fdt_path_offset(blob, "/config"); 102926403871SSimon Glass if (config_node < 0) { 103026403871SSimon Glass debug("%s: Cannot find /config node\n", __func__); 103126403871SSimon Glass return -ENOENT; 103226403871SSimon Glass } 103326403871SSimon Glass } 103426403871SSimon Glass if (!suffix) 103526403871SSimon Glass suffix = ""; 103626403871SSimon Glass 103726403871SSimon Glass snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type, 103826403871SSimon Glass suffix); 103926403871SSimon Glass mem = fdt_getprop(blob, config_node, prop_name, NULL); 104026403871SSimon Glass if (!mem) { 104126403871SSimon Glass debug("%s: No memory type for '%s', using /memory\n", __func__, 104226403871SSimon Glass prop_name); 104326403871SSimon Glass mem = "/memory"; 104426403871SSimon Glass } 104526403871SSimon Glass 104626403871SSimon Glass node = fdt_path_offset(blob, mem); 104726403871SSimon Glass if (node < 0) { 104826403871SSimon Glass debug("%s: Failed to find node '%s': %s\n", __func__, mem, 104926403871SSimon Glass fdt_strerror(node)); 105026403871SSimon Glass return -ENOENT; 105126403871SSimon Glass } 105226403871SSimon Glass 105326403871SSimon Glass /* 105426403871SSimon Glass * Not strictly correct - the memory may have multiple banks. We just 105526403871SSimon Glass * use the first 105626403871SSimon Glass */ 105726403871SSimon Glass if (fdtdec_decode_region(blob, node, "reg", &base, &size)) { 105826403871SSimon Glass debug("%s: Failed to decode memory region %s\n", __func__, 105926403871SSimon Glass mem); 106026403871SSimon Glass return -EINVAL; 106126403871SSimon Glass } 106226403871SSimon Glass 106326403871SSimon Glass snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type, 106426403871SSimon Glass suffix); 106526403871SSimon Glass if (fdtdec_decode_region(blob, config_node, prop_name, &offset, 106626403871SSimon Glass &offset_size)) { 106726403871SSimon Glass debug("%s: Failed to decode memory region '%s'\n", __func__, 106826403871SSimon Glass prop_name); 106926403871SSimon Glass return -EINVAL; 107026403871SSimon Glass } 107126403871SSimon Glass 107226403871SSimon Glass *basep = base + offset; 107326403871SSimon Glass *sizep = offset_size; 107426403871SSimon Glass 107526403871SSimon Glass return 0; 107626403871SSimon Glass } 1077b45122fdSSimon Glass 107812e67114SSimon Glass static int decode_timing_property(const void *blob, int node, const char *name, 107912e67114SSimon Glass struct timing_entry *result) 108012e67114SSimon Glass { 108112e67114SSimon Glass int length, ret = 0; 108212e67114SSimon Glass const u32 *prop; 108312e67114SSimon Glass 108412e67114SSimon Glass prop = fdt_getprop(blob, node, name, &length); 108512e67114SSimon Glass if (!prop) { 108612e67114SSimon Glass debug("%s: could not find property %s\n", 108712e67114SSimon Glass fdt_get_name(blob, node, NULL), name); 108812e67114SSimon Glass return length; 108912e67114SSimon Glass } 109012e67114SSimon Glass 109112e67114SSimon Glass if (length == sizeof(u32)) { 109212e67114SSimon Glass result->typ = fdtdec_get_int(blob, node, name, 0); 109312e67114SSimon Glass result->min = result->typ; 109412e67114SSimon Glass result->max = result->typ; 109512e67114SSimon Glass } else { 109612e67114SSimon Glass ret = fdtdec_get_int_array(blob, node, name, &result->min, 3); 109712e67114SSimon Glass } 109812e67114SSimon Glass 109912e67114SSimon Glass return ret; 110012e67114SSimon Glass } 110112e67114SSimon Glass 110212e67114SSimon Glass int fdtdec_decode_display_timing(const void *blob, int parent, int index, 110312e67114SSimon Glass struct display_timing *dt) 110412e67114SSimon Glass { 110512e67114SSimon Glass int i, node, timings_node; 110612e67114SSimon Glass u32 val = 0; 110712e67114SSimon Glass int ret = 0; 110812e67114SSimon Glass 110912e67114SSimon Glass timings_node = fdt_subnode_offset(blob, parent, "display-timings"); 111012e67114SSimon Glass if (timings_node < 0) 111112e67114SSimon Glass return timings_node; 111212e67114SSimon Glass 111312e67114SSimon Glass for (i = 0, node = fdt_first_subnode(blob, timings_node); 111412e67114SSimon Glass node > 0 && i != index; 111512e67114SSimon Glass node = fdt_next_subnode(blob, node)) 111612e67114SSimon Glass i++; 111712e67114SSimon Glass 111812e67114SSimon Glass if (node < 0) 111912e67114SSimon Glass return node; 112012e67114SSimon Glass 112112e67114SSimon Glass memset(dt, 0, sizeof(*dt)); 112212e67114SSimon Glass 112312e67114SSimon Glass ret |= decode_timing_property(blob, node, "hback-porch", 112412e67114SSimon Glass &dt->hback_porch); 112512e67114SSimon Glass ret |= decode_timing_property(blob, node, "hfront-porch", 112612e67114SSimon Glass &dt->hfront_porch); 112712e67114SSimon Glass ret |= decode_timing_property(blob, node, "hactive", &dt->hactive); 112812e67114SSimon Glass ret |= decode_timing_property(blob, node, "hsync-len", &dt->hsync_len); 112912e67114SSimon Glass ret |= decode_timing_property(blob, node, "vback-porch", 113012e67114SSimon Glass &dt->vback_porch); 113112e67114SSimon Glass ret |= decode_timing_property(blob, node, "vfront-porch", 113212e67114SSimon Glass &dt->vfront_porch); 113312e67114SSimon Glass ret |= decode_timing_property(blob, node, "vactive", &dt->vactive); 113412e67114SSimon Glass ret |= decode_timing_property(blob, node, "vsync-len", &dt->vsync_len); 113512e67114SSimon Glass ret |= decode_timing_property(blob, node, "clock-frequency", 113612e67114SSimon Glass &dt->pixelclock); 113712e67114SSimon Glass 113812e67114SSimon Glass dt->flags = 0; 113912e67114SSimon Glass val = fdtdec_get_int(blob, node, "vsync-active", -1); 114012e67114SSimon Glass if (val != -1) { 114112e67114SSimon Glass dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH : 114212e67114SSimon Glass DISPLAY_FLAGS_VSYNC_LOW; 114312e67114SSimon Glass } 114412e67114SSimon Glass val = fdtdec_get_int(blob, node, "hsync-active", -1); 114512e67114SSimon Glass if (val != -1) { 114612e67114SSimon Glass dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH : 114712e67114SSimon Glass DISPLAY_FLAGS_HSYNC_LOW; 114812e67114SSimon Glass } 114912e67114SSimon Glass val = fdtdec_get_int(blob, node, "de-active", -1); 115012e67114SSimon Glass if (val != -1) { 115112e67114SSimon Glass dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH : 115212e67114SSimon Glass DISPLAY_FLAGS_DE_LOW; 115312e67114SSimon Glass } 115412e67114SSimon Glass val = fdtdec_get_int(blob, node, "pixelclk-active", -1); 115512e67114SSimon Glass if (val != -1) { 115612e67114SSimon Glass dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE : 115712e67114SSimon Glass DISPLAY_FLAGS_PIXDATA_NEGEDGE; 115812e67114SSimon Glass } 115912e67114SSimon Glass 116012e67114SSimon Glass if (fdtdec_get_bool(blob, node, "interlaced")) 116112e67114SSimon Glass dt->flags |= DISPLAY_FLAGS_INTERLACED; 116212e67114SSimon Glass if (fdtdec_get_bool(blob, node, "doublescan")) 116312e67114SSimon Glass dt->flags |= DISPLAY_FLAGS_DOUBLESCAN; 116412e67114SSimon Glass if (fdtdec_get_bool(blob, node, "doubleclk")) 116512e67114SSimon Glass dt->flags |= DISPLAY_FLAGS_DOUBLECLK; 116612e67114SSimon Glass 116704b9dd10SSimon Glass return ret; 116812e67114SSimon Glass } 116912e67114SSimon Glass 11700879361fSSimon Glass int fdtdec_setup(void) 1171b45122fdSSimon Glass { 11720f925822SMasahiro Yamada #if CONFIG_IS_ENABLED(OF_CONTROL) 1173b45122fdSSimon Glass # ifdef CONFIG_OF_EMBED 1174b45122fdSSimon Glass /* Get a pointer to the FDT */ 1175b45122fdSSimon Glass gd->fdt_blob = __dtb_dt_begin; 1176b45122fdSSimon Glass # elif defined CONFIG_OF_SEPARATE 1177b45122fdSSimon Glass # ifdef CONFIG_SPL_BUILD 117810172962SSimon Glass /* FDT is at end of BSS unless it is in a different memory region */ 117910172962SSimon Glass if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) 118010172962SSimon Glass gd->fdt_blob = (ulong *)&_image_binary_end; 118110172962SSimon Glass else 1182b45122fdSSimon Glass gd->fdt_blob = (ulong *)&__bss_end; 1183b45122fdSSimon Glass # else 1184b45122fdSSimon Glass /* FDT is at end of image */ 1185b45122fdSSimon Glass gd->fdt_blob = (ulong *)&_end; 118629a23f9dSHeiko Schocher # endif 1187b45122fdSSimon Glass # elif defined(CONFIG_OF_HOSTFILE) 1188b45122fdSSimon Glass if (sandbox_read_fdt_from_file()) { 1189b45122fdSSimon Glass puts("Failed to read control FDT\n"); 1190b45122fdSSimon Glass return -1; 1191b45122fdSSimon Glass } 1192b45122fdSSimon Glass # endif 1193b45122fdSSimon Glass # ifndef CONFIG_SPL_BUILD 1194b45122fdSSimon Glass /* Allow the early environment to override the fdt address */ 1195b45122fdSSimon Glass gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16, 1196b45122fdSSimon Glass (uintptr_t)gd->fdt_blob); 1197b45122fdSSimon Glass # endif 1198b45122fdSSimon Glass #endif 11990879361fSSimon Glass return fdtdec_prepare_fdt(); 1200b45122fdSSimon Glass } 1201b45122fdSSimon Glass 1202b45122fdSSimon Glass #endif /* !USE_HOSTCC */ 1203