libfdt.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154
  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. static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt,
  606. int offset,
  607. int *lenp)
  608. {
  609. return (struct fdt_property *)(uintptr_t)
  610. fdt_get_property_by_offset(fdt, offset, lenp);
  611. }
  612. /**
  613. * fdt_get_property_namelen - find a property based on substring
  614. * @fdt: pointer to the device tree blob
  615. * @nodeoffset: offset of the node whose property to find
  616. * @name: name of the property to find
  617. * @namelen: number of characters of name to consider
  618. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  619. *
  620. * Identical to fdt_get_property(), but only examine the first namelen
  621. * characters of name for matching the property name.
  622. *
  623. * Return: pointer to the structure representing the property, or NULL
  624. * if not found
  625. */
  626. #ifndef SWIG /* Not available in Python */
  627. const struct fdt_property *fdt_get_property_namelen(const void *fdt,
  628. int nodeoffset,
  629. const char *name,
  630. int namelen, int *lenp);
  631. #endif
  632. /**
  633. * fdt_get_property - find a given property in a given node
  634. * @fdt: pointer to the device tree blob
  635. * @nodeoffset: offset of the node whose property to find
  636. * @name: name of the property to find
  637. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  638. *
  639. * fdt_get_property() retrieves a pointer to the fdt_property
  640. * structure within the device tree blob corresponding to the property
  641. * named 'name' of the node at offset nodeoffset. If lenp is
  642. * non-NULL, the length of the property value is also returned, in the
  643. * integer pointed to by lenp.
  644. *
  645. * returns:
  646. * pointer to the structure representing the property
  647. * if lenp is non-NULL, *lenp contains the length of the property
  648. * value (>=0)
  649. * NULL, on error
  650. * if lenp is non-NULL, *lenp contains an error code (<0):
  651. * -FDT_ERR_NOTFOUND, node does not have named property
  652. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
  653. * tag
  654. * -FDT_ERR_BADMAGIC,
  655. * -FDT_ERR_BADVERSION,
  656. * -FDT_ERR_BADSTATE,
  657. * -FDT_ERR_BADSTRUCTURE,
  658. * -FDT_ERR_TRUNCATED, standard meanings
  659. */
  660. const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  661. const char *name, int *lenp);
  662. static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
  663. const char *name,
  664. int *lenp)
  665. {
  666. return (struct fdt_property *)(uintptr_t)
  667. fdt_get_property(fdt, nodeoffset, name, lenp);
  668. }
  669. /**
  670. * fdt_getprop_by_offset - retrieve the value of a property at a given offset
  671. * @fdt: pointer to the device tree blob
  672. * @offset: offset of the property to read
  673. * @namep: pointer to a string variable (will be overwritten) or NULL
  674. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  675. *
  676. * fdt_getprop_by_offset() retrieves a pointer to the value of the
  677. * property at structure block offset 'offset' (this will be a pointer
  678. * to within the device blob itself, not a copy of the value). If
  679. * lenp is non-NULL, the length of the property value is also
  680. * returned, in the integer pointed to by lenp. If namep is non-NULL,
  681. * the property's namne will also be returned in the char * pointed to
  682. * by namep (this will be a pointer to within the device tree's string
  683. * block, not a new copy of the name).
  684. *
  685. * returns:
  686. * pointer to the property's value
  687. * if lenp is non-NULL, *lenp contains the length of the property
  688. * value (>=0)
  689. * if namep is non-NULL *namep contiains a pointer to the property
  690. * name.
  691. * NULL, on error
  692. * if lenp is non-NULL, *lenp contains an error code (<0):
  693. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
  694. * -FDT_ERR_BADMAGIC,
  695. * -FDT_ERR_BADVERSION,
  696. * -FDT_ERR_BADSTATE,
  697. * -FDT_ERR_BADSTRUCTURE,
  698. * -FDT_ERR_TRUNCATED, standard meanings
  699. */
  700. #ifndef SWIG /* This function is not useful in Python */
  701. const void *fdt_getprop_by_offset(const void *fdt, int offset,
  702. const char **namep, int *lenp);
  703. #endif
  704. /**
  705. * fdt_getprop_namelen - get property value based on substring
  706. * @fdt: pointer to the device tree blob
  707. * @nodeoffset: offset of the node whose property to find
  708. * @name: name of the property to find
  709. * @namelen: number of characters of name to consider
  710. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  711. *
  712. * Identical to fdt_getprop(), but only examine the first namelen
  713. * characters of name for matching the property name.
  714. *
  715. * Return: pointer to the property's value or NULL on error
  716. */
  717. #ifndef SWIG /* Not available in Python */
  718. const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
  719. const char *name, int namelen, int *lenp);
  720. static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
  721. const char *name, int namelen,
  722. int *lenp)
  723. {
  724. return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
  725. namelen, lenp);
  726. }
  727. #endif
  728. /**
  729. * fdt_getprop - retrieve the value of a given property
  730. * @fdt: pointer to the device tree blob
  731. * @nodeoffset: offset of the node whose property to find
  732. * @name: name of the property to find
  733. * @lenp: pointer to an integer variable (will be overwritten) or NULL
  734. *
  735. * fdt_getprop() retrieves a pointer to the value of the property
  736. * named @name of the node at offset @nodeoffset (this will be a
  737. * pointer to within the device blob itself, not a copy of the value).
  738. * If @lenp is non-NULL, the length of the property value is also
  739. * returned, in the integer pointed to by @lenp.
  740. *
  741. * returns:
  742. * pointer to the property's value
  743. * if lenp is non-NULL, *lenp contains the length of the property
  744. * value (>=0)
  745. * NULL, on error
  746. * if lenp is non-NULL, *lenp contains an error code (<0):
  747. * -FDT_ERR_NOTFOUND, node does not have named property
  748. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
  749. * tag
  750. * -FDT_ERR_BADMAGIC,
  751. * -FDT_ERR_BADVERSION,
  752. * -FDT_ERR_BADSTATE,
  753. * -FDT_ERR_BADSTRUCTURE,
  754. * -FDT_ERR_TRUNCATED, standard meanings
  755. */
  756. const void *fdt_getprop(const void *fdt, int nodeoffset,
  757. const char *name, int *lenp);
  758. static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  759. const char *name, int *lenp)
  760. {
  761. return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
  762. }
  763. /**
  764. * fdt_get_phandle - retrieve the phandle of a given node
  765. * @fdt: pointer to the device tree blob
  766. * @nodeoffset: structure block offset of the node
  767. *
  768. * fdt_get_phandle() retrieves the phandle of the device tree node at
  769. * structure block offset nodeoffset.
  770. *
  771. * returns:
  772. * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  773. * 0, if the node has no phandle, or another error occurs
  774. */
  775. uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
  776. /**
  777. * fdt_get_alias_namelen - get alias based on substring
  778. * @fdt: pointer to the device tree blob
  779. * @name: name of the alias th look up
  780. * @namelen: number of characters of name to consider
  781. *
  782. * Identical to fdt_get_alias(), but only examine the first @namelen
  783. * characters of @name for matching the alias name.
  784. *
  785. * Return: a pointer to the expansion of the alias named @name, if it exists,
  786. * NULL otherwise
  787. */
  788. #ifndef SWIG /* Not available in Python */
  789. const char *fdt_get_alias_namelen(const void *fdt,
  790. const char *name, int namelen);
  791. #endif
  792. /**
  793. * fdt_get_alias - retrieve the path referenced by a given alias
  794. * @fdt: pointer to the device tree blob
  795. * @name: name of the alias th look up
  796. *
  797. * fdt_get_alias() retrieves the value of a given alias. That is, the
  798. * value of the property named @name in the node /aliases.
  799. *
  800. * returns:
  801. * a pointer to the expansion of the alias named 'name', if it exists
  802. * NULL, if the given alias or the /aliases node does not exist
  803. */
  804. const char *fdt_get_alias(const void *fdt, const char *name);
  805. /**
  806. * fdt_get_path - determine the full path of a node
  807. * @fdt: pointer to the device tree blob
  808. * @nodeoffset: offset of the node whose path to find
  809. * @buf: character buffer to contain the returned path (will be overwritten)
  810. * @buflen: size of the character buffer at buf
  811. *
  812. * fdt_get_path() computes the full path of the node at offset
  813. * nodeoffset, and records that path in the buffer at buf.
  814. *
  815. * NOTE: This function is expensive, as it must scan the device tree
  816. * structure from the start to nodeoffset.
  817. *
  818. * returns:
  819. * 0, on success
  820. * buf contains the absolute path of the node at
  821. * nodeoffset, as a NUL-terminated string.
  822. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  823. * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
  824. * characters and will not fit in the given buffer.
  825. * -FDT_ERR_BADMAGIC,
  826. * -FDT_ERR_BADVERSION,
  827. * -FDT_ERR_BADSTATE,
  828. * -FDT_ERR_BADSTRUCTURE, standard meanings
  829. */
  830. int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
  831. /**
  832. * fdt_supernode_atdepth_offset - find a specific ancestor of a node
  833. * @fdt: pointer to the device tree blob
  834. * @nodeoffset: offset of the node whose parent to find
  835. * @supernodedepth: depth of the ancestor to find
  836. * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
  837. *
  838. * fdt_supernode_atdepth_offset() finds an ancestor of the given node
  839. * at a specific depth from the root (where the root itself has depth
  840. * 0, its immediate subnodes depth 1 and so forth). So
  841. * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
  842. * will always return 0, the offset of the root node. If the node at
  843. * nodeoffset has depth D, then:
  844. * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
  845. * will return nodeoffset itself.
  846. *
  847. * NOTE: This function is expensive, as it must scan the device tree
  848. * structure from the start to nodeoffset.
  849. *
  850. * returns:
  851. * structure block offset of the node at node offset's ancestor
  852. * of depth supernodedepth (>=0), on success
  853. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  854. * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
  855. * nodeoffset
  856. * -FDT_ERR_BADMAGIC,
  857. * -FDT_ERR_BADVERSION,
  858. * -FDT_ERR_BADSTATE,
  859. * -FDT_ERR_BADSTRUCTURE, standard meanings
  860. */
  861. int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
  862. int supernodedepth, int *nodedepth);
  863. /**
  864. * fdt_node_depth - find the depth of a given node
  865. * @fdt: pointer to the device tree blob
  866. * @nodeoffset: offset of the node whose parent to find
  867. *
  868. * fdt_node_depth() finds the depth of a given node. The root node
  869. * has depth 0, its immediate subnodes depth 1 and so forth.
  870. *
  871. * NOTE: This function is expensive, as it must scan the device tree
  872. * structure from the start to nodeoffset.
  873. *
  874. * returns:
  875. * depth of the node at nodeoffset (>=0), on success
  876. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  877. * -FDT_ERR_BADMAGIC,
  878. * -FDT_ERR_BADVERSION,
  879. * -FDT_ERR_BADSTATE,
  880. * -FDT_ERR_BADSTRUCTURE, standard meanings
  881. */
  882. int fdt_node_depth(const void *fdt, int nodeoffset);
  883. /**
  884. * fdt_parent_offset - find the parent of a given node
  885. * @fdt: pointer to the device tree blob
  886. * @nodeoffset: offset of the node whose parent to find
  887. *
  888. * fdt_parent_offset() locates the parent node of a given node (that
  889. * is, it finds the offset of the node which contains the node at
  890. * nodeoffset as a subnode).
  891. *
  892. * NOTE: This function is expensive, as it must scan the device tree
  893. * structure from the start to nodeoffset, *twice*.
  894. *
  895. * returns:
  896. * structure block offset of the parent of the node at nodeoffset
  897. * (>=0), on success
  898. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  899. * -FDT_ERR_BADMAGIC,
  900. * -FDT_ERR_BADVERSION,
  901. * -FDT_ERR_BADSTATE,
  902. * -FDT_ERR_BADSTRUCTURE, standard meanings
  903. */
  904. int fdt_parent_offset(const void *fdt, int nodeoffset);
  905. /**
  906. * fdt_node_offset_by_prop_value - find nodes with a given property value
  907. * @fdt: pointer to the device tree blob
  908. * @startoffset: only find nodes after this offset
  909. * @propname: property name to check
  910. * @propval: property value to search for
  911. * @proplen: length of the value in propval
  912. *
  913. * fdt_node_offset_by_prop_value() returns the offset of the first
  914. * node after startoffset, which has a property named propname whose
  915. * value is of length proplen and has value equal to propval; or if
  916. * startoffset is -1, the very first such node in the tree.
  917. *
  918. * To iterate through all nodes matching the criterion, the following
  919. * idiom can be used:
  920. * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  921. * propval, proplen);
  922. * while (offset != -FDT_ERR_NOTFOUND) {
  923. * // other code here
  924. * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  925. * propval, proplen);
  926. * }
  927. *
  928. * Note the -1 in the first call to the function, if 0 is used here
  929. * instead, the function will never locate the root node, even if it
  930. * matches the criterion.
  931. *
  932. * returns:
  933. * structure block offset of the located node (>= 0, >startoffset),
  934. * on success
  935. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  936. * tree after startoffset
  937. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  938. * -FDT_ERR_BADMAGIC,
  939. * -FDT_ERR_BADVERSION,
  940. * -FDT_ERR_BADSTATE,
  941. * -FDT_ERR_BADSTRUCTURE, standard meanings
  942. */
  943. int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
  944. const char *propname,
  945. const void *propval, int proplen);
  946. /**
  947. * fdt_node_offset_by_phandle - find the node with a given phandle
  948. * @fdt: pointer to the device tree blob
  949. * @phandle: phandle value
  950. *
  951. * fdt_node_offset_by_phandle() returns the offset of the node
  952. * which has the given phandle value. If there is more than one node
  953. * in the tree with the given phandle (an invalid tree), results are
  954. * undefined.
  955. *
  956. * returns:
  957. * structure block offset of the located node (>= 0), on success
  958. * -FDT_ERR_NOTFOUND, no node with that phandle exists
  959. * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
  960. * -FDT_ERR_BADMAGIC,
  961. * -FDT_ERR_BADVERSION,
  962. * -FDT_ERR_BADSTATE,
  963. * -FDT_ERR_BADSTRUCTURE, standard meanings
  964. */
  965. int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  966. /**
  967. * fdt_node_check_compatible - check a node's compatible property
  968. * @fdt: pointer to the device tree blob
  969. * @nodeoffset: offset of a tree node
  970. * @compatible: string to match against
  971. *
  972. * fdt_node_check_compatible() returns 0 if the given node contains a
  973. * @compatible property with the given string as one of its elements,
  974. * it returns non-zero otherwise, or on error.
  975. *
  976. * returns:
  977. * 0, if the node has a 'compatible' property listing the given string
  978. * 1, if the node has a 'compatible' property, but it does not list
  979. * the given string
  980. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  981. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  982. * -FDT_ERR_BADMAGIC,
  983. * -FDT_ERR_BADVERSION,
  984. * -FDT_ERR_BADSTATE,
  985. * -FDT_ERR_BADSTRUCTURE, standard meanings
  986. */
  987. int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  988. const char *compatible);
  989. /**
  990. * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  991. * @fdt: pointer to the device tree blob
  992. * @startoffset: only find nodes after this offset
  993. * @compatible: 'compatible' string to match against
  994. *
  995. * fdt_node_offset_by_compatible() returns the offset of the first
  996. * node after startoffset, which has a 'compatible' property which
  997. * lists the given compatible string; or if startoffset is -1, the
  998. * very first such node in the tree.
  999. *
  1000. * To iterate through all nodes matching the criterion, the following
  1001. * idiom can be used:
  1002. * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  1003. * while (offset != -FDT_ERR_NOTFOUND) {
  1004. * // other code here
  1005. * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  1006. * }
  1007. *
  1008. * Note the -1 in the first call to the function, if 0 is used here
  1009. * instead, the function will never locate the root node, even if it
  1010. * matches the criterion.
  1011. *
  1012. * returns:
  1013. * structure block offset of the located node (>= 0, >startoffset),
  1014. * on success
  1015. * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
  1016. * tree after startoffset
  1017. * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  1018. * -FDT_ERR_BADMAGIC,
  1019. * -FDT_ERR_BADVERSION,
  1020. * -FDT_ERR_BADSTATE,
  1021. * -FDT_ERR_BADSTRUCTURE, standard meanings
  1022. */
  1023. int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  1024. const char *compatible);
  1025. /**
  1026. * fdt_stringlist_contains - check a string list property for a string
  1027. * @strlist: Property containing a list of strings to check
  1028. * @listlen: Length of property
  1029. * @str: String to search for
  1030. *
  1031. * This is a utility function provided for convenience. The list contains
  1032. * one or more strings, each terminated by \0, as is found in a device tree
  1033. * "compatible" property.
  1034. *
  1035. * Return: 1 if the string is found in the list, 0 not found, or invalid list
  1036. */
  1037. int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
  1038. /**
  1039. * fdt_stringlist_count - count the number of strings in a string list
  1040. * @fdt: pointer to the device tree blob
  1041. * @nodeoffset: offset of a tree node
  1042. * @property: name of the property containing the string list
  1043. *
  1044. * Return:
  1045. * the number of strings in the given property
  1046. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1047. * -FDT_ERR_NOTFOUND if the property does not exist
  1048. */
  1049. int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
  1050. /**
  1051. * fdt_stringlist_search - find a string in a string list and return its index
  1052. * @fdt: pointer to the device tree blob
  1053. * @nodeoffset: offset of a tree node
  1054. * @property: name of the property containing the string list
  1055. * @string: string to look up in the string list
  1056. *
  1057. * Note that it is possible for this function to succeed on property values
  1058. * that are not NUL-terminated. That's because the function will stop after
  1059. * finding the first occurrence of @string. This can for example happen with
  1060. * small-valued cell properties, such as #address-cells, when searching for
  1061. * the empty string.
  1062. *
  1063. * return:
  1064. * the index of the string in the list of strings
  1065. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1066. * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
  1067. * the given string
  1068. */
  1069. int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
  1070. const char *string);
  1071. /**
  1072. * fdt_stringlist_get() - obtain the string at a given index in a string list
  1073. * @fdt: pointer to the device tree blob
  1074. * @nodeoffset: offset of a tree node
  1075. * @property: name of the property containing the string list
  1076. * @index: index of the string to return
  1077. * @lenp: return location for the string length or an error code on failure
  1078. *
  1079. * Note that this will successfully extract strings from properties with
  1080. * non-NUL-terminated values. For example on small-valued cell properties
  1081. * this function will return the empty string.
  1082. *
  1083. * If non-NULL, the length of the string (on success) or a negative error-code
  1084. * (on failure) will be stored in the integer pointer to by lenp.
  1085. *
  1086. * Return:
  1087. * A pointer to the string at the given index in the string list or NULL on
  1088. * failure. On success the length of the string will be stored in the memory
  1089. * location pointed to by the lenp parameter, if non-NULL. On failure one of
  1090. * the following negative error codes will be returned in the lenp parameter
  1091. * (if non-NULL):
  1092. * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
  1093. * -FDT_ERR_NOTFOUND if the property does not exist
  1094. */
  1095. const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
  1096. const char *property, int index,
  1097. int *lenp);
  1098. /**********************************************************************/
  1099. /* Read-only functions (addressing related) */
  1100. /**********************************************************************/
  1101. /**
  1102. * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
  1103. *
  1104. * This is the maximum value for #address-cells, #size-cells and
  1105. * similar properties that will be processed by libfdt. IEE1275
  1106. * requires that OF implementations handle values up to 4.
  1107. * Implementations may support larger values, but in practice higher
  1108. * values aren't used.
  1109. */
  1110. #define FDT_MAX_NCELLS 4
  1111. /**
  1112. * fdt_address_cells - retrieve address size for a bus represented in the tree
  1113. * @fdt: pointer to the device tree blob
  1114. * @nodeoffset: offset of the node to find the address size for
  1115. *
  1116. * When the node has a valid #address-cells property, returns its value.
  1117. *
  1118. * returns:
  1119. * 0 <= n < FDT_MAX_NCELLS, on success
  1120. * 2, if the node has no #address-cells property
  1121. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1122. * #address-cells property
  1123. * -FDT_ERR_BADMAGIC,
  1124. * -FDT_ERR_BADVERSION,
  1125. * -FDT_ERR_BADSTATE,
  1126. * -FDT_ERR_BADSTRUCTURE,
  1127. * -FDT_ERR_TRUNCATED, standard meanings
  1128. */
  1129. int fdt_address_cells(const void *fdt, int nodeoffset);
  1130. /**
  1131. * fdt_size_cells - retrieve address range size for a bus represented in the
  1132. * tree
  1133. * @fdt: pointer to the device tree blob
  1134. * @nodeoffset: offset of the node to find the address range size for
  1135. *
  1136. * When the node has a valid #size-cells property, returns its value.
  1137. *
  1138. * returns:
  1139. * 0 <= n < FDT_MAX_NCELLS, on success
  1140. * 1, if the node has no #size-cells property
  1141. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1142. * #size-cells property
  1143. * -FDT_ERR_BADMAGIC,
  1144. * -FDT_ERR_BADVERSION,
  1145. * -FDT_ERR_BADSTATE,
  1146. * -FDT_ERR_BADSTRUCTURE,
  1147. * -FDT_ERR_TRUNCATED, standard meanings
  1148. */
  1149. int fdt_size_cells(const void *fdt, int nodeoffset);
  1150. /**********************************************************************/
  1151. /* Write-in-place functions */
  1152. /**********************************************************************/
  1153. /**
  1154. * fdt_setprop_inplace_namelen_partial - change a property's value,
  1155. * but not its size
  1156. * @fdt: pointer to the device tree blob
  1157. * @nodeoffset: offset of the node whose property to change
  1158. * @name: name of the property to change
  1159. * @namelen: number of characters of name to consider
  1160. * @idx: index of the property to change in the array
  1161. * @val: pointer to data to replace the property value with
  1162. * @len: length of the property value
  1163. *
  1164. * Identical to fdt_setprop_inplace(), but modifies the given property
  1165. * starting from the given index, and using only the first characters
  1166. * of the name. It is useful when you want to manipulate only one value of
  1167. * an array and you have a string that doesn't end with \0.
  1168. *
  1169. * Return: 0 on success, negative libfdt error value otherwise
  1170. */
  1171. #ifndef SWIG /* Not available in Python */
  1172. int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
  1173. const char *name, int namelen,
  1174. uint32_t idx, const void *val,
  1175. int len);
  1176. #endif
  1177. /**
  1178. * fdt_setprop_inplace - change a property's value, but not its size
  1179. * @fdt: pointer to the device tree blob
  1180. * @nodeoffset: offset of the node whose property to change
  1181. * @name: name of the property to change
  1182. * @val: pointer to data to replace the property value with
  1183. * @len: length of the property value
  1184. *
  1185. * fdt_setprop_inplace() replaces the value of a given property with
  1186. * the data in val, of length len. This function cannot change the
  1187. * size of a property, and so will only work if len is equal to the
  1188. * current length of the property.
  1189. *
  1190. * This function will alter only the bytes in the blob which contain
  1191. * the given property value, and will not alter or move any other part
  1192. * of the tree.
  1193. *
  1194. * returns:
  1195. * 0, on success
  1196. * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
  1197. * -FDT_ERR_NOTFOUND, node does not have the named property
  1198. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1199. * -FDT_ERR_BADMAGIC,
  1200. * -FDT_ERR_BADVERSION,
  1201. * -FDT_ERR_BADSTATE,
  1202. * -FDT_ERR_BADSTRUCTURE,
  1203. * -FDT_ERR_TRUNCATED, standard meanings
  1204. */
  1205. #ifndef SWIG /* Not available in Python */
  1206. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  1207. const void *val, int len);
  1208. #endif
  1209. /**
  1210. * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
  1211. * @fdt: pointer to the device tree blob
  1212. * @nodeoffset: offset of the node whose property to change
  1213. * @name: name of the property to change
  1214. * @val: 32-bit integer value to replace the property with
  1215. *
  1216. * fdt_setprop_inplace_u32() replaces the value of a given property
  1217. * with the 32-bit integer value in val, converting val to big-endian
  1218. * if necessary. This function cannot change the size of a property,
  1219. * and so will only work if the property already exists and has length
  1220. * 4.
  1221. *
  1222. * This function will alter only the bytes in the blob which contain
  1223. * the given property value, and will not alter or move any other part
  1224. * of the tree.
  1225. *
  1226. * returns:
  1227. * 0, on success
  1228. * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
  1229. * -FDT_ERR_NOTFOUND, node does not have the named property
  1230. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1231. * -FDT_ERR_BADMAGIC,
  1232. * -FDT_ERR_BADVERSION,
  1233. * -FDT_ERR_BADSTATE,
  1234. * -FDT_ERR_BADSTRUCTURE,
  1235. * -FDT_ERR_TRUNCATED, standard meanings
  1236. */
  1237. static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
  1238. const char *name, uint32_t val)
  1239. {
  1240. fdt32_t tmp = cpu_to_fdt32(val);
  1241. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1242. }
  1243. /**
  1244. * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
  1245. * @fdt: pointer to the device tree blob
  1246. * @nodeoffset: offset of the node whose property to change
  1247. * @name: name of the property to change
  1248. * @val: 64-bit integer value to replace the property with
  1249. *
  1250. * fdt_setprop_inplace_u64() replaces the value of a given property
  1251. * with the 64-bit integer value in val, converting val to big-endian
  1252. * if necessary. This function cannot change the size of a property,
  1253. * and so will only work if the property already exists and has length
  1254. * 8.
  1255. *
  1256. * This function will alter only the bytes in the blob which contain
  1257. * the given property value, and will not alter or move any other part
  1258. * of the tree.
  1259. *
  1260. * returns:
  1261. * 0, on success
  1262. * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
  1263. * -FDT_ERR_NOTFOUND, node does not have the named property
  1264. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1265. * -FDT_ERR_BADMAGIC,
  1266. * -FDT_ERR_BADVERSION,
  1267. * -FDT_ERR_BADSTATE,
  1268. * -FDT_ERR_BADSTRUCTURE,
  1269. * -FDT_ERR_TRUNCATED, standard meanings
  1270. */
  1271. static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
  1272. const char *name, uint64_t val)
  1273. {
  1274. fdt64_t tmp = cpu_to_fdt64(val);
  1275. return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1276. }
  1277. /**
  1278. * fdt_setprop_inplace_cell - change the value of a single-cell property
  1279. * @fdt: pointer to the device tree blob
  1280. * @nodeoffset: offset of the node containing the property
  1281. * @name: name of the property to change the value of
  1282. * @val: new value of the 32-bit cell
  1283. *
  1284. * This is an alternative name for fdt_setprop_inplace_u32()
  1285. * Return: 0 on success, negative libfdt error number otherwise.
  1286. */
  1287. static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
  1288. const char *name, uint32_t val)
  1289. {
  1290. return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
  1291. }
  1292. /**
  1293. * fdt_nop_property - replace a property with nop tags
  1294. * @fdt: pointer to the device tree blob
  1295. * @nodeoffset: offset of the node whose property to nop
  1296. * @name: name of the property to nop
  1297. *
  1298. * fdt_nop_property() will replace a given property's representation
  1299. * in the blob with FDT_NOP tags, effectively removing it from the
  1300. * tree.
  1301. *
  1302. * This function will alter only the bytes in the blob which contain
  1303. * the property, and will not alter or move any other part of the
  1304. * tree.
  1305. *
  1306. * returns:
  1307. * 0, on success
  1308. * -FDT_ERR_NOTFOUND, node does not have the named property
  1309. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1310. * -FDT_ERR_BADMAGIC,
  1311. * -FDT_ERR_BADVERSION,
  1312. * -FDT_ERR_BADSTATE,
  1313. * -FDT_ERR_BADSTRUCTURE,
  1314. * -FDT_ERR_TRUNCATED, standard meanings
  1315. */
  1316. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  1317. /**
  1318. * fdt_nop_node - replace a node (subtree) with nop tags
  1319. * @fdt: pointer to the device tree blob
  1320. * @nodeoffset: offset of the node to nop
  1321. *
  1322. * fdt_nop_node() will replace a given node's representation in the
  1323. * blob, including all its subnodes, if any, with FDT_NOP tags,
  1324. * effectively removing it from the tree.
  1325. *
  1326. * This function will alter only the bytes in the blob which contain
  1327. * the node and its properties and subnodes, and will not alter or
  1328. * move any other part of the tree.
  1329. *
  1330. * returns:
  1331. * 0, on success
  1332. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1333. * -FDT_ERR_BADMAGIC,
  1334. * -FDT_ERR_BADVERSION,
  1335. * -FDT_ERR_BADSTATE,
  1336. * -FDT_ERR_BADSTRUCTURE,
  1337. * -FDT_ERR_TRUNCATED, standard meanings
  1338. */
  1339. int fdt_nop_node(void *fdt, int nodeoffset);
  1340. /**********************************************************************/
  1341. /* Sequential write functions */
  1342. /**********************************************************************/
  1343. /* fdt_create_with_flags flags */
  1344. #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
  1345. /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
  1346. * names in the fdt. This can result in faster creation times, but
  1347. * a larger fdt. */
  1348. #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
  1349. /**
  1350. * fdt_create_with_flags - begin creation of a new fdt
  1351. * @buf: pointer to memory allocated where fdt will be created
  1352. * @bufsize: size of the memory space at fdt
  1353. * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
  1354. *
  1355. * fdt_create_with_flags() begins the process of creating a new fdt with
  1356. * the sequential write interface.
  1357. *
  1358. * fdt creation process must end with fdt_finished() to produce a valid fdt.
  1359. *
  1360. * returns:
  1361. * 0, on success
  1362. * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
  1363. * -FDT_ERR_BADFLAGS, flags is not valid
  1364. */
  1365. int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
  1366. /**
  1367. * fdt_create - begin creation of a new fdt
  1368. * @buf: pointer to memory allocated where fdt will be created
  1369. * @bufsize: size of the memory space at fdt
  1370. *
  1371. * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
  1372. *
  1373. * returns:
  1374. * 0, on success
  1375. * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
  1376. */
  1377. int fdt_create(void *buf, int bufsize);
  1378. int fdt_resize(void *fdt, void *buf, int bufsize);
  1379. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  1380. int fdt_finish_reservemap(void *fdt);
  1381. int fdt_begin_node(void *fdt, const char *name);
  1382. int fdt_property(void *fdt, const char *name, const void *val, int len);
  1383. static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
  1384. {
  1385. fdt32_t tmp = cpu_to_fdt32(val);
  1386. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1387. }
  1388. static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
  1389. {
  1390. fdt64_t tmp = cpu_to_fdt64(val);
  1391. return fdt_property(fdt, name, &tmp, sizeof(tmp));
  1392. }
  1393. #ifndef SWIG /* Not available in Python */
  1394. static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
  1395. {
  1396. return fdt_property_u32(fdt, name, val);
  1397. }
  1398. #endif
  1399. /**
  1400. * fdt_property_placeholder - add a new property and return a ptr to its value
  1401. *
  1402. * @fdt: pointer to the device tree blob
  1403. * @name: name of property to add
  1404. * @len: length of property value in bytes
  1405. * @valp: returns a pointer to where where the value should be placed
  1406. *
  1407. * returns:
  1408. * 0, on success
  1409. * -FDT_ERR_BADMAGIC,
  1410. * -FDT_ERR_NOSPACE, standard meanings
  1411. */
  1412. int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
  1413. #define fdt_property_string(fdt, name, str) \
  1414. fdt_property(fdt, name, str, strlen(str)+1)
  1415. int fdt_end_node(void *fdt);
  1416. int fdt_finish(void *fdt);
  1417. /**********************************************************************/
  1418. /* Read-write functions */
  1419. /**********************************************************************/
  1420. int fdt_create_empty_tree(void *buf, int bufsize);
  1421. int fdt_open_into(const void *fdt, void *buf, int bufsize);
  1422. int fdt_pack(void *fdt);
  1423. /**
  1424. * fdt_add_mem_rsv - add one memory reserve map entry
  1425. * @fdt: pointer to the device tree blob
  1426. * @address: 64-bit start address of the reserve map entry
  1427. * @size: 64-bit size of the reserved region
  1428. *
  1429. * Adds a reserve map entry to the given blob reserving a region at
  1430. * address address of length size.
  1431. *
  1432. * This function will insert data into the reserve map and will
  1433. * therefore change the indexes of some entries in the table.
  1434. *
  1435. * returns:
  1436. * 0, on success
  1437. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1438. * contain the new reservation entry
  1439. * -FDT_ERR_BADMAGIC,
  1440. * -FDT_ERR_BADVERSION,
  1441. * -FDT_ERR_BADSTATE,
  1442. * -FDT_ERR_BADSTRUCTURE,
  1443. * -FDT_ERR_BADLAYOUT,
  1444. * -FDT_ERR_TRUNCATED, standard meanings
  1445. */
  1446. int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
  1447. /**
  1448. * fdt_del_mem_rsv - remove a memory reserve map entry
  1449. * @fdt: pointer to the device tree blob
  1450. * @n: entry to remove
  1451. *
  1452. * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
  1453. * the blob.
  1454. *
  1455. * This function will delete data from the reservation table and will
  1456. * therefore change the indexes of some entries in the table.
  1457. *
  1458. * returns:
  1459. * 0, on success
  1460. * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
  1461. * are less than n+1 reserve map entries)
  1462. * -FDT_ERR_BADMAGIC,
  1463. * -FDT_ERR_BADVERSION,
  1464. * -FDT_ERR_BADSTATE,
  1465. * -FDT_ERR_BADSTRUCTURE,
  1466. * -FDT_ERR_BADLAYOUT,
  1467. * -FDT_ERR_TRUNCATED, standard meanings
  1468. */
  1469. int fdt_del_mem_rsv(void *fdt, int n);
  1470. /**
  1471. * fdt_set_name - change the name of a given node
  1472. * @fdt: pointer to the device tree blob
  1473. * @nodeoffset: structure block offset of a node
  1474. * @name: name to give the node
  1475. *
  1476. * fdt_set_name() replaces the name (including unit address, if any)
  1477. * of the given node with the given string. NOTE: this function can't
  1478. * efficiently check if the new name is unique amongst the given
  1479. * node's siblings; results are undefined if this function is invoked
  1480. * with a name equal to one of the given node's siblings.
  1481. *
  1482. * This function may insert or delete data from the blob, and will
  1483. * therefore change the offsets of some existing nodes.
  1484. *
  1485. * returns:
  1486. * 0, on success
  1487. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
  1488. * to contain the new name
  1489. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1490. * -FDT_ERR_BADMAGIC,
  1491. * -FDT_ERR_BADVERSION,
  1492. * -FDT_ERR_BADSTATE, standard meanings
  1493. */
  1494. int fdt_set_name(void *fdt, int nodeoffset, const char *name);
  1495. /**
  1496. * fdt_setprop - create or change a property
  1497. * @fdt: pointer to the device tree blob
  1498. * @nodeoffset: offset of the node whose property to change
  1499. * @name: name of the property to change
  1500. * @val: pointer to data to set the property value to
  1501. * @len: length of the property value
  1502. *
  1503. * fdt_setprop() sets the value of the named property in the given
  1504. * node to the given value and length, creating the property if it
  1505. * does not already exist.
  1506. *
  1507. * This function may insert or delete data from the blob, and will
  1508. * therefore change the offsets of some existing nodes.
  1509. *
  1510. * returns:
  1511. * 0, on success
  1512. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1513. * contain the new property value
  1514. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1515. * -FDT_ERR_BADLAYOUT,
  1516. * -FDT_ERR_BADMAGIC,
  1517. * -FDT_ERR_BADVERSION,
  1518. * -FDT_ERR_BADSTATE,
  1519. * -FDT_ERR_BADSTRUCTURE,
  1520. * -FDT_ERR_BADLAYOUT,
  1521. * -FDT_ERR_TRUNCATED, standard meanings
  1522. */
  1523. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  1524. const void *val, int len);
  1525. /**
  1526. * fdt_setprop_placeholder - allocate space for a property
  1527. * @fdt: pointer to the device tree blob
  1528. * @nodeoffset: offset of the node whose property to change
  1529. * @name: name of the property to change
  1530. * @len: length of the property value
  1531. * @prop_data: return pointer to property data
  1532. *
  1533. * fdt_setprop_placeholer() allocates the named property in the given node.
  1534. * If the property exists it is resized. In either case a pointer to the
  1535. * property data is returned.
  1536. *
  1537. * This function may insert or delete data from the blob, and will
  1538. * therefore change the offsets of some existing nodes.
  1539. *
  1540. * returns:
  1541. * 0, on success
  1542. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1543. * contain the new property value
  1544. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1545. * -FDT_ERR_BADLAYOUT,
  1546. * -FDT_ERR_BADMAGIC,
  1547. * -FDT_ERR_BADVERSION,
  1548. * -FDT_ERR_BADSTATE,
  1549. * -FDT_ERR_BADSTRUCTURE,
  1550. * -FDT_ERR_BADLAYOUT,
  1551. * -FDT_ERR_TRUNCATED, standard meanings
  1552. */
  1553. int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
  1554. int len, void **prop_data);
  1555. /**
  1556. * fdt_setprop_u32 - set a property to a 32-bit integer
  1557. * @fdt: pointer to the device tree blob
  1558. * @nodeoffset: offset of the node whose property to change
  1559. * @name: name of the property to change
  1560. * @val: 32-bit integer value for the property (native endian)
  1561. *
  1562. * fdt_setprop_u32() sets the value of the named property in the given
  1563. * node to the given 32-bit integer value (converting to big-endian if
  1564. * necessary), or creates a new property with that value if it does
  1565. * not already exist.
  1566. *
  1567. * This function may insert or delete data from the blob, and will
  1568. * therefore change the offsets of some existing nodes.
  1569. *
  1570. * returns:
  1571. * 0, on success
  1572. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1573. * contain the new property value
  1574. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1575. * -FDT_ERR_BADLAYOUT,
  1576. * -FDT_ERR_BADMAGIC,
  1577. * -FDT_ERR_BADVERSION,
  1578. * -FDT_ERR_BADSTATE,
  1579. * -FDT_ERR_BADSTRUCTURE,
  1580. * -FDT_ERR_BADLAYOUT,
  1581. * -FDT_ERR_TRUNCATED, standard meanings
  1582. */
  1583. static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
  1584. uint32_t val)
  1585. {
  1586. fdt32_t tmp = cpu_to_fdt32(val);
  1587. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1588. }
  1589. /**
  1590. * fdt_setprop_u64 - set a property to a 64-bit integer
  1591. * @fdt: pointer to the device tree blob
  1592. * @nodeoffset: offset of the node whose property to change
  1593. * @name: name of the property to change
  1594. * @val: 64-bit integer value for the property (native endian)
  1595. *
  1596. * fdt_setprop_u64() sets the value of the named property in the given
  1597. * node to the given 64-bit integer value (converting to big-endian if
  1598. * necessary), or creates a new property with that value if it does
  1599. * not already exist.
  1600. *
  1601. * This function may insert or delete data from the blob, and will
  1602. * therefore change the offsets of some existing nodes.
  1603. *
  1604. * returns:
  1605. * 0, on success
  1606. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1607. * contain the new property value
  1608. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1609. * -FDT_ERR_BADLAYOUT,
  1610. * -FDT_ERR_BADMAGIC,
  1611. * -FDT_ERR_BADVERSION,
  1612. * -FDT_ERR_BADSTATE,
  1613. * -FDT_ERR_BADSTRUCTURE,
  1614. * -FDT_ERR_BADLAYOUT,
  1615. * -FDT_ERR_TRUNCATED, standard meanings
  1616. */
  1617. static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
  1618. uint64_t val)
  1619. {
  1620. fdt64_t tmp = cpu_to_fdt64(val);
  1621. return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1622. }
  1623. /**
  1624. * fdt_setprop_cell - set a property to a single cell value
  1625. * @fdt: pointer to the device tree blob
  1626. * @nodeoffset: offset of the node whose property to change
  1627. * @name: name of the property to change
  1628. * @val: 32-bit integer value for the property (native endian)
  1629. *
  1630. * This is an alternative name for fdt_setprop_u32()
  1631. *
  1632. * Return: 0 on success, negative libfdt error value otherwise.
  1633. */
  1634. static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
  1635. uint32_t val)
  1636. {
  1637. return fdt_setprop_u32(fdt, nodeoffset, name, val);
  1638. }
  1639. /**
  1640. * fdt_setprop_string - set a property to a string value
  1641. * @fdt: pointer to the device tree blob
  1642. * @nodeoffset: offset of the node whose property to change
  1643. * @name: name of the property to change
  1644. * @str: string value for the property
  1645. *
  1646. * fdt_setprop_string() sets the value of the named property in the
  1647. * given node to the given string value (using the length of the
  1648. * string to determine the new length of the property), or creates a
  1649. * new property with that value if it does not already exist.
  1650. *
  1651. * This function may insert or delete data from the blob, and will
  1652. * therefore change the offsets of some existing nodes.
  1653. *
  1654. * returns:
  1655. * 0, on success
  1656. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1657. * contain the new property value
  1658. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1659. * -FDT_ERR_BADLAYOUT,
  1660. * -FDT_ERR_BADMAGIC,
  1661. * -FDT_ERR_BADVERSION,
  1662. * -FDT_ERR_BADSTATE,
  1663. * -FDT_ERR_BADSTRUCTURE,
  1664. * -FDT_ERR_BADLAYOUT,
  1665. * -FDT_ERR_TRUNCATED, standard meanings
  1666. */
  1667. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  1668. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1669. /**
  1670. * fdt_setprop_empty - set a property to an empty value
  1671. * @fdt: pointer to the device tree blob
  1672. * @nodeoffset: offset of the node whose property to change
  1673. * @name: name of the property to change
  1674. *
  1675. * fdt_setprop_empty() sets the value of the named property in the
  1676. * given node to an empty (zero length) value, or creates a new empty
  1677. * property if it does not already exist.
  1678. *
  1679. * This function may insert or delete data from the blob, and will
  1680. * therefore change the offsets of some existing nodes.
  1681. *
  1682. * returns:
  1683. * 0, on success
  1684. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1685. * contain the new property value
  1686. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1687. * -FDT_ERR_BADLAYOUT,
  1688. * -FDT_ERR_BADMAGIC,
  1689. * -FDT_ERR_BADVERSION,
  1690. * -FDT_ERR_BADSTATE,
  1691. * -FDT_ERR_BADSTRUCTURE,
  1692. * -FDT_ERR_BADLAYOUT,
  1693. * -FDT_ERR_TRUNCATED, standard meanings
  1694. */
  1695. #define fdt_setprop_empty(fdt, nodeoffset, name) \
  1696. fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
  1697. /**
  1698. * fdt_appendprop - append to or create a property
  1699. * @fdt: pointer to the device tree blob
  1700. * @nodeoffset: offset of the node whose property to change
  1701. * @name: name of the property to append to
  1702. * @val: pointer to data to append to the property value
  1703. * @len: length of the data to append to the property value
  1704. *
  1705. * fdt_appendprop() appends the value to the named property in the
  1706. * given node, creating the property if it does not already exist.
  1707. *
  1708. * This function may insert data into the blob, and will therefore
  1709. * change the offsets of some existing nodes.
  1710. *
  1711. * returns:
  1712. * 0, on success
  1713. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1714. * contain the new property value
  1715. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1716. * -FDT_ERR_BADLAYOUT,
  1717. * -FDT_ERR_BADMAGIC,
  1718. * -FDT_ERR_BADVERSION,
  1719. * -FDT_ERR_BADSTATE,
  1720. * -FDT_ERR_BADSTRUCTURE,
  1721. * -FDT_ERR_BADLAYOUT,
  1722. * -FDT_ERR_TRUNCATED, standard meanings
  1723. */
  1724. int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
  1725. const void *val, int len);
  1726. /**
  1727. * fdt_appendprop_u32 - append a 32-bit integer value to a property
  1728. * @fdt: pointer to the device tree blob
  1729. * @nodeoffset: offset of the node whose property to change
  1730. * @name: name of the property to change
  1731. * @val: 32-bit integer value to append to the property (native endian)
  1732. *
  1733. * fdt_appendprop_u32() appends the given 32-bit integer value
  1734. * (converting to big-endian if necessary) to the value of the named
  1735. * property in the given node, or creates a new property with that
  1736. * value if it does not already exist.
  1737. *
  1738. * This function may insert data into the blob, and will therefore
  1739. * change the offsets of some existing nodes.
  1740. *
  1741. * returns:
  1742. * 0, on success
  1743. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1744. * contain the new property value
  1745. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1746. * -FDT_ERR_BADLAYOUT,
  1747. * -FDT_ERR_BADMAGIC,
  1748. * -FDT_ERR_BADVERSION,
  1749. * -FDT_ERR_BADSTATE,
  1750. * -FDT_ERR_BADSTRUCTURE,
  1751. * -FDT_ERR_BADLAYOUT,
  1752. * -FDT_ERR_TRUNCATED, standard meanings
  1753. */
  1754. static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
  1755. const char *name, uint32_t val)
  1756. {
  1757. fdt32_t tmp = cpu_to_fdt32(val);
  1758. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1759. }
  1760. /**
  1761. * fdt_appendprop_u64 - append a 64-bit integer value to a property
  1762. * @fdt: pointer to the device tree blob
  1763. * @nodeoffset: offset of the node whose property to change
  1764. * @name: name of the property to change
  1765. * @val: 64-bit integer value to append to the property (native endian)
  1766. *
  1767. * fdt_appendprop_u64() appends the given 64-bit integer value
  1768. * (converting to big-endian if necessary) to the value of the named
  1769. * property in the given node, or creates a new property with that
  1770. * value if it does not already exist.
  1771. *
  1772. * This function may insert data into the blob, and will therefore
  1773. * change the offsets of some existing nodes.
  1774. *
  1775. * returns:
  1776. * 0, on success
  1777. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1778. * contain the new property value
  1779. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1780. * -FDT_ERR_BADLAYOUT,
  1781. * -FDT_ERR_BADMAGIC,
  1782. * -FDT_ERR_BADVERSION,
  1783. * -FDT_ERR_BADSTATE,
  1784. * -FDT_ERR_BADSTRUCTURE,
  1785. * -FDT_ERR_BADLAYOUT,
  1786. * -FDT_ERR_TRUNCATED, standard meanings
  1787. */
  1788. static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
  1789. const char *name, uint64_t val)
  1790. {
  1791. fdt64_t tmp = cpu_to_fdt64(val);
  1792. return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
  1793. }
  1794. /**
  1795. * fdt_appendprop_cell - append a single cell value to a property
  1796. * @fdt: pointer to the device tree blob
  1797. * @nodeoffset: offset of the node whose property to change
  1798. * @name: name of the property to change
  1799. * @val: 32-bit integer value to append to the property (native endian)
  1800. *
  1801. * This is an alternative name for fdt_appendprop_u32()
  1802. *
  1803. * Return: 0 on success, negative libfdt error value otherwise.
  1804. */
  1805. static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
  1806. const char *name, uint32_t val)
  1807. {
  1808. return fdt_appendprop_u32(fdt, nodeoffset, name, val);
  1809. }
  1810. /**
  1811. * fdt_appendprop_string - append a string to a property
  1812. * @fdt: pointer to the device tree blob
  1813. * @nodeoffset: offset of the node whose property to change
  1814. * @name: name of the property to change
  1815. * @str: string value to append to the property
  1816. *
  1817. * fdt_appendprop_string() appends the given string to the value of
  1818. * the named property in the given node, or creates a new property
  1819. * with that value if it does not already exist.
  1820. *
  1821. * This function may insert data into the blob, and will therefore
  1822. * change the offsets of some existing nodes.
  1823. *
  1824. * returns:
  1825. * 0, on success
  1826. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1827. * contain the new property value
  1828. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1829. * -FDT_ERR_BADLAYOUT,
  1830. * -FDT_ERR_BADMAGIC,
  1831. * -FDT_ERR_BADVERSION,
  1832. * -FDT_ERR_BADSTATE,
  1833. * -FDT_ERR_BADSTRUCTURE,
  1834. * -FDT_ERR_BADLAYOUT,
  1835. * -FDT_ERR_TRUNCATED, standard meanings
  1836. */
  1837. #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
  1838. fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  1839. /**
  1840. * fdt_appendprop_addrrange - append a address range property
  1841. * @fdt: pointer to the device tree blob
  1842. * @parent: offset of the parent node
  1843. * @nodeoffset: offset of the node to add a property at
  1844. * @name: name of property
  1845. * @addr: start address of a given range
  1846. * @size: size of a given range
  1847. *
  1848. * fdt_appendprop_addrrange() appends an address range value (start
  1849. * address and size) to the value of the named property in the given
  1850. * node, or creates a new property with that value if it does not
  1851. * already exist.
  1852. * If "name" is not specified, a default "reg" is used.
  1853. * Cell sizes are determined by parent's #address-cells and #size-cells.
  1854. *
  1855. * This function may insert data into the blob, and will therefore
  1856. * change the offsets of some existing nodes.
  1857. *
  1858. * returns:
  1859. * 0, on success
  1860. * -FDT_ERR_BADLAYOUT,
  1861. * -FDT_ERR_BADMAGIC,
  1862. * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  1863. * #address-cells property
  1864. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1865. * -FDT_ERR_BADSTATE,
  1866. * -FDT_ERR_BADSTRUCTURE,
  1867. * -FDT_ERR_BADVERSION,
  1868. * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
  1869. * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
  1870. * contain a new property
  1871. * -FDT_ERR_TRUNCATED, standard meanings
  1872. */
  1873. int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
  1874. const char *name, uint64_t addr, uint64_t size);
  1875. /**
  1876. * fdt_delprop - delete a property
  1877. * @fdt: pointer to the device tree blob
  1878. * @nodeoffset: offset of the node whose property to nop
  1879. * @name: name of the property to nop
  1880. *
  1881. * fdt_del_property() will delete the given property.
  1882. *
  1883. * This function will delete data from the blob, and will therefore
  1884. * change the offsets of some existing nodes.
  1885. *
  1886. * returns:
  1887. * 0, on success
  1888. * -FDT_ERR_NOTFOUND, node does not have the named property
  1889. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1890. * -FDT_ERR_BADLAYOUT,
  1891. * -FDT_ERR_BADMAGIC,
  1892. * -FDT_ERR_BADVERSION,
  1893. * -FDT_ERR_BADSTATE,
  1894. * -FDT_ERR_BADSTRUCTURE,
  1895. * -FDT_ERR_TRUNCATED, standard meanings
  1896. */
  1897. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  1898. /**
  1899. * fdt_add_subnode_namelen - creates a new node based on substring
  1900. * @fdt: pointer to the device tree blob
  1901. * @parentoffset: structure block offset of a node
  1902. * @name: name of the subnode to create
  1903. * @namelen: number of characters of name to consider
  1904. *
  1905. * Identical to fdt_add_subnode(), but use only the first @namelen
  1906. * characters of @name as the name of the new node. This is useful for
  1907. * creating subnodes based on a portion of a larger string, such as a
  1908. * full path.
  1909. *
  1910. * Return: structure block offset of the created subnode (>=0),
  1911. * negative libfdt error value otherwise
  1912. */
  1913. #ifndef SWIG /* Not available in Python */
  1914. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  1915. const char *name, int namelen);
  1916. #endif
  1917. /**
  1918. * fdt_add_subnode - creates a new node
  1919. * @fdt: pointer to the device tree blob
  1920. * @parentoffset: structure block offset of a node
  1921. * @name: name of the subnode to locate
  1922. *
  1923. * fdt_add_subnode() creates a new node as a subnode of the node at
  1924. * structure block offset parentoffset, with the given name (which
  1925. * should include the unit address, if any).
  1926. *
  1927. * This function will insert data into the blob, and will therefore
  1928. * change the offsets of some existing nodes.
  1929. *
  1930. * returns:
  1931. * structure block offset of the created nodeequested subnode (>=0), on
  1932. * success
  1933. * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
  1934. * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
  1935. * tag
  1936. * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
  1937. * the given name
  1938. * -FDT_ERR_NOSPACE, if there is insufficient free space in the
  1939. * blob to contain the new node
  1940. * -FDT_ERR_NOSPACE
  1941. * -FDT_ERR_BADLAYOUT
  1942. * -FDT_ERR_BADMAGIC,
  1943. * -FDT_ERR_BADVERSION,
  1944. * -FDT_ERR_BADSTATE,
  1945. * -FDT_ERR_BADSTRUCTURE,
  1946. * -FDT_ERR_TRUNCATED, standard meanings.
  1947. */
  1948. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  1949. /**
  1950. * fdt_del_node - delete a node (subtree)
  1951. * @fdt: pointer to the device tree blob
  1952. * @nodeoffset: offset of the node to nop
  1953. *
  1954. * fdt_del_node() will remove the given node, including all its
  1955. * subnodes if any, from the blob.
  1956. *
  1957. * This function will delete data from the blob, and will therefore
  1958. * change the offsets of some existing nodes.
  1959. *
  1960. * returns:
  1961. * 0, on success
  1962. * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
  1963. * -FDT_ERR_BADLAYOUT,
  1964. * -FDT_ERR_BADMAGIC,
  1965. * -FDT_ERR_BADVERSION,
  1966. * -FDT_ERR_BADSTATE,
  1967. * -FDT_ERR_BADSTRUCTURE,
  1968. * -FDT_ERR_TRUNCATED, standard meanings
  1969. */
  1970. int fdt_del_node(void *fdt, int nodeoffset);
  1971. /**
  1972. * fdt_overlay_apply - Applies a DT overlay on a base DT
  1973. * @fdt: pointer to the base device tree blob
  1974. * @fdto: pointer to the device tree overlay blob
  1975. *
  1976. * fdt_overlay_apply() will apply the given device tree overlay on the
  1977. * given base device tree.
  1978. *
  1979. * Expect the base device tree to be modified, even if the function
  1980. * returns an error.
  1981. *
  1982. * returns:
  1983. * 0, on success
  1984. * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
  1985. * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
  1986. * properties in the base DT
  1987. * -FDT_ERR_BADPHANDLE,
  1988. * -FDT_ERR_BADOVERLAY,
  1989. * -FDT_ERR_NOPHANDLES,
  1990. * -FDT_ERR_INTERNAL,
  1991. * -FDT_ERR_BADLAYOUT,
  1992. * -FDT_ERR_BADMAGIC,
  1993. * -FDT_ERR_BADOFFSET,
  1994. * -FDT_ERR_BADPATH,
  1995. * -FDT_ERR_BADVERSION,
  1996. * -FDT_ERR_BADSTRUCTURE,
  1997. * -FDT_ERR_BADSTATE,
  1998. * -FDT_ERR_TRUNCATED, standard meanings
  1999. */
  2000. int fdt_overlay_apply(void *fdt, void *fdto);
  2001. /**
  2002. * fdt_overlay_target_offset - retrieves the offset of a fragment's target
  2003. * @fdt: Base device tree blob
  2004. * @fdto: Device tree overlay blob
  2005. * @fragment_offset: node offset of the fragment in the overlay
  2006. * @pathp: pointer which receives the path of the target (or NULL)
  2007. *
  2008. * fdt_overlay_target_offset() retrieves the target offset in the base
  2009. * device tree of a fragment, no matter how the actual targeting is
  2010. * done (through a phandle or a path)
  2011. *
  2012. * returns:
  2013. * the targeted node offset in the base device tree
  2014. * Negative error code on error
  2015. */
  2016. int fdt_overlay_target_offset(const void *fdt, const void *fdto,
  2017. int fragment_offset, char const **pathp);
  2018. /**********************************************************************/
  2019. /* Debugging / informational functions */
  2020. /**********************************************************************/
  2021. const char *fdt_strerror(int errval);
  2022. #ifdef __cplusplus
  2023. }
  2024. #endif
  2025. #endif /* LIBFDT_H */