7 void xlate( char * inb
, char * trb
, unsigned len
)
10 for ( i
=0; i
<len
; ++i
) {
28 #define ElfHeaderSize (64 * 1024)
29 #define ElfPages (ElfHeaderSize / 4096)
30 #define KERNELBASE (0xc0000000)
32 void get4k( /*istream *inf*/FILE *file
, char *buf
)
35 unsigned num
= fread(buf
, 1, 4096, file
);
36 for ( j
=num
; j
<4096; ++j
)
40 void put4k( /*ostream *outf*/FILE *file
, char *buf
)
42 fwrite(buf
, 1, 4096, file
);
45 int main(int argc
, char **argv
)
49 FILE *inputVmlinux
= NULL
;
50 FILE *outputVmlinux
= NULL
;
52 unsigned long ramFileLen
= 0;
53 unsigned long ramLen
= 0;
54 unsigned long roundR
= 0;
55 unsigned long kernelLen
= 0;
56 unsigned long actualKernelLen
= 0;
57 unsigned long round
= 0;
58 unsigned long roundedKernelLen
= 0;
59 unsigned long ramStartOffs
= 0;
60 unsigned long ramPages
= 0;
61 unsigned long roundedKernelPages
= 0;
63 printf("Name of System Map file missing.\n");
68 printf("Name of vmlinux file missing.\n");
73 printf("Name of vmlinux output file missing.\n");
77 ramDisk
= fopen(argv
[1], "r");
79 printf("System Map file \"%s\" failed to open.\n", argv
[1]);
82 inputVmlinux
= fopen(argv
[2], "r");
83 if ( ! inputVmlinux
) {
84 printf("vmlinux file \"%s\" failed to open.\n", argv
[2]);
87 outputVmlinux
= fopen(argv
[3], "w");
88 if ( ! outputVmlinux
) {
89 printf("output vmlinux file \"%s\" failed to open.\n", argv
[3]);
92 fseek(ramDisk
, 0, SEEK_END
);
93 ramFileLen
= ftell(ramDisk
);
94 fseek(ramDisk
, 0, SEEK_SET
);
95 printf("%s file size = %ld\n", argv
[1], ramFileLen
);
99 roundR
= 4096 - (ramLen
% 4096);
101 printf("Rounding System Map file up to a multiple of 4096, adding %ld\n", roundR
);
105 printf("Rounded System Map size is %ld\n", ramLen
);
106 fseek(inputVmlinux
, 0, SEEK_END
);
107 kernelLen
= ftell(inputVmlinux
);
108 fseek(inputVmlinux
, 0, SEEK_SET
);
109 printf("kernel file size = %ld\n", kernelLen
);
110 if ( kernelLen
== 0 ) {
111 printf("You must have a linux kernel specified as argv[2]\n");
115 actualKernelLen
= kernelLen
- ElfHeaderSize
;
117 printf("actual kernel length (minus ELF header) = %ld\n", actualKernelLen
);
119 round
= actualKernelLen
% 4096;
120 roundedKernelLen
= actualKernelLen
;
122 roundedKernelLen
+= (4096 - round
);
124 printf("actual kernel length rounded up to a 4k multiple = %ld\n", roundedKernelLen
);
126 ramStartOffs
= roundedKernelLen
;
127 ramPages
= ramLen
/ 4096;
129 printf("System map pages to copy = %ld\n", ramPages
);
131 // Copy 64K ELF header
132 for (i
=0; i
<(ElfPages
); ++i
) {
133 get4k( inputVmlinux
, inbuf
);
134 put4k( outputVmlinux
, inbuf
);
139 roundedKernelPages
= roundedKernelLen
/ 4096;
141 fseek(inputVmlinux
, ElfHeaderSize
, SEEK_SET
);
144 for ( i
=0; i
<roundedKernelPages
; ++i
) {
145 get4k( inputVmlinux
, inbuf
);
148 printf("Storing embedded_sysmap_start at 0x3c\n");
149 p
= (unsigned long *)(inbuf
+ 0x3c);
151 #if (BYTE_ORDER == __BIG_ENDIAN)
154 *p
= bswap_32(ramStartOffs
);
157 printf("Storing embedded_sysmap_end at 0x44\n");
158 p
= (unsigned long *)(inbuf
+ 0x44);
159 #if (BYTE_ORDER == __BIG_ENDIAN)
160 *p
= ramStartOffs
+ ramFileLen
;
162 *p
= bswap_32(ramStartOffs
+ ramFileLen
);
165 put4k( outputVmlinux
, inbuf
);
170 for ( i
=0; i
<ramPages
; ++i
) {
171 get4k( ramDisk
, inbuf
);
172 put4k( outputVmlinux
, inbuf
);
178 fclose(inputVmlinux
);
179 fclose(outputVmlinux
);
180 /* Set permission to executable */
181 chmod(argv
[3], S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IXGRP
|S_IROTH
|S_IXOTH
);