image.c 83 KB

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