libfdt.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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. #define FDT_ERR_MAX 13
  113. /**********************************************************************/
  114. /* Low-level functions (you probably don't need these) */
  115. /**********************************************************************/
  116. const void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
  117. static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  118. {
  119. return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
  120. }
  121. uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
  122. /**********************************************************************/
  123. /* Traversal functions */
  124. /**********************************************************************/
  125. int fdt_next_node(const void *fdt, int offset, int *depth);
  126. /**********************************************************************/
  127. /* General functions */
  128. /**********************************************************************/
  129. #define fdt_get_header(fdt, field) \
  130. (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
  131. #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
  132. #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
  133. #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
  134. #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
  135. #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
  136. #define fdt_version(fdt) (fdt_get_header(fdt, version))
  137. #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
  138. #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
  139. #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
  140. #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
  141. #define __fdt_set_hdr(name) \
  142. static inline void fdt_set_##name(void *fdt, uint32_t val) \
  143. { \
  144. struct fdt_header *fdth = fdt; \
  145. fdth->name = cpu_to_fdt32(val); \
  146. }
  147. __fdt_set_hdr(magic);
  148. __fdt_set_hdr(totalsize);
  149. __fdt_set_hdr(off_dt_struct);
  150. __fdt_set_hdr(off_dt_strings);
  151. __fdt_set_hdr(off_mem_rsvmap);
  152. __fdt_set_hdr(version);
  153. __fdt_set_hdr(last_comp_version);
  154. __fdt_set_hdr(boot_cpuid_phys);
  155. __fdt_set_hdr(size_dt_strings);
  156. __fdt_set_hdr(size_dt_struct);
  157. #undef __fdt_set_hdr
  158. /**
  159. * fdt_check_header - sanity check a device tree or possible device tree
  160. * @fdt: pointer to data which might be a flattened device tree
  161. *
  162. * fdt_check_header() checks that the given buffer contains what
  163. * appears to be a flattened device tree with sane information in its
  164. * header.
  165. *
  166. * returns:
  167. * 0, if the buffer appears to contain a valid device tree
  168. * -FDT_ERR_BADMAGIC,
  169. * -FDT_ERR_BADVERSION,
  170. * -FDT_ERR_BADSTATE, standard meanings, as above
  171. */
  172. int fdt_check_header(const void *fdt);
  173. /**
  174. * fdt_move - move a device tree around in memory
  175. * @fdt: pointer to the device tree to move
  176. * @buf: pointer to memory where the device is to be moved
  177. * @bufsize: size of the memory space at buf
  178. *
  179. * fdt_move() relocates, if possible, the device tree blob located at
  180. * fdt to the buffer at buf of size bufsize. The buffer may overlap
  181. * with the existing device tree blob at fdt. Therefore,
  182. * fdt_move(fdt, fdt, fdt_totalsize(fdt))
  183. * should always succeed.
  184. *
  185. * returns:
  186. * 0, on success
  187. * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
  188. * -FDT_ERR_BADMAGIC,
  189. * -FDT_ERR_BADVERSION,
  190. * -FDT_ERR_BADSTATE, standard meanings
  191. */
  192. int fdt_move(const void *fdt, void *buf, int bufsize);
  193. /**********************************************************************/
  194. /* Read-only functions */
  195. /**********************************************************************/
  196. /**
  197. * fdt_string - retrieve a string from the strings block of a device tree
  198. * @fdt: pointer to the device tree blob
  199. * @stroffset: offset of the string within the strings block (native endian)
  200. *
  201. * fdt_string() retrieves a pointer to a single string from the
  202. * strings block of the device tree blob at fdt.
  203. *
  204. * returns:
  205. * a pointer to the string, on success
  206. * NULL, if stroffset is out of bounds
  207. */
  208. const char *fdt_string(const void *fdt, int stroffset);
  209. /**
  210. * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
  211. * @fdt: pointer to the device tree blob
  212. *
  213. * Returns the number of entries in the device tree blob's memory
  214. * reservation map. This does not include the terminating 0,0 entry
  215. * or any other (0,0) entries reserved for expansion.
  216. *
  217. * returns:
  218. * the number of entries
  219. */
  220. int fdt_num_mem_rsv(const void *fdt);
  221. /**
  222. * fdt_get_mem_rsv - retrieve one memory reserve map entry
  223. * @fdt: pointer to the device tree blob
  224. * @address, @size: pointers to 64-bit variables
  225. *
  226. * On success, *address and *size will contain the address and size of
  227. * the n-th reserve map entry from the device tree blob, in
  228. * native-endian format.
  229. *
  230. * returns:
  231. * 0, on success
  232. * -FDT_ERR_BADMAGIC,
  233. * -FDT_ERR_BADVERSION,
  234. * -FDT_ERR_BADSTATE, standard meanings
  235. */
  236. int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
  237. /**
  238. * fdt_subnode_offset_namelen - find a subnode based on substring
  239. * @fdt: pointer to the device tree blob
  240. * @parentoffset: structure block offset of a node
  241. * @name: name of the subnode to locate
  242. * @namelen: number of characters of name to consider
  243. *
  244. * Identical to fdt_subnode_offset(), but only examine the first
  245. * namelen characters of name for matching the subnode name. This is
  246. * useful for finding subnodes based on a portion of a larger string,
  247. * such as a full path.
  248. */
  249. int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
  250. const char *name, int namelen);
  251. /**
  252. * fdt_subnode_offset - find a subnode of a given node
  253. * @fdt: pointer to the device tree blob
  254. * @parentoffset: structure block offset of a node
  255. * @name: name of the subnode to locate
  256. *
  257. * fdt_subnode_offset() finds a subnode of the node at structure block
  258. * offset parentoffset with the given name. name may include a unit
  259. * address, in which case fdt_subnode_offset() will find the subnode
  260. * with that unit address, or the unit address may be omitted, in
  261. * which case fdt_subnode_offset() will find an arbitrary subnode
  262. * whose name excluding unit address matches the given name.
  263. *
  264. * returns:
  265. * structure block offset of the requested subnode (>=0), on success
  266. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  267. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  268. * -FDT_ERR_BADMAGIC,
  269. * -FDT_ERR_BADVERSION,
  270. * -FDT_ERR_BADSTATE,
  271. * -FDT_ERR_BADSTRUCTURE,
  272. * -FDT_ERR_TRUNCATED, standard meanings.
  273. */
  274. int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
  275. /**
  276. * fdt_path_offset - find a tree node by its full path
  277. * @fdt: pointer to the device tree blob
  278. * @path: full path of the node to locate
  279. *
  280. * fdt_path_offset() finds a node of a given path in the device tree.
  281. * Each path component may omit the unit address portion, but the
  282. * results of this are undefined if any such path component is
  283. * ambiguous (that is if there are multiple nodes at the relevant
  284. * level matching the given component, differentiated only by unit
  285. * address).
  286. *
  287. * returns:
  288. * structure block offset of the node with the requested path (>=0), on success
  289. * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
  290. * -FDT_ERR_NOTFOUND, if the requested node does not exist
  291. * -FDT_ERR_BADMAGIC,
  292. * -FDT_ERR_BADVERSION,
  293. * -FDT_ERR_BADSTATE,
  294. * -FDT_ERR_BADSTRUCTURE,
  295. * -FDT_ERR_TRUNCATED, standard meanings.
  296. */
  297. int fdt_path_offset(const void *fdt, const char *path);
  298. /**
  299. * fdt_get_name - retrieve the name of a given node
  300. * @fdt: pointer to the device tree blob
  301. * @nodeoffset: structure block offset of the starting node
  302. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  303. *
  304. * fdt_get_name() retrieves the name (including unit address) of the
  305. * device tree node at structure block offset nodeoffset. If lenp is
  306. * non-NULL, the length of this name is also returned, in the integer
  307. * pointed to by lenp.
  308. *
  309. * returns:
  310. * pointer to the node's name, on success
  311. * If lenp is non-NULL, *lenp contains the length of that name (>=0)
  312. * NULL, on error
  313. * if lenp is non-NULL *lenp contains an error code (<0):
  314. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  315. * -FDT_ERR_BADMAGIC,
  316. * -FDT_ERR_BADVERSION,
  317. * -FDT_ERR_BADSTATE, standard meanings
  318. */
  319. const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
  320. /**
  321. * fdt_get_property_namelen - find a property based on substring
  322. * @fdt: pointer to the device tree blob
  323. * @nodeoffset: offset of the node whose property to find
  324. * @name: name of the property to find
  325. * @namelen: number of characters of name to consider
  326. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  327. *
  328. * Identical to fdt_get_property_namelen(), but only examine the first
  329. * namelen characters of name for matching the property name.
  330. */
  331. const struct fdt_property *fdt_get_property_namelen(const void *fdt,
  332. int nodeoffset,
  333. const char *name,
  334. int namelen, int *lenp);
  335. /**
  336. * fdt_get_property - find a given property in a given node
  337. * @fdt: pointer to the device tree blob
  338. * @nodeoffset: offset of the node whose property to find
  339. * @name: name of the property to find
  340. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  341. *
  342. * fdt_get_property() retrieves a pointer to the fdt_property
  343. * structure within the device tree blob corresponding to the property
  344. * named 'name' of the node at offset nodeoffset. If lenp is
  345. * non-NULL, the length of the property value is also returned, in the
  346. * integer pointed to by lenp.
  347. *
  348. * returns:
  349. * pointer to the structure representing the property
  350. * if lenp is non-NULL, *lenp contains the length of the property
  351. * value (>=0)
  352. * NULL, on error
  353. * if lenp is non-NULL, *lenp contains an error code (<0):
  354. * -FDT_ERR_NOTFOUND, node does not have named property
  355. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  356. * -FDT_ERR_BADMAGIC,
  357. * -FDT_ERR_BADVERSION,
  358. * -FDT_ERR_BADSTATE,
  359. * -FDT_ERR_BADSTRUCTURE,
  360. * -FDT_ERR_TRUNCATED, standard meanings
  361. */
  362. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  363. const char *name, int *lenp);
  364. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  365. const char *name,
  366. int *lenp)
  367. {
  368. return (struct fdt_property *)(uintptr_t)
  369. fdt_get_property(fdt, nodeoffset, name, lenp);
  370. }
  371. /**
  372. * fdt_getprop_namelen - get property value based on substring
  373. * @fdt: pointer to the device tree blob
  374. * @nodeoffset: offset of the node whose property to find
  375. * @name: name of the property to find
  376. * @namelen: number of characters of name to consider
  377. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  378. *
  379. * Identical to fdt_getprop(), but only examine the first namelen
  380. * characters of name for matching the property name.
  381. */
  382. const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
  383. const char *name, int namelen, int *lenp);
  384. /**
  385. * fdt_getprop - retrieve the value of a given property
  386. * @fdt: pointer to the device tree blob
  387. * @nodeoffset: offset of the node whose property to find
  388. * @name: name of the property to find
  389. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  390. *
  391. * fdt_getprop() retrieves a pointer to the value of the property
  392. * named 'name' of the node at offset nodeoffset (this will be a
  393. * pointer to within the device blob itself, not a copy of the value).
  394. * If lenp is non-NULL, the length of the property value is also
  395. * returned, in the integer pointed to by lenp.
  396. *
  397. * returns:
  398. * pointer to the property's value
  399. * if lenp is non-NULL, *lenp contains the length of the property
  400. * value (>=0)
  401. * NULL, on error
  402. * if lenp is non-NULL, *lenp contains an error code (<0):
  403. * -FDT_ERR_NOTFOUND, node does not have named property
  404. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  405. * -FDT_ERR_BADMAGIC,
  406. * -FDT_ERR_BADVERSION,
  407. * -FDT_ERR_BADSTATE,
  408. * -FDT_ERR_BADSTRUCTURE,
  409. * -FDT_ERR_TRUNCATED, standard meanings
  410. */
  411. const void *fdt_getprop(const void *fdt, int nodeoffset,
  412. const char *name, int *lenp);
  413. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  414. const char *name, int *lenp)
  415. {
  416. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  417. }
  418. /**
  419. * fdt_get_phandle - retrieve the phandle of a given node
  420. * @fdt: pointer to the device tree blob
  421. * @nodeoffset: structure block offset of the node
  422. *
  423. * fdt_get_phandle() retrieves the phandle of the device tree node at
  424. * structure block offset nodeoffset.
  425. *
  426. * returns:
  427. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  428. * 0, if the node has no phandle, or another error occurs
  429. */
  430. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  431. /**
  432. * fdt_get_path - determine the full path of a node
  433. * @fdt: pointer to the device tree blob
  434. * @nodeoffset: offset of the node whose path to find
  435. * @buf: character buffer to contain the returned path (will be overwritten)
  436. * @buflen: size of the character buffer at buf
  437. *
  438. * fdt_get_path() computes the full path of the node at offset
  439. * nodeoffset, and records that path in the buffer at buf.
  440. *
  441. * NOTE: This function is expensive, as it must scan the device tree
  442. * structure from the start to nodeoffset.
  443. *
  444. * returns:
  445. * 0, on success
  446. * buf contains the absolute path of the node at
  447. * nodeoffset, as a NUL-terminated string.
  448. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  449. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  450. * characters and will not fit in the given buffer.
  451. * -FDT_ERR_BADMAGIC,
  452. * -FDT_ERR_BADVERSION,
  453. * -FDT_ERR_BADSTATE,
  454. * -FDT_ERR_BADSTRUCTURE, standard meanings
  455. */
  456. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  457. /**
  458. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  459. * @fdt: pointer to the device tree blob
  460. * @nodeoffset: offset of the node whose parent to find
  461. * @supernodedepth: depth of the ancestor to find
  462. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  463. *
  464. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  465. * at a specific depth from the root (where the root itself has depth
  466. * 0, its immediate subnodes depth 1 and so forth). So
  467. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  468. * will always return 0, the offset of the root node. If the node at
  469. * nodeoffset has depth D, then:
  470. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  471. * will return nodeoffset itself.
  472. *
  473. * NOTE: This function is expensive, as it must scan the device tree
  474. * structure from the start to nodeoffset.
  475. *
  476. * returns:
  477. * structure block offset of the node at node offset's ancestor
  478. * of depth supernodedepth (>=0), on success
  479. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  480. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
  481. * -FDT_ERR_BADMAGIC,
  482. * -FDT_ERR_BADVERSION,
  483. * -FDT_ERR_BADSTATE,
  484. * -FDT_ERR_BADSTRUCTURE, standard meanings
  485. */
  486. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  487. int supernodedepth, int *nodedepth);
  488. /**
  489. * fdt_node_depth - find the depth of a given node
  490. * @fdt: pointer to the device tree blob
  491. * @nodeoffset: offset of the node whose parent to find
  492. *
  493. * fdt_node_depth() finds the depth of a given node. The root node
  494. * has depth 0, its immediate subnodes depth 1 and so forth.
  495. *
  496. * NOTE: This function is expensive, as it must scan the device tree
  497. * structure from the start to nodeoffset.
  498. *
  499. * returns:
  500. * depth of the node at nodeoffset (>=0), on success
  501. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  502. * -FDT_ERR_BADMAGIC,
  503. * -FDT_ERR_BADVERSION,
  504. * -FDT_ERR_BADSTATE,
  505. * -FDT_ERR_BADSTRUCTURE, standard meanings
  506. */
  507. int fdt_node_depth(const void *fdt, int nodeoffset);
  508. /**
  509. * fdt_parent_offset - find the parent of a given node
  510. * @fdt: pointer to the device tree blob
  511. * @nodeoffset: offset of the node whose parent to find
  512. *
  513. * fdt_parent_offset() locates the parent node of a given node (that
  514. * is, it finds the offset of the node which contains the node at
  515. * nodeoffset as a subnode).
  516. *
  517. * NOTE: This function is expensive, as it must scan the device tree
  518. * structure from the start to nodeoffset, *twice*.
  519. *
  520. * returns:
  521. * structure block offset of the parent of the node at nodeoffset
  522. * (>=0), on success
  523. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  524. * -FDT_ERR_BADMAGIC,
  525. * -FDT_ERR_BADVERSION,
  526. * -FDT_ERR_BADSTATE,
  527. * -FDT_ERR_BADSTRUCTURE, standard meanings
  528. */
  529. int fdt_parent_offset(const void *fdt, int nodeoffset);
  530. /**
  531. * fdt_node_offset_by_prop_value - find nodes with a given property value
  532. * @fdt: pointer to the device tree blob
  533. * @startoffset: only find nodes after this offset
  534. * @propname: property name to check
  535. * @propval: property value to search for
  536. * @proplen: length of the value in propval
  537. *
  538. * fdt_node_offset_by_prop_value() returns the offset of the first
  539. * node after startoffset, which has a property named propname whose
  540. * value is of length proplen and has value equal to propval; or if
  541. * startoffset is -1, the very first such node in the tree.
  542. *
  543. * To iterate through all nodes matching the criterion, the following
  544. * idiom can be used:
  545. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  546. * propval, proplen);
  547. * while (offset != -FDT_ERR_NOTFOUND) {
  548. * ... other code here ...
  549. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  550. * propval, proplen);
  551. * }
  552. *
  553. * Note the -1 in the first call to the function, if 0 is used here
  554. * instead, the function will never locate the root node, even if it
  555. * matches the criterion.
  556. *
  557. * returns:
  558. * structure block offset of the located node (>= 0, >startoffset),
  559. * on success
  560. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  561. * tree after startoffset
  562. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  563. * -FDT_ERR_BADMAGIC,
  564. * -FDT_ERR_BADVERSION,
  565. * -FDT_ERR_BADSTATE,
  566. * -FDT_ERR_BADSTRUCTURE, standard meanings
  567. */
  568. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  569. const char *propname,
  570. const void *propval, int proplen);
  571. /**
  572. * fdt_node_offset_by_phandle - find the node with a given phandle
  573. * @fdt: pointer to the device tree blob
  574. * @phandle: phandle value
  575. *
  576. * fdt_node_offset_by_phandle() returns the offset of the node
  577. * which has the given phandle value. If there is more than one node
  578. * in the tree with the given phandle (an invalid tree), results are
  579. * undefined.
  580. *
  581. * returns:
  582. * structure block offset of the located node (>= 0), on success
  583. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  584. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  585. * -FDT_ERR_BADMAGIC,
  586. * -FDT_ERR_BADVERSION,
  587. * -FDT_ERR_BADSTATE,
  588. * -FDT_ERR_BADSTRUCTURE, standard meanings
  589. */
  590. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  591. /**
  592. * fdt_node_check_compatible: check a node's compatible property
  593. * @fdt: pointer to the device tree blob
  594. * @nodeoffset: offset of a tree node
  595. * @compatible: string to match against
  596. *
  597. *
  598. * fdt_node_check_compatible() returns 0 if the given node contains a
  599. * 'compatible' property with the given string as one of its elements,
  600. * it returns non-zero otherwise, or on error.
  601. *
  602. * returns:
  603. * 0, if the node has a 'compatible' property listing the given string
  604. * 1, if the node has a 'compatible' property, but it does not list
  605. * the given string
  606. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  607. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  608. * -FDT_ERR_BADMAGIC,
  609. * -FDT_ERR_BADVERSION,
  610. * -FDT_ERR_BADSTATE,
  611. * -FDT_ERR_BADSTRUCTURE, standard meanings
  612. */
  613. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  614. const char *compatible);
  615. /**
  616. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  617. * @fdt: pointer to the device tree blob
  618. * @startoffset: only find nodes after this offset
  619. * @compatible: 'compatible' string to match against
  620. *
  621. * fdt_node_offset_by_compatible() returns the offset of the first
  622. * node after startoffset, which has a 'compatible' property which
  623. * lists the given compatible string; or if startoffset is -1, the
  624. * very first such node in the tree.
  625. *
  626. * To iterate through all nodes matching the criterion, the following
  627. * idiom can be used:
  628. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  629. * while (offset != -FDT_ERR_NOTFOUND) {
  630. * ... other code here ...
  631. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  632. * }
  633. *
  634. * Note the -1 in the first call to the function, if 0 is used here
  635. * instead, the function will never locate the root node, even if it
  636. * matches the criterion.
  637. *
  638. * returns:
  639. * structure block offset of the located node (>= 0, >startoffset),
  640. * on success
  641. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  642. * tree after startoffset
  643. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  644. * -FDT_ERR_BADMAGIC,
  645. * -FDT_ERR_BADVERSION,
  646. * -FDT_ERR_BADSTATE,
  647. * -FDT_ERR_BADSTRUCTURE, standard meanings
  648. */
  649. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  650. const char *compatible);
  651. /**********************************************************************/
  652. /* Write-in-place functions */
  653. /**********************************************************************/
  654. /**
  655. * fdt_setprop_inplace - change a property's value, but not its size
  656. * @fdt: pointer to the device tree blob
  657. * @nodeoffset: offset of the node whose property to change
  658. * @name: name of the property to change
  659. * @val: pointer to data to replace the property value with
  660. * @len: length of the property value
  661. *
  662. * fdt_setprop_inplace() replaces the value of a given property with
  663. * the data in val, of length len. This function cannot change the
  664. * size of a property, and so will only work if len is equal to the
  665. * current length of the property.
  666. *
  667. * This function will alter only the bytes in the blob which contain
  668. * the given property value, and will not alter or move any other part
  669. * of the tree.
  670. *
  671. * returns:
  672. * 0, on success
  673. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  674. * -FDT_ERR_NOTFOUND, node does not have the named property
  675. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  676. * -FDT_ERR_BADMAGIC,
  677. * -FDT_ERR_BADVERSION,
  678. * -FDT_ERR_BADSTATE,
  679. * -FDT_ERR_BADSTRUCTURE,
  680. * -FDT_ERR_TRUNCATED, standard meanings
  681. */
  682. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  683. const void *val, int len);
  684. /**
  685. * fdt_setprop_inplace_cell - change the value of a single-cell property
  686. * @fdt: pointer to the device tree blob
  687. * @nodeoffset: offset of the node whose property to change
  688. * @name: name of the property to change
  689. * @val: cell (32-bit integer) value to replace the property with
  690. *
  691. * fdt_setprop_inplace_cell() replaces the value of a given property
  692. * with the 32-bit integer cell value in val, converting val to
  693. * big-endian if necessary. This function cannot change the size of a
  694. * property, and so will only work if the property already exists and
  695. * has length 4.
  696. *
  697. * This function will alter only the bytes in the blob which contain
  698. * the given property value, and will not alter or move any other part
  699. * of the tree.
  700. *
  701. * returns:
  702. * 0, on success
  703. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  704. * -FDT_ERR_NOTFOUND, node does not have the named property
  705. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  706. * -FDT_ERR_BADMAGIC,
  707. * -FDT_ERR_BADVERSION,
  708. * -FDT_ERR_BADSTATE,
  709. * -FDT_ERR_BADSTRUCTURE,
  710. * -FDT_ERR_TRUNCATED, standard meanings
  711. */
  712. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  713. const char *name, uint32_t val)
  714. {
  715. val = cpu_to_fdt32(val);
  716. return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
  717. }
  718. /**
  719. * fdt_nop_property - replace a property with nop tags
  720. * @fdt: pointer to the device tree blob
  721. * @nodeoffset: offset of the node whose property to nop
  722. * @name: name of the property to nop
  723. *
  724. * fdt_nop_property() will replace a given property's representation
  725. * in the blob with FDT_NOP tags, effectively removing it from the
  726. * tree.
  727. *
  728. * This function will alter only the bytes in the blob which contain
  729. * the property, and will not alter or move any other part of the
  730. * tree.
  731. *
  732. * returns:
  733. * 0, on success
  734. * -FDT_ERR_NOTFOUND, node does not have the named property
  735. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  736. * -FDT_ERR_BADMAGIC,
  737. * -FDT_ERR_BADVERSION,
  738. * -FDT_ERR_BADSTATE,
  739. * -FDT_ERR_BADSTRUCTURE,
  740. * -FDT_ERR_TRUNCATED, standard meanings
  741. */
  742. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  743. /**
  744. * fdt_nop_node - replace a node (subtree) with nop tags
  745. * @fdt: pointer to the device tree blob
  746. * @nodeoffset: offset of the node to nop
  747. *
  748. * fdt_nop_node() will replace a given node's representation in the
  749. * blob, including all its subnodes, if any, with FDT_NOP tags,
  750. * effectively removing it from the tree.
  751. *
  752. * This function will alter only the bytes in the blob which contain
  753. * the node and its properties and subnodes, and will not alter or
  754. * move any other part of the tree.
  755. *
  756. * returns:
  757. * 0, on success
  758. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  759. * -FDT_ERR_BADMAGIC,
  760. * -FDT_ERR_BADVERSION,
  761. * -FDT_ERR_BADSTATE,
  762. * -FDT_ERR_BADSTRUCTURE,
  763. * -FDT_ERR_TRUNCATED, standard meanings
  764. */
  765. int fdt_nop_node(void *fdt, int nodeoffset);
  766. /**********************************************************************/
  767. /* Sequential write functions */
  768. /**********************************************************************/
  769. int fdt_create(void *buf, int bufsize);
  770. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  771. int fdt_finish_reservemap(void *fdt);
  772. int fdt_begin_node(void *fdt, const char *name);
  773. int fdt_property(void *fdt, const char *name, const void *val, int len);
  774. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  775. {
  776. val = cpu_to_fdt32(val);
  777. return fdt_property(fdt, name, &val, sizeof(val));
  778. }
  779. #define fdt_property_string(fdt, name, str) \
  780. fdt_property(fdt, name, str, strlen(str)+1)
  781. int fdt_end_node(void *fdt);
  782. int fdt_finish(void *fdt);
  783. /**********************************************************************/
  784. /* Read-write functions */
  785. /**********************************************************************/
  786. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  787. int fdt_pack(void *fdt);
  788. /**
  789. * fdt_add_mem_rsv - add one memory reserve map entry
  790. * @fdt: pointer to the device tree blob
  791. * @address, @size: 64-bit values (native endian)
  792. *
  793. * Adds a reserve map entry to the given blob reserving a region at
  794. * address address of length size.
  795. *
  796. * This function will insert data into the reserve map and will
  797. * therefore change the indexes of some entries in the table.
  798. *
  799. * returns:
  800. * 0, on success
  801. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  802. * contain the new reservation entry
  803. * -FDT_ERR_BADMAGIC,
  804. * -FDT_ERR_BADVERSION,
  805. * -FDT_ERR_BADSTATE,
  806. * -FDT_ERR_BADSTRUCTURE,
  807. * -FDT_ERR_BADLAYOUT,
  808. * -FDT_ERR_TRUNCATED, standard meanings
  809. */
  810. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  811. /**
  812. * fdt_del_mem_rsv - remove a memory reserve map entry
  813. * @fdt: pointer to the device tree blob
  814. * @n: entry to remove
  815. *
  816. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  817. * the blob.
  818. *
  819. * This function will delete data from the reservation table and will
  820. * therefore change the indexes of some entries in the table.
  821. *
  822. * returns:
  823. * 0, on success
  824. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  825. * are less than n+1 reserve map entries)
  826. * -FDT_ERR_BADMAGIC,
  827. * -FDT_ERR_BADVERSION,
  828. * -FDT_ERR_BADSTATE,
  829. * -FDT_ERR_BADSTRUCTURE,
  830. * -FDT_ERR_BADLAYOUT,
  831. * -FDT_ERR_TRUNCATED, standard meanings
  832. */
  833. int fdt_del_mem_rsv(void *fdt, int n);
  834. /**
  835. * fdt_set_name - change the name of a given node
  836. * @fdt: pointer to the device tree blob
  837. * @nodeoffset: structure block offset of a node
  838. * @name: name to give the node
  839. *
  840. * fdt_set_name() replaces the name (including unit address, if any)
  841. * of the given node with the given string. NOTE: this function can't
  842. * efficiently check if the new name is unique amongst the given
  843. * node's siblings; results are undefined if this function is invoked
  844. * with a name equal to one of the given node's siblings.
  845. *
  846. * This function may insert or delete data from the blob, and will
  847. * therefore change the offsets of some existing nodes.
  848. *
  849. * returns:
  850. * 0, on success
  851. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  852. * to contain the new name
  853. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  854. * -FDT_ERR_BADMAGIC,
  855. * -FDT_ERR_BADVERSION,
  856. * -FDT_ERR_BADSTATE, standard meanings
  857. */
  858. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  859. /**
  860. * fdt_setprop - create or change a property
  861. * @fdt: pointer to the device tree blob
  862. * @nodeoffset: offset of the node whose property to change
  863. * @name: name of the property to change
  864. * @val: pointer to data to set the property value to
  865. * @len: length of the property value
  866. *
  867. * fdt_setprop() sets the value of the named property in the given
  868. * node to the given value and length, creating the property if it
  869. * does not already exist.
  870. *
  871. * This function may insert or delete data from the blob, and will
  872. * therefore change the offsets of some existing nodes.
  873. *
  874. * returns:
  875. * 0, on success
  876. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  877. * contain the new property value
  878. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  879. * -FDT_ERR_BADLAYOUT,
  880. * -FDT_ERR_BADMAGIC,
  881. * -FDT_ERR_BADVERSION,
  882. * -FDT_ERR_BADSTATE,
  883. * -FDT_ERR_BADSTRUCTURE,
  884. * -FDT_ERR_BADLAYOUT,
  885. * -FDT_ERR_TRUNCATED, standard meanings
  886. */
  887. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  888. const void *val, int len);
  889. /**
  890. * fdt_setprop_cell - set a property to a single cell value
  891. * @fdt: pointer to the device tree blob
  892. * @nodeoffset: offset of the node whose property to change
  893. * @name: name of the property to change
  894. * @val: 32-bit integer value for the property (native endian)
  895. *
  896. * fdt_setprop_cell() sets the value of the named property in the
  897. * given node to the given cell value (converting to big-endian if
  898. * necessary), or creates a new property with that value if it does
  899. * not already exist.
  900. *
  901. * This function may insert or delete data from the blob, and will
  902. * therefore change the offsets of some existing nodes.
  903. *
  904. * returns:
  905. * 0, on success
  906. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  907. * contain the new property value
  908. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  909. * -FDT_ERR_BADLAYOUT,
  910. * -FDT_ERR_BADMAGIC,
  911. * -FDT_ERR_BADVERSION,
  912. * -FDT_ERR_BADSTATE,
  913. * -FDT_ERR_BADSTRUCTURE,
  914. * -FDT_ERR_BADLAYOUT,
  915. * -FDT_ERR_TRUNCATED, standard meanings
  916. */
  917. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  918. uint32_t val)
  919. {
  920. val = cpu_to_fdt32(val);
  921. return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
  922. }
  923. /**
  924. * fdt_setprop_string - set a property to a string value
  925. * @fdt: pointer to the device tree blob
  926. * @nodeoffset: offset of the node whose property to change
  927. * @name: name of the property to change
  928. * @str: string value for the property
  929. *
  930. * fdt_setprop_string() sets the value of the named property in the
  931. * given node to the given string value (using the length of the
  932. * string to determine the new length of the property), or creates a
  933. * new property with that value if it does not already exist.
  934. *
  935. * This function may insert or delete data from the blob, and will
  936. * therefore change the offsets of some existing nodes.
  937. *
  938. * returns:
  939. * 0, on success
  940. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  941. * contain the new property value
  942. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  943. * -FDT_ERR_BADLAYOUT,
  944. * -FDT_ERR_BADMAGIC,
  945. * -FDT_ERR_BADVERSION,
  946. * -FDT_ERR_BADSTATE,
  947. * -FDT_ERR_BADSTRUCTURE,
  948. * -FDT_ERR_BADLAYOUT,
  949. * -FDT_ERR_TRUNCATED, standard meanings
  950. */
  951. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  952. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  953. /**
  954. * fdt_delprop - delete a property
  955. * @fdt: pointer to the device tree blob
  956. * @nodeoffset: offset of the node whose property to nop
  957. * @name: name of the property to nop
  958. *
  959. * fdt_del_property() will delete the given property.
  960. *
  961. * This function will delete data from the blob, and will therefore
  962. * change the offsets of some existing nodes.
  963. *
  964. * returns:
  965. * 0, on success
  966. * -FDT_ERR_NOTFOUND, node does not have the named property
  967. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  968. * -FDT_ERR_BADLAYOUT,
  969. * -FDT_ERR_BADMAGIC,
  970. * -FDT_ERR_BADVERSION,
  971. * -FDT_ERR_BADSTATE,
  972. * -FDT_ERR_BADSTRUCTURE,
  973. * -FDT_ERR_TRUNCATED, standard meanings
  974. */
  975. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  976. /**
  977. * fdt_add_subnode_namelen - creates a new node based on substring
  978. * @fdt: pointer to the device tree blob
  979. * @parentoffset: structure block offset of a node
  980. * @name: name of the subnode to locate
  981. * @namelen: number of characters of name to consider
  982. *
  983. * Identical to fdt_add_subnode(), but use only the first namelen
  984. * characters of name as the name of the new node. This is useful for
  985. * creating subnodes based on a portion of a larger string, such as a
  986. * full path.
  987. */
  988. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  989. const char *name, int namelen);
  990. /**
  991. * fdt_add_subnode - creates a new node
  992. * @fdt: pointer to the device tree blob
  993. * @parentoffset: structure block offset of a node
  994. * @name: name of the subnode to locate
  995. *
  996. * fdt_add_subnode() creates a new node as a subnode of the node at
  997. * structure block offset parentoffset, with the given name (which
  998. * should include the unit address, if any).
  999. *
  1000. * This function will insert data into the blob, and will therefore
  1001. * change the offsets of some existing nodes.
  1002. * returns:
  1003. * structure block offset of the created nodeequested subnode (>=0), on success
  1004. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  1005. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
  1006. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  1007. * the given name
  1008. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  1009. * blob to contain the new node
  1010. * -FDT_ERR_NOSPACE
  1011. * -FDT_ERR_BADLAYOUT
  1012. * -FDT_ERR_BADMAGIC,
  1013. * -FDT_ERR_BADVERSION,
  1014. * -FDT_ERR_BADSTATE,
  1015. * -FDT_ERR_BADSTRUCTURE,
  1016. * -FDT_ERR_TRUNCATED, standard meanings.
  1017. */
  1018. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  1019. /**
  1020. * fdt_del_node - delete a node (subtree)
  1021. * @fdt: pointer to the device tree blob
  1022. * @nodeoffset: offset of the node to nop
  1023. *
  1024. * fdt_del_node() will remove the given node, including all its
  1025. * subnodes if any, from the blob.
  1026. *
  1027. * This function will delete data from the blob, and will therefore
  1028. * change the offsets of some existing nodes.
  1029. *
  1030. * returns:
  1031. * 0, on success
  1032. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1033. * -FDT_ERR_BADLAYOUT,
  1034. * -FDT_ERR_BADMAGIC,
  1035. * -FDT_ERR_BADVERSION,
  1036. * -FDT_ERR_BADSTATE,
  1037. * -FDT_ERR_BADSTRUCTURE,
  1038. * -FDT_ERR_TRUNCATED, standard meanings
  1039. */
  1040. int fdt_del_node(void *fdt, int nodeoffset);
  1041. /**********************************************************************/
  1042. /* Debugging / informational functions */
  1043. /**********************************************************************/
  1044. const char *fdt_strerror(int errval);
  1045. #endif /* _LIBFDT_H */