为VisionFive2编译uboot, opensbi, kernel

接上篇,单板收到后,能点亮,能运行官方debian镜像,下一步就想着自己编译一些文件。就从follow官方文档开始吧,选取了软件技术参考手册,(下文简称“TRM文档”)一步一步来。

在此之前,要先安装好交叉编译工具riscv64-linux-gnu-gcc.

[X@X u-boot-VF2_v2.5.0]$ riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (GCC) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

首先是编译是u-boot

下载源代码,VF2_v2.5.0

解压后,进入目录执行:

make starfive_visionfive2_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

结果遇到编译错误:

arch/riscv/cpu/cpu.c:96: Error: unrecognized opcode `csrs sstatus,a5', extension `zicsr' required
arch/riscv/cpu/cpu.c:97: Error: unrecognized opcode `csrw 0x003,0', extension `zicsr' required
make[1]: *** [scripts/Makefile.build:254: arch/riscv/cpu/cpu.o] Error 1
make: *** [Makefile:1817: arch/riscv/cpu] Error 2

在网上搜索了一下,大原因如下:

# Newer binutils versions default to ISA spec version 20191213 which moves some
# instructions from the I extension to the Zicsr and Zifencei extensions.

用下面这个文件替换u-boot_path/arch/riscv/Makefile即可。

u-boot/Makefile at master · u-boot/u-boot · GitHub

替换后重新执行 make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ,编译成功。下面三个文件后续会用。

=>u-boot.bin
=>arch/riscv/dts/starfive_visionfive2.dtb
=>spl/u-boot-spl.bin

然后是编译opensbi

下载代码:git clone https://github.com/starfive-tech/opensbi.git

cd opensbi
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=../u-boot-VF2_v2.5.0/u-boot.bin \
FW_FDT_PATH=../u-boot-VF2_v2.5.0/arch/riscv/dts/starfive_visionfive2.dtb FW_TEXT_START=0x40000000

注意,这里要指定上一步编译出来的u-boot.bin和starfive_visionfive2.dtb。

没有错误,后续会用到 build/platform/generic/firmware/fw_payload.bin

接下来创建SPL文件

下载代码:git clone https://github.com/starfive-tech/Tools.git

cd Tools
./create_sbl ../../u-boot-VF2_v2.5.0/spl/u-boot-spl.bin 0x01010101

这里需要指定uboot目录下的u-boot-spl.bin文件。

这一步出错了,

./create_hdr: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
cd /usr/lib
sudo ln -s libcrypto.so.3 libcrypto.so.1.1

本地已经有libcrypto.so.3,创建了一个链接再试,发现还是不行:

./create_hdr: /usr/lib/libcrypto.so.1.1: version `OPENSSL_1_1_0' not found (required by ./create_hdr)

看来编译需要特定版本的库文件。从网上下载了一个,可以从下面获取:

链接: https://pan.baidu.com/s/1KqeteLyGznoir1bXwHAFsA 提取码: eqks 
放到/usr/lib 目录即可,再次执行上面的命令,就会生成

opensbi/spl-tool/u-boot-spl.bin.normal.out,用于更新SPL和U-Boot

创建fw_payload文件

cd Tools_path/uboot_its/
cp opensbi_path/build/platform/generic/firmware/fw_payload.bin ./

将opensbi目录下之前生成的fw_payload.bin拷贝到 Tools/uboot_its/目录下,在此目录下执行:

../../u-boot-VF2_v2.5.0/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware visionfive2_fw_payload.img

注意,执行的是uboot目录下的命令。执行成功后生成visionfive2_fw_payload.img,用于更新SPL和U-Boot。

编译Linux内核

git clone https://github.com/starfive-tech/linux
git checkout -b JH7110_VisionFive2_devel origin/JH7110_VisionFive2_devel
git pull

make starfive_visionfive2_defconfig CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv -j8

与编译uboot类似,也会出现错误,需要修改arch/riscv/Makefile,如下(Makefile.bak是原来的文件):

[X@X riscv]$ diff -u Makefile.bak Makefile
--- Makefile.bak        2022-12-31 17:56:42.546938840 +0800
+++ Makefile    2022-12-31 17:57:14.706940158 +0800
@@ -52,6 +52,13 @@
 riscv-march-$(CONFIG_ARCH_RV64I)       := rv64ima
 riscv-march-$(CONFIG_FPU)              := $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)      := $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

编译完成后将在linux/arch/riscv/boot目录下,生成内核镜像文件Image.gz

至此,uboot,opensbi,kernel编译完成。

后面,可继续参考同一文档中“制作BusyBox系统”,在移植rootfs、dtb和内核到开发板上时,将使用到Image.gz和.dtb文件。

我的系统:manjaro 22.0

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值