treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / mips / boot / compressed / calc_vmlinuz_load_addr.c
blob080b926d2623768bc324f9e079bd5ab3db8be5a7
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com>
4 */
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <errno.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <linux/sizes.h>
14 int main(int argc, char *argv[])
16 unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
17 struct stat sb;
19 if (argc != 3) {
20 fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",
21 argv[0]);
22 return EXIT_FAILURE;
25 if (stat(argv[1], &sb) == -1) {
26 perror("stat");
27 return EXIT_FAILURE;
30 /* Convert hex characters to dec number */
31 errno = 0;
32 if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
33 if (errno != 0)
34 perror("sscanf");
35 else
36 fprintf(stderr, "No matching characters\n");
38 return EXIT_FAILURE;
41 vmlinux_size = (uint64_t)sb.st_size;
42 vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;
45 * Align with 64KB: KEXEC needs load sections to be aligned to PAGE_SIZE,
46 * which may be as large as 64KB depending on the kernel configuration.
49 vmlinuz_load_addr += (SZ_64K - vmlinux_size % SZ_64K);
51 printf("0x%llx\n", vmlinuz_load_addr);
53 return EXIT_SUCCESS;