libfdt.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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 */