]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/meta-ti-glsdk.git/blob - recipes-bsp/x-load/signgp/signGP.c
recipes-kernel: Add GLSDK specific kernel tree for omap-a15
[glsdk/meta-ti-glsdk.git] / recipes-bsp / x-load / signgp / signGP.c
1 /*
2  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *    Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *    Neither the name of Texas Instruments Incorporated nor the names of
18  *    its contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33 */
36 //
37 // signGP.c
38 // Read the x-load.bin file and write out the x-load.bin.ift file.
39 // The signed image is the original pre-pended with the size of the image
40 // and the load address.  If not entered on command line, file name is
41 // assumed to be x-load.bin in current directory and load address is
42 // 0x40200800.
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <fcntl.h>
47 #include <sys/stat.h>
48 #include <string.h>
49 #include <malloc.h>
52 main(int argc, char *argv[])
53 {
54         int     i;
55         char    ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
56         FILE    *ifile, *ofile;
57         unsigned long   loadaddr, len;
58         struct stat     sinfo;
61         // Default to x-load.bin and 0x40200800.
62         strcpy(ifname, "x-load.bin");
63         loadaddr = 0x40200800;
65         if ((argc == 2) || (argc == 3))
66                 strcpy(ifname, argv[1]);
68         if (argc == 3)
69                 loadaddr = strtol(argv[2], NULL, 16);
71         // Form the output file name.
72         strcpy(ofname, ifname);
73         strcat(ofname, ".ift");
75         // Open the input file.
76         ifile = fopen(ifname, "rb");
77         if (ifile == NULL) {
78                 printf("Cannot open %s\n", ifname);
79                 exit(0);
80         }
82         // Get file length.
83         stat(ifname, &sinfo);
84         len = sinfo.st_size;
86         // Open the output file and write it.
87         ofile = fopen(ofname, "wb");
88         if (ofile == NULL) {
89                 printf("Cannot open %s\n", ofname);
90                 fclose(ifile);
91                 exit(0);
92         }
94         // Pad 1 sector of zeroes.
95         //ch = 0x00;
96         //for (i=0; i<0x200; i++)
97         //      fwrite(&ch, 1, 1, ofile);
99         fwrite(&len, 1, 4, ofile);
100         fwrite(&loadaddr, 1, 4, ofile);
101         for (i=0; i<len; i++) {
102                 fread(&ch, 1, 1, ifile);
103                 fwrite(&ch, 1, 1, ofile);
104         }
106         fclose(ifile);
107         fclose(ofile);