libfdt.h 62 KB

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