libfdt.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  1. /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
  2. #ifndef LIBFDT_H
  3. #define LIBFDT_H
  4. /*
  5. * libfdt - Flat Device Tree manipulation
  6. * Copyright (C) 2006 David Gibson, IBM Corporation.
  7. */
  8. #include "libfdt_env.h"
  9. #include "fdt.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #define FDT_FIRST_SUPPORTED_VERSION 0x02
  14. #define FDT_LAST_COMPATIBLE_VERSION 0x10
  15. #define FDT_LAST_SUPPORTED_VERSION 0x11
  16. /* Error codes: informative error codes */
  17. #define FDT_ERR_NOTFOUND 1
  18. /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
  19. #define FDT_ERR_EXISTS 2
  20. /* FDT_ERR_EXISTS: Attempted to create a node or property which
  21. * already exists */
  22. #define FDT_ERR_NOSPACE 3
  23. /* FDT_ERR_NOSPACE: Operation needed to expand the device
  24. * tree, but its buffer did not have sufficient space to
  25. * contain the expanded tree. Use fdt_open_into() to move the
  26. * device tree to a buffer with more space. */
  27. /* Error codes: codes for bad parameters */
  28. #define FDT_ERR_BADOFFSET 4
  29. /* FDT_ERR_BADOFFSET: Function was passed a structure block
  30. * offset which is out-of-bounds, or which points to an
  31. * unsuitable part of the structure for the operation. */
  32. #define FDT_ERR_BADPATH 5
  33. /* FDT_ERR_BADPATH: Function was passed a badly formatted path
  34. * (e.g. missing a leading / for a function which requires an
  35. * absolute path) */
  36. #define FDT_ERR_BADPHANDLE 6
  37. /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
  38. * This can be caused either by an invalid phandle property
  39. * length, or the phandle value was either 0 or -1, which are
  40. * not permitted. */
  41. #define FDT_ERR_BADSTATE 7
  42. /* FDT_ERR_BADSTATE: Function was passed an incomplete device
  43. * tree created by the sequential-write functions, which is
  44. * not sufficiently complete for the requested operation. */
  45. /* Error codes: codes for bad device tree blobs */
  46. #define FDT_ERR_TRUNCATED 8
  47. /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
  48. * terminated (overflows, goes outside allowed bounds, or
  49. * isn't properly terminated). */
  50. #define FDT_ERR_BADMAGIC 9
  51. /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
  52. * device tree at all - it is missing the flattened device
  53. * tree magic number. */
  54. #define FDT_ERR_BADVERSION 10
  55. /* FDT_ERR_BADVERSION: Given device tree has a version which
  56. * can't be handled by the requested operation. For
  57. * read-write functions, this may mean that fdt_open_into() is
  58. * required to convert the tree to the expected version. */
  59. #define FDT_ERR_BADSTRUCTURE 11
  60. /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
  61. * structure block or other serious error (e.g. misnested
  62. * nodes, or subnodes preceding properties). */
  63. #define FDT_ERR_BADLAYOUT 12
  64. /* FDT_ERR_BADLAYOUT: For read-write functions, the given
  65. * device tree has it's sub-blocks in an order that the
  66. * function can't handle (memory reserve map, then structure,
  67. * then strings). Use fdt_open_into() to reorganize the tree
  68. * into a form suitable for the read-write operations. */
  69. /* "Can't happen" error indicating a bug in libfdt */
  70. #define FDT_ERR_INTERNAL 13
  71. /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
  72. * Should never be returned, if it is, it indicates a bug in
  73. * libfdt itself. */
  74. /* Errors in device tree content */
  75. #define FDT_ERR_BADNCELLS 14
  76. /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
  77. * or similar property with a bad format or value */
  78. #define FDT_ERR_BADVALUE 15
  79. /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
  80. * value. For example: a property expected to contain a string list
  81. * is not NUL-terminated within the length of its value. */
  82. #define FDT_ERR_BADOVERLAY 16
  83. /* FDT_ERR_BADOVERLAY: The device tree overlay, while
  84. * correctly structured, cannot be applied due to some
  85. * unexpected or missing value, property or node. */
  86. #define FDT_ERR_NOPHANDLES 17
  87. /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
  88. * phandle available anymore without causing an overflow */
  89. #define FDT_ERR_BADFLAGS 18
  90. /* FDT_ERR_BADFLAGS: The function was passed a flags field that
  91. * contains invalid flags or an invalid combination of flags. */
  92. #define FDT_ERR_ALIGNMENT 19
  93. /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
  94. * aligned. */
  95. #define FDT_ERR_MAX 19
  96. /* constants */
  97. #define FDT_MAX_PHANDLE 0xfffffffe
  98. /* Valid values for phandles range from 1 to 2^32-2. */
  99. /**********************************************************************/
  100. /* Low-level functions (you probably don't need these) */
  101. /**********************************************************************/
  102. #ifndef SWIG /* This function is not useful in Python */
  103. const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
  104. #endif
  105. static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  106. {
  107. return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
  108. }
  109. uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
  110. /*
  111. * External helpers to access words from a device tree blob. They're built
  112. * to work even with unaligned pointers on platforms (such as ARMv5) that don't
  113. * like unaligned loads and stores.
  114. */
  115. static inline uint16_t fdt16_ld(const fdt16_t *p)
  116. {
  117. const uint8_t *bp = (const uint8_t *)p;
  118. return ((uint16_t)bp[0] << 8) | bp[1];
  119. }
  120. static inline uint32_t fdt32_ld(const fdt32_t *p)
  121. {
  122. const uint8_t *bp = (const uint8_t *)p;
  123. return ((uint32_t)bp[0] << 24)
  124. | ((uint32_t)bp[1] << 16)
  125. | ((uint32_t)bp[2] << 8)
  126. | bp[3];
  127. }
  128. static inline void fdt32_st(void *property, uint32_t value)
  129. {
  130. uint8_t *bp = (uint8_t *)property;
  131. bp[0] = value >> 24;
  132. bp[1] = (value >> 16) & 0xff;
  133. bp[2] = (value >> 8) & 0xff;
  134. bp[3] = value & 0xff;
  135. }
  136. static inline uint64_t fdt64_ld(const fdt64_t *p)
  137. {
  138. const uint8_t *bp = (const uint8_t *)p;
  139. return ((uint64_t)bp[0] << 56)
  140. | ((uint64_t)bp[1] << 48)
  141. | ((uint64_t)bp[2] << 40)
  142. | ((uint64_t)bp[3] << 32)
  143. | ((uint64_t)bp[4] << 24)
  144. | ((uint64_t)bp[5] << 16)
  145. | ((uint64_t)bp[6] << 8)
  146. | bp[7];
  147. }
  148. static inline void fdt64_st(void *property, uint64_t value)
  149. {
  150. uint8_t *bp = (uint8_t *)property;
  151. bp[0] = value >> 56;
  152. bp[1] = (value >> 48) & 0xff;
  153. bp[2] = (value >> 40) & 0xff;
  154. bp[3] = (value >> 32) & 0xff;
  155. bp[4] = (value >> 24) & 0xff;
  156. bp[5] = (value >> 16) & 0xff;
  157. bp[6] = (value >> 8) & 0xff;
  158. bp[7] = value & 0xff;
  159. }
  160. /**********************************************************************/
  161. /* Traversal functions */
  162. /**********************************************************************/
  163. int fdt_next_node(const void *fdt, int offset, int *depth);
  164. /**
  165. * fdt_first_subnode() - get offset of first direct subnode
  166. * @fdt: FDT blob
  167. * @offset: Offset of node to check
  168. *
  169. * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
  170. */
  171. int fdt_first_subnode(const void *fdt, int offset);
  172. /**
  173. * fdt_next_subnode() - get offset of next direct subnode
  174. * @fdt: FDT blob
  175. * @offset: Offset of previous subnode
  176. *
  177. * After first calling fdt_first_subnode(), call this function repeatedly to
  178. * get direct subnodes of a parent node.
  179. *
  180. * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
  181. * subnodes
  182. */
  183. int fdt_next_subnode(const void *fdt, int offset);
  184. /**
  185. * fdt_for_each_subnode - iterate over all subnodes of a parent
  186. *
  187. * @node: child node (int, lvalue)
  188. * @fdt: FDT blob (const void *)
  189. * @parent: parent node (int)
  190. *
  191. * This is actually a wrapper around a for loop and would be used like so:
  192. *
  193. * fdt_for_each_subnode(node, fdt, parent) {
  194. * Use node
  195. * ...
  196. * }
  197. *
  198. * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
  199. * Error handling
  200. * }
  201. *
  202. * Note that this is implemented as a macro and @node is used as
  203. * iterator in the loop. The parent variable be constant or even a
  204. * literal.
  205. */
  206. #define fdt_for_each_subnode(node, fdt, parent) \
  207. for (node = fdt_first_subnode(fdt, parent); \
  208. node >= 0; \
  209. node = fdt_next_subnode(fdt, node))
  210. /**********************************************************************/
  211. /* General functions */
  212. /**********************************************************************/
  213. #define fdt_get_header(fdt, field) \
  214. (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
  215. #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
  216. #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
  217. #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
  218. #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
  219. #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
  220. #define fdt_version(fdt) (fdt_get_header(fdt, version))
  221. #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
  222. #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
  223. #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
  224. #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
  225. #define fdt_set_hdr_(name) \
  226. static inline void fdt_set_##name(void *fdt, uint32_t val) \
  227. { \
  228. struct fdt_header *fdth = (struct fdt_header *)fdt; \
  229. fdth->name = cpu_to_fdt32(val); \
  230. }
  231. fdt_set_hdr_(magic);
  232. fdt_set_hdr_(totalsize);
  233. fdt_set_hdr_(off_dt_struct);
  234. fdt_set_hdr_(off_dt_strings);
  235. fdt_set_hdr_(off_mem_rsvmap);
  236. fdt_set_hdr_(version);
  237. fdt_set_hdr_(last_comp_version);
  238. fdt_set_hdr_(boot_cpuid_phys);
  239. fdt_set_hdr_(size_dt_strings);
  240. fdt_set_hdr_(size_dt_struct);
  241. #undef fdt_set_hdr_
  242. /**
  243. * fdt_header_size - return the size of the tree's header
  244. * @fdt: pointer to a flattened device tree
  245. *
  246. * Return: size of DTB header in bytes
  247. */
  248. size_t fdt_header_size(const void *fdt);
  249. /**
  250. * fdt_header_size_ - internal function to get header size from a version number
  251. * @version: devicetree version number
  252. *
  253. * Return: size of DTB header in bytes
  254. */
  255. size_t fdt_header_size_(uint32_t version);
  256. /**
  257. * fdt_check_header - sanity check a device tree header
  258. * @fdt: pointer to data which might be a flattened device tree
  259. *
  260. * fdt_check_header() checks that the given buffer contains what
  261. * appears to be a flattened device tree, and that the header contains
  262. * valid information (to the extent that can be determined from the
  263. * header alone).
  264. *
  265. * returns:
  266. * 0, if the buffer appears to contain a valid device tree
  267. * -FDT_ERR_BADMAGIC,
  268. * -FDT_ERR_BADVERSION,
  269. * -FDT_ERR_BADSTATE,
  270. * -FDT_ERR_TRUNCATED, standard meanings, as above
  271. */
  272. int fdt_check_header(const void *fdt);
  273. /**
  274. * fdt_move - move a device tree around in memory
  275. * @fdt: pointer to the device tree to move
  276. * @buf: pointer to memory where the device is to be moved
  277. * @bufsize: size of the memory space at buf
  278. *
  279. * fdt_move() relocates, if possible, the device tree blob located at
  280. * fdt to the buffer at buf of size bufsize. The buffer may overlap
  281. * with the existing device tree blob at fdt. Therefore,
  282. * fdt_move(fdt, fdt, fdt_totalsize(fdt))
  283. * should always succeed.
  284. *
  285. * returns:
  286. * 0, on success
  287. * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
  288. * -FDT_ERR_BADMAGIC,
  289. * -FDT_ERR_BADVERSION,
  290. * -FDT_ERR_BADSTATE, standard meanings
  291. */
  292. int fdt_move(const void *fdt, void *buf, int bufsize);
  293. /**********************************************************************/
  294. /* Read-only functions */
  295. /**********************************************************************/
  296. int fdt_check_full(const void *fdt, size_t bufsize);
  297. /**
  298. * fdt_get_string - retrieve a string from the strings block of a device tree
  299. * @fdt: pointer to the device tree blob
  300. * @stroffset: offset of the string within the strings block (native endian)
  301. * @lenp: optional pointer to return the string's length
  302. *
  303. * fdt_get_string() retrieves a pointer to a single string from the
  304. * strings block of the device tree blob at fdt, and optionally also
  305. * returns the string's length in *lenp.
  306. *
  307. * returns:
  308. * a pointer to the string, on success
  309. * NULL, if stroffset is out of bounds, or doesn't point to a valid string
  310. */
  311. const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
  312. /**
  313. * fdt_string - retrieve a string from the strings block of a device tree
  314. * @fdt: pointer to the device tree blob
  315. * @stroffset: offset of the string within the strings block (native endian)
  316. *
  317. * fdt_string() retrieves a pointer to a single string from the
  318. * strings block of the device tree blob at fdt.
  319. *
  320. * returns:
  321. * a pointer to the string, on success
  322. * NULL, if stroffset is out of bounds, or doesn't point to a valid string
  323. */
  324. const char *fdt_string(const void *fdt, int stroffset);
  325. /**
  326. * fdt_find_max_phandle - find and return the highest phandle in a tree
  327. * @fdt: pointer to the device tree blob
  328. * @phandle: return location for the highest phandle value found in the tree
  329. *
  330. * fdt_find_max_phandle() finds the highest phandle value in the given device
  331. * tree. The value returned in @phandle is only valid if the function returns
  332. * success.
  333. *
  334. * returns:
  335. * 0 on success or a negative error code on failure
  336. */
  337. int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
  338. /**
  339. * fdt_get_max_phandle - retrieves the highest phandle in a tree
  340. * @fdt: pointer to the device tree blob
  341. *
  342. * fdt_get_max_phandle retrieves the highest phandle in the given
  343. * device tree. This will ignore badly formatted phandles, or phandles
  344. * with a value of 0 or -1.
  345. *
  346. * This function is deprecated in favour of fdt_find_max_phandle().
  347. *
  348. * returns:
  349. * the highest phandle on success
  350. * 0, if no phandle was found in the device tree
  351. * -1, if an error occurred
  352. */
  353. static inline uint32_t fdt_get_max_phandle(const void *fdt)
  354. {
  355. uint32_t phandle;
  356. int err;
  357. err = fdt_find_max_phandle(fdt, &phandle);
  358. if (err < 0)
  359. return (uint32_t)-1;
  360. return phandle;
  361. }
  362. /**
  363. * fdt_generate_phandle - return a new, unused phandle for a device tree blob
  364. * @fdt: pointer to the device tree blob
  365. * @phandle: return location for the new phandle
  366. *
  367. * Walks the device tree blob and looks for the highest phandle value. On
  368. * success, the new, unused phandle value (one higher than the previously
  369. * highest phandle value in the device tree blob) will be returned in the
  370. * @phandle parameter.
  371. *
  372. * Return: 0 on success or a negative error-code on failure
  373. */
  374. int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
  375. /**
  376. * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
  377. * @fdt: pointer to the device tree blob
  378. *
  379. * Returns the number of entries in the device tree blob's memory
  380. * reservation map. This does not include the terminating 0,0 entry
  381. * or any other (0,0) entries reserved for expansion.
  382. *
  383. * returns:
  384. * the number of entries
  385. */
  386. int fdt_num_mem_rsv(const void *fdt);
  387. /**
  388. * fdt_get_mem_rsv - retrieve one memory reserve map entry
  389. * @fdt: pointer to the device tree blob
  390. * @n: index of reserve map entry
  391. * @address: pointer to 64-bit variable to hold the start address
  392. * @size: pointer to 64-bit variable to hold the size of the entry
  393. *
  394. * On success, @address and @size will contain the address and size of
  395. * the n-th reserve map entry from the device tree blob, in
  396. * native-endian format.
  397. *
  398. * returns:
  399. * 0, on success
  400. * -FDT_ERR_BADMAGIC,
  401. * -FDT_ERR_BADVERSION,
  402. * -FDT_ERR_BADSTATE, standard meanings
  403. */
  404. int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
  405. /**
  406. * fdt_subnode_offset_namelen - find a subnode based on substring
  407. * @fdt: pointer to the device tree blob
  408. * @parentoffset: structure block offset of a node
  409. * @name: name of the subnode to locate
  410. * @namelen: number of characters of name to consider
  411. *
  412. * Identical to fdt_subnode_offset(), but only examine the first
  413. * namelen characters of name for matching the subnode name. This is
  414. * useful for finding subnodes based on a portion of a larger string,
  415. * such as a full path.
  416. *
  417. * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found.
  418. */
  419. #ifndef SWIG /* Not available in Python */
  420. int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
  421. const char *name, int namelen);
  422. #endif
  423. /**
  424. * fdt_subnode_offset - find a subnode of a given node
  425. * @fdt: pointer to the device tree blob
  426. * @parentoffset: structure block offset of a node
  427. * @name: name of the subnode to locate
  428. *
  429. * fdt_subnode_offset() finds a subnode of the node at structure block
  430. * offset parentoffset with the given name. name may include a unit
  431. * address, in which case fdt_subnode_offset() will find the subnode
  432. * with that unit address, or the unit address may be omitted, in
  433. * which case fdt_subnode_offset() will find an arbitrary subnode
  434. * whose name excluding unit address matches the given name.
  435. *
  436. * returns:
  437. * structure block offset of the requested subnode (>=0), on success
  438. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  439. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
  440. * tag
  441. * -FDT_ERR_BADMAGIC,
  442. * -FDT_ERR_BADVERSION,
  443. * -FDT_ERR_BADSTATE,
  444. * -FDT_ERR_BADSTRUCTURE,
  445. * -FDT_ERR_TRUNCATED, standard meanings.
  446. */
  447. int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
  448. /**
  449. * fdt_path_offset_namelen - find a tree node by its full path
  450. * @fdt: pointer to the device tree blob
  451. * @path: full path of the node to locate
  452. * @namelen: number of characters of path to consider
  453. *
  454. * Identical to fdt_path_offset(), but only consider the first namelen
  455. * characters of path as the path name.
  456. *
  457. * Return: offset of the node or negative libfdt error value otherwise
  458. */
  459. #ifndef SWIG /* Not available in Python */
  460. int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
  461. #endif
  462. /**
  463. * fdt_path_offset - find a tree node by its full path
  464. * @fdt: pointer to the device tree blob
  465. * @path: full path of the node to locate
  466. *
  467. * fdt_path_offset() finds a node of a given path in the device tree.
  468. * Each path component may omit the unit address portion, but the
  469. * results of this are undefined if any such path component is
  470. * ambiguous (that is if there are multiple nodes at the relevant
  471. * level matching the given component, differentiated only by unit
  472. * address).
  473. *
  474. * returns:
  475. * structure block offset of the node with the requested path (>=0), on
  476. * success
  477. * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
  478. * -FDT_ERR_NOTFOUND, if the requested node does not exist
  479. * -FDT_ERR_BADMAGIC,
  480. * -FDT_ERR_BADVERSION,
  481. * -FDT_ERR_BADSTATE,
  482. * -FDT_ERR_BADSTRUCTURE,
  483. * -FDT_ERR_TRUNCATED, standard meanings.
  484. */
  485. int fdt_path_offset(const void *fdt, const char *path);
  486. /**
  487. * fdt_get_name - retrieve the name of a given node
  488. * @fdt: pointer to the device tree blob
  489. * @nodeoffset: structure block offset of the starting node
  490. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  491. *
  492. * fdt_get_name() retrieves the name (including unit address) of the
  493. * device tree node at structure block offset nodeoffset. If lenp is
  494. * non-NULL, the length of this name is also returned, in the integer
  495. * pointed to by lenp.
  496. *
  497. * returns:
  498. * pointer to the node's name, on success
  499. * If lenp is non-NULL, *lenp contains the length of that name
  500. * (>=0)
  501. * NULL, on error
  502. * if lenp is non-NULL *lenp contains an error code (<0):
  503. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
  504. * tag
  505. * -FDT_ERR_BADMAGIC,
  506. * -FDT_ERR_BADVERSION,
  507. * -FDT_ERR_BADSTATE, standard meanings
  508. */
  509. const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
  510. /**
  511. * fdt_first_property_offset - find the offset of a node's first property
  512. * @fdt: pointer to the device tree blob
  513. * @nodeoffset: structure block offset of a node
  514. *
  515. * fdt_first_property_offset() finds the first property of the node at
  516. * the given structure block offset.
  517. *
  518. * returns:
  519. * structure block offset of the property (>=0), on success
  520. * -FDT_ERR_NOTFOUND, if the requested node has no properties
  521. * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
  522. * -FDT_ERR_BADMAGIC,
  523. * -FDT_ERR_BADVERSION,
  524. * -FDT_ERR_BADSTATE,
  525. * -FDT_ERR_BADSTRUCTURE,
  526. * -FDT_ERR_TRUNCATED, standard meanings.
  527. */
  528. int fdt_first_property_offset(const void *fdt, int nodeoffset);
  529. /**
  530. * fdt_next_property_offset - step through a node's properties
  531. * @fdt: pointer to the device tree blob
  532. * @offset: structure block offset of a property
  533. *
  534. * fdt_next_property_offset() finds the property immediately after the
  535. * one at the given structure block offset. This will be a property
  536. * of the same node as the given property.
  537. *
  538. * returns:
  539. * structure block offset of the next property (>=0), on success
  540. * -FDT_ERR_NOTFOUND, if the given property is the last in its node
  541. * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP 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. int fdt_next_property_offset(const void *fdt, int offset);
  549. /**
  550. * fdt_for_each_property_offset - iterate over all properties of a node
  551. *
  552. * @property: property offset (int, lvalue)
  553. * @fdt: FDT blob (const void *)
  554. * @node: node offset (int)
  555. *
  556. * This is actually a wrapper around a for loop and would be used like so:
  557. *
  558. * fdt_for_each_property_offset(property, fdt, node) {
  559. * Use property
  560. * ...
  561. * }
  562. *
  563. * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
  564. * Error handling
  565. * }
  566. *
  567. * Note that this is implemented as a macro and property is used as
  568. * iterator in the loop. The node variable can be constant or even a
  569. * literal.
  570. */
  571. #define fdt_for_each_property_offset(property, fdt, node) \
  572. for (property = fdt_first_property_offset(fdt, node); \
  573. property >= 0; \
  574. property = fdt_next_property_offset(fdt, property))
  575. /**
  576. * fdt_get_property_by_offset - retrieve the property at a given offset
  577. * @fdt: pointer to the device tree blob
  578. * @offset: offset of the property to retrieve
  579. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  580. *
  581. * fdt_get_property_by_offset() retrieves a pointer to the
  582. * fdt_property structure within the device tree blob at the given
  583. * offset. If lenp is non-NULL, the length of the property value is
  584. * also returned, in the integer pointed to by lenp.
  585. *
  586. * Note that this code only works on device tree versions >= 16. fdt_getprop()
  587. * works on all versions.
  588. *
  589. * returns:
  590. * pointer to the structure representing the property
  591. * if lenp is non-NULL, *lenp contains the length of the property
  592. * value (>=0)
  593. * NULL, on error
  594. * if lenp is non-NULL, *lenp contains an error code (<0):
  595. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
  596. * -FDT_ERR_BADMAGIC,
  597. * -FDT_ERR_BADVERSION,
  598. * -FDT_ERR_BADSTATE,
  599. * -FDT_ERR_BADSTRUCTURE,
  600. * -FDT_ERR_TRUNCATED, standard meanings
  601. */
  602. const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
  603. int offset,
  604. int *lenp);
  605. /**
  606. * fdt_get_property_namelen - find a property based on substring
  607. * @fdt: pointer to the device tree blob
  608. * @nodeoffset: offset of the node whose property to find
  609. * @name: name of the property to find
  610. * @namelen: number of characters of name to consider
  611. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  612. *
  613. * Identical to fdt_get_property(), but only examine the first namelen
  614. * characters of name for matching the property name.
  615. *
  616. * Return: pointer to the structure representing the property, or NULL
  617. * if not found
  618. */
  619. #ifndef SWIG /* Not available in Python */
  620. const struct fdt_property *fdt_get_property_namelen(const void *fdt,
  621. int nodeoffset,
  622. const char *name,
  623. int namelen, int *lenp);
  624. #endif
  625. /**
  626. * fdt_get_property - find a given property in a given node
  627. * @fdt: pointer to the device tree blob
  628. * @nodeoffset: offset of the node whose property to find
  629. * @name: name of the property to find
  630. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  631. *
  632. * fdt_get_property() retrieves a pointer to the fdt_property
  633. * structure within the device tree blob corresponding to the property
  634. * named 'name' of the node at offset nodeoffset. If lenp is
  635. * non-NULL, the length of the property value is also returned, in the
  636. * integer pointed to by lenp.
  637. *
  638. * returns:
  639. * pointer to the structure representing the property
  640. * if lenp is non-NULL, *lenp contains the length of the property
  641. * value (>=0)
  642. * NULL, on error
  643. * if lenp is non-NULL, *lenp contains an error code (<0):
  644. * -FDT_ERR_NOTFOUND, node does not have named property
  645. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
  646. * tag
  647. * -FDT_ERR_BADMAGIC,
  648. * -FDT_ERR_BADVERSION,
  649. * -FDT_ERR_BADSTATE,
  650. * -FDT_ERR_BADSTRUCTURE,
  651. * -FDT_ERR_TRUNCATED, standard meanings
  652. */
  653. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  654. const char *name, int *lenp);
  655. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  656. const char *name,
  657. int *lenp)
  658. {
  659. return (struct fdt_property *)(uintptr_t)
  660. fdt_get_property(fdt, nodeoffset, name, lenp);
  661. }
  662. /**
  663. * fdt_getprop_by_offset - retrieve the value of a property at a given offset
  664. * @fdt: pointer to the device tree blob
  665. * @offset: offset of the property to read
  666. * @namep: pointer to a string variable (will be overwritten) or NULL
  667. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  668. *
  669. * fdt_getprop_by_offset() retrieves a pointer to the value of the
  670. * property at structure block offset 'offset' (this will be a pointer
  671. * to within the device blob itself, not a copy of the value). If
  672. * lenp is non-NULL, the length of the property value is also
  673. * returned, in the integer pointed to by lenp. If namep is non-NULL,
  674. * the property's namne will also be returned in the char * pointed to
  675. * by namep (this will be a pointer to within the device tree's string
  676. * block, not a new copy of the name).
  677. *
  678. * returns:
  679. * pointer to the property's value
  680. * if lenp is non-NULL, *lenp contains the length of the property
  681. * value (>=0)
  682. * if namep is non-NULL *namep contiains a pointer to the property
  683. * name.
  684. * NULL, on error
  685. * if lenp is non-NULL, *lenp contains an error code (<0):
  686. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
  687. * -FDT_ERR_BADMAGIC,
  688. * -FDT_ERR_BADVERSION,
  689. * -FDT_ERR_BADSTATE,
  690. * -FDT_ERR_BADSTRUCTURE,
  691. * -FDT_ERR_TRUNCATED, standard meanings
  692. */
  693. #ifndef SWIG /* This function is not useful in Python */
  694. const void *fdt_getprop_by_offset(const void *fdt, int offset,
  695. const char **namep, int *lenp);
  696. #endif
  697. /**
  698. * fdt_getprop_namelen - get property value based on substring
  699. * @fdt: pointer to the device tree blob
  700. * @nodeoffset: offset of the node whose property to find
  701. * @name: name of the property to find
  702. * @namelen: number of characters of name to consider
  703. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  704. *
  705. * Identical to fdt_getprop(), but only examine the first namelen
  706. * characters of name for matching the property name.
  707. *
  708. * Return: pointer to the property's value or NULL on error
  709. */
  710. #ifndef SWIG /* Not available in Python */
  711. const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
  712. const char *name, int namelen, int *lenp);
  713. static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
  714. const char *name, int namelen,
  715. int *lenp)
  716. {
  717. return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
  718. namelen, lenp);
  719. }
  720. #endif
  721. /**
  722. * fdt_getprop - retrieve the value of a given property
  723. * @fdt: pointer to the device tree blob
  724. * @nodeoffset: offset of the node whose property to find
  725. * @name: name of the property to find
  726. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  727. *
  728. * fdt_getprop() retrieves a pointer to the value of the property
  729. * named @name of the node at offset @nodeoffset (this will be a
  730. * pointer to within the device blob itself, not a copy of the value).
  731. * If @lenp is non-NULL, the length of the property value is also
  732. * returned, in the integer pointed to by @lenp.
  733. *
  734. * returns:
  735. * pointer to the property's value
  736. * if lenp is non-NULL, *lenp contains the length of the property
  737. * value (>=0)
  738. * NULL, on error
  739. * if lenp is non-NULL, *lenp contains an error code (<0):
  740. * -FDT_ERR_NOTFOUND, node does not have named property
  741. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
  742. * tag
  743. * -FDT_ERR_BADMAGIC,
  744. * -FDT_ERR_BADVERSION,
  745. * -FDT_ERR_BADSTATE,
  746. * -FDT_ERR_BADSTRUCTURE,
  747. * -FDT_ERR_TRUNCATED, standard meanings
  748. */
  749. const void *fdt_getprop(const void *fdt, int nodeoffset,
  750. const char *name, int *lenp);
  751. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  752. const char *name, int *lenp)
  753. {
  754. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  755. }
  756. /**
  757. * fdt_get_phandle - retrieve the phandle of a given node
  758. * @fdt: pointer to the device tree blob
  759. * @nodeoffset: structure block offset of the node
  760. *
  761. * fdt_get_phandle() retrieves the phandle of the device tree node at
  762. * structure block offset nodeoffset.
  763. *
  764. * returns:
  765. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  766. * 0, if the node has no phandle, or another error occurs
  767. */
  768. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  769. /**
  770. * fdt_get_alias_namelen - get alias based on substring
  771. * @fdt: pointer to the device tree blob
  772. * @name: name of the alias th look up
  773. * @namelen: number of characters of name to consider
  774. *
  775. * Identical to fdt_get_alias(), but only examine the first @namelen
  776. * characters of @name for matching the alias name.
  777. *
  778. * Return: a pointer to the expansion of the alias named @name, if it exists,
  779. * NULL otherwise
  780. */
  781. #ifndef SWIG /* Not available in Python */
  782. const char *fdt_get_alias_namelen(const void *fdt,
  783. const char *name, int namelen);
  784. #endif
  785. /**
  786. * fdt_get_alias - retrieve the path referenced by a given alias
  787. * @fdt: pointer to the device tree blob
  788. * @name: name of the alias th look up
  789. *
  790. * fdt_get_alias() retrieves the value of a given alias. That is, the
  791. * value of the property named @name in the node /aliases.
  792. *
  793. * returns:
  794. * a pointer to the expansion of the alias named 'name', if it exists
  795. * NULL, if the given alias or the /aliases node does not exist
  796. */
  797. const char *fdt_get_alias(const void *fdt, const char *name);
  798. /**
  799. * fdt_get_path - determine the full path of a node
  800. * @fdt: pointer to the device tree blob
  801. * @nodeoffset: offset of the node whose path to find
  802. * @buf: character buffer to contain the returned path (will be overwritten)
  803. * @buflen: size of the character buffer at buf
  804. *
  805. * fdt_get_path() computes the full path of the node at offset
  806. * nodeoffset, and records that path in the buffer at buf.
  807. *
  808. * NOTE: This function is expensive, as it must scan the device tree
  809. * structure from the start to nodeoffset.
  810. *
  811. * returns:
  812. * 0, on success
  813. * buf contains the absolute path of the node at
  814. * nodeoffset, as a NUL-terminated string.
  815. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  816. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  817. * characters and will not fit in the given buffer.
  818. * -FDT_ERR_BADMAGIC,
  819. * -FDT_ERR_BADVERSION,
  820. * -FDT_ERR_BADSTATE,
  821. * -FDT_ERR_BADSTRUCTURE, standard meanings
  822. */
  823. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  824. /**
  825. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  826. * @fdt: pointer to the device tree blob
  827. * @nodeoffset: offset of the node whose parent to find
  828. * @supernodedepth: depth of the ancestor to find
  829. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  830. *
  831. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  832. * at a specific depth from the root (where the root itself has depth
  833. * 0, its immediate subnodes depth 1 and so forth). So
  834. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  835. * will always return 0, the offset of the root node. If the node at
  836. * nodeoffset has depth D, then:
  837. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  838. * will return nodeoffset itself.
  839. *
  840. * NOTE: This function is expensive, as it must scan the device tree
  841. * structure from the start to nodeoffset.
  842. *
  843. * returns:
  844. * structure block offset of the node at node offset's ancestor
  845. * of depth supernodedepth (>=0), on success
  846. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  847. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
  848. * nodeoffset
  849. * -FDT_ERR_BADMAGIC,
  850. * -FDT_ERR_BADVERSION,
  851. * -FDT_ERR_BADSTATE,
  852. * -FDT_ERR_BADSTRUCTURE, standard meanings
  853. */
  854. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  855. int supernodedepth, int *nodedepth);
  856. /**
  857. * fdt_node_depth - find the depth of a given node
  858. * @fdt: pointer to the device tree blob
  859. * @nodeoffset: offset of the node whose parent to find
  860. *
  861. * fdt_node_depth() finds the depth of a given node. The root node
  862. * has depth 0, its immediate subnodes depth 1 and so forth.
  863. *
  864. * NOTE: This function is expensive, as it must scan the device tree
  865. * structure from the start to nodeoffset.
  866. *
  867. * returns:
  868. * depth of the node at nodeoffset (>=0), on success
  869. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  870. * -FDT_ERR_BADMAGIC,
  871. * -FDT_ERR_BADVERSION,
  872. * -FDT_ERR_BADSTATE,
  873. * -FDT_ERR_BADSTRUCTURE, standard meanings
  874. */
  875. int fdt_node_depth(const void *fdt, int nodeoffset);
  876. /**
  877. * fdt_parent_offset - find the parent of a given node
  878. * @fdt: pointer to the device tree blob
  879. * @nodeoffset: offset of the node whose parent to find
  880. *
  881. * fdt_parent_offset() locates the parent node of a given node (that
  882. * is, it finds the offset of the node which contains the node at
  883. * nodeoffset as a subnode).
  884. *
  885. * NOTE: This function is expensive, as it must scan the device tree
  886. * structure from the start to nodeoffset, *twice*.
  887. *
  888. * returns:
  889. * structure block offset of the parent of the node at nodeoffset
  890. * (>=0), on success
  891. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  892. * -FDT_ERR_BADMAGIC,
  893. * -FDT_ERR_BADVERSION,
  894. * -FDT_ERR_BADSTATE,
  895. * -FDT_ERR_BADSTRUCTURE, standard meanings
  896. */
  897. int fdt_parent_offset(const void *fdt, int nodeoffset);
  898. /**
  899. * fdt_node_offset_by_prop_value - find nodes with a given property value
  900. * @fdt: pointer to the device tree blob
  901. * @startoffset: only find nodes after this offset
  902. * @propname: property name to check
  903. * @propval: property value to search for
  904. * @proplen: length of the value in propval
  905. *
  906. * fdt_node_offset_by_prop_value() returns the offset of the first
  907. * node after startoffset, which has a property named propname whose
  908. * value is of length proplen and has value equal to propval; or if
  909. * startoffset is -1, the very first such node in the tree.
  910. *
  911. * To iterate through all nodes matching the criterion, the following
  912. * idiom can be used:
  913. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  914. * propval, proplen);
  915. * while (offset != -FDT_ERR_NOTFOUND) {
  916. * // other code here
  917. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  918. * propval, proplen);
  919. * }
  920. *
  921. * Note the -1 in the first call to the function, if 0 is used here
  922. * instead, the function will never locate the root node, even if it
  923. * matches the criterion.
  924. *
  925. * returns:
  926. * structure block offset of the located node (>= 0, >startoffset),
  927. * on success
  928. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  929. * tree after startoffset
  930. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  931. * -FDT_ERR_BADMAGIC,
  932. * -FDT_ERR_BADVERSION,
  933. * -FDT_ERR_BADSTATE,
  934. * -FDT_ERR_BADSTRUCTURE, standard meanings
  935. */
  936. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  937. const char *propname,
  938. const void *propval, int proplen);
  939. /**
  940. * fdt_node_offset_by_phandle - find the node with a given phandle
  941. * @fdt: pointer to the device tree blob
  942. * @phandle: phandle value
  943. *
  944. * fdt_node_offset_by_phandle() returns the offset of the node
  945. * which has the given phandle value. If there is more than one node
  946. * in the tree with the given phandle (an invalid tree), results are
  947. * undefined.
  948. *
  949. * returns:
  950. * structure block offset of the located node (>= 0), on success
  951. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  952. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  953. * -FDT_ERR_BADMAGIC,
  954. * -FDT_ERR_BADVERSION,
  955. * -FDT_ERR_BADSTATE,
  956. * -FDT_ERR_BADSTRUCTURE, standard meanings
  957. */
  958. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  959. /**
  960. * fdt_node_check_compatible - check a node's compatible property
  961. * @fdt: pointer to the device tree blob
  962. * @nodeoffset: offset of a tree node
  963. * @compatible: string to match against
  964. *
  965. * fdt_node_check_compatible() returns 0 if the given node contains a
  966. * @compatible property with the given string as one of its elements,
  967. * it returns non-zero otherwise, or on error.
  968. *
  969. * returns:
  970. * 0, if the node has a 'compatible' property listing the given string
  971. * 1, if the node has a 'compatible' property, but it does not list
  972. * the given string
  973. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  974. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  975. * -FDT_ERR_BADMAGIC,
  976. * -FDT_ERR_BADVERSION,
  977. * -FDT_ERR_BADSTATE,
  978. * -FDT_ERR_BADSTRUCTURE, standard meanings
  979. */
  980. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  981. const char *compatible);
  982. /**
  983. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  984. * @fdt: pointer to the device tree blob
  985. * @startoffset: only find nodes after this offset
  986. * @compatible: 'compatible' string to match against
  987. *
  988. * fdt_node_offset_by_compatible() returns the offset of the first
  989. * node after startoffset, which has a 'compatible' property which
  990. * lists the given compatible string; or if startoffset is -1, the
  991. * very first such node in the tree.
  992. *
  993. * To iterate through all nodes matching the criterion, the following
  994. * idiom can be used:
  995. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  996. * while (offset != -FDT_ERR_NOTFOUND) {
  997. * // other code here
  998. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  999. * }
  1000. *
  1001. * Note the -1 in the first call to the function, if 0 is used here
  1002. * instead, the function will never locate the root node, even if it
  1003. * matches the criterion.
  1004. *
  1005. * returns:
  1006. * structure block offset of the located node (>= 0, >startoffset),
  1007. * on success
  1008. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  1009. * tree after startoffset
  1010. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  1011. * -FDT_ERR_BADMAGIC,
  1012. * -FDT_ERR_BADVERSION,
  1013. * -FDT_ERR_BADSTATE,
  1014. * -FDT_ERR_BADSTRUCTURE, standard meanings
  1015. */
  1016. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  1017. const char *compatible);
  1018. /**
  1019. * fdt_stringlist_contains - check a string list property for a string
  1020. * @strlist: Property containing a list of strings to check
  1021. * @listlen: Length of property
  1022. * @str: String to search for
  1023. *
  1024. * This is a utility function provided for convenience. The list contains
  1025. * one or more strings, each terminated by \0, as is found in a device tree
  1026. * "compatible" property.
  1027. *
  1028. * Return: 1 if the string is found in the list, 0 not found, or invalid list
  1029. */
  1030. int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
  1031. /**
  1032. * fdt_stringlist_count - count the number of strings in a string list
  1033. * @fdt: pointer to the device tree blob
  1034. * @nodeoffset: offset of a tree node
  1035. * @property: name of the property containing the string list
  1036. *
  1037. * Return:
  1038. * the number of strings in the given property
  1039. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1040. * -FDT_ERR_NOTFOUND if the property does not exist
  1041. */
  1042. int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
  1043. /**
  1044. * fdt_stringlist_search - find a string in a string list and return its index
  1045. * @fdt: pointer to the device tree blob
  1046. * @nodeoffset: offset of a tree node
  1047. * @property: name of the property containing the string list
  1048. * @string: string to look up in the string list
  1049. *
  1050. * Note that it is possible for this function to succeed on property values
  1051. * that are not NUL-terminated. That's because the function will stop after
  1052. * finding the first occurrence of @string. This can for example happen with
  1053. * small-valued cell properties, such as #address-cells, when searching for
  1054. * the empty string.
  1055. *
  1056. * return:
  1057. * the index of the string in the list of strings
  1058. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1059. * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
  1060. * the given string
  1061. */
  1062. int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
  1063. const char *string);
  1064. /**
  1065. * fdt_stringlist_get() - obtain the string at a given index in a string list
  1066. * @fdt: pointer to the device tree blob
  1067. * @nodeoffset: offset of a tree node
  1068. * @property: name of the property containing the string list
  1069. * @index: index of the string to return
  1070. * @lenp: return location for the string length or an error code on failure
  1071. *
  1072. * Note that this will successfully extract strings from properties with
  1073. * non-NUL-terminated values. For example on small-valued cell properties
  1074. * this function will return the empty string.
  1075. *
  1076. * If non-NULL, the length of the string (on success) or a negative error-code
  1077. * (on failure) will be stored in the integer pointer to by lenp.
  1078. *
  1079. * Return:
  1080. * A pointer to the string at the given index in the string list or NULL on
  1081. * failure. On success the length of the string will be stored in the memory
  1082. * location pointed to by the lenp parameter, if non-NULL. On failure one of
  1083. * the following negative error codes will be returned in the lenp parameter
  1084. * (if non-NULL):
  1085. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1086. * -FDT_ERR_NOTFOUND if the property does not exist
  1087. */
  1088. const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
  1089. const char *property, int index,
  1090. int *lenp);
  1091. /**********************************************************************/
  1092. /* Read-only functions (addressing related) */
  1093. /**********************************************************************/
  1094. /**
  1095. * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
  1096. *
  1097. * This is the maximum value for #address-cells, #size-cells and
  1098. * similar properties that will be processed by libfdt. IEE1275
  1099. * requires that OF implementations handle values up to 4.
  1100. * Implementations may support larger values, but in practice higher
  1101. * values aren't used.
  1102. */
  1103. #define FDT_MAX_NCELLS 4
  1104. /**
  1105. * fdt_address_cells - retrieve address size for a bus represented in the tree
  1106. * @fdt: pointer to the device tree blob
  1107. * @nodeoffset: offset of the node to find the address size for
  1108. *
  1109. * When the node has a valid #address-cells property, returns its value.
  1110. *
  1111. * returns:
  1112. * 0 <= n < FDT_MAX_NCELLS, on success
  1113. * 2, if the node has no #address-cells property
  1114. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1115. * #address-cells property
  1116. * -FDT_ERR_BADMAGIC,
  1117. * -FDT_ERR_BADVERSION,
  1118. * -FDT_ERR_BADSTATE,
  1119. * -FDT_ERR_BADSTRUCTURE,
  1120. * -FDT_ERR_TRUNCATED, standard meanings
  1121. */
  1122. int fdt_address_cells(const void *fdt, int nodeoffset);
  1123. /**
  1124. * fdt_size_cells - retrieve address range size for a bus represented in the
  1125. * tree
  1126. * @fdt: pointer to the device tree blob
  1127. * @nodeoffset: offset of the node to find the address range size for
  1128. *
  1129. * When the node has a valid #size-cells property, returns its value.
  1130. *
  1131. * returns:
  1132. * 0 <= n < FDT_MAX_NCELLS, on success
  1133. * 1, if the node has no #size-cells property
  1134. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1135. * #size-cells property
  1136. * -FDT_ERR_BADMAGIC,
  1137. * -FDT_ERR_BADVERSION,
  1138. * -FDT_ERR_BADSTATE,
  1139. * -FDT_ERR_BADSTRUCTURE,
  1140. * -FDT_ERR_TRUNCATED, standard meanings
  1141. */
  1142. int fdt_size_cells(const void *fdt, int nodeoffset);
  1143. /**********************************************************************/
  1144. /* Write-in-place functions */
  1145. /**********************************************************************/
  1146. /**
  1147. * fdt_setprop_inplace_namelen_partial - change a property's value,
  1148. * but not its size
  1149. * @fdt: pointer to the device tree blob
  1150. * @nodeoffset: offset of the node whose property to change
  1151. * @name: name of the property to change
  1152. * @namelen: number of characters of name to consider
  1153. * @idx: index of the property to change in the array
  1154. * @val: pointer to data to replace the property value with
  1155. * @len: length of the property value
  1156. *
  1157. * Identical to fdt_setprop_inplace(), but modifies the given property
  1158. * starting from the given index, and using only the first characters
  1159. * of the name. It is useful when you want to manipulate only one value of
  1160. * an array and you have a string that doesn't end with \0.
  1161. *
  1162. * Return: 0 on success, negative libfdt error value otherwise
  1163. */
  1164. #ifndef SWIG /* Not available in Python */
  1165. int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
  1166. const char *name, int namelen,
  1167. uint32_t idx, const void *val,
  1168. int len);
  1169. #endif
  1170. /**
  1171. * fdt_setprop_inplace - change a property's value, but not its size
  1172. * @fdt: pointer to the device tree blob
  1173. * @nodeoffset: offset of the node whose property to change
  1174. * @name: name of the property to change
  1175. * @val: pointer to data to replace the property value with
  1176. * @len: length of the property value
  1177. *
  1178. * fdt_setprop_inplace() replaces the value of a given property with
  1179. * the data in val, of length len. This function cannot change the
  1180. * size of a property, and so will only work if len is equal to the
  1181. * current length of the property.
  1182. *
  1183. * This function will alter only the bytes in the blob which contain
  1184. * the given property value, and will not alter or move any other part
  1185. * of the tree.
  1186. *
  1187. * returns:
  1188. * 0, on success
  1189. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  1190. * -FDT_ERR_NOTFOUND, node does not have the named property
  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,
  1195. * -FDT_ERR_BADSTRUCTURE,
  1196. * -FDT_ERR_TRUNCATED, standard meanings
  1197. */
  1198. #ifndef SWIG /* Not available in Python */
  1199. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  1200. const void *val, int len);
  1201. #endif
  1202. /**
  1203. * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
  1204. * @fdt: pointer to the device tree blob
  1205. * @nodeoffset: offset of the node whose property to change
  1206. * @name: name of the property to change
  1207. * @val: 32-bit integer value to replace the property with
  1208. *
  1209. * fdt_setprop_inplace_u32() replaces the value of a given property
  1210. * with the 32-bit integer value in val, converting val to big-endian
  1211. * if necessary. This function cannot change the size of a property,
  1212. * and so will only work if the property already exists and has length
  1213. * 4.
  1214. *
  1215. * This function will alter only the bytes in the blob which contain
  1216. * the given property value, and will not alter or move any other part
  1217. * of the tree.
  1218. *
  1219. * returns:
  1220. * 0, on success
  1221. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  1222. * -FDT_ERR_NOTFOUND, node does not have the named property
  1223. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1224. * -FDT_ERR_BADMAGIC,
  1225. * -FDT_ERR_BADVERSION,
  1226. * -FDT_ERR_BADSTATE,
  1227. * -FDT_ERR_BADSTRUCTURE,
  1228. * -FDT_ERR_TRUNCATED, standard meanings
  1229. */
  1230. static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
  1231. const char *name, uint32_t val)
  1232. {
  1233. fdt32_t tmp = cpu_to_fdt32(val);
  1234. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1235. }
  1236. /**
  1237. * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
  1238. * @fdt: pointer to the device tree blob
  1239. * @nodeoffset: offset of the node whose property to change
  1240. * @name: name of the property to change
  1241. * @val: 64-bit integer value to replace the property with
  1242. *
  1243. * fdt_setprop_inplace_u64() replaces the value of a given property
  1244. * with the 64-bit integer value in val, converting val to big-endian
  1245. * if necessary. This function cannot change the size of a property,
  1246. * and so will only work if the property already exists and has length
  1247. * 8.
  1248. *
  1249. * This function will alter only the bytes in the blob which contain
  1250. * the given property value, and will not alter or move any other part
  1251. * of the tree.
  1252. *
  1253. * returns:
  1254. * 0, on success
  1255. * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
  1256. * -FDT_ERR_NOTFOUND, node does not have the named property
  1257. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1258. * -FDT_ERR_BADMAGIC,
  1259. * -FDT_ERR_BADVERSION,
  1260. * -FDT_ERR_BADSTATE,
  1261. * -FDT_ERR_BADSTRUCTURE,
  1262. * -FDT_ERR_TRUNCATED, standard meanings
  1263. */
  1264. static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
  1265. const char *name, uint64_t val)
  1266. {
  1267. fdt64_t tmp = cpu_to_fdt64(val);
  1268. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1269. }
  1270. /**
  1271. * fdt_setprop_inplace_cell - change the value of a single-cell property
  1272. * @fdt: pointer to the device tree blob
  1273. * @nodeoffset: offset of the node containing the property
  1274. * @name: name of the property to change the value of
  1275. * @val: new value of the 32-bit cell
  1276. *
  1277. * This is an alternative name for fdt_setprop_inplace_u32()
  1278. * Return: 0 on success, negative libfdt error number otherwise.
  1279. */
  1280. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  1281. const char *name, uint32_t val)
  1282. {
  1283. return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
  1284. }
  1285. /**
  1286. * fdt_nop_property - replace a property with nop tags
  1287. * @fdt: pointer to the device tree blob
  1288. * @nodeoffset: offset of the node whose property to nop
  1289. * @name: name of the property to nop
  1290. *
  1291. * fdt_nop_property() will replace a given property's representation
  1292. * in the blob with FDT_NOP tags, effectively removing it from the
  1293. * tree.
  1294. *
  1295. * This function will alter only the bytes in the blob which contain
  1296. * the property, and will not alter or move any other part of the
  1297. * tree.
  1298. *
  1299. * returns:
  1300. * 0, on success
  1301. * -FDT_ERR_NOTFOUND, node does not have the named property
  1302. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1303. * -FDT_ERR_BADMAGIC,
  1304. * -FDT_ERR_BADVERSION,
  1305. * -FDT_ERR_BADSTATE,
  1306. * -FDT_ERR_BADSTRUCTURE,
  1307. * -FDT_ERR_TRUNCATED, standard meanings
  1308. */
  1309. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  1310. /**
  1311. * fdt_nop_node - replace a node (subtree) with nop tags
  1312. * @fdt: pointer to the device tree blob
  1313. * @nodeoffset: offset of the node to nop
  1314. *
  1315. * fdt_nop_node() will replace a given node's representation in the
  1316. * blob, including all its subnodes, if any, with FDT_NOP tags,
  1317. * effectively removing it from the tree.
  1318. *
  1319. * This function will alter only the bytes in the blob which contain
  1320. * the node and its properties and subnodes, and will not alter or
  1321. * move any other part of the tree.
  1322. *
  1323. * returns:
  1324. * 0, on success
  1325. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1326. * -FDT_ERR_BADMAGIC,
  1327. * -FDT_ERR_BADVERSION,
  1328. * -FDT_ERR_BADSTATE,
  1329. * -FDT_ERR_BADSTRUCTURE,
  1330. * -FDT_ERR_TRUNCATED, standard meanings
  1331. */
  1332. int fdt_nop_node(void *fdt, int nodeoffset);
  1333. /**********************************************************************/
  1334. /* Sequential write functions */
  1335. /**********************************************************************/
  1336. /* fdt_create_with_flags flags */
  1337. #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
  1338. /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
  1339. * names in the fdt. This can result in faster creation times, but
  1340. * a larger fdt. */
  1341. #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
  1342. /**
  1343. * fdt_create_with_flags - begin creation of a new fdt
  1344. * @buf: pointer to memory allocated where fdt will be created
  1345. * @bufsize: size of the memory space at fdt
  1346. * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
  1347. *
  1348. * fdt_create_with_flags() begins the process of creating a new fdt with
  1349. * the sequential write interface.
  1350. *
  1351. * fdt creation process must end with fdt_finished() to produce a valid fdt.
  1352. *
  1353. * returns:
  1354. * 0, on success
  1355. * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
  1356. * -FDT_ERR_BADFLAGS, flags is not valid
  1357. */
  1358. int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
  1359. /**
  1360. * fdt_create - begin creation of a new fdt
  1361. * @buf: pointer to memory allocated where fdt will be created
  1362. * @bufsize: size of the memory space at fdt
  1363. *
  1364. * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
  1365. *
  1366. * returns:
  1367. * 0, on success
  1368. * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
  1369. */
  1370. int fdt_create(void *buf, int bufsize);
  1371. int fdt_resize(void *fdt, void *buf, int bufsize);
  1372. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  1373. int fdt_finish_reservemap(void *fdt);
  1374. int fdt_begin_node(void *fdt, const char *name);
  1375. int fdt_property(void *fdt, const char *name, const void *val, int len);
  1376. static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
  1377. {
  1378. fdt32_t tmp = cpu_to_fdt32(val);
  1379. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1380. }
  1381. static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
  1382. {
  1383. fdt64_t tmp = cpu_to_fdt64(val);
  1384. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1385. }
  1386. #ifndef SWIG /* Not available in Python */
  1387. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  1388. {
  1389. return fdt_property_u32(fdt, name, val);
  1390. }
  1391. #endif
  1392. /**
  1393. * fdt_property_placeholder - add a new property and return a ptr to its value
  1394. *
  1395. * @fdt: pointer to the device tree blob
  1396. * @name: name of property to add
  1397. * @len: length of property value in bytes
  1398. * @valp: returns a pointer to where where the value should be placed
  1399. *
  1400. * returns:
  1401. * 0, on success
  1402. * -FDT_ERR_BADMAGIC,
  1403. * -FDT_ERR_NOSPACE, standard meanings
  1404. */
  1405. int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
  1406. #define fdt_property_string(fdt, name, str) \
  1407. fdt_property(fdt, name, str, strlen(str)+1)
  1408. int fdt_end_node(void *fdt);
  1409. int fdt_finish(void *fdt);
  1410. /**********************************************************************/
  1411. /* Read-write functions */
  1412. /**********************************************************************/
  1413. int fdt_create_empty_tree(void *buf, int bufsize);
  1414. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  1415. int fdt_pack(void *fdt);
  1416. /**
  1417. * fdt_add_mem_rsv - add one memory reserve map entry
  1418. * @fdt: pointer to the device tree blob
  1419. * @address: 64-bit start address of the reserve map entry
  1420. * @size: 64-bit size of the reserved region
  1421. *
  1422. * Adds a reserve map entry to the given blob reserving a region at
  1423. * address address of length size.
  1424. *
  1425. * This function will insert data into the reserve map and will
  1426. * therefore change the indexes of some entries in the table.
  1427. *
  1428. * returns:
  1429. * 0, on success
  1430. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1431. * contain the new reservation entry
  1432. * -FDT_ERR_BADMAGIC,
  1433. * -FDT_ERR_BADVERSION,
  1434. * -FDT_ERR_BADSTATE,
  1435. * -FDT_ERR_BADSTRUCTURE,
  1436. * -FDT_ERR_BADLAYOUT,
  1437. * -FDT_ERR_TRUNCATED, standard meanings
  1438. */
  1439. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  1440. /**
  1441. * fdt_del_mem_rsv - remove a memory reserve map entry
  1442. * @fdt: pointer to the device tree blob
  1443. * @n: entry to remove
  1444. *
  1445. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  1446. * the blob.
  1447. *
  1448. * This function will delete data from the reservation table and will
  1449. * therefore change the indexes of some entries in the table.
  1450. *
  1451. * returns:
  1452. * 0, on success
  1453. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  1454. * are less than n+1 reserve map entries)
  1455. * -FDT_ERR_BADMAGIC,
  1456. * -FDT_ERR_BADVERSION,
  1457. * -FDT_ERR_BADSTATE,
  1458. * -FDT_ERR_BADSTRUCTURE,
  1459. * -FDT_ERR_BADLAYOUT,
  1460. * -FDT_ERR_TRUNCATED, standard meanings
  1461. */
  1462. int fdt_del_mem_rsv(void *fdt, int n);
  1463. /**
  1464. * fdt_set_name - change the name of a given node
  1465. * @fdt: pointer to the device tree blob
  1466. * @nodeoffset: structure block offset of a node
  1467. * @name: name to give the node
  1468. *
  1469. * fdt_set_name() replaces the name (including unit address, if any)
  1470. * of the given node with the given string. NOTE: this function can't
  1471. * efficiently check if the new name is unique amongst the given
  1472. * node's siblings; results are undefined if this function is invoked
  1473. * with a name equal to one of the given node's siblings.
  1474. *
  1475. * This function may insert or delete data from the blob, and will
  1476. * therefore change the offsets of some existing nodes.
  1477. *
  1478. * returns:
  1479. * 0, on success
  1480. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  1481. * to contain the new name
  1482. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1483. * -FDT_ERR_BADMAGIC,
  1484. * -FDT_ERR_BADVERSION,
  1485. * -FDT_ERR_BADSTATE, standard meanings
  1486. */
  1487. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  1488. /**
  1489. * fdt_setprop - create or change a property
  1490. * @fdt: pointer to the device tree blob
  1491. * @nodeoffset: offset of the node whose property to change
  1492. * @name: name of the property to change
  1493. * @val: pointer to data to set the property value to
  1494. * @len: length of the property value
  1495. *
  1496. * fdt_setprop() sets the value of the named property in the given
  1497. * node to the given value and length, creating the property if it
  1498. * does not already exist.
  1499. *
  1500. * This function may insert or delete data from the blob, and will
  1501. * therefore change the offsets of some existing nodes.
  1502. *
  1503. * returns:
  1504. * 0, on success
  1505. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1506. * contain the new property value
  1507. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1508. * -FDT_ERR_BADLAYOUT,
  1509. * -FDT_ERR_BADMAGIC,
  1510. * -FDT_ERR_BADVERSION,
  1511. * -FDT_ERR_BADSTATE,
  1512. * -FDT_ERR_BADSTRUCTURE,
  1513. * -FDT_ERR_BADLAYOUT,
  1514. * -FDT_ERR_TRUNCATED, standard meanings
  1515. */
  1516. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  1517. const void *val, int len);
  1518. /**
  1519. * fdt_setprop_placeholder - allocate space for a property
  1520. * @fdt: pointer to the device tree blob
  1521. * @nodeoffset: offset of the node whose property to change
  1522. * @name: name of the property to change
  1523. * @len: length of the property value
  1524. * @prop_data: return pointer to property data
  1525. *
  1526. * fdt_setprop_placeholer() allocates the named property in the given node.
  1527. * If the property exists it is resized. In either case a pointer to the
  1528. * property data is returned.
  1529. *
  1530. * This function may insert or delete data from the blob, and will
  1531. * therefore change the offsets of some existing nodes.
  1532. *
  1533. * returns:
  1534. * 0, on success
  1535. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1536. * contain the new property value
  1537. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1538. * -FDT_ERR_BADLAYOUT,
  1539. * -FDT_ERR_BADMAGIC,
  1540. * -FDT_ERR_BADVERSION,
  1541. * -FDT_ERR_BADSTATE,
  1542. * -FDT_ERR_BADSTRUCTURE,
  1543. * -FDT_ERR_BADLAYOUT,
  1544. * -FDT_ERR_TRUNCATED, standard meanings
  1545. */
  1546. int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
  1547. int len, void **prop_data);
  1548. /**
  1549. * fdt_setprop_u32 - set a property to a 32-bit integer
  1550. * @fdt: pointer to the device tree blob
  1551. * @nodeoffset: offset of the node whose property to change
  1552. * @name: name of the property to change
  1553. * @val: 32-bit integer value for the property (native endian)
  1554. *
  1555. * fdt_setprop_u32() sets the value of the named property in the given
  1556. * node to the given 32-bit integer value (converting to big-endian if
  1557. * necessary), or creates a new property with that value if it does
  1558. * not already exist.
  1559. *
  1560. * This function may insert or delete data from the blob, and will
  1561. * therefore change the offsets of some existing nodes.
  1562. *
  1563. * returns:
  1564. * 0, on success
  1565. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1566. * contain the new property value
  1567. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1568. * -FDT_ERR_BADLAYOUT,
  1569. * -FDT_ERR_BADMAGIC,
  1570. * -FDT_ERR_BADVERSION,
  1571. * -FDT_ERR_BADSTATE,
  1572. * -FDT_ERR_BADSTRUCTURE,
  1573. * -FDT_ERR_BADLAYOUT,
  1574. * -FDT_ERR_TRUNCATED, standard meanings
  1575. */
  1576. static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
  1577. uint32_t val)
  1578. {
  1579. fdt32_t tmp = cpu_to_fdt32(val);
  1580. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1581. }
  1582. /**
  1583. * fdt_setprop_u64 - set a property to a 64-bit integer
  1584. * @fdt: pointer to the device tree blob
  1585. * @nodeoffset: offset of the node whose property to change
  1586. * @name: name of the property to change
  1587. * @val: 64-bit integer value for the property (native endian)
  1588. *
  1589. * fdt_setprop_u64() sets the value of the named property in the given
  1590. * node to the given 64-bit integer value (converting to big-endian if
  1591. * necessary), or creates a new property with that value if it does
  1592. * not already exist.
  1593. *
  1594. * This function may insert or delete data from the blob, and will
  1595. * therefore change the offsets of some existing nodes.
  1596. *
  1597. * returns:
  1598. * 0, on success
  1599. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1600. * contain the new property value
  1601. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1602. * -FDT_ERR_BADLAYOUT,
  1603. * -FDT_ERR_BADMAGIC,
  1604. * -FDT_ERR_BADVERSION,
  1605. * -FDT_ERR_BADSTATE,
  1606. * -FDT_ERR_BADSTRUCTURE,
  1607. * -FDT_ERR_BADLAYOUT,
  1608. * -FDT_ERR_TRUNCATED, standard meanings
  1609. */
  1610. static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
  1611. uint64_t val)
  1612. {
  1613. fdt64_t tmp = cpu_to_fdt64(val);
  1614. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1615. }
  1616. /**
  1617. * fdt_setprop_cell - set a property to a single cell value
  1618. * @fdt: pointer to the device tree blob
  1619. * @nodeoffset: offset of the node whose property to change
  1620. * @name: name of the property to change
  1621. * @val: 32-bit integer value for the property (native endian)
  1622. *
  1623. * This is an alternative name for fdt_setprop_u32()
  1624. *
  1625. * Return: 0 on success, negative libfdt error value otherwise.
  1626. */
  1627. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  1628. uint32_t val)
  1629. {
  1630. return fdt_setprop_u32(fdt, nodeoffset, name, val);
  1631. }
  1632. /**
  1633. * fdt_setprop_string - set a property to a string value
  1634. * @fdt: pointer to the device tree blob
  1635. * @nodeoffset: offset of the node whose property to change
  1636. * @name: name of the property to change
  1637. * @str: string value for the property
  1638. *
  1639. * fdt_setprop_string() sets the value of the named property in the
  1640. * given node to the given string value (using the length of the
  1641. * string to determine the new length of the property), or creates a
  1642. * new property with that value if it does not already exist.
  1643. *
  1644. * This function may insert or delete data from the blob, and will
  1645. * therefore change the offsets of some existing nodes.
  1646. *
  1647. * returns:
  1648. * 0, on success
  1649. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1650. * contain the new property value
  1651. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1652. * -FDT_ERR_BADLAYOUT,
  1653. * -FDT_ERR_BADMAGIC,
  1654. * -FDT_ERR_BADVERSION,
  1655. * -FDT_ERR_BADSTATE,
  1656. * -FDT_ERR_BADSTRUCTURE,
  1657. * -FDT_ERR_BADLAYOUT,
  1658. * -FDT_ERR_TRUNCATED, standard meanings
  1659. */
  1660. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  1661. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1662. /**
  1663. * fdt_setprop_empty - set a property to an empty value
  1664. * @fdt: pointer to the device tree blob
  1665. * @nodeoffset: offset of the node whose property to change
  1666. * @name: name of the property to change
  1667. *
  1668. * fdt_setprop_empty() sets the value of the named property in the
  1669. * given node to an empty (zero length) value, or creates a new empty
  1670. * property if it does not already exist.
  1671. *
  1672. * This function may insert or delete data from the blob, and will
  1673. * therefore change the offsets of some existing nodes.
  1674. *
  1675. * returns:
  1676. * 0, on success
  1677. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1678. * contain the new property value
  1679. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1680. * -FDT_ERR_BADLAYOUT,
  1681. * -FDT_ERR_BADMAGIC,
  1682. * -FDT_ERR_BADVERSION,
  1683. * -FDT_ERR_BADSTATE,
  1684. * -FDT_ERR_BADSTRUCTURE,
  1685. * -FDT_ERR_BADLAYOUT,
  1686. * -FDT_ERR_TRUNCATED, standard meanings
  1687. */
  1688. #define fdt_setprop_empty(fdt, nodeoffset, name) \
  1689. fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
  1690. /**
  1691. * fdt_appendprop - append to or create a property
  1692. * @fdt: pointer to the device tree blob
  1693. * @nodeoffset: offset of the node whose property to change
  1694. * @name: name of the property to append to
  1695. * @val: pointer to data to append to the property value
  1696. * @len: length of the data to append to the property value
  1697. *
  1698. * fdt_appendprop() appends the value to the named property in the
  1699. * given node, creating the property if it does not already exist.
  1700. *
  1701. * This function may insert data into the blob, and will therefore
  1702. * change the offsets of some existing nodes.
  1703. *
  1704. * returns:
  1705. * 0, on success
  1706. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1707. * contain the new property value
  1708. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1709. * -FDT_ERR_BADLAYOUT,
  1710. * -FDT_ERR_BADMAGIC,
  1711. * -FDT_ERR_BADVERSION,
  1712. * -FDT_ERR_BADSTATE,
  1713. * -FDT_ERR_BADSTRUCTURE,
  1714. * -FDT_ERR_BADLAYOUT,
  1715. * -FDT_ERR_TRUNCATED, standard meanings
  1716. */
  1717. int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
  1718. const void *val, int len);
  1719. /**
  1720. * fdt_appendprop_u32 - append a 32-bit integer value to a property
  1721. * @fdt: pointer to the device tree blob
  1722. * @nodeoffset: offset of the node whose property to change
  1723. * @name: name of the property to change
  1724. * @val: 32-bit integer value to append to the property (native endian)
  1725. *
  1726. * fdt_appendprop_u32() appends the given 32-bit integer value
  1727. * (converting to big-endian if necessary) to the value of the named
  1728. * property in the given node, or creates a new property with that
  1729. * value if it does not already exist.
  1730. *
  1731. * This function may insert data into the blob, and will therefore
  1732. * change the offsets of some existing nodes.
  1733. *
  1734. * returns:
  1735. * 0, on success
  1736. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1737. * contain the new property value
  1738. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1739. * -FDT_ERR_BADLAYOUT,
  1740. * -FDT_ERR_BADMAGIC,
  1741. * -FDT_ERR_BADVERSION,
  1742. * -FDT_ERR_BADSTATE,
  1743. * -FDT_ERR_BADSTRUCTURE,
  1744. * -FDT_ERR_BADLAYOUT,
  1745. * -FDT_ERR_TRUNCATED, standard meanings
  1746. */
  1747. static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
  1748. const char *name, uint32_t val)
  1749. {
  1750. fdt32_t tmp = cpu_to_fdt32(val);
  1751. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1752. }
  1753. /**
  1754. * fdt_appendprop_u64 - append a 64-bit integer value to a property
  1755. * @fdt: pointer to the device tree blob
  1756. * @nodeoffset: offset of the node whose property to change
  1757. * @name: name of the property to change
  1758. * @val: 64-bit integer value to append to the property (native endian)
  1759. *
  1760. * fdt_appendprop_u64() appends the given 64-bit integer value
  1761. * (converting to big-endian if necessary) to the value of the named
  1762. * property in the given node, or creates a new property with that
  1763. * value if it does not already exist.
  1764. *
  1765. * This function may insert data into the blob, and will therefore
  1766. * change the offsets of some existing nodes.
  1767. *
  1768. * returns:
  1769. * 0, on success
  1770. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1771. * contain the new property value
  1772. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1773. * -FDT_ERR_BADLAYOUT,
  1774. * -FDT_ERR_BADMAGIC,
  1775. * -FDT_ERR_BADVERSION,
  1776. * -FDT_ERR_BADSTATE,
  1777. * -FDT_ERR_BADSTRUCTURE,
  1778. * -FDT_ERR_BADLAYOUT,
  1779. * -FDT_ERR_TRUNCATED, standard meanings
  1780. */
  1781. static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
  1782. const char *name, uint64_t val)
  1783. {
  1784. fdt64_t tmp = cpu_to_fdt64(val);
  1785. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1786. }
  1787. /**
  1788. * fdt_appendprop_cell - append a single cell value to a property
  1789. * @fdt: pointer to the device tree blob
  1790. * @nodeoffset: offset of the node whose property to change
  1791. * @name: name of the property to change
  1792. * @val: 32-bit integer value to append to the property (native endian)
  1793. *
  1794. * This is an alternative name for fdt_appendprop_u32()
  1795. *
  1796. * Return: 0 on success, negative libfdt error value otherwise.
  1797. */
  1798. static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
  1799. const char *name, uint32_t val)
  1800. {
  1801. return fdt_appendprop_u32(fdt, nodeoffset, name, val);
  1802. }
  1803. /**
  1804. * fdt_appendprop_string - append a string to a property
  1805. * @fdt: pointer to the device tree blob
  1806. * @nodeoffset: offset of the node whose property to change
  1807. * @name: name of the property to change
  1808. * @str: string value to append to the property
  1809. *
  1810. * fdt_appendprop_string() appends the given string to the value of
  1811. * the named property in the given node, or creates a new property
  1812. * with that value if it does not already exist.
  1813. *
  1814. * This function may insert data into the blob, and will therefore
  1815. * change the offsets of some existing nodes.
  1816. *
  1817. * returns:
  1818. * 0, on success
  1819. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1820. * contain the new property value
  1821. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1822. * -FDT_ERR_BADLAYOUT,
  1823. * -FDT_ERR_BADMAGIC,
  1824. * -FDT_ERR_BADVERSION,
  1825. * -FDT_ERR_BADSTATE,
  1826. * -FDT_ERR_BADSTRUCTURE,
  1827. * -FDT_ERR_BADLAYOUT,
  1828. * -FDT_ERR_TRUNCATED, standard meanings
  1829. */
  1830. #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
  1831. fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1832. /**
  1833. * fdt_appendprop_addrrange - append a address range property
  1834. * @fdt: pointer to the device tree blob
  1835. * @parent: offset of the parent node
  1836. * @nodeoffset: offset of the node to add a property at
  1837. * @name: name of property
  1838. * @addr: start address of a given range
  1839. * @size: size of a given range
  1840. *
  1841. * fdt_appendprop_addrrange() appends an address range value (start
  1842. * address and size) to the value of the named property in the given
  1843. * node, or creates a new property with that value if it does not
  1844. * already exist.
  1845. * If "name" is not specified, a default "reg" is used.
  1846. * Cell sizes are determined by parent's #address-cells and #size-cells.
  1847. *
  1848. * This function may insert data into the blob, and will therefore
  1849. * change the offsets of some existing nodes.
  1850. *
  1851. * returns:
  1852. * 0, on success
  1853. * -FDT_ERR_BADLAYOUT,
  1854. * -FDT_ERR_BADMAGIC,
  1855. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1856. * #address-cells property
  1857. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1858. * -FDT_ERR_BADSTATE,
  1859. * -FDT_ERR_BADSTRUCTURE,
  1860. * -FDT_ERR_BADVERSION,
  1861. * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
  1862. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1863. * contain a new property
  1864. * -FDT_ERR_TRUNCATED, standard meanings
  1865. */
  1866. int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
  1867. const char *name, uint64_t addr, uint64_t size);
  1868. /**
  1869. * fdt_delprop - delete a property
  1870. * @fdt: pointer to the device tree blob
  1871. * @nodeoffset: offset of the node whose property to nop
  1872. * @name: name of the property to nop
  1873. *
  1874. * fdt_del_property() will delete the given property.
  1875. *
  1876. * This function will delete data from the blob, and will therefore
  1877. * change the offsets of some existing nodes.
  1878. *
  1879. * returns:
  1880. * 0, on success
  1881. * -FDT_ERR_NOTFOUND, node does not have the named property
  1882. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1883. * -FDT_ERR_BADLAYOUT,
  1884. * -FDT_ERR_BADMAGIC,
  1885. * -FDT_ERR_BADVERSION,
  1886. * -FDT_ERR_BADSTATE,
  1887. * -FDT_ERR_BADSTRUCTURE,
  1888. * -FDT_ERR_TRUNCATED, standard meanings
  1889. */
  1890. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  1891. /**
  1892. * fdt_add_subnode_namelen - creates a new node based on substring
  1893. * @fdt: pointer to the device tree blob
  1894. * @parentoffset: structure block offset of a node
  1895. * @name: name of the subnode to create
  1896. * @namelen: number of characters of name to consider
  1897. *
  1898. * Identical to fdt_add_subnode(), but use only the first @namelen
  1899. * characters of @name as the name of the new node. This is useful for
  1900. * creating subnodes based on a portion of a larger string, such as a
  1901. * full path.
  1902. *
  1903. * Return: structure block offset of the created subnode (>=0),
  1904. * negative libfdt error value otherwise
  1905. */
  1906. #ifndef SWIG /* Not available in Python */
  1907. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  1908. const char *name, int namelen);
  1909. #endif
  1910. /**
  1911. * fdt_add_subnode - creates a new node
  1912. * @fdt: pointer to the device tree blob
  1913. * @parentoffset: structure block offset of a node
  1914. * @name: name of the subnode to locate
  1915. *
  1916. * fdt_add_subnode() creates a new node as a subnode of the node at
  1917. * structure block offset parentoffset, with the given name (which
  1918. * should include the unit address, if any).
  1919. *
  1920. * This function will insert data into the blob, and will therefore
  1921. * change the offsets of some existing nodes.
  1922. *
  1923. * returns:
  1924. * structure block offset of the created nodeequested subnode (>=0), on
  1925. * success
  1926. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  1927. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
  1928. * tag
  1929. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  1930. * the given name
  1931. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  1932. * blob to contain the new node
  1933. * -FDT_ERR_NOSPACE
  1934. * -FDT_ERR_BADLAYOUT
  1935. * -FDT_ERR_BADMAGIC,
  1936. * -FDT_ERR_BADVERSION,
  1937. * -FDT_ERR_BADSTATE,
  1938. * -FDT_ERR_BADSTRUCTURE,
  1939. * -FDT_ERR_TRUNCATED, standard meanings.
  1940. */
  1941. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  1942. /**
  1943. * fdt_del_node - delete a node (subtree)
  1944. * @fdt: pointer to the device tree blob
  1945. * @nodeoffset: offset of the node to nop
  1946. *
  1947. * fdt_del_node() will remove the given node, including all its
  1948. * subnodes if any, from the blob.
  1949. *
  1950. * This function will delete data from the blob, and will therefore
  1951. * change the offsets of some existing nodes.
  1952. *
  1953. * returns:
  1954. * 0, on success
  1955. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1956. * -FDT_ERR_BADLAYOUT,
  1957. * -FDT_ERR_BADMAGIC,
  1958. * -FDT_ERR_BADVERSION,
  1959. * -FDT_ERR_BADSTATE,
  1960. * -FDT_ERR_BADSTRUCTURE,
  1961. * -FDT_ERR_TRUNCATED, standard meanings
  1962. */
  1963. int fdt_del_node(void *fdt, int nodeoffset);
  1964. /**
  1965. * fdt_overlay_apply - Applies a DT overlay on a base DT
  1966. * @fdt: pointer to the base device tree blob
  1967. * @fdto: pointer to the device tree overlay blob
  1968. *
  1969. * fdt_overlay_apply() will apply the given device tree overlay on the
  1970. * given base device tree.
  1971. *
  1972. * Expect the base device tree to be modified, even if the function
  1973. * returns an error.
  1974. *
  1975. * returns:
  1976. * 0, on success
  1977. * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
  1978. * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
  1979. * properties in the base DT
  1980. * -FDT_ERR_BADPHANDLE,
  1981. * -FDT_ERR_BADOVERLAY,
  1982. * -FDT_ERR_NOPHANDLES,
  1983. * -FDT_ERR_INTERNAL,
  1984. * -FDT_ERR_BADLAYOUT,
  1985. * -FDT_ERR_BADMAGIC,
  1986. * -FDT_ERR_BADOFFSET,
  1987. * -FDT_ERR_BADPATH,
  1988. * -FDT_ERR_BADVERSION,
  1989. * -FDT_ERR_BADSTRUCTURE,
  1990. * -FDT_ERR_BADSTATE,
  1991. * -FDT_ERR_TRUNCATED, standard meanings
  1992. */
  1993. int fdt_overlay_apply(void *fdt, void *fdto);
  1994. /**********************************************************************/
  1995. /* Debugging / informational functions */
  1996. /**********************************************************************/
  1997. const char *fdt_strerror(int errval);
  1998. #ifdef __cplusplus
  1999. }
  2000. #endif
  2001. #endif /* LIBFDT_H */