image.c 84 KB

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