image.c 68 KB

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