riscvarchive / riscv-edk2-platforms

Port of EDK2 implementation of UEFI to RISC-V. See documentation at:
https://github.com/riscv/riscv-uefi-edk2-docs
Other
18 stars 7 forks source link

Boot Haiku OS #13

Open JohnAZoidberg opened 3 years ago

JohnAZoidberg commented 3 years ago

Haiku doesn't currently boot. The bootloader returns EFI_UNSUPPORTED. Probably some driver isn't included in our build that the Haiki bootloader requires. See: https://github.com/riscv/riscv-edk2-platforms/issues/7#issuecomment-787461881

@kallisti5 where can I find the code and how can I build it easily? Or can you try to add some debugging prints to see what causes EFI_UNSUPPORTED?

JohnAZoidberg commented 3 years ago

Here, right? https://github.com/haiku/haiku/blob/master/src/system/boot/platform/efi/start.cpp#L194 Hmm, it always returns 'EFI_SUCCESS`?

It calls acpi_init? We don't have ACPI yet. But looking at the implementation, it should be fine, if there's no RSDT, right?

Good to see that you're trying to get the device tree from the system config table! We already put it there :)

I can't see anything wrong but I can't find where main is defined: https://github.com/haiku/haiku/blob/master/src/system/boot/platform/efi/start.cpp#L222

JohnAZoidberg commented 3 years ago

https://github.com/tianocore/edk2/blob/stable/202011/MdePkg/Library/BasePeCoffLib/BasePeCoff.c#L313-L321 https://github.com/riscv/riscv-edk2/blob/4476a272ccdaaabc8afc4a6149968e9d31f10efd/MdePkg/Library/BasePeCoffLib/BasePeCoff.c#L329-L338

I did some debugging and this is where EFI_UNSUPPORTED comes from. Seems like something is wrong with your bootloader executable.

JohnAZoidberg commented 3 years ago

Here's the image with more debug output: http://danielschaefer.me/static/U540-virt-haiku-debug-mar1.fd Based on this commit: https://github.com/riscv/riscv-edk2/commit/4476a272ccdaaabc8afc4a6149968e9d31f10efd

kallisti5 commented 3 years ago

I did some debugging and this is where EFI_UNSUPPORTED comes from. Seems like something is wrong with your bootloader executable.

Odd. I thought we had the Pe issues sorted out (u-boot's bootefi seems happy)

Here are the relevant files which generate our RV64 EFI bootloader:

JohnAZoidberg commented 3 years ago

I found the issue. https://git.haiku-os.org/haiku/tree/src/system/boot/platform/efi/arch/riscv64/crt0-efi-riscv64.S#n90 is 6 when it should really be 16. I guess this could be a typo.

https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#optional-header-windows-specific-fields-image-only says this value should be the number of data directory entries of which there are 16.

I patched the binary and I can start the bootloader and make it start Haiku (but it gets stuck)!

image

I'd like to find out how to contribute to Haiku and send this as a patch. I'll try to figure it out tomorrow. I'm happy about operating system diversity :)

These are the last few lines when it appears to be stuck:

  0xbf982000-0xbf9b2000  0x0 0x5 0x800000000000000f
  0xbf9b2000-0xbf9d6000  0x0 0x6 0x800000000000000f
  0xbf9d6000-0xbf9e6000  0x0 0x7 0xf
  0xbf9e6000-0xbfa07000  0x0 0x4 0xf
  0xbfa07000-0xbfa45000  0x0 0x3 0xf
  0xbfa45000-0xbffd6000  0x0 0x4 0xf
  0xbffd6000-0xbfffe000  0x0 0x3 0xf
  0xbfffe000-0xc0000000  0x0 0x4 0xf
Calling ExitBootServices. So long, EFI!
TimerDriverSetTimerPeriod(0x0)
SetUefiImageMemoryAttributes - 0x00000000BF9A9000 - 0x0000000000009000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BF9A1000 - 0x0000000000008000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BF999000 - 0x0000000000008000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BF992000 - 0x0000000000007000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BE8EA000 - 0x0000000000018000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BF98A000 - 0x0000000000008000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BF982000 - 0x0000000000008000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BE8D3000 - 0x0000000000006000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet
SetUefiImageMemoryAttributes - 0x00000000BE8CC000 - 0x0000000000007000 (0x0000000000000000)
CpuSetMemoryAttributes: Set memory attributes not supported yet

The stuff about memory attributes comes from our edk2 changes. I guess we really need to implement them? Do you think they would cause the hang?

tqh commented 3 years ago

Oh, nice! We use Gerrit for patches. Here are the guidelines for patches: https://dev.haiku-os.org/wiki/CodingGuidelines/SubmittingPatches

kallisti5 commented 3 years ago

Nice!! I can apply that fix to our codebase @JohnAZoidberg if you don't have the bandwidth / time :-)

kallisti5 commented 3 years ago

ooh.. also the cause of the hang jumping into our kernel isn't a EDK2 unique issue.

I've been working through a patchset to setup a new Sv39 page table from our bootloader before jumping into our kernel.

https://review.haiku-os.org/c/haiku/+/3733

It's getting there... but I don't know what I'm doing :sweat_smile:

JohnAZoidberg commented 3 years ago

Linux boots fine, please try again when you've got time :) I see the change request isn't merged yet.

You cant get the latest FD from Github Actions. Now it is here: https://github.com/riscv/riscv-edk2-platforms/suites/2725452052/artifacts/60114481 (unpack the zip)