Kernel/riscv64: Add Linux boot header

This allows us to boot via U-Boot's booti command.
This commit is contained in:
Sönke Holz 2024-02-15 20:59:00 +01:00 committed by Andrew Kaster
parent d99d66e358
commit ec5cfc031e
Notes: sideshowbarker 2024-07-18 00:34:07 +09:00

View file

@ -7,6 +7,28 @@
// In a specially-named text section so that the linker script can put it first in .text.
.section ".text.first"
// Make the kernel bootable using U-Boot's booti command by adding a linux header (https://www.kernel.org/doc/html/latest/arch/riscv/boot-image-header.html).
// Booting via booti causes U-Boot to pass us the boot hart ID and a flattened devicetree (https://www.kernel.org/doc/html/latest/arch/riscv/boot.html).
linux_header:
.option push
.option norvc
j start // u32 code0
j start // u32 code1
.option pop
// This offset is needed, as otherwise U-Boot will try to load us at the same address where OpenSBI is loaded.
// The value is the same that Linux uses.
.dword 0x400000 // u64 text_offset
.dword end_of_kernel_image - linux_header // u64 image_size
.dword 0 // u64 flags
.word 2 // u32 version
.word 0 // u32 res1
.dword 0 // u64 res2
.ascii "RISCV\0\0\0" // u64 magic (deprecated)
.ascii "RSC\x5" // u32 magic2
.word 0 // u32 res3
.global start
.type start, @function
start: