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 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 struct ch_chsettings_nochram config_header __attribute__((section(".config_header"))) = {
213 {(sizeof(struct ch_toc)) * 2,
214 sizeof(struct chsettings),
221 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
223 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
226 /* CHSETTINGS section */
238 int main(int argc, char *argv[])
241 char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
243 unsigned long loadaddr, len;
247 /* Default to x-load.bin and 0x40200800. */
248 strcpy(ifname, "x-load.bin");
249 loadaddr = 0x40200800;
251 if ((argc == 2) || (argc == 3))
252 strcpy(ifname, argv[1]);
255 loadaddr = strtoul(argv[2], NULL, 16);
257 /* Form the output file name. */
258 strcpy(ofname, ifname);
259 strcat(ofname, ".ift");
261 /* Open the input file. */
262 ifile = fopen(ifname, "rb");
264 printf("Cannot open %s\n", ifname);
268 /* Get file length. */
269 stat(ifname, &sinfo);
272 /* Open the output file and write it. */
273 ofile = fopen(ofname, "wb");
275 printf("Cannot open %s\n", ofname);
280 /* Pad 1 sector of zeroes. */
283 for (i = 0; i < 0x200; i++)
284 fwrite(&ch, 1, 1, ofile);
287 fwrite(&config_header, 1, 512, ofile);
288 fwrite(&len, 1, 4, ofile);
289 fwrite(&loadaddr, 1, 4, ofile);
290 for (i=0; i<len; i++) {
291 fread(&ch, 1, 1, ifile);
292 fwrite(&ch, 1, 1, ofile);