Skip to content

Commit f56063c

Browse files
AKASHI Takahirowildea01
authored andcommitted
arm64: add image head flag definitions
Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Acked-by: James Morse <james.morse@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 497e185 commit f56063c

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

arch/arm64/include/asm/image.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_IMAGE_H
4+
#define __ASM_IMAGE_H
5+
6+
#define ARM64_IMAGE_MAGIC "ARM\x64"
7+
8+
#define ARM64_IMAGE_FLAG_BE_SHIFT 0
9+
#define ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT (ARM64_IMAGE_FLAG_BE_SHIFT + 1)
10+
#define ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT \
11+
(ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT + 2)
12+
#define ARM64_IMAGE_FLAG_BE_MASK 0x1
13+
#define ARM64_IMAGE_FLAG_PAGE_SIZE_MASK 0x3
14+
#define ARM64_IMAGE_FLAG_PHYS_BASE_MASK 0x1
15+
16+
#define ARM64_IMAGE_FLAG_LE 0
17+
#define ARM64_IMAGE_FLAG_BE 1
18+
#define ARM64_IMAGE_FLAG_PAGE_SIZE_4K 1
19+
#define ARM64_IMAGE_FLAG_PAGE_SIZE_16K 2
20+
#define ARM64_IMAGE_FLAG_PAGE_SIZE_64K 3
21+
#define ARM64_IMAGE_FLAG_PHYS_BASE 1
22+
23+
#ifndef __ASSEMBLY__
24+
25+
#define arm64_image_flag_field(flags, field) \
26+
(((flags) >> field##_SHIFT) & field##_MASK)
27+
28+
/*
29+
* struct arm64_image_header - arm64 kernel image header
30+
* See Documentation/arm64/booting.txt for details
31+
*
32+
* @code0: Executable code, or
33+
* @mz_header alternatively used for part of MZ header
34+
* @code1: Executable code
35+
* @text_offset: Image load offset
36+
* @image_size: Effective Image size
37+
* @flags: kernel flags
38+
* @reserved: reserved
39+
* @magic: Magic number
40+
* @reserved5: reserved, or
41+
* @pe_header: alternatively used for PE COFF offset
42+
*/
43+
44+
struct arm64_image_header {
45+
__le32 code0;
46+
__le32 code1;
47+
__le64 text_offset;
48+
__le64 image_size;
49+
__le64 flags;
50+
__le64 res2;
51+
__le64 res3;
52+
__le64 res4;
53+
__le32 magic;
54+
__le32 res5;
55+
};
56+
57+
#endif /* __ASSEMBLY__ */
58+
59+
#endif /* __ASM_IMAGE_H */

arch/arm64/kernel/head.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <asm/cache.h>
3232
#include <asm/cputype.h>
3333
#include <asm/elf.h>
34+
#include <asm/image.h>
3435
#include <asm/kernel-pgtable.h>
3536
#include <asm/kvm_arm.h>
3637
#include <asm/memory.h>
@@ -91,7 +92,7 @@ _head:
9192
.quad 0 // reserved
9293
.quad 0 // reserved
9394
.quad 0 // reserved
94-
.ascii "ARM\x64" // Magic number
95+
.ascii ARM64_IMAGE_MAGIC // Magic number
9596
#ifdef CONFIG_EFI
9697
.long pe_header - _head // Offset to the PE header.
9798

arch/arm64/kernel/image.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
#ifndef __ASM_IMAGE_H
19-
#define __ASM_IMAGE_H
18+
#ifndef __ARM64_KERNEL_IMAGE_H
19+
#define __ARM64_KERNEL_IMAGE_H
2020

2121
#ifndef LINKER_SCRIPT
2222
#error This file should only be included in vmlinux.lds.S
2323
#endif
2424

25+
#include <asm/image.h>
26+
2527
/*
2628
* There aren't any ELF relocations we can use to endian-swap values known only
2729
* at link time (e.g. the subtraction of two symbol addresses), so we must get
@@ -47,19 +49,22 @@
4749
sym##_lo32 = DATA_LE32((data) & 0xffffffff); \
4850
sym##_hi32 = DATA_LE32((data) >> 32)
4951

52+
#define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \
53+
ARM64_IMAGE_FLAG_##field##_SHIFT)
54+
5055
#ifdef CONFIG_CPU_BIG_ENDIAN
51-
#define __HEAD_FLAG_BE 1
56+
#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE
5257
#else
53-
#define __HEAD_FLAG_BE 0
58+
#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE
5459
#endif
5560

5661
#define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
5762

5863
#define __HEAD_FLAG_PHYS_BASE 1
5964

60-
#define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \
61-
(__HEAD_FLAG_PAGE_SIZE << 1) | \
62-
(__HEAD_FLAG_PHYS_BASE << 3))
65+
#define __HEAD_FLAGS (__HEAD_FLAG(BE) | \
66+
__HEAD_FLAG(PAGE_SIZE) | \
67+
__HEAD_FLAG(PHYS_BASE))
6368

6469
/*
6570
* These will output as part of the Image header, which should be little-endian
@@ -119,4 +124,4 @@ __efistub_screen_info = KALLSYMS_HIDE(screen_info);
119124

120125
#endif
121126

122-
#endif /* __ASM_IMAGE_H */
127+
#endif /* __ARM64_KERNEL_IMAGE_H */

0 commit comments

Comments
 (0)