image.c 84 KB

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