litex-hub / linux-on-litex-vexriscv

Linux on LiteX-VexRiscv
BSD 2-Clause "Simplified" License
573 stars 174 forks source link

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

Open zoro269 opened 2 years ago

zoro269 commented 2 years ago

https://github.com/litex-hub/linux-on-litex-vexriscv/issues/164#issue-767463348 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 commented 2 years ago

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 commented 2 years ago

Hi enjoy-digital Can you guide me the running steps and order of running? I still don't quite understand. Many thanks

Vào Th 3, 7 thg 6, 2022 vào lúc 14:05 enjoy-digital < @.***> đã viết:

Hi @zoro269 https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/litex-hub/linux-on-litex-vexriscv/issues/282#issuecomment-1148276695, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZP7SWH5MXLTNUBUNLMAQG3VN3YD3ANCNFSM5X7VYLMA . You are receiving this because you were mentioned.Message ID: @.***>

enjoy-digital commented 2 years ago

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 commented 2 years ago

I followed the instructions and got some errors as follows:

zoro269 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

zoro269 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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.