image.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509
  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. /* Prevent initrd from overwriting logbuffer */
  905. lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
  906. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  907. initrd_high, initrd_copy_to_ram);
  908. if (rd_data) {
  909. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  910. debug (" in-place initrd\n");
  911. *initrd_start = rd_data;
  912. *initrd_end = rd_data + rd_len;
  913. lmb_reserve(lmb, rd_data, rd_len);
  914. } else {
  915. if (initrd_high)
  916. *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
  917. else
  918. *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
  919. if (*initrd_start == 0) {
  920. puts ("ramdisk - allocation error\n");
  921. goto error;
  922. }
  923. show_boot_progress (12);
  924. *initrd_end = *initrd_start + rd_len;
  925. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  926. *initrd_start, *initrd_end);
  927. memmove_wd ((void *)*initrd_start,
  928. (void *)rd_data, rd_len, CHUNKSZ);
  929. puts ("OK\n");
  930. }
  931. } else {
  932. *initrd_start = 0;
  933. *initrd_end = 0;
  934. }
  935. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  936. *initrd_start, *initrd_end);
  937. return 0;
  938. error:
  939. return -1;
  940. }
  941. /**
  942. * boot_get_cmdline - allocate and initialize kernel cmdline
  943. * @lmb: pointer to lmb handle, will be used for memory mgmt
  944. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  945. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  946. * @bootmap_base: ulong variable, holds offset in physical memory to
  947. * base of bootmap
  948. *
  949. * boot_get_cmdline() allocates space for kernel command line below
  950. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  951. * variable is present its contents is copied to allocated kernel
  952. * command line.
  953. *
  954. * returns:
  955. * 0 - success
  956. * -1 - failure
  957. */
  958. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  959. ulong bootmap_base)
  960. {
  961. char *cmdline;
  962. char *s;
  963. cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
  964. CFG_BOOTMAPSZ + bootmap_base);
  965. if (cmdline == NULL)
  966. return -1;
  967. if ((s = getenv("bootargs")) == NULL)
  968. s = "";
  969. strcpy(cmdline, s);
  970. *cmd_start = (ulong) & cmdline[0];
  971. *cmd_end = *cmd_start + strlen(cmdline);
  972. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  973. return 0;
  974. }
  975. /**
  976. * boot_get_kbd - allocate and initialize kernel copy of board info
  977. * @lmb: pointer to lmb handle, will be used for memory mgmt
  978. * @kbd: double pointer to board info data
  979. * @bootmap_base: ulong variable, holds offset in physical memory to
  980. * base of bootmap
  981. *
  982. * boot_get_kbd() allocates space for kernel copy of board info data below
  983. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  984. * the current u-boot board info data.
  985. *
  986. * returns:
  987. * 0 - success
  988. * -1 - failure
  989. */
  990. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  991. {
  992. *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  993. CFG_BOOTMAPSZ + bootmap_base);
  994. if (*kbd == NULL)
  995. return -1;
  996. **kbd = *(gd->bd);
  997. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  998. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  999. do_bdinfo(NULL, 0, 0, NULL);
  1000. #endif
  1001. return 0;
  1002. }
  1003. #endif /* CONFIG_PPC || CONFIG_M68K */
  1004. #endif /* !USE_HOSTCC */
  1005. #if defined(CONFIG_FIT)
  1006. /*****************************************************************************/
  1007. /* New uImage format routines */
  1008. /*****************************************************************************/
  1009. #ifndef USE_HOSTCC
  1010. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1011. ulong *addr, const char **name)
  1012. {
  1013. const char *sep;
  1014. *addr = addr_curr;
  1015. *name = NULL;
  1016. sep = strchr (spec, sepc);
  1017. if (sep) {
  1018. if (sep - spec > 0)
  1019. *addr = simple_strtoul (spec, NULL, 16);
  1020. *name = sep + 1;
  1021. return 1;
  1022. }
  1023. return 0;
  1024. }
  1025. /**
  1026. * fit_parse_conf - parse FIT configuration spec
  1027. * @spec: input string, containing configuration spec
  1028. * @add_curr: current image address (to be used as a possible default)
  1029. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1030. * configuration
  1031. * @conf_name double pointer to a char, will hold pointer to a configuration
  1032. * unit name
  1033. *
  1034. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1035. * where <addr> is a FIT image address that contains configuration
  1036. * with a <conf> unit name.
  1037. *
  1038. * Address part is optional, and if omitted default add_curr will
  1039. * be used instead.
  1040. *
  1041. * returns:
  1042. * 1 if spec is a valid configuration string,
  1043. * addr and conf_name are set accordingly
  1044. * 0 otherwise
  1045. */
  1046. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1047. ulong *addr, const char **conf_name)
  1048. {
  1049. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1050. }
  1051. /**
  1052. * fit_parse_subimage - parse FIT subimage spec
  1053. * @spec: input string, containing subimage spec
  1054. * @add_curr: current image address (to be used as a possible default)
  1055. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1056. * subimage
  1057. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1058. *
  1059. * fit_parse_subimage() expects subimage spec in the for of
  1060. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1061. * subimage with a <subimg> unit name.
  1062. *
  1063. * Address part is optional, and if omitted default add_curr will
  1064. * be used instead.
  1065. *
  1066. * returns:
  1067. * 1 if spec is a valid subimage string,
  1068. * addr and image_name are set accordingly
  1069. * 0 otherwise
  1070. */
  1071. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1072. ulong *addr, const char **image_name)
  1073. {
  1074. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1075. }
  1076. #endif /* !USE_HOSTCC */
  1077. static void fit_get_debug (const void *fit, int noffset,
  1078. char *prop_name, int err)
  1079. {
  1080. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1081. "node: offset %d, name %s (%s)\n",
  1082. prop_name, (ulong)fit, noffset,
  1083. fit_get_name (fit, noffset, NULL),
  1084. fdt_strerror (err));
  1085. }
  1086. /**
  1087. * fit_print_contents - prints out the contents of the FIT format image
  1088. * @fit: pointer to the FIT format image header
  1089. * @p: pointer to prefix string
  1090. *
  1091. * fit_print_contents() formats a multi line FIT image contents description.
  1092. * The routine prints out FIT image properties (root node level) follwed by
  1093. * the details of each component image.
  1094. *
  1095. * returns:
  1096. * no returned results
  1097. */
  1098. void fit_print_contents (const void *fit)
  1099. {
  1100. char *desc;
  1101. char *uname;
  1102. int images_noffset;
  1103. int confs_noffset;
  1104. int noffset;
  1105. int ndepth;
  1106. int count = 0;
  1107. int ret;
  1108. const char *p;
  1109. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1110. time_t timestamp;
  1111. #endif
  1112. #ifdef USE_HOSTCC
  1113. p = "";
  1114. #else
  1115. p = " ";
  1116. #endif
  1117. /* Root node properties */
  1118. ret = fit_get_desc (fit, 0, &desc);
  1119. printf ("%sFIT description: ", p);
  1120. if (ret)
  1121. printf ("unavailable\n");
  1122. else
  1123. printf ("%s\n", desc);
  1124. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1125. ret = fit_get_timestamp (fit, 0, &timestamp);
  1126. printf ("%sCreated: ", p);
  1127. if (ret)
  1128. printf ("unavailable\n");
  1129. else
  1130. genimg_print_time (timestamp);
  1131. #endif
  1132. /* Find images parent node offset */
  1133. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1134. if (images_noffset < 0) {
  1135. printf ("Can't find images parent node '%s' (%s)\n",
  1136. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1137. return;
  1138. }
  1139. /* Process its subnodes, print out component images details */
  1140. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1141. (noffset >= 0) && (ndepth > 0);
  1142. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1143. if (ndepth == 1) {
  1144. /*
  1145. * Direct child node of the images parent node,
  1146. * i.e. component image node.
  1147. */
  1148. printf ("%s Image %u (%s)\n", p, count++,
  1149. fit_get_name(fit, noffset, NULL));
  1150. fit_image_print (fit, noffset, p);
  1151. }
  1152. }
  1153. /* Find configurations parent node offset */
  1154. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1155. if (confs_noffset < 0) {
  1156. debug ("Can't get configurations parent node '%s' (%s)\n",
  1157. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1158. return;
  1159. }
  1160. /* get default configuration unit name from default property */
  1161. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1162. if (uname)
  1163. printf ("%s Default Configuration: '%s'\n", p, uname);
  1164. /* Process its subnodes, print out configurations details */
  1165. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1166. (noffset >= 0) && (ndepth > 0);
  1167. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1168. if (ndepth == 1) {
  1169. /*
  1170. * Direct child node of the configurations parent node,
  1171. * i.e. configuration node.
  1172. */
  1173. printf ("%s Configuration %u (%s)\n", p, count++,
  1174. fit_get_name(fit, noffset, NULL));
  1175. fit_conf_print (fit, noffset, p);
  1176. }
  1177. }
  1178. }
  1179. /**
  1180. * fit_image_print - prints out the FIT component image details
  1181. * @fit: pointer to the FIT format image header
  1182. * @image_noffset: offset of the component image node
  1183. * @p: pointer to prefix string
  1184. *
  1185. * fit_image_print() lists all mandatory properies for the processed component
  1186. * image. If present, hash nodes are printed out as well.
  1187. *
  1188. * returns:
  1189. * no returned results
  1190. */
  1191. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1192. {
  1193. char *desc;
  1194. uint8_t type, arch, os, comp;
  1195. size_t size;
  1196. ulong load, entry;
  1197. const void *data;
  1198. int noffset;
  1199. int ndepth;
  1200. int ret;
  1201. /* Mandatory properties */
  1202. ret = fit_get_desc (fit, image_noffset, &desc);
  1203. printf ("%s Description: ", p);
  1204. if (ret)
  1205. printf ("unavailable\n");
  1206. else
  1207. printf ("%s\n", desc);
  1208. fit_image_get_type (fit, image_noffset, &type);
  1209. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1210. fit_image_get_comp (fit, image_noffset, &comp);
  1211. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1212. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1213. #ifndef USE_HOSTCC
  1214. printf ("%s Data Start: ", p);
  1215. if (ret)
  1216. printf ("unavailable\n");
  1217. else
  1218. printf ("0x%08lx\n", (ulong)data);
  1219. #endif
  1220. printf ("%s Data Size: ", p);
  1221. if (ret)
  1222. printf ("unavailable\n");
  1223. else
  1224. genimg_print_size (size);
  1225. /* Remaining, type dependent properties */
  1226. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1227. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1228. (type == IH_TYPE_FLATDT)) {
  1229. fit_image_get_arch (fit, image_noffset, &arch);
  1230. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1231. }
  1232. if (type == IH_TYPE_KERNEL) {
  1233. fit_image_get_os (fit, image_noffset, &os);
  1234. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1235. }
  1236. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1237. ret = fit_image_get_load (fit, image_noffset, &load);
  1238. printf ("%s Load Address: ", p);
  1239. if (ret)
  1240. printf ("unavailable\n");
  1241. else
  1242. printf ("0x%08lx\n", load);
  1243. fit_image_get_entry (fit, image_noffset, &entry);
  1244. printf ("%s Entry Point: ", p);
  1245. if (ret)
  1246. printf ("unavailable\n");
  1247. else
  1248. printf ("0x%08lx\n", entry);
  1249. }
  1250. /* Process all hash subnodes of the component image node */
  1251. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1252. (noffset >= 0) && (ndepth > 0);
  1253. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1254. if (ndepth == 1) {
  1255. /* Direct child node of the component image node */
  1256. fit_image_print_hash (fit, noffset, p);
  1257. }
  1258. }
  1259. }
  1260. /**
  1261. * fit_image_print_hash - prints out the hash node details
  1262. * @fit: pointer to the FIT format image header
  1263. * @noffset: offset of the hash node
  1264. * @p: pointer to prefix string
  1265. *
  1266. * fit_image_print_hash() lists properies for the processed hash node
  1267. *
  1268. * returns:
  1269. * no returned results
  1270. */
  1271. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1272. {
  1273. char *algo;
  1274. uint8_t *value;
  1275. int value_len;
  1276. int i, ret;
  1277. /*
  1278. * Check subnode name, must be equal to "hash".
  1279. * Multiple hash nodes require unique unit node
  1280. * names, e.g. hash@1, hash@2, etc.
  1281. */
  1282. if (strncmp (fit_get_name(fit, noffset, NULL),
  1283. FIT_HASH_NODENAME,
  1284. strlen(FIT_HASH_NODENAME)) != 0)
  1285. return;
  1286. debug ("%s Hash node: '%s'\n", p,
  1287. fit_get_name (fit, noffset, NULL));
  1288. printf ("%s Hash algo: ", p);
  1289. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1290. printf ("invalid/unsupported\n");
  1291. return;
  1292. }
  1293. printf ("%s\n", algo);
  1294. ret = fit_image_hash_get_value (fit, noffset, &value,
  1295. &value_len);
  1296. printf ("%s Hash value: ", p);
  1297. if (ret) {
  1298. printf ("unavailable\n");
  1299. } else {
  1300. for (i = 0; i < value_len; i++)
  1301. printf ("%02x", value[i]);
  1302. printf ("\n");
  1303. }
  1304. debug ("%s Hash len: %d\n", p, value_len);
  1305. }
  1306. /**
  1307. * fit_get_desc - get node description property
  1308. * @fit: pointer to the FIT format image header
  1309. * @noffset: node offset
  1310. * @desc: double pointer to the char, will hold pointer to the descrption
  1311. *
  1312. * fit_get_desc() reads description property from a given node, if
  1313. * description is found pointer to it is returened in third call argument.
  1314. *
  1315. * returns:
  1316. * 0, on success
  1317. * -1, on failure
  1318. */
  1319. int fit_get_desc (const void *fit, int noffset, char **desc)
  1320. {
  1321. int len;
  1322. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1323. if (*desc == NULL) {
  1324. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1325. return -1;
  1326. }
  1327. return 0;
  1328. }
  1329. /**
  1330. * fit_get_timestamp - get node timestamp property
  1331. * @fit: pointer to the FIT format image header
  1332. * @noffset: node offset
  1333. * @timestamp: pointer to the time_t, will hold read timestamp
  1334. *
  1335. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1336. * is found and has a correct size its value is retured in third call
  1337. * argument.
  1338. *
  1339. * returns:
  1340. * 0, on success
  1341. * -1, on property read failure
  1342. * -2, on wrong timestamp size
  1343. */
  1344. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1345. {
  1346. int len;
  1347. const void *data;
  1348. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1349. if (data == NULL) {
  1350. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1351. return -1;
  1352. }
  1353. if (len != sizeof (uint32_t)) {
  1354. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1355. return -2;
  1356. }
  1357. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1358. return 0;
  1359. }
  1360. /**
  1361. * fit_image_get_node - get node offset for component image of a given unit name
  1362. * @fit: pointer to the FIT format image header
  1363. * @image_uname: component image node unit name
  1364. *
  1365. * fit_image_get_node() finds a component image (withing the '/images'
  1366. * node) of a provided unit name. If image is found its node offset is
  1367. * returned to the caller.
  1368. *
  1369. * returns:
  1370. * image node offset when found (>=0)
  1371. * negative number on failure (FDT_ERR_* code)
  1372. */
  1373. int fit_image_get_node (const void *fit, const char *image_uname)
  1374. {
  1375. int noffset, images_noffset;
  1376. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1377. if (images_noffset < 0) {
  1378. debug ("Can't find images parent node '%s' (%s)\n",
  1379. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1380. return images_noffset;
  1381. }
  1382. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1383. if (noffset < 0) {
  1384. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1385. image_uname, fdt_strerror (noffset));
  1386. }
  1387. return noffset;
  1388. }
  1389. /**
  1390. * fit_image_get_os - get os id for a given component image node
  1391. * @fit: pointer to the FIT format image header
  1392. * @noffset: component image node offset
  1393. * @os: pointer to the uint8_t, will hold os numeric id
  1394. *
  1395. * fit_image_get_os() finds os property in a given component image node.
  1396. * If the property is found, its (string) value is translated to the numeric
  1397. * id which is returned to the caller.
  1398. *
  1399. * returns:
  1400. * 0, on success
  1401. * -1, on failure
  1402. */
  1403. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1404. {
  1405. int len;
  1406. const void *data;
  1407. /* Get OS name from property data */
  1408. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1409. if (data == NULL) {
  1410. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1411. *os = -1;
  1412. return -1;
  1413. }
  1414. /* Translate OS name to id */
  1415. *os = genimg_get_os_id (data);
  1416. return 0;
  1417. }
  1418. /**
  1419. * fit_image_get_arch - get arch id for a given component image node
  1420. * @fit: pointer to the FIT format image header
  1421. * @noffset: component image node offset
  1422. * @arch: pointer to the uint8_t, will hold arch numeric id
  1423. *
  1424. * fit_image_get_arch() finds arch property in a given component image node.
  1425. * If the property is found, its (string) value is translated to the numeric
  1426. * id which is returned to the caller.
  1427. *
  1428. * returns:
  1429. * 0, on success
  1430. * -1, on failure
  1431. */
  1432. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1433. {
  1434. int len;
  1435. const void *data;
  1436. /* Get architecture name from property data */
  1437. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1438. if (data == NULL) {
  1439. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1440. *arch = -1;
  1441. return -1;
  1442. }
  1443. /* Translate architecture name to id */
  1444. *arch = genimg_get_arch_id (data);
  1445. return 0;
  1446. }
  1447. /**
  1448. * fit_image_get_type - get type id for a given component image node
  1449. * @fit: pointer to the FIT format image header
  1450. * @noffset: component image node offset
  1451. * @type: pointer to the uint8_t, will hold type numeric id
  1452. *
  1453. * fit_image_get_type() finds type property in a given component image node.
  1454. * If the property is found, its (string) value is translated to the numeric
  1455. * id which is returned to the caller.
  1456. *
  1457. * returns:
  1458. * 0, on success
  1459. * -1, on failure
  1460. */
  1461. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1462. {
  1463. int len;
  1464. const void *data;
  1465. /* Get image type name from property data */
  1466. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1467. if (data == NULL) {
  1468. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1469. *type = -1;
  1470. return -1;
  1471. }
  1472. /* Translate image type name to id */
  1473. *type = genimg_get_type_id (data);
  1474. return 0;
  1475. }
  1476. /**
  1477. * fit_image_get_comp - get comp id for a given component image node
  1478. * @fit: pointer to the FIT format image header
  1479. * @noffset: component image node offset
  1480. * @comp: pointer to the uint8_t, will hold comp numeric id
  1481. *
  1482. * fit_image_get_comp() finds comp property in a given component image node.
  1483. * If the property is found, its (string) value is translated to the numeric
  1484. * id which is returned to the caller.
  1485. *
  1486. * returns:
  1487. * 0, on success
  1488. * -1, on failure
  1489. */
  1490. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1491. {
  1492. int len;
  1493. const void *data;
  1494. /* Get compression name from property data */
  1495. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1496. if (data == NULL) {
  1497. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1498. *comp = -1;
  1499. return -1;
  1500. }
  1501. /* Translate compression name to id */
  1502. *comp = genimg_get_comp_id (data);
  1503. return 0;
  1504. }
  1505. /**
  1506. * fit_image_get_load - get load address property for a given component image node
  1507. * @fit: pointer to the FIT format image header
  1508. * @noffset: component image node offset
  1509. * @load: pointer to the uint32_t, will hold load address
  1510. *
  1511. * fit_image_get_load() finds load address property in a given component image node.
  1512. * If the property is found, its value is returned to the caller.
  1513. *
  1514. * returns:
  1515. * 0, on success
  1516. * -1, on failure
  1517. */
  1518. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1519. {
  1520. int len;
  1521. const uint32_t *data;
  1522. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1523. if (data == NULL) {
  1524. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1525. return -1;
  1526. }
  1527. *load = uimage_to_cpu (*data);
  1528. return 0;
  1529. }
  1530. /**
  1531. * fit_image_get_entry - get entry point address property for a given component image node
  1532. * @fit: pointer to the FIT format image header
  1533. * @noffset: component image node offset
  1534. * @entry: pointer to the uint32_t, will hold entry point address
  1535. *
  1536. * fit_image_get_entry() finds entry point address property in a given component image node.
  1537. * If the property is found, its value is returned to the caller.
  1538. *
  1539. * returns:
  1540. * 0, on success
  1541. * -1, on failure
  1542. */
  1543. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  1544. {
  1545. int len;
  1546. const uint32_t *data;
  1547. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  1548. if (data == NULL) {
  1549. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  1550. return -1;
  1551. }
  1552. *entry = uimage_to_cpu (*data);
  1553. return 0;
  1554. }
  1555. /**
  1556. * fit_image_get_data - get data property and its size for a given component image node
  1557. * @fit: pointer to the FIT format image header
  1558. * @noffset: component image node offset
  1559. * @data: double pointer to void, will hold data property's data address
  1560. * @size: pointer to size_t, will hold data property's data size
  1561. *
  1562. * fit_image_get_data() finds data property in a given component image node.
  1563. * If the property is found its data start address and size are returned to
  1564. * the caller.
  1565. *
  1566. * returns:
  1567. * 0, on success
  1568. * -1, on failure
  1569. */
  1570. int fit_image_get_data (const void *fit, int noffset,
  1571. const void **data, size_t *size)
  1572. {
  1573. int len;
  1574. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  1575. if (*data == NULL) {
  1576. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  1577. *size = 0;
  1578. return -1;
  1579. }
  1580. *size = len;
  1581. return 0;
  1582. }
  1583. /**
  1584. * fit_image_hash_get_algo - get hash algorithm name
  1585. * @fit: pointer to the FIT format image header
  1586. * @noffset: hash node offset
  1587. * @algo: double pointer to char, will hold pointer to the algorithm name
  1588. *
  1589. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  1590. * If the property is found its data start address is returned to the caller.
  1591. *
  1592. * returns:
  1593. * 0, on success
  1594. * -1, on failure
  1595. */
  1596. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  1597. {
  1598. int len;
  1599. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  1600. if (*algo == NULL) {
  1601. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  1602. return -1;
  1603. }
  1604. return 0;
  1605. }
  1606. /**
  1607. * fit_image_hash_get_value - get hash value and length
  1608. * @fit: pointer to the FIT format image header
  1609. * @noffset: hash node offset
  1610. * @value: double pointer to uint8_t, will hold address of a hash value data
  1611. * @value_len: pointer to an int, will hold hash data length
  1612. *
  1613. * fit_image_hash_get_value() finds hash value property in a given hash node.
  1614. * If the property is found its data start address and size are returned to
  1615. * the caller.
  1616. *
  1617. * returns:
  1618. * 0, on success
  1619. * -1, on failure
  1620. */
  1621. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  1622. int *value_len)
  1623. {
  1624. int len;
  1625. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  1626. if (*value == NULL) {
  1627. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  1628. *value_len = 0;
  1629. return -1;
  1630. }
  1631. *value_len = len;
  1632. return 0;
  1633. }
  1634. /**
  1635. * fit_set_timestamp - set node timestamp property
  1636. * @fit: pointer to the FIT format image header
  1637. * @noffset: node offset
  1638. * @timestamp: timestamp value to be set
  1639. *
  1640. * fit_set_timestamp() attempts to set timestamp property in the requested
  1641. * node and returns operation status to the caller.
  1642. *
  1643. * returns:
  1644. * 0, on success
  1645. * -1, on property read failure
  1646. */
  1647. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  1648. {
  1649. uint32_t t;
  1650. int ret;
  1651. t = cpu_to_uimage (timestamp);
  1652. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  1653. sizeof (uint32_t));
  1654. if (ret) {
  1655. printf ("Can't set '%s' property for '%s' node (%s)\n",
  1656. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  1657. fdt_strerror (ret));
  1658. return -1;
  1659. }
  1660. return 0;
  1661. }
  1662. /**
  1663. * calculate_hash - calculate and return hash for provided input data
  1664. * @data: pointer to the input data
  1665. * @data_len: data length
  1666. * @algo: requested hash algorithm
  1667. * @value: pointer to the char, will hold hash value data (caller must
  1668. * allocate enough free space)
  1669. * value_len: length of the calculated hash
  1670. *
  1671. * calculate_hash() computes input data hash according to the requested algorithm.
  1672. * Resulting hash value is placed in caller provided 'value' buffer, length
  1673. * of the calculated hash is returned via value_len pointer argument.
  1674. *
  1675. * returns:
  1676. * 0, on success
  1677. * -1, when algo is unsupported
  1678. */
  1679. static int calculate_hash (const void *data, int data_len, const char *algo,
  1680. uint8_t *value, int *value_len)
  1681. {
  1682. if (strcmp (algo, "crc32") == 0 ) {
  1683. *((uint32_t *)value) = crc32_wd (0, data, data_len,
  1684. CHUNKSZ_CRC32);
  1685. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  1686. *value_len = 4;
  1687. } else if (strcmp (algo, "sha1") == 0 ) {
  1688. sha1_csum_wd ((unsigned char *) data, data_len,
  1689. (unsigned char *) value, CHUNKSZ_SHA1);
  1690. *value_len = 20;
  1691. } else if (strcmp (algo, "md5") == 0 ) {
  1692. md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  1693. *value_len = 16;
  1694. } else {
  1695. debug ("Unsupported hash alogrithm\n");
  1696. return -1;
  1697. }
  1698. return 0;
  1699. }
  1700. #ifdef USE_HOSTCC
  1701. /**
  1702. * fit_set_hashes - process FIT component image nodes and calculate hashes
  1703. * @fit: pointer to the FIT format image header
  1704. *
  1705. * fit_set_hashes() adds hash values for all component images in the FIT blob.
  1706. * Hashes are calculated for all component images which have hash subnodes
  1707. * with algorithm property set to one of the supported hash algorithms.
  1708. *
  1709. * returns
  1710. * 0, on success
  1711. * libfdt error code, on failure
  1712. */
  1713. int fit_set_hashes (void *fit)
  1714. {
  1715. int images_noffset;
  1716. int noffset;
  1717. int ndepth;
  1718. int ret;
  1719. /* Find images parent node offset */
  1720. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1721. if (images_noffset < 0) {
  1722. printf ("Can't find images parent node '%s' (%s)\n",
  1723. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1724. return images_noffset;
  1725. }
  1726. /* Process its subnodes, print out component images details */
  1727. for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1728. (noffset >= 0) && (ndepth > 0);
  1729. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1730. if (ndepth == 1) {
  1731. /*
  1732. * Direct child node of the images parent node,
  1733. * i.e. component image node.
  1734. */
  1735. ret = fit_image_set_hashes (fit, noffset);
  1736. if (ret)
  1737. return ret;
  1738. }
  1739. }
  1740. return 0;
  1741. }
  1742. /**
  1743. * fit_image_set_hashes - calculate/set hashes for given component image node
  1744. * @fit: pointer to the FIT format image header
  1745. * @image_noffset: requested component image node
  1746. *
  1747. * fit_image_set_hashes() adds hash values for an component image node. All
  1748. * existing hash subnodes are checked, if algorithm property is set to one of
  1749. * the supported hash algorithms, hash value is computed and corresponding
  1750. * hash node property is set, for example:
  1751. *
  1752. * Input component image node structure:
  1753. *
  1754. * o image@1 (at image_noffset)
  1755. * | - data = [binary data]
  1756. * o hash@1
  1757. * |- algo = "sha1"
  1758. *
  1759. * Output component image node structure:
  1760. *
  1761. * o image@1 (at image_noffset)
  1762. * | - data = [binary data]
  1763. * o hash@1
  1764. * |- algo = "sha1"
  1765. * |- value = sha1(data)
  1766. *
  1767. * returns:
  1768. * 0 on sucess
  1769. * <0 on failure
  1770. */
  1771. int fit_image_set_hashes (void *fit, int image_noffset)
  1772. {
  1773. const void *data;
  1774. size_t size;
  1775. char *algo;
  1776. uint8_t value[FIT_MAX_HASH_LEN];
  1777. int value_len;
  1778. int noffset;
  1779. int ndepth;
  1780. /* Get image data and data length */
  1781. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1782. printf ("Can't get image data/size\n");
  1783. return -1;
  1784. }
  1785. /* Process all hash subnodes of the component image node */
  1786. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1787. (noffset >= 0) && (ndepth > 0);
  1788. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1789. if (ndepth == 1) {
  1790. /* Direct child node of the component image node */
  1791. /*
  1792. * Check subnode name, must be equal to "hash".
  1793. * Multiple hash nodes require unique unit node
  1794. * names, e.g. hash@1, hash@2, etc.
  1795. */
  1796. if (strncmp (fit_get_name(fit, noffset, NULL),
  1797. FIT_HASH_NODENAME,
  1798. strlen(FIT_HASH_NODENAME)) != 0) {
  1799. /* Not a hash subnode, skip it */
  1800. continue;
  1801. }
  1802. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1803. printf ("Can't get hash algo property for "
  1804. "'%s' hash node in '%s' image node\n",
  1805. fit_get_name (fit, noffset, NULL),
  1806. fit_get_name (fit, image_noffset, NULL));
  1807. return -1;
  1808. }
  1809. if (calculate_hash (data, size, algo, value, &value_len)) {
  1810. printf ("Unsupported hash algorithm (%s) for "
  1811. "'%s' hash node in '%s' image node\n",
  1812. algo, fit_get_name (fit, noffset, NULL),
  1813. fit_get_name (fit, image_noffset, NULL));
  1814. return -1;
  1815. }
  1816. if (fit_image_hash_set_value (fit, noffset, value,
  1817. value_len)) {
  1818. printf ("Can't set hash value for "
  1819. "'%s' hash node in '%s' image node\n",
  1820. fit_get_name (fit, noffset, NULL),
  1821. fit_get_name (fit, image_noffset, NULL));
  1822. return -1;
  1823. }
  1824. }
  1825. }
  1826. return 0;
  1827. }
  1828. /**
  1829. * fit_image_hash_set_value - set hash value in requested has node
  1830. * @fit: pointer to the FIT format image header
  1831. * @noffset: hash node offset
  1832. * @value: hash value to be set
  1833. * @value_len: hash value length
  1834. *
  1835. * fit_image_hash_set_value() attempts to set hash value in a node at offset
  1836. * given and returns operation status to the caller.
  1837. *
  1838. * returns
  1839. * 0, on success
  1840. * -1, on failure
  1841. */
  1842. int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
  1843. int value_len)
  1844. {
  1845. int ret;
  1846. ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
  1847. if (ret) {
  1848. printf ("Can't set hash '%s' property for '%s' node (%s)\n",
  1849. FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
  1850. fdt_strerror (ret));
  1851. return -1;
  1852. }
  1853. return 0;
  1854. }
  1855. #endif /* USE_HOSTCC */
  1856. /**
  1857. * fit_image_check_hashes - verify data intergity
  1858. * @fit: pointer to the FIT format image header
  1859. * @image_noffset: component image node offset
  1860. *
  1861. * fit_image_check_hashes() goes over component image hash nodes,
  1862. * re-calculates each data hash and compares with the value stored in hash
  1863. * node.
  1864. *
  1865. * returns:
  1866. * 1, if all hashes are valid
  1867. * 0, otherwise (or on error)
  1868. */
  1869. int fit_image_check_hashes (const void *fit, int image_noffset)
  1870. {
  1871. const void *data;
  1872. size_t size;
  1873. char *algo;
  1874. uint8_t *fit_value;
  1875. int fit_value_len;
  1876. uint8_t value[FIT_MAX_HASH_LEN];
  1877. int value_len;
  1878. int noffset;
  1879. int ndepth;
  1880. char *err_msg = "";
  1881. /* Get image data and data length */
  1882. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1883. printf ("Can't get image data/size\n");
  1884. return 0;
  1885. }
  1886. /* Process all hash subnodes of the component image node */
  1887. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1888. (noffset >= 0) && (ndepth > 0);
  1889. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1890. if (ndepth == 1) {
  1891. /* Direct child node of the component image node */
  1892. /*
  1893. * Check subnode name, must be equal to "hash".
  1894. * Multiple hash nodes require unique unit node
  1895. * names, e.g. hash@1, hash@2, etc.
  1896. */
  1897. if (strncmp (fit_get_name(fit, noffset, NULL),
  1898. FIT_HASH_NODENAME,
  1899. strlen(FIT_HASH_NODENAME)) != 0)
  1900. continue;
  1901. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1902. err_msg = "Can't get hash algo property";
  1903. goto error;
  1904. }
  1905. printf ("%s", algo);
  1906. if (fit_image_hash_get_value (fit, noffset, &fit_value,
  1907. &fit_value_len)) {
  1908. err_msg = "Can't get hash value property";
  1909. goto error;
  1910. }
  1911. if (calculate_hash (data, size, algo, value, &value_len)) {
  1912. err_msg = "Unsupported hash algorithm";
  1913. goto error;
  1914. }
  1915. if (value_len != fit_value_len) {
  1916. err_msg = "Bad hash value len";
  1917. goto error;
  1918. } else if (memcmp (value, fit_value, value_len) != 0) {
  1919. err_msg = "Bad hash value";
  1920. goto error;
  1921. }
  1922. printf ("+ ");
  1923. }
  1924. }
  1925. return 1;
  1926. error:
  1927. printf ("%s for '%s' hash node in '%s' image node\n",
  1928. err_msg, fit_get_name (fit, noffset, NULL),
  1929. fit_get_name (fit, image_noffset, NULL));
  1930. return 0;
  1931. }
  1932. /**
  1933. * fit_image_check_os - check whether image node is of a given os type
  1934. * @fit: pointer to the FIT format image header
  1935. * @noffset: component image node offset
  1936. * @os: requested image os
  1937. *
  1938. * fit_image_check_os() reads image os property and compares its numeric
  1939. * id with the requested os. Comparison result is returned to the caller.
  1940. *
  1941. * returns:
  1942. * 1 if image is of given os type
  1943. * 0 otherwise (or on error)
  1944. */
  1945. int fit_image_check_os (const void *fit, int noffset, uint8_t os)
  1946. {
  1947. uint8_t image_os;
  1948. if (fit_image_get_os (fit, noffset, &image_os))
  1949. return 0;
  1950. return (os == image_os);
  1951. }
  1952. /**
  1953. * fit_image_check_arch - check whether image node is of a given arch
  1954. * @fit: pointer to the FIT format image header
  1955. * @noffset: component image node offset
  1956. * @arch: requested imagearch
  1957. *
  1958. * fit_image_check_arch() reads image arch property and compares its numeric
  1959. * id with the requested arch. Comparison result is returned to the caller.
  1960. *
  1961. * returns:
  1962. * 1 if image is of given arch
  1963. * 0 otherwise (or on error)
  1964. */
  1965. int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
  1966. {
  1967. uint8_t image_arch;
  1968. if (fit_image_get_arch (fit, noffset, &image_arch))
  1969. return 0;
  1970. return (arch == image_arch);
  1971. }
  1972. /**
  1973. * fit_image_check_type - check whether image node is of a given type
  1974. * @fit: pointer to the FIT format image header
  1975. * @noffset: component image node offset
  1976. * @type: requested image type
  1977. *
  1978. * fit_image_check_type() reads image type property and compares its numeric
  1979. * id with the requested type. Comparison result is returned to the caller.
  1980. *
  1981. * returns:
  1982. * 1 if image is of given type
  1983. * 0 otherwise (or on error)
  1984. */
  1985. int fit_image_check_type (const void *fit, int noffset, uint8_t type)
  1986. {
  1987. uint8_t image_type;
  1988. if (fit_image_get_type (fit, noffset, &image_type))
  1989. return 0;
  1990. return (type == image_type);
  1991. }
  1992. /**
  1993. * fit_image_check_comp - check whether image node uses given compression
  1994. * @fit: pointer to the FIT format image header
  1995. * @noffset: component image node offset
  1996. * @comp: requested image compression type
  1997. *
  1998. * fit_image_check_comp() reads image compression property and compares its
  1999. * numeric id with the requested compression type. Comparison result is
  2000. * returned to the caller.
  2001. *
  2002. * returns:
  2003. * 1 if image uses requested compression
  2004. * 0 otherwise (or on error)
  2005. */
  2006. int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
  2007. {
  2008. uint8_t image_comp;
  2009. if (fit_image_get_comp (fit, noffset, &image_comp))
  2010. return 0;
  2011. return (comp == image_comp);
  2012. }
  2013. /**
  2014. * fit_check_format - sanity check FIT image format
  2015. * @fit: pointer to the FIT format image header
  2016. *
  2017. * fit_check_format() runs a basic sanity FIT image verification.
  2018. * Routine checks for mandatory properties, nodes, etc.
  2019. *
  2020. * returns:
  2021. * 1, on success
  2022. * 0, on failure
  2023. */
  2024. int fit_check_format (const void *fit)
  2025. {
  2026. /* mandatory / node 'description' property */
  2027. if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  2028. debug ("Wrong FIT format: no description\n");
  2029. return 0;
  2030. }
  2031. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  2032. /* mandatory / node 'timestamp' property */
  2033. if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  2034. debug ("Wrong FIT format: no description\n");
  2035. return 0;
  2036. }
  2037. #endif
  2038. /* mandatory subimages parent '/images' node */
  2039. if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
  2040. debug ("Wrong FIT format: no images parent node\n");
  2041. return 0;
  2042. }
  2043. return 1;
  2044. }
  2045. /**
  2046. * fit_conf_get_node - get node offset for configuration of a given unit name
  2047. * @fit: pointer to the FIT format image header
  2048. * @conf_uname: configuration node unit name
  2049. *
  2050. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  2051. * parant node) of a provided unit name. If configuration is found its node offset
  2052. * is returned to the caller.
  2053. *
  2054. * When NULL is provided in second argument fit_conf_get_node() will search
  2055. * for a default configuration node instead. Default configuration node unit name
  2056. * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
  2057. *
  2058. * returns:
  2059. * configuration node offset when found (>=0)
  2060. * negative number on failure (FDT_ERR_* code)
  2061. */
  2062. int fit_conf_get_node (const void *fit, const char *conf_uname)
  2063. {
  2064. int noffset, confs_noffset;
  2065. int len;
  2066. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  2067. if (confs_noffset < 0) {
  2068. debug ("Can't find configurations parent node '%s' (%s)\n",
  2069. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  2070. return confs_noffset;
  2071. }
  2072. if (conf_uname == NULL) {
  2073. /* get configuration unit name from the default property */
  2074. debug ("No configuration specified, trying default...\n");
  2075. conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
  2076. if (conf_uname == NULL) {
  2077. fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
  2078. return len;
  2079. }
  2080. debug ("Found default configuration: '%s'\n", conf_uname);
  2081. }
  2082. noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
  2083. if (noffset < 0) {
  2084. debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
  2085. conf_uname, fdt_strerror (noffset));
  2086. }
  2087. return noffset;
  2088. }
  2089. static int __fit_conf_get_prop_node (const void *fit, int noffset,
  2090. const char *prop_name)
  2091. {
  2092. char *uname;
  2093. int len;
  2094. /* get kernel image unit name from configuration kernel property */
  2095. uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
  2096. if (uname == NULL)
  2097. return len;
  2098. return fit_image_get_node (fit, uname);
  2099. }
  2100. /**
  2101. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  2102. * a given configuration
  2103. * @fit: pointer to the FIT format image header
  2104. * @noffset: configuration node offset
  2105. *
  2106. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  2107. * configuration FIT_KERNEL_PROP property and translates it to the node
  2108. * offset.
  2109. *
  2110. * returns:
  2111. * image node offset when found (>=0)
  2112. * negative number on failure (FDT_ERR_* code)
  2113. */
  2114. int fit_conf_get_kernel_node (const void *fit, int noffset)
  2115. {
  2116. return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
  2117. }
  2118. /**
  2119. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  2120. * a given configuration
  2121. * @fit: pointer to the FIT format image header
  2122. * @noffset: configuration node offset
  2123. *
  2124. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  2125. * configuration FIT_KERNEL_PROP property and translates it to the node
  2126. * offset.
  2127. *
  2128. * returns:
  2129. * image node offset when found (>=0)
  2130. * negative number on failure (FDT_ERR_* code)
  2131. */
  2132. int fit_conf_get_ramdisk_node (const void *fit, int noffset)
  2133. {
  2134. return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
  2135. }
  2136. /**
  2137. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  2138. * a given configuration
  2139. * @fit: pointer to the FIT format image header
  2140. * @noffset: configuration node offset
  2141. *
  2142. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  2143. * configuration FIT_KERNEL_PROP property and translates it to the node
  2144. * offset.
  2145. *
  2146. * returns:
  2147. * image node offset when found (>=0)
  2148. * negative number on failure (FDT_ERR_* code)
  2149. */
  2150. int fit_conf_get_fdt_node (const void *fit, int noffset)
  2151. {
  2152. return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
  2153. }
  2154. /**
  2155. * fit_conf_print - prints out the FIT configuration details
  2156. * @fit: pointer to the FIT format image header
  2157. * @noffset: offset of the configuration node
  2158. * @p: pointer to prefix string
  2159. *
  2160. * fit_conf_print() lists all mandatory properies for the processed
  2161. * configuration node.
  2162. *
  2163. * returns:
  2164. * no returned results
  2165. */
  2166. void fit_conf_print (const void *fit, int noffset, const char *p)
  2167. {
  2168. char *desc;
  2169. char *uname;
  2170. int ret;
  2171. /* Mandatory properties */
  2172. ret = fit_get_desc (fit, noffset, &desc);
  2173. printf ("%s Description: ", p);
  2174. if (ret)
  2175. printf ("unavailable\n");
  2176. else
  2177. printf ("%s\n", desc);
  2178. uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
  2179. printf ("%s Kernel: ", p);
  2180. if (uname == NULL)
  2181. printf ("unavailable\n");
  2182. else
  2183. printf ("%s\n", uname);
  2184. /* Optional properties */
  2185. uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
  2186. if (uname)
  2187. printf ("%s Init Ramdisk: %s\n", p, uname);
  2188. uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
  2189. if (uname)
  2190. printf ("%s FDT: %s\n", p, uname);
  2191. }
  2192. /**
  2193. * fit_check_ramdisk - verify FIT format ramdisk subimage
  2194. * @fit_hdr: pointer to the FIT ramdisk header
  2195. * @rd_noffset: ramdisk subimage node offset within FIT image
  2196. * @arch: requested ramdisk image architecture type
  2197. * @verify: data CRC verification flag
  2198. *
  2199. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  2200. * specified FIT image.
  2201. *
  2202. * returns:
  2203. * 1, on success
  2204. * 0, on failure
  2205. */
  2206. #ifndef USE_HOSTCC
  2207. static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
  2208. {
  2209. fit_image_print (fit, rd_noffset, " ");
  2210. if (verify) {
  2211. puts (" Verifying Hash Integrity ... ");
  2212. if (!fit_image_check_hashes (fit, rd_noffset)) {
  2213. puts ("Bad Data Hash\n");
  2214. show_boot_progress (-125);
  2215. return 0;
  2216. }
  2217. puts ("OK\n");
  2218. }
  2219. show_boot_progress (126);
  2220. if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
  2221. !fit_image_check_arch (fit, rd_noffset, arch) ||
  2222. !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
  2223. printf ("No Linux %s Ramdisk Image\n",
  2224. genimg_get_arch_name(arch));
  2225. show_boot_progress (-126);
  2226. return 0;
  2227. }
  2228. show_boot_progress (127);
  2229. return 1;
  2230. }
  2231. #endif /* USE_HOSTCC */
  2232. #endif /* CONFIG_FIT */