Linux-2.6.12-rc2
[linux-2.6] / arch / ppc64 / boot / piggyback.c
1 /*
2  * Copyright 2001 IBM Corp 
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <string.h>
12
13 extern long ce_exec_config[];
14
15 int main(int argc, char *argv[])
16 {
17         int i, cnt, pos, len;
18         unsigned int cksum, val;
19         unsigned char *lp;
20         unsigned char buf[8192];
21         char *varname;
22         if (argc != 2)
23         {
24                 fprintf(stderr, "usage: %s name <in-file >out-file\n",
25                         argv[0]);
26                 exit(1);
27         }
28
29         varname = strrchr(argv[1], '/');
30         if (varname)
31                 varname++;
32         else
33                 varname = argv[1];
34
35         fprintf(stdout, "#\n");
36         fprintf(stdout, "# Miscellaneous data structures:\n");
37         fprintf(stdout, "# WARNING - this file is automatically generated!\n");
38         fprintf(stdout, "#\n");
39         fprintf(stdout, "\n");
40         fprintf(stdout, "\t.data\n");
41         fprintf(stdout, "\t.globl %s_data\n", varname);
42         fprintf(stdout, "%s_data:\n", varname);
43         pos = 0;
44         cksum = 0;
45         while ((len = read(0, buf, sizeof(buf))) > 0)
46         {
47                 cnt = 0;
48                 lp = (unsigned char *)buf;
49                 len = (len + 3) & ~3;  /* Round up to longwords */
50                 for (i = 0;  i < len;  i += 4)
51                 {
52                         if (cnt == 0)
53                         {
54                                 fprintf(stdout, "\t.long\t");
55                         }
56                         fprintf(stdout, "0x%02X%02X%02X%02X", lp[0], lp[1], lp[2], lp[3]);
57                         val = *(unsigned long *)lp;
58                         cksum ^= val;
59                         lp += 4;
60                         if (++cnt == 4)
61                         {
62                                 cnt = 0;
63                                 fprintf(stdout, " # %x \n", pos+i-12);
64                                 fflush(stdout);
65                         } else
66                         {
67                                 fprintf(stdout, ",");
68                         }
69                 }
70                 if (cnt)
71                 {
72                         fprintf(stdout, "0\n");
73                 }
74                 pos += len;
75         }
76         fprintf(stdout, "\t.globl %s_len\n", varname);
77         fprintf(stdout, "%s_len:\t.long\t0x%x\n", varname, pos);
78         fflush(stdout);
79         fclose(stdout);
80         fprintf(stderr, "cksum = %x\n", cksum);
81         exit(0);
82 }
83