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