Path: blob/master/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
10818 views
/*1* Copyright (C) 2010 "Wu Zhangjin" <[email protected]>2*3* This program is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License as published by the5* Free Software Foundation; either version 2 of the License, or (at your6* option) any later version.7*/89#include <sys/types.h>10#include <sys/stat.h>11#include <errno.h>12#include <stdint.h>13#include <stdio.h>14#include <stdlib.h>1516int main(int argc, char *argv[])17{18unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;19struct stat sb;2021if (argc != 3) {22fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",23argv[0]);24return EXIT_FAILURE;25}2627if (stat(argv[1], &sb) == -1) {28perror("stat");29return EXIT_FAILURE;30}3132/* Convert hex characters to dec number */33errno = 0;34if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {35if (errno != 0)36perror("sscanf");37else38fprintf(stderr, "No matching characters\n");3940return EXIT_FAILURE;41}4243vmlinux_size = (uint64_t)sb.st_size;44vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;4546/*47* Align with 16 bytes: "greater than that used for any standard data48* types by a MIPS compiler." -- See MIPS Run Linux (Second Edition).49*/5051vmlinuz_load_addr += (16 - vmlinux_size % 16);5253printf("0x%llx\n", vmlinuz_load_addr);5455return EXIT_SUCCESS;56}575859