Code Monkey home page Code Monkey logo

Comments (2)

zhutang avatar zhutang commented on May 25, 2024 1

Hi @zhutang, I tried using your toolchain. When I enter ./riscv64-unknown-elf-gcc -v to see the result.

Using built-in specs.
COLLECT_GCC=./riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/qqm/Downloads/riscv/bin/../libexec/gcc/riscv64-unknown-elf/12.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc/configure --target=riscv64-unknown-elf --prefix=/opt/riscv --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=g2ee5e430018 --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc --disable-multilib --with-abi=lp64d --with-arch=rv64gc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os   -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os   -mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (g2ee5e430018) 

-mcmodel=medlow is not an option we need. Because trusted_fw.bin need to link to high addresses above 0x80000000.You can refer to the instructions here for the correct toolchain compilation options(sorry only in chinese).

2021.07.28(晚上):trusted_domain裸机程序可以使用newlib了,因此修改了一下启动脚本并做了相关newlib桩函数的移植,然后编译发现出错,原来是因为我们使用编译选项-mcmodel=medany来保证程序可以链接到0x80000000以上的高地址,但是默认编译的带newlib的编译器使用了-mcmodel=medlow来编译c库,因此无法链接,又踩到一个坑,只好重新编译了。最终总结编译命令如下:
```shell
# 用于裸机带newlib的gcc
./configure --prefix=/opt/gcc-riscv64-unknown-elf --with-cmodel=medany
make -j16
# 用于linux带glibc的gcc
./configure --prefix=/opt/gcc-riscv64-unknown-linux-gnu
make linux -j16
```
到这里我们的编译器基本更换完成,后面如果遇到问题终于不用担心别人提供的二进制开发工具是否存在问题了,我们拥有全部的源码可以自行编译、debug、fix问题,O(∩_∩)O哈哈~

谢谢!我用你发的这个编译器
https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz)
成功完成了trusted_domain的编译,但用这个
https://github.com/riscv/riscv-gnu-toolchain/releases/download/2021.08.07/riscv64-glibc-ubuntu-20.04-nightly-2021.08.07-nightly.tar.gz)
编译器编译busybox的时候有些问题:
/opt/gcc-riscv64-unknown-linux-gnu/bin/../lib/gcc/riscv64-unknown-linux-gnu/11.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: coreutils/lib.a(mktemp.o): in function .L5': mktemp.c:(.text.mktemp_main+0x88): warning: the use of mktemp' is dangerous, better use mkstemp' or mkdtemp'
/opt/gcc-riscv64-unknown-linux-gnu/bin/../lib/gcc/riscv64-unknown-linux-gnu/11.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: unknown z ISA extension zmmul' /opt/gcc-riscv64-unknown-linux-gnu/bin/../lib/gcc/riscv64-unknown-linux-gnu/11.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: failed to merge target specific data of file coreutils/lib.a(test_ptr_hack.o) /opt/gcc-riscv64-unknown-linux-gnu/bin/../lib/gcc/riscv64-unknown-linux-gnu/11.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: unknown z ISA extension zmmul'
/opt/gcc-riscv64-unknown-linux-gnu/bin/../lib/gcc/riscv64-unknown-linux-gnu/11.1.0/../../../../riscv64-unknown-linux-gnu/bin/ld: failed to merge target specific data of file libbb/lib.a(lineedit_ptr_hack.o)
collect2: error: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
make: *** [Makefile:718:busybox_unstripped] 错误 1

然后切换到这个
https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.02.25/riscv64-glibc-ubuntu-20.04-nightly-2023.02.25-nightly.tar.gz)
编译器编译busybox和rootfs之后,就成功运行了。

from quard_star_tutorial.

QQxiaoming avatar QQxiaoming commented on May 25, 2024

Hi @zhutang, I tried using your toolchain. When I enter ./riscv64-unknown-elf-gcc -v to see the result.

Using built-in specs.
COLLECT_GCC=./riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/qqm/Downloads/riscv/bin/../libexec/gcc/riscv64-unknown-elf/12.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc/configure --target=riscv64-unknown-elf --prefix=/opt/riscv --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=g2ee5e430018 --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc --disable-multilib --with-abi=lp64d --with-arch=rv64gc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os   -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os   -mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (g2ee5e430018) 

-mcmodel=medlow is not an option we need. Because trusted_fw.bin need to link to high addresses above 0x80000000.You can refer to the instructions here for the correct toolchain compilation options(sorry only in chinese).

2021.07.28(晚上):trusted_domain裸机程序可以使用newlib了,因此修改了一下启动脚本并做了相关newlib桩函数的移植,然后编译发现出错,原来是因为我们使用编译选项-mcmodel=medany来保证程序可以链接到0x80000000以上的高地址,但是默认编译的带newlib的编译器使用了-mcmodel=medlow来编译c库,因此无法链接,又踩到一个坑,只好重新编译了。最终总结编译命令如下:
```shell
# 用于裸机带newlib的gcc
./configure --prefix=/opt/gcc-riscv64-unknown-elf --with-cmodel=medany
make -j16
# 用于linux带glibc的gcc
./configure --prefix=/opt/gcc-riscv64-unknown-linux-gnu
make linux -j16
```
到这里我们的编译器基本更换完成,后面如果遇到问题终于不用担心别人提供的二进制开发工具是否存在问题了,我们拥有全部的源码可以自行编译、debug、fix问题,O(∩_∩)O哈哈~

from quard_star_tutorial.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.