fdtdec.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * SPDX-License-Identifier: GPL-2.0+
  4. */
  5. #ifndef USE_HOSTCC
  6. #include <common.h>
  7. #include <errno.h>
  8. #include <serial.h>
  9. #include <libfdt.h>
  10. #include <fdtdec.h>
  11. #include <asm/sections.h>
  12. #include <linux/ctype.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /*
  15. * Here are the type we know about. One day we might allow drivers to
  16. * register. For now we just put them here. The COMPAT macro allows us to
  17. * turn this into a sparse list later, and keeps the ID with the name.
  18. */
  19. #define COMPAT(id, name) name
  20. static const char * const compat_names[COMPAT_COUNT] = {
  21. COMPAT(UNKNOWN, "<none>"),
  22. COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
  23. COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
  24. COMPAT(NVIDIA_TEGRA20_KBC, "nvidia,tegra20-kbc"),
  25. COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
  26. COMPAT(NVIDIA_TEGRA20_PWM, "nvidia,tegra20-pwm"),
  27. COMPAT(NVIDIA_TEGRA124_DC, "nvidia,tegra124-dc"),
  28. COMPAT(NVIDIA_TEGRA124_SOR, "nvidia,tegra124-sor"),
  29. COMPAT(NVIDIA_TEGRA124_PMC, "nvidia,tegra124-pmc"),
  30. COMPAT(NVIDIA_TEGRA20_DC, "nvidia,tegra20-dc"),
  31. COMPAT(NVIDIA_TEGRA210_SDMMC, "nvidia,tegra210-sdhci"),
  32. COMPAT(NVIDIA_TEGRA124_SDMMC, "nvidia,tegra124-sdhci"),
  33. COMPAT(NVIDIA_TEGRA30_SDMMC, "nvidia,tegra30-sdhci"),
  34. COMPAT(NVIDIA_TEGRA20_SDMMC, "nvidia,tegra20-sdhci"),
  35. COMPAT(NVIDIA_TEGRA124_PCIE, "nvidia,tegra124-pcie"),
  36. COMPAT(NVIDIA_TEGRA30_PCIE, "nvidia,tegra30-pcie"),
  37. COMPAT(NVIDIA_TEGRA20_PCIE, "nvidia,tegra20-pcie"),
  38. COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"),
  39. COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"),
  40. COMPAT(SMSC_LAN9215, "smsc,lan9215"),
  41. COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"),
  42. COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"),
  43. COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"),
  44. COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"),
  45. COMPAT(GOOGLE_CROS_EC_KEYB, "google,cros-ec-keyb"),
  46. COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
  47. COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"),
  48. COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"),
  49. COMPAT(SAMSUNG_EXYNOS_FIMD, "samsung,exynos-fimd"),
  50. COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"),
  51. COMPAT(SAMSUNG_EXYNOS5_DP, "samsung,exynos5-dp"),
  52. COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"),
  53. COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"),
  54. COMPAT(SAMSUNG_EXYNOS_SERIAL, "samsung,exynos4210-uart"),
  55. COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686"),
  56. COMPAT(GENERIC_SPI_FLASH, "spi-flash"),
  57. COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"),
  58. COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"),
  59. COMPAT(SANDBOX_LCD_SDL, "sandbox,lcd-sdl"),
  60. COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"),
  61. COMPAT(INTEL_MICROCODE, "intel,microcode"),
  62. COMPAT(MEMORY_SPD, "memory-spd"),
  63. COMPAT(INTEL_PANTHERPOINT_AHCI, "intel,pantherpoint-ahci"),
  64. COMPAT(INTEL_MODEL_206AX, "intel,model-206ax"),
  65. COMPAT(INTEL_GMA, "intel,gma"),
  66. COMPAT(AMS_AS3722, "ams,as3722"),
  67. COMPAT(INTEL_ICH_SPI, "intel,ich-spi"),
  68. COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"),
  69. COMPAT(INTEL_X86_PINCTRL, "intel,x86-pinctrl"),
  70. COMPAT(SOCIONEXT_XHCI, "socionext,uniphier-xhci"),
  71. COMPAT(COMPAT_INTEL_PCH, "intel,bd82x6x"),
  72. COMPAT(COMPAT_INTEL_IRQ_ROUTER, "intel,irq-router"),
  73. COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"),
  74. COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"),
  75. COMPAT(COMPAT_INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"),
  76. COMPAT(COMPAT_INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"),
  77. };
  78. const char *fdtdec_get_compatible(enum fdt_compat_id id)
  79. {
  80. /* We allow reading of the 'unknown' ID for testing purposes */
  81. assert(id >= 0 && id < COMPAT_COUNT);
  82. return compat_names[id];
  83. }
  84. fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
  85. const char *prop_name, int index, int na, int ns,
  86. fdt_size_t *sizep)
  87. {
  88. const fdt32_t *prop, *prop_end;
  89. const fdt32_t *prop_addr, *prop_size, *prop_after_size;
  90. int len;
  91. fdt_addr_t addr;
  92. debug("%s: %s: ", __func__, prop_name);
  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. if (ns > (sizeof(fdt_size_t) / sizeof(fdt32_t))) {
  98. debug("(ns too large for fdt_size_t type)\n");
  99. return FDT_ADDR_T_NONE;
  100. }
  101. prop = fdt_getprop(blob, node, prop_name, &len);
  102. if (!prop) {
  103. debug("(not found)\n");
  104. return FDT_ADDR_T_NONE;
  105. }
  106. prop_end = prop + (len / sizeof(*prop));
  107. prop_addr = prop + (index * (na + ns));
  108. prop_size = prop_addr + na;
  109. prop_after_size = prop_size + ns;
  110. if (prop_after_size > prop_end) {
  111. debug("(not enough data: expected >= %d cells, got %d cells)\n",
  112. (u32)(prop_after_size - prop), ((u32)(prop_end - prop)));
  113. return FDT_ADDR_T_NONE;
  114. }
  115. addr = fdtdec_get_number(prop_addr, na);
  116. if (sizep) {
  117. *sizep = fdtdec_get_number(prop_size, ns);
  118. debug("addr=%08llx, size=%llx\n", (u64)addr, (u64)*sizep);
  119. } else {
  120. debug("addr=%08llx\n", (u64)addr);
  121. }
  122. return addr;
  123. }
  124. fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
  125. int node, const char *prop_name, int index, fdt_size_t *sizep)
  126. {
  127. int na, ns;
  128. debug("%s: ", __func__);
  129. na = fdt_address_cells(blob, parent);
  130. if (na < 1) {
  131. debug("(bad #address-cells)\n");
  132. return FDT_ADDR_T_NONE;
  133. }
  134. ns = fdt_size_cells(blob, parent);
  135. if (ns < 0) {
  136. debug("(bad #size-cells)\n");
  137. return FDT_ADDR_T_NONE;
  138. }
  139. debug("na=%d, ns=%d, ", na, ns);
  140. return fdtdec_get_addr_size_fixed(blob, node, prop_name, index, na,
  141. ns, sizep);
  142. }
  143. fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
  144. const char *prop_name, int index, fdt_size_t *sizep)
  145. {
  146. int parent;
  147. debug("%s: ", __func__);
  148. parent = fdt_parent_offset(blob, node);
  149. if (parent < 0) {
  150. debug("(no parent found)\n");
  151. return FDT_ADDR_T_NONE;
  152. }
  153. return fdtdec_get_addr_size_auto_parent(blob, parent, node, prop_name,
  154. index, sizep);
  155. }
  156. fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
  157. const char *prop_name, fdt_size_t *sizep)
  158. {
  159. int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0;
  160. return fdtdec_get_addr_size_fixed(blob, node, prop_name, 0,
  161. sizeof(fdt_addr_t) / sizeof(fdt32_t),
  162. ns, sizep);
  163. }
  164. fdt_addr_t fdtdec_get_addr(const void *blob, int node,
  165. const char *prop_name)
  166. {
  167. return fdtdec_get_addr_size(blob, node, prop_name, NULL);
  168. }
  169. #ifdef CONFIG_PCI
  170. int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
  171. const char *prop_name, struct fdt_pci_addr *addr)
  172. {
  173. const u32 *cell;
  174. int len;
  175. int ret = -ENOENT;
  176. debug("%s: %s: ", __func__, prop_name);
  177. /*
  178. * If we follow the pci bus bindings strictly, we should check
  179. * the value of the node's parent node's #address-cells and
  180. * #size-cells. They need to be 3 and 2 accordingly. However,
  181. * for simplicity we skip the check here.
  182. */
  183. cell = fdt_getprop(blob, node, prop_name, &len);
  184. if (!cell)
  185. goto fail;
  186. if ((len % FDT_PCI_REG_SIZE) == 0) {
  187. int num = len / FDT_PCI_REG_SIZE;
  188. int i;
  189. for (i = 0; i < num; i++) {
  190. debug("pci address #%d: %08lx %08lx %08lx\n", i,
  191. (ulong)fdt32_to_cpu(cell[0]),
  192. (ulong)fdt32_to_cpu(cell[1]),
  193. (ulong)fdt32_to_cpu(cell[2]));
  194. if ((fdt32_to_cpu(*cell) & type) == type) {
  195. addr->phys_hi = fdt32_to_cpu(cell[0]);
  196. addr->phys_mid = fdt32_to_cpu(cell[1]);
  197. addr->phys_lo = fdt32_to_cpu(cell[1]);
  198. break;
  199. } else {
  200. cell += (FDT_PCI_ADDR_CELLS +
  201. FDT_PCI_SIZE_CELLS);
  202. }
  203. }
  204. if (i == num) {
  205. ret = -ENXIO;
  206. goto fail;
  207. }
  208. return 0;
  209. } else {
  210. ret = -EINVAL;
  211. }
  212. fail:
  213. debug("(not found)\n");
  214. return ret;
  215. }
  216. int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
  217. {
  218. const char *list, *end;
  219. int len;
  220. list = fdt_getprop(blob, node, "compatible", &len);
  221. if (!list)
  222. return -ENOENT;
  223. end = list + len;
  224. while (list < end) {
  225. char *s;
  226. len = strlen(list);
  227. if (len >= strlen("pciVVVV,DDDD")) {
  228. s = strstr(list, "pci");
  229. /*
  230. * check if the string is something like pciVVVV,DDDD.RR
  231. * or just pciVVVV,DDDD
  232. */
  233. if (s && s[7] == ',' &&
  234. (s[12] == '.' || s[12] == 0)) {
  235. s += 3;
  236. *vendor = simple_strtol(s, NULL, 16);
  237. s += 5;
  238. *device = simple_strtol(s, NULL, 16);
  239. return 0;
  240. }
  241. }
  242. list += (len + 1);
  243. }
  244. return -ENOENT;
  245. }
  246. int fdtdec_get_pci_bdf(const void *blob, int node,
  247. struct fdt_pci_addr *addr, pci_dev_t *bdf)
  248. {
  249. u16 dt_vendor, dt_device, vendor, device;
  250. int ret;
  251. /* get vendor id & device id from the compatible string */
  252. ret = fdtdec_get_pci_vendev(blob, node, &dt_vendor, &dt_device);
  253. if (ret)
  254. return ret;
  255. /* extract the bdf from fdt_pci_addr */
  256. *bdf = addr->phys_hi & 0xffff00;
  257. /* read vendor id & device id based on bdf */
  258. pci_read_config_word(*bdf, PCI_VENDOR_ID, &vendor);
  259. pci_read_config_word(*bdf, PCI_DEVICE_ID, &device);
  260. /*
  261. * Note there are two places in the device tree to fully describe
  262. * a pci device: one is via compatible string with a format of
  263. * "pciVVVV,DDDD" and the other one is the bdf numbers encoded in
  264. * the device node's reg address property. We read the vendor id
  265. * and device id based on bdf and compare the values with the
  266. * "VVVV,DDDD". If they are the same, then we are good to use bdf
  267. * to read device's bar. But if they are different, we have to rely
  268. * on the vendor id and device id extracted from the compatible
  269. * string and locate the real bdf by pci_find_device(). This is
  270. * because normally we may only know device's device number and
  271. * function number when writing device tree. The bus number is
  272. * dynamically assigned during the pci enumeration process.
  273. */
  274. if ((dt_vendor != vendor) || (dt_device != device)) {
  275. *bdf = pci_find_device(dt_vendor, dt_device, 0);
  276. if (*bdf == -1)
  277. return -ENODEV;
  278. }
  279. return 0;
  280. }
  281. int fdtdec_get_pci_bar32(const void *blob, int node,
  282. struct fdt_pci_addr *addr, u32 *bar)
  283. {
  284. pci_dev_t bdf;
  285. int barnum;
  286. int ret;
  287. /* get pci devices's bdf */
  288. ret = fdtdec_get_pci_bdf(blob, node, addr, &bdf);
  289. if (ret)
  290. return ret;
  291. /* extract the bar number from fdt_pci_addr */
  292. barnum = addr->phys_hi & 0xff;
  293. if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS))
  294. return -EINVAL;
  295. barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
  296. *bar = pci_read_bar32(pci_bus_to_hose(PCI_BUS(bdf)), bdf, barnum);
  297. return 0;
  298. }
  299. #endif
  300. uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
  301. uint64_t default_val)
  302. {
  303. const uint64_t *cell64;
  304. int length;
  305. cell64 = fdt_getprop(blob, node, prop_name, &length);
  306. if (!cell64 || length < sizeof(*cell64))
  307. return default_val;
  308. return fdt64_to_cpu(*cell64);
  309. }
  310. int fdtdec_get_is_enabled(const void *blob, int node)
  311. {
  312. const char *cell;
  313. /*
  314. * It should say "okay", so only allow that. Some fdts use "ok" but
  315. * this is a bug. Please fix your device tree source file. See here
  316. * for discussion:
  317. *
  318. * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html
  319. */
  320. cell = fdt_getprop(blob, node, "status", NULL);
  321. if (cell)
  322. return 0 == strcmp(cell, "okay");
  323. return 1;
  324. }
  325. enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
  326. {
  327. enum fdt_compat_id id;
  328. /* Search our drivers */
  329. for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++)
  330. if (0 == fdt_node_check_compatible(blob, node,
  331. compat_names[id]))
  332. return id;
  333. return COMPAT_UNKNOWN;
  334. }
  335. int fdtdec_next_compatible(const void *blob, int node,
  336. enum fdt_compat_id id)
  337. {
  338. return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
  339. }
  340. int fdtdec_next_compatible_subnode(const void *blob, int node,
  341. enum fdt_compat_id id, int *depthp)
  342. {
  343. do {
  344. node = fdt_next_node(blob, node, depthp);
  345. } while (*depthp > 1);
  346. /* If this is a direct subnode, and compatible, return it */
  347. if (*depthp == 1 && 0 == fdt_node_check_compatible(
  348. blob, node, compat_names[id]))
  349. return node;
  350. return -FDT_ERR_NOTFOUND;
  351. }
  352. int fdtdec_next_alias(const void *blob, const char *name,
  353. enum fdt_compat_id id, int *upto)
  354. {
  355. #define MAX_STR_LEN 20
  356. char str[MAX_STR_LEN + 20];
  357. int node, err;
  358. /* snprintf() is not available */
  359. assert(strlen(name) < MAX_STR_LEN);
  360. sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto);
  361. node = fdt_path_offset(blob, str);
  362. if (node < 0)
  363. return node;
  364. err = fdt_node_check_compatible(blob, node, compat_names[id]);
  365. if (err < 0)
  366. return err;
  367. if (err)
  368. return -FDT_ERR_NOTFOUND;
  369. (*upto)++;
  370. return node;
  371. }
  372. int fdtdec_find_aliases_for_id(const void *blob, const char *name,
  373. enum fdt_compat_id id, int *node_list, int maxcount)
  374. {
  375. memset(node_list, '\0', sizeof(*node_list) * maxcount);
  376. return fdtdec_add_aliases_for_id(blob, name, id, node_list, maxcount);
  377. }
  378. /* TODO: Can we tighten this code up a little? */
  379. int fdtdec_add_aliases_for_id(const void *blob, const char *name,
  380. enum fdt_compat_id id, int *node_list, int maxcount)
  381. {
  382. int name_len = strlen(name);
  383. int nodes[maxcount];
  384. int num_found = 0;
  385. int offset, node;
  386. int alias_node;
  387. int count;
  388. int i, j;
  389. /* find the alias node if present */
  390. alias_node = fdt_path_offset(blob, "/aliases");
  391. /*
  392. * start with nothing, and we can assume that the root node can't
  393. * match
  394. */
  395. memset(nodes, '\0', sizeof(nodes));
  396. /* First find all the compatible nodes */
  397. for (node = count = 0; node >= 0 && count < maxcount;) {
  398. node = fdtdec_next_compatible(blob, node, id);
  399. if (node >= 0)
  400. nodes[count++] = node;
  401. }
  402. if (node >= 0)
  403. debug("%s: warning: maxcount exceeded with alias '%s'\n",
  404. __func__, name);
  405. /* Now find all the aliases */
  406. for (offset = fdt_first_property_offset(blob, alias_node);
  407. offset > 0;
  408. offset = fdt_next_property_offset(blob, offset)) {
  409. const struct fdt_property *prop;
  410. const char *path;
  411. int number;
  412. int found;
  413. node = 0;
  414. prop = fdt_get_property_by_offset(blob, offset, NULL);
  415. path = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
  416. if (prop->len && 0 == strncmp(path, name, name_len))
  417. node = fdt_path_offset(blob, prop->data);
  418. if (node <= 0)
  419. continue;
  420. /* Get the alias number */
  421. number = simple_strtoul(path + name_len, NULL, 10);
  422. if (number < 0 || number >= maxcount) {
  423. debug("%s: warning: alias '%s' is out of range\n",
  424. __func__, path);
  425. continue;
  426. }
  427. /* Make sure the node we found is actually in our list! */
  428. found = -1;
  429. for (j = 0; j < count; j++)
  430. if (nodes[j] == node) {
  431. found = j;
  432. break;
  433. }
  434. if (found == -1) {
  435. debug("%s: warning: alias '%s' points to a node "
  436. "'%s' that is missing or is not compatible "
  437. " with '%s'\n", __func__, path,
  438. fdt_get_name(blob, node, NULL),
  439. compat_names[id]);
  440. continue;
  441. }
  442. /*
  443. * Add this node to our list in the right place, and mark
  444. * it as done.
  445. */
  446. if (fdtdec_get_is_enabled(blob, node)) {
  447. if (node_list[number]) {
  448. debug("%s: warning: alias '%s' requires that "
  449. "a node be placed in the list in a "
  450. "position which is already filled by "
  451. "node '%s'\n", __func__, path,
  452. fdt_get_name(blob, node, NULL));
  453. continue;
  454. }
  455. node_list[number] = node;
  456. if (number >= num_found)
  457. num_found = number + 1;
  458. }
  459. nodes[found] = 0;
  460. }
  461. /* Add any nodes not mentioned by an alias */
  462. for (i = j = 0; i < maxcount; i++) {
  463. if (!node_list[i]) {
  464. for (; j < maxcount; j++)
  465. if (nodes[j] &&
  466. fdtdec_get_is_enabled(blob, nodes[j]))
  467. break;
  468. /* Have we run out of nodes to add? */
  469. if (j == maxcount)
  470. break;
  471. assert(!node_list[i]);
  472. node_list[i] = nodes[j++];
  473. if (i >= num_found)
  474. num_found = i + 1;
  475. }
  476. }
  477. return num_found;
  478. }
  479. int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
  480. int *seqp)
  481. {
  482. int base_len = strlen(base);
  483. const char *find_name;
  484. int find_namelen;
  485. int prop_offset;
  486. int aliases;
  487. find_name = fdt_get_name(blob, offset, &find_namelen);
  488. debug("Looking for '%s' at %d, name %s\n", base, offset, find_name);
  489. aliases = fdt_path_offset(blob, "/aliases");
  490. for (prop_offset = fdt_first_property_offset(blob, aliases);
  491. prop_offset > 0;
  492. prop_offset = fdt_next_property_offset(blob, prop_offset)) {
  493. const char *prop;
  494. const char *name;
  495. const char *slash;
  496. int len, val;
  497. prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
  498. debug(" - %s, %s\n", name, prop);
  499. if (len < find_namelen || *prop != '/' || prop[len - 1] ||
  500. strncmp(name, base, base_len))
  501. continue;
  502. slash = strrchr(prop, '/');
  503. if (strcmp(slash + 1, find_name))
  504. continue;
  505. val = trailing_strtol(name);
  506. if (val != -1) {
  507. *seqp = val;
  508. debug("Found seq %d\n", *seqp);
  509. return 0;
  510. }
  511. }
  512. debug("Not found\n");
  513. return -ENOENT;
  514. }
  515. const char *fdtdec_get_chosen_prop(const void *blob, const char *name)
  516. {
  517. int chosen_node;
  518. if (!blob)
  519. return NULL;
  520. chosen_node = fdt_path_offset(blob, "/chosen");
  521. return fdt_getprop(blob, chosen_node, name, NULL);
  522. }
  523. int fdtdec_get_chosen_node(const void *blob, const char *name)
  524. {
  525. const char *prop;
  526. prop = fdtdec_get_chosen_prop(blob, name);
  527. if (!prop)
  528. return -FDT_ERR_NOTFOUND;
  529. return fdt_path_offset(blob, prop);
  530. }
  531. int fdtdec_check_fdt(void)
  532. {
  533. /*
  534. * We must have an FDT, but we cannot panic() yet since the console
  535. * is not ready. So for now, just assert(). Boards which need an early
  536. * FDT (prior to console ready) will need to make their own
  537. * arrangements and do their own checks.
  538. */
  539. assert(!fdtdec_prepare_fdt());
  540. return 0;
  541. }
  542. /*
  543. * This function is a little odd in that it accesses global data. At some
  544. * point if the architecture board.c files merge this will make more sense.
  545. * Even now, it is common code.
  546. */
  547. int fdtdec_prepare_fdt(void)
  548. {
  549. if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) ||
  550. fdt_check_header(gd->fdt_blob)) {
  551. #ifdef CONFIG_SPL_BUILD
  552. puts("Missing DTB\n");
  553. #else
  554. 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");
  555. # ifdef DEBUG
  556. if (gd->fdt_blob) {
  557. printf("fdt_blob=%p\n", gd->fdt_blob);
  558. print_buffer((ulong)gd->fdt_blob, gd->fdt_blob, 4,
  559. 32, 0);
  560. }
  561. # endif
  562. #endif
  563. return -1;
  564. }
  565. return 0;
  566. }
  567. int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name)
  568. {
  569. const u32 *phandle;
  570. int lookup;
  571. debug("%s: %s\n", __func__, prop_name);
  572. phandle = fdt_getprop(blob, node, prop_name, NULL);
  573. if (!phandle)
  574. return -FDT_ERR_NOTFOUND;
  575. lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle));
  576. return lookup;
  577. }
  578. /**
  579. * Look up a property in a node and check that it has a minimum length.
  580. *
  581. * @param blob FDT blob
  582. * @param node node to examine
  583. * @param prop_name name of property to find
  584. * @param min_len minimum property length in bytes
  585. * @param err 0 if ok, or -FDT_ERR_NOTFOUND if the property is not
  586. found, or -FDT_ERR_BADLAYOUT if not enough data
  587. * @return pointer to cell, which is only valid if err == 0
  588. */
  589. static const void *get_prop_check_min_len(const void *blob, int node,
  590. const char *prop_name, int min_len, int *err)
  591. {
  592. const void *cell;
  593. int len;
  594. debug("%s: %s\n", __func__, prop_name);
  595. cell = fdt_getprop(blob, node, prop_name, &len);
  596. if (!cell)
  597. *err = -FDT_ERR_NOTFOUND;
  598. else if (len < min_len)
  599. *err = -FDT_ERR_BADLAYOUT;
  600. else
  601. *err = 0;
  602. return cell;
  603. }
  604. int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
  605. u32 *array, int count)
  606. {
  607. const u32 *cell;
  608. int i, err = 0;
  609. debug("%s: %s\n", __func__, prop_name);
  610. cell = get_prop_check_min_len(blob, node, prop_name,
  611. sizeof(u32) * count, &err);
  612. if (!err) {
  613. for (i = 0; i < count; i++)
  614. array[i] = fdt32_to_cpu(cell[i]);
  615. }
  616. return err;
  617. }
  618. int fdtdec_get_int_array_count(const void *blob, int node,
  619. const char *prop_name, u32 *array, int count)
  620. {
  621. const u32 *cell;
  622. int len, elems;
  623. int i;
  624. debug("%s: %s\n", __func__, prop_name);
  625. cell = fdt_getprop(blob, node, prop_name, &len);
  626. if (!cell)
  627. return -FDT_ERR_NOTFOUND;
  628. elems = len / sizeof(u32);
  629. if (count > elems)
  630. count = elems;
  631. for (i = 0; i < count; i++)
  632. array[i] = fdt32_to_cpu(cell[i]);
  633. return count;
  634. }
  635. const u32 *fdtdec_locate_array(const void *blob, int node,
  636. const char *prop_name, int count)
  637. {
  638. const u32 *cell;
  639. int err;
  640. cell = get_prop_check_min_len(blob, node, prop_name,
  641. sizeof(u32) * count, &err);
  642. return err ? NULL : cell;
  643. }
  644. int fdtdec_get_bool(const void *blob, int node, const char *prop_name)
  645. {
  646. const s32 *cell;
  647. int len;
  648. debug("%s: %s\n", __func__, prop_name);
  649. cell = fdt_getprop(blob, node, prop_name, &len);
  650. return cell != NULL;
  651. }
  652. int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
  653. const char *list_name,
  654. const char *cells_name,
  655. int cell_count, int index,
  656. struct fdtdec_phandle_args *out_args)
  657. {
  658. const __be32 *list, *list_end;
  659. int rc = 0, size, cur_index = 0;
  660. uint32_t count = 0;
  661. int node = -1;
  662. int phandle;
  663. /* Retrieve the phandle list property */
  664. list = fdt_getprop(blob, src_node, list_name, &size);
  665. if (!list)
  666. return -ENOENT;
  667. list_end = list + size / sizeof(*list);
  668. /* Loop over the phandles until all the requested entry is found */
  669. while (list < list_end) {
  670. rc = -EINVAL;
  671. count = 0;
  672. /*
  673. * If phandle is 0, then it is an empty entry with no
  674. * arguments. Skip forward to the next entry.
  675. */
  676. phandle = be32_to_cpup(list++);
  677. if (phandle) {
  678. /*
  679. * Find the provider node and parse the #*-cells
  680. * property to determine the argument length.
  681. *
  682. * This is not needed if the cell count is hard-coded
  683. * (i.e. cells_name not set, but cell_count is set),
  684. * except when we're going to return the found node
  685. * below.
  686. */
  687. if (cells_name || cur_index == index) {
  688. node = fdt_node_offset_by_phandle(blob,
  689. phandle);
  690. if (!node) {
  691. debug("%s: could not find phandle\n",
  692. fdt_get_name(blob, src_node,
  693. NULL));
  694. goto err;
  695. }
  696. }
  697. if (cells_name) {
  698. count = fdtdec_get_int(blob, node, cells_name,
  699. -1);
  700. if (count == -1) {
  701. debug("%s: could not get %s for %s\n",
  702. fdt_get_name(blob, src_node,
  703. NULL),
  704. cells_name,
  705. fdt_get_name(blob, node,
  706. NULL));
  707. goto err;
  708. }
  709. } else {
  710. count = cell_count;
  711. }
  712. /*
  713. * Make sure that the arguments actually fit in the
  714. * remaining property data length
  715. */
  716. if (list + count > list_end) {
  717. debug("%s: arguments longer than property\n",
  718. fdt_get_name(blob, src_node, NULL));
  719. goto err;
  720. }
  721. }
  722. /*
  723. * All of the error cases above bail out of the loop, so at
  724. * this point, the parsing is successful. If the requested
  725. * index matches, then fill the out_args structure and return,
  726. * or return -ENOENT for an empty entry.
  727. */
  728. rc = -ENOENT;
  729. if (cur_index == index) {
  730. if (!phandle)
  731. goto err;
  732. if (out_args) {
  733. int i;
  734. if (count > MAX_PHANDLE_ARGS) {
  735. debug("%s: too many arguments %d\n",
  736. fdt_get_name(blob, src_node,
  737. NULL), count);
  738. count = MAX_PHANDLE_ARGS;
  739. }
  740. out_args->node = node;
  741. out_args->args_count = count;
  742. for (i = 0; i < count; i++) {
  743. out_args->args[i] =
  744. be32_to_cpup(list++);
  745. }
  746. }
  747. /* Found it! return success */
  748. return 0;
  749. }
  750. node = -1;
  751. list += count;
  752. cur_index++;
  753. }
  754. /*
  755. * Result will be one of:
  756. * -ENOENT : index is for empty phandle
  757. * -EINVAL : parsing error on data
  758. * [1..n] : Number of phandle (count mode; when index = -1)
  759. */
  760. rc = index < 0 ? cur_index : -ENOENT;
  761. err:
  762. return rc;
  763. }
  764. int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
  765. u8 *array, int count)
  766. {
  767. const u8 *cell;
  768. int err;
  769. cell = get_prop_check_min_len(blob, node, prop_name, count, &err);
  770. if (!err)
  771. memcpy(array, cell, count);
  772. return err;
  773. }
  774. const u8 *fdtdec_locate_byte_array(const void *blob, int node,
  775. const char *prop_name, int count)
  776. {
  777. const u8 *cell;
  778. int err;
  779. cell = get_prop_check_min_len(blob, node, prop_name, count, &err);
  780. if (err)
  781. return NULL;
  782. return cell;
  783. }
  784. int fdtdec_get_config_int(const void *blob, const char *prop_name,
  785. int default_val)
  786. {
  787. int config_node;
  788. debug("%s: %s\n", __func__, prop_name);
  789. config_node = fdt_path_offset(blob, "/config");
  790. if (config_node < 0)
  791. return default_val;
  792. return fdtdec_get_int(blob, config_node, prop_name, default_val);
  793. }
  794. int fdtdec_get_config_bool(const void *blob, const char *prop_name)
  795. {
  796. int config_node;
  797. const void *prop;
  798. debug("%s: %s\n", __func__, prop_name);
  799. config_node = fdt_path_offset(blob, "/config");
  800. if (config_node < 0)
  801. return 0;
  802. prop = fdt_get_property(blob, config_node, prop_name, NULL);
  803. return prop != NULL;
  804. }
  805. char *fdtdec_get_config_string(const void *blob, const char *prop_name)
  806. {
  807. const char *nodep;
  808. int nodeoffset;
  809. int len;
  810. debug("%s: %s\n", __func__, prop_name);
  811. nodeoffset = fdt_path_offset(blob, "/config");
  812. if (nodeoffset < 0)
  813. return NULL;
  814. nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
  815. if (!nodep)
  816. return NULL;
  817. return (char *)nodep;
  818. }
  819. int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
  820. fdt_addr_t *basep, fdt_size_t *sizep)
  821. {
  822. const fdt_addr_t *cell;
  823. int len;
  824. debug("%s: %s: %s\n", __func__, fdt_get_name(blob, node, NULL),
  825. prop_name);
  826. cell = fdt_getprop(blob, node, prop_name, &len);
  827. if (!cell || (len < sizeof(fdt_addr_t) * 2)) {
  828. debug("cell=%p, len=%d\n", cell, len);
  829. return -1;
  830. }
  831. *basep = fdt_addr_to_cpu(*cell);
  832. *sizep = fdt_size_to_cpu(cell[1]);
  833. debug("%s: base=%08lx, size=%lx\n", __func__, (ulong)*basep,
  834. (ulong)*sizep);
  835. return 0;
  836. }
  837. /**
  838. * Read a flash entry from the fdt
  839. *
  840. * @param blob FDT blob
  841. * @param node Offset of node to read
  842. * @param name Name of node being read
  843. * @param entry Place to put offset and size of this node
  844. * @return 0 if ok, -ve on error
  845. */
  846. int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
  847. struct fmap_entry *entry)
  848. {
  849. const char *prop;
  850. u32 reg[2];
  851. if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
  852. debug("Node '%s' has bad/missing 'reg' property\n", name);
  853. return -FDT_ERR_NOTFOUND;
  854. }
  855. entry->offset = reg[0];
  856. entry->length = reg[1];
  857. entry->used = fdtdec_get_int(blob, node, "used", entry->length);
  858. prop = fdt_getprop(blob, node, "compress", NULL);
  859. entry->compress_algo = prop && !strcmp(prop, "lzo") ?
  860. FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE;
  861. prop = fdt_getprop(blob, node, "hash", &entry->hash_size);
  862. entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
  863. entry->hash = (uint8_t *)prop;
  864. return 0;
  865. }
  866. u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
  867. {
  868. u64 number = 0;
  869. while (cells--)
  870. number = (number << 32) | fdt32_to_cpu(*ptr++);
  871. return number;
  872. }
  873. int fdt_get_resource(const void *fdt, int node, const char *property,
  874. unsigned int index, struct fdt_resource *res)
  875. {
  876. const fdt32_t *ptr, *end;
  877. int na, ns, len, parent;
  878. unsigned int i = 0;
  879. parent = fdt_parent_offset(fdt, node);
  880. if (parent < 0)
  881. return parent;
  882. na = fdt_address_cells(fdt, parent);
  883. ns = fdt_size_cells(fdt, parent);
  884. ptr = fdt_getprop(fdt, node, property, &len);
  885. if (!ptr)
  886. return len;
  887. end = ptr + len / sizeof(*ptr);
  888. while (ptr + na + ns <= end) {
  889. if (i == index) {
  890. res->start = res->end = fdtdec_get_number(ptr, na);
  891. res->end += fdtdec_get_number(&ptr[na], ns) - 1;
  892. return 0;
  893. }
  894. ptr += na + ns;
  895. i++;
  896. }
  897. return -FDT_ERR_NOTFOUND;
  898. }
  899. int fdt_get_named_resource(const void *fdt, int node, const char *property,
  900. const char *prop_names, const char *name,
  901. struct fdt_resource *res)
  902. {
  903. int index;
  904. index = fdt_find_string(fdt, node, prop_names, name);
  905. if (index < 0)
  906. return index;
  907. return fdt_get_resource(fdt, node, property, index, res);
  908. }
  909. int fdtdec_decode_memory_region(const void *blob, int config_node,
  910. const char *mem_type, const char *suffix,
  911. fdt_addr_t *basep, fdt_size_t *sizep)
  912. {
  913. char prop_name[50];
  914. const char *mem;
  915. fdt_size_t size, offset_size;
  916. fdt_addr_t base, offset;
  917. int node;
  918. if (config_node == -1) {
  919. config_node = fdt_path_offset(blob, "/config");
  920. if (config_node < 0) {
  921. debug("%s: Cannot find /config node\n", __func__);
  922. return -ENOENT;
  923. }
  924. }
  925. if (!suffix)
  926. suffix = "";
  927. snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type,
  928. suffix);
  929. mem = fdt_getprop(blob, config_node, prop_name, NULL);
  930. if (!mem) {
  931. debug("%s: No memory type for '%s', using /memory\n", __func__,
  932. prop_name);
  933. mem = "/memory";
  934. }
  935. node = fdt_path_offset(blob, mem);
  936. if (node < 0) {
  937. debug("%s: Failed to find node '%s': %s\n", __func__, mem,
  938. fdt_strerror(node));
  939. return -ENOENT;
  940. }
  941. /*
  942. * Not strictly correct - the memory may have multiple banks. We just
  943. * use the first
  944. */
  945. if (fdtdec_decode_region(blob, node, "reg", &base, &size)) {
  946. debug("%s: Failed to decode memory region %s\n", __func__,
  947. mem);
  948. return -EINVAL;
  949. }
  950. snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type,
  951. suffix);
  952. if (fdtdec_decode_region(blob, config_node, prop_name, &offset,
  953. &offset_size)) {
  954. debug("%s: Failed to decode memory region '%s'\n", __func__,
  955. prop_name);
  956. return -EINVAL;
  957. }
  958. *basep = base + offset;
  959. *sizep = offset_size;
  960. return 0;
  961. }
  962. static int decode_timing_property(const void *blob, int node, const char *name,
  963. struct timing_entry *result)
  964. {
  965. int length, ret = 0;
  966. const u32 *prop;
  967. prop = fdt_getprop(blob, node, name, &length);
  968. if (!prop) {
  969. debug("%s: could not find property %s\n",
  970. fdt_get_name(blob, node, NULL), name);
  971. return length;
  972. }
  973. if (length == sizeof(u32)) {
  974. result->typ = fdtdec_get_int(blob, node, name, 0);
  975. result->min = result->typ;
  976. result->max = result->typ;
  977. } else {
  978. ret = fdtdec_get_int_array(blob, node, name, &result->min, 3);
  979. }
  980. return ret;
  981. }
  982. int fdtdec_decode_display_timing(const void *blob, int parent, int index,
  983. struct display_timing *dt)
  984. {
  985. int i, node, timings_node;
  986. u32 val = 0;
  987. int ret = 0;
  988. timings_node = fdt_subnode_offset(blob, parent, "display-timings");
  989. if (timings_node < 0)
  990. return timings_node;
  991. for (i = 0, node = fdt_first_subnode(blob, timings_node);
  992. node > 0 && i != index;
  993. node = fdt_next_subnode(blob, node))
  994. i++;
  995. if (node < 0)
  996. return node;
  997. memset(dt, 0, sizeof(*dt));
  998. ret |= decode_timing_property(blob, node, "hback-porch",
  999. &dt->hback_porch);
  1000. ret |= decode_timing_property(blob, node, "hfront-porch",
  1001. &dt->hfront_porch);
  1002. ret |= decode_timing_property(blob, node, "hactive", &dt->hactive);
  1003. ret |= decode_timing_property(blob, node, "hsync-len", &dt->hsync_len);
  1004. ret |= decode_timing_property(blob, node, "vback-porch",
  1005. &dt->vback_porch);
  1006. ret |= decode_timing_property(blob, node, "vfront-porch",
  1007. &dt->vfront_porch);
  1008. ret |= decode_timing_property(blob, node, "vactive", &dt->vactive);
  1009. ret |= decode_timing_property(blob, node, "vsync-len", &dt->vsync_len);
  1010. ret |= decode_timing_property(blob, node, "clock-frequency",
  1011. &dt->pixelclock);
  1012. dt->flags = 0;
  1013. val = fdtdec_get_int(blob, node, "vsync-active", -1);
  1014. if (val != -1) {
  1015. dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH :
  1016. DISPLAY_FLAGS_VSYNC_LOW;
  1017. }
  1018. val = fdtdec_get_int(blob, node, "hsync-active", -1);
  1019. if (val != -1) {
  1020. dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH :
  1021. DISPLAY_FLAGS_HSYNC_LOW;
  1022. }
  1023. val = fdtdec_get_int(blob, node, "de-active", -1);
  1024. if (val != -1) {
  1025. dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH :
  1026. DISPLAY_FLAGS_DE_LOW;
  1027. }
  1028. val = fdtdec_get_int(blob, node, "pixelclk-active", -1);
  1029. if (val != -1) {
  1030. dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE :
  1031. DISPLAY_FLAGS_PIXDATA_NEGEDGE;
  1032. }
  1033. if (fdtdec_get_bool(blob, node, "interlaced"))
  1034. dt->flags |= DISPLAY_FLAGS_INTERLACED;
  1035. if (fdtdec_get_bool(blob, node, "doublescan"))
  1036. dt->flags |= DISPLAY_FLAGS_DOUBLESCAN;
  1037. if (fdtdec_get_bool(blob, node, "doubleclk"))
  1038. dt->flags |= DISPLAY_FLAGS_DOUBLECLK;
  1039. return 0;
  1040. }
  1041. int fdtdec_setup(void)
  1042. {
  1043. #if CONFIG_IS_ENABLED(OF_CONTROL)
  1044. # ifdef CONFIG_OF_EMBED
  1045. /* Get a pointer to the FDT */
  1046. gd->fdt_blob = __dtb_dt_begin;
  1047. # elif defined CONFIG_OF_SEPARATE
  1048. # ifdef CONFIG_SPL_BUILD
  1049. /* FDT is at end of BSS unless it is in a different memory region */
  1050. if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
  1051. gd->fdt_blob = (ulong *)&_image_binary_end;
  1052. else
  1053. gd->fdt_blob = (ulong *)&__bss_end;
  1054. # else
  1055. /* FDT is at end of image */
  1056. gd->fdt_blob = (ulong *)&_end;
  1057. # endif
  1058. # elif defined(CONFIG_OF_HOSTFILE)
  1059. if (sandbox_read_fdt_from_file()) {
  1060. puts("Failed to read control FDT\n");
  1061. return -1;
  1062. }
  1063. # endif
  1064. # ifndef CONFIG_SPL_BUILD
  1065. /* Allow the early environment to override the fdt address */
  1066. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  1067. (uintptr_t)gd->fdt_blob);
  1068. # endif
  1069. #endif
  1070. return fdtdec_prepare_fdt();
  1071. }
  1072. #endif /* !USE_HOSTCC */