image.c 84 KB

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