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