litex-hub / linux-on-litex-vexriscv

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

Error: unrecognized opcode `csrr s5,0xf14', extension `zicsr' required #391

Open phillippZZ opened 3 weeks ago

phillippZZ commented 3 weeks ago

Hi, everyone.

I tried to build a linux image with following commands:

$ git clone http://github.com/buildroot/buildroot $ cd buildroot $ make BR2_EXTERNAL=../linux-on-litex-vexriscv/buildroot/ litex_vexriscv_defconfig $ make menuconfig (And I checked out "gcc 11.x support removed" in the legacy config options) $ make

Then I got a lot of errors due to "ziscr":

/usr/src/buildroot/output/build/opensbi-1.3.1-linux-on-litex-vexriscv/lib/sbi/riscv_asm.c:195: Error: unrecognized opcode csrw 0x3b0+32+16+0+0+2+1,a1', extensionzicsr' required

How can I solve this issue?

Dolu1990 commented 3 weeks ago

hmm maybe replacing https://github.com/litex-hub/linux-on-litex-vexriscv/blob/ea17e31537cdabe780cf5747cbe5b37ea09f717f/buildroot/configs/litex_vexriscv_defconfig#L25C1-L25C21 with BR2_GCC_VERSION_12_X=y ?

Not sure

phillippZZ commented 3 weeks ago

It doesn't work. And I tried to add "March=rv32i_zicsr" somewhere for gcc but couldn't find a place to add it😅

Dolu1990 commented 2 weeks ago

This is related to :

Bootloader (opensbi)

BR2_TARGET_OPENSBI=y BR2_TARGET_OPENSBI_CUSTOM_GIT=y BR2_TARGET_OPENSBI_CUSTOM_REPO_URL="https://github.com/litex-hub/opensbi.git" BR2_TARGET_OPENSBI_CUSTOM_REPO_VERSION="1.3.1-linux-on-litex-vexriscv" BR2_TARGET_OPENSBI_PLAT="litex/vexriscv" BR2_TARGET_OPENSBI_INSTALL_DYNAMIC_IMG=n

That opensbi branch seems to bo too outdated.

trabucayre commented 2 weeks ago

@Dolu1990 this branch is used in CI with mainly one patch I have observed gateware and buildroot MUST be coherent (RVC is enabled in config, --with-rvc must be added)

phillippZZ commented 2 weeks ago

Sorry, I don't know what I'm supposed to do now. Do I use "https://github.com/riscv-software-src/opensbi" in "litex_vexriscv_defconfig", or keep using "https://github.com/litex-hub/opensbi.git" and follow @trabucayre 's instruction?

To enable RVC in config, I did the following:

BR2_RISCV_ISA_CUSTOM_RVC=y BR2_RISCV_ISA_RVC=y

Did I configure it in the correct way? And I don't know where to add "--with-rvc". Do I do it when building "riscv64-unknown-elf-gcc"? For now, I'm using "riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14" from the following flow:

$ wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gz $ tar -xvf riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gz $ export PATH=$PATH:$PWD/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/

Dolu1990 commented 2 weeks ago

@trabucayre My bad, you are right ^^ the version is good.

@phillippZZ By a happy hazard, i just hit the same issue.

I got things to compile with (didn't used RVC, i was on opensbi 1.4 on the generic platform, not the litex one, so it isn't 1 to 1 necessarly):

make   ... \
     PLATFORM_RISCV_XLEN=32 \
     PLATFORM_RISCV_ISA=rv32ima_zicsr_zifencei \
     PLATFORM_RISCV_ABI=ilp32 \
     ...
phillippZZ commented 2 weeks ago

@Dolu1990 Thank you.

Do I download opensbi 1.4 and compile it with something like:

$ wget https://github.com/riscv-software-src/opensbi/archive/refs/tags/v1.4.zip $ unzip v.1.4.zip $ cd opensbi $ make CROSS_COMPILE=riscv-none-embed- PLATFORM=generic PLATFORM_RISCV_XLEN=32 PLATFORM_RISCV_ISA=rv32ima_zicsr_zifencei PLATFORM_RISCV_ABI=ilp32

Somehow I get:

Assembler messages: Error: cannot find default versions of the ISA extension zicsr' Error: cannot find default versions of the ISA extensionzifencei'

Maybe there's something wrong with my riscv-none-embed-gcc.

Also, should I modify litex_vexriscv_defconfig as the following:

BR2_TARGET_OPENSBI=y BR2_TARGET_OPENSBI_CUSTOM_GIT=n BR2_TARGET_OPENSBI_CUSTOM_DIR="/path/to/local/opensbi" BR2_TARGET_OPENSBI_PLAT="generic" BR2_TARGET_OPENSBI_INSTALL_DYNAMIC_IMG=n

UPDATES: Insteading of integrating my program while building the linux image, I chose not to build a new linux image and put my program into the rootf.cpio downloaded via "https://github.com/litex-hub/linux-on-litex-vexriscv/files/8331338/linux_2022_03_23.zip". But I couldn't invoke the program by using "./program" or "source program".

After several attempts, I found that "sh XX.sh" works

Dolu1990 commented 1 week ago

Don't use opensbi 1.4, as i proposed, it is for when you use the generic opensbi platform, which is the same as proposed on linux-on-litex-vexriscv.

How did you made your program file ?

phillippZZ commented 1 week ago

I didn't use opensbi 1.4 or build the linux image. I simply compiled a project called IsolBench with "riscv64-unknown-linux-gnu-gcc" and moved it into the rootf.cpio. Then I simulated the linux with the files downloaded from "https://github.com/litex-hub/linux-on-litex-vexriscv/files/8331338/linux_2022_03_23.zip". Image As you can see, some of the scripts don't work since the linux image doesn't support certain functionalities.

Could you tell me how I can solve these issues? And IsolBench can be downloaded from "https://github.com/CSL-KU/IsolBench"