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

PeiMain Module Hang on U540 with Qemu #1

Closed eliaskousk closed 4 years ago

eliaskousk commented 4 years ago

Hi,

I'm trying to boot the produced U540.fd on Qemu 5.0.0 but it hangs while trying to load PeiMain.

I'm using riscv-edk2 main branch (ca407c7) and riscv-edk2-platforms staging branch (1b9a7ba) on Ubuntu 18.04 with latest RISCV toolchain (10.1 256a410).

Could the issue be the toolchain? I can't use provided 9.2 for CI though (see below).

Any help on figuring this out will be great, thank you!

My build steps:

cd riscv-uefi (folder containing both riscv-edk2 and riscv-edk2-platforms)
cd riscv-edk2
make -C BaseTools clean
make -C BaseTools
source edksetup.sh
cd ..
export WORKSPACE=`pwd`
export PACKAGES_PATH=`pwd`/riscv-edk2:`pwd`/riscv-edk2-platforms
rm -rf Build
export GCC5_RISCV64_PREFIX=/opt/riscv/bin/riscv64-unknown-elf-
build -a RISCV64 -p Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc -t GCC5

Qemu console output

It hangs when trying to load PeiMain module (52C05B14-0B98-496C-BC3B-04B50211D680):

qemu-system-riscv64 -machine sifive_u -bios Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/FV/U540.fd -serial stdio
SecCoreStartUpWithStack: Initializing OpenSBI library for booting hart
Device Tree can't be expanded to accmodate new node
OpenSBI v0.6
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name          : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs     : 5
Current Hart           : 1
Firmware Base          : 0x80000000
Firmware Size          : 704 KB
Runtime SBI Version    : 0.2

MIDELEG : 0x0000000000000222
MEDELEG : 0x000000000000b109
PMP0    : 0x0000000080000000-0x00000000800fffff (A,R,W,X)
PMP1    : 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
FindAndReportEntryPoints: Entry
FindPeiCoreImageBase: Entry
FindPeiCoreImageBaseInFv: PeiCoreImageBase found
FindAndReportEntryPoints: PeCoffLoaderGetEntryPoint success: 80022240
PeiCore: OpenSBI scratch address for each hart:
          Hart 0: 0x800A9E00
          Hart 1: 0x800A7E00
          Hart 2: 0x800A5E00
          Hart 3: 0x800A3E00
          Hart 4: 0x800A1E00
PeiCore: Helloooo????
PeiCore: OpenSBI platform table at address: 0x80016D20
Firmware Context is located at 0x8080FD20
PeiCore: OpenSBI Hart 0 Firmware Context Hart-specific at address: 0x800A9C00
PeiCore: OpenSBI Hart 1 Firmware Context Hart-specific at address: 0x800A7C00
PeiCore: OpenSBI Hart 2 Firmware Context Hart-specific at address: 0x800A5C00
PeiCore: OpenSBI Hart 3 Firmware Context Hart-specific at address: 0x800A3C00
PeiCore: OpenSBI Hart 4 Firmware Context Hart-specific at address: 0x800A1C00
Set PEI Service 0x8080F7C8 at OpenSBI Firmware Context at 0x8080FD20
Register PPI Notify: DCD0BE23-9586-40F4-B643-06522CED4EDE
Install PPI: 8C8CE578-8A3D-4F1C-9935-896185C32DD3
Install PPI: 5473C07A-3DCB-4DCA-BD6F-1E9689E7349A
The 0th FV start address is 0x00080020000, size is 0x00080000, handle is 0x80020000
Register PPI Notify: 49EDB1C1-BF21-4761-BB12-EB0031AABB39
Register PPI Notify: EA7CA24B-DED5-4DAD-A389-BF827E8F9B38
Install PPI: B9E0ABFE-5979-4914-977F-6DEE78C278A6
Install PPI: DBE23AA9-A345-4B97-85B6-B226F1617389
Install PPI: CEAB683C-EC56-4A2D-A906-4053FA4E9C16
DiscoverPeimsAndOrderWithApriori(): Found 0x5 PEI FFS files in the 0th FV
Loading PEIM A3610442-E69F-4DF3-82CA-2360C4031A23
Loading PEIM at 0x00080048000 EntryPoint=0x00080048240 ReportStatusCodeRouterPei.efi
Set PEI Service 0x8080F7C8 at OpenSBI Firmware Context at 0x8080FD20
Install PPI: 0065D394-9951-4144-82A3-0AFC8579C251
Install PPI: 229832D3-7A30-4B36-B827-F40CB7D45436
Loading PEIM 9D225237-FA01-464C-A949-BAABC02D31D0
Loading PEIM at 0x0008004F000 EntryPoint=0x0008004F240 StatusCodeHandlerPei.efi
Set PEI Service 0x8080F7C8 at OpenSBI Firmware Context at 0x8080FD20
PROGRESS CODE: V03020003 I0
Loading PEIM 9B3ADA4F-AE56-4C24-8DEA-F03B7558AE50
Loading PEIM at 0x0008003C000 EntryPoint=0x0008003C240 PcdPeim.efi
PROGRESS CODE: V03020002 I0
Set PEI Service 0x8080F7C8 at OpenSBI Firmware Context at 0x8080FD20
Install PPI: 06E81C58-4AD7-44BC-8390-F10265F72480
Install PPI: 01F34D25-4DE2-23AD-3FF3-36353FF323F1
Install PPI: 4D8B155B-C059-4C8F-8926-06FD4331DB8A
Install PPI: A60C6B59-E459-425D-9C69-0BCC9CB27D81
Register PPI Notify: 605EA650-C65C-42E1-BA80-91A52AB618C6
PROGRESS CODE: V03020003 I0
Loading PEIM 5592FC16-8FEF-4DE3-A6CF-6C59081E4EB7
Loading PEIM at 0x00080066000 EntryPoint=0x00080066240 PlatformPei.efi
PROGRESS CODE: V03020002 I0
Set PEI Service 0x8080F7C8 at OpenSBI Firmware Context at 0x8080FD20
Platform PEIM Loaded
This is normal boot
Install PPI: 7408D748-FC8C-4EE6-9288-C4BEC092A410
Platform BOOT mode initiated.
PublishPeiMemory: MemoryBase:0x81000000 MemorySize:3F000000
PeiInstallPeiMemory MemoryBegin 0x81000000, MemoryLength 0x3F000000
PEI memory published.
Platform RAM regions initiated.
Platform PEI Firmware Volume Initialization
Platform builds DXE FV at 80100000, size 18C000.
Install PPI: 49EDB1C1-BF21-4761-BB12-EB0031AABB39
Notify: PPI Guid: 49EDB1C1-BF21-4761-BB12-EB0031AABB39, Peim notify entry point: 800265A8
The 1th FV start address is 0x00080100000, size is 0x0018C000, handle is 0x80100000
Found firmware volume Image File 80100078 in FV[1] 80100000
Building U5 Coreplex processor information HOB
CreateE51CoreProcessorSpecificDataHob: Entry.
    Firmware Context is at 0x8080FD20.
    Firmware Context Hart specific is at 0x800A9C00.
        *HartId = 0x0
        *Is Boot Hart? = 0x0
        *PrivilegeModeSupported = 0x9
        *MModeExcepDelegation = 0x0
        *MModeInterruptDelegation = 0x0
        *HartXlen = 0x2
        *MachineModeXlen = 0x2
        *SupervisorModeXlen = 0x0
        *UserModeXlen = 0x2
        *InstSetSupported = 0x101105
        *MachineVendorId = 0x0
        *MachineArchId = 0x0
        *MachineImplId = 0x0
Support E5 Monitor core on U5 platform, HOB at address 0x80800E18
CreateU54CoreProcessorSpecificDataHob: Entry.
    Firmware Context is at 0x8080FD20.
    Firmware Context Hart specific is at 0x800A7C00.
        *HartId = 0x1
        *Is Boot Hart? = 0x1
        *PrivilegeModeSupported = 0x1
        *MModeExcepDelegation = 0x0
        *MModeInterruptDelegation = 0x0
        *HartXlen = 0x2
        *MachineModeXlen = 0x2
        *SupervisorModeXlen = 0x0
        *UserModeXlen = 0x2
        *InstSetSupported = 0x0
        *MachineVendorId = 0x0
        *MachineArchId = 0x80018B90
        *MachineImplId = 0xA000001
Support U5 application core on U5 platform, HOB Data at address 0x80800ED0
CreateU54CoreProcessorSpecificDataHob: Entry.
    Firmware Context is at 0x8080FD20.
    Firmware Context Hart specific is at 0x800A5C00.
        *HartId = 0x2
        *Is Boot Hart? = 0x0
        *PrivilegeModeSupported = 0xD
        *MModeExcepDelegation = 0x0
        *MModeInterruptDelegation = 0x0
        *HartXlen = 0x2
        *MachineModeXlen = 0x2
        *SupervisorModeXlen = 0x0
        *UserModeXlen = 0x2
        *InstSetSupported = 0xFFFFFFFF
        *MachineVendorId = 0xFFFFFFFF
        *MachineArchId = 0xFFFFFFFF
        *MachineImplId = 0xFFFFFFFF
Support U5 application core on U5 platform, HOB Data at address 0x80800F88
CreateU54CoreProcessorSpecificDataHob: Entry.
    Firmware Context is at 0x8080FD20.
    Firmware Context Hart specific is at 0x800A3C00.
        *HartId = 0x3
        *Is Boot Hart? = 0x0
        *PrivilegeModeSupported = 0xD
        *MModeExcepDelegation = 0x0
        *MModeInterruptDelegation = 0x0
        *HartXlen = 0x2
        *MachineModeXlen = 0x2
        *SupervisorModeXlen = 0x0
        *UserModeXlen = 0x2
        *InstSetSupported = 0xFFFFFFFF
        *MachineVendorId = 0xFFFFFFFF
        *MachineArchId = 0xFFFFFFFF
        *MachineImplId = 0xFFFFFFFF
Support U5 application core on U5 platform, HOB Data at address 0x80801040
CreateU54CoreProcessorSpecificDataHob: Entry.
    Firmware Context is at 0x8080FD20.
    Firmware Context Hart specific is at 0x800A1C00.
        *HartId = 0x4
        *Is Boot Hart? = 0x0
        *PrivilegeModeSupported = 0xD
        *MModeExcepDelegation = 0x0
        *MModeInterruptDelegation = 0x0
        *HartXlen = 0x2
        *MachineModeXlen = 0x2
        *SupervisorModeXlen = 0x0
        *UserModeXlen = 0x2
        *InstSetSupported = 0xFFFFFFFF
        *MachineVendorId = 0xFFFFFFFF
        *MachineArchId = 0xFFFFFFFF
        *MachineImplId = 0xFFFFFFFF
Support U5 application core on U5 platform, HOB Data at address 0x808010F8
Support 4 U5 application cores on U5 platform
CreateU5MCProcessorSmbiosDataHob: Entry
CreateU5MCProcessorSmbiosDataHob: Exit
U5 MC Coreplex SMBIOS DATA HOB at address 0x80801268
PROGRESS CODE: V03020003 I0
Temp Stack : BaseAddress=0x80808000 Length=0x8000
Temp Heap  : BaseAddress=0x80800000 Length=0x8000
Total temporary memory:    65536 bytes.
  temporary memory stack ever used:       4776 bytes.
  temporary memory heap used for HobList: 4760 bytes.
  temporary memory heap occupied by memory pages: 0 bytes.
Old Stack size 32768, New stack size 131072
Stack Hob: BaseAddress=0x81000000 Length=0x20000
Heap Offset = 0x820000 Stack Offset = 0x810000
TemporaryRamMigration: Temp Mem Base:0x80800000, Permanent Mem Base:0x81018000, CopySize:0x10000
TemporaryRamMigration: OpenSBI Firmware Context is relocated to 0x8101FD20
DebutPrintFirmwareContext: OpenSBI Firmware Context at 0x8101FD20
DebutPrintFirmwareContext:              PEI Service at 0x8101F7C8

Set PEI Service 0x8101F7C8 at OpenSBI Firmware Context at 0x8101FD20
Set PEI Service 0x8101F7C8 at OpenSBI Firmware Context at 0x8101FD20
Loading PEIM 52C05B14-0B98-496C-BC3B-04B50211D680

I've also tried the provided v9.2 toolchain found here but cannot build the firmware with it due to the following error (the provided toolchain archive is missing libmpfr):

...

Processing meta-data .
Architecture(s)  = RISCV64
Build target     = NOOPT
Toolchain        = GCC5

...

Active Platform          = /home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2-platforms/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
.. done!
Building ... /home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf [RISCV64]
Building ... /home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Library/UefiLib/UefiLib.inf [RISCV64]
"/home/lupo/Downloads/gcc-riscv-9.2.0-2020.04-x86_64_riscv64-unknown-gnu/bin/riscv64-unknown-elf-gcc" -MMD -MF /home/lupo/Development/Software/Firmware/riscv-uefi/Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/RISCV64/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint/OUTPUT/DriverEntryPoint.obj.deps -g -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=UefiDriverEntryPointStrings -msmall-data-limit=0 -Wno-tautological-compare -Wno-pointer-compare -DOPENSBI_EXTERNAL_SBI_TYPES=OpensbiTypes.h -march=rv64imafdc -fno-builtin -fno-builtin-memcpy -fno-stack-protector -Wno-address -fno-asynchronous-unwind-tables -Wno-unused-but-set-variable -fpack-struct=8 -mcmodel=medany -mabi=lp64 -mno-relax -save-temps -c -o /home/lupo/Development/Software/Firmware/riscv-uefi/Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/RISCV64/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint/OUTPUT/./DriverEntryPoint.obj -I/home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Library/UefiDriverEntryPoint -I/home/lupo/Development/Software/Firmware/riscv-uefi/Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/RISCV64/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint/DEBUG -I/home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg -I/home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Include -I/home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Include/RiscV64 /home/lupo/Development/Software/Firmware/riscv-uefi/riscv-edk2/MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
/home/Storage/HDD/Personal/Downloads/gcc-riscv-9.2.0-2020.04-x86_64_riscv64-unknown-gnu/bin/../libexec/gcc/riscv64-unknown-elf/9.2.0/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory
GNUmakefile:298: recipe for target '/home/lupo/Development/Software/Firmware/riscv-uefi/Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/RISCV64/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint/OUTPUT/DriverEntryPoint.obj' failed
make: *** [/home/lupo/Development/Software/Firmware/riscv-uefi/Build/FreedomU540HiFiveUnleashed/NOOPT_GCC5/RISCV64/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint/OUTPUT/DriverEntryPoint.obj] Error 1

...

Moreover, I have also tried my own built v9.2 toolchain, where instead of hanging while trying to load PeiMain module, it enters an endless loop that continously boots the machine until the PeiMain module load. Each loop iteration starts from FindAndReportEntryPoints: Entry on the above log and ends on Loading PEIM 52C05B14-0B98-496C-BC3B-04B50211D680.

Best, Elias

changab commented 4 years ago

For the build issue, we didn't try toolchain 10.1 though. The one we use for RISC-V edk2 is v9.2 as you pointed out. Do you install those prerequisites mentioned here https://github.com/riscv/riscv-gnu-toolchai?

For the boot fail, could you also specify -cpu sifive-u54 -smp cpus=5,maxcpus=5 to qemu-system-riscv64? BTW, the QEMU I am using is v4.1.50. that would be bad if later QEMU version or toolchain leads to the boot errors you met and we will have to figure it out.

eliaskousk commented 4 years ago

RISC-V Toolchain

The v9.2 toolchain archive provided for CI requires libmpfr v4 from Ubuntu 16.04 and I have Ubuntu 18.04 which has libmpfr v6. So I installed libmpfr v4 and the firmware build completed fine.

However, I still get the exact same hang when trying to load PeiMain.

(BTW I initially thought that libmpfr was needed as a library on the toolchain and not on the host that runs that toolchain, sorry for the confusion.)

Qemu

I tried adding the above -cpu and -smp options and the result is the same and I get the same hang.

Qemu versions I've tried:

v4.1.1 complained if I put cpus=5 in -smp (max allowed = 4). Regardless of that, whatever number I tried didn't boot at all.

I can't find anywhere Qemu v.4.1.50. Maybe it's from a package of a Linux distro?

Maybe you can provide me with a U540.fd binary that works for you so that I can try it? If it works for me as well it will at least verify that Qemu v.5.0 or v4.2 is not the issue here.

Thank you, Elias

changab commented 4 years ago

Binary is sent by email to you. and the QEMU I am using seems old (last Oct), which is commit ID e9d42461920f6f40f4d847a5ba18e90d095ed0b9.

Let me know that binary works or not. Thanks.

eliaskousk commented 4 years ago

Thank you Abner, I tested and the hang remains.

So probably the FW is not the issue and I will concentrate on Qemu, testing with the commit you mention above later today.

Best, Elias

eliaskousk commented 4 years ago

Tested Qemu 4.1.50 e9d42461920f6f40f4d847a5ba18e90d095ed0b9 and the hang persists.

Something weird is going on!

eliaskousk commented 4 years ago

For whoever looks this in the future, I used Qemu commandline options that Abner sent me and the issue was solved.

The important option was by giving more RAM memory to Qemu. The default 512MB is not enough and thus at least -m 1024 is needed in Qemu's commandline to boot without a hang.

qemu-system-riscv64 -machine sifive_u -m 1024 -bios ./U540.fd -nographic

Thanks, Elias

P.S Now let's inverstigate why less than 1024MB is not enough!

changab commented 4 years ago

Thank Elias for verifying this. I will add this information to the document under https://github.com/riscv/riscv-uefi-edk2-docs.

changab commented 4 years ago

Thank Elias for verifying this. I will add this information to the document under https://github.com/riscv/riscv-uefi-edk2-docs.

Done. Add QEMU section on https://github.com/riscv/riscv-uefi-edk2-docs/blob/master/README.md