1
2
3
4
5
6
7
8
9
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <errno.h>
13#include <stdint.h>
14#include <stdio.h>
15#include <stdlib.h>
16
17int main(int argc, char *argv[])
18{
19 unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
20 struct stat sb;
21
22 if (argc != 3) {
23 fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",
24 argv[0]);
25 return EXIT_FAILURE;
26 }
27
28 if (stat(argv[1], &sb) == -1) {
29 perror("stat");
30 return EXIT_FAILURE;
31 }
32
33
34 errno = 0;
35 if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
36 if (errno != 0)
37 perror("sscanf");
38 else
39 fprintf(stderr, "No matching characters\n");
40
41 return EXIT_FAILURE;
42 }
43
44 vmlinux_size = (uint64_t)sb.st_size;
45 vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;
46
47
48
49
50
51
52 vmlinuz_load_addr += (16 - vmlinux_size % 16);
53
54 printf("0x%llx\n", vmlinuz_load_addr);
55
56 return EXIT_SUCCESS;
57}
58