libfdt.h 60 KB

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