Linux Audio

Check our new training course

Linux BSP upgrade and security maintenance

Need help to get security updates for your Linux BSP?
Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com>
 
 
 
 
 
 4 */
 5
 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>
13
14int main(int argc, char *argv[])
15{
16	unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
17	struct stat sb;
18
19	if (argc != 3) {
20		fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",
21				argv[0]);
22		return EXIT_FAILURE;
23	}
24
25	if (stat(argv[1], &sb) == -1) {
26		perror("stat");
27		return EXIT_FAILURE;
28	}
29
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");
37
38		return EXIT_FAILURE;
39	}
40
41	vmlinux_size = (uint64_t)sb.st_size;
42	vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;
43
44	/*
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.
47	 */
48
49	vmlinuz_load_addr += (SZ_64K - vmlinux_size % SZ_64K);
50
51	printf("0x%llx\n", vmlinuz_load_addr);
52
53	return EXIT_SUCCESS;
54}
v3.5.6
 
 1/*
 2 * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com>
 3 *
 4 * This program is free software; you can redistribute  it and/or modify it
 5 * under  the terms of  the GNU General  Public License as published by the
 6 * Free Software Foundation;  either version 2 of the  License, or (at your
 7 * option) any later version.
 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	/* Convert hex characters to dec number */
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	 * Align with 16 bytes: "greater than that used for any standard data
49	 * types by a MIPS compiler." -- See MIPS Run Linux (Second Edition).
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}