Skip to content
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

how to build and create opensbi.bin and image files as in Pre-built Bitstreams and Linux/OpenSBI images #282

Open
zoro269 opened this issue Jun 6, 2022 · 13 comments
Labels

Comments

@zoro269
Copy link

zoro269 commented Jun 6, 2022

#164 (comment)
I have followed the steps but still not working.
The purpose I want is to be able to build an openSBI image file like in the instructions above

@enjoy-digital
Copy link
Member

Hi @zoro269,

here is some code I used recently and that will probably be integrated soon in the repository:

def opensbi_build():
    # Be sure third_party dir is present and switch to it.
    create_third_party_dir()
    os.chdir("third_party")

    # Get OpenSBI.
    if not os.path.exists("opensbi"):
        os.system("git clone https://github.com/litex-hub/opensbi --branch 0.8-linux-on-litex-vexriscv")
    os.chdir("opensbi")

    # Configure / Build OpenSBI.
    os.system("make CROSS_COMPILE=riscv64-unknown-elf- PLATFORM=litex/vexriscv")

    # Copy Linux Images.
    os.system("cp build/platform/litex/vexriscv/firmware/fw_payload.bin ../../images/opensbi.bin")

Please let me know if you still have troubles building with this.

@zoro269
Copy link
Author

zoro269 commented Jun 7, 2022 via email

@enjoy-digital
Copy link
Member

This should work:

git clone https://github.com/litex-hub/opensbi --branch 0.8-linux-on-litex-vexriscv
cd opensbi
make CROSS_COMPILE=riscv64-unknown-elf- PLATFORM=litex/vexriscv

The binary is then located at build/platform/litex/vexriscv/firmware/fw_payload.bin.

@zoro269
Copy link
Author

zoro269 commented Jun 7, 2022

I followed the instructions and got some errors as follows:

  • first: at make CROSS_COMPILE=riscv64-unknown-elf- PLATFORM=litex/vexriscv . I got the following error:

ELF platform/litex/vexriscv/firmware/fw_dynamic.elf
/home/namnguyendc4/Testtt/linux-on-litex-vexriscv/opensbi/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/../lib/gcc/riscv64-unknown-elf/8.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/namnguyendc4/Testtt/linux-on-litex-vexriscv/opensbi/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/../lib/gcc/riscv64-unknown-elf/8.1.0/libgcc.a(div.o): ABI is incompatible with that of the selected emulation:
target emulation elf64-littleriscv' does not match elf32-littleriscv'
/home/namnguyendc4/Testtt/linux-on-litex-vexriscv/opensbi/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/../lib/gcc/riscv64-unknown-elf/8.1.0/../../../../riscv64-unknown-elf/bin/ld: failed to merge target specific data of file /home/namnguyendc4/Testtt/linux-on-litex-vexriscv/opensbi/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/../lib/gcc/riscv64-unknown-elf/8.1.0/libgcc.a(div.o)
collect2: error: ld returned 1 exit status
make: *** [Makefile:317: /home/namnguyendc4/Testtt/linux-on-litex-vexriscv/opensbi/build/platform/litex/vexriscv/firmware/fw_dynamic.elf] Error 1

@zoro269
Copy link
Author

zoro269 commented Jun 7, 2022

This leads to the file opensbi/build/platform/litex/vexriscv/firmware there is no file fw_payload.bin
and here is a picture of my firmware
image

@enjoy-digital
Copy link
Member

enjoy-digital commented Jun 7, 2022

@zoro269: Can you test with the GCC toolchain provided by python3 litex_setup.py --gcc=riscv?

(https://github.com/enjoy-digital/litex/blob/master/litex_setup.py#L323-L345)

@zoro269
Copy link
Author

zoro269 commented Jun 7, 2022

@enjoy-digital I have installed and tried the toolchain and still have the error

@zoro269
Copy link
Author

zoro269 commented Jun 8, 2022

@zoro269: Can you test with the GCC toolchain provided by python3 litex_setup.py --gcc=riscv?

(https://github.com/enjoy-digital/litex/blob/master/litex_setup.py#L323-L345)

@enjoy-digital
i tried it and it still fails
image

@zoro269
Copy link
Author

zoro269 commented Jun 20, 2022

@enjoy-digital

@zoro269: Can you test with the GCC toolchain provided by python3 litex_setup.py --gcc=riscv?

(https://github.com/enjoy-digital/litex/blob/master/litex_setup.py#L323-L345)

Thanks guys, I fixed it with the gcc toolchain that was shown and downloaded in the litex_setup.py file. But can you guys explain to me the difference between these two versions of gcc toolchain?

@enjoy-digital
Copy link
Member

Hi @zoro269,

the OpenSBI build probably require a minimum GCC version to build correctly. We haven't analyzed this so just recommend using the version that has been used successfully.

@myy1966
Copy link

myy1966 commented Dec 27, 2024

make CROSS_COMPILE=riscv64-unknown-elf- PLATFORM=litex/vexriscv
I get this error:
unrecognized opcode csrr a4,0x301', extension zicsr' required

How to fix it?

@Dolu1990
Copy link
Contributor

Either you get a older version of gcc (11.x) either would need to fix the flow to add the _zicsr to the march

@myy1966
Copy link

myy1966 commented Dec 30, 2024

Either you get a older version of gcc (11.x) either would need to fix the flow to add the _zicsr to the march

After changed PLATFORM_RISCV_ISA from rv32ima to rv32ima_zicsr_zifencei, I successfully built 1.3.1-linux-on-litex-vexriscv branch opensbi binary and used it to run sim.py.

I need to highlight two points that differ from enjoy-digital's description:

  1. After changed PLATFORM_RISCV_ISA from rv32ima to rv32ima_zicsr_zifencei, 0.8-linux-on-litex-vexriscv can built to binary but failed to boot linux. We should use 1.3.1-linux-on-litex-vexriscv.
  2. We should use fw_jump.bin instead of fw_payload.bin. The fw_payload.bin file has reached a size of 1.1 GB and contains a dump payload instead of booting the user-provided Linux kernel image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants