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 * See file CREDITS for list of people who contributed to this
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 /* Required to obtain the getline prototype from stdio.h */
38 #include "omapimage.h"
40 /* Header size is CH header rounded up to 512 bytes plus GP header */
41 #define OMAP_CH_HDR_SIZE 512
42 #define OMAP_GP_HDR_SIZE (sizeof(struct gp_header))
43 #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE+OMAP_GP_HDR_SIZE)
45 static uint8_t omapimage_header
[OMAP_FILE_HDR_SIZE
];
47 static int omapimage_check_image_types(uint8_t type
)
49 if (type
== IH_TYPE_OMAPIMAGE
)
52 fprintf(stderr
, "Unknown OMAP image type - %x", type
);
58 * Only the simplest image type is currently supported:
59 * TOC pointing to CHSETTINGS
63 * padding to OMAP_CH_HDR_SIZE bytes
69 static int valid_gph_size(uint32_t size
)
74 static int valid_gph_load_addr(uint32_t load_addr
)
79 static int omapimage_verify_header(unsigned char *ptr
, int image_size
,
80 struct mkimage_params
*params
)
82 struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
83 struct gp_header
*gph
= (struct gp_header
*)(ptr
+OMAP_CH_HDR_SIZE
);
84 uint32_t offset
, size
;
86 while (toc
->section_offset
!= 0xffffffff
87 && toc
->section_size
!= 0xffffffff) {
88 offset
= toc
->section_offset
;
89 size
= toc
->section_size
;
92 if (offset
>= OMAP_CH_HDR_SIZE
||
93 offset
+size
>= OMAP_CH_HDR_SIZE
)
97 if (!valid_gph_size(gph
->size
))
99 if (!valid_gph_load_addr(gph
->load_addr
))
105 static void omapimage_print_section(struct ch_settings
*chs
)
107 const char *section_name
;
109 if (chs
->section_key
)
110 section_name
= "CHSETTINGS";
112 section_name
= "UNKNOWNKEY";
127 static void omapimage_print_header(const void *ptr
)
129 const struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
130 const struct gp_header
*gph
=
131 (struct gp_header
*)(ptr
+OMAP_CH_HDR_SIZE
);
132 uint32_t offset
, size
;
134 while (toc
->section_offset
!= 0xffffffff
135 && toc
->section_size
!= 0xffffffff) {
136 offset
= toc
->section_offset
;
137 size
= toc
->section_size
;
139 if (offset
>= OMAP_CH_HDR_SIZE
||
140 offset
+size
>= OMAP_CH_HDR_SIZE
)
143 printf("Section %s offset %x length %x\n",
148 omapimage_print_section((struct ch_settings
*)(ptr
+offset
));
152 if (!valid_gph_size(gph
->size
)) {
154 "Error: invalid image size %x\n",
159 if (!valid_gph_load_addr(gph
->load_addr
)) {
161 "Error: invalid image load address %x\n",
166 printf("GP Header: Size %x LoadAddr %x\n",
167 gph
->size
, gph
->load_addr
);
170 static int toc_offset(void *hdr
, void *member
)
175 static void omapimage_set_header(void *ptr
, struct stat
*sbuf
, int ifd
,
176 struct mkimage_params
*params
)
178 struct ch_toc
*toc
= (struct ch_toc
*)ptr
;
179 struct ch_settings
*chs
= (struct ch_settings
*)
180 (ptr
+ 2 * sizeof(*toc
));
181 struct gp_header
*gph
= (struct gp_header
*)(ptr
+ OMAP_CH_HDR_SIZE
);
183 toc
->section_offset
= toc_offset(ptr
, chs
);
184 toc
->section_size
= sizeof(struct ch_settings
);
185 strcpy((char *)toc
->section_name
, "CHSETTINGS");
187 chs
->section_key
= KEY_CHSETTINGS
;
194 memset(toc
, 0xff, sizeof(*toc
));
196 gph
->size
= sbuf
->st_size
- OMAP_FILE_HDR_SIZE
;
197 gph
->load_addr
= params
->addr
;
200 int omapimage_check_params(struct mkimage_params
*params
)
202 return (params
->dflag
&& (params
->fflag
|| params
->lflag
)) ||
203 (params
->fflag
&& (params
->dflag
|| params
->lflag
)) ||
204 (params
->lflag
&& (params
->dflag
|| params
->fflag
));
208 * omapimage parameters
210 static struct image_type_params omapimage_params
= {
211 .name
= "TI OMAP CH/GP Boot Image support",
212 .header_size
= OMAP_FILE_HDR_SIZE
,
213 .hdr
= (void *)&omapimage_header
,
214 .check_image_type
= omapimage_check_image_types
,
215 .verify_header
= omapimage_verify_header
,
216 .print_header
= omapimage_print_header
,
217 .set_header
= omapimage_set_header
,
218 .check_params
= omapimage_check_params
,
221 void init_omap_image_type(void)
223 mkimage_register(&omapimage_params
);