Path: blob/master/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
26493 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 2010 "Wu Zhangjin" <[email protected]>3*/45#include <sys/types.h>6#include <sys/stat.h>7#include <errno.h>8#include <stdint.h>9#include <stdio.h>10#include <stdlib.h>11#include <linux/sizes.h>1213int main(int argc, char *argv[])14{15unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;16struct stat sb;1718if (argc != 3) {19fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",20argv[0]);21return EXIT_FAILURE;22}2324if (stat(argv[1], &sb) == -1) {25perror("stat");26return EXIT_FAILURE;27}2829/* Convert hex characters to dec number */30errno = 0;31if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {32if (errno != 0)33perror("sscanf");34else35fprintf(stderr, "No matching characters\n");3637return EXIT_FAILURE;38}3940vmlinux_size = (uint64_t)sb.st_size;41vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;4243/*44* Align with 64KB: KEXEC needs load sections to be aligned to PAGE_SIZE,45* which may be as large as 64KB depending on the kernel configuration.46*/4748vmlinuz_load_addr += (SZ_64K - vmlinux_size % SZ_64K);4950printf("0x%llx\n", vmlinuz_load_addr);5152return EXIT_SUCCESS;53}545556