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/>.
31 #include <linux/types.h>
40 } __attribute__ ((__packed__));
42 /* __u32 cm_clksel_core;
44 __u32 cm_autoidle_dpll_mpu;
45 __u32 cm_clksel_dpll_mpu;
46 __u32 cm_div_m2_dpll_mpu;
47 __u32 cm_autoidle_dpll_core;
48 __u32 cm_clksel_dpll_core;
49 __u32 cm_div_m2_dpll_core;
50 __u32 cm_div_m3_dpll_core;
51 __u32 cm_div_m4_dpll_core;
52 __u32 cm_div_m5_dpll_core;
53 __u32 cm_div_m6_dpll_core;
54 __u32 cm_div_m7_dpll_core;
55 __u32 cm_autoidle_dpll_per;
56 __u32 cm_clksel_dpll_per;
57 __u32 cm_div_m2_dpll_per;
58 __u32 cm_div_m3_dpll_per;
59 __u32 cm_div_m4_dpll_per;
60 __u32 cm_div_m5_dpll_per;
61 __u32 cm_div_m6_dpll_per;
62 __u32 cm_div_m7_dpll_per;
63 __u32 cm_autoidle_dpll_usb;
64 __u32 cm_clksel_dpll_usb;
65 __u32 cm_div_m2_dpll_usb;
71 } __attribute__ ((__packed__));
77 __u8 section_name[12];
78 } __attribute__ ((__packed__));
82 __u32 section_key_chr;
83 __u8 section_disable_chr;
91 __u32 pwrControl_emif1;
92 __u32 phy_cntr1_emif1;
93 __u32 phy_cntr2_emif1;
104 __u32 pwrControl_emif2;
105 __u32 phy_cntr1_emif2;
106 __u32 phy_cntr2_emif2;
115 } __attribute__ ((__packed__));
118 struct ch_chsettings_chram {
119 struct ch_toc toc_chsettings;
120 struct ch_toc toc_chram;
121 struct ch_toc toc_terminator;
122 struct chsettings section_chsettings;
123 struct chram section_chram;
125 (sizeof(struct ch_toc) * 3 +
126 sizeof(struct chsettings) + sizeof(struct chram))];
127 /* struct gp_header gpheader; */
128 } __attribute__ ((__packed__));
130 struct ch_chsettings_nochram {
131 struct ch_toc toc_chsettings;
132 struct ch_toc toc_terminator;
133 struct chsettings section_chsettings;
135 (sizeof(struct ch_toc) * 2 +
136 sizeof(struct chsettings))];
137 /* struct gp_header gpheader; */
138 } __attribute__ ((__packed__));
142 static const struct ch_chsettings_chram config_header = {
144 {sizeof(struct ch_toc) * 4,
145 sizeof(struct chsettings),
150 {sizeof(struct ch_toc) * 4 + sizeof(struct chsettings),
151 sizeof(struct chram),
158 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
160 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
163 /* CHSETTINGS section */
212 static struct ch_chsettings_nochram config_header
213 __attribute__((section(".config_header"))) = {
215 {(sizeof(struct ch_toc)) * 2,
216 sizeof(struct chsettings),
223 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
225 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
228 /* CHSETTINGS section */
240 #define err(...) do { int save_errno = errno; \
241 fprintf(stderr, __VA_ARGS__); \
242 errno = save_errno; \
244 #define pdie(func, ...) do { perror(func); exit(1); } while (0);
246 int main(int argc, char *argv[])
249 char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
251 unsigned long loadaddr, len;
256 /* Default to x-load.bin and 0x40200800. */
257 strcpy(ifname, "x-load.bin");
258 loadaddr = 0x40200800;
260 if ((argc == 2) || (argc == 3) || (argc == 4))
261 strcpy(ifname, argv[1]);
263 if ((argc == 3) || (argc == 4))
264 loadaddr = strtoul(argv[2], NULL, 16);
267 ch_add = strtoul(argv[3], NULL, 16);
269 /* Form the output file name. */
270 strcpy(ofname, ifname);
271 strcat(ofname, ".ift");
273 /* Open the input file. */
274 ifile = fopen(ifname, "rb");
276 err("Cannot open %s\n", ifname);
280 /* Get file length. */
281 stat(ifname, &sinfo);
284 /* Open the output file and write it. */
285 ofile = fopen(ofname, "wb");
288 err("Cannot open %s\n", ofname);
293 if (fwrite(&config_header, 1, 512, ofile) <= 0)
296 if (fwrite(&len, 1, 4, ofile) <= 0)
298 if (fwrite(&loadaddr, 1, 4, ofile) <= 0)
300 for (i = 0; i < len; i++) {
301 if (fread(&ch, 1, 1, ifile) <= 0)
303 if (fwrite(&ch, 1, 1, ofile) <= 0)
308 perror("warning: fclose");
310 perror("warning: fclose");