libfdt.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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: Attempted 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, 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 - find a given property in a given node
  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. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  326. *
  327. * fdt_get_property() retrieves a pointer to the fdt_property
  328. * structure within the device tree blob corresponding to the property
  329. * named 'name' of the node at offset nodeoffset. If lenp is
  330. * non-NULL, the length of the property value is also returned, in the
  331. * integer pointed to by lenp.
  332. *
  333. * returns:
  334. * pointer to the structure representing the property
  335. * if lenp is non-NULL, *lenp contains the length of the property
  336. * value (>=0)
  337. * NULL, on error
  338. * if lenp is non-NULL, *lenp contains an error code (<0):
  339. * -FDT_ERR_NOTFOUND, node does not have named property
  340. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  341. * -FDT_ERR_BADMAGIC,
  342. * -FDT_ERR_BADVERSION,
  343. * -FDT_ERR_BADSTATE,
  344. * -FDT_ERR_BADSTRUCTURE,
  345. * -FDT_ERR_TRUNCATED, standard meanings
  346. */
  347. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  348. const char *name, int *lenp);
  349. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  350. const char *name,
  351. int *lenp)
  352. {
  353. return (struct fdt_property *)(uintptr_t)
  354. fdt_get_property(fdt, nodeoffset, name, lenp);
  355. }
  356. /**
  357. * fdt_getprop - retrieve the value of a given property
  358. * @fdt: pointer to the device tree blob
  359. * @nodeoffset: offset of the node whose property to find
  360. * @name: name of the property to find
  361. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  362. *
  363. * fdt_getprop() retrieves a pointer to the value of the property
  364. * named 'name' of the node at offset nodeoffset (this will be a
  365. * pointer to within the device blob itself, not a copy of the value).
  366. * If lenp is non-NULL, the length of the property value is also
  367. * returned, in the integer pointed to by lenp.
  368. *
  369. * returns:
  370. * pointer to the property's value
  371. * if lenp is non-NULL, *lenp contains the length of the property
  372. * value (>=0)
  373. * NULL, on error
  374. * if lenp is non-NULL, *lenp contains an error code (<0):
  375. * -FDT_ERR_NOTFOUND, node does not have named property
  376. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  377. * -FDT_ERR_BADMAGIC,
  378. * -FDT_ERR_BADVERSION,
  379. * -FDT_ERR_BADSTATE,
  380. * -FDT_ERR_BADSTRUCTURE,
  381. * -FDT_ERR_TRUNCATED, standard meanings
  382. */
  383. const void *fdt_getprop(const void *fdt, int nodeoffset,
  384. const char *name, int *lenp);
  385. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  386. const char *name, int *lenp)
  387. {
  388. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  389. }
  390. /**
  391. * fdt_get_phandle - retrieve the phandle of a given node
  392. * @fdt: pointer to the device tree blob
  393. * @nodeoffset: structure block offset of the node
  394. *
  395. * fdt_get_phandle() retrieves the phandle of the device tree node at
  396. * structure block offset nodeoffset.
  397. *
  398. * returns:
  399. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  400. * 0, if the node has no phandle, or another error occurs
  401. */
  402. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  403. /**
  404. * fdt_get_path - determine the full path of a node
  405. * @fdt: pointer to the device tree blob
  406. * @nodeoffset: offset of the node whose path to find
  407. * @buf: character buffer to contain the returned path (will be overwritten)
  408. * @buflen: size of the character buffer at buf
  409. *
  410. * fdt_get_path() computes the full path of the node at offset
  411. * nodeoffset, and records that path in the buffer at buf.
  412. *
  413. * NOTE: This function is expensive, as it must scan the device tree
  414. * structure from the start to nodeoffset.
  415. *
  416. * returns:
  417. * 0, on success
  418. * buf contains the absolute path of the node at
  419. * nodeoffset, as a NUL-terminated string.
  420. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  421. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  422. * characters and will not fit in the given buffer.
  423. * -FDT_ERR_BADMAGIC,
  424. * -FDT_ERR_BADVERSION,
  425. * -FDT_ERR_BADSTATE,
  426. * -FDT_ERR_BADSTRUCTURE, standard meanings
  427. */
  428. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  429. /**
  430. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  431. * @fdt: pointer to the device tree blob
  432. * @nodeoffset: offset of the node whose parent to find
  433. * @supernodedepth: depth of the ancestor to find
  434. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  435. *
  436. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  437. * at a specific depth from the root (where the root itself has depth
  438. * 0, its immediate subnodes depth 1 and so forth). So
  439. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  440. * will always return 0, the offset of the root node. If the node at
  441. * nodeoffset has depth D, then:
  442. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  443. * will return nodeoffset itself.
  444. *
  445. * NOTE: This function is expensive, as it must scan the device tree
  446. * structure from the start to nodeoffset.
  447. *
  448. * returns:
  449. * structure block offset of the node at node offset's ancestor
  450. * of depth supernodedepth (>=0), on success
  451. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  452. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
  453. * -FDT_ERR_BADMAGIC,
  454. * -FDT_ERR_BADVERSION,
  455. * -FDT_ERR_BADSTATE,
  456. * -FDT_ERR_BADSTRUCTURE, standard meanings
  457. */
  458. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  459. int supernodedepth, int *nodedepth);
  460. /**
  461. * fdt_node_depth - find the depth of a given node
  462. * @fdt: pointer to the device tree blob
  463. * @nodeoffset: offset of the node whose parent to find
  464. *
  465. * fdt_node_depth() finds the depth of a given node. The root node
  466. * has depth 0, its immediate subnodes depth 1 and so forth.
  467. *
  468. * NOTE: This function is expensive, as it must scan the device tree
  469. * structure from the start to nodeoffset.
  470. *
  471. * returns:
  472. * depth of the node at nodeoffset (>=0), on success
  473. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  474. * -FDT_ERR_BADMAGIC,
  475. * -FDT_ERR_BADVERSION,
  476. * -FDT_ERR_BADSTATE,
  477. * -FDT_ERR_BADSTRUCTURE, standard meanings
  478. */
  479. int fdt_node_depth(const void *fdt, int nodeoffset);
  480. /**
  481. * fdt_parent_offset - find the parent of a given node
  482. * @fdt: pointer to the device tree blob
  483. * @nodeoffset: offset of the node whose parent to find
  484. *
  485. * fdt_parent_offset() locates the parent node of a given node (that
  486. * is, it finds the offset of the node which contains the node at
  487. * nodeoffset as a subnode).
  488. *
  489. * NOTE: This function is expensive, as it must scan the device tree
  490. * structure from the start to nodeoffset, *twice*.
  491. *
  492. * returns:
  493. * structure block offset of the parent of the node at nodeoffset
  494. * (>=0), on success
  495. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  496. * -FDT_ERR_BADMAGIC,
  497. * -FDT_ERR_BADVERSION,
  498. * -FDT_ERR_BADSTATE,
  499. * -FDT_ERR_BADSTRUCTURE, standard meanings
  500. */
  501. int fdt_parent_offset(const void *fdt, int nodeoffset);
  502. /**
  503. * fdt_node_offset_by_prop_value - find nodes with a given property value
  504. * @fdt: pointer to the device tree blob
  505. * @startoffset: only find nodes after this offset
  506. * @propname: property name to check
  507. * @propval: property value to search for
  508. * @proplen: length of the value in propval
  509. *
  510. * fdt_node_offset_by_prop_value() returns the offset of the first
  511. * node after startoffset, which has a property named propname whose
  512. * value is of length proplen and has value equal to propval; or if
  513. * startoffset is -1, the very first such node in the tree.
  514. *
  515. * To iterate through all nodes matching the criterion, the following
  516. * idiom can be used:
  517. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  518. * propval, proplen);
  519. * while (offset != -FDT_ERR_NOTFOUND) {
  520. * // other code here
  521. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  522. * propval, proplen);
  523. * }
  524. *
  525. * Note the -1 in the first call to the function, if 0 is used here
  526. * instead, the function will never locate the root node, even if it
  527. * matches the criterion.
  528. *
  529. * returns:
  530. * structure block offset of the located node (>= 0, >startoffset),
  531. * on success
  532. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  533. * tree after startoffset
  534. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  535. * -FDT_ERR_BADMAGIC,
  536. * -FDT_ERR_BADVERSION,
  537. * -FDT_ERR_BADSTATE,
  538. * -FDT_ERR_BADSTRUCTURE, standard meanings
  539. */
  540. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  541. const char *propname,
  542. const void *propval, int proplen);
  543. /**
  544. * fdt_node_offset_by_phandle - find the node with a given phandle
  545. * @fdt: pointer to the device tree blob
  546. * @phandle: phandle value
  547. *
  548. * fdt_node_offset_by_phandle() returns the offset of the node
  549. * which has the given phandle value. If there is more than one node
  550. * in the tree with the given phandle (an invalid tree), results are
  551. * undefined.
  552. *
  553. * returns:
  554. * structure block offset of the located node (>= 0), on success
  555. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  556. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  557. * -FDT_ERR_BADMAGIC,
  558. * -FDT_ERR_BADVERSION,
  559. * -FDT_ERR_BADSTATE,
  560. * -FDT_ERR_BADSTRUCTURE, standard meanings
  561. */
  562. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  563. /**
  564. * fdt_node_check_compatible: check a node's compatible property
  565. * @fdt: pointer to the device tree blob
  566. * @nodeoffset: offset of a tree node
  567. * @compatible: string to match against
  568. *
  569. *
  570. * fdt_node_check_compatible() returns 0 if the given node contains a
  571. * 'compatible' property with the given string as one of its elements,
  572. * it returns non-zero otherwise, or on error.
  573. *
  574. * returns:
  575. * 0, if the node has a 'compatible' property listing the given string
  576. * 1, if the node has a 'compatible' property, but it does not list
  577. * the given string
  578. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  579. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  580. * -FDT_ERR_BADMAGIC,
  581. * -FDT_ERR_BADVERSION,
  582. * -FDT_ERR_BADSTATE,
  583. * -FDT_ERR_BADSTRUCTURE, standard meanings
  584. */
  585. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  586. const char *compatible);
  587. /**
  588. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  589. * @fdt: pointer to the device tree blob
  590. * @startoffset: only find nodes after this offset
  591. * @compatible: 'compatible' string to match against
  592. *
  593. * fdt_node_offset_by_compatible() returns the offset of the first
  594. * node after startoffset, which has a 'compatible' property which
  595. * lists the given compatible string; or if startoffset is -1, the
  596. * very first such node in the tree.
  597. *
  598. * To iterate through all nodes matching the criterion, the following
  599. * idiom can be used:
  600. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  601. * while (offset != -FDT_ERR_NOTFOUND) {
  602. * // other code here
  603. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  604. * }
  605. *
  606. * Note the -1 in the first call to the function, if 0 is used here
  607. * instead, the function will never locate the root node, even if it
  608. * matches the criterion.
  609. *
  610. * returns:
  611. * structure block offset of the located node (>= 0, >startoffset),
  612. * on success
  613. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  614. * tree after startoffset
  615. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  616. * -FDT_ERR_BADMAGIC,
  617. * -FDT_ERR_BADVERSION,
  618. * -FDT_ERR_BADSTATE,
  619. * -FDT_ERR_BADSTRUCTURE, standard meanings
  620. */
  621. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  622. const char *compatible);
  623. /**********************************************************************/
  624. /* Write-in-place functions */
  625. /**********************************************************************/
  626. /**
  627. * fdt_setprop_inplace - change a property's value, but not its size
  628. * @fdt: pointer to the device tree blob
  629. * @nodeoffset: offset of the node whose property to change
  630. * @name: name of the property to change
  631. * @val: pointer to data to replace the property value with
  632. * @len: length of the property value
  633. *
  634. * fdt_setprop_inplace() replaces the value of a given property with
  635. * the data in val, of length len. This function cannot change the
  636. * size of a property, and so will only work if len is equal to the
  637. * current length of the property.
  638. *
  639. * This function will alter only the bytes in the blob which contain
  640. * the given property value, and will not alter or move any other part
  641. * of the tree.
  642. *
  643. * returns:
  644. * 0, on success
  645. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  646. * -FDT_ERR_NOTFOUND, node does not have the named property
  647. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  648. * -FDT_ERR_BADMAGIC,
  649. * -FDT_ERR_BADVERSION,
  650. * -FDT_ERR_BADSTATE,
  651. * -FDT_ERR_BADSTRUCTURE,
  652. * -FDT_ERR_TRUNCATED, standard meanings
  653. */
  654. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  655. const void *val, int len);
  656. /**
  657. * fdt_setprop_inplace_cell - change the value of a single-cell property
  658. * @fdt: pointer to the device tree blob
  659. * @nodeoffset: offset of the node whose property to change
  660. * @name: name of the property to change
  661. * @val: cell (32-bit integer) value to replace the property with
  662. *
  663. * fdt_setprop_inplace_cell() replaces the value of a given property
  664. * with the 32-bit integer cell value in val, converting val to
  665. * big-endian if necessary. This function cannot change the size of a
  666. * property, and so will only work if the property already exists and
  667. * has length 4.
  668. *
  669. * This function will alter only the bytes in the blob which contain
  670. * the given property value, and will not alter or move any other part
  671. * of the tree.
  672. *
  673. * returns:
  674. * 0, on success
  675. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  676. * -FDT_ERR_NOTFOUND, node does not have the named property
  677. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  678. * -FDT_ERR_BADMAGIC,
  679. * -FDT_ERR_BADVERSION,
  680. * -FDT_ERR_BADSTATE,
  681. * -FDT_ERR_BADSTRUCTURE,
  682. * -FDT_ERR_TRUNCATED, standard meanings
  683. */
  684. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  685. const char *name, uint32_t val)
  686. {
  687. val = cpu_to_fdt32(val);
  688. return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
  689. }
  690. /**
  691. * fdt_nop_property - replace a property with nop tags
  692. * @fdt: pointer to the device tree blob
  693. * @nodeoffset: offset of the node whose property to nop
  694. * @name: name of the property to nop
  695. *
  696. * fdt_nop_property() will replace a given property's representation
  697. * in the blob with FDT_NOP tags, effectively removing it from the
  698. * tree.
  699. *
  700. * This function will alter only the bytes in the blob which contain
  701. * the property, and will not alter or move any other part of the
  702. * tree.
  703. *
  704. * returns:
  705. * 0, on success
  706. * -FDT_ERR_NOTFOUND, node does not have the named property
  707. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  708. * -FDT_ERR_BADMAGIC,
  709. * -FDT_ERR_BADVERSION,
  710. * -FDT_ERR_BADSTATE,
  711. * -FDT_ERR_BADSTRUCTURE,
  712. * -FDT_ERR_TRUNCATED, standard meanings
  713. */
  714. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  715. /**
  716. * fdt_nop_node - replace a node (subtree) with nop tags
  717. * @fdt: pointer to the device tree blob
  718. * @nodeoffset: offset of the node to nop
  719. *
  720. * fdt_nop_node() will replace a given node's representation in the
  721. * blob, including all its subnodes, if any, with FDT_NOP tags,
  722. * effectively removing it from the tree.
  723. *
  724. * This function will alter only the bytes in the blob which contain
  725. * the node and its properties and subnodes, and will not alter or
  726. * move any other part of the tree.
  727. *
  728. * returns:
  729. * 0, on success
  730. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  731. * -FDT_ERR_BADMAGIC,
  732. * -FDT_ERR_BADVERSION,
  733. * -FDT_ERR_BADSTATE,
  734. * -FDT_ERR_BADSTRUCTURE,
  735. * -FDT_ERR_TRUNCATED, standard meanings
  736. */
  737. int fdt_nop_node(void *fdt, int nodeoffset);
  738. /**********************************************************************/
  739. /* Sequential write functions */
  740. /**********************************************************************/
  741. int fdt_create(void *buf, int bufsize);
  742. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  743. int fdt_finish_reservemap(void *fdt);
  744. int fdt_begin_node(void *fdt, const char *name);
  745. int fdt_property(void *fdt, const char *name, const void *val, int len);
  746. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  747. {
  748. val = cpu_to_fdt32(val);
  749. return fdt_property(fdt, name, &val, sizeof(val));
  750. }
  751. #define fdt_property_string(fdt, name, str) \
  752. fdt_property(fdt, name, str, strlen(str)+1)
  753. int fdt_end_node(void *fdt);
  754. int fdt_finish(void *fdt);
  755. /**********************************************************************/
  756. /* Read-write functions */
  757. /**********************************************************************/
  758. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  759. int fdt_pack(void *fdt);
  760. /**
  761. * fdt_add_mem_rsv - add one memory reserve map entry
  762. * @fdt: pointer to the device tree blob
  763. * @address, @size: 64-bit values (native endian)
  764. *
  765. * Adds a reserve map entry to the given blob reserving a region at
  766. * address address of length size.
  767. *
  768. * This function will insert data into the reserve map and will
  769. * therefore change the indexes of some entries in the table.
  770. *
  771. * returns:
  772. * 0, on success
  773. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  774. * contain the new reservation entry
  775. * -FDT_ERR_BADMAGIC,
  776. * -FDT_ERR_BADVERSION,
  777. * -FDT_ERR_BADSTATE,
  778. * -FDT_ERR_BADSTRUCTURE,
  779. * -FDT_ERR_BADLAYOUT,
  780. * -FDT_ERR_TRUNCATED, standard meanings
  781. */
  782. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  783. /**
  784. * fdt_del_mem_rsv - remove a memory reserve map entry
  785. * @fdt: pointer to the device tree blob
  786. * @n: entry to remove
  787. *
  788. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  789. * the blob.
  790. *
  791. * This function will delete data from the reservation table and will
  792. * therefore change the indexes of some entries in the table.
  793. *
  794. * returns:
  795. * 0, on success
  796. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  797. * are less than n+1 reserve map entries)
  798. * -FDT_ERR_BADMAGIC,
  799. * -FDT_ERR_BADVERSION,
  800. * -FDT_ERR_BADSTATE,
  801. * -FDT_ERR_BADSTRUCTURE,
  802. * -FDT_ERR_BADLAYOUT,
  803. * -FDT_ERR_TRUNCATED, standard meanings
  804. */
  805. int fdt_del_mem_rsv(void *fdt, int n);
  806. /**
  807. * fdt_set_name - change the name of a given node
  808. * @fdt: pointer to the device tree blob
  809. * @nodeoffset: structure block offset of a node
  810. * @name: name to give the node
  811. *
  812. * fdt_set_name() replaces the name (including unit address, if any)
  813. * of the given node with the given string. NOTE: this function can't
  814. * efficiently check if the new name is unique amongst the given
  815. * node's siblings; results are undefined if this function is invoked
  816. * with a name equal to one of the given node's siblings.
  817. *
  818. * This function may insert or delete data from the blob, and will
  819. * therefore change the offsets of some existing nodes.
  820. *
  821. * returns:
  822. * 0, on success
  823. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  824. * to contain the new name
  825. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  826. * -FDT_ERR_BADMAGIC,
  827. * -FDT_ERR_BADVERSION,
  828. * -FDT_ERR_BADSTATE, standard meanings
  829. */
  830. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  831. /**
  832. * fdt_setprop - create or change a property
  833. * @fdt: pointer to the device tree blob
  834. * @nodeoffset: offset of the node whose property to change
  835. * @name: name of the property to change
  836. * @val: pointer to data to set the property value to
  837. * @len: length of the property value
  838. *
  839. * fdt_setprop() sets the value of the named property in the given
  840. * node to the given value and length, creating the property if it
  841. * does not already exist.
  842. *
  843. * This function may insert or delete data from the blob, and will
  844. * therefore change the offsets of some existing nodes.
  845. *
  846. * returns:
  847. * 0, on success
  848. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  849. * contain the new property value
  850. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  851. * -FDT_ERR_BADLAYOUT,
  852. * -FDT_ERR_BADMAGIC,
  853. * -FDT_ERR_BADVERSION,
  854. * -FDT_ERR_BADSTATE,
  855. * -FDT_ERR_BADSTRUCTURE,
  856. * -FDT_ERR_BADLAYOUT,
  857. * -FDT_ERR_TRUNCATED, standard meanings
  858. */
  859. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  860. const void *val, int len);
  861. /**
  862. * fdt_setprop_cell - set a property to a single cell value
  863. * @fdt: pointer to the device tree blob
  864. * @nodeoffset: offset of the node whose property to change
  865. * @name: name of the property to change
  866. * @val: 32-bit integer value for the property (native endian)
  867. *
  868. * fdt_setprop_cell() sets the value of the named property in the
  869. * given node to the given cell value (converting to big-endian if
  870. * necessary), or creates a new property with that value if it does
  871. * not already exist.
  872. *
  873. * This function may insert or delete data from the blob, and will
  874. * therefore change the offsets of some existing nodes.
  875. *
  876. * returns:
  877. * 0, on success
  878. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  879. * contain the new property value
  880. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  881. * -FDT_ERR_BADLAYOUT,
  882. * -FDT_ERR_BADMAGIC,
  883. * -FDT_ERR_BADVERSION,
  884. * -FDT_ERR_BADSTATE,
  885. * -FDT_ERR_BADSTRUCTURE,
  886. * -FDT_ERR_BADLAYOUT,
  887. * -FDT_ERR_TRUNCATED, standard meanings
  888. */
  889. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  890. uint32_t val)
  891. {
  892. val = cpu_to_fdt32(val);
  893. return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
  894. }
  895. /**
  896. * fdt_setprop_string - set a property to a string value
  897. * @fdt: pointer to the device tree blob
  898. * @nodeoffset: offset of the node whose property to change
  899. * @name: name of the property to change
  900. * @str: string value for the property
  901. *
  902. * fdt_setprop_string() sets the value of the named property in the
  903. * given node to the given string value (using the length of the
  904. * string to determine the new length of the property), or creates a
  905. * new property with that value if it does not already exist.
  906. *
  907. * This function may insert or delete data from the blob, and will
  908. * therefore change the offsets of some existing nodes.
  909. *
  910. * returns:
  911. * 0, on success
  912. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  913. * contain the new property value
  914. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  915. * -FDT_ERR_BADLAYOUT,
  916. * -FDT_ERR_BADMAGIC,
  917. * -FDT_ERR_BADVERSION,
  918. * -FDT_ERR_BADSTATE,
  919. * -FDT_ERR_BADSTRUCTURE,
  920. * -FDT_ERR_BADLAYOUT,
  921. * -FDT_ERR_TRUNCATED, standard meanings
  922. */
  923. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  924. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  925. /**
  926. * fdt_delprop - delete a property
  927. * @fdt: pointer to the device tree blob
  928. * @nodeoffset: offset of the node whose property to nop
  929. * @name: name of the property to nop
  930. *
  931. * fdt_del_property() will delete the given property.
  932. *
  933. * This function will delete data from the blob, and will therefore
  934. * change the offsets of some existing nodes.
  935. *
  936. * returns:
  937. * 0, on success
  938. * -FDT_ERR_NOTFOUND, node does not have the named property
  939. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  940. * -FDT_ERR_BADLAYOUT,
  941. * -FDT_ERR_BADMAGIC,
  942. * -FDT_ERR_BADVERSION,
  943. * -FDT_ERR_BADSTATE,
  944. * -FDT_ERR_BADSTRUCTURE,
  945. * -FDT_ERR_TRUNCATED, standard meanings
  946. */
  947. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  948. /**
  949. * fdt_add_subnode_namelen - creates a new node based on substring
  950. * @fdt: pointer to the device tree blob
  951. * @parentoffset: structure block offset of a node
  952. * @name: name of the subnode to locate
  953. * @namelen: number of characters of name to consider
  954. *
  955. * Identical to fdt_add_subnode(), but use only the first namelen
  956. * characters of name as the name of the new node. This is useful for
  957. * creating subnodes based on a portion of a larger string, such as a
  958. * full path.
  959. */
  960. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  961. const char *name, int namelen);
  962. /**
  963. * fdt_add_subnode - creates a new node
  964. * @fdt: pointer to the device tree blob
  965. * @parentoffset: structure block offset of a node
  966. * @name: name of the subnode to locate
  967. *
  968. * fdt_add_subnode() creates a new node as a subnode of the node at
  969. * structure block offset parentoffset, with the given name (which
  970. * should include the unit address, if any).
  971. *
  972. * This function will insert data into the blob, and will therefore
  973. * change the offsets of some existing nodes.
  974. * returns:
  975. * structure block offset of the created nodeequested subnode (>=0), on success
  976. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  977. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  978. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  979. * the given name
  980. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  981. * blob to contain the new node
  982. * -FDT_ERR_NOSPACE
  983. * -FDT_ERR_BADLAYOUT
  984. * -FDT_ERR_BADMAGIC,
  985. * -FDT_ERR_BADVERSION,
  986. * -FDT_ERR_BADSTATE,
  987. * -FDT_ERR_BADSTRUCTURE,
  988. * -FDT_ERR_TRUNCATED, standard meanings.
  989. */
  990. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  991. /**
  992. * fdt_del_node - delete a node (subtree)
  993. * @fdt: pointer to the device tree blob
  994. * @nodeoffset: offset of the node to nop
  995. *
  996. * fdt_del_node() will remove the given node, including all its
  997. * subnodes if any, from the blob.
  998. *
  999. * This function will delete data from the blob, and will therefore
  1000. * change the offsets of some existing nodes.
  1001. *
  1002. * returns:
  1003. * 0, on success
  1004. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1005. * -FDT_ERR_BADLAYOUT,
  1006. * -FDT_ERR_BADMAGIC,
  1007. * -FDT_ERR_BADVERSION,
  1008. * -FDT_ERR_BADSTATE,
  1009. * -FDT_ERR_BADSTRUCTURE,
  1010. * -FDT_ERR_TRUNCATED, standard meanings
  1011. */
  1012. int fdt_del_node(void *fdt, int nodeoffset);
  1013. /**********************************************************************/
  1014. /* Debugging / informational functions */
  1015. /**********************************************************************/
  1016. const char *fdt_strerror(int errval);
  1017. #endif /* _LIBFDT_H */