image.c 68 KB

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