image.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076
  1. /*
  2. * (C) Copyright 2008 Semihalf
  3. *
  4. * (C) Copyright 2000-2006
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #ifndef USE_HOSTCC
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  29. #include <status_led.h>
  30. #endif
  31. #ifdef CONFIG_HAS_DATAFLASH
  32. #include <dataflash.h>
  33. #endif
  34. #ifdef CONFIG_LOGBUFFER
  35. #include <logbuff.h>
  36. #endif
  37. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  38. #include <rtc.h>
  39. #endif
  40. #include <image.h>
  41. #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
  42. #include <fdt.h>
  43. #include <libfdt.h>
  44. #include <fdt_support.h>
  45. #endif
  46. #if defined(CONFIG_FIT)
  47. #include <u-boot/md5.h>
  48. #include <sha1.h>
  49. static int fit_check_ramdisk (const void *fit, int os_noffset,
  50. uint8_t arch, int verify);
  51. #endif
  52. #ifdef CONFIG_CMD_BDI
  53. extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  54. #endif
  55. DECLARE_GLOBAL_DATA_PTR;
  56. static const image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
  57. int verify);
  58. #else
  59. #include "mkimage.h"
  60. #include <u-boot/md5.h>
  61. #include <time.h>
  62. #include <image.h>
  63. #endif /* !USE_HOSTCC*/
  64. static table_entry_t uimage_arch[] = {
  65. { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
  66. { IH_ARCH_ALPHA, "alpha", "Alpha", },
  67. { IH_ARCH_ARM, "arm", "ARM", },
  68. { IH_ARCH_I386, "x86", "Intel x86", },
  69. { IH_ARCH_IA64, "ia64", "IA64", },
  70. { IH_ARCH_M68K, "m68k", "M68K", },
  71. { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
  72. { IH_ARCH_MIPS, "mips", "MIPS", },
  73. { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
  74. { IH_ARCH_NIOS, "nios", "NIOS", },
  75. { IH_ARCH_NIOS2, "nios2", "NIOS II", },
  76. { IH_ARCH_PPC, "powerpc", "PowerPC", },
  77. { IH_ARCH_PPC, "ppc", "PowerPC", },
  78. { IH_ARCH_S390, "s390", "IBM S390", },
  79. { IH_ARCH_SH, "sh", "SuperH", },
  80. { IH_ARCH_SPARC, "sparc", "SPARC", },
  81. { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
  82. { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
  83. { IH_ARCH_AVR32, "avr32", "AVR32", },
  84. { -1, "", "", },
  85. };
  86. static table_entry_t uimage_os[] = {
  87. { IH_OS_INVALID, NULL, "Invalid OS", },
  88. { IH_OS_LINUX, "linux", "Linux", },
  89. #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
  90. { IH_OS_LYNXOS, "lynxos", "LynxOS", },
  91. #endif
  92. { IH_OS_NETBSD, "netbsd", "NetBSD", },
  93. { IH_OS_RTEMS, "rtems", "RTEMS", },
  94. { IH_OS_U_BOOT, "u-boot", "U-Boot", },
  95. #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
  96. { IH_OS_QNX, "qnx", "QNX", },
  97. { IH_OS_VXWORKS, "vxworks", "VxWorks", },
  98. #endif
  99. #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
  100. { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
  101. #endif
  102. #ifdef USE_HOSTCC
  103. { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
  104. { IH_OS_DELL, "dell", "Dell", },
  105. { IH_OS_ESIX, "esix", "Esix", },
  106. { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
  107. { IH_OS_IRIX, "irix", "Irix", },
  108. { IH_OS_NCR, "ncr", "NCR", },
  109. { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
  110. { IH_OS_PSOS, "psos", "pSOS", },
  111. { IH_OS_SCO, "sco", "SCO", },
  112. { IH_OS_SOLARIS, "solaris", "Solaris", },
  113. { IH_OS_SVR4, "svr4", "SVR4", },
  114. #endif
  115. { -1, "", "", },
  116. };
  117. static table_entry_t uimage_type[] = {
  118. { IH_TYPE_INVALID, NULL, "Invalid Image", },
  119. { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
  120. { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
  121. { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
  122. { IH_TYPE_MULTI, "multi", "Multi-File Image", },
  123. { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
  124. { IH_TYPE_SCRIPT, "script", "Script", },
  125. { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
  126. { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
  127. { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
  128. { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
  129. { -1, "", "", },
  130. };
  131. static table_entry_t uimage_comp[] = {
  132. { IH_COMP_NONE, "none", "uncompressed", },
  133. { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
  134. { IH_COMP_GZIP, "gzip", "gzip compressed", },
  135. { IH_COMP_LZMA, "lzma", "lzma compressed", },
  136. { IH_COMP_LZO, "lzo", "lzo compressed", },
  137. { -1, "", "", },
  138. };
  139. uint32_t crc32 (uint32_t, const unsigned char *, uint);
  140. uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
  141. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  142. static void genimg_print_time (time_t timestamp);
  143. #endif
  144. /*****************************************************************************/
  145. /* Legacy format routines */
  146. /*****************************************************************************/
  147. int image_check_hcrc (const image_header_t *hdr)
  148. {
  149. ulong hcrc;
  150. ulong len = image_get_header_size ();
  151. image_header_t header;
  152. /* Copy header so we can blank CRC field for re-calculation */
  153. memmove (&header, (char *)hdr, image_get_header_size ());
  154. image_set_hcrc (&header, 0);
  155. hcrc = crc32 (0, (unsigned char *)&header, len);
  156. return (hcrc == image_get_hcrc (hdr));
  157. }
  158. int image_check_dcrc (const image_header_t *hdr)
  159. {
  160. ulong data = image_get_data (hdr);
  161. ulong len = image_get_data_size (hdr);
  162. ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
  163. return (dcrc == image_get_dcrc (hdr));
  164. }
  165. /**
  166. * image_multi_count - get component (sub-image) count
  167. * @hdr: pointer to the header of the multi component image
  168. *
  169. * image_multi_count() returns number of components in a multi
  170. * component image.
  171. *
  172. * Note: no checking of the image type is done, caller must pass
  173. * a valid multi component image.
  174. *
  175. * returns:
  176. * number of components
  177. */
  178. ulong image_multi_count (const image_header_t *hdr)
  179. {
  180. ulong i, count = 0;
  181. uint32_t *size;
  182. /* get start of the image payload, which in case of multi
  183. * component images that points to a table of component sizes */
  184. size = (uint32_t *)image_get_data (hdr);
  185. /* count non empty slots */
  186. for (i = 0; size[i]; ++i)
  187. count++;
  188. return count;
  189. }
  190. /**
  191. * image_multi_getimg - get component data address and size
  192. * @hdr: pointer to the header of the multi component image
  193. * @idx: index of the requested component
  194. * @data: pointer to a ulong variable, will hold component data address
  195. * @len: pointer to a ulong variable, will hold component size
  196. *
  197. * image_multi_getimg() returns size and data address for the requested
  198. * component in a multi component image.
  199. *
  200. * Note: no checking of the image type is done, caller must pass
  201. * a valid multi component image.
  202. *
  203. * returns:
  204. * data address and size of the component, if idx is valid
  205. * 0 in data and len, if idx is out of range
  206. */
  207. void image_multi_getimg (const image_header_t *hdr, ulong idx,
  208. ulong *data, ulong *len)
  209. {
  210. int i;
  211. uint32_t *size;
  212. ulong offset, count, img_data;
  213. /* get number of component */
  214. count = image_multi_count (hdr);
  215. /* get start of the image payload, which in case of multi
  216. * component images that points to a table of component sizes */
  217. size = (uint32_t *)image_get_data (hdr);
  218. /* get address of the proper component data start, which means
  219. * skipping sizes table (add 1 for last, null entry) */
  220. img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
  221. if (idx < count) {
  222. *len = uimage_to_cpu (size[idx]);
  223. offset = 0;
  224. /* go over all indices preceding requested component idx */
  225. for (i = 0; i < idx; i++) {
  226. /* add up i-th component size, rounding up to 4 bytes */
  227. offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
  228. }
  229. /* calculate idx-th component data address */
  230. *data = img_data + offset;
  231. } else {
  232. *len = 0;
  233. *data = 0;
  234. }
  235. }
  236. static void image_print_type (const image_header_t *hdr)
  237. {
  238. const char *os, *arch, *type, *comp;
  239. os = genimg_get_os_name (image_get_os (hdr));
  240. arch = genimg_get_arch_name (image_get_arch (hdr));
  241. type = genimg_get_type_name (image_get_type (hdr));
  242. comp = genimg_get_comp_name (image_get_comp (hdr));
  243. printf ("%s %s %s (%s)\n", arch, os, type, comp);
  244. }
  245. /**
  246. * image_print_contents - prints out the contents of the legacy format image
  247. * @ptr: pointer to the legacy format image header
  248. * @p: pointer to prefix string
  249. *
  250. * image_print_contents() formats a multi line legacy image contents description.
  251. * The routine prints out all header fields followed by the size/offset data
  252. * for MULTI/SCRIPT images.
  253. *
  254. * returns:
  255. * no returned results
  256. */
  257. void image_print_contents (const void *ptr)
  258. {
  259. const image_header_t *hdr = (const image_header_t *)ptr;
  260. const char *p;
  261. #ifdef USE_HOSTCC
  262. p = "";
  263. #else
  264. p = " ";
  265. #endif
  266. printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
  267. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  268. printf ("%sCreated: ", p);
  269. genimg_print_time ((time_t)image_get_time (hdr));
  270. #endif
  271. printf ("%sImage Type: ", p);
  272. image_print_type (hdr);
  273. printf ("%sData Size: ", p);
  274. genimg_print_size (image_get_data_size (hdr));
  275. printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
  276. printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
  277. if (image_check_type (hdr, IH_TYPE_MULTI) ||
  278. image_check_type (hdr, IH_TYPE_SCRIPT)) {
  279. int i;
  280. ulong data, len;
  281. ulong count = image_multi_count (hdr);
  282. printf ("%sContents:\n", p);
  283. for (i = 0; i < count; i++) {
  284. image_multi_getimg (hdr, i, &data, &len);
  285. printf ("%s Image %d: ", p, i);
  286. genimg_print_size (len);
  287. if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
  288. /*
  289. * the user may need to know offsets
  290. * if planning to do something with
  291. * multiple files
  292. */
  293. printf ("%s Offset = 0x%08lx\n", p, data);
  294. }
  295. }
  296. }
  297. }
  298. #ifndef USE_HOSTCC
  299. /**
  300. * image_get_ramdisk - get and verify ramdisk image
  301. * @rd_addr: ramdisk image start address
  302. * @arch: expected ramdisk architecture
  303. * @verify: checksum verification flag
  304. *
  305. * image_get_ramdisk() returns a pointer to the verified ramdisk image
  306. * header. Routine receives image start address and expected architecture
  307. * flag. Verification done covers data and header integrity and os/type/arch
  308. * fields checking.
  309. *
  310. * If dataflash support is enabled routine checks for dataflash addresses
  311. * and handles required dataflash reads.
  312. *
  313. * returns:
  314. * pointer to a ramdisk image header, if image was found and valid
  315. * otherwise, return NULL
  316. */
  317. static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
  318. int verify)
  319. {
  320. const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
  321. if (!image_check_magic (rd_hdr)) {
  322. puts ("Bad Magic Number\n");
  323. show_boot_progress (-10);
  324. return NULL;
  325. }
  326. if (!image_check_hcrc (rd_hdr)) {
  327. puts ("Bad Header Checksum\n");
  328. show_boot_progress (-11);
  329. return NULL;
  330. }
  331. show_boot_progress (10);
  332. image_print_contents (rd_hdr);
  333. if (verify) {
  334. puts(" Verifying Checksum ... ");
  335. if (!image_check_dcrc (rd_hdr)) {
  336. puts ("Bad Data CRC\n");
  337. show_boot_progress (-12);
  338. return NULL;
  339. }
  340. puts("OK\n");
  341. }
  342. show_boot_progress (11);
  343. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  344. !image_check_arch (rd_hdr, arch) ||
  345. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  346. printf ("No Linux %s Ramdisk Image\n",
  347. genimg_get_arch_name(arch));
  348. show_boot_progress (-13);
  349. return NULL;
  350. }
  351. return rd_hdr;
  352. }
  353. #endif /* !USE_HOSTCC */
  354. /*****************************************************************************/
  355. /* Shared dual-format routines */
  356. /*****************************************************************************/
  357. #ifndef USE_HOSTCC
  358. int getenv_yesno (char *var)
  359. {
  360. char *s = getenv (var);
  361. return (s && (*s == 'n')) ? 0 : 1;
  362. }
  363. ulong getenv_bootm_low(void)
  364. {
  365. char *s = getenv ("bootm_low");
  366. if (s) {
  367. ulong tmp = simple_strtoul (s, NULL, 16);
  368. return tmp;
  369. }
  370. #if defined(CONFIG_SYS_SDRAM_BASE)
  371. return CONFIG_SYS_SDRAM_BASE;
  372. #elif defined(CONFIG_ARM)
  373. return gd->bd->bi_dram[0].start;
  374. #else
  375. return 0;
  376. #endif
  377. }
  378. phys_size_t getenv_bootm_size(void)
  379. {
  380. char *s = getenv ("bootm_size");
  381. if (s) {
  382. phys_size_t tmp;
  383. tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
  384. return tmp;
  385. }
  386. #if defined(CONFIG_ARM)
  387. return gd->bd->bi_dram[0].size;
  388. #else
  389. return gd->bd->bi_memsize;
  390. #endif
  391. }
  392. void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
  393. {
  394. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  395. while (len > 0) {
  396. size_t tail = (len > chunksz) ? chunksz : len;
  397. WATCHDOG_RESET ();
  398. memmove (to, from, tail);
  399. to += tail;
  400. from += tail;
  401. len -= tail;
  402. }
  403. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  404. memmove (to, from, len);
  405. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  406. }
  407. #endif /* !USE_HOSTCC */
  408. void genimg_print_size (uint32_t size)
  409. {
  410. #ifndef USE_HOSTCC
  411. printf ("%d Bytes = ", size);
  412. print_size (size, "\n");
  413. #else
  414. printf ("%d Bytes = %.2f kB = %.2f MB\n",
  415. size, (double)size / 1.024e3,
  416. (double)size / 1.048576e6);
  417. #endif
  418. }
  419. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  420. static void genimg_print_time (time_t timestamp)
  421. {
  422. #ifndef USE_HOSTCC
  423. struct rtc_time tm;
  424. to_tm (timestamp, &tm);
  425. printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
  426. tm.tm_year, tm.tm_mon, tm.tm_mday,
  427. tm.tm_hour, tm.tm_min, tm.tm_sec);
  428. #else
  429. printf ("%s", ctime(&timestamp));
  430. #endif
  431. }
  432. #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
  433. /**
  434. * get_table_entry_name - translate entry id to long name
  435. * @table: pointer to a translation table for entries of a specific type
  436. * @msg: message to be returned when translation fails
  437. * @id: entry id to be translated
  438. *
  439. * get_table_entry_name() will go over translation table trying to find
  440. * entry that matches given id. If matching entry is found, its long
  441. * name is returned to the caller.
  442. *
  443. * returns:
  444. * long entry name if translation succeeds
  445. * msg otherwise
  446. */
  447. char *get_table_entry_name (table_entry_t *table, char *msg, int id)
  448. {
  449. for (; table->id >= 0; ++table) {
  450. if (table->id == id)
  451. #if defined(USE_HOSTCC) || defined(CONFIG_RELOC_FIXUP_WORKS)
  452. return table->lname;
  453. #else
  454. return table->lname + gd->reloc_off;
  455. #endif
  456. }
  457. return (msg);
  458. }
  459. const char *genimg_get_os_name (uint8_t os)
  460. {
  461. return (get_table_entry_name (uimage_os, "Unknown OS", os));
  462. }
  463. const char *genimg_get_arch_name (uint8_t arch)
  464. {
  465. return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
  466. }
  467. const char *genimg_get_type_name (uint8_t type)
  468. {
  469. return (get_table_entry_name (uimage_type, "Unknown Image", type));
  470. }
  471. const char *genimg_get_comp_name (uint8_t comp)
  472. {
  473. return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
  474. }
  475. /**
  476. * get_table_entry_id - translate short entry name to id
  477. * @table: pointer to a translation table for entries of a specific type
  478. * @table_name: to be used in case of error
  479. * @name: entry short name to be translated
  480. *
  481. * get_table_entry_id() will go over translation table trying to find
  482. * entry that matches given short name. If matching entry is found,
  483. * its id returned to the caller.
  484. *
  485. * returns:
  486. * entry id if translation succeeds
  487. * -1 otherwise
  488. */
  489. int get_table_entry_id (table_entry_t *table,
  490. const char *table_name, const char *name)
  491. {
  492. table_entry_t *t;
  493. #ifdef USE_HOSTCC
  494. int first = 1;
  495. for (t = table; t->id >= 0; ++t) {
  496. if (t->sname && strcasecmp(t->sname, name) == 0)
  497. return (t->id);
  498. }
  499. fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
  500. for (t = table; t->id >= 0; ++t) {
  501. if (t->sname == NULL)
  502. continue;
  503. fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
  504. first = 0;
  505. }
  506. fprintf (stderr, "\n");
  507. #else
  508. for (t = table; t->id >= 0; ++t) {
  509. #ifdef CONFIG_RELOC_FIXUP_WORKS
  510. if (t->sname && strcmp(t->sname, name) == 0)
  511. #else
  512. if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
  513. #endif
  514. return (t->id);
  515. }
  516. debug ("Invalid %s Type: %s\n", table_name, name);
  517. #endif /* USE_HOSTCC */
  518. return (-1);
  519. }
  520. int genimg_get_os_id (const char *name)
  521. {
  522. return (get_table_entry_id (uimage_os, "OS", name));
  523. }
  524. int genimg_get_arch_id (const char *name)
  525. {
  526. return (get_table_entry_id (uimage_arch, "CPU", name));
  527. }
  528. int genimg_get_type_id (const char *name)
  529. {
  530. return (get_table_entry_id (uimage_type, "Image", name));
  531. }
  532. int genimg_get_comp_id (const char *name)
  533. {
  534. return (get_table_entry_id (uimage_comp, "Compression", name));
  535. }
  536. #ifndef USE_HOSTCC
  537. /**
  538. * genimg_get_format - get image format type
  539. * @img_addr: image start address
  540. *
  541. * genimg_get_format() checks whether provided address points to a valid
  542. * legacy or FIT image.
  543. *
  544. * New uImage format and FDT blob are based on a libfdt. FDT blob
  545. * may be passed directly or embedded in a FIT image. In both situations
  546. * genimg_get_format() must be able to dectect libfdt header.
  547. *
  548. * returns:
  549. * image format type or IMAGE_FORMAT_INVALID if no image is present
  550. */
  551. int genimg_get_format (void *img_addr)
  552. {
  553. ulong format = IMAGE_FORMAT_INVALID;
  554. const image_header_t *hdr;
  555. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  556. char *fit_hdr;
  557. #endif
  558. hdr = (const image_header_t *)img_addr;
  559. if (image_check_magic(hdr))
  560. format = IMAGE_FORMAT_LEGACY;
  561. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  562. else {
  563. fit_hdr = (char *)img_addr;
  564. if (fdt_check_header (fit_hdr) == 0)
  565. format = IMAGE_FORMAT_FIT;
  566. }
  567. #endif
  568. return format;
  569. }
  570. /**
  571. * genimg_get_image - get image from special storage (if necessary)
  572. * @img_addr: image start address
  573. *
  574. * genimg_get_image() checks if provided image start adddress is located
  575. * in a dataflash storage. If so, image is moved to a system RAM memory.
  576. *
  577. * returns:
  578. * image start address after possible relocation from special storage
  579. */
  580. ulong genimg_get_image (ulong img_addr)
  581. {
  582. ulong ram_addr = img_addr;
  583. #ifdef CONFIG_HAS_DATAFLASH
  584. ulong h_size, d_size;
  585. if (addr_dataflash (img_addr)){
  586. /* ger RAM address */
  587. ram_addr = CONFIG_SYS_LOAD_ADDR;
  588. /* get header size */
  589. h_size = image_get_header_size ();
  590. #if defined(CONFIG_FIT)
  591. if (sizeof(struct fdt_header) > h_size)
  592. h_size = sizeof(struct fdt_header);
  593. #endif
  594. /* read in header */
  595. debug (" Reading image header from dataflash address "
  596. "%08lx to RAM address %08lx\n", img_addr, ram_addr);
  597. read_dataflash (img_addr, h_size, (char *)ram_addr);
  598. /* get data size */
  599. switch (genimg_get_format ((void *)ram_addr)) {
  600. case IMAGE_FORMAT_LEGACY:
  601. d_size = image_get_data_size ((const image_header_t *)ram_addr);
  602. debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
  603. ram_addr, d_size);
  604. break;
  605. #if defined(CONFIG_FIT)
  606. case IMAGE_FORMAT_FIT:
  607. d_size = fit_get_size ((const void *)ram_addr) - h_size;
  608. debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
  609. ram_addr, d_size);
  610. break;
  611. #endif
  612. default:
  613. printf (" No valid image found at 0x%08lx\n", img_addr);
  614. return ram_addr;
  615. }
  616. /* read in image data */
  617. debug (" Reading image remaining data from dataflash address "
  618. "%08lx to RAM address %08lx\n", img_addr + h_size,
  619. ram_addr + h_size);
  620. read_dataflash (img_addr + h_size, d_size,
  621. (char *)(ram_addr + h_size));
  622. }
  623. #endif /* CONFIG_HAS_DATAFLASH */
  624. return ram_addr;
  625. }
  626. /**
  627. * fit_has_config - check if there is a valid FIT configuration
  628. * @images: pointer to the bootm command headers structure
  629. *
  630. * fit_has_config() checks if there is a FIT configuration in use
  631. * (if FTI support is present).
  632. *
  633. * returns:
  634. * 0, no FIT support or no configuration found
  635. * 1, configuration found
  636. */
  637. int genimg_has_config (bootm_headers_t *images)
  638. {
  639. #if defined(CONFIG_FIT)
  640. if (images->fit_uname_cfg)
  641. return 1;
  642. #endif
  643. return 0;
  644. }
  645. /**
  646. * boot_get_ramdisk - main ramdisk handling routine
  647. * @argc: command argument count
  648. * @argv: command argument list
  649. * @images: pointer to the bootm images structure
  650. * @arch: expected ramdisk architecture
  651. * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  652. * @rd_end: pointer to a ulong variable, will hold ramdisk end
  653. *
  654. * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
  655. * Curently supported are the following ramdisk sources:
  656. * - multicomponent kernel/ramdisk image,
  657. * - commandline provided address of decicated ramdisk image.
  658. *
  659. * returns:
  660. * 0, if ramdisk image was found and valid, or skiped
  661. * rd_start and rd_end are set to ramdisk start/end addresses if
  662. * ramdisk image is found and valid
  663. *
  664. * 1, if ramdisk image is found but corrupted, or invalid
  665. * rd_start and rd_end are set to 0 if no ramdisk exists
  666. */
  667. int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
  668. uint8_t arch, ulong *rd_start, ulong *rd_end)
  669. {
  670. ulong rd_addr, rd_load;
  671. ulong rd_data, rd_len;
  672. const image_header_t *rd_hdr;
  673. #if defined(CONFIG_FIT)
  674. void *fit_hdr;
  675. const char *fit_uname_config = NULL;
  676. const char *fit_uname_ramdisk = NULL;
  677. ulong default_addr;
  678. int rd_noffset;
  679. int cfg_noffset;
  680. const void *data;
  681. size_t size;
  682. #endif
  683. *rd_start = 0;
  684. *rd_end = 0;
  685. /*
  686. * Look for a '-' which indicates to ignore the
  687. * ramdisk argument
  688. */
  689. if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
  690. debug ("## Skipping init Ramdisk\n");
  691. rd_len = rd_data = 0;
  692. } else if (argc >= 3 || genimg_has_config (images)) {
  693. #if defined(CONFIG_FIT)
  694. if (argc >= 3) {
  695. /*
  696. * If the init ramdisk comes from the FIT image and
  697. * the FIT image address is omitted in the command
  698. * line argument, try to use os FIT image address or
  699. * default load address.
  700. */
  701. if (images->fit_uname_os)
  702. default_addr = (ulong)images->fit_hdr_os;
  703. else
  704. default_addr = load_addr;
  705. if (fit_parse_conf (argv[2], default_addr,
  706. &rd_addr, &fit_uname_config)) {
  707. debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
  708. fit_uname_config, rd_addr);
  709. } else if (fit_parse_subimage (argv[2], default_addr,
  710. &rd_addr, &fit_uname_ramdisk)) {
  711. debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
  712. fit_uname_ramdisk, rd_addr);
  713. } else
  714. #endif
  715. {
  716. rd_addr = simple_strtoul(argv[2], NULL, 16);
  717. debug ("* ramdisk: cmdline image address = 0x%08lx\n",
  718. rd_addr);
  719. }
  720. #if defined(CONFIG_FIT)
  721. } else {
  722. /* use FIT configuration provided in first bootm
  723. * command argument
  724. */
  725. rd_addr = (ulong)images->fit_hdr_os;
  726. fit_uname_config = images->fit_uname_cfg;
  727. debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
  728. fit_uname_config, rd_addr);
  729. /*
  730. * Check whether configuration has ramdisk defined,
  731. * if not, don't try to use it, quit silently.
  732. */
  733. fit_hdr = (void *)rd_addr;
  734. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  735. if (cfg_noffset < 0) {
  736. debug ("* ramdisk: no such config\n");
  737. return 1;
  738. }
  739. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  740. if (rd_noffset < 0) {
  741. debug ("* ramdisk: no ramdisk in config\n");
  742. return 0;
  743. }
  744. }
  745. #endif
  746. /* copy from dataflash if needed */
  747. rd_addr = genimg_get_image (rd_addr);
  748. /*
  749. * Check if there is an initrd image at the
  750. * address provided in the second bootm argument
  751. * check image type, for FIT images get FIT node.
  752. */
  753. switch (genimg_get_format ((void *)rd_addr)) {
  754. case IMAGE_FORMAT_LEGACY:
  755. printf ("## Loading init Ramdisk from Legacy "
  756. "Image at %08lx ...\n", rd_addr);
  757. show_boot_progress (9);
  758. rd_hdr = image_get_ramdisk (rd_addr, arch,
  759. images->verify);
  760. if (rd_hdr == NULL)
  761. return 1;
  762. rd_data = image_get_data (rd_hdr);
  763. rd_len = image_get_data_size (rd_hdr);
  764. rd_load = image_get_load (rd_hdr);
  765. break;
  766. #if defined(CONFIG_FIT)
  767. case IMAGE_FORMAT_FIT:
  768. fit_hdr = (void *)rd_addr;
  769. printf ("## Loading init Ramdisk from FIT "
  770. "Image at %08lx ...\n", rd_addr);
  771. show_boot_progress (120);
  772. if (!fit_check_format (fit_hdr)) {
  773. puts ("Bad FIT ramdisk image format!\n");
  774. show_boot_progress (-120);
  775. return 1;
  776. }
  777. show_boot_progress (121);
  778. if (!fit_uname_ramdisk) {
  779. /*
  780. * no ramdisk image node unit name, try to get config
  781. * node first. If config unit node name is NULL
  782. * fit_conf_get_node() will try to find default config node
  783. */
  784. show_boot_progress (122);
  785. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  786. if (cfg_noffset < 0) {
  787. puts ("Could not find configuration node\n");
  788. show_boot_progress (-122);
  789. return 1;
  790. }
  791. fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
  792. printf (" Using '%s' configuration\n", fit_uname_config);
  793. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  794. fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
  795. } else {
  796. /* get ramdisk component image node offset */
  797. show_boot_progress (123);
  798. rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
  799. }
  800. if (rd_noffset < 0) {
  801. puts ("Could not find subimage node\n");
  802. show_boot_progress (-124);
  803. return 1;
  804. }
  805. printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
  806. show_boot_progress (125);
  807. if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
  808. return 1;
  809. /* get ramdisk image data address and length */
  810. if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
  811. puts ("Could not find ramdisk subimage data!\n");
  812. show_boot_progress (-127);
  813. return 1;
  814. }
  815. show_boot_progress (128);
  816. rd_data = (ulong)data;
  817. rd_len = size;
  818. if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
  819. puts ("Can't get ramdisk subimage load address!\n");
  820. show_boot_progress (-129);
  821. return 1;
  822. }
  823. show_boot_progress (129);
  824. images->fit_hdr_rd = fit_hdr;
  825. images->fit_uname_rd = fit_uname_ramdisk;
  826. images->fit_noffset_rd = rd_noffset;
  827. break;
  828. #endif
  829. default:
  830. puts ("Wrong Ramdisk Image Format\n");
  831. rd_data = rd_len = rd_load = 0;
  832. return 1;
  833. }
  834. #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
  835. /*
  836. * We need to copy the ramdisk to SRAM to let Linux boot
  837. */
  838. if (rd_data) {
  839. memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
  840. rd_data = rd_load;
  841. }
  842. #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
  843. } else if (images->legacy_hdr_valid &&
  844. image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  845. /*
  846. * Now check if we have a legacy mult-component image,
  847. * get second entry data start address and len.
  848. */
  849. show_boot_progress (13);
  850. printf ("## Loading init Ramdisk from multi component "
  851. "Legacy Image at %08lx ...\n",
  852. (ulong)images->legacy_hdr_os);
  853. image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
  854. } else {
  855. /*
  856. * no initrd image
  857. */
  858. show_boot_progress (14);
  859. rd_len = rd_data = 0;
  860. }
  861. if (!rd_data) {
  862. debug ("## No init Ramdisk\n");
  863. } else {
  864. *rd_start = rd_data;
  865. *rd_end = rd_data + rd_len;
  866. }
  867. debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
  868. *rd_start, *rd_end);
  869. return 0;
  870. }
  871. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
  872. /**
  873. * boot_ramdisk_high - relocate init ramdisk
  874. * @lmb: pointer to lmb handle, will be used for memory mgmt
  875. * @rd_data: ramdisk data start address
  876. * @rd_len: ramdisk data length
  877. * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
  878. * start address (after possible relocation)
  879. * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  880. * end address (after possible relocation)
  881. *
  882. * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
  883. * variable and if requested ramdisk data is moved to a specified location.
  884. *
  885. * Initrd_start and initrd_end are set to final (after relocation) ramdisk
  886. * start/end addresses if ramdisk image start and len were provided,
  887. * otherwise set initrd_start and initrd_end set to zeros.
  888. *
  889. * returns:
  890. * 0 - success
  891. * -1 - failure
  892. */
  893. int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
  894. ulong *initrd_start, ulong *initrd_end)
  895. {
  896. char *s;
  897. ulong initrd_high;
  898. int initrd_copy_to_ram = 1;
  899. if ((s = getenv ("initrd_high")) != NULL) {
  900. /* a value of "no" or a similar string will act like 0,
  901. * turning the "load high" feature off. This is intentional.
  902. */
  903. initrd_high = simple_strtoul (s, NULL, 16);
  904. if (initrd_high == ~0)
  905. initrd_copy_to_ram = 0;
  906. } else {
  907. /* not set, no restrictions to load high */
  908. initrd_high = ~0;
  909. }
  910. #ifdef CONFIG_LOGBUFFER
  911. /* Prevent initrd from overwriting logbuffer */
  912. lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
  913. #endif
  914. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  915. initrd_high, initrd_copy_to_ram);
  916. if (rd_data) {
  917. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  918. debug (" in-place initrd\n");
  919. *initrd_start = rd_data;
  920. *initrd_end = rd_data + rd_len;
  921. lmb_reserve(lmb, rd_data, rd_len);
  922. } else {
  923. if (initrd_high)
  924. *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
  925. else
  926. *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
  927. if (*initrd_start == 0) {
  928. puts ("ramdisk - allocation error\n");
  929. goto error;
  930. }
  931. show_boot_progress (12);
  932. *initrd_end = *initrd_start + rd_len;
  933. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  934. *initrd_start, *initrd_end);
  935. memmove_wd ((void *)*initrd_start,
  936. (void *)rd_data, rd_len, CHUNKSZ);
  937. puts ("OK\n");
  938. }
  939. } else {
  940. *initrd_start = 0;
  941. *initrd_end = 0;
  942. }
  943. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  944. *initrd_start, *initrd_end);
  945. return 0;
  946. error:
  947. return -1;
  948. }
  949. #endif /* defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) */
  950. #ifdef CONFIG_OF_LIBFDT
  951. static void fdt_error (const char *msg)
  952. {
  953. puts ("ERROR: ");
  954. puts (msg);
  955. puts (" - must RESET the board to recover.\n");
  956. }
  957. static const image_header_t *image_get_fdt (ulong fdt_addr)
  958. {
  959. const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
  960. image_print_contents (fdt_hdr);
  961. puts (" Verifying Checksum ... ");
  962. if (!image_check_hcrc (fdt_hdr)) {
  963. fdt_error ("fdt header checksum invalid");
  964. return NULL;
  965. }
  966. if (!image_check_dcrc (fdt_hdr)) {
  967. fdt_error ("fdt checksum invalid");
  968. return NULL;
  969. }
  970. puts ("OK\n");
  971. if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
  972. fdt_error ("uImage is not a fdt");
  973. return NULL;
  974. }
  975. if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
  976. fdt_error ("uImage is compressed");
  977. return NULL;
  978. }
  979. if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
  980. fdt_error ("uImage data is not a fdt");
  981. return NULL;
  982. }
  983. return fdt_hdr;
  984. }
  985. /**
  986. * fit_check_fdt - verify FIT format FDT subimage
  987. * @fit_hdr: pointer to the FIT header
  988. * fdt_noffset: FDT subimage node offset within FIT image
  989. * @verify: data CRC verification flag
  990. *
  991. * fit_check_fdt() verifies integrity of the FDT subimage and from
  992. * specified FIT image.
  993. *
  994. * returns:
  995. * 1, on success
  996. * 0, on failure
  997. */
  998. #if defined(CONFIG_FIT)
  999. static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
  1000. {
  1001. fit_image_print (fit, fdt_noffset, " ");
  1002. if (verify) {
  1003. puts (" Verifying Hash Integrity ... ");
  1004. if (!fit_image_check_hashes (fit, fdt_noffset)) {
  1005. fdt_error ("Bad Data Hash");
  1006. return 0;
  1007. }
  1008. puts ("OK\n");
  1009. }
  1010. if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
  1011. fdt_error ("Not a FDT image");
  1012. return 0;
  1013. }
  1014. if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
  1015. fdt_error ("FDT image is compressed");
  1016. return 0;
  1017. }
  1018. return 1;
  1019. }
  1020. #endif /* CONFIG_FIT */
  1021. #ifndef CONFIG_SYS_FDT_PAD
  1022. #define CONFIG_SYS_FDT_PAD 0x3000
  1023. #endif
  1024. /**
  1025. * boot_relocate_fdt - relocate flat device tree
  1026. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1027. * @bootmap_base: base address of the bootmap region
  1028. * @of_flat_tree: pointer to a char* variable, will hold fdt start address
  1029. * @of_size: pointer to a ulong variable, will hold fdt length
  1030. *
  1031. * boot_relocate_fdt() determines if the of_flat_tree address is within
  1032. * the bootmap and if not relocates it into that region
  1033. *
  1034. * of_flat_tree and of_size are set to final (after relocation) values
  1035. *
  1036. * returns:
  1037. * 0 - success
  1038. * 1 - failure
  1039. */
  1040. int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
  1041. char **of_flat_tree, ulong *of_size)
  1042. {
  1043. char *fdt_blob = *of_flat_tree;
  1044. ulong relocate = 0;
  1045. ulong of_len = 0;
  1046. /* nothing to do */
  1047. if (*of_size == 0)
  1048. return 0;
  1049. if (fdt_check_header (fdt_blob) != 0) {
  1050. fdt_error ("image is not a fdt");
  1051. goto error;
  1052. }
  1053. #ifndef CONFIG_SYS_NO_FLASH
  1054. /* move the blob if it is in flash (set relocate) */
  1055. if (addr2info ((ulong)fdt_blob) != NULL)
  1056. relocate = 1;
  1057. #endif
  1058. /*
  1059. * The blob needs to be inside the boot mapping.
  1060. */
  1061. if (fdt_blob < (char *)bootmap_base)
  1062. relocate = 1;
  1063. if ((fdt_blob + *of_size + CONFIG_SYS_FDT_PAD) >=
  1064. ((char *)CONFIG_SYS_BOOTMAPSZ + bootmap_base))
  1065. relocate = 1;
  1066. /* move flattend device tree if needed */
  1067. if (relocate) {
  1068. int err;
  1069. ulong of_start = 0;
  1070. /* position on a 4K boundary before the alloc_current */
  1071. /* Pad the FDT by a specified amount */
  1072. of_len = *of_size + CONFIG_SYS_FDT_PAD;
  1073. of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
  1074. (CONFIG_SYS_BOOTMAPSZ + bootmap_base));
  1075. if (of_start == 0) {
  1076. puts("device tree - allocation error\n");
  1077. goto error;
  1078. }
  1079. debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
  1080. (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1,
  1081. of_len, of_len);
  1082. printf (" Loading Device Tree to %08lx, end %08lx ... ",
  1083. of_start, of_start + of_len - 1);
  1084. err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
  1085. if (err != 0) {
  1086. fdt_error ("fdt move failed");
  1087. goto error;
  1088. }
  1089. puts ("OK\n");
  1090. *of_flat_tree = (char *)of_start;
  1091. *of_size = of_len;
  1092. } else {
  1093. *of_flat_tree = fdt_blob;
  1094. of_len = (CONFIG_SYS_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob;
  1095. lmb_reserve(lmb, (ulong)fdt_blob, of_len);
  1096. fdt_set_totalsize(*of_flat_tree, of_len);
  1097. *of_size = of_len;
  1098. }
  1099. set_working_fdt_addr(*of_flat_tree);
  1100. return 0;
  1101. error:
  1102. return 1;
  1103. }
  1104. /**
  1105. * boot_get_fdt - main fdt handling routine
  1106. * @argc: command argument count
  1107. * @argv: command argument list
  1108. * @images: pointer to the bootm images structure
  1109. * @of_flat_tree: pointer to a char* variable, will hold fdt start address
  1110. * @of_size: pointer to a ulong variable, will hold fdt length
  1111. *
  1112. * boot_get_fdt() is responsible for finding a valid flat device tree image.
  1113. * Curently supported are the following ramdisk sources:
  1114. * - multicomponent kernel/ramdisk image,
  1115. * - commandline provided address of decicated ramdisk image.
  1116. *
  1117. * returns:
  1118. * 0, if fdt image was found and valid, or skipped
  1119. * of_flat_tree and of_size are set to fdt start address and length if
  1120. * fdt image is found and valid
  1121. *
  1122. * 1, if fdt image is found but corrupted
  1123. * of_flat_tree and of_size are set to 0 if no fdt exists
  1124. */
  1125. int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images,
  1126. char **of_flat_tree, ulong *of_size)
  1127. {
  1128. const image_header_t *fdt_hdr;
  1129. ulong fdt_addr;
  1130. char *fdt_blob = NULL;
  1131. ulong image_start, image_end;
  1132. ulong load_start, load_end;
  1133. #if defined(CONFIG_FIT)
  1134. void *fit_hdr;
  1135. const char *fit_uname_config = NULL;
  1136. const char *fit_uname_fdt = NULL;
  1137. ulong default_addr;
  1138. int cfg_noffset;
  1139. int fdt_noffset;
  1140. const void *data;
  1141. size_t size;
  1142. #endif
  1143. *of_flat_tree = NULL;
  1144. *of_size = 0;
  1145. if (argc > 3 || genimg_has_config (images)) {
  1146. #if defined(CONFIG_FIT)
  1147. if (argc > 3) {
  1148. /*
  1149. * If the FDT blob comes from the FIT image and the
  1150. * FIT image address is omitted in the command line
  1151. * argument, try to use ramdisk or os FIT image
  1152. * address or default load address.
  1153. */
  1154. if (images->fit_uname_rd)
  1155. default_addr = (ulong)images->fit_hdr_rd;
  1156. else if (images->fit_uname_os)
  1157. default_addr = (ulong)images->fit_hdr_os;
  1158. else
  1159. default_addr = load_addr;
  1160. if (fit_parse_conf (argv[3], default_addr,
  1161. &fdt_addr, &fit_uname_config)) {
  1162. debug ("* fdt: config '%s' from image at 0x%08lx\n",
  1163. fit_uname_config, fdt_addr);
  1164. } else if (fit_parse_subimage (argv[3], default_addr,
  1165. &fdt_addr, &fit_uname_fdt)) {
  1166. debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
  1167. fit_uname_fdt, fdt_addr);
  1168. } else
  1169. #endif
  1170. {
  1171. fdt_addr = simple_strtoul(argv[3], NULL, 16);
  1172. debug ("* fdt: cmdline image address = 0x%08lx\n",
  1173. fdt_addr);
  1174. }
  1175. #if defined(CONFIG_FIT)
  1176. } else {
  1177. /* use FIT configuration provided in first bootm
  1178. * command argument
  1179. */
  1180. fdt_addr = (ulong)images->fit_hdr_os;
  1181. fit_uname_config = images->fit_uname_cfg;
  1182. debug ("* fdt: using config '%s' from image at 0x%08lx\n",
  1183. fit_uname_config, fdt_addr);
  1184. /*
  1185. * Check whether configuration has FDT blob defined,
  1186. * if not quit silently.
  1187. */
  1188. fit_hdr = (void *)fdt_addr;
  1189. cfg_noffset = fit_conf_get_node (fit_hdr,
  1190. fit_uname_config);
  1191. if (cfg_noffset < 0) {
  1192. debug ("* fdt: no such config\n");
  1193. return 0;
  1194. }
  1195. fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
  1196. cfg_noffset);
  1197. if (fdt_noffset < 0) {
  1198. debug ("* fdt: no fdt in config\n");
  1199. return 0;
  1200. }
  1201. }
  1202. #endif
  1203. debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
  1204. fdt_addr);
  1205. /* copy from dataflash if needed */
  1206. fdt_addr = genimg_get_image (fdt_addr);
  1207. /*
  1208. * Check if there is an FDT image at the
  1209. * address provided in the second bootm argument
  1210. * check image type, for FIT images get a FIT node.
  1211. */
  1212. switch (genimg_get_format ((void *)fdt_addr)) {
  1213. case IMAGE_FORMAT_LEGACY:
  1214. /* verify fdt_addr points to a valid image header */
  1215. printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
  1216. fdt_addr);
  1217. fdt_hdr = image_get_fdt (fdt_addr);
  1218. if (!fdt_hdr)
  1219. goto error;
  1220. /*
  1221. * move image data to the load address,
  1222. * make sure we don't overwrite initial image
  1223. */
  1224. image_start = (ulong)fdt_hdr;
  1225. image_end = image_get_image_end (fdt_hdr);
  1226. load_start = image_get_load (fdt_hdr);
  1227. load_end = load_start + image_get_data_size (fdt_hdr);
  1228. if ((load_start < image_end) && (load_end > image_start)) {
  1229. fdt_error ("fdt overwritten");
  1230. goto error;
  1231. }
  1232. debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
  1233. image_get_data (fdt_hdr), load_start);
  1234. memmove ((void *)load_start,
  1235. (void *)image_get_data (fdt_hdr),
  1236. image_get_data_size (fdt_hdr));
  1237. fdt_blob = (char *)load_start;
  1238. break;
  1239. case IMAGE_FORMAT_FIT:
  1240. /*
  1241. * This case will catch both: new uImage format
  1242. * (libfdt based) and raw FDT blob (also libfdt
  1243. * based).
  1244. */
  1245. #if defined(CONFIG_FIT)
  1246. /* check FDT blob vs FIT blob */
  1247. if (fit_check_format ((const void *)fdt_addr)) {
  1248. /*
  1249. * FIT image
  1250. */
  1251. fit_hdr = (void *)fdt_addr;
  1252. printf ("## Flattened Device Tree from FIT Image at %08lx\n",
  1253. fdt_addr);
  1254. if (!fit_uname_fdt) {
  1255. /*
  1256. * no FDT blob image node unit name,
  1257. * try to get config node first. If
  1258. * config unit node name is NULL
  1259. * fit_conf_get_node() will try to
  1260. * find default config node
  1261. */
  1262. cfg_noffset = fit_conf_get_node (fit_hdr,
  1263. fit_uname_config);
  1264. if (cfg_noffset < 0) {
  1265. fdt_error ("Could not find configuration node\n");
  1266. goto error;
  1267. }
  1268. fit_uname_config = fdt_get_name (fit_hdr,
  1269. cfg_noffset, NULL);
  1270. printf (" Using '%s' configuration\n",
  1271. fit_uname_config);
  1272. fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
  1273. cfg_noffset);
  1274. fit_uname_fdt = fit_get_name (fit_hdr,
  1275. fdt_noffset, NULL);
  1276. } else {
  1277. /* get FDT component image node offset */
  1278. fdt_noffset = fit_image_get_node (fit_hdr,
  1279. fit_uname_fdt);
  1280. }
  1281. if (fdt_noffset < 0) {
  1282. fdt_error ("Could not find subimage node\n");
  1283. goto error;
  1284. }
  1285. printf (" Trying '%s' FDT blob subimage\n",
  1286. fit_uname_fdt);
  1287. if (!fit_check_fdt (fit_hdr, fdt_noffset,
  1288. images->verify))
  1289. goto error;
  1290. /* get ramdisk image data address and length */
  1291. if (fit_image_get_data (fit_hdr, fdt_noffset,
  1292. &data, &size)) {
  1293. fdt_error ("Could not find FDT subimage data");
  1294. goto error;
  1295. }
  1296. /* verift that image data is a proper FDT blob */
  1297. if (fdt_check_header ((char *)data) != 0) {
  1298. fdt_error ("Subimage data is not a FTD");
  1299. goto error;
  1300. }
  1301. /*
  1302. * move image data to the load address,
  1303. * make sure we don't overwrite initial image
  1304. */
  1305. image_start = (ulong)fit_hdr;
  1306. image_end = fit_get_end (fit_hdr);
  1307. if (fit_image_get_load (fit_hdr, fdt_noffset,
  1308. &load_start) == 0) {
  1309. load_end = load_start + size;
  1310. if ((load_start < image_end) &&
  1311. (load_end > image_start)) {
  1312. fdt_error ("FDT overwritten");
  1313. goto error;
  1314. }
  1315. printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
  1316. (ulong)data, load_start);
  1317. memmove ((void *)load_start,
  1318. (void *)data, size);
  1319. fdt_blob = (char *)load_start;
  1320. } else {
  1321. fdt_blob = (char *)data;
  1322. }
  1323. images->fit_hdr_fdt = fit_hdr;
  1324. images->fit_uname_fdt = fit_uname_fdt;
  1325. images->fit_noffset_fdt = fdt_noffset;
  1326. break;
  1327. } else
  1328. #endif
  1329. {
  1330. /*
  1331. * FDT blob
  1332. */
  1333. fdt_blob = (char *)fdt_addr;
  1334. debug ("* fdt: raw FDT blob\n");
  1335. printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
  1336. }
  1337. break;
  1338. default:
  1339. puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
  1340. goto error;
  1341. }
  1342. printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
  1343. } else if (images->legacy_hdr_valid &&
  1344. image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1345. ulong fdt_data, fdt_len;
  1346. /*
  1347. * Now check if we have a legacy multi-component image,
  1348. * get second entry data start address and len.
  1349. */
  1350. printf ("## Flattened Device Tree from multi "
  1351. "component Image at %08lX\n",
  1352. (ulong)images->legacy_hdr_os);
  1353. image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
  1354. if (fdt_len) {
  1355. fdt_blob = (char *)fdt_data;
  1356. printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
  1357. if (fdt_check_header (fdt_blob) != 0) {
  1358. fdt_error ("image is not a fdt");
  1359. goto error;
  1360. }
  1361. if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
  1362. fdt_error ("fdt size != image size");
  1363. goto error;
  1364. }
  1365. } else {
  1366. debug ("## No Flattened Device Tree\n");
  1367. return 0;
  1368. }
  1369. } else {
  1370. debug ("## No Flattened Device Tree\n");
  1371. return 0;
  1372. }
  1373. *of_flat_tree = fdt_blob;
  1374. *of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
  1375. debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
  1376. (ulong)*of_flat_tree, *of_size);
  1377. return 0;
  1378. error:
  1379. *of_flat_tree = 0;
  1380. *of_size = 0;
  1381. return 1;
  1382. }
  1383. #endif /* CONFIG_OF_LIBFDT */
  1384. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  1385. /**
  1386. * boot_get_cmdline - allocate and initialize kernel cmdline
  1387. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1388. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  1389. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  1390. * @bootmap_base: ulong variable, holds offset in physical memory to
  1391. * base of bootmap
  1392. *
  1393. * boot_get_cmdline() allocates space for kernel command line below
  1394. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  1395. * variable is present its contents is copied to allocated kernel
  1396. * command line.
  1397. *
  1398. * returns:
  1399. * 0 - success
  1400. * -1 - failure
  1401. */
  1402. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  1403. ulong bootmap_base)
  1404. {
  1405. char *cmdline;
  1406. char *s;
  1407. cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
  1408. CONFIG_SYS_BOOTMAPSZ + bootmap_base);
  1409. if (cmdline == NULL)
  1410. return -1;
  1411. if ((s = getenv("bootargs")) == NULL)
  1412. s = "";
  1413. strcpy(cmdline, s);
  1414. *cmd_start = (ulong) & cmdline[0];
  1415. *cmd_end = *cmd_start + strlen(cmdline);
  1416. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  1417. return 0;
  1418. }
  1419. /**
  1420. * boot_get_kbd - allocate and initialize kernel copy of board info
  1421. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1422. * @kbd: double pointer to board info data
  1423. * @bootmap_base: ulong variable, holds offset in physical memory to
  1424. * base of bootmap
  1425. *
  1426. * boot_get_kbd() allocates space for kernel copy of board info data below
  1427. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  1428. * the current u-boot board info data.
  1429. *
  1430. * returns:
  1431. * 0 - success
  1432. * -1 - failure
  1433. */
  1434. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  1435. {
  1436. *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  1437. CONFIG_SYS_BOOTMAPSZ + bootmap_base);
  1438. if (*kbd == NULL)
  1439. return -1;
  1440. **kbd = *(gd->bd);
  1441. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  1442. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  1443. do_bdinfo(NULL, 0, 0, NULL);
  1444. #endif
  1445. return 0;
  1446. }
  1447. #endif /* CONFIG_PPC || CONFIG_M68K */
  1448. #endif /* !USE_HOSTCC */
  1449. #if defined(CONFIG_FIT)
  1450. /*****************************************************************************/
  1451. /* New uImage format routines */
  1452. /*****************************************************************************/
  1453. #ifndef USE_HOSTCC
  1454. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1455. ulong *addr, const char **name)
  1456. {
  1457. const char *sep;
  1458. *addr = addr_curr;
  1459. *name = NULL;
  1460. sep = strchr (spec, sepc);
  1461. if (sep) {
  1462. if (sep - spec > 0)
  1463. *addr = simple_strtoul (spec, NULL, 16);
  1464. *name = sep + 1;
  1465. return 1;
  1466. }
  1467. return 0;
  1468. }
  1469. /**
  1470. * fit_parse_conf - parse FIT configuration spec
  1471. * @spec: input string, containing configuration spec
  1472. * @add_curr: current image address (to be used as a possible default)
  1473. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1474. * configuration
  1475. * @conf_name double pointer to a char, will hold pointer to a configuration
  1476. * unit name
  1477. *
  1478. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1479. * where <addr> is a FIT image address that contains configuration
  1480. * with a <conf> unit name.
  1481. *
  1482. * Address part is optional, and if omitted default add_curr will
  1483. * be used instead.
  1484. *
  1485. * returns:
  1486. * 1 if spec is a valid configuration string,
  1487. * addr and conf_name are set accordingly
  1488. * 0 otherwise
  1489. */
  1490. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1491. ulong *addr, const char **conf_name)
  1492. {
  1493. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1494. }
  1495. /**
  1496. * fit_parse_subimage - parse FIT subimage spec
  1497. * @spec: input string, containing subimage spec
  1498. * @add_curr: current image address (to be used as a possible default)
  1499. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1500. * subimage
  1501. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1502. *
  1503. * fit_parse_subimage() expects subimage spec in the for of
  1504. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1505. * subimage with a <subimg> unit name.
  1506. *
  1507. * Address part is optional, and if omitted default add_curr will
  1508. * be used instead.
  1509. *
  1510. * returns:
  1511. * 1 if spec is a valid subimage string,
  1512. * addr and image_name are set accordingly
  1513. * 0 otherwise
  1514. */
  1515. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1516. ulong *addr, const char **image_name)
  1517. {
  1518. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1519. }
  1520. #endif /* !USE_HOSTCC */
  1521. static void fit_get_debug (const void *fit, int noffset,
  1522. char *prop_name, int err)
  1523. {
  1524. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1525. "node: offset %d, name %s (%s)\n",
  1526. prop_name, (ulong)fit, noffset,
  1527. fit_get_name (fit, noffset, NULL),
  1528. fdt_strerror (err));
  1529. }
  1530. /**
  1531. * fit_print_contents - prints out the contents of the FIT format image
  1532. * @fit: pointer to the FIT format image header
  1533. * @p: pointer to prefix string
  1534. *
  1535. * fit_print_contents() formats a multi line FIT image contents description.
  1536. * The routine prints out FIT image properties (root node level) follwed by
  1537. * the details of each component image.
  1538. *
  1539. * returns:
  1540. * no returned results
  1541. */
  1542. void fit_print_contents (const void *fit)
  1543. {
  1544. char *desc;
  1545. char *uname;
  1546. int images_noffset;
  1547. int confs_noffset;
  1548. int noffset;
  1549. int ndepth;
  1550. int count = 0;
  1551. int ret;
  1552. const char *p;
  1553. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1554. time_t timestamp;
  1555. #endif
  1556. #ifdef USE_HOSTCC
  1557. p = "";
  1558. #else
  1559. p = " ";
  1560. #endif
  1561. /* Root node properties */
  1562. ret = fit_get_desc (fit, 0, &desc);
  1563. printf ("%sFIT description: ", p);
  1564. if (ret)
  1565. printf ("unavailable\n");
  1566. else
  1567. printf ("%s\n", desc);
  1568. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1569. ret = fit_get_timestamp (fit, 0, &timestamp);
  1570. printf ("%sCreated: ", p);
  1571. if (ret)
  1572. printf ("unavailable\n");
  1573. else
  1574. genimg_print_time (timestamp);
  1575. #endif
  1576. /* Find images parent node offset */
  1577. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1578. if (images_noffset < 0) {
  1579. printf ("Can't find images parent node '%s' (%s)\n",
  1580. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1581. return;
  1582. }
  1583. /* Process its subnodes, print out component images details */
  1584. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1585. (noffset >= 0) && (ndepth > 0);
  1586. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1587. if (ndepth == 1) {
  1588. /*
  1589. * Direct child node of the images parent node,
  1590. * i.e. component image node.
  1591. */
  1592. printf ("%s Image %u (%s)\n", p, count++,
  1593. fit_get_name(fit, noffset, NULL));
  1594. fit_image_print (fit, noffset, p);
  1595. }
  1596. }
  1597. /* Find configurations parent node offset */
  1598. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1599. if (confs_noffset < 0) {
  1600. debug ("Can't get configurations parent node '%s' (%s)\n",
  1601. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1602. return;
  1603. }
  1604. /* get default configuration unit name from default property */
  1605. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1606. if (uname)
  1607. printf ("%s Default Configuration: '%s'\n", p, uname);
  1608. /* Process its subnodes, print out configurations details */
  1609. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1610. (noffset >= 0) && (ndepth > 0);
  1611. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1612. if (ndepth == 1) {
  1613. /*
  1614. * Direct child node of the configurations parent node,
  1615. * i.e. configuration node.
  1616. */
  1617. printf ("%s Configuration %u (%s)\n", p, count++,
  1618. fit_get_name(fit, noffset, NULL));
  1619. fit_conf_print (fit, noffset, p);
  1620. }
  1621. }
  1622. }
  1623. /**
  1624. * fit_image_print - prints out the FIT component image details
  1625. * @fit: pointer to the FIT format image header
  1626. * @image_noffset: offset of the component image node
  1627. * @p: pointer to prefix string
  1628. *
  1629. * fit_image_print() lists all mandatory properies for the processed component
  1630. * image. If present, hash nodes are printed out as well. Load
  1631. * address for images of type firmware is also printed out. Since the load
  1632. * address is not mandatory for firmware images, it will be output as
  1633. * "unavailable" when not present.
  1634. *
  1635. * returns:
  1636. * no returned results
  1637. */
  1638. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1639. {
  1640. char *desc;
  1641. uint8_t type, arch, os, comp;
  1642. size_t size;
  1643. ulong load, entry;
  1644. const void *data;
  1645. int noffset;
  1646. int ndepth;
  1647. int ret;
  1648. /* Mandatory properties */
  1649. ret = fit_get_desc (fit, image_noffset, &desc);
  1650. printf ("%s Description: ", p);
  1651. if (ret)
  1652. printf ("unavailable\n");
  1653. else
  1654. printf ("%s\n", desc);
  1655. fit_image_get_type (fit, image_noffset, &type);
  1656. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1657. fit_image_get_comp (fit, image_noffset, &comp);
  1658. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1659. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1660. #ifndef USE_HOSTCC
  1661. printf ("%s Data Start: ", p);
  1662. if (ret)
  1663. printf ("unavailable\n");
  1664. else
  1665. printf ("0x%08lx\n", (ulong)data);
  1666. #endif
  1667. printf ("%s Data Size: ", p);
  1668. if (ret)
  1669. printf ("unavailable\n");
  1670. else
  1671. genimg_print_size (size);
  1672. /* Remaining, type dependent properties */
  1673. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1674. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1675. (type == IH_TYPE_FLATDT)) {
  1676. fit_image_get_arch (fit, image_noffset, &arch);
  1677. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1678. }
  1679. if (type == IH_TYPE_KERNEL) {
  1680. fit_image_get_os (fit, image_noffset, &os);
  1681. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1682. }
  1683. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1684. (type == IH_TYPE_FIRMWARE)) {
  1685. ret = fit_image_get_load (fit, image_noffset, &load);
  1686. printf ("%s Load Address: ", p);
  1687. if (ret)
  1688. printf ("unavailable\n");
  1689. else
  1690. printf ("0x%08lx\n", load);
  1691. }
  1692. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1693. fit_image_get_entry (fit, image_noffset, &entry);
  1694. printf ("%s Entry Point: ", p);
  1695. if (ret)
  1696. printf ("unavailable\n");
  1697. else
  1698. printf ("0x%08lx\n", entry);
  1699. }
  1700. /* Process all hash subnodes of the component image node */
  1701. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1702. (noffset >= 0) && (ndepth > 0);
  1703. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1704. if (ndepth == 1) {
  1705. /* Direct child node of the component image node */
  1706. fit_image_print_hash (fit, noffset, p);
  1707. }
  1708. }
  1709. }
  1710. /**
  1711. * fit_image_print_hash - prints out the hash node details
  1712. * @fit: pointer to the FIT format image header
  1713. * @noffset: offset of the hash node
  1714. * @p: pointer to prefix string
  1715. *
  1716. * fit_image_print_hash() lists properies for the processed hash node
  1717. *
  1718. * returns:
  1719. * no returned results
  1720. */
  1721. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1722. {
  1723. char *algo;
  1724. uint8_t *value;
  1725. int value_len;
  1726. int i, ret;
  1727. /*
  1728. * Check subnode name, must be equal to "hash".
  1729. * Multiple hash nodes require unique unit node
  1730. * names, e.g. hash@1, hash@2, etc.
  1731. */
  1732. if (strncmp (fit_get_name(fit, noffset, NULL),
  1733. FIT_HASH_NODENAME,
  1734. strlen(FIT_HASH_NODENAME)) != 0)
  1735. return;
  1736. debug ("%s Hash node: '%s'\n", p,
  1737. fit_get_name (fit, noffset, NULL));
  1738. printf ("%s Hash algo: ", p);
  1739. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1740. printf ("invalid/unsupported\n");
  1741. return;
  1742. }
  1743. printf ("%s\n", algo);
  1744. ret = fit_image_hash_get_value (fit, noffset, &value,
  1745. &value_len);
  1746. printf ("%s Hash value: ", p);
  1747. if (ret) {
  1748. printf ("unavailable\n");
  1749. } else {
  1750. for (i = 0; i < value_len; i++)
  1751. printf ("%02x", value[i]);
  1752. printf ("\n");
  1753. }
  1754. debug ("%s Hash len: %d\n", p, value_len);
  1755. }
  1756. /**
  1757. * fit_get_desc - get node description property
  1758. * @fit: pointer to the FIT format image header
  1759. * @noffset: node offset
  1760. * @desc: double pointer to the char, will hold pointer to the descrption
  1761. *
  1762. * fit_get_desc() reads description property from a given node, if
  1763. * description is found pointer to it is returened in third call argument.
  1764. *
  1765. * returns:
  1766. * 0, on success
  1767. * -1, on failure
  1768. */
  1769. int fit_get_desc (const void *fit, int noffset, char **desc)
  1770. {
  1771. int len;
  1772. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1773. if (*desc == NULL) {
  1774. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1775. return -1;
  1776. }
  1777. return 0;
  1778. }
  1779. /**
  1780. * fit_get_timestamp - get node timestamp property
  1781. * @fit: pointer to the FIT format image header
  1782. * @noffset: node offset
  1783. * @timestamp: pointer to the time_t, will hold read timestamp
  1784. *
  1785. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1786. * is found and has a correct size its value is retured in third call
  1787. * argument.
  1788. *
  1789. * returns:
  1790. * 0, on success
  1791. * -1, on property read failure
  1792. * -2, on wrong timestamp size
  1793. */
  1794. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1795. {
  1796. int len;
  1797. const void *data;
  1798. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1799. if (data == NULL) {
  1800. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1801. return -1;
  1802. }
  1803. if (len != sizeof (uint32_t)) {
  1804. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1805. return -2;
  1806. }
  1807. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1808. return 0;
  1809. }
  1810. /**
  1811. * fit_image_get_node - get node offset for component image of a given unit name
  1812. * @fit: pointer to the FIT format image header
  1813. * @image_uname: component image node unit name
  1814. *
  1815. * fit_image_get_node() finds a component image (withing the '/images'
  1816. * node) of a provided unit name. If image is found its node offset is
  1817. * returned to the caller.
  1818. *
  1819. * returns:
  1820. * image node offset when found (>=0)
  1821. * negative number on failure (FDT_ERR_* code)
  1822. */
  1823. int fit_image_get_node (const void *fit, const char *image_uname)
  1824. {
  1825. int noffset, images_noffset;
  1826. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1827. if (images_noffset < 0) {
  1828. debug ("Can't find images parent node '%s' (%s)\n",
  1829. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1830. return images_noffset;
  1831. }
  1832. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1833. if (noffset < 0) {
  1834. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1835. image_uname, fdt_strerror (noffset));
  1836. }
  1837. return noffset;
  1838. }
  1839. /**
  1840. * fit_image_get_os - get os id for a given component image node
  1841. * @fit: pointer to the FIT format image header
  1842. * @noffset: component image node offset
  1843. * @os: pointer to the uint8_t, will hold os numeric id
  1844. *
  1845. * fit_image_get_os() finds os property in a given component image node.
  1846. * If the property is found, its (string) value is translated to the numeric
  1847. * id which is returned to the caller.
  1848. *
  1849. * returns:
  1850. * 0, on success
  1851. * -1, on failure
  1852. */
  1853. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1854. {
  1855. int len;
  1856. const void *data;
  1857. /* Get OS name from property data */
  1858. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1859. if (data == NULL) {
  1860. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1861. *os = -1;
  1862. return -1;
  1863. }
  1864. /* Translate OS name to id */
  1865. *os = genimg_get_os_id (data);
  1866. return 0;
  1867. }
  1868. /**
  1869. * fit_image_get_arch - get arch id for a given component image node
  1870. * @fit: pointer to the FIT format image header
  1871. * @noffset: component image node offset
  1872. * @arch: pointer to the uint8_t, will hold arch numeric id
  1873. *
  1874. * fit_image_get_arch() finds arch property in a given component image node.
  1875. * If the property is found, its (string) value is translated to the numeric
  1876. * id which is returned to the caller.
  1877. *
  1878. * returns:
  1879. * 0, on success
  1880. * -1, on failure
  1881. */
  1882. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1883. {
  1884. int len;
  1885. const void *data;
  1886. /* Get architecture name from property data */
  1887. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1888. if (data == NULL) {
  1889. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1890. *arch = -1;
  1891. return -1;
  1892. }
  1893. /* Translate architecture name to id */
  1894. *arch = genimg_get_arch_id (data);
  1895. return 0;
  1896. }
  1897. /**
  1898. * fit_image_get_type - get type id for a given component image node
  1899. * @fit: pointer to the FIT format image header
  1900. * @noffset: component image node offset
  1901. * @type: pointer to the uint8_t, will hold type numeric id
  1902. *
  1903. * fit_image_get_type() finds type property in a given component image node.
  1904. * If the property is found, its (string) value is translated to the numeric
  1905. * id which is returned to the caller.
  1906. *
  1907. * returns:
  1908. * 0, on success
  1909. * -1, on failure
  1910. */
  1911. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1912. {
  1913. int len;
  1914. const void *data;
  1915. /* Get image type name from property data */
  1916. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1917. if (data == NULL) {
  1918. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1919. *type = -1;
  1920. return -1;
  1921. }
  1922. /* Translate image type name to id */
  1923. *type = genimg_get_type_id (data);
  1924. return 0;
  1925. }
  1926. /**
  1927. * fit_image_get_comp - get comp id for a given component image node
  1928. * @fit: pointer to the FIT format image header
  1929. * @noffset: component image node offset
  1930. * @comp: pointer to the uint8_t, will hold comp numeric id
  1931. *
  1932. * fit_image_get_comp() finds comp property in a given component image node.
  1933. * If the property is found, its (string) value is translated to the numeric
  1934. * id which is returned to the caller.
  1935. *
  1936. * returns:
  1937. * 0, on success
  1938. * -1, on failure
  1939. */
  1940. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1941. {
  1942. int len;
  1943. const void *data;
  1944. /* Get compression name from property data */
  1945. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1946. if (data == NULL) {
  1947. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1948. *comp = -1;
  1949. return -1;
  1950. }
  1951. /* Translate compression name to id */
  1952. *comp = genimg_get_comp_id (data);
  1953. return 0;
  1954. }
  1955. /**
  1956. * fit_image_get_load - get load address property for a given component image node
  1957. * @fit: pointer to the FIT format image header
  1958. * @noffset: component image node offset
  1959. * @load: pointer to the uint32_t, will hold load address
  1960. *
  1961. * fit_image_get_load() finds load address property in a given component image node.
  1962. * If the property is found, its value is returned to the caller.
  1963. *
  1964. * returns:
  1965. * 0, on success
  1966. * -1, on failure
  1967. */
  1968. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1969. {
  1970. int len;
  1971. const uint32_t *data;
  1972. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1973. if (data == NULL) {
  1974. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1975. return -1;
  1976. }
  1977. *load = uimage_to_cpu (*data);
  1978. return 0;
  1979. }
  1980. /**
  1981. * fit_image_get_entry - get entry point address property for a given component image node
  1982. * @fit: pointer to the FIT format image header
  1983. * @noffset: component image node offset
  1984. * @entry: pointer to the uint32_t, will hold entry point address
  1985. *
  1986. * fit_image_get_entry() finds entry point address property in a given component image node.
  1987. * If the property is found, its value is returned to the caller.
  1988. *
  1989. * returns:
  1990. * 0, on success
  1991. * -1, on failure
  1992. */
  1993. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  1994. {
  1995. int len;
  1996. const uint32_t *data;
  1997. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  1998. if (data == NULL) {
  1999. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  2000. return -1;
  2001. }
  2002. *entry = uimage_to_cpu (*data);
  2003. return 0;
  2004. }
  2005. /**
  2006. * fit_image_get_data - get data property and its size for a given component image node
  2007. * @fit: pointer to the FIT format image header
  2008. * @noffset: component image node offset
  2009. * @data: double pointer to void, will hold data property's data address
  2010. * @size: pointer to size_t, will hold data property's data size
  2011. *
  2012. * fit_image_get_data() finds data property in a given component image node.
  2013. * If the property is found its data start address and size are returned to
  2014. * the caller.
  2015. *
  2016. * returns:
  2017. * 0, on success
  2018. * -1, on failure
  2019. */
  2020. int fit_image_get_data (const void *fit, int noffset,
  2021. const void **data, size_t *size)
  2022. {
  2023. int len;
  2024. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  2025. if (*data == NULL) {
  2026. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  2027. *size = 0;
  2028. return -1;
  2029. }
  2030. *size = len;
  2031. return 0;
  2032. }
  2033. /**
  2034. * fit_image_hash_get_algo - get hash algorithm name
  2035. * @fit: pointer to the FIT format image header
  2036. * @noffset: hash node offset
  2037. * @algo: double pointer to char, will hold pointer to the algorithm name
  2038. *
  2039. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  2040. * If the property is found its data start address is returned to the caller.
  2041. *
  2042. * returns:
  2043. * 0, on success
  2044. * -1, on failure
  2045. */
  2046. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  2047. {
  2048. int len;
  2049. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  2050. if (*algo == NULL) {
  2051. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  2052. return -1;
  2053. }
  2054. return 0;
  2055. }
  2056. /**
  2057. * fit_image_hash_get_value - get hash value and length
  2058. * @fit: pointer to the FIT format image header
  2059. * @noffset: hash node offset
  2060. * @value: double pointer to uint8_t, will hold address of a hash value data
  2061. * @value_len: pointer to an int, will hold hash data length
  2062. *
  2063. * fit_image_hash_get_value() finds hash value property in a given hash node.
  2064. * If the property is found its data start address and size are returned to
  2065. * the caller.
  2066. *
  2067. * returns:
  2068. * 0, on success
  2069. * -1, on failure
  2070. */
  2071. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  2072. int *value_len)
  2073. {
  2074. int len;
  2075. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  2076. if (*value == NULL) {
  2077. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  2078. *value_len = 0;
  2079. return -1;
  2080. }
  2081. *value_len = len;
  2082. return 0;
  2083. }
  2084. /**
  2085. * fit_set_timestamp - set node timestamp property
  2086. * @fit: pointer to the FIT format image header
  2087. * @noffset: node offset
  2088. * @timestamp: timestamp value to be set
  2089. *
  2090. * fit_set_timestamp() attempts to set timestamp property in the requested
  2091. * node and returns operation status to the caller.
  2092. *
  2093. * returns:
  2094. * 0, on success
  2095. * -1, on property read failure
  2096. */
  2097. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  2098. {
  2099. uint32_t t;
  2100. int ret;
  2101. t = cpu_to_uimage (timestamp);
  2102. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  2103. sizeof (uint32_t));
  2104. if (ret) {
  2105. printf ("Can't set '%s' property for '%s' node (%s)\n",
  2106. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  2107. fdt_strerror (ret));
  2108. return -1;
  2109. }
  2110. return 0;
  2111. }
  2112. /**
  2113. * calculate_hash - calculate and return hash for provided input data
  2114. * @data: pointer to the input data
  2115. * @data_len: data length
  2116. * @algo: requested hash algorithm
  2117. * @value: pointer to the char, will hold hash value data (caller must
  2118. * allocate enough free space)
  2119. * value_len: length of the calculated hash
  2120. *
  2121. * calculate_hash() computes input data hash according to the requested algorithm.
  2122. * Resulting hash value is placed in caller provided 'value' buffer, length
  2123. * of the calculated hash is returned via value_len pointer argument.
  2124. *
  2125. * returns:
  2126. * 0, on success
  2127. * -1, when algo is unsupported
  2128. */
  2129. static int calculate_hash (const void *data, int data_len, const char *algo,
  2130. uint8_t *value, int *value_len)
  2131. {
  2132. if (strcmp (algo, "crc32") == 0 ) {
  2133. *((uint32_t *)value) = crc32_wd (0, data, data_len,
  2134. CHUNKSZ_CRC32);
  2135. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  2136. *value_len = 4;
  2137. } else if (strcmp (algo, "sha1") == 0 ) {
  2138. sha1_csum_wd ((unsigned char *) data, data_len,
  2139. (unsigned char *) value, CHUNKSZ_SHA1);
  2140. *value_len = 20;
  2141. } else if (strcmp (algo, "md5") == 0 ) {
  2142. md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  2143. *value_len = 16;
  2144. } else {
  2145. debug ("Unsupported hash alogrithm\n");
  2146. return -1;
  2147. }
  2148. return 0;
  2149. }
  2150. #ifdef USE_HOSTCC
  2151. /**
  2152. * fit_set_hashes - process FIT component image nodes and calculate hashes
  2153. * @fit: pointer to the FIT format image header
  2154. *
  2155. * fit_set_hashes() adds hash values for all component images in the FIT blob.
  2156. * Hashes are calculated for all component images which have hash subnodes
  2157. * with algorithm property set to one of the supported hash algorithms.
  2158. *
  2159. * returns
  2160. * 0, on success
  2161. * libfdt error code, on failure
  2162. */
  2163. int fit_set_hashes (void *fit)
  2164. {
  2165. int images_noffset;
  2166. int noffset;
  2167. int ndepth;
  2168. int ret;
  2169. /* Find images parent node offset */
  2170. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  2171. if (images_noffset < 0) {
  2172. printf ("Can't find images parent node '%s' (%s)\n",
  2173. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  2174. return images_noffset;
  2175. }
  2176. /* Process its subnodes, print out component images details */
  2177. for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  2178. (noffset >= 0) && (ndepth > 0);
  2179. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2180. if (ndepth == 1) {
  2181. /*
  2182. * Direct child node of the images parent node,
  2183. * i.e. component image node.
  2184. */
  2185. ret = fit_image_set_hashes (fit, noffset);
  2186. if (ret)
  2187. return ret;
  2188. }
  2189. }
  2190. return 0;
  2191. }
  2192. /**
  2193. * fit_image_set_hashes - calculate/set hashes for given component image node
  2194. * @fit: pointer to the FIT format image header
  2195. * @image_noffset: requested component image node
  2196. *
  2197. * fit_image_set_hashes() adds hash values for an component image node. All
  2198. * existing hash subnodes are checked, if algorithm property is set to one of
  2199. * the supported hash algorithms, hash value is computed and corresponding
  2200. * hash node property is set, for example:
  2201. *
  2202. * Input component image node structure:
  2203. *
  2204. * o image@1 (at image_noffset)
  2205. * | - data = [binary data]
  2206. * o hash@1
  2207. * |- algo = "sha1"
  2208. *
  2209. * Output component image node structure:
  2210. *
  2211. * o image@1 (at image_noffset)
  2212. * | - data = [binary data]
  2213. * o hash@1
  2214. * |- algo = "sha1"
  2215. * |- value = sha1(data)
  2216. *
  2217. * returns:
  2218. * 0 on sucess
  2219. * <0 on failure
  2220. */
  2221. int fit_image_set_hashes (void *fit, int image_noffset)
  2222. {
  2223. const void *data;
  2224. size_t size;
  2225. char *algo;
  2226. uint8_t value[FIT_MAX_HASH_LEN];
  2227. int value_len;
  2228. int noffset;
  2229. int ndepth;
  2230. /* Get image data and data length */
  2231. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  2232. printf ("Can't get image data/size\n");
  2233. return -1;
  2234. }
  2235. /* Process all hash subnodes of the component image node */
  2236. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  2237. (noffset >= 0) && (ndepth > 0);
  2238. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2239. if (ndepth == 1) {
  2240. /* Direct child node of the component image node */
  2241. /*
  2242. * Check subnode name, must be equal to "hash".
  2243. * Multiple hash nodes require unique unit node
  2244. * names, e.g. hash@1, hash@2, etc.
  2245. */
  2246. if (strncmp (fit_get_name(fit, noffset, NULL),
  2247. FIT_HASH_NODENAME,
  2248. strlen(FIT_HASH_NODENAME)) != 0) {
  2249. /* Not a hash subnode, skip it */
  2250. continue;
  2251. }
  2252. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  2253. printf ("Can't get hash algo property for "
  2254. "'%s' hash node in '%s' image node\n",
  2255. fit_get_name (fit, noffset, NULL),
  2256. fit_get_name (fit, image_noffset, NULL));
  2257. return -1;
  2258. }
  2259. if (calculate_hash (data, size, algo, value, &value_len)) {
  2260. printf ("Unsupported hash algorithm (%s) for "
  2261. "'%s' hash node in '%s' image node\n",
  2262. algo, fit_get_name (fit, noffset, NULL),
  2263. fit_get_name (fit, image_noffset, NULL));
  2264. return -1;
  2265. }
  2266. if (fit_image_hash_set_value (fit, noffset, value,
  2267. value_len)) {
  2268. printf ("Can't set hash value for "
  2269. "'%s' hash node in '%s' image node\n",
  2270. fit_get_name (fit, noffset, NULL),
  2271. fit_get_name (fit, image_noffset, NULL));
  2272. return -1;
  2273. }
  2274. }
  2275. }
  2276. return 0;
  2277. }
  2278. /**
  2279. * fit_image_hash_set_value - set hash value in requested has node
  2280. * @fit: pointer to the FIT format image header
  2281. * @noffset: hash node offset
  2282. * @value: hash value to be set
  2283. * @value_len: hash value length
  2284. *
  2285. * fit_image_hash_set_value() attempts to set hash value in a node at offset
  2286. * given and returns operation status to the caller.
  2287. *
  2288. * returns
  2289. * 0, on success
  2290. * -1, on failure
  2291. */
  2292. int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
  2293. int value_len)
  2294. {
  2295. int ret;
  2296. ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
  2297. if (ret) {
  2298. printf ("Can't set hash '%s' property for '%s' node (%s)\n",
  2299. FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
  2300. fdt_strerror (ret));
  2301. return -1;
  2302. }
  2303. return 0;
  2304. }
  2305. #endif /* USE_HOSTCC */
  2306. /**
  2307. * fit_image_check_hashes - verify data intergity
  2308. * @fit: pointer to the FIT format image header
  2309. * @image_noffset: component image node offset
  2310. *
  2311. * fit_image_check_hashes() goes over component image hash nodes,
  2312. * re-calculates each data hash and compares with the value stored in hash
  2313. * node.
  2314. *
  2315. * returns:
  2316. * 1, if all hashes are valid
  2317. * 0, otherwise (or on error)
  2318. */
  2319. int fit_image_check_hashes (const void *fit, int image_noffset)
  2320. {
  2321. const void *data;
  2322. size_t size;
  2323. char *algo;
  2324. uint8_t *fit_value;
  2325. int fit_value_len;
  2326. uint8_t value[FIT_MAX_HASH_LEN];
  2327. int value_len;
  2328. int noffset;
  2329. int ndepth;
  2330. char *err_msg = "";
  2331. /* Get image data and data length */
  2332. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  2333. printf ("Can't get image data/size\n");
  2334. return 0;
  2335. }
  2336. /* Process all hash subnodes of the component image node */
  2337. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  2338. (noffset >= 0) && (ndepth > 0);
  2339. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2340. if (ndepth == 1) {
  2341. /* Direct child node of the component image node */
  2342. /*
  2343. * Check subnode name, must be equal to "hash".
  2344. * Multiple hash nodes require unique unit node
  2345. * names, e.g. hash@1, hash@2, etc.
  2346. */
  2347. if (strncmp (fit_get_name(fit, noffset, NULL),
  2348. FIT_HASH_NODENAME,
  2349. strlen(FIT_HASH_NODENAME)) != 0)
  2350. continue;
  2351. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  2352. err_msg = " error!\nCan't get hash algo "
  2353. "property";
  2354. goto error;
  2355. }
  2356. printf ("%s", algo);
  2357. if (fit_image_hash_get_value (fit, noffset, &fit_value,
  2358. &fit_value_len)) {
  2359. err_msg = " error!\nCan't get hash value "
  2360. "property";
  2361. goto error;
  2362. }
  2363. if (calculate_hash (data, size, algo, value, &value_len)) {
  2364. err_msg = " error!\nUnsupported hash algorithm";
  2365. goto error;
  2366. }
  2367. if (value_len != fit_value_len) {
  2368. err_msg = " error !\nBad hash value len";
  2369. goto error;
  2370. } else if (memcmp (value, fit_value, value_len) != 0) {
  2371. err_msg = " error!\nBad hash value";
  2372. goto error;
  2373. }
  2374. printf ("+ ");
  2375. }
  2376. }
  2377. return 1;
  2378. error:
  2379. printf ("%s for '%s' hash node in '%s' image node\n",
  2380. err_msg, fit_get_name (fit, noffset, NULL),
  2381. fit_get_name (fit, image_noffset, NULL));
  2382. return 0;
  2383. }
  2384. /**
  2385. * fit_all_image_check_hashes - verify data intergity for all images
  2386. * @fit: pointer to the FIT format image header
  2387. *
  2388. * fit_all_image_check_hashes() goes over all images in the FIT and
  2389. * for every images checks if all it's hashes are valid.
  2390. *
  2391. * returns:
  2392. * 1, if all hashes of all images are valid
  2393. * 0, otherwise (or on error)
  2394. */
  2395. int fit_all_image_check_hashes (const void *fit)
  2396. {
  2397. int images_noffset;
  2398. int noffset;
  2399. int ndepth;
  2400. int count;
  2401. /* Find images parent node offset */
  2402. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  2403. if (images_noffset < 0) {
  2404. printf ("Can't find images parent node '%s' (%s)\n",
  2405. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  2406. return 0;
  2407. }
  2408. /* Process all image subnodes, check hashes for each */
  2409. printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
  2410. (ulong)fit);
  2411. for (ndepth = 0, count = 0,
  2412. noffset = fdt_next_node (fit, images_noffset, &ndepth);
  2413. (noffset >= 0) && (ndepth > 0);
  2414. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2415. if (ndepth == 1) {
  2416. /*
  2417. * Direct child node of the images parent node,
  2418. * i.e. component image node.
  2419. */
  2420. printf (" Hash(es) for Image %u (%s): ", count++,
  2421. fit_get_name (fit, noffset, NULL));
  2422. if (!fit_image_check_hashes (fit, noffset))
  2423. return 0;
  2424. printf ("\n");
  2425. }
  2426. }
  2427. return 1;
  2428. }
  2429. /**
  2430. * fit_image_check_os - check whether image node is of a given os type
  2431. * @fit: pointer to the FIT format image header
  2432. * @noffset: component image node offset
  2433. * @os: requested image os
  2434. *
  2435. * fit_image_check_os() reads image os property and compares its numeric
  2436. * id with the requested os. Comparison result is returned to the caller.
  2437. *
  2438. * returns:
  2439. * 1 if image is of given os type
  2440. * 0 otherwise (or on error)
  2441. */
  2442. int fit_image_check_os (const void *fit, int noffset, uint8_t os)
  2443. {
  2444. uint8_t image_os;
  2445. if (fit_image_get_os (fit, noffset, &image_os))
  2446. return 0;
  2447. return (os == image_os);
  2448. }
  2449. /**
  2450. * fit_image_check_arch - check whether image node is of a given arch
  2451. * @fit: pointer to the FIT format image header
  2452. * @noffset: component image node offset
  2453. * @arch: requested imagearch
  2454. *
  2455. * fit_image_check_arch() reads image arch property and compares its numeric
  2456. * id with the requested arch. Comparison result is returned to the caller.
  2457. *
  2458. * returns:
  2459. * 1 if image is of given arch
  2460. * 0 otherwise (or on error)
  2461. */
  2462. int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
  2463. {
  2464. uint8_t image_arch;
  2465. if (fit_image_get_arch (fit, noffset, &image_arch))
  2466. return 0;
  2467. return (arch == image_arch);
  2468. }
  2469. /**
  2470. * fit_image_check_type - check whether image node is of a given type
  2471. * @fit: pointer to the FIT format image header
  2472. * @noffset: component image node offset
  2473. * @type: requested image type
  2474. *
  2475. * fit_image_check_type() reads image type property and compares its numeric
  2476. * id with the requested type. Comparison result is returned to the caller.
  2477. *
  2478. * returns:
  2479. * 1 if image is of given type
  2480. * 0 otherwise (or on error)
  2481. */
  2482. int fit_image_check_type (const void *fit, int noffset, uint8_t type)
  2483. {
  2484. uint8_t image_type;
  2485. if (fit_image_get_type (fit, noffset, &image_type))
  2486. return 0;
  2487. return (type == image_type);
  2488. }
  2489. /**
  2490. * fit_image_check_comp - check whether image node uses given compression
  2491. * @fit: pointer to the FIT format image header
  2492. * @noffset: component image node offset
  2493. * @comp: requested image compression type
  2494. *
  2495. * fit_image_check_comp() reads image compression property and compares its
  2496. * numeric id with the requested compression type. Comparison result is
  2497. * returned to the caller.
  2498. *
  2499. * returns:
  2500. * 1 if image uses requested compression
  2501. * 0 otherwise (or on error)
  2502. */
  2503. int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
  2504. {
  2505. uint8_t image_comp;
  2506. if (fit_image_get_comp (fit, noffset, &image_comp))
  2507. return 0;
  2508. return (comp == image_comp);
  2509. }
  2510. /**
  2511. * fit_check_format - sanity check FIT image format
  2512. * @fit: pointer to the FIT format image header
  2513. *
  2514. * fit_check_format() runs a basic sanity FIT image verification.
  2515. * Routine checks for mandatory properties, nodes, etc.
  2516. *
  2517. * returns:
  2518. * 1, on success
  2519. * 0, on failure
  2520. */
  2521. int fit_check_format (const void *fit)
  2522. {
  2523. /* mandatory / node 'description' property */
  2524. if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  2525. debug ("Wrong FIT format: no description\n");
  2526. return 0;
  2527. }
  2528. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  2529. /* mandatory / node 'timestamp' property */
  2530. if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  2531. debug ("Wrong FIT format: no timestamp\n");
  2532. return 0;
  2533. }
  2534. #endif
  2535. /* mandatory subimages parent '/images' node */
  2536. if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
  2537. debug ("Wrong FIT format: no images parent node\n");
  2538. return 0;
  2539. }
  2540. return 1;
  2541. }
  2542. /**
  2543. * fit_conf_get_node - get node offset for configuration of a given unit name
  2544. * @fit: pointer to the FIT format image header
  2545. * @conf_uname: configuration node unit name
  2546. *
  2547. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  2548. * parant node) of a provided unit name. If configuration is found its node offset
  2549. * is returned to the caller.
  2550. *
  2551. * When NULL is provided in second argument fit_conf_get_node() will search
  2552. * for a default configuration node instead. Default configuration node unit name
  2553. * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
  2554. *
  2555. * returns:
  2556. * configuration node offset when found (>=0)
  2557. * negative number on failure (FDT_ERR_* code)
  2558. */
  2559. int fit_conf_get_node (const void *fit, const char *conf_uname)
  2560. {
  2561. int noffset, confs_noffset;
  2562. int len;
  2563. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  2564. if (confs_noffset < 0) {
  2565. debug ("Can't find configurations parent node '%s' (%s)\n",
  2566. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  2567. return confs_noffset;
  2568. }
  2569. if (conf_uname == NULL) {
  2570. /* get configuration unit name from the default property */
  2571. debug ("No configuration specified, trying default...\n");
  2572. conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
  2573. if (conf_uname == NULL) {
  2574. fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
  2575. return len;
  2576. }
  2577. debug ("Found default configuration: '%s'\n", conf_uname);
  2578. }
  2579. noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
  2580. if (noffset < 0) {
  2581. debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
  2582. conf_uname, fdt_strerror (noffset));
  2583. }
  2584. return noffset;
  2585. }
  2586. static int __fit_conf_get_prop_node (const void *fit, int noffset,
  2587. const char *prop_name)
  2588. {
  2589. char *uname;
  2590. int len;
  2591. /* get kernel image unit name from configuration kernel property */
  2592. uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
  2593. if (uname == NULL)
  2594. return len;
  2595. return fit_image_get_node (fit, uname);
  2596. }
  2597. /**
  2598. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  2599. * a given configuration
  2600. * @fit: pointer to the FIT format image header
  2601. * @noffset: configuration node offset
  2602. *
  2603. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  2604. * configuration FIT_KERNEL_PROP property and translates it to the node
  2605. * offset.
  2606. *
  2607. * returns:
  2608. * image node offset when found (>=0)
  2609. * negative number on failure (FDT_ERR_* code)
  2610. */
  2611. int fit_conf_get_kernel_node (const void *fit, int noffset)
  2612. {
  2613. return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
  2614. }
  2615. /**
  2616. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  2617. * a given configuration
  2618. * @fit: pointer to the FIT format image header
  2619. * @noffset: configuration node offset
  2620. *
  2621. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  2622. * configuration FIT_KERNEL_PROP property and translates it to the node
  2623. * offset.
  2624. *
  2625. * returns:
  2626. * image node offset when found (>=0)
  2627. * negative number on failure (FDT_ERR_* code)
  2628. */
  2629. int fit_conf_get_ramdisk_node (const void *fit, int noffset)
  2630. {
  2631. return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
  2632. }
  2633. /**
  2634. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  2635. * a given configuration
  2636. * @fit: pointer to the FIT format image header
  2637. * @noffset: configuration node offset
  2638. *
  2639. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  2640. * configuration FIT_KERNEL_PROP property and translates it to the node
  2641. * offset.
  2642. *
  2643. * returns:
  2644. * image node offset when found (>=0)
  2645. * negative number on failure (FDT_ERR_* code)
  2646. */
  2647. int fit_conf_get_fdt_node (const void *fit, int noffset)
  2648. {
  2649. return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
  2650. }
  2651. /**
  2652. * fit_conf_print - prints out the FIT configuration details
  2653. * @fit: pointer to the FIT format image header
  2654. * @noffset: offset of the configuration node
  2655. * @p: pointer to prefix string
  2656. *
  2657. * fit_conf_print() lists all mandatory properies for the processed
  2658. * configuration node.
  2659. *
  2660. * returns:
  2661. * no returned results
  2662. */
  2663. void fit_conf_print (const void *fit, int noffset, const char *p)
  2664. {
  2665. char *desc;
  2666. char *uname;
  2667. int ret;
  2668. /* Mandatory properties */
  2669. ret = fit_get_desc (fit, noffset, &desc);
  2670. printf ("%s Description: ", p);
  2671. if (ret)
  2672. printf ("unavailable\n");
  2673. else
  2674. printf ("%s\n", desc);
  2675. uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
  2676. printf ("%s Kernel: ", p);
  2677. if (uname == NULL)
  2678. printf ("unavailable\n");
  2679. else
  2680. printf ("%s\n", uname);
  2681. /* Optional properties */
  2682. uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
  2683. if (uname)
  2684. printf ("%s Init Ramdisk: %s\n", p, uname);
  2685. uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
  2686. if (uname)
  2687. printf ("%s FDT: %s\n", p, uname);
  2688. }
  2689. /**
  2690. * fit_check_ramdisk - verify FIT format ramdisk subimage
  2691. * @fit_hdr: pointer to the FIT ramdisk header
  2692. * @rd_noffset: ramdisk subimage node offset within FIT image
  2693. * @arch: requested ramdisk image architecture type
  2694. * @verify: data CRC verification flag
  2695. *
  2696. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  2697. * specified FIT image.
  2698. *
  2699. * returns:
  2700. * 1, on success
  2701. * 0, on failure
  2702. */
  2703. #ifndef USE_HOSTCC
  2704. static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
  2705. {
  2706. fit_image_print (fit, rd_noffset, " ");
  2707. if (verify) {
  2708. puts (" Verifying Hash Integrity ... ");
  2709. if (!fit_image_check_hashes (fit, rd_noffset)) {
  2710. puts ("Bad Data Hash\n");
  2711. show_boot_progress (-125);
  2712. return 0;
  2713. }
  2714. puts ("OK\n");
  2715. }
  2716. show_boot_progress (126);
  2717. if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
  2718. !fit_image_check_arch (fit, rd_noffset, arch) ||
  2719. !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
  2720. printf ("No Linux %s Ramdisk Image\n",
  2721. genimg_get_arch_name(arch));
  2722. show_boot_progress (-126);
  2723. return 0;
  2724. }
  2725. show_boot_progress (127);
  2726. return 1;
  2727. }
  2728. #endif /* USE_HOSTCC */
  2729. #endif /* CONFIG_FIT */