image.c 83 KB

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