Skip to content

Commit cd86ec2

Browse files
lorcnashif
authored andcommitted
aarch64: add ability to generate image header
Image header is compatible with Linux aarch64 boot protocol, so zephyr can be booted with U-boot or Xen loader. Signed-off-by: Volodymyr Babchuk <[email protected]>
1 parent 7191b64 commit cd86ec2

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

arch/arm/core/aarch64/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S)
3131
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
3232
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE ../common/tls.c)
3333
zephyr_library_sources_ifdef(CONFIG_ARM_PSCI smccc-call.S)
34+
zephyr_library_sources_ifdef(CONFIG_AARCH64_IMAGE_HEADER header.S)
3435

3536
add_subdirectory_ifdef(CONFIG_ARM_MMU mmu)

arch/arm/core/aarch64/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ config CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE
5656
config IPM_CONSOLE_STACK_SIZE
5757
default 2048
5858

59+
config AARCH64_IMAGE_HEADER
60+
bool "Add image header"
61+
help
62+
This option enables standard ARM64 boot image header used by Linux
63+
and understood by loaders such as u-boot on Xen xl tool.
64+
5965
if CPU_CORTEX_A
6066

6167
config ARMV8_A_NS

arch/arm/core/aarch64/header.S

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <linker/sections.h>
8+
#include <arch/cpu.h>
9+
#include "mmu/arm_mmu.h"
10+
11+
#if CONFIG_MMU_PAGE_SIZE == 4096
12+
#define HEADER_PGSIZE 1
13+
#elif CONFIG_MMU_PAGE_SIZE == 16384
14+
#define HEADER_PGSIZE 2
15+
#elif CONFIG_MMU_PAGE_SIZE == 65536
16+
#define HEADER_PGSIZE 3
17+
#else
18+
#define HEADER_PGSIZE 0
19+
#warning "Can't determine page size for header flags"
20+
#endif
21+
22+
#define HEADER_FLAGS (HEADER_PGSIZE << 1)
23+
24+
_ASM_FILE_PROLOGUE
25+
26+
SECTION_SUBSEC_FUNC(image_header,_image_header_section,_image_header)
27+
b __start // branch to kernel start
28+
.long 0 // reserved
29+
.quad 0 // Image load offset from start
30+
// of RAM, little-endian
31+
32+
.quad _flash_used // Effective size of kernel
33+
// image, little-endian
34+
35+
.quad HEADER_FLAGS // Informative flags,
36+
// little-endian
37+
38+
.quad 0 // reserved
39+
.quad 0 // reserved
40+
.quad 0 // reserved
41+
.ascii "ARM\x64" // Magic number
42+
.long 0 // reserved

include/arch/arm/aarch64/scripts/linker.ld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ SECTIONS
107107
#ifndef CONFIG_XIP
108108
z_mapped_start = .;
109109
#endif
110+
111+
#ifdef CONFIG_AARCH64_IMAGE_HEADER
112+
KEEP(*(.image_header))
113+
KEEP(*(".image_header.*"))
114+
#endif
115+
110116
_vector_start = .;
111117
KEEP(*(.exc_vector_table))
112118
KEEP(*(".exc_vector_table.*"))

0 commit comments

Comments
 (0)