1 // SPDX-License-Identifier: GPL-2.0+
4 * Linaro LTD, www.linaro.org
5 * Author: John Rigby <john.rigby@linaro.org>
6 * Based on TI's signGP.c
9 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
12 * Marvell Semiconductor <www.marvell.com>
13 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
16 #include "imagetool.h"
20 #include "omapimage.h"
22 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
24 /* Header size is CH header rounded up to 512 bytes plus GP header */
25 #define OMAP_CH_HDR_SIZE 512
26 #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE)
28 static int do_swap32 = 0;
30 static uint8_t omapimage_header[OMAP_FILE_HDR_SIZE];
32 static int omapimage_check_image_types(uint8_t type)
34 if (type == IH_TYPE_OMAPIMAGE)
39 static int omapimage_verify_header(unsigned char *ptr, int image_size,
40 struct image_tool_params *params)
42 struct ch_toc *toc = (struct ch_toc *)ptr;
43 struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
44 uint32_t offset, size;
46 while (toc->section_offset != 0xffffffff
47 && toc->section_size != 0xffffffff) {
49 offset = cpu_to_be32(toc->section_offset);
50 size = cpu_to_be32(toc->section_size);
52 offset = toc->section_offset;
53 size = toc->section_size;
57 if (offset >= OMAP_CH_HDR_SIZE ||
58 offset+size >= OMAP_CH_HDR_SIZE)
63 return gph_verify_header(gph, do_swap32);
66 static void omapimage_print_section(struct ch_settings *chs)
68 const char *section_name;
71 section_name = "CHSETTINGS";
73 section_name = "UNKNOWNKEY";
88 static void omapimage_print_header(const void *ptr)
90 const struct ch_toc *toc = (struct ch_toc *)ptr;
91 const struct gp_header *gph =
92 (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
93 uint32_t offset, size;
95 while (toc->section_offset != 0xffffffff
96 && toc->section_size != 0xffffffff) {
98 offset = cpu_to_be32(toc->section_offset);
99 size = cpu_to_be32(toc->section_size);
101 offset = toc->section_offset;
102 size = toc->section_size;
105 if (offset >= OMAP_CH_HDR_SIZE ||
106 offset+size >= OMAP_CH_HDR_SIZE)
109 printf("Section %s offset %x length %x\n",
114 omapimage_print_section((struct ch_settings *)(ptr+offset));
118 gph_print_header(gph, do_swap32);
121 static int toc_offset(void *hdr, void *member)
126 static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
127 struct image_tool_params *params)
129 struct ch_toc *toc = (struct ch_toc *)ptr;
130 struct ch_settings *chs = (struct ch_settings *)
131 (ptr + 2 * sizeof(*toc));
132 struct gp_header *gph = (struct gp_header *)(ptr + OMAP_CH_HDR_SIZE);
134 toc->section_offset = toc_offset(ptr, chs);
135 toc->section_size = sizeof(struct ch_settings);
136 strcpy((char *)toc->section_name, "CHSETTINGS");
138 chs->section_key = KEY_CHSETTINGS;
145 memset(toc, 0xff, sizeof(*toc));
147 gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE,
150 if (strncmp(params->imagename, "byteswap", 8) == 0) {
153 uint32_t *data = (uint32_t *)ptr;
154 const off_t size_in_words =
155 DIV_ROUND_UP(sbuf->st_size, sizeof(uint32_t));
157 while (swapped < size_in_words) {
158 *data = cpu_to_be32(*data);
166 * omapimage parameters
170 "TI OMAP CH/GP Boot Image support",
172 (void *)&omapimage_header,
173 gpimage_check_params,
174 omapimage_verify_header,
175 omapimage_print_header,
176 omapimage_set_header,
178 omapimage_check_image_types,