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