3 * Linaro LTD, www.linaro.org
4 * Author: John Rigby <john.rigby@linaro.org>
5 * Based on TI's signGP.c
8 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
11 * Marvell Semiconductor <www.marvell.com>
12 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
14 * SPDX-License-Identifier: GPL-2.0+
17 #include "imagetool.h"
21 #include "omapimage.h"
23 /* Header size is CH header rounded up to 512 bytes plus GP header */
24 #define OMAP_CH_HDR_SIZE 512
25 #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE)
27 static int do_swap32
= 0;
29 static uint8_t omapimage_header
[OMAP_FILE_HDR_SIZE
];
31 static int omapimage_check_image_types(uint8_t type
)
33 if (type
== IH_TYPE_OMAPIMAGE
)
38 static int omapimage_verify_header(unsigned char *ptr
, int image_size
,
39 struct image_tool_params
*params
)
41 struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
42 struct gp_header
*gph
= (struct gp_header
*)(ptr
+OMAP_CH_HDR_SIZE
);
43 uint32_t offset
, size
;
45 while (toc
->section_offset
!= 0xffffffff
46 && toc
->section_size
!= 0xffffffff) {
48 offset
= cpu_to_be32(toc
->section_offset
);
49 size
= cpu_to_be32(toc
->section_size
);
51 offset
= toc
->section_offset
;
52 size
= toc
->section_size
;
56 if (offset
>= OMAP_CH_HDR_SIZE
||
57 offset
+size
>= OMAP_CH_HDR_SIZE
)
62 return gph_verify_header(gph
, do_swap32
);
65 static void omapimage_print_section(struct ch_settings
*chs
)
67 const char *section_name
;
70 section_name
= "CHSETTINGS";
72 section_name
= "UNKNOWNKEY";
87 static void omapimage_print_header(const void *ptr
)
89 const struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
90 const struct gp_header
*gph
=
91 (struct gp_header
*)(ptr
+OMAP_CH_HDR_SIZE
);
92 uint32_t offset
, size
;
94 while (toc
->section_offset
!= 0xffffffff
95 && toc
->section_size
!= 0xffffffff) {
97 offset
= cpu_to_be32(toc
->section_offset
);
98 size
= cpu_to_be32(toc
->section_size
);
100 offset
= toc
->section_offset
;
101 size
= toc
->section_size
;
104 if (offset
>= OMAP_CH_HDR_SIZE
||
105 offset
+size
>= OMAP_CH_HDR_SIZE
)
108 printf("Section %s offset %x length %x\n",
113 omapimage_print_section((struct ch_settings
*)(ptr
+offset
));
117 gph_print_header(gph
, do_swap32
);
120 static int toc_offset(void *hdr
, void *member
)
125 static void omapimage_set_header(void *ptr
, struct stat
*sbuf
, int ifd
,
126 struct image_tool_params
*params
)
128 struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
129 struct ch_settings
*chs
= (struct ch_settings
*)
130 (ptr
+ 2 * sizeof(*toc
));
131 struct gp_header
*gph
= (struct gp_header
*)(ptr
+ OMAP_CH_HDR_SIZE
);
133 toc
->section_offset
= toc_offset(ptr
, chs
);
134 toc
->section_size
= sizeof(struct ch_settings
);
135 strcpy((char *)toc
->section_name
, "CHSETTINGS");
137 chs
->section_key
= KEY_CHSETTINGS
;
144 memset(toc
, 0xff, sizeof(*toc
));
146 gph_set_header(gph
, sbuf
->st_size
- OMAP_FILE_HDR_SIZE
,
149 if (strncmp(params
->imagename
, "byteswap", 8) == 0) {
152 uint32_t *data
= (uint32_t *)ptr
;
154 while (swapped
<= (sbuf
->st_size
/ sizeof(uint32_t))) {
155 *data
= cpu_to_be32(*data
);
163 * omapimage parameters
165 static struct image_type_params omapimage_params
= {
166 .name
= "TI OMAP CH/GP Boot Image support",
167 .header_size
= OMAP_FILE_HDR_SIZE
,
168 .hdr
= (void *)&omapimage_header
,
169 .check_image_type
= omapimage_check_image_types
,
170 .verify_header
= omapimage_verify_header
,
171 .print_header
= omapimage_print_header
,
172 .set_header
= omapimage_set_header
,
173 .check_params
= gpimage_check_params
,
176 void init_omap_image_type(void)
178 register_image_type(&omapimage_params
);