1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef __IMAGE_H__
17#define __IMAGE_H__
18
19#include "compiler.h"
20#include <asm/byteorder.h>
21
22
23struct lmb;
24
25#ifdef USE_HOSTCC
26#include <sys/types.h>
27
28
29#define IMAGE_ENABLE_FIT 1
30#define IMAGE_ENABLE_OF_LIBFDT 1
31#define CONFIG_FIT_VERBOSE 1
32
33#define IMAGE_ENABLE_IGNORE 0
34#define IMAGE_INDENT_STRING ""
35
36#else
37
38#include <lmb.h>
39#include <asm/u-boot.h>
40#include <command.h>
41
42
43#define IMAGE_ENABLE_IGNORE 1
44#define IMAGE_INDENT_STRING " "
45
46#define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT)
47#define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT)
48
49#endif
50
51#if IMAGE_ENABLE_FIT
52#include <hash.h>
53#include <libfdt.h>
54#include <fdt_support.h>
55# ifdef CONFIG_SPL_BUILD
56# ifdef CONFIG_SPL_CRC32_SUPPORT
57# define IMAGE_ENABLE_CRC32 1
58# endif
59# ifdef CONFIG_SPL_MD5_SUPPORT
60# define IMAGE_ENABLE_MD5 1
61# endif
62# ifdef CONFIG_SPL_SHA1_SUPPORT
63# define IMAGE_ENABLE_SHA1 1
64# endif
65# ifdef CONFIG_SPL_SHA256_SUPPORT
66# define IMAGE_ENABLE_SHA256 1
67# endif
68# else
69# define CONFIG_CRC32
70# define CONFIG_MD5
71# define CONFIG_SHA1
72# define CONFIG_SHA256
73# define IMAGE_ENABLE_CRC32 1
74# define IMAGE_ENABLE_MD5 1
75# define IMAGE_ENABLE_SHA1 1
76# define IMAGE_ENABLE_SHA256 1
77# endif
78
79#ifdef CONFIG_FIT_DISABLE_SHA256
80#undef CONFIG_SHA256
81#undef IMAGE_ENABLE_SHA256
82#endif
83
84#ifndef IMAGE_ENABLE_CRC32
85#define IMAGE_ENABLE_CRC32 0
86#endif
87
88#ifndef IMAGE_ENABLE_MD5
89#define IMAGE_ENABLE_MD5 0
90#endif
91
92#ifndef IMAGE_ENABLE_SHA1
93#define IMAGE_ENABLE_SHA1 0
94#endif
95
96#ifndef IMAGE_ENABLE_SHA256
97#define IMAGE_ENABLE_SHA256 0
98#endif
99
100#endif
101
102#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
103# define IMAGE_ENABLE_RAMDISK_HIGH 1
104#else
105# define IMAGE_ENABLE_RAMDISK_HIGH 0
106#endif
107
108#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
109# define IMAGE_BOOT_GET_CMDLINE 1
110#else
111# define IMAGE_BOOT_GET_CMDLINE 0
112#endif
113
114#ifdef CONFIG_OF_BOARD_SETUP
115# define IMAGE_OF_BOARD_SETUP 1
116#else
117# define IMAGE_OF_BOARD_SETUP 0
118#endif
119
120#ifdef CONFIG_OF_SYSTEM_SETUP
121# define IMAGE_OF_SYSTEM_SETUP 1
122#else
123# define IMAGE_OF_SYSTEM_SETUP 0
124#endif
125
126enum ih_category {
127 IH_ARCH,
128 IH_COMP,
129 IH_OS,
130 IH_TYPE,
131
132 IH_COUNT,
133};
134
135
136
137
138
139
140
141enum {
142 IH_OS_INVALID = 0,
143 IH_OS_OPENBSD,
144 IH_OS_NETBSD,
145 IH_OS_FREEBSD,
146 IH_OS_4_4BSD,
147 IH_OS_LINUX,
148 IH_OS_SVR4,
149 IH_OS_ESIX,
150 IH_OS_SOLARIS,
151 IH_OS_IRIX,
152 IH_OS_SCO,
153 IH_OS_DELL,
154 IH_OS_NCR,
155 IH_OS_LYNXOS,
156 IH_OS_VXWORKS,
157 IH_OS_PSOS,
158 IH_OS_QNX,
159 IH_OS_U_BOOT,
160 IH_OS_RTEMS,
161 IH_OS_ARTOS,
162 IH_OS_UNITY,
163 IH_OS_INTEGRITY,
164 IH_OS_OSE,
165 IH_OS_PLAN9,
166 IH_OS_OPENRTOS,
167
168 IH_OS_COUNT,
169};
170
171
172
173
174
175
176
177enum {
178 IH_ARCH_INVALID = 0,
179 IH_ARCH_ALPHA,
180 IH_ARCH_ARM,
181 IH_ARCH_I386,
182 IH_ARCH_IA64,
183 IH_ARCH_MIPS,
184 IH_ARCH_MIPS64,
185 IH_ARCH_PPC,
186 IH_ARCH_S390,
187 IH_ARCH_SH,
188 IH_ARCH_SPARC,
189 IH_ARCH_SPARC64,
190 IH_ARCH_M68K,
191 IH_ARCH_NIOS,
192 IH_ARCH_MICROBLAZE,
193 IH_ARCH_NIOS2,
194 IH_ARCH_BLACKFIN,
195 IH_ARCH_AVR32,
196 IH_ARCH_ST200,
197 IH_ARCH_SANDBOX,
198 IH_ARCH_NDS32,
199 IH_ARCH_OPENRISC,
200 IH_ARCH_ARM64,
201 IH_ARCH_ARC,
202 IH_ARCH_X86_64,
203 IH_ARCH_XTENSA,
204
205 IH_ARCH_COUNT,
206};
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250enum {
251 IH_TYPE_INVALID = 0,
252 IH_TYPE_STANDALONE,
253 IH_TYPE_KERNEL,
254 IH_TYPE_RAMDISK,
255 IH_TYPE_MULTI,
256 IH_TYPE_FIRMWARE,
257 IH_TYPE_SCRIPT,
258 IH_TYPE_FILESYSTEM,
259 IH_TYPE_FLATDT,
260 IH_TYPE_KWBIMAGE,
261 IH_TYPE_IMXIMAGE,
262 IH_TYPE_UBLIMAGE,
263 IH_TYPE_OMAPIMAGE,
264 IH_TYPE_AISIMAGE,
265
266 IH_TYPE_KERNEL_NOLOAD,
267 IH_TYPE_PBLIMAGE,
268 IH_TYPE_MXSIMAGE,
269 IH_TYPE_GPIMAGE,
270 IH_TYPE_ATMELIMAGE,
271 IH_TYPE_SOCFPGAIMAGE,
272 IH_TYPE_X86_SETUP,
273 IH_TYPE_LPC32XXIMAGE,
274 IH_TYPE_LOADABLE,
275 IH_TYPE_RKIMAGE,
276 IH_TYPE_RKSD,
277 IH_TYPE_RKSPI,
278 IH_TYPE_ZYNQIMAGE,
279 IH_TYPE_ZYNQMPIMAGE,
280 IH_TYPE_FPGA,
281 IH_TYPE_VYBRIDIMAGE,
282 IH_TYPE_TEE,
283 IH_TYPE_FIRMWARE_IVT,
284
285 IH_TYPE_COUNT,
286};
287
288
289
290
291
292
293
294enum {
295 IH_COMP_NONE = 0,
296 IH_COMP_GZIP,
297 IH_COMP_BZIP2,
298 IH_COMP_LZMA,
299 IH_COMP_LZO,
300 IH_COMP_LZ4,
301
302 IH_COMP_COUNT,
303};
304
305#define IH_MAGIC 0x27051956
306#define IH_NMLEN 32
307
308
309#define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
310
311
312
313
314
315typedef struct image_header {
316 __be32 ih_magic;
317 __be32 ih_hcrc;
318 __be32 ih_time;
319 __be32 ih_size;
320 __be32 ih_load;
321 __be32 ih_ep;
322 __be32 ih_dcrc;
323 uint8_t ih_os;
324 uint8_t ih_arch;
325 uint8_t ih_type;
326 uint8_t ih_comp;
327 uint8_t ih_name[IH_NMLEN];
328} image_header_t;
329
330typedef struct image_info {
331 ulong start, end;
332 ulong image_start, image_len;
333 ulong load;
334 uint8_t comp, type, os;
335 uint8_t arch;
336} image_info_t;
337
338
339
340
341
342typedef struct bootm_headers {
343
344
345
346
347
348 image_header_t *legacy_hdr_os;
349 image_header_t legacy_hdr_os_copy;
350 ulong legacy_hdr_valid;
351
352#if IMAGE_ENABLE_FIT
353 const char *fit_uname_cfg;
354
355 void *fit_hdr_os;
356 const char *fit_uname_os;
357 int fit_noffset_os;
358
359 void *fit_hdr_rd;
360 const char *fit_uname_rd;
361 int fit_noffset_rd;
362
363 void *fit_hdr_fdt;
364 const char *fit_uname_fdt;
365 int fit_noffset_fdt;
366
367 void *fit_hdr_setup;
368 const char *fit_uname_setup;
369 int fit_noffset_setup;
370#endif
371
372#ifndef USE_HOSTCC
373 image_info_t os;
374 ulong ep;
375
376 ulong rd_start, rd_end;
377
378 char *ft_addr;
379 ulong ft_len;
380
381 ulong initrd_start;
382 ulong initrd_end;
383 ulong cmdline_start;
384 ulong cmdline_end;
385 bd_t *kbd;
386#endif
387
388 int verify;
389
390#define BOOTM_STATE_START (0x00000001)
391#define BOOTM_STATE_FINDOS (0x00000002)
392#define BOOTM_STATE_FINDOTHER (0x00000004)
393#define BOOTM_STATE_LOADOS (0x00000008)
394#define BOOTM_STATE_RAMDISK (0x00000010)
395#define BOOTM_STATE_FDT (0x00000020)
396#define BOOTM_STATE_OS_CMDLINE (0x00000040)
397#define BOOTM_STATE_OS_BD_T (0x00000080)
398#define BOOTM_STATE_OS_PREP (0x00000100)
399#define BOOTM_STATE_OS_FAKE_GO (0x00000200)
400#define BOOTM_STATE_OS_GO (0x00000400)
401 int state;
402
403#ifdef CONFIG_LMB
404 struct lmb lmb;
405#endif
406} bootm_headers_t;
407
408extern bootm_headers_t images;
409
410
411
412
413
414
415#ifndef CHUNKSZ
416#define CHUNKSZ (64 * 1024)
417#endif
418
419#ifndef CHUNKSZ_CRC32
420#define CHUNKSZ_CRC32 (64 * 1024)
421#endif
422
423#ifndef CHUNKSZ_MD5
424#define CHUNKSZ_MD5 (64 * 1024)
425#endif
426
427#ifndef CHUNKSZ_SHA1
428#define CHUNKSZ_SHA1 (64 * 1024)
429#endif
430
431#define uimage_to_cpu(x) be32_to_cpu(x)
432#define cpu_to_uimage(x) cpu_to_be32(x)
433
434
435
436
437
438typedef struct table_entry {
439 int id;
440 char *sname;
441 char *lname;
442} table_entry_t;
443
444
445
446
447
448
449int get_table_entry_id(const table_entry_t *table,
450 const char *table_name, const char *name);
451
452
453
454
455
456char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
457
458const char *genimg_get_os_name(uint8_t os);
459
460
461
462
463
464
465
466const char *genimg_get_os_short_name(uint8_t comp);
467
468const char *genimg_get_arch_name(uint8_t arch);
469
470
471
472
473
474
475
476const char *genimg_get_arch_short_name(uint8_t arch);
477
478const char *genimg_get_type_name(uint8_t type);
479
480
481
482
483
484
485
486const char *genimg_get_type_short_name(uint8_t type);
487
488const char *genimg_get_comp_name(uint8_t comp);
489
490
491
492
493
494
495
496const char *genimg_get_comp_short_name(uint8_t comp);
497
498
499
500
501
502
503
504
505const char *genimg_get_cat_name(enum ih_category category, uint id);
506
507
508
509
510
511
512
513
514const char *genimg_get_cat_short_name(enum ih_category category, uint id);
515
516
517
518
519
520
521
522int genimg_get_cat_count(enum ih_category category);
523
524
525
526
527
528
529
530const char *genimg_get_cat_desc(enum ih_category category);
531
532int genimg_get_os_id(const char *name);
533int genimg_get_arch_id(const char *name);
534int genimg_get_type_id(const char *name);
535int genimg_get_comp_id(const char *name);
536void genimg_print_size(uint32_t size);
537
538#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
539 defined(USE_HOSTCC)
540#define IMAGE_ENABLE_TIMESTAMP 1
541#else
542#define IMAGE_ENABLE_TIMESTAMP 0
543#endif
544void genimg_print_time(time_t timestamp);
545
546
547enum fit_load_op {
548 FIT_LOAD_IGNORED,
549 FIT_LOAD_OPTIONAL,
550 FIT_LOAD_OPTIONAL_NON_ZERO,
551 FIT_LOAD_REQUIRED,
552};
553
554int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
555 ulong *setup_len);
556
557#ifndef USE_HOSTCC
558
559#define IMAGE_FORMAT_INVALID 0x00
560#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
561#define IMAGE_FORMAT_LEGACY 0x01
562#endif
563#define IMAGE_FORMAT_FIT 0x02
564#define IMAGE_FORMAT_ANDROID 0x03
565
566ulong genimg_get_kernel_addr_fit(char * const img_addr,
567 const char **fit_uname_config,
568 const char **fit_uname_kernel);
569ulong genimg_get_kernel_addr(char * const img_addr);
570int genimg_get_format(const void *img_addr);
571int genimg_has_config(bootm_headers_t *images);
572ulong genimg_get_image(ulong img_addr);
573
574int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
575 uint8_t arch, const ulong *ld_start, ulong * const ld_len);
576int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
577 uint8_t arch, ulong *rd_start, ulong *rd_end);
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
601 uint8_t arch, const ulong *ld_start, ulong * const ld_len);
602#endif
603
604int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
605 ulong *setup_start, ulong *setup_len);
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637int fit_image_load(bootm_headers_t *images, ulong addr,
638 const char **fit_unamep, const char **fit_uname_configp,
639 int arch, int image_type, int bootstage_id,
640 enum fit_load_op load_op, ulong *datap, ulong *lenp);
641
642#ifndef USE_HOSTCC
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
671 ulong addr);
672
673int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
674 bootm_headers_t *images,
675 char **of_flat_tree, ulong *of_size);
676void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
677int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
678
679int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
680 ulong *initrd_start, ulong *initrd_end);
681int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
682#ifdef CONFIG_SYS_BOOT_GET_KBD
683int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
684#endif
685#endif
686
687
688
689
690static inline uint32_t image_get_header_size(void)
691{
692 return (sizeof(image_header_t));
693}
694
695#define image_get_hdr_l(f) \
696 static inline uint32_t image_get_##f(const image_header_t *hdr) \
697 { \
698 return uimage_to_cpu(hdr->ih_##f); \
699 }
700image_get_hdr_l(magic)
701image_get_hdr_l(hcrc)
702image_get_hdr_l(time)
703image_get_hdr_l(size)
704image_get_hdr_l(load)
705image_get_hdr_l(ep)
706image_get_hdr_l(dcrc)
707
708#define image_get_hdr_b(f) \
709 static inline uint8_t image_get_##f(const image_header_t *hdr) \
710 { \
711 return hdr->ih_##f; \
712 }
713image_get_hdr_b(os)
714image_get_hdr_b(arch)
715image_get_hdr_b(type)
716image_get_hdr_b(comp)
717
718static inline char *image_get_name(const image_header_t *hdr)
719{
720 return (char *)hdr->ih_name;
721}
722
723static inline uint32_t image_get_data_size(const image_header_t *hdr)
724{
725 return image_get_size(hdr);
726}
727
728
729
730
731
732
733
734
735
736
737
738
739static inline ulong image_get_data(const image_header_t *hdr)
740{
741 return ((ulong)hdr + image_get_header_size());
742}
743
744static inline uint32_t image_get_image_size(const image_header_t *hdr)
745{
746 return (image_get_size(hdr) + image_get_header_size());
747}
748static inline ulong image_get_image_end(const image_header_t *hdr)
749{
750 return ((ulong)hdr + image_get_image_size(hdr));
751}
752
753#define image_set_hdr_l(f) \
754 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
755 { \
756 hdr->ih_##f = cpu_to_uimage(val); \
757 }
758image_set_hdr_l(magic)
759image_set_hdr_l(hcrc)
760image_set_hdr_l(time)
761image_set_hdr_l(size)
762image_set_hdr_l(load)
763image_set_hdr_l(ep)
764image_set_hdr_l(dcrc)
765
766#define image_set_hdr_b(f) \
767 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
768 { \
769 hdr->ih_##f = val; \
770 }
771image_set_hdr_b(os)
772image_set_hdr_b(arch)
773image_set_hdr_b(type)
774image_set_hdr_b(comp)
775
776static inline void image_set_name(image_header_t *hdr, const char *name)
777{
778 strncpy(image_get_name(hdr), name, IH_NMLEN);
779}
780
781int image_check_hcrc(const image_header_t *hdr);
782int image_check_dcrc(const image_header_t *hdr);
783#ifndef USE_HOSTCC
784ulong getenv_bootm_low(void);
785phys_size_t getenv_bootm_size(void);
786phys_size_t getenv_bootm_mapsize(void);
787#endif
788void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
789
790static inline int image_check_magic(const image_header_t *hdr)
791{
792 return (image_get_magic(hdr) == IH_MAGIC);
793}
794static inline int image_check_type(const image_header_t *hdr, uint8_t type)
795{
796 return (image_get_type(hdr) == type);
797}
798static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
799{
800 return (image_get_arch(hdr) == arch);
801}
802static inline int image_check_os(const image_header_t *hdr, uint8_t os)
803{
804 return (image_get_os(hdr) == os);
805}
806
807ulong image_multi_count(const image_header_t *hdr);
808void image_multi_getimg(const image_header_t *hdr, ulong idx,
809 ulong *data, ulong *len);
810
811void image_print_contents(const void *hdr);
812
813#ifndef USE_HOSTCC
814static inline int image_check_target_arch(const image_header_t *hdr)
815{
816#ifndef IH_ARCH_DEFAULT
817# error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
818#endif
819 return image_check_arch(hdr, IH_ARCH_DEFAULT);
820}
821#endif
822
823
824
825
826
827
828
829
830
831
832
833
834int image_setup_libfdt(bootm_headers_t *images, void *blob,
835 int of_size, struct lmb *lmb);
836
837
838
839
840
841
842
843
844
845
846int image_setup_linux(bootm_headers_t *images);
847
848
849
850
851
852
853
854
855
856int bootz_setup(ulong image, ulong *start, ulong *end);
857
858
859
860
861
862
863#define FIT_IMAGES_PATH "/images"
864#define FIT_CONFS_PATH "/configurations"
865
866
867#define FIT_HASH_NODENAME "hash"
868#define FIT_ALGO_PROP "algo"
869#define FIT_VALUE_PROP "value"
870#define FIT_IGNORE_PROP "uboot-ignore"
871#define FIT_SIG_NODENAME "signature"
872
873
874#define FIT_DATA_PROP "data"
875#define FIT_TIMESTAMP_PROP "timestamp"
876#define FIT_DESC_PROP "description"
877#define FIT_ARCH_PROP "arch"
878#define FIT_TYPE_PROP "type"
879#define FIT_OS_PROP "os"
880#define FIT_COMP_PROP "compression"
881#define FIT_ENTRY_PROP "entry"
882#define FIT_LOAD_PROP "load"
883
884
885#define FIT_KERNEL_PROP "kernel"
886#define FIT_RAMDISK_PROP "ramdisk"
887#define FIT_FDT_PROP "fdt"
888#define FIT_LOADABLE_PROP "loadables"
889#define FIT_DEFAULT_PROP "default"
890#define FIT_SETUP_PROP "setup"
891#define FIT_FPGA_PROP "fpga"
892
893#define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE
894
895#if IMAGE_ENABLE_FIT
896
897int fit_parse_conf(const char *spec, ulong addr_curr,
898 ulong *addr, const char **conf_name);
899int fit_parse_subimage(const char *spec, ulong addr_curr,
900 ulong *addr, const char **image_name);
901
902int fit_get_subimage_count(const void *fit, int images_noffset);
903void fit_print_contents(const void *fit);
904void fit_image_print(const void *fit, int noffset, const char *p);
905
906
907
908
909
910
911
912
913static inline ulong fit_get_size(const void *fit)
914{
915 return fdt_totalsize(fit);
916}
917
918
919
920
921
922
923
924
925ulong fit_get_end(const void *fit);
926
927
928
929
930
931
932
933
934
935static inline const char *fit_get_name(const void *fit_hdr,
936 int noffset, int *len)
937{
938 return fdt_get_name(fit_hdr, noffset, len);
939}
940
941int fit_get_desc(const void *fit, int noffset, char **desc);
942int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
943
944int fit_image_get_node(const void *fit, const char *image_uname);
945int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
946int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
947int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
948int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
949int fit_image_get_load(const void *fit, int noffset, ulong *load);
950int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
951int fit_image_get_data(const void *fit, int noffset,
952 const void **data, size_t *size);
953
954int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
955int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
956 int *value_len);
957
958int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
980 const char *comment, int require_keys);
981
982int fit_image_verify(const void *fit, int noffset);
983int fit_config_verify(const void *fit, int conf_noffset);
984int fit_all_image_verify(const void *fit);
985int fit_image_check_os(const void *fit, int noffset, uint8_t os);
986int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
987int fit_image_check_type(const void *fit, int noffset, uint8_t type);
988int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
989int fit_check_format(const void *fit);
990
991int fit_conf_find_compat(const void *fit, const void *fdt);
992int fit_conf_get_node(const void *fit, const char *conf_uname);
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005int fit_conf_get_prop_node(const void *fit, int noffset,
1006 const char *prop_name);
1007
1008void fit_conf_print(const void *fit, int noffset, const char *p);
1009
1010int fit_check_ramdisk(const void *fit, int os_noffset,
1011 uint8_t arch, int verify);
1012
1013int calculate_hash(const void *data, int data_len, const char *algo,
1014 uint8_t *value, int *value_len);
1015
1016
1017
1018
1019
1020#if defined(CONFIG_FIT_SIGNATURE)
1021# ifdef USE_HOSTCC
1022# define IMAGE_ENABLE_SIGN 1
1023# define IMAGE_ENABLE_VERIFY 1
1024# include <openssl/evp.h>
1025#else
1026# define IMAGE_ENABLE_SIGN 0
1027# define IMAGE_ENABLE_VERIFY 1
1028# endif
1029#else
1030# define IMAGE_ENABLE_SIGN 0
1031# define IMAGE_ENABLE_VERIFY 0
1032#endif
1033
1034#ifdef USE_HOSTCC
1035void *image_get_host_blob(void);
1036void image_set_host_blob(void *host_blob);
1037# define gd_fdt_blob() image_get_host_blob()
1038#else
1039# define gd_fdt_blob() (gd->fdt_blob)
1040#endif
1041
1042#ifdef CONFIG_FIT_BEST_MATCH
1043#define IMAGE_ENABLE_BEST_MATCH 1
1044#else
1045#define IMAGE_ENABLE_BEST_MATCH 0
1046#endif
1047
1048
1049struct image_sign_info {
1050 const char *keydir;
1051 const char *keyname;
1052 void *fit;
1053 int node_offset;
1054 const char *name;
1055 struct checksum_algo *checksum;
1056 struct crypto_algo *crypto;
1057 const void *fdt_blob;
1058 int required_keynode;
1059 const char *require_keys;
1060};
1061#endif
1062
1063
1064struct image_region {
1065 const void *data;
1066 int size;
1067};
1068
1069#if IMAGE_ENABLE_FIT
1070
1071#if IMAGE_ENABLE_VERIFY
1072# include <u-boot/rsa-checksum.h>
1073#endif
1074struct checksum_algo {
1075 const char *name;
1076 const int checksum_len;
1077 const int der_len;
1078 const uint8_t *der_prefix;
1079#if IMAGE_ENABLE_SIGN
1080 const EVP_MD *(*calculate_sign)(void);
1081#endif
1082 int (*calculate)(const char *name,
1083 const struct image_region region[],
1084 int region_count, uint8_t *checksum);
1085};
1086
1087struct crypto_algo {
1088 const char *name;
1089 const int key_len;
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108 int (*sign)(struct image_sign_info *info,
1109 const struct image_region region[],
1110 int region_count, uint8_t **sigp, uint *sig_len);
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123 int (*add_verify_data)(struct image_sign_info *info, void *keydest);
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135 int (*verify)(struct image_sign_info *info,
1136 const struct image_region region[], int region_count,
1137 uint8_t *sig, uint sig_len);
1138};
1139
1140
1141
1142
1143
1144
1145
1146struct checksum_algo *image_get_checksum_algo(const char *full_name);
1147
1148
1149
1150
1151
1152
1153
1154struct crypto_algo *image_get_crypto_algo(const char *full_name);
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170int fit_image_verify_required_sigs(const void *fit, int image_noffset,
1171 const char *data, size_t size, const void *sig_blob,
1172 int *no_sigsp);
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189int fit_image_check_sig(const void *fit, int noffset, const void *data,
1190 size_t size, int required_keynode, char **err_msgp);
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205struct image_region *fit_region_make_list(const void *fit,
1206 struct fdt_region *fdt_regions, int count,
1207 struct image_region *region);
1208
1209static inline int fit_image_check_target_arch(const void *fdt, int node)
1210{
1211#ifndef USE_HOSTCC
1212 return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
1213#else
1214 return 0;
1215#endif
1216}
1217
1218#ifdef CONFIG_FIT_VERBOSE
1219#define fit_unsupported(msg) printf("! %s:%d " \
1220 "FIT images not supported for '%s'\n", \
1221 __FILE__, __LINE__, (msg))
1222
1223#define fit_unsupported_reset(msg) printf("! %s:%d " \
1224 "FIT images not supported for '%s' " \
1225 "- must reset board to recover!\n", \
1226 __FILE__, __LINE__, (msg))
1227#else
1228#define fit_unsupported(msg)
1229#define fit_unsupported_reset(msg)
1230#endif
1231#endif
1232
1233#if defined(CONFIG_ANDROID_BOOT_IMAGE)
1234struct andr_img_hdr;
1235int android_image_check_header(const struct andr_img_hdr *hdr);
1236int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
1237 ulong *os_data, ulong *os_len);
1238int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
1239 ulong *rd_data, ulong *rd_len);
1240ulong android_image_get_end(const struct andr_img_hdr *hdr);
1241ulong android_image_get_kload(const struct andr_img_hdr *hdr);
1242void android_print_contents(const struct andr_img_hdr *hdr);
1243
1244#endif
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257int board_fit_config_name_match(const char *name);
1258
1259#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273void board_fit_image_post_process(void **p_image, size_t *p_size);
1274#endif
1275
1276
1277
1278
1279
1280
1281
1282
1283struct fit_loadable_tbl {
1284 int type;
1285
1286
1287
1288
1289
1290
1291 void (*handler)(ulong data, size_t size);
1292};
1293
1294
1295
1296
1297
1298
1299
1300#define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
1301 ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
1302 .type = _type, \
1303 .handler = _handler, \
1304 }
1305
1306#endif
1307