0001
0002
0003
0004
0005
0006 #include <sys/types.h>
0007 #include <sys/stat.h>
0008 #include <errno.h>
0009 #include <stdint.h>
0010 #include <stdio.h>
0011 #include <stdlib.h>
0012 #include <linux/sizes.h>
0013
0014 int main(int argc, char *argv[])
0015 {
0016 unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
0017 struct stat sb;
0018
0019 if (argc != 3) {
0020 fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",
0021 argv[0]);
0022 return EXIT_FAILURE;
0023 }
0024
0025 if (stat(argv[1], &sb) == -1) {
0026 perror("stat");
0027 return EXIT_FAILURE;
0028 }
0029
0030
0031 errno = 0;
0032 if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
0033 if (errno != 0)
0034 perror("sscanf");
0035 else
0036 fprintf(stderr, "No matching characters\n");
0037
0038 return EXIT_FAILURE;
0039 }
0040
0041 vmlinux_size = (uint64_t)sb.st_size;
0042 vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;
0043
0044
0045
0046
0047
0048
0049 vmlinuz_load_addr += (SZ_64K - vmlinux_size % SZ_64K);
0050
0051 printf("0x%llx\n", vmlinuz_load_addr);
0052
0053 return EXIT_SUCCESS;
0054 }