3 // 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
15 #include <linux/types.h>
24 } __attribute__ ((__packed__));
26 /* __u32 cm_clksel_core;
28 __u32 cm_autoidle_dpll_mpu;
29 __u32 cm_clksel_dpll_mpu;
30 __u32 cm_div_m2_dpll_mpu;
31 __u32 cm_autoidle_dpll_core;
32 __u32 cm_clksel_dpll_core;
33 __u32 cm_div_m2_dpll_core;
34 __u32 cm_div_m3_dpll_core;
35 __u32 cm_div_m4_dpll_core;
36 __u32 cm_div_m5_dpll_core;
37 __u32 cm_div_m6_dpll_core;
38 __u32 cm_div_m7_dpll_core;
39 __u32 cm_autoidle_dpll_per;
40 __u32 cm_clksel_dpll_per;
41 __u32 cm_div_m2_dpll_per;
42 __u32 cm_div_m3_dpll_per;
43 __u32 cm_div_m4_dpll_per;
44 __u32 cm_div_m5_dpll_per;
45 __u32 cm_div_m6_dpll_per;
46 __u32 cm_div_m7_dpll_per;
47 __u32 cm_autoidle_dpll_usb;
48 __u32 cm_clksel_dpll_usb;
49 __u32 cm_div_m2_dpll_usb;
55 } __attribute__ ((__packed__));
61 __u8 section_name[12];
62 } __attribute__ ((__packed__));
66 __u32 section_key_chr;
67 __u8 section_disable_chr;
75 __u32 pwrControl_emif1;
76 __u32 phy_cntr1_emif1;
77 __u32 phy_cntr2_emif1;
88 __u32 pwrControl_emif2;
89 __u32 phy_cntr1_emif2;
90 __u32 phy_cntr2_emif2;
99 } __attribute__ ((__packed__));
102 struct ch_chsettings_chram {
103 struct ch_toc toc_chsettings;
104 struct ch_toc toc_chram;
105 struct ch_toc toc_terminator;
106 struct chsettings section_chsettings;
107 struct chram section_chram;
109 (sizeof(struct ch_toc) * 3 +
110 sizeof(struct chsettings) + sizeof(struct chram))];
111 //struct gp_header gpheader;
112 } __attribute__ ((__packed__));
114 struct ch_chsettings_nochram {
115 struct ch_toc toc_chsettings;
116 struct ch_toc toc_terminator;
117 struct chsettings section_chsettings;
119 (sizeof(struct ch_toc) * 2 +
120 sizeof(struct chsettings))];
121 //struct gp_header gpheader;
122 } __attribute__ ((__packed__));
126 const struct ch_chsettings_chram config_header = {
128 {sizeof(struct ch_toc) * 4,
129 sizeof(struct chsettings),
134 {sizeof(struct ch_toc) * 4 + sizeof(struct chsettings),
135 sizeof(struct chram),
142 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
144 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
196 struct ch_chsettings_nochram config_header __attribute__((section(".config_header"))) = {
198 {(sizeof(struct ch_toc)) * 2,
199 sizeof(struct chsettings),
206 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
208 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
223 main(int argc, char *argv[])
226 char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
228 unsigned long loadaddr, len;
232 // Default to x-load.bin and 0x40200800.
233 strcpy(ifname, "x-load.bin");
234 loadaddr = 0x40200800;
236 if ((argc == 2) || (argc == 3))
237 strcpy(ifname, argv[1]);
240 loadaddr = strtoul(argv[2], NULL, 16);
242 // Form the output file name.
243 strcpy(ofname, ifname);
244 strcat(ofname, ".ift");
246 // Open the input file.
247 ifile = fopen(ifname, "rb");
249 printf("Cannot open %s\n", ifname);
254 stat(ifname, &sinfo);
257 // Open the output file and write it.
258 ofile = fopen(ofname, "wb");
260 printf("Cannot open %s\n", ofname);
265 // Pad 1 sector of zeroes.
267 //for (i=0; i<0x200; i++)
268 // fwrite(&ch, 1, 1, ofile);
270 fwrite(&config_header, 1, 512, ofile);
271 fwrite(&len, 1, 4, ofile);
272 fwrite(&loadaddr, 1, 4, ofile);
273 for (i=0; i<len; i++) {
274 fread(&ch, 1, 1, ifile);
275 fwrite(&ch, 1, 1, ofile);