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 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
25 /* Header size is CH header rounded up to 512 bytes plus GP header */
26 #define OMAP_CH_HDR_SIZE 512
27 #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE)
29 static int do_swap32 = 0;
31 static uint8_t omapimage_header[OMAP_FILE_HDR_SIZE];
33 static int omapimage_check_image_types(uint8_t type)
35 if (type == IH_TYPE_OMAPIMAGE)
40 static int omapimage_verify_header(unsigned char *ptr, int image_size,
41 struct image_tool_params *params)
43 struct ch_toc *toc = (struct ch_toc *)ptr;
44 struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
45 uint32_t offset, size;
47 while (toc->section_offset != 0xffffffff
48 && toc->section_size != 0xffffffff) {
50 offset = cpu_to_be32(toc->section_offset);
51 size = cpu_to_be32(toc->section_size);
53 offset = toc->section_offset;
54 size = toc->section_size;
58 if (offset >= OMAP_CH_HDR_SIZE ||
59 offset+size >= OMAP_CH_HDR_SIZE)
64 return gph_verify_header(gph, do_swap32);
67 static void omapimage_print_section(struct ch_settings *chs)
69 const char *section_name;
72 section_name = "CHSETTINGS";
74 section_name = "UNKNOWNKEY";
89 static void omapimage_print_header(const void *ptr)
91 const struct ch_toc *toc = (struct ch_toc *)ptr;
92 const struct gp_header *gph =
93 (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
94 uint32_t offset, size;
96 while (toc->section_offset != 0xffffffff
97 && toc->section_size != 0xffffffff) {
99 offset = cpu_to_be32(toc->section_offset);
100 size = cpu_to_be32(toc->section_size);
102 offset = toc->section_offset;
103 size = toc->section_size;
106 if (offset >= OMAP_CH_HDR_SIZE ||
107 offset+size >= OMAP_CH_HDR_SIZE)
110 printf("Section %s offset %x length %x\n",
115 omapimage_print_section((struct ch_settings *)(ptr+offset));
119 gph_print_header(gph, do_swap32);
122 static int toc_offset(void *hdr, void *member)
127 static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
128 struct image_tool_params *params)
130 struct ch_toc *toc = (struct ch_toc *)ptr;
131 struct ch_settings *chs = (struct ch_settings *)
132 (ptr + 2 * sizeof(*toc));
133 struct gp_header *gph = (struct gp_header *)(ptr + OMAP_CH_HDR_SIZE);
135 toc->section_offset = toc_offset(ptr, chs);
136 toc->section_size = sizeof(struct ch_settings);
137 strcpy((char *)toc->section_name, "CHSETTINGS");
139 chs->section_key = KEY_CHSETTINGS;
146 memset(toc, 0xff, sizeof(*toc));
148 gph_set_header(gph, sbuf->st_size - OMAP_CH_HDR_SIZE,
151 if (strncmp(params->imagename, "byteswap", 8) == 0) {
154 uint32_t *data = (uint32_t *)ptr;
155 const off_t size_in_words =
156 DIV_ROUND_UP(sbuf->st_size, sizeof(uint32_t));
158 while (swapped < size_in_words) {
159 *data = cpu_to_be32(*data);
167 * omapimage parameters
171 "TI OMAP CH/GP Boot Image support",
173 (void *)&omapimage_header,
174 gpimage_check_params,
175 omapimage_verify_header,
176 omapimage_print_header,
177 omapimage_set_header,
179 omapimage_check_image_types,