2 * signGP.c - Read the x-load.bin file and write out the x-load.bin.ift file
4 * The signed image is the original pre-pended with the size of the image
5 * and the load address. If not entered on command line, file name is
6 * assumed to be x-load.bin in current directory and load address is
9 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 of
13 * the License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include <linux/types.h>
39 } __attribute__ ((__packed__));
41 /* __u32 cm_clksel_core;
43 __u32 cm_autoidle_dpll_mpu;
44 __u32 cm_clksel_dpll_mpu;
45 __u32 cm_div_m2_dpll_mpu;
46 __u32 cm_autoidle_dpll_core;
47 __u32 cm_clksel_dpll_core;
48 __u32 cm_div_m2_dpll_core;
49 __u32 cm_div_m3_dpll_core;
50 __u32 cm_div_m4_dpll_core;
51 __u32 cm_div_m5_dpll_core;
52 __u32 cm_div_m6_dpll_core;
53 __u32 cm_div_m7_dpll_core;
54 __u32 cm_autoidle_dpll_per;
55 __u32 cm_clksel_dpll_per;
56 __u32 cm_div_m2_dpll_per;
57 __u32 cm_div_m3_dpll_per;
58 __u32 cm_div_m4_dpll_per;
59 __u32 cm_div_m5_dpll_per;
60 __u32 cm_div_m6_dpll_per;
61 __u32 cm_div_m7_dpll_per;
62 __u32 cm_autoidle_dpll_usb;
63 __u32 cm_clksel_dpll_usb;
64 __u32 cm_div_m2_dpll_usb;
70 } __attribute__ ((__packed__));
76 __u8 section_name[12];
77 } __attribute__ ((__packed__));
81 __u32 section_key_chr;
82 __u8 section_disable_chr;
90 __u32 pwrControl_emif1;
91 __u32 phy_cntr1_emif1;
92 __u32 phy_cntr2_emif1;
103 __u32 pwrControl_emif2;
104 __u32 phy_cntr1_emif2;
105 __u32 phy_cntr2_emif2;
114 } __attribute__ ((__packed__));
117 struct ch_chsettings_chram {
118 struct ch_toc toc_chsettings;
119 struct ch_toc toc_chram;
120 struct ch_toc toc_terminator;
121 struct chsettings section_chsettings;
122 struct chram section_chram;
124 (sizeof(struct ch_toc) * 3 +
125 sizeof(struct chsettings) + sizeof(struct chram))];
126 /* struct gp_header gpheader; */
127 } __attribute__ ((__packed__));
129 struct ch_chsettings_nochram {
130 struct ch_toc toc_chsettings;
131 struct ch_toc toc_terminator;
132 struct chsettings section_chsettings;
134 (sizeof(struct ch_toc) * 2 +
135 sizeof(struct chsettings))];
136 /* struct gp_header gpheader; */
137 } __attribute__ ((__packed__));
141 static const struct ch_chsettings_chram config_header = {
143 {sizeof(struct ch_toc) * 4,
144 sizeof(struct chsettings),
149 {sizeof(struct ch_toc) * 4 + sizeof(struct chsettings),
150 sizeof(struct chram),
157 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
159 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
162 /* CHSETTINGS section */
211 static struct ch_chsettings_nochram config_header
212 __attribute__((section(".config_header"))) = {
214 {(sizeof(struct ch_toc)) * 2,
215 sizeof(struct chsettings),
222 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
224 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
227 /* CHSETTINGS section */
239 int main(int argc, char *argv[])
242 char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
244 unsigned long loadaddr, len;
249 /* Default to x-load.bin and 0x40200800. */
250 strcpy(ifname, "x-load.bin");
251 loadaddr = 0x40200800;
253 if ((argc == 2) || (argc == 3) || (argc == 4))
254 strcpy(ifname, argv[1]);
256 if ((argc == 3) || (argc == 4))
257 loadaddr = strtoul(argv[2], NULL, 16);
260 ch_add = strtoul(argv[3], NULL, 16);
262 /* Form the output file name. */
263 strcpy(ofname, ifname);
264 strcat(ofname, ".ift");
266 /* Open the input file. */
267 ifile = fopen(ifname, "rb");
269 printf("Cannot open %s\n", ifname);
273 /* Get file length. */
274 stat(ifname, &sinfo);
277 /* Open the output file and write it. */
278 ofile = fopen(ofname, "wb");
280 printf("Cannot open %s\n", ofname);
285 /* Pad 1 sector of zeroes. */
288 for (i = 0; i < 0x200; i++)
289 fwrite(&ch, 1, 1, ofile);
293 fwrite(&config_header, 1, 512, ofile);
295 fwrite(&len, 1, 4, ofile);
296 fwrite(&loadaddr, 1, 4, ofile);
297 for (i = 0; i < len; i++) {
298 fread(&ch, 1, 1, ifile);
299 fwrite(&ch, 1, 1, ofile);