-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RISC-V: Support separate firmware and kernel payload #107
RISC-V: Support separate firmware and kernel payload #107
Conversation
Here's the QEMU PR: Here's a QEMU branch to test this PR: |
There is a bug in #ifdef to relax the alignment if
Extract from
It seems |
Support for separate firmware and kernel payload is added by updating BBL to read optional preloaded kernel address attributes from device-tree using a similar mechanism to that used to pass init ramdisk addresses to linux kernel. chosen { riscv,kernel-start = <0x00000000 0x80200000>; riscv,kernel-end = <0x00000000 0x80590634>; }; These attributes are added by QEMU and read by BBL when combining -bios <firmware-image> and -kernel <kernel-image> options. e.g. $ qemu-system-riscv64 -machine virt -bios bbl -kernel vmlinux With this change, bbl can be compiled without --with-payload and the dummy payload alignment is altered to make the memory footprint of the firmware-only bbl smaller. The dummy payload message is updated to indicate the alternative load method. This load method could also be supported by a first stage boot loader that reads seperate firmware and kernel from SPI flash. The main advantage of this new mechanism is that it eases kernel development by avoiding the riscv-pk packaging step after kernel builds, makes building per repository artefacts for CI simpler, and mimics bootloaders on other platforms that can load a kernel image file directly. Ultimately BBL should use an SPI driver to load the kernel image however this mechanism supports use cases such such as QEMU's -bios, -kernel and -initrd options following examples from other platforms that pass kernel entry to firmware via device-tree. Cc: Palmer Dabbelt <palmer@sifive.com> Cc: Alistair Francis <Alistair.Francis@wdc.com> Signed-off-by: Michael Clark <mjc@sifive.com>
5c46e6a
to
474ee5a
Compare
It seems the
I've tested alignment with the dummy payload and external kernel (RELAXED_ALIGNMENT=1) using This is the output if the dummy payload is run on its own:
Squashed the changes back into the original commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. My one question is: is there a standard way of providing the kernel to the firmware so we can avoid defining RISC-V specific chosen nodes (`riscv,kernel-start')?
If not then I vote we merge it.
There are a couple of other boards that do this but they use
There is symmetry with the Linux mechanism, with the difference that the riscv,kernel nodes are to be consumed by the bootloader and the linux,initrd nodes are to be consumed by the kernel. The choice to not name them with a qemu, prefix was so thay they could potentially be used by hardware (however for hardware it might be more likely that we add SPI/MMC loader and possible filesystem drivers to bbl). lowRISC have a BSD licensed @terpstra doesn't like the idea of using FAT, but the reality is that it is pretty much universally supported. i.e. Mac and Windows users can just insert a SDCard adapter and drop a In any case, as you see from the comments in the associated QEMU change, we'll need to modify the boot protocol to handle kernels that decompress themselves. Putting the FDT right after the kernel doesn't support kernels that have header code that decompresses the kernel (like linux does on platforms that support vmlinuz). The initrd is placed halfway into memory and I think linux-kernel has code to reserve or free this memory. We still have quite a bit of work to do on early boot protocol stuff, like potentially changing the kernel to use 4KiB pages to map itself so that we can add kernel memory protection i.e. map .rodata +R |
I agree: calling the nodes FYI: Wes is on vacation for a bit, so if you want to merge some FAT32 patches now's your chance :) |
Agree. Calling them BTW We haven't added this mechanism to That said, it might make development easier if we did add it to @alistair23 is working on SPI emulation for SiFive SPI so we can plug an emulated SD card into |
This is the patch to add it to |
Overall this looks good to me. I think it moves in the right direction. There are some nit picks in the actual commit to better match QEMU style. Do you want me to comment here or wait until you send it to the mailing list? I have had to put the SPI work on the back burner for the moment unfortunately. Linux can probe it can't detect the rootFS. Is someone working on SPI boot loader support at the moment? Like I mentioned the other day a non-Linux test case would help, but I still can't find one. |
Okay i've merged the associated commit to QEMU for the @alastair23 this is the riscv-pk PR. We can fix up QEMU nits when we send it for patch review. The PR just gets the commit into into the qemu-2.13-for-upstream branch which we need to send to qemu-devel as the number of commits is growing... |
@alastair23 the QEMU commit passes |
@alastair23 nice thing in QEMU is that we now get kernel symbols with |
Ah, that might help. Although the kernel doesn't hang, it loops around and I think I know where. Are you going to patch all of the machines? |
We could add it to |
@alistair23 you might find the lowRISC bbl fork useful for SPI testing. They have a tiny SD card driver i.e. you could modify bbl to exercise the SiFive SPI emulation in QEMU. Might be a simpler test harness than a full blown kernel. See here https://github.com/lowRISC/lowrisc-kc705/tree/ab3e216c9369704a96cf23fdd21a55d656045395/driver |
Thanks for the link, unfortunately that driver is for the Xilinx SPI device, not the SiFive one. |
Support for separate firmware and kernel payload is added
by updating BBL to read optional preloaded kernel address
attributes from device-tree using a similar mechanism to
that used to pass init ramdisk addresses to linux kernel.
These attributes are added by QEMU and read by BBL when combining
-bios <firmware-image>
and-kernel <kernel-image>
options. e.g.With this change, bbl can be compiled without
--with-payload
and the dummy payload alignment is altered to make the memory
footprint of the firmware-only bbl smaller. The dummy payload
message is updated to indicate the alternative load method.
This load method could also be supported by a first stage boot
loader that reads seperate firmware and kernel from SPI flash.
The main advantage of this new mechanism is that it eases kernel
development by avoiding the riscv-pk packaging step after kernel
builds, makes building per repository artefacts for CI simpler,
and mimics bootloaders on other platforms that can load a kernel
image file directly. Ultimately BBL should use an SPI driver to
load the kernel image however this mechanism supports use cases
such such as QEMU's -bios, -kernel and -initrd options following
examples from other platforms that pass kernel entry to firmware
via device-tree.
Cc: @palmer-dabbelt
Cc: @alistair23