image.c 68 KB

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