libfdt.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. #ifndef _LIBFDT_H
  2. #define _LIBFDT_H
  3. /*
  4. * libfdt - Flat Device Tree manipulation
  5. * Copyright (C) 2006 David Gibson, IBM Corporation.
  6. *
  7. * libfdt is dual licensed: you can use it either under the terms of
  8. * the GPL, or the BSD license, at your option.
  9. *
  10. * a) This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this library; if not, write to the Free
  22. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  23. * MA 02110-1301 USA
  24. *
  25. * Alternatively,
  26. *
  27. * b) Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted provided that the following
  29. * conditions are met:
  30. *
  31. * 1. Redistributions of source code must retain the above
  32. * copyright notice, this list of conditions and the following
  33. * disclaimer.
  34. * 2. Redistributions in binary form must reproduce the above
  35. * copyright notice, this list of conditions and the following
  36. * disclaimer in the documentation and/or other materials
  37. * provided with the distribution.
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  40. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  41. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  42. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  43. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  44. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  45. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  46. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  47. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  49. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  50. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  51. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. */
  53. #include <libfdt_env.h>
  54. #include <fdt.h>
  55. #define FDT_FIRST_SUPPORTED_VERSION 0x10
  56. #define FDT_LAST_SUPPORTED_VERSION 0x11
  57. /* Error codes: informative error codes */
  58. #define FDT_ERR_NOTFOUND 1
  59. /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
  60. #define FDT_ERR_EXISTS 2
  61. /* FDT_ERR_EXISTS: Attemped to create a node or property which
  62. * already exists */
  63. #define FDT_ERR_NOSPACE 3
  64. /* FDT_ERR_NOSPACE: Operation needed to expand the device
  65. * tree, but its buffer did not have sufficient space to
  66. * contain the expanded tree. Use fdt_open_into() to move the
  67. * device tree to a buffer with more space. */
  68. /* Error codes: codes for bad parameters */
  69. #define FDT_ERR_BADOFFSET 4
  70. /* FDT_ERR_BADOFFSET: Function was passed a structure block
  71. * offset which is out-of-bounds, or which points to an
  72. * unsuitable part of the structure for the operation. */
  73. #define FDT_ERR_BADPATH 5
  74. /* FDT_ERR_BADPATH: Function was passed a badly formatted path
  75. * (e.g. missing a leading / for a function which requires an
  76. * absolute path) */
  77. #define FDT_ERR_BADPHANDLE 6
  78. /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
  79. * value. phandle values of 0 and -1 are not permitted. */
  80. #define FDT_ERR_BADSTATE 7
  81. /* FDT_ERR_BADSTATE: Function was passed an incomplete device
  82. * tree created by the sequential-write functions, which is
  83. * not sufficiently complete for the requested operation. */
  84. /* Error codes: codes for bad device tree blobs */
  85. #define FDT_ERR_TRUNCATED 8
  86. /* FDT_ERR_TRUNCATED: Structure block of the given device tree
  87. * ends without an FDT_END tag. */
  88. #define FDT_ERR_BADMAGIC 9
  89. /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
  90. * device tree at all - it is missing the flattened device
  91. * tree magic number. */
  92. #define FDT_ERR_BADVERSION 10
  93. /* FDT_ERR_BADVERSION: Given device tree has a version which
  94. * can't be handled by the requested operation. For
  95. * read-write functions, this may mean that fdt_open_into() is
  96. * required to convert the tree to the expected version. */
  97. #define FDT_ERR_BADSTRUCTURE 11
  98. /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
  99. * structure block or other serious error (e.g. misnested
  100. * nodes, or subnodes preceding properties). */
  101. #define FDT_ERR_BADLAYOUT 12
  102. /* FDT_ERR_BADLAYOUT: For read-write functions, the given
  103. * device tree has it's sub-blocks in an order that the
  104. * function can't handle (memory reserve map, then structure,
  105. * then strings). Use fdt_open_into() to reorganize the tree
  106. * into a form suitable for the read-write operations. */
  107. /* "Can't happen" error indicating a bug in libfdt */
  108. #define FDT_ERR_INTERNAL 13
  109. /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
  110. * Should never be returned, if it is, it indicates a bug in
  111. * libfdt itself. */
  112. #define FDT_ERR_MAX 13
  113. /**********************************************************************/
  114. /* Low-level functions (you probably don't need these) */
  115. /**********************************************************************/
  116. const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
  117. static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  118. {
  119. return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
  120. }
  121. uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
  122. /**********************************************************************/
  123. /* Traversal functions */
  124. /**********************************************************************/
  125. int fdt_next_node(const void *fdt, int offset, int *depth);
  126. /**********************************************************************/
  127. /* General functions */
  128. /**********************************************************************/
  129. #define fdt_get_header(fdt, field) \
  130. (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
  131. #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
  132. #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
  133. #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
  134. #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
  135. #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
  136. #define fdt_version(fdt) (fdt_get_header(fdt, version))
  137. #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
  138. #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
  139. #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
  140. #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
  141. #define __fdt_set_hdr(name) \
  142. static inline void fdt_set_##name(void *fdt, uint32_t val) \
  143. { \
  144. struct fdt_header *fdth = fdt; \
  145. fdth->name = cpu_to_fdt32(val); \
  146. }
  147. __fdt_set_hdr(magic);
  148. __fdt_set_hdr(totalsize);
  149. __fdt_set_hdr(off_dt_struct);
  150. __fdt_set_hdr(off_dt_strings);
  151. __fdt_set_hdr(off_mem_rsvmap);
  152. __fdt_set_hdr(version);
  153. __fdt_set_hdr(last_comp_version);
  154. __fdt_set_hdr(boot_cpuid_phys);
  155. __fdt_set_hdr(size_dt_strings);
  156. __fdt_set_hdr(size_dt_struct);
  157. #undef __fdt_set_hdr
  158. /**
  159. * fdt_check_header - sanity check a device tree or possible device tree
  160. * @fdt: pointer to data which might be a flattened device tree
  161. *
  162. * fdt_check_header() checks that the given buffer contains what
  163. * appears to be a flattened device tree with sane information in its
  164. * header.
  165. *
  166. * returns:
  167. * 0, if the buffer appears to contain a valid device tree
  168. * -FDT_ERR_BADMAGIC,
  169. * -FDT_ERR_BADVERSION,
  170. * -FDT_ERR_BADSTATE, standard meanings, as above
  171. */
  172. int fdt_check_header(const void *fdt);
  173. /**
  174. * fdt_move - move a device tree around in memory
  175. * @fdt: pointer to the device tree to move
  176. * @buf: pointer to memory where the device is to be moved
  177. * @bufsize: size of the memory space at buf
  178. *
  179. * fdt_move() relocates, if possible, the device tree blob located at
  180. * fdt to the buffer at buf of size bufsize. The buffer may overlap
  181. * with the existing device tree blob at fdt. Therefore,
  182. * fdt_move(fdt, fdt, fdt_totalsize(fdt))
  183. * should always succeed.
  184. *
  185. * returns:
  186. * 0, on success
  187. * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
  188. * -FDT_ERR_BADMAGIC,
  189. * -FDT_ERR_BADVERSION,
  190. * -FDT_ERR_BADSTATE, standard meanings
  191. */
  192. int fdt_move(const void *fdt, void *buf, int bufsize);
  193. /**********************************************************************/
  194. /* Read-only functions */
  195. /**********************************************************************/
  196. /**
  197. * fdt_string - retrieve a string from the strings block of a device tree
  198. * @fdt: pointer to the device tree blob
  199. * @stroffset: offset of the string within the strings block (native endian)
  200. *
  201. * fdt_string() retrieves a pointer to a single string from the
  202. * strings block of the device tree blob at fdt.
  203. *
  204. * returns:
  205. * a pointer to the string, on success
  206. * NULL, if stroffset is out of bounds
  207. */
  208. const char *fdt_string(const void *fdt, int stroffset);
  209. /**
  210. * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
  211. * @fdt: pointer to the device tree blob
  212. *
  213. * Returns the number of entries in the device tree blob's memory
  214. * reservation map. This does not include the terminating 0,0 entry
  215. * or any other (0,0) entries reserved for expansion.
  216. *
  217. * returns:
  218. * the number of entries
  219. */
  220. int fdt_num_mem_rsv(const void *fdt);
  221. /**
  222. * fdt_get_mem_rsv - retrieve one memory reserve map entry
  223. * @fdt: pointer to the device tree blob
  224. * @address, @size: pointers to 64-bit variables
  225. *
  226. * On success, *address and *size will contain the address and size of
  227. * the n-th reserve map entry from the device tree blob, in
  228. * native-endian format.
  229. *
  230. * returns:
  231. * 0, on success
  232. * -FDT_ERR_BADMAGIC,
  233. * -FDT_ERR_BADVERSION,
  234. * -FDT_ERR_BADSTATE, standard meanings
  235. */
  236. int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
  237. /**
  238. * fdt_subnode_offset_namelen - find a subnode based on substring
  239. * @fdt: pointer to the device tree blob
  240. * @parentoffset: structure block offset of a node
  241. * @name: name of the subnode to locate
  242. * @namelen: number of characters of name to consider
  243. *
  244. * Identical to fdt_subnode_offset(), but only examine the first
  245. * namelen characters of name for matching the subnode name. This is
  246. * useful for finding subnodes based on a portion of a larger string,
  247. * such as a full path.
  248. */
  249. int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
  250. const char *name, int namelen);
  251. /**
  252. * fdt_subnode_offset - find a subnode of a given node
  253. * @fdt: pointer to the device tree blob
  254. * @parentoffset: structure block offset of a node
  255. * @name: name of the subnode to locate
  256. *
  257. * fdt_subnode_offset() finds a subnode of the node at structure block
  258. * offset parentoffset with the given name. name may include a unit
  259. * address, in which case fdt_subnode_offset() will find the subnode
  260. * with that unit address, or the unit address may be omitted, in
  261. * which case fdt_subnode_offset() will find an arbitrary subnode
  262. * whose name excluding unit address matches the given name.
  263. *
  264. * returns:
  265. * structure block offset of the requested subnode (>=0), on success
  266. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  267. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  268. * -FDT_ERR_BADMAGIC,
  269. * -FDT_ERR_BADVERSION,
  270. * -FDT_ERR_BADSTATE,
  271. * -FDT_ERR_BADSTRUCTURE,
  272. * -FDT_ERR_TRUNCATED, standard meanings.
  273. */
  274. int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
  275. /**
  276. * fdt_path_offset - find a tree node by its full path
  277. * @fdt: pointer to the device tree blob
  278. * @path: full path of the node to locate
  279. *
  280. * fdt_path_offset() finds a node of a given path in the device tree.
  281. * Each path component may omit the unit address portion, but the
  282. * results of this are undefined if any such path component is
  283. * ambiguous (that is if there are multiple nodes at the relevant
  284. * level matching the given component, differentiated only by unit
  285. * address).
  286. *
  287. * returns:
  288. * structure block offset of the node with the requested path (>=0), on success
  289. * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
  290. * -FDT_ERR_NOTFOUND, if the requested node does not exist
  291. * -FDT_ERR_BADMAGIC,
  292. * -FDT_ERR_BADVERSION,
  293. * -FDT_ERR_BADSTATE,
  294. * -FDT_ERR_BADSTRUCTURE,
  295. * -FDT_ERR_TRUNCATED, standard meanings.
  296. */
  297. int fdt_path_offset(const void *fdt, const char *path);
  298. /**
  299. * fdt_get_name - retrieve the name of a given node
  300. * @fdt: pointer to the device tree blob
  301. * @nodeoffset: structure block offset of the starting node
  302. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  303. *
  304. * fdt_get_name() retrieves the name (including unit address) of the
  305. * device tree node at structure block offset nodeoffset. If lenp is
  306. * non-NULL, the length of this name is also returned, in the integer
  307. * pointed to by lenp.
  308. *
  309. * returns:
  310. * pointer to the node's name, on success
  311. * If lenp is non-NULL, *lenp contains the length of that name (>=0)
  312. * NULL, on error
  313. * if lenp is non-NULL *lenp contains an error code (<0):
  314. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  315. * -FDT_ERR_BADMAGIC,
  316. * -FDT_ERR_BADVERSION,
  317. * -FDT_ERR_BADSTATE, standard meanings
  318. */
  319. const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
  320. /**
  321. * fdt_get_property_namelen - find a property based on substring
  322. * @fdt: pointer to the device tree blob
  323. * @nodeoffset: offset of the node whose property to find
  324. * @name: name of the property to find
  325. * @namelen: number of characters of name to consider
  326. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  327. *
  328. * Identical to fdt_get_property_namelen(), but only examine the first
  329. * namelen characters of name for matching the property name.
  330. */
  331. const struct fdt_property *fdt_get_property_namelen(const void *fdt,
  332. int nodeoffset,
  333. const char *name,
  334. int namelen, int *lenp);
  335. /**
  336. * fdt_get_property - find a given property in a given node
  337. * @fdt: pointer to the device tree blob
  338. * @nodeoffset: offset of the node whose property to find
  339. * @name: name of the property to find
  340. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  341. *
  342. * fdt_get_property() retrieves a pointer to the fdt_property
  343. * structure within the device tree blob corresponding to the property
  344. * named 'name' of the node at offset nodeoffset. If lenp is
  345. * non-NULL, the length of the property value is also returned, in the
  346. * integer pointed to by lenp.
  347. *
  348. * returns:
  349. * pointer to the structure representing the property
  350. * if lenp is non-NULL, *lenp contains the length of the property
  351. * value (>=0)
  352. * NULL, on error
  353. * if lenp is non-NULL, *lenp contains an error code (<0):
  354. * -FDT_ERR_NOTFOUND, node does not have named property
  355. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  356. * -FDT_ERR_BADMAGIC,
  357. * -FDT_ERR_BADVERSION,
  358. * -FDT_ERR_BADSTATE,
  359. * -FDT_ERR_BADSTRUCTURE,
  360. * -FDT_ERR_TRUNCATED, standard meanings
  361. */
  362. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  363. const char *name, int *lenp);
  364. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  365. const char *name,
  366. int *lenp)
  367. {
  368. return (struct fdt_property *)(uintptr_t)
  369. fdt_get_property(fdt, nodeoffset, name, lenp);
  370. }
  371. /**
  372. * fdt_getprop_namelen - get property value based on substring
  373. * @fdt: pointer to the device tree blob
  374. * @nodeoffset: offset of the node whose property to find
  375. * @name: name of the property to find
  376. * @namelen: number of characters of name to consider
  377. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  378. *
  379. * Identical to fdt_getprop(), but only examine the first namelen
  380. * characters of name for matching the property name.
  381. */
  382. const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
  383. const char *name, int namelen, int *lenp);
  384. /**
  385. * fdt_getprop - retrieve the value of a given property
  386. * @fdt: pointer to the device tree blob
  387. * @nodeoffset: offset of the node whose property to find
  388. * @name: name of the property to find
  389. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  390. *
  391. * fdt_getprop() retrieves a pointer to the value of the property
  392. * named 'name' of the node at offset nodeoffset (this will be a
  393. * pointer to within the device blob itself, not a copy of the value).
  394. * If lenp is non-NULL, the length of the property value is also
  395. * returned, in the integer pointed to by lenp.
  396. *
  397. * returns:
  398. * pointer to the property's value
  399. * if lenp is non-NULL, *lenp contains the length of the property
  400. * value (>=0)
  401. * NULL, on error
  402. * if lenp is non-NULL, *lenp contains an error code (<0):
  403. * -FDT_ERR_NOTFOUND, node does not have named property
  404. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  405. * -FDT_ERR_BADMAGIC,
  406. * -FDT_ERR_BADVERSION,
  407. * -FDT_ERR_BADSTATE,
  408. * -FDT_ERR_BADSTRUCTURE,
  409. * -FDT_ERR_TRUNCATED, standard meanings
  410. */
  411. const void *fdt_getprop(const void *fdt, int nodeoffset,
  412. const char *name, int *lenp);
  413. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  414. const char *name, int *lenp)
  415. {
  416. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  417. }
  418. /**
  419. * fdt_get_phandle - retrieve the phandle of a given node
  420. * @fdt: pointer to the device tree blob
  421. * @nodeoffset: structure block offset of the node
  422. *
  423. * fdt_get_phandle() retrieves the phandle of the device tree node at
  424. * structure block offset nodeoffset.
  425. *
  426. * returns:
  427. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  428. * 0, if the node has no phandle, or another error occurs
  429. */
  430. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  431. /**
  432. * fdt_get_alias_namelen - get alias based on substring
  433. * @fdt: pointer to the device tree blob
  434. * @name: name of the alias th look up
  435. * @namelen: number of characters of name to consider
  436. *
  437. * Identical to fdt_get_alias(), but only examine the first namelen
  438. * characters of name for matching the alias name.
  439. */
  440. const char *fdt_get_alias_namelen(const void *fdt,
  441. const char *name, int namelen);
  442. /**
  443. * fdt_get_alias - retreive the path referenced by a given alias
  444. * @fdt: pointer to the device tree blob
  445. * @name: name of the alias th look up
  446. *
  447. * fdt_get_alias() retrieves the value of a given alias. That is, the
  448. * value of the property named 'name' in the node /aliases.
  449. *
  450. * returns:
  451. * a pointer to the expansion of the alias named 'name', of it exists
  452. * NULL, if the given alias or the /aliases node does not exist
  453. */
  454. const char *fdt_get_alias(const void *fdt, const char *name);
  455. /**
  456. * fdt_get_path - determine the full path of a node
  457. * @fdt: pointer to the device tree blob
  458. * @nodeoffset: offset of the node whose path to find
  459. * @buf: character buffer to contain the returned path (will be overwritten)
  460. * @buflen: size of the character buffer at buf
  461. *
  462. * fdt_get_path() computes the full path of the node at offset
  463. * nodeoffset, and records that path in the buffer at buf.
  464. *
  465. * NOTE: This function is expensive, as it must scan the device tree
  466. * structure from the start to nodeoffset.
  467. *
  468. * returns:
  469. * 0, on success
  470. * buf contains the absolute path of the node at
  471. * nodeoffset, as a NUL-terminated string.
  472. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  473. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  474. * characters and will not fit in the given buffer.
  475. * -FDT_ERR_BADMAGIC,
  476. * -FDT_ERR_BADVERSION,
  477. * -FDT_ERR_BADSTATE,
  478. * -FDT_ERR_BADSTRUCTURE, standard meanings
  479. */
  480. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  481. /**
  482. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  483. * @fdt: pointer to the device tree blob
  484. * @nodeoffset: offset of the node whose parent to find
  485. * @supernodedepth: depth of the ancestor to find
  486. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  487. *
  488. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  489. * at a specific depth from the root (where the root itself has depth
  490. * 0, its immediate subnodes depth 1 and so forth). So
  491. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  492. * will always return 0, the offset of the root node. If the node at
  493. * nodeoffset has depth D, then:
  494. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  495. * will return nodeoffset itself.
  496. *
  497. * NOTE: This function is expensive, as it must scan the device tree
  498. * structure from the start to nodeoffset.
  499. *
  500. * returns:
  501. * structure block offset of the node at node offset's ancestor
  502. * of depth supernodedepth (>=0), on success
  503. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  504. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
  505. * -FDT_ERR_BADMAGIC,
  506. * -FDT_ERR_BADVERSION,
  507. * -FDT_ERR_BADSTATE,
  508. * -FDT_ERR_BADSTRUCTURE, standard meanings
  509. */
  510. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  511. int supernodedepth, int *nodedepth);
  512. /**
  513. * fdt_node_depth - find the depth of a given node
  514. * @fdt: pointer to the device tree blob
  515. * @nodeoffset: offset of the node whose parent to find
  516. *
  517. * fdt_node_depth() finds the depth of a given node. The root node
  518. * has depth 0, its immediate subnodes depth 1 and so forth.
  519. *
  520. * NOTE: This function is expensive, as it must scan the device tree
  521. * structure from the start to nodeoffset.
  522. *
  523. * returns:
  524. * depth of the node at nodeoffset (>=0), on success
  525. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  526. * -FDT_ERR_BADMAGIC,
  527. * -FDT_ERR_BADVERSION,
  528. * -FDT_ERR_BADSTATE,
  529. * -FDT_ERR_BADSTRUCTURE, standard meanings
  530. */
  531. int fdt_node_depth(const void *fdt, int nodeoffset);
  532. /**
  533. * fdt_parent_offset - find the parent of a given node
  534. * @fdt: pointer to the device tree blob
  535. * @nodeoffset: offset of the node whose parent to find
  536. *
  537. * fdt_parent_offset() locates the parent node of a given node (that
  538. * is, it finds the offset of the node which contains the node at
  539. * nodeoffset as a subnode).
  540. *
  541. * NOTE: This function is expensive, as it must scan the device tree
  542. * structure from the start to nodeoffset, *twice*.
  543. *
  544. * returns:
  545. * structure block offset of the parent of the node at nodeoffset
  546. * (>=0), on success
  547. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  548. * -FDT_ERR_BADMAGIC,
  549. * -FDT_ERR_BADVERSION,
  550. * -FDT_ERR_BADSTATE,
  551. * -FDT_ERR_BADSTRUCTURE, standard meanings
  552. */
  553. int fdt_parent_offset(const void *fdt, int nodeoffset);
  554. /**
  555. * fdt_node_offset_by_prop_value - find nodes with a given property value
  556. * @fdt: pointer to the device tree blob
  557. * @startoffset: only find nodes after this offset
  558. * @propname: property name to check
  559. * @propval: property value to search for
  560. * @proplen: length of the value in propval
  561. *
  562. * fdt_node_offset_by_prop_value() returns the offset of the first
  563. * node after startoffset, which has a property named propname whose
  564. * value is of length proplen and has value equal to propval; or if
  565. * startoffset is -1, the very first such node in the tree.
  566. *
  567. * To iterate through all nodes matching the criterion, the following
  568. * idiom can be used:
  569. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  570. * propval, proplen);
  571. * while (offset != -FDT_ERR_NOTFOUND) {
  572. * ... other code here ...
  573. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  574. * propval, proplen);
  575. * }
  576. *
  577. * Note the -1 in the first call to the function, if 0 is used here
  578. * instead, the function will never locate the root node, even if it
  579. * matches the criterion.
  580. *
  581. * returns:
  582. * structure block offset of the located node (>= 0, >startoffset),
  583. * on success
  584. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  585. * tree after startoffset
  586. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  587. * -FDT_ERR_BADMAGIC,
  588. * -FDT_ERR_BADVERSION,
  589. * -FDT_ERR_BADSTATE,
  590. * -FDT_ERR_BADSTRUCTURE, standard meanings
  591. */
  592. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  593. const char *propname,
  594. const void *propval, int proplen);
  595. /**
  596. * fdt_node_offset_by_phandle - find the node with a given phandle
  597. * @fdt: pointer to the device tree blob
  598. * @phandle: phandle value
  599. *
  600. * fdt_node_offset_by_phandle() returns the offset of the node
  601. * which has the given phandle value. If there is more than one node
  602. * in the tree with the given phandle (an invalid tree), results are
  603. * undefined.
  604. *
  605. * returns:
  606. * structure block offset of the located node (>= 0), on success
  607. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  608. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  609. * -FDT_ERR_BADMAGIC,
  610. * -FDT_ERR_BADVERSION,
  611. * -FDT_ERR_BADSTATE,
  612. * -FDT_ERR_BADSTRUCTURE, standard meanings
  613. */
  614. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  615. /**
  616. * fdt_node_check_compatible: check a node's compatible property
  617. * @fdt: pointer to the device tree blob
  618. * @nodeoffset: offset of a tree node
  619. * @compatible: string to match against
  620. *
  621. *
  622. * fdt_node_check_compatible() returns 0 if the given node contains a
  623. * 'compatible' property with the given string as one of its elements,
  624. * it returns non-zero otherwise, or on error.
  625. *
  626. * returns:
  627. * 0, if the node has a 'compatible' property listing the given string
  628. * 1, if the node has a 'compatible' property, but it does not list
  629. * the given string
  630. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  631. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  632. * -FDT_ERR_BADMAGIC,
  633. * -FDT_ERR_BADVERSION,
  634. * -FDT_ERR_BADSTATE,
  635. * -FDT_ERR_BADSTRUCTURE, standard meanings
  636. */
  637. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  638. const char *compatible);
  639. /**
  640. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  641. * @fdt: pointer to the device tree blob
  642. * @startoffset: only find nodes after this offset
  643. * @compatible: 'compatible' string to match against
  644. *
  645. * fdt_node_offset_by_compatible() returns the offset of the first
  646. * node after startoffset, which has a 'compatible' property which
  647. * lists the given compatible string; or if startoffset is -1, the
  648. * very first such node in the tree.
  649. *
  650. * To iterate through all nodes matching the criterion, the following
  651. * idiom can be used:
  652. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  653. * while (offset != -FDT_ERR_NOTFOUND) {
  654. * ... other code here ...
  655. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  656. * }
  657. *
  658. * Note the -1 in the first call to the function, if 0 is used here
  659. * instead, the function will never locate the root node, even if it
  660. * matches the criterion.
  661. *
  662. * returns:
  663. * structure block offset of the located node (>= 0, >startoffset),
  664. * on success
  665. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  666. * tree after startoffset
  667. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  668. * -FDT_ERR_BADMAGIC,
  669. * -FDT_ERR_BADVERSION,
  670. * -FDT_ERR_BADSTATE,
  671. * -FDT_ERR_BADSTRUCTURE, standard meanings
  672. */
  673. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  674. const char *compatible);
  675. /**********************************************************************/
  676. /* Write-in-place functions */
  677. /**********************************************************************/
  678. /**
  679. * fdt_setprop_inplace - change a property's value, but not its size
  680. * @fdt: pointer to the device tree blob
  681. * @nodeoffset: offset of the node whose property to change
  682. * @name: name of the property to change
  683. * @val: pointer to data to replace the property value with
  684. * @len: length of the property value
  685. *
  686. * fdt_setprop_inplace() replaces the value of a given property with
  687. * the data in val, of length len. This function cannot change the
  688. * size of a property, and so will only work if len is equal to the
  689. * current length of the property.
  690. *
  691. * This function will alter only the bytes in the blob which contain
  692. * the given property value, and will not alter or move any other part
  693. * of the tree.
  694. *
  695. * returns:
  696. * 0, on success
  697. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  698. * -FDT_ERR_NOTFOUND, node does not have the named property
  699. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  700. * -FDT_ERR_BADMAGIC,
  701. * -FDT_ERR_BADVERSION,
  702. * -FDT_ERR_BADSTATE,
  703. * -FDT_ERR_BADSTRUCTURE,
  704. * -FDT_ERR_TRUNCATED, standard meanings
  705. */
  706. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  707. const void *val, int len);
  708. /**
  709. * fdt_setprop_inplace_cell - change the value of a single-cell property
  710. * @fdt: pointer to the device tree blob
  711. * @nodeoffset: offset of the node whose property to change
  712. * @name: name of the property to change
  713. * @val: cell (32-bit integer) value to replace the property with
  714. *
  715. * fdt_setprop_inplace_cell() replaces the value of a given property
  716. * with the 32-bit integer cell value in val, converting val to
  717. * big-endian if necessary. This function cannot change the size of a
  718. * property, and so will only work if the property already exists and
  719. * has length 4.
  720. *
  721. * This function will alter only the bytes in the blob which contain
  722. * the given property value, and will not alter or move any other part
  723. * of the tree.
  724. *
  725. * returns:
  726. * 0, on success
  727. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  728. * -FDT_ERR_NOTFOUND, node does not have the named property
  729. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  730. * -FDT_ERR_BADMAGIC,
  731. * -FDT_ERR_BADVERSION,
  732. * -FDT_ERR_BADSTATE,
  733. * -FDT_ERR_BADSTRUCTURE,
  734. * -FDT_ERR_TRUNCATED, standard meanings
  735. */
  736. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  737. const char *name, uint32_t val)
  738. {
  739. val = cpu_to_fdt32(val);
  740. return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
  741. }
  742. /**
  743. * fdt_nop_property - replace a property with nop tags
  744. * @fdt: pointer to the device tree blob
  745. * @nodeoffset: offset of the node whose property to nop
  746. * @name: name of the property to nop
  747. *
  748. * fdt_nop_property() will replace a given property's representation
  749. * in the blob with FDT_NOP tags, effectively removing it from the
  750. * tree.
  751. *
  752. * This function will alter only the bytes in the blob which contain
  753. * the property, and will not alter or move any other part of the
  754. * tree.
  755. *
  756. * returns:
  757. * 0, on success
  758. * -FDT_ERR_NOTFOUND, node does not have the named property
  759. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  760. * -FDT_ERR_BADMAGIC,
  761. * -FDT_ERR_BADVERSION,
  762. * -FDT_ERR_BADSTATE,
  763. * -FDT_ERR_BADSTRUCTURE,
  764. * -FDT_ERR_TRUNCATED, standard meanings
  765. */
  766. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  767. /**
  768. * fdt_nop_node - replace a node (subtree) with nop tags
  769. * @fdt: pointer to the device tree blob
  770. * @nodeoffset: offset of the node to nop
  771. *
  772. * fdt_nop_node() will replace a given node's representation in the
  773. * blob, including all its subnodes, if any, with FDT_NOP tags,
  774. * effectively removing it from the tree.
  775. *
  776. * This function will alter only the bytes in the blob which contain
  777. * the node and its properties and subnodes, and will not alter or
  778. * move any other part of the tree.
  779. *
  780. * returns:
  781. * 0, on success
  782. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  783. * -FDT_ERR_BADMAGIC,
  784. * -FDT_ERR_BADVERSION,
  785. * -FDT_ERR_BADSTATE,
  786. * -FDT_ERR_BADSTRUCTURE,
  787. * -FDT_ERR_TRUNCATED, standard meanings
  788. */
  789. int fdt_nop_node(void *fdt, int nodeoffset);
  790. /**********************************************************************/
  791. /* Sequential write functions */
  792. /**********************************************************************/
  793. int fdt_create(void *buf, int bufsize);
  794. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  795. int fdt_finish_reservemap(void *fdt);
  796. int fdt_begin_node(void *fdt, const char *name);
  797. int fdt_property(void *fdt, const char *name, const void *val, int len);
  798. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  799. {
  800. val = cpu_to_fdt32(val);
  801. return fdt_property(fdt, name, &val, sizeof(val));
  802. }
  803. #define fdt_property_string(fdt, name, str) \
  804. fdt_property(fdt, name, str, strlen(str)+1)
  805. int fdt_end_node(void *fdt);
  806. int fdt_finish(void *fdt);
  807. /**********************************************************************/
  808. /* Read-write functions */
  809. /**********************************************************************/
  810. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  811. int fdt_pack(void *fdt);
  812. /**
  813. * fdt_add_mem_rsv - add one memory reserve map entry
  814. * @fdt: pointer to the device tree blob
  815. * @address, @size: 64-bit values (native endian)
  816. *
  817. * Adds a reserve map entry to the given blob reserving a region at
  818. * address address of length size.
  819. *
  820. * This function will insert data into the reserve map and will
  821. * therefore change the indexes of some entries in the table.
  822. *
  823. * returns:
  824. * 0, on success
  825. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  826. * contain the new reservation entry
  827. * -FDT_ERR_BADMAGIC,
  828. * -FDT_ERR_BADVERSION,
  829. * -FDT_ERR_BADSTATE,
  830. * -FDT_ERR_BADSTRUCTURE,
  831. * -FDT_ERR_BADLAYOUT,
  832. * -FDT_ERR_TRUNCATED, standard meanings
  833. */
  834. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  835. /**
  836. * fdt_del_mem_rsv - remove a memory reserve map entry
  837. * @fdt: pointer to the device tree blob
  838. * @n: entry to remove
  839. *
  840. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  841. * the blob.
  842. *
  843. * This function will delete data from the reservation table and will
  844. * therefore change the indexes of some entries in the table.
  845. *
  846. * returns:
  847. * 0, on success
  848. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  849. * are less than n+1 reserve map entries)
  850. * -FDT_ERR_BADMAGIC,
  851. * -FDT_ERR_BADVERSION,
  852. * -FDT_ERR_BADSTATE,
  853. * -FDT_ERR_BADSTRUCTURE,
  854. * -FDT_ERR_BADLAYOUT,
  855. * -FDT_ERR_TRUNCATED, standard meanings
  856. */
  857. int fdt_del_mem_rsv(void *fdt, int n);
  858. /**
  859. * fdt_set_name - change the name of a given node
  860. * @fdt: pointer to the device tree blob
  861. * @nodeoffset: structure block offset of a node
  862. * @name: name to give the node
  863. *
  864. * fdt_set_name() replaces the name (including unit address, if any)
  865. * of the given node with the given string. NOTE: this function can't
  866. * efficiently check if the new name is unique amongst the given
  867. * node's siblings; results are undefined if this function is invoked
  868. * with a name equal to one of the given node's siblings.
  869. *
  870. * This function may insert or delete data from the blob, and will
  871. * therefore change the offsets of some existing nodes.
  872. *
  873. * returns:
  874. * 0, on success
  875. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  876. * to contain the new name
  877. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  878. * -FDT_ERR_BADMAGIC,
  879. * -FDT_ERR_BADVERSION,
  880. * -FDT_ERR_BADSTATE, standard meanings
  881. */
  882. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  883. /**
  884. * fdt_setprop - create or change a property
  885. * @fdt: pointer to the device tree blob
  886. * @nodeoffset: offset of the node whose property to change
  887. * @name: name of the property to change
  888. * @val: pointer to data to set the property value to
  889. * @len: length of the property value
  890. *
  891. * fdt_setprop() sets the value of the named property in the given
  892. * node to the given value and length, creating the property if it
  893. * does not already exist.
  894. *
  895. * This function may insert or delete data from the blob, and will
  896. * therefore change the offsets of some existing nodes.
  897. *
  898. * returns:
  899. * 0, on success
  900. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  901. * contain the new property value
  902. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  903. * -FDT_ERR_BADLAYOUT,
  904. * -FDT_ERR_BADMAGIC,
  905. * -FDT_ERR_BADVERSION,
  906. * -FDT_ERR_BADSTATE,
  907. * -FDT_ERR_BADSTRUCTURE,
  908. * -FDT_ERR_BADLAYOUT,
  909. * -FDT_ERR_TRUNCATED, standard meanings
  910. */
  911. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  912. const void *val, int len);
  913. /**
  914. * fdt_setprop_cell - set a property to a single cell value
  915. * @fdt: pointer to the device tree blob
  916. * @nodeoffset: offset of the node whose property to change
  917. * @name: name of the property to change
  918. * @val: 32-bit integer value for the property (native endian)
  919. *
  920. * fdt_setprop_cell() sets the value of the named property in the
  921. * given node to the given cell value (converting to big-endian if
  922. * necessary), or creates a new property with that value if it does
  923. * not already exist.
  924. *
  925. * This function may insert or delete data from the blob, and will
  926. * therefore change the offsets of some existing nodes.
  927. *
  928. * returns:
  929. * 0, on success
  930. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  931. * contain the new property value
  932. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  933. * -FDT_ERR_BADLAYOUT,
  934. * -FDT_ERR_BADMAGIC,
  935. * -FDT_ERR_BADVERSION,
  936. * -FDT_ERR_BADSTATE,
  937. * -FDT_ERR_BADSTRUCTURE,
  938. * -FDT_ERR_BADLAYOUT,
  939. * -FDT_ERR_TRUNCATED, standard meanings
  940. */
  941. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  942. uint32_t val)
  943. {
  944. val = cpu_to_fdt32(val);
  945. return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
  946. }
  947. /**
  948. * fdt_setprop_string - set a property to a string value
  949. * @fdt: pointer to the device tree blob
  950. * @nodeoffset: offset of the node whose property to change
  951. * @name: name of the property to change
  952. * @str: string value for the property
  953. *
  954. * fdt_setprop_string() sets the value of the named property in the
  955. * given node to the given string value (using the length of the
  956. * string to determine the new length of the property), or creates a
  957. * new property with that value if it does not already exist.
  958. *
  959. * This function may insert or delete data from the blob, and will
  960. * therefore change the offsets of some existing nodes.
  961. *
  962. * returns:
  963. * 0, on success
  964. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  965. * contain the new property value
  966. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  967. * -FDT_ERR_BADLAYOUT,
  968. * -FDT_ERR_BADMAGIC,
  969. * -FDT_ERR_BADVERSION,
  970. * -FDT_ERR_BADSTATE,
  971. * -FDT_ERR_BADSTRUCTURE,
  972. * -FDT_ERR_BADLAYOUT,
  973. * -FDT_ERR_TRUNCATED, standard meanings
  974. */
  975. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  976. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  977. /**
  978. * fdt_delprop - delete a property
  979. * @fdt: pointer to the device tree blob
  980. * @nodeoffset: offset of the node whose property to nop
  981. * @name: name of the property to nop
  982. *
  983. * fdt_del_property() will delete the given property.
  984. *
  985. * This function will delete data from the blob, and will therefore
  986. * change the offsets of some existing nodes.
  987. *
  988. * returns:
  989. * 0, on success
  990. * -FDT_ERR_NOTFOUND, node does not have the named property
  991. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  992. * -FDT_ERR_BADLAYOUT,
  993. * -FDT_ERR_BADMAGIC,
  994. * -FDT_ERR_BADVERSION,
  995. * -FDT_ERR_BADSTATE,
  996. * -FDT_ERR_BADSTRUCTURE,
  997. * -FDT_ERR_TRUNCATED, standard meanings
  998. */
  999. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  1000. /**
  1001. * fdt_add_subnode_namelen - creates a new node based on substring
  1002. * @fdt: pointer to the device tree blob
  1003. * @parentoffset: structure block offset of a node
  1004. * @name: name of the subnode to locate
  1005. * @namelen: number of characters of name to consider
  1006. *
  1007. * Identical to fdt_add_subnode(), but use only the first namelen
  1008. * characters of name as the name of the new node. This is useful for
  1009. * creating subnodes based on a portion of a larger string, such as a
  1010. * full path.
  1011. */
  1012. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  1013. const char *name, int namelen);
  1014. /**
  1015. * fdt_add_subnode - creates a new node
  1016. * @fdt: pointer to the device tree blob
  1017. * @parentoffset: structure block offset of a node
  1018. * @name: name of the subnode to locate
  1019. *
  1020. * fdt_add_subnode() creates a new node as a subnode of the node at
  1021. * structure block offset parentoffset, with the given name (which
  1022. * should include the unit address, if any).
  1023. *
  1024. * This function will insert data into the blob, and will therefore
  1025. * change the offsets of some existing nodes.
  1026. * returns:
  1027. * structure block offset of the created nodeequested subnode (>=0), on success
  1028. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  1029. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  1030. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  1031. * the given name
  1032. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  1033. * blob to contain the new node
  1034. * -FDT_ERR_NOSPACE
  1035. * -FDT_ERR_BADLAYOUT
  1036. * -FDT_ERR_BADMAGIC,
  1037. * -FDT_ERR_BADVERSION,
  1038. * -FDT_ERR_BADSTATE,
  1039. * -FDT_ERR_BADSTRUCTURE,
  1040. * -FDT_ERR_TRUNCATED, standard meanings.
  1041. */
  1042. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  1043. /**
  1044. * fdt_del_node - delete a node (subtree)
  1045. * @fdt: pointer to the device tree blob
  1046. * @nodeoffset: offset of the node to nop
  1047. *
  1048. * fdt_del_node() will remove the given node, including all its
  1049. * subnodes if any, from the blob.
  1050. *
  1051. * This function will delete data from the blob, and will therefore
  1052. * change the offsets of some existing nodes.
  1053. *
  1054. * returns:
  1055. * 0, on success
  1056. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1057. * -FDT_ERR_BADLAYOUT,
  1058. * -FDT_ERR_BADMAGIC,
  1059. * -FDT_ERR_BADVERSION,
  1060. * -FDT_ERR_BADSTATE,
  1061. * -FDT_ERR_BADSTRUCTURE,
  1062. * -FDT_ERR_TRUNCATED, standard meanings
  1063. */
  1064. int fdt_del_node(void *fdt, int nodeoffset);
  1065. /**********************************************************************/
  1066. /* Debugging / informational functions */
  1067. /**********************************************************************/
  1068. const char *fdt_strerror(int errval);
  1069. #endif /* _LIBFDT_H */