Skip to content

Commit 405fe7a

Browse files
Christoph Hellwigpaul-walmsley-sifive
authored andcommitted
riscv: provide a flat image loader
This allows just loading the kernel at a pre-set address without qemu going bonkers trying to map the ELF file. Contains a contribution from Aurabindo Jayamohanan to reuse the PAGE_OFFSET definition. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Anup Patel <[email protected]> [[email protected]: fixed checkpatch issue; minor commit message fix] Signed-off-by: Paul Walmsley <[email protected]>
1 parent 6bd33e1 commit 405fe7a

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

arch/riscv/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ PHONY += vdso_install
8383
vdso_install:
8484
$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
8585

86-
all: Image.gz
86+
ifeq ($(CONFIG_RISCV_M_MODE),y)
87+
KBUILD_IMAGE := $(boot)/loader
88+
else
89+
KBUILD_IMAGE := $(boot)/Image.gz
90+
endif
91+
BOOT_TARGETS := Image Image.gz loader
8792

88-
Image: vmlinux
89-
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
93+
all: $(notdir $(KBUILD_IMAGE))
9094

91-
Image.%: Image
95+
$(BOOT_TARGETS): vmlinux
9296
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
97+
@$(kecho) ' Kernel: $(boot)/$@ is ready'
9398

9499
zinstall install:
95100
$(Q)$(MAKE) $(build)=$(boot) $@

arch/riscv/boot/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616

1717
OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
1818

19-
targets := Image
19+
targets := Image loader
2020

2121
$(obj)/Image: vmlinux FORCE
2222
$(call if_changed,objcopy)
2323

2424
$(obj)/Image.gz: $(obj)/Image FORCE
2525
$(call if_changed,gzip)
2626

27+
loader.o: $(src)/loader.S $(obj)/Image
28+
29+
$(obj)/loader: $(obj)/loader.o $(obj)/Image $(obj)/loader.lds FORCE
30+
$(Q)$(LD) -T $(obj)/loader.lds -o $@ $(obj)/loader.o
31+
2732
install:
2833
$(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \
2934
$(obj)/Image System.map "$(INSTALL_PATH)"

arch/riscv/boot/loader.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
.align 4
4+
.section .payload, "ax", %progbits
5+
.globl _start
6+
_start:
7+
.incbin "arch/riscv/boot/Image"
8+

arch/riscv/boot/loader.lds.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#include <asm/page.h>
4+
5+
OUTPUT_ARCH(riscv)
6+
ENTRY(_start)
7+
8+
SECTIONS
9+
{
10+
. = PAGE_OFFSET;
11+
12+
.payload : {
13+
*(.payload)
14+
. = ALIGN(8);
15+
}
16+
}

0 commit comments

Comments
 (0)