]>
Commit | Line | Data |
---|---|---|
3decb14a JR |
1 | /* |
2 | * (C) Copyright 2010 | |
3 | * Linaro LTD, www.linaro.org | |
4 | * Author: John Rigby <[email protected]> | |
5 | * Based on TI's signGP.c | |
6 | * | |
7 | * (C) Copyright 2009 | |
8 | * Stefano Babic, DENX Software Engineering, [email protected]. | |
9 | * | |
10 | * (C) Copyright 2008 | |
11 | * Marvell Semiconductor <www.marvell.com> | |
12 | * Written-by: Prafulla Wadaskar <[email protected]> | |
13 | * | |
3765b3e7 | 14 | * SPDX-License-Identifier: GPL-2.0+ |
3decb14a JR |
15 | */ |
16 | ||
f86ed6a8 | 17 | #include "imagetool.h" |
bf411ea9 | 18 | #include <compiler.h> |
3decb14a | 19 | #include <image.h> |
bf411ea9 | 20 | #include "gpheader.h" |
3decb14a JR |
21 | #include "omapimage.h" |
22 | ||
23 | /* Header size is CH header rounded up to 512 bytes plus GP header */ | |
24 | #define OMAP_CH_HDR_SIZE 512 | |
bf411ea9 | 25 | #define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE + GPIMAGE_HDR_SIZE) |
3decb14a | 26 | |
79b9ebb7 TR |
27 | static int do_swap32 = 0; |
28 | ||
3decb14a JR |
29 | static uint8_t omapimage_header[OMAP_FILE_HDR_SIZE]; |
30 | ||
31 | static int omapimage_check_image_types(uint8_t type) | |
32 | { | |
33 | if (type == IH_TYPE_OMAPIMAGE) | |
34 | return EXIT_SUCCESS; | |
bf411ea9 | 35 | return EXIT_FAILURE; |
3decb14a JR |
36 | } |
37 | ||
38 | static int omapimage_verify_header(unsigned char *ptr, int image_size, | |
f86ed6a8 | 39 | struct image_tool_params *params) |
3decb14a JR |
40 | { |
41 | struct ch_toc *toc = (struct ch_toc *)ptr; | |
42 | struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE); | |
bf411ea9 | 43 | uint32_t offset, size; |
3decb14a JR |
44 | |
45 | while (toc->section_offset != 0xffffffff | |
46 | && toc->section_size != 0xffffffff) { | |
79b9ebb7 | 47 | if (do_swap32) { |
bf411ea9 KM |
48 | offset = cpu_to_be32(toc->section_offset); |
49 | size = cpu_to_be32(toc->section_size); | |
79b9ebb7 TR |
50 | } else { |
51 | offset = toc->section_offset; | |
52 | size = toc->section_size; | |
53 | } | |
3decb14a JR |
54 | if (!offset || !size) |
55 | return -1; | |
56 | if (offset >= OMAP_CH_HDR_SIZE || | |
57 | offset+size >= OMAP_CH_HDR_SIZE) | |
58 | return -1; | |
59 | toc++; | |
60 | } | |
79b9ebb7 | 61 | |
bf411ea9 | 62 | return gph_verify_header(gph, do_swap32); |
3decb14a JR |
63 | } |
64 | ||
65 | static void omapimage_print_section(struct ch_settings *chs) | |
66 | { | |
67 | const char *section_name; | |
68 | ||
69 | if (chs->section_key) | |
70 | section_name = "CHSETTINGS"; | |
71 | else | |
72 | section_name = "UNKNOWNKEY"; | |
73 | ||
74 | printf("%s (%x) " | |
75 | "valid:%x " | |
76 | "version:%x " | |
77 | "reserved:%x " | |
78 | "flags:%x\n", | |
79 | section_name, | |
80 | chs->section_key, | |
81 | chs->valid, | |
82 | chs->version, | |
83 | chs->reserved, | |
84 | chs->flags); | |
85 | } | |
86 | ||
87 | static void omapimage_print_header(const void *ptr) | |
88 | { | |
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); | |
bf411ea9 | 92 | uint32_t offset, size; |
3decb14a JR |
93 | |
94 | while (toc->section_offset != 0xffffffff | |
95 | && toc->section_size != 0xffffffff) { | |
79b9ebb7 | 96 | if (do_swap32) { |
bf411ea9 KM |
97 | offset = cpu_to_be32(toc->section_offset); |
98 | size = cpu_to_be32(toc->section_size); | |
79b9ebb7 TR |
99 | } else { |
100 | offset = toc->section_offset; | |
101 | size = toc->section_size; | |
102 | } | |
3decb14a JR |
103 | |
104 | if (offset >= OMAP_CH_HDR_SIZE || | |
105 | offset+size >= OMAP_CH_HDR_SIZE) | |
106 | exit(EXIT_FAILURE); | |
107 | ||
108 | printf("Section %s offset %x length %x\n", | |
109 | toc->section_name, | |
110 | toc->section_offset, | |
111 | toc->section_size); | |
112 | ||
113 | omapimage_print_section((struct ch_settings *)(ptr+offset)); | |
114 | toc++; | |
115 | } | |
116 | ||
bf411ea9 | 117 | gph_print_header(gph, do_swap32); |
3decb14a JR |
118 | } |
119 | ||
120 | static int toc_offset(void *hdr, void *member) | |
121 | { | |
122 | return member - hdr; | |
123 | } | |
124 | ||
125 | static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd, | |
f86ed6a8 | 126 | struct image_tool_params *params) |
3decb14a JR |
127 | { |
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); | |
132 | ||
133 | toc->section_offset = toc_offset(ptr, chs); | |
134 | toc->section_size = sizeof(struct ch_settings); | |
135 | strcpy((char *)toc->section_name, "CHSETTINGS"); | |
136 | ||
137 | chs->section_key = KEY_CHSETTINGS; | |
138 | chs->valid = 0; | |
139 | chs->version = 1; | |
140 | chs->reserved = 0; | |
141 | chs->flags = 0; | |
142 | ||
143 | toc++; | |
144 | memset(toc, 0xff, sizeof(*toc)); | |
145 | ||
bf411ea9 KM |
146 | gph_set_header(gph, sbuf->st_size - OMAP_FILE_HDR_SIZE, |
147 | params->addr, 0); | |
79b9ebb7 TR |
148 | |
149 | if (strncmp(params->imagename, "byteswap", 8) == 0) { | |
150 | do_swap32 = 1; | |
151 | int swapped = 0; | |
152 | uint32_t *data = (uint32_t *)ptr; | |
153 | ||
154 | while (swapped <= (sbuf->st_size / sizeof(uint32_t))) { | |
bf411ea9 | 155 | *data = cpu_to_be32(*data); |
79b9ebb7 TR |
156 | swapped++; |
157 | data++; | |
158 | } | |
159 | } | |
3decb14a JR |
160 | } |
161 | ||
3decb14a JR |
162 | /* |
163 | * omapimage parameters | |
164 | */ | |
a93648d1 GMF |
165 | U_BOOT_IMAGE_TYPE( |
166 | omapimage, | |
167 | "TI OMAP CH/GP Boot Image support", | |
168 | OMAP_FILE_HDR_SIZE, | |
169 | (void *)&omapimage_header, | |
170 | gpimage_check_params, | |
171 | omapimage_verify_header, | |
172 | omapimage_print_header, | |
173 | omapimage_set_header, | |
174 | NULL, | |
175 | omapimage_check_image_types, | |
176 | NULL, | |
177 | NULL | |
178 | ); |