libfdt.h 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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. /* Errors in device tree content */
  113. #define FDT_ERR_BADNCELLS 14
  114. /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
  115. * or similar property with a bad format or value */
  116. #define FDT_ERR_MAX 14
  117. /**********************************************************************/
  118. /* Low-level functions (you probably don't need these) */
  119. /**********************************************************************/
  120. const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
  121. static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  122. {
  123. return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
  124. }
  125. uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
  126. /**********************************************************************/
  127. /* Traversal functions */
  128. /**********************************************************************/
  129. int fdt_next_node(const void *fdt, int offset, int *depth);
  130. /**
  131. * fdt_first_subnode() - get offset of first direct subnode
  132. *
  133. * @fdt: FDT blob
  134. * @offset: Offset of node to check
  135. * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
  136. */
  137. int fdt_first_subnode(const void *fdt, int offset);
  138. /**
  139. * fdt_next_subnode() - get offset of next direct subnode
  140. *
  141. * After first calling fdt_first_subnode(), call this function repeatedly to
  142. * get direct subnodes of a parent node.
  143. *
  144. * @fdt: FDT blob
  145. * @offset: Offset of previous subnode
  146. * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
  147. * subnodes
  148. */
  149. int fdt_next_subnode(const void *fdt, int offset);
  150. /**********************************************************************/
  151. /* General functions */
  152. /**********************************************************************/
  153. #define fdt_get_header(fdt, field) \
  154. (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
  155. #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
  156. #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
  157. #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
  158. #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
  159. #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
  160. #define fdt_version(fdt) (fdt_get_header(fdt, version))
  161. #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
  162. #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
  163. #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
  164. #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
  165. #define __fdt_set_hdr(name) \
  166. static inline void fdt_set_##name(void *fdt, uint32_t val) \
  167. { \
  168. struct fdt_header *fdth = (struct fdt_header*)fdt; \
  169. fdth->name = cpu_to_fdt32(val); \
  170. }
  171. __fdt_set_hdr(magic);
  172. __fdt_set_hdr(totalsize);
  173. __fdt_set_hdr(off_dt_struct);
  174. __fdt_set_hdr(off_dt_strings);
  175. __fdt_set_hdr(off_mem_rsvmap);
  176. __fdt_set_hdr(version);
  177. __fdt_set_hdr(last_comp_version);
  178. __fdt_set_hdr(boot_cpuid_phys);
  179. __fdt_set_hdr(size_dt_strings);
  180. __fdt_set_hdr(size_dt_struct);
  181. #undef __fdt_set_hdr
  182. /**
  183. * fdt_check_header - sanity check a device tree or possible device tree
  184. * @fdt: pointer to data which might be a flattened device tree
  185. *
  186. * fdt_check_header() checks that the given buffer contains what
  187. * appears to be a flattened device tree with sane information in its
  188. * header.
  189. *
  190. * returns:
  191. * 0, if the buffer appears to contain a valid device tree
  192. * -FDT_ERR_BADMAGIC,
  193. * -FDT_ERR_BADVERSION,
  194. * -FDT_ERR_BADSTATE, standard meanings, as above
  195. */
  196. int fdt_check_header(const void *fdt);
  197. /**
  198. * fdt_move - move a device tree around in memory
  199. * @fdt: pointer to the device tree to move
  200. * @buf: pointer to memory where the device is to be moved
  201. * @bufsize: size of the memory space at buf
  202. *
  203. * fdt_move() relocates, if possible, the device tree blob located at
  204. * fdt to the buffer at buf of size bufsize. The buffer may overlap
  205. * with the existing device tree blob at fdt. Therefore,
  206. * fdt_move(fdt, fdt, fdt_totalsize(fdt))
  207. * should always succeed.
  208. *
  209. * returns:
  210. * 0, on success
  211. * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
  212. * -FDT_ERR_BADMAGIC,
  213. * -FDT_ERR_BADVERSION,
  214. * -FDT_ERR_BADSTATE, standard meanings
  215. */
  216. int fdt_move(const void *fdt, void *buf, int bufsize);
  217. /**********************************************************************/
  218. /* Read-only functions */
  219. /**********************************************************************/
  220. /**
  221. * fdt_string - retrieve a string from the strings block of a device tree
  222. * @fdt: pointer to the device tree blob
  223. * @stroffset: offset of the string within the strings block (native endian)
  224. *
  225. * fdt_string() retrieves a pointer to a single string from the
  226. * strings block of the device tree blob at fdt.
  227. *
  228. * returns:
  229. * a pointer to the string, on success
  230. * NULL, if stroffset is out of bounds
  231. */
  232. const char *fdt_string(const void *fdt, int stroffset);
  233. /**
  234. * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
  235. * @fdt: pointer to the device tree blob
  236. *
  237. * Returns the number of entries in the device tree blob's memory
  238. * reservation map. This does not include the terminating 0,0 entry
  239. * or any other (0,0) entries reserved for expansion.
  240. *
  241. * returns:
  242. * the number of entries
  243. */
  244. int fdt_num_mem_rsv(const void *fdt);
  245. /**
  246. * fdt_get_mem_rsv - retrieve one memory reserve map entry
  247. * @fdt: pointer to the device tree blob
  248. * @address, @size: pointers to 64-bit variables
  249. *
  250. * On success, *address and *size will contain the address and size of
  251. * the n-th reserve map entry from the device tree blob, in
  252. * native-endian format.
  253. *
  254. * returns:
  255. * 0, on success
  256. * -FDT_ERR_BADMAGIC,
  257. * -FDT_ERR_BADVERSION,
  258. * -FDT_ERR_BADSTATE, standard meanings
  259. */
  260. int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
  261. /**
  262. * fdt_subnode_offset_namelen - find a subnode based on substring
  263. * @fdt: pointer to the device tree blob
  264. * @parentoffset: structure block offset of a node
  265. * @name: name of the subnode to locate
  266. * @namelen: number of characters of name to consider
  267. *
  268. * Identical to fdt_subnode_offset(), but only examine the first
  269. * namelen characters of name for matching the subnode name. This is
  270. * useful for finding subnodes based on a portion of a larger string,
  271. * such as a full path.
  272. */
  273. int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
  274. const char *name, int namelen);
  275. /**
  276. * fdt_subnode_offset - find a subnode of a given node
  277. * @fdt: pointer to the device tree blob
  278. * @parentoffset: structure block offset of a node
  279. * @name: name of the subnode to locate
  280. *
  281. * fdt_subnode_offset() finds a subnode of the node at structure block
  282. * offset parentoffset with the given name. name may include a unit
  283. * address, in which case fdt_subnode_offset() will find the subnode
  284. * with that unit address, or the unit address may be omitted, in
  285. * which case fdt_subnode_offset() will find an arbitrary subnode
  286. * whose name excluding unit address matches the given name.
  287. *
  288. * returns:
  289. * structure block offset of the requested subnode (>=0), on success
  290. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  291. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  292. * -FDT_ERR_BADMAGIC,
  293. * -FDT_ERR_BADVERSION,
  294. * -FDT_ERR_BADSTATE,
  295. * -FDT_ERR_BADSTRUCTURE,
  296. * -FDT_ERR_TRUNCATED, standard meanings.
  297. */
  298. int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
  299. /**
  300. * fdt_path_offset_namelen - find a tree node by its full path
  301. * @fdt: pointer to the device tree blob
  302. * @path: full path of the node to locate
  303. * @namelen: number of characters of path to consider
  304. *
  305. * Identical to fdt_path_offset(), but only consider the first namelen
  306. * characters of path as the path name.
  307. */
  308. int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
  309. /**
  310. * fdt_path_offset - find a tree node by its full path
  311. * @fdt: pointer to the device tree blob
  312. * @path: full path of the node to locate
  313. *
  314. * fdt_path_offset() finds a node of a given path in the device tree.
  315. * Each path component may omit the unit address portion, but the
  316. * results of this are undefined if any such path component is
  317. * ambiguous (that is if there are multiple nodes at the relevant
  318. * level matching the given component, differentiated only by unit
  319. * address).
  320. *
  321. * returns:
  322. * structure block offset of the node with the requested path (>=0), on success
  323. * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
  324. * -FDT_ERR_NOTFOUND, if the requested node does not exist
  325. * -FDT_ERR_BADMAGIC,
  326. * -FDT_ERR_BADVERSION,
  327. * -FDT_ERR_BADSTATE,
  328. * -FDT_ERR_BADSTRUCTURE,
  329. * -FDT_ERR_TRUNCATED, standard meanings.
  330. */
  331. int fdt_path_offset(const void *fdt, const char *path);
  332. /**
  333. * fdt_get_name - retrieve the name of a given node
  334. * @fdt: pointer to the device tree blob
  335. * @nodeoffset: structure block offset of the starting node
  336. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  337. *
  338. * fdt_get_name() retrieves the name (including unit address) of the
  339. * device tree node at structure block offset nodeoffset. If lenp is
  340. * non-NULL, the length of this name is also returned, in the integer
  341. * pointed to by lenp.
  342. *
  343. * returns:
  344. * pointer to the node's name, on success
  345. * If lenp is non-NULL, *lenp contains the length of that name (>=0)
  346. * NULL, on error
  347. * if lenp is non-NULL *lenp contains an error code (<0):
  348. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  349. * -FDT_ERR_BADMAGIC,
  350. * -FDT_ERR_BADVERSION,
  351. * -FDT_ERR_BADSTATE, standard meanings
  352. */
  353. const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
  354. /**
  355. * fdt_first_property_offset - find the offset of a node's first property
  356. * @fdt: pointer to the device tree blob
  357. * @nodeoffset: structure block offset of a node
  358. *
  359. * fdt_first_property_offset() finds the first property of the node at
  360. * the given structure block offset.
  361. *
  362. * returns:
  363. * structure block offset of the property (>=0), on success
  364. * -FDT_ERR_NOTFOUND, if the requested node has no properties
  365. * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
  366. * -FDT_ERR_BADMAGIC,
  367. * -FDT_ERR_BADVERSION,
  368. * -FDT_ERR_BADSTATE,
  369. * -FDT_ERR_BADSTRUCTURE,
  370. * -FDT_ERR_TRUNCATED, standard meanings.
  371. */
  372. int fdt_first_property_offset(const void *fdt, int nodeoffset);
  373. /**
  374. * fdt_next_property_offset - step through a node's properties
  375. * @fdt: pointer to the device tree blob
  376. * @offset: structure block offset of a property
  377. *
  378. * fdt_next_property_offset() finds the property immediately after the
  379. * one at the given structure block offset. This will be a property
  380. * of the same node as the given property.
  381. *
  382. * returns:
  383. * structure block offset of the next property (>=0), on success
  384. * -FDT_ERR_NOTFOUND, if the given property is the last in its node
  385. * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
  386. * -FDT_ERR_BADMAGIC,
  387. * -FDT_ERR_BADVERSION,
  388. * -FDT_ERR_BADSTATE,
  389. * -FDT_ERR_BADSTRUCTURE,
  390. * -FDT_ERR_TRUNCATED, standard meanings.
  391. */
  392. int fdt_next_property_offset(const void *fdt, int offset);
  393. /**
  394. * fdt_get_property_by_offset - retrieve the property at a given offset
  395. * @fdt: pointer to the device tree blob
  396. * @offset: offset of the property to retrieve
  397. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  398. *
  399. * fdt_get_property_by_offset() retrieves a pointer to the
  400. * fdt_property structure within the device tree blob at the given
  401. * offset. If lenp is non-NULL, the length of the property value is
  402. * also returned, in the integer pointed to by lenp.
  403. *
  404. * returns:
  405. * pointer to the structure representing the property
  406. * if lenp is non-NULL, *lenp contains the length of the property
  407. * value (>=0)
  408. * NULL, on error
  409. * if lenp is non-NULL, *lenp contains an error code (<0):
  410. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
  411. * -FDT_ERR_BADMAGIC,
  412. * -FDT_ERR_BADVERSION,
  413. * -FDT_ERR_BADSTATE,
  414. * -FDT_ERR_BADSTRUCTURE,
  415. * -FDT_ERR_TRUNCATED, standard meanings
  416. */
  417. const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
  418. int offset,
  419. int *lenp);
  420. /**
  421. * fdt_get_property_namelen - find a property based on substring
  422. * @fdt: pointer to the device tree blob
  423. * @nodeoffset: offset of the node whose property to find
  424. * @name: name of the property to find
  425. * @namelen: number of characters of name to consider
  426. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  427. *
  428. * Identical to fdt_get_property_namelen(), but only examine the first
  429. * namelen characters of name for matching the property name.
  430. */
  431. const struct fdt_property *fdt_get_property_namelen(const void *fdt,
  432. int nodeoffset,
  433. const char *name,
  434. int namelen, int *lenp);
  435. /**
  436. * fdt_get_property - find a given property in a given node
  437. * @fdt: pointer to the device tree blob
  438. * @nodeoffset: offset of the node whose property to find
  439. * @name: name of the property to find
  440. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  441. *
  442. * fdt_get_property() retrieves a pointer to the fdt_property
  443. * structure within the device tree blob corresponding to the property
  444. * named 'name' of the node at offset nodeoffset. If lenp is
  445. * non-NULL, the length of the property value is also returned, in the
  446. * integer pointed to by lenp.
  447. *
  448. * returns:
  449. * pointer to the structure representing the property
  450. * if lenp is non-NULL, *lenp contains the length of the property
  451. * value (>=0)
  452. * NULL, on error
  453. * if lenp is non-NULL, *lenp contains an error code (<0):
  454. * -FDT_ERR_NOTFOUND, node does not have named property
  455. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  456. * -FDT_ERR_BADMAGIC,
  457. * -FDT_ERR_BADVERSION,
  458. * -FDT_ERR_BADSTATE,
  459. * -FDT_ERR_BADSTRUCTURE,
  460. * -FDT_ERR_TRUNCATED, standard meanings
  461. */
  462. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  463. const char *name, int *lenp);
  464. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  465. const char *name,
  466. int *lenp)
  467. {
  468. return (struct fdt_property *)(uintptr_t)
  469. fdt_get_property(fdt, nodeoffset, name, lenp);
  470. }
  471. /**
  472. * fdt_getprop_by_offset - retrieve the value of a property at a given offset
  473. * @fdt: pointer to the device tree blob
  474. * @ffset: offset of the property to read
  475. * @namep: pointer to a string variable (will be overwritten) or NULL
  476. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  477. *
  478. * fdt_getprop_by_offset() retrieves a pointer to the value of the
  479. * property at structure block offset 'offset' (this will be a pointer
  480. * to within the device blob itself, not a copy of the value). If
  481. * lenp is non-NULL, the length of the property value is also
  482. * returned, in the integer pointed to by lenp. If namep is non-NULL,
  483. * the property's namne will also be returned in the char * pointed to
  484. * by namep (this will be a pointer to within the device tree's string
  485. * block, not a new copy of the name).
  486. *
  487. * returns:
  488. * pointer to the property's value
  489. * if lenp is non-NULL, *lenp contains the length of the property
  490. * value (>=0)
  491. * if namep is non-NULL *namep contiains a pointer to the property
  492. * name.
  493. * NULL, on error
  494. * if lenp is non-NULL, *lenp contains an error code (<0):
  495. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
  496. * -FDT_ERR_BADMAGIC,
  497. * -FDT_ERR_BADVERSION,
  498. * -FDT_ERR_BADSTATE,
  499. * -FDT_ERR_BADSTRUCTURE,
  500. * -FDT_ERR_TRUNCATED, standard meanings
  501. */
  502. const void *fdt_getprop_by_offset(const void *fdt, int offset,
  503. const char **namep, int *lenp);
  504. /**
  505. * fdt_getprop_namelen - get property value based on substring
  506. * @fdt: pointer to the device tree blob
  507. * @nodeoffset: offset of the node whose property to find
  508. * @name: name of the property to find
  509. * @namelen: number of characters of name to consider
  510. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  511. *
  512. * Identical to fdt_getprop(), but only examine the first namelen
  513. * characters of name for matching the property name.
  514. */
  515. const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
  516. const char *name, int namelen, int *lenp);
  517. /**
  518. * fdt_getprop - retrieve the value of a given property
  519. * @fdt: pointer to the device tree blob
  520. * @nodeoffset: offset of the node whose property to find
  521. * @name: name of the property to find
  522. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  523. *
  524. * fdt_getprop() retrieves a pointer to the value of the property
  525. * named 'name' of the node at offset nodeoffset (this will be a
  526. * pointer to within the device blob itself, not a copy of the value).
  527. * If lenp is non-NULL, the length of the property value is also
  528. * returned, in the integer pointed to by lenp.
  529. *
  530. * returns:
  531. * pointer to the property's value
  532. * if lenp is non-NULL, *lenp contains the length of the property
  533. * value (>=0)
  534. * NULL, on error
  535. * if lenp is non-NULL, *lenp contains an error code (<0):
  536. * -FDT_ERR_NOTFOUND, node does not have named property
  537. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  538. * -FDT_ERR_BADMAGIC,
  539. * -FDT_ERR_BADVERSION,
  540. * -FDT_ERR_BADSTATE,
  541. * -FDT_ERR_BADSTRUCTURE,
  542. * -FDT_ERR_TRUNCATED, standard meanings
  543. */
  544. const void *fdt_getprop(const void *fdt, int nodeoffset,
  545. const char *name, int *lenp);
  546. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  547. const char *name, int *lenp)
  548. {
  549. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  550. }
  551. /**
  552. * fdt_get_phandle - retrieve the phandle of a given node
  553. * @fdt: pointer to the device tree blob
  554. * @nodeoffset: structure block offset of the node
  555. *
  556. * fdt_get_phandle() retrieves the phandle of the device tree node at
  557. * structure block offset nodeoffset.
  558. *
  559. * returns:
  560. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  561. * 0, if the node has no phandle, or another error occurs
  562. */
  563. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  564. /**
  565. * fdt_get_alias_namelen - get alias based on substring
  566. * @fdt: pointer to the device tree blob
  567. * @name: name of the alias th look up
  568. * @namelen: number of characters of name to consider
  569. *
  570. * Identical to fdt_get_alias(), but only examine the first namelen
  571. * characters of name for matching the alias name.
  572. */
  573. const char *fdt_get_alias_namelen(const void *fdt,
  574. const char *name, int namelen);
  575. /**
  576. * fdt_get_alias - retreive the path referenced by a given alias
  577. * @fdt: pointer to the device tree blob
  578. * @name: name of the alias th look up
  579. *
  580. * fdt_get_alias() retrieves the value of a given alias. That is, the
  581. * value of the property named 'name' in the node /aliases.
  582. *
  583. * returns:
  584. * a pointer to the expansion of the alias named 'name', if it exists
  585. * NULL, if the given alias or the /aliases node does not exist
  586. */
  587. const char *fdt_get_alias(const void *fdt, const char *name);
  588. /**
  589. * fdt_get_path - determine the full path of a node
  590. * @fdt: pointer to the device tree blob
  591. * @nodeoffset: offset of the node whose path to find
  592. * @buf: character buffer to contain the returned path (will be overwritten)
  593. * @buflen: size of the character buffer at buf
  594. *
  595. * fdt_get_path() computes the full path of the node at offset
  596. * nodeoffset, and records that path in the buffer at buf.
  597. *
  598. * NOTE: This function is expensive, as it must scan the device tree
  599. * structure from the start to nodeoffset.
  600. *
  601. * returns:
  602. * 0, on success
  603. * buf contains the absolute path of the node at
  604. * nodeoffset, as a NUL-terminated string.
  605. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  606. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  607. * characters and will not fit in the given buffer.
  608. * -FDT_ERR_BADMAGIC,
  609. * -FDT_ERR_BADVERSION,
  610. * -FDT_ERR_BADSTATE,
  611. * -FDT_ERR_BADSTRUCTURE, standard meanings
  612. */
  613. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  614. /**
  615. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  616. * @fdt: pointer to the device tree blob
  617. * @nodeoffset: offset of the node whose parent to find
  618. * @supernodedepth: depth of the ancestor to find
  619. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  620. *
  621. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  622. * at a specific depth from the root (where the root itself has depth
  623. * 0, its immediate subnodes depth 1 and so forth). So
  624. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  625. * will always return 0, the offset of the root node. If the node at
  626. * nodeoffset has depth D, then:
  627. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  628. * will return nodeoffset itself.
  629. *
  630. * NOTE: This function is expensive, as it must scan the device tree
  631. * structure from the start to nodeoffset.
  632. *
  633. * returns:
  634. * structure block offset of the node at node offset's ancestor
  635. * of depth supernodedepth (>=0), on success
  636. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  637. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
  638. * -FDT_ERR_BADMAGIC,
  639. * -FDT_ERR_BADVERSION,
  640. * -FDT_ERR_BADSTATE,
  641. * -FDT_ERR_BADSTRUCTURE, standard meanings
  642. */
  643. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  644. int supernodedepth, int *nodedepth);
  645. /**
  646. * fdt_node_depth - find the depth of a given node
  647. * @fdt: pointer to the device tree blob
  648. * @nodeoffset: offset of the node whose parent to find
  649. *
  650. * fdt_node_depth() finds the depth of a given node. The root node
  651. * has depth 0, its immediate subnodes depth 1 and so forth.
  652. *
  653. * NOTE: This function is expensive, as it must scan the device tree
  654. * structure from the start to nodeoffset.
  655. *
  656. * returns:
  657. * depth of the node at nodeoffset (>=0), on success
  658. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  659. * -FDT_ERR_BADMAGIC,
  660. * -FDT_ERR_BADVERSION,
  661. * -FDT_ERR_BADSTATE,
  662. * -FDT_ERR_BADSTRUCTURE, standard meanings
  663. */
  664. int fdt_node_depth(const void *fdt, int nodeoffset);
  665. /**
  666. * fdt_parent_offset - find the parent of a given node
  667. * @fdt: pointer to the device tree blob
  668. * @nodeoffset: offset of the node whose parent to find
  669. *
  670. * fdt_parent_offset() locates the parent node of a given node (that
  671. * is, it finds the offset of the node which contains the node at
  672. * nodeoffset as a subnode).
  673. *
  674. * NOTE: This function is expensive, as it must scan the device tree
  675. * structure from the start to nodeoffset, *twice*.
  676. *
  677. * returns:
  678. * structure block offset of the parent of the node at nodeoffset
  679. * (>=0), on success
  680. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  681. * -FDT_ERR_BADMAGIC,
  682. * -FDT_ERR_BADVERSION,
  683. * -FDT_ERR_BADSTATE,
  684. * -FDT_ERR_BADSTRUCTURE, standard meanings
  685. */
  686. int fdt_parent_offset(const void *fdt, int nodeoffset);
  687. /**
  688. * fdt_node_offset_by_prop_value - find nodes with a given property value
  689. * @fdt: pointer to the device tree blob
  690. * @startoffset: only find nodes after this offset
  691. * @propname: property name to check
  692. * @propval: property value to search for
  693. * @proplen: length of the value in propval
  694. *
  695. * fdt_node_offset_by_prop_value() returns the offset of the first
  696. * node after startoffset, which has a property named propname whose
  697. * value is of length proplen and has value equal to propval; or if
  698. * startoffset is -1, the very first such node in the tree.
  699. *
  700. * To iterate through all nodes matching the criterion, the following
  701. * idiom can be used:
  702. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  703. * propval, proplen);
  704. * while (offset != -FDT_ERR_NOTFOUND) {
  705. * // other code here
  706. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  707. * propval, proplen);
  708. * }
  709. *
  710. * Note the -1 in the first call to the function, if 0 is used here
  711. * instead, the function will never locate the root node, even if it
  712. * matches the criterion.
  713. *
  714. * returns:
  715. * structure block offset of the located node (>= 0, >startoffset),
  716. * on success
  717. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  718. * tree after startoffset
  719. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  720. * -FDT_ERR_BADMAGIC,
  721. * -FDT_ERR_BADVERSION,
  722. * -FDT_ERR_BADSTATE,
  723. * -FDT_ERR_BADSTRUCTURE, standard meanings
  724. */
  725. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  726. const char *propname,
  727. const void *propval, int proplen);
  728. /**
  729. * fdt_node_offset_by_phandle - find the node with a given phandle
  730. * @fdt: pointer to the device tree blob
  731. * @phandle: phandle value
  732. *
  733. * fdt_node_offset_by_phandle() returns the offset of the node
  734. * which has the given phandle value. If there is more than one node
  735. * in the tree with the given phandle (an invalid tree), results are
  736. * undefined.
  737. *
  738. * returns:
  739. * structure block offset of the located node (>= 0), on success
  740. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  741. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  742. * -FDT_ERR_BADMAGIC,
  743. * -FDT_ERR_BADVERSION,
  744. * -FDT_ERR_BADSTATE,
  745. * -FDT_ERR_BADSTRUCTURE, standard meanings
  746. */
  747. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  748. /**
  749. * fdt_node_check_compatible: check a node's compatible property
  750. * @fdt: pointer to the device tree blob
  751. * @nodeoffset: offset of a tree node
  752. * @compatible: string to match against
  753. *
  754. *
  755. * fdt_node_check_compatible() returns 0 if the given node contains a
  756. * 'compatible' property with the given string as one of its elements,
  757. * it returns non-zero otherwise, or on error.
  758. *
  759. * returns:
  760. * 0, if the node has a 'compatible' property listing the given string
  761. * 1, if the node has a 'compatible' property, but it does not list
  762. * the given string
  763. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  764. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  765. * -FDT_ERR_BADMAGIC,
  766. * -FDT_ERR_BADVERSION,
  767. * -FDT_ERR_BADSTATE,
  768. * -FDT_ERR_BADSTRUCTURE, standard meanings
  769. */
  770. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  771. const char *compatible);
  772. /**
  773. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  774. * @fdt: pointer to the device tree blob
  775. * @startoffset: only find nodes after this offset
  776. * @compatible: 'compatible' string to match against
  777. *
  778. * fdt_node_offset_by_compatible() returns the offset of the first
  779. * node after startoffset, which has a 'compatible' property which
  780. * lists the given compatible string; or if startoffset is -1, the
  781. * very first such node in the tree.
  782. *
  783. * To iterate through all nodes matching the criterion, the following
  784. * idiom can be used:
  785. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  786. * while (offset != -FDT_ERR_NOTFOUND) {
  787. * // other code here
  788. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  789. * }
  790. *
  791. * Note the -1 in the first call to the function, if 0 is used here
  792. * instead, the function will never locate the root node, even if it
  793. * matches the criterion.
  794. *
  795. * returns:
  796. * structure block offset of the located node (>= 0, >startoffset),
  797. * on success
  798. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  799. * tree after startoffset
  800. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  801. * -FDT_ERR_BADMAGIC,
  802. * -FDT_ERR_BADVERSION,
  803. * -FDT_ERR_BADSTATE,
  804. * -FDT_ERR_BADSTRUCTURE, standard meanings
  805. */
  806. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  807. const char *compatible);
  808. /**
  809. * fdt_stringlist_contains - check a string list property for a string
  810. * @strlist: Property containing a list of strings to check
  811. * @listlen: Length of property
  812. * @str: String to search for
  813. *
  814. * This is a utility function provided for convenience. The list contains
  815. * one or more strings, each terminated by \0, as is found in a device tree
  816. * "compatible" property.
  817. *
  818. * @return: 1 if the string is found in the list, 0 not found, or invalid list
  819. */
  820. int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
  821. /**********************************************************************/
  822. /* Read-only functions (addressing related) */
  823. /**********************************************************************/
  824. /**
  825. * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
  826. *
  827. * This is the maximum value for #address-cells, #size-cells and
  828. * similar properties that will be processed by libfdt. IEE1275
  829. * requires that OF implementations handle values up to 4.
  830. * Implementations may support larger values, but in practice higher
  831. * values aren't used.
  832. */
  833. #define FDT_MAX_NCELLS 4
  834. /**
  835. * fdt_address_cells - retrieve address size for a bus represented in the tree
  836. * @fdt: pointer to the device tree blob
  837. * @nodeoffset: offset of the node to find the address size for
  838. *
  839. * When the node has a valid #address-cells property, returns its value.
  840. *
  841. * returns:
  842. * 0 <= n < FDT_MAX_NCELLS, on success
  843. * 2, if the node has no #address-cells property
  844. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #address-cells property
  845. * -FDT_ERR_BADMAGIC,
  846. * -FDT_ERR_BADVERSION,
  847. * -FDT_ERR_BADSTATE,
  848. * -FDT_ERR_BADSTRUCTURE,
  849. * -FDT_ERR_TRUNCATED, standard meanings
  850. */
  851. int fdt_address_cells(const void *fdt, int nodeoffset);
  852. /**
  853. * fdt_size_cells - retrieve address range size for a bus represented in the
  854. * tree
  855. * @fdt: pointer to the device tree blob
  856. * @nodeoffset: offset of the node to find the address range size for
  857. *
  858. * When the node has a valid #size-cells property, returns its value.
  859. *
  860. * returns:
  861. * 0 <= n < FDT_MAX_NCELLS, on success
  862. * 2, if the node has no #address-cells property
  863. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #size-cells property
  864. * -FDT_ERR_BADMAGIC,
  865. * -FDT_ERR_BADVERSION,
  866. * -FDT_ERR_BADSTATE,
  867. * -FDT_ERR_BADSTRUCTURE,
  868. * -FDT_ERR_TRUNCATED, standard meanings
  869. */
  870. int fdt_size_cells(const void *fdt, int nodeoffset);
  871. /**********************************************************************/
  872. /* Write-in-place functions */
  873. /**********************************************************************/
  874. /**
  875. * fdt_setprop_inplace - change a property's value, but not its size
  876. * @fdt: pointer to the device tree blob
  877. * @nodeoffset: offset of the node whose property to change
  878. * @name: name of the property to change
  879. * @val: pointer to data to replace the property value with
  880. * @len: length of the property value
  881. *
  882. * fdt_setprop_inplace() replaces the value of a given property with
  883. * the data in val, of length len. This function cannot change the
  884. * size of a property, and so will only work if len is equal to the
  885. * current length of the property.
  886. *
  887. * This function will alter only the bytes in the blob which contain
  888. * the given property value, and will not alter or move any other part
  889. * of the tree.
  890. *
  891. * returns:
  892. * 0, on success
  893. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  894. * -FDT_ERR_NOTFOUND, node does not have the named property
  895. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  896. * -FDT_ERR_BADMAGIC,
  897. * -FDT_ERR_BADVERSION,
  898. * -FDT_ERR_BADSTATE,
  899. * -FDT_ERR_BADSTRUCTURE,
  900. * -FDT_ERR_TRUNCATED, standard meanings
  901. */
  902. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  903. const void *val, int len);
  904. /**
  905. * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
  906. * @fdt: pointer to the device tree blob
  907. * @nodeoffset: offset of the node whose property to change
  908. * @name: name of the property to change
  909. * @val: 32-bit integer value to replace the property with
  910. *
  911. * fdt_setprop_inplace_u32() replaces the value of a given property
  912. * with the 32-bit integer value in val, converting val to big-endian
  913. * if necessary. This function cannot change the size of a property,
  914. * and so will only work if the property already exists and has length
  915. * 4.
  916. *
  917. * This function will alter only the bytes in the blob which contain
  918. * the given property value, and will not alter or move any other part
  919. * of the tree.
  920. *
  921. * returns:
  922. * 0, on success
  923. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  924. * -FDT_ERR_NOTFOUND, node does not have the named property
  925. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  926. * -FDT_ERR_BADMAGIC,
  927. * -FDT_ERR_BADVERSION,
  928. * -FDT_ERR_BADSTATE,
  929. * -FDT_ERR_BADSTRUCTURE,
  930. * -FDT_ERR_TRUNCATED, standard meanings
  931. */
  932. static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
  933. const char *name, uint32_t val)
  934. {
  935. fdt32_t tmp = cpu_to_fdt32(val);
  936. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  937. }
  938. /**
  939. * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
  940. * @fdt: pointer to the device tree blob
  941. * @nodeoffset: offset of the node whose property to change
  942. * @name: name of the property to change
  943. * @val: 64-bit integer value to replace the property with
  944. *
  945. * fdt_setprop_inplace_u64() replaces the value of a given property
  946. * with the 64-bit integer value in val, converting val to big-endian
  947. * if necessary. This function cannot change the size of a property,
  948. * and so will only work if the property already exists and has length
  949. * 8.
  950. *
  951. * This function will alter only the bytes in the blob which contain
  952. * the given property value, and will not alter or move any other part
  953. * of the tree.
  954. *
  955. * returns:
  956. * 0, on success
  957. * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
  958. * -FDT_ERR_NOTFOUND, node does not have the named property
  959. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  960. * -FDT_ERR_BADMAGIC,
  961. * -FDT_ERR_BADVERSION,
  962. * -FDT_ERR_BADSTATE,
  963. * -FDT_ERR_BADSTRUCTURE,
  964. * -FDT_ERR_TRUNCATED, standard meanings
  965. */
  966. static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
  967. const char *name, uint64_t val)
  968. {
  969. fdt64_t tmp = cpu_to_fdt64(val);
  970. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  971. }
  972. /**
  973. * fdt_setprop_inplace_cell - change the value of a single-cell property
  974. *
  975. * This is an alternative name for fdt_setprop_inplace_u32()
  976. */
  977. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  978. const char *name, uint32_t val)
  979. {
  980. return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
  981. }
  982. /**
  983. * fdt_nop_property - replace a property with nop tags
  984. * @fdt: pointer to the device tree blob
  985. * @nodeoffset: offset of the node whose property to nop
  986. * @name: name of the property to nop
  987. *
  988. * fdt_nop_property() will replace a given property's representation
  989. * in the blob with FDT_NOP tags, effectively removing it from the
  990. * tree.
  991. *
  992. * This function will alter only the bytes in the blob which contain
  993. * the property, and will not alter or move any other part of the
  994. * tree.
  995. *
  996. * returns:
  997. * 0, on success
  998. * -FDT_ERR_NOTFOUND, node does not have the named property
  999. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1000. * -FDT_ERR_BADMAGIC,
  1001. * -FDT_ERR_BADVERSION,
  1002. * -FDT_ERR_BADSTATE,
  1003. * -FDT_ERR_BADSTRUCTURE,
  1004. * -FDT_ERR_TRUNCATED, standard meanings
  1005. */
  1006. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  1007. /**
  1008. * fdt_nop_node - replace a node (subtree) with nop tags
  1009. * @fdt: pointer to the device tree blob
  1010. * @nodeoffset: offset of the node to nop
  1011. *
  1012. * fdt_nop_node() will replace a given node's representation in the
  1013. * blob, including all its subnodes, if any, with FDT_NOP tags,
  1014. * effectively removing it from the tree.
  1015. *
  1016. * This function will alter only the bytes in the blob which contain
  1017. * the node and its properties and subnodes, and will not alter or
  1018. * move any other part of the tree.
  1019. *
  1020. * returns:
  1021. * 0, on success
  1022. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1023. * -FDT_ERR_BADMAGIC,
  1024. * -FDT_ERR_BADVERSION,
  1025. * -FDT_ERR_BADSTATE,
  1026. * -FDT_ERR_BADSTRUCTURE,
  1027. * -FDT_ERR_TRUNCATED, standard meanings
  1028. */
  1029. int fdt_nop_node(void *fdt, int nodeoffset);
  1030. /**********************************************************************/
  1031. /* Sequential write functions */
  1032. /**********************************************************************/
  1033. int fdt_create(void *buf, int bufsize);
  1034. int fdt_resize(void *fdt, void *buf, int bufsize);
  1035. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  1036. int fdt_finish_reservemap(void *fdt);
  1037. int fdt_begin_node(void *fdt, const char *name);
  1038. int fdt_property(void *fdt, const char *name, const void *val, int len);
  1039. static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
  1040. {
  1041. fdt32_t tmp = cpu_to_fdt32(val);
  1042. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1043. }
  1044. static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
  1045. {
  1046. fdt64_t tmp = cpu_to_fdt64(val);
  1047. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1048. }
  1049. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  1050. {
  1051. return fdt_property_u32(fdt, name, val);
  1052. }
  1053. #define fdt_property_string(fdt, name, str) \
  1054. fdt_property(fdt, name, str, strlen(str)+1)
  1055. int fdt_end_node(void *fdt);
  1056. int fdt_finish(void *fdt);
  1057. /**********************************************************************/
  1058. /* Read-write functions */
  1059. /**********************************************************************/
  1060. int fdt_create_empty_tree(void *buf, int bufsize);
  1061. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  1062. int fdt_pack(void *fdt);
  1063. /**
  1064. * fdt_add_mem_rsv - add one memory reserve map entry
  1065. * @fdt: pointer to the device tree blob
  1066. * @address, @size: 64-bit values (native endian)
  1067. *
  1068. * Adds a reserve map entry to the given blob reserving a region at
  1069. * address address of length size.
  1070. *
  1071. * This function will insert data into the reserve map and will
  1072. * therefore change the indexes of some entries in the table.
  1073. *
  1074. * returns:
  1075. * 0, on success
  1076. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1077. * contain the new reservation entry
  1078. * -FDT_ERR_BADMAGIC,
  1079. * -FDT_ERR_BADVERSION,
  1080. * -FDT_ERR_BADSTATE,
  1081. * -FDT_ERR_BADSTRUCTURE,
  1082. * -FDT_ERR_BADLAYOUT,
  1083. * -FDT_ERR_TRUNCATED, standard meanings
  1084. */
  1085. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  1086. /**
  1087. * fdt_del_mem_rsv - remove a memory reserve map entry
  1088. * @fdt: pointer to the device tree blob
  1089. * @n: entry to remove
  1090. *
  1091. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  1092. * the blob.
  1093. *
  1094. * This function will delete data from the reservation table and will
  1095. * therefore change the indexes of some entries in the table.
  1096. *
  1097. * returns:
  1098. * 0, on success
  1099. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  1100. * are less than n+1 reserve map entries)
  1101. * -FDT_ERR_BADMAGIC,
  1102. * -FDT_ERR_BADVERSION,
  1103. * -FDT_ERR_BADSTATE,
  1104. * -FDT_ERR_BADSTRUCTURE,
  1105. * -FDT_ERR_BADLAYOUT,
  1106. * -FDT_ERR_TRUNCATED, standard meanings
  1107. */
  1108. int fdt_del_mem_rsv(void *fdt, int n);
  1109. /**
  1110. * fdt_set_name - change the name of a given node
  1111. * @fdt: pointer to the device tree blob
  1112. * @nodeoffset: structure block offset of a node
  1113. * @name: name to give the node
  1114. *
  1115. * fdt_set_name() replaces the name (including unit address, if any)
  1116. * of the given node with the given string. NOTE: this function can't
  1117. * efficiently check if the new name is unique amongst the given
  1118. * node's siblings; results are undefined if this function is invoked
  1119. * with a name equal to one of the given node's siblings.
  1120. *
  1121. * This function may insert or delete data from the blob, and will
  1122. * therefore change the offsets of some existing nodes.
  1123. *
  1124. * returns:
  1125. * 0, on success
  1126. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  1127. * to contain the new name
  1128. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1129. * -FDT_ERR_BADMAGIC,
  1130. * -FDT_ERR_BADVERSION,
  1131. * -FDT_ERR_BADSTATE, standard meanings
  1132. */
  1133. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  1134. /**
  1135. * fdt_setprop - create or change a property
  1136. * @fdt: pointer to the device tree blob
  1137. * @nodeoffset: offset of the node whose property to change
  1138. * @name: name of the property to change
  1139. * @val: pointer to data to set the property value to
  1140. * @len: length of the property value
  1141. *
  1142. * fdt_setprop() sets the value of the named property in the given
  1143. * node to the given value and length, creating the property if it
  1144. * does not already exist.
  1145. *
  1146. * This function may insert or delete data from the blob, and will
  1147. * therefore change the offsets of some existing nodes.
  1148. *
  1149. * returns:
  1150. * 0, on success
  1151. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1152. * contain the new property value
  1153. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1154. * -FDT_ERR_BADLAYOUT,
  1155. * -FDT_ERR_BADMAGIC,
  1156. * -FDT_ERR_BADVERSION,
  1157. * -FDT_ERR_BADSTATE,
  1158. * -FDT_ERR_BADSTRUCTURE,
  1159. * -FDT_ERR_BADLAYOUT,
  1160. * -FDT_ERR_TRUNCATED, standard meanings
  1161. */
  1162. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  1163. const void *val, int len);
  1164. /**
  1165. * fdt_setprop_u32 - set a property to a 32-bit integer
  1166. * @fdt: pointer to the device tree blob
  1167. * @nodeoffset: offset of the node whose property to change
  1168. * @name: name of the property to change
  1169. * @val: 32-bit integer value for the property (native endian)
  1170. *
  1171. * fdt_setprop_u32() sets the value of the named property in the given
  1172. * node to the given 32-bit integer value (converting to big-endian if
  1173. * necessary), or creates a new property with that value if it does
  1174. * not already exist.
  1175. *
  1176. * This function may insert or delete data from the blob, and will
  1177. * therefore change the offsets of some existing nodes.
  1178. *
  1179. * returns:
  1180. * 0, on success
  1181. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1182. * contain the new property value
  1183. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1184. * -FDT_ERR_BADLAYOUT,
  1185. * -FDT_ERR_BADMAGIC,
  1186. * -FDT_ERR_BADVERSION,
  1187. * -FDT_ERR_BADSTATE,
  1188. * -FDT_ERR_BADSTRUCTURE,
  1189. * -FDT_ERR_BADLAYOUT,
  1190. * -FDT_ERR_TRUNCATED, standard meanings
  1191. */
  1192. static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
  1193. uint32_t val)
  1194. {
  1195. fdt32_t tmp = cpu_to_fdt32(val);
  1196. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1197. }
  1198. /**
  1199. * fdt_setprop_u64 - set a property to a 64-bit integer
  1200. * @fdt: pointer to the device tree blob
  1201. * @nodeoffset: offset of the node whose property to change
  1202. * @name: name of the property to change
  1203. * @val: 64-bit integer value for the property (native endian)
  1204. *
  1205. * fdt_setprop_u64() sets the value of the named property in the given
  1206. * node to the given 64-bit integer value (converting to big-endian if
  1207. * necessary), or creates a new property with that value if it does
  1208. * not already exist.
  1209. *
  1210. * This function may insert or delete data from the blob, and will
  1211. * therefore change the offsets of some existing nodes.
  1212. *
  1213. * returns:
  1214. * 0, on success
  1215. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1216. * contain the new property value
  1217. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1218. * -FDT_ERR_BADLAYOUT,
  1219. * -FDT_ERR_BADMAGIC,
  1220. * -FDT_ERR_BADVERSION,
  1221. * -FDT_ERR_BADSTATE,
  1222. * -FDT_ERR_BADSTRUCTURE,
  1223. * -FDT_ERR_BADLAYOUT,
  1224. * -FDT_ERR_TRUNCATED, standard meanings
  1225. */
  1226. static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
  1227. uint64_t val)
  1228. {
  1229. fdt64_t tmp = cpu_to_fdt64(val);
  1230. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1231. }
  1232. /**
  1233. * fdt_setprop_cell - set a property to a single cell value
  1234. *
  1235. * This is an alternative name for fdt_setprop_u32()
  1236. */
  1237. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  1238. uint32_t val)
  1239. {
  1240. return fdt_setprop_u32(fdt, nodeoffset, name, val);
  1241. }
  1242. /**
  1243. * fdt_setprop_string - set a property to a string value
  1244. * @fdt: pointer to the device tree blob
  1245. * @nodeoffset: offset of the node whose property to change
  1246. * @name: name of the property to change
  1247. * @str: string value for the property
  1248. *
  1249. * fdt_setprop_string() sets the value of the named property in the
  1250. * given node to the given string value (using the length of the
  1251. * string to determine the new length of the property), or creates a
  1252. * new property with that value if it does not already exist.
  1253. *
  1254. * This function may insert or delete data from the blob, and will
  1255. * therefore change the offsets of some existing nodes.
  1256. *
  1257. * returns:
  1258. * 0, on success
  1259. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1260. * contain the new property value
  1261. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1262. * -FDT_ERR_BADLAYOUT,
  1263. * -FDT_ERR_BADMAGIC,
  1264. * -FDT_ERR_BADVERSION,
  1265. * -FDT_ERR_BADSTATE,
  1266. * -FDT_ERR_BADSTRUCTURE,
  1267. * -FDT_ERR_BADLAYOUT,
  1268. * -FDT_ERR_TRUNCATED, standard meanings
  1269. */
  1270. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  1271. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1272. /**
  1273. * fdt_appendprop - append to or create a property
  1274. * @fdt: pointer to the device tree blob
  1275. * @nodeoffset: offset of the node whose property to change
  1276. * @name: name of the property to append to
  1277. * @val: pointer to data to append to the property value
  1278. * @len: length of the data to append to the property value
  1279. *
  1280. * fdt_appendprop() appends the value to the named property in the
  1281. * given node, creating the property if it does not already exist.
  1282. *
  1283. * This function may insert data into the blob, and will therefore
  1284. * change the offsets of some existing nodes.
  1285. *
  1286. * returns:
  1287. * 0, on success
  1288. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1289. * contain the new property value
  1290. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1291. * -FDT_ERR_BADLAYOUT,
  1292. * -FDT_ERR_BADMAGIC,
  1293. * -FDT_ERR_BADVERSION,
  1294. * -FDT_ERR_BADSTATE,
  1295. * -FDT_ERR_BADSTRUCTURE,
  1296. * -FDT_ERR_BADLAYOUT,
  1297. * -FDT_ERR_TRUNCATED, standard meanings
  1298. */
  1299. int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
  1300. const void *val, int len);
  1301. /**
  1302. * fdt_appendprop_u32 - append a 32-bit integer value to a property
  1303. * @fdt: pointer to the device tree blob
  1304. * @nodeoffset: offset of the node whose property to change
  1305. * @name: name of the property to change
  1306. * @val: 32-bit integer value to append to the property (native endian)
  1307. *
  1308. * fdt_appendprop_u32() appends the given 32-bit integer value
  1309. * (converting to big-endian if necessary) to the value of the named
  1310. * property in the given node, or creates a new property with that
  1311. * value if it does not already exist.
  1312. *
  1313. * This function may insert data into the blob, and will therefore
  1314. * change the offsets of some existing nodes.
  1315. *
  1316. * returns:
  1317. * 0, on success
  1318. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1319. * contain the new property value
  1320. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1321. * -FDT_ERR_BADLAYOUT,
  1322. * -FDT_ERR_BADMAGIC,
  1323. * -FDT_ERR_BADVERSION,
  1324. * -FDT_ERR_BADSTATE,
  1325. * -FDT_ERR_BADSTRUCTURE,
  1326. * -FDT_ERR_BADLAYOUT,
  1327. * -FDT_ERR_TRUNCATED, standard meanings
  1328. */
  1329. static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
  1330. const char *name, uint32_t val)
  1331. {
  1332. fdt32_t tmp = cpu_to_fdt32(val);
  1333. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1334. }
  1335. /**
  1336. * fdt_appendprop_u64 - append a 64-bit integer value to a property
  1337. * @fdt: pointer to the device tree blob
  1338. * @nodeoffset: offset of the node whose property to change
  1339. * @name: name of the property to change
  1340. * @val: 64-bit integer value to append to the property (native endian)
  1341. *
  1342. * fdt_appendprop_u64() appends the given 64-bit integer value
  1343. * (converting to big-endian if necessary) to the value of the named
  1344. * property in the given node, or creates a new property with that
  1345. * value if it does not already exist.
  1346. *
  1347. * This function may insert data into the blob, and will therefore
  1348. * change the offsets of some existing nodes.
  1349. *
  1350. * returns:
  1351. * 0, on success
  1352. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1353. * contain the new property value
  1354. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1355. * -FDT_ERR_BADLAYOUT,
  1356. * -FDT_ERR_BADMAGIC,
  1357. * -FDT_ERR_BADVERSION,
  1358. * -FDT_ERR_BADSTATE,
  1359. * -FDT_ERR_BADSTRUCTURE,
  1360. * -FDT_ERR_BADLAYOUT,
  1361. * -FDT_ERR_TRUNCATED, standard meanings
  1362. */
  1363. static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
  1364. const char *name, uint64_t val)
  1365. {
  1366. fdt64_t tmp = cpu_to_fdt64(val);
  1367. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1368. }
  1369. /**
  1370. * fdt_appendprop_cell - append a single cell value to a property
  1371. *
  1372. * This is an alternative name for fdt_appendprop_u32()
  1373. */
  1374. static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
  1375. const char *name, uint32_t val)
  1376. {
  1377. return fdt_appendprop_u32(fdt, nodeoffset, name, val);
  1378. }
  1379. /**
  1380. * fdt_appendprop_string - append a string to a property
  1381. * @fdt: pointer to the device tree blob
  1382. * @nodeoffset: offset of the node whose property to change
  1383. * @name: name of the property to change
  1384. * @str: string value to append to the property
  1385. *
  1386. * fdt_appendprop_string() appends the given string to the value of
  1387. * the named property in the given node, or creates a new property
  1388. * with that value if it does not already exist.
  1389. *
  1390. * This function may insert data into the blob, and will therefore
  1391. * change the offsets of some existing nodes.
  1392. *
  1393. * returns:
  1394. * 0, on success
  1395. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1396. * contain the new property value
  1397. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1398. * -FDT_ERR_BADLAYOUT,
  1399. * -FDT_ERR_BADMAGIC,
  1400. * -FDT_ERR_BADVERSION,
  1401. * -FDT_ERR_BADSTATE,
  1402. * -FDT_ERR_BADSTRUCTURE,
  1403. * -FDT_ERR_BADLAYOUT,
  1404. * -FDT_ERR_TRUNCATED, standard meanings
  1405. */
  1406. #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
  1407. fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1408. /**
  1409. * fdt_delprop - delete a property
  1410. * @fdt: pointer to the device tree blob
  1411. * @nodeoffset: offset of the node whose property to nop
  1412. * @name: name of the property to nop
  1413. *
  1414. * fdt_del_property() will delete the given property.
  1415. *
  1416. * This function will delete data from the blob, and will therefore
  1417. * change the offsets of some existing nodes.
  1418. *
  1419. * returns:
  1420. * 0, on success
  1421. * -FDT_ERR_NOTFOUND, node does not have the named property
  1422. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1423. * -FDT_ERR_BADLAYOUT,
  1424. * -FDT_ERR_BADMAGIC,
  1425. * -FDT_ERR_BADVERSION,
  1426. * -FDT_ERR_BADSTATE,
  1427. * -FDT_ERR_BADSTRUCTURE,
  1428. * -FDT_ERR_TRUNCATED, standard meanings
  1429. */
  1430. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  1431. /**
  1432. * fdt_add_subnode_namelen - creates a new node based on substring
  1433. * @fdt: pointer to the device tree blob
  1434. * @parentoffset: structure block offset of a node
  1435. * @name: name of the subnode to locate
  1436. * @namelen: number of characters of name to consider
  1437. *
  1438. * Identical to fdt_add_subnode(), but use only the first namelen
  1439. * characters of name as the name of the new node. This is useful for
  1440. * creating subnodes based on a portion of a larger string, such as a
  1441. * full path.
  1442. */
  1443. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  1444. const char *name, int namelen);
  1445. /**
  1446. * fdt_add_subnode - creates a new node
  1447. * @fdt: pointer to the device tree blob
  1448. * @parentoffset: structure block offset of a node
  1449. * @name: name of the subnode to locate
  1450. *
  1451. * fdt_add_subnode() creates a new node as a subnode of the node at
  1452. * structure block offset parentoffset, with the given name (which
  1453. * should include the unit address, if any).
  1454. *
  1455. * This function will insert data into the blob, and will therefore
  1456. * change the offsets of some existing nodes.
  1457. * returns:
  1458. * structure block offset of the created nodeequested subnode (>=0), on success
  1459. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  1460. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  1461. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  1462. * the given name
  1463. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  1464. * blob to contain the new node
  1465. * -FDT_ERR_NOSPACE
  1466. * -FDT_ERR_BADLAYOUT
  1467. * -FDT_ERR_BADMAGIC,
  1468. * -FDT_ERR_BADVERSION,
  1469. * -FDT_ERR_BADSTATE,
  1470. * -FDT_ERR_BADSTRUCTURE,
  1471. * -FDT_ERR_TRUNCATED, standard meanings.
  1472. */
  1473. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  1474. /**
  1475. * fdt_del_node - delete a node (subtree)
  1476. * @fdt: pointer to the device tree blob
  1477. * @nodeoffset: offset of the node to nop
  1478. *
  1479. * fdt_del_node() will remove the given node, including all its
  1480. * subnodes if any, from the blob.
  1481. *
  1482. * This function will delete data from the blob, and will therefore
  1483. * change the offsets of some existing nodes.
  1484. *
  1485. * returns:
  1486. * 0, on success
  1487. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1488. * -FDT_ERR_BADLAYOUT,
  1489. * -FDT_ERR_BADMAGIC,
  1490. * -FDT_ERR_BADVERSION,
  1491. * -FDT_ERR_BADSTATE,
  1492. * -FDT_ERR_BADSTRUCTURE,
  1493. * -FDT_ERR_TRUNCATED, standard meanings
  1494. */
  1495. int fdt_del_node(void *fdt, int nodeoffset);
  1496. /**********************************************************************/
  1497. /* Debugging / informational functions */
  1498. /**********************************************************************/
  1499. const char *fdt_strerror(int errval);
  1500. #endif /* _LIBFDT_H */