Page MenuHomeFreeBSD

Set the LMA of the riscv kernel to the OpenSBI jump target by default
ClosedPublic

Authored by arichardson on Jan 31 2020, 12:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 5:51 AM
Unknown Object (File)
Fri, Apr 19, 2:05 AM
Unknown Object (File)
Thu, Apr 11, 3:53 AM
Unknown Object (File)
Feb 21 2024, 2:53 AM
Unknown Object (File)
Jan 14 2024, 10:17 AM
Unknown Object (File)
Jan 6 2024, 11:49 PM
Unknown Object (File)
Dec 30 2023, 5:41 AM
Unknown Object (File)
Dec 22 2023, 9:24 PM
Subscribers
Tokens
"Like" token, awarded by br.

Details

Summary

This allows us to boot FreeBSD RISCV on QEMU using the -kernel command line
options. When using that option, QEMU maps the kernel ELF file to the
addresses specified in the LMAs in the program headers.

Since version 4.2 QEMU ships with OpenSBI fw_jump by default so this allows
booting FreeBSD using the following command line:
qemu-system-riscv64 -bios default -kernel /.../boot/kernel/kernel -nographic -M virt

Without this change the -kernel option cannot be used since the LMAs start
at address zero and QEMU already maps a ROM to these low physical addresses.

For targets that require a different kernel LMA the make variable
KERNEL_LMA can be overwritten in the config file. For example, adding
makeoptions KERNEL_LMA=0xc0200000 will create an ELF file that will be
loaded at 0xc0200000.

Before:
There are 4 program headers, starting at offset 64

Program Headers:

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x001000 0xffffffc000000000 0x0000000000000000 0x75e598 0x8be318 RWE 0x1000
DYNAMIC        0x71fb20 0xffffffc00071eb20 0x000000000071eb20 0x000100 0x000100 RW  0x8
GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
NOTE           0x693400 0xffffffc000692400 0x0000000000692400 0x000024 0x000024 R   0x4

After:

There are 4 program headers, starting at offset 64

Program Headers:

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x001000 0xffffffc000000000 0x0000000080200000 0x734198 0x893e18 RWE 0x1000
DYNAMIC        0x6f7810 0xffffffc0006f6810 0x00000000808f6810 0x000100 0x000100 RW  0x8
GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
NOTE           0x66ca70 0xffffffc00066ba70 0x000000008086ba70 0x000024 0x000024 R   0x4
Test Plan

Boots in QEMU, I haven't been able to test anywehere else.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 29124
Build 27064: arc lint + arc unit

Event Timeline

Thanks Alex, this is really useful. Up until now I have been converting the kernel to a flat binary to make use of OpenSBI's fw_jump.elf.

I just gave it a test with the default OpenSBI firmware and the one we have in ports and it looks good.

sys/conf/ldscript.riscv
12

I think you could drop the trailing underscores here, but that's totally up to you. I had a glance through our other linker scripts but I didn't find a good precedent.

This revision is now accepted and ready to land.Jan 31 2020, 8:20 PM

Allow overriding the LMA as may be required for some targets (requested by @jrtc27)

This revision now requires review to proceed.Feb 3 2020, 12:45 PM
arichardson retitled this revision from Set the LMA of the riscv kernel to the OpenSBI jump target to Set the LMA of the riscv kernel to the OpenSBI jump target by default.Feb 3 2020, 12:45 PM
arichardson edited the summary of this revision. (Show Details)

Thanks!

sys/conf/Makefile.riscv
34

THe -> The

br added inline comments.
sys/conf/Makefile.riscv
34

"Note: For rv32 the start address is different: 0x80400000"

This revision is now accepted and ready to land.Feb 3 2020, 1:55 PM