image.c 69 KB

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