当前位置: 首页 > 工具软件 > riscv-rootfs > 使用案例 >

为全志D1/RISCV64设备移植openwrt-22.03系统

凤晨朗
2023-12-01

在东山派设备上运行openwrt-22.03

本文记录了笔者为全志D1/RISCV64芯片的东山派STU嵌入式设备编译openwrt-22.03-rc6的过程。截止目前,笔者仅解决了基本的构建的问题,并未深入地进行系统级的开发(因此有很多问题,例如,目前它的网络是不通的)。移植过程中,参考了TINA-D1-SDK的一些处理,并与TINA-D1-SDK的分区配置保持一致。编译生成的固件可以使用全志PhoeniSuit工具烧写,系统能够正常启动、运行:

root@(none):/etc/config# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.5M      4.5M         0 100% /
tmpfs                   246.1M     36.0K    246.1M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
root@(none):/etc/config# mkfs.
mkfs.ext2   mkfs.ext3   mkfs.ext4   mkfs.f2fs   mkfs.ubifs
root@(none):/etc/config# mkfs.ubifs -y /dev/ubi0_8
root@(none):/etc/config# sync
root@(none):/etc/config# reboot
root@(none):/etc/config# [  198.038008] reboot_callback(): empty arg
[  198.042434] sunxi_ohci_hcd_shutdown, ohci0-controller is disable, need not shutdown
[  198.051083] sunxi_ehci_hcd_shutdown, ehci0-controller is disable, need not shutdown
[  198.059928] [ohci1-controller]: ohci shutdown start
[  198.065516] [ohci1-controller]: ohci shutdown end
[  198.070779] [ehci1-controller]: ehci shutdown start
[  198.076264] [ehci1-controller]: ehci shutdown end
[  199.092846] reboot: Restarting system

注意到,固件烧写成功后,笔者通过执行mkfs.ubifs命令在/dev/ubi0_8设备上创建了ubifs文件系统;当设备再次启动时,才能够正常挂载overlay文件系统:

BusyBox v1.35.0 (2022-07-31 15:12:47 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 22.03.0-rc6, r19590-042d558536
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/# uname -a
Linux OpenWrt 5.4.61+ #0 PREEMPT Sun Jul 31 15:12:47 2022 riscv64 GNU/Linux
root@OpenWrt:/# cat /proc/cpuinfo
processor       : 0
hart            : 0
isa             : rv64imafdcvu
mmu             : sv39

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.5M      4.5M         0 100% /rom
tmpfs                   246.1M     44.0K    246.1M   0% /tmp
/dev/ubi0_8             172.4M     44.0K    172.4M   0% /overlay
overlayfs:/overlay      172.4M     44.0K    172.4M   0% /
tmpfs                   512.0K         0    512.0K   0% /dev
root@OpenWrt:/# ps -w | tail
  614 root      1852 S    /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 -K 300 -T 3
  718 root      2884 S    {hostapd} /sbin/ujail -t 5 -n hostapd -U network -G network -C /etc/capabilities/wpad.json -c -- /usr/sbi
  719 root      2884 S    {wpa_supplicant} /sbin/ujail -t 5 -n wpa_supplicant -U network -G network -C /etc/capabilities/wpad.json 
  728 network   4696 S    /usr/sbin/hostapd -s -g /var/run/hostapd/global
  729 network   4696 S    /usr/sbin/wpa_supplicant -n -s -g /var/run/wpa_supplicant/global
  784 root      1932 S    /sbin/netifd
  842 root      1728 S    /usr/sbin/odhcpd
 1019 root      1804 S    /sbin/blockd
 1254 root      2848 R    ps -w
 1255 root      2784 S    tail
root@OpenWrt:/#

为东山派编译openwrt-22.03

在下载源码之前,需要安装riscv64-glibc-gcc-thead_20200702.tar.xz工具链。笔者修改的openwrt-22.03系统要求该工具链解压到/opt目录下:

sudo tar -Jxf riscv64-glibc-gcc-thead_20200702.tar.xz -C /opt

笔者已将源码上传至github,该仓库包含了两个子模块,分别对应D1-SoC的内核源码,以及openwrt-22.03,可以通过以下命令下载三个仓库的源码:

git clone https://github.com/jaqchen/ftopenwrt
cd ftopenwrt
git submodule init 
git submodule update

笔者执行以上命令的结果如下:

yejq@ubuntu:~$ git clone https://github.com/jaqchen/ftopenwrt
Cloning into 'ftopenwrt'...
remote: Enumerating objects: 127, done.
remote: Counting objects: 100% (127/127), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 127 (delta 33), reused 122 (delta 28), pack-reused 0
Receiving objects: 100% (127/127), 7.04 MiB | 1.68 MiB/s, done.
Resolving deltas: 100% (33/33), done.
yejq@ubuntu:~$ cd ftopenwrt/
yejq@ubuntu:~/ftopenwrt$ ls
build.bash  d1-h-nezha  dongshanpi-riscv64-target  linux-5.4  openwrt-22.03  target  tools
yejq@ubuntu:~/ftopenwrt$ git submodule init 
Submodule 'linux-5.4' (https://github.com/jaqchen/awd1-linux-5.4.git) registered for path 'linux-5.4'
Submodule 'openwrt-22.03' (https://github.com/jaqchen/openwrt-riscv64.git) registered for path 'openwrt-22.03'
yejq@ubuntu:~/ftopenwrt$ git submodule update
Cloning into '/home/yejq/ftopenwrt/linux-5.4'...
Cloning into '/home/yejq/ftopenwrt/openwrt-22.03'...
Submodule path 'linux-5.4': checked out 'b1fa839570ed3058e9440aee586b26383a1edfb6'
Submodule path 'openwrt-22.03': checked out 'daa9996b15d1997be57b617210a5abf5d733adbb'

源码下载完成后,可以执行./build.bash脚本,实现一键编译生成东山派的烧写镜像,在d1-h-nezha目录下:

yejq@ubuntu:~/ftopenwrt$ ls -lh
total 40K
-rwxrwxr-x  1 yejq yejq  13K 8月  28 10:17 build.bash
drwxrwxr-x  4 yejq yejq 4.0K 9月  18 21:22 d1-h-nezha
drwxrwxr-x  5 yejq yejq 4.0K 9月  18 21:13 dongshanpi-riscv64-target
drwxr-xr-x  3 yejq yejq 4.0K 8月  28 11:14 download
drwxrwxr-x 26 yejq yejq 4.0K 9月  18 21:57 linux-5.4
drwxrwxr-x 11 yejq yejq 4.0K 9月  18 21:58 openwrt-22.03
lrwxrwxrwx  1 yejq yejq   25 9月  18 16:13 target -> dongshanpi-riscv64-target
drwxrwxr-x  2 yejq yejq 4.0K 9月  18 21:13 tools
yejq@ubuntu:~/topenwrt$ ls openwrt-22.03/
BSDmakefile  config  Config.in  COPYING  feeds.conf.default  include  LICENSES  Makefile  package  README.md  rules.mk  scripts  target  toolchain  tools  version  version.date
yejq@ubuntu:~/ftopenwrt$ ./build.bash

编译过程中需要下载软件包的源码,根据不同的网络环境,可能会花费一些时间。编译完成的结果如下:

Generating index for package ./procd-ujail_2022-06-01-7a009685-2_riscv64_awd1.ipk
Generating index for package ./procd_2022-06-01-7a009685-2_riscv64_awd1.ipk
Generating index for package ./strace_5.16-1_riscv64_awd1.ipk
Generating index for package ./ubox_2021-08-03-205defb5-2_riscv64_awd1.ipk
Generating index for package ./ubus_2022-06-01-2bebf93c-1_riscv64_awd1.ipk
Generating index for package ./ubusd_2022-06-01-2bebf93c-1_riscv64_awd1.ipk
Generating index for package ./uci_2021-10-22-f84f49f0-6_riscv64_awd1.ipk
Generating index for package ./uclient-fetch_2021-05-14-6a6011df-1_riscv64_awd1.ipk
Generating index for package ./ucode-mod-fs_2022-06-01-b211ca0e-1_riscv64_awd1.ipk
Generating index for package ./ucode-mod-ubus_2022-06-01-b211ca0e-1_riscv64_awd1.ipk
Generating index for package ./ucode-mod-uci_2022-06-01-b211ca0e-1_riscv64_awd1.ipk
Generating index for package ./ucode_2022-06-01-b211ca0e-1_riscv64_awd1.ipk
Generating index for package ./urandom-seed_3_riscv64_awd1.ipk
Generating index for package ./urngd_2020-01-21-c7f7b6b6-1_riscv64_awd1.ipk
Generating index for package ./usign_2020-05-23-f1f65026-1_riscv64_awd1.ipk
Generating index for package ./wpad-basic-wolfssl_2022-01-16-cff80b4f-1_riscv64_awd1.ipk
Generating index for package ./zlib_1.2.11-4_riscv64_awd1.ipk
Generating index for package ./lua-bit32_5.3.0-1_riscv64_awd1.ipk
Generating index for package ./luaposix_35.1-1_riscv64_awd1.ipk
Signing package index...
make[2]: Leaving directory '/home/yejq/ftopenwrt/openwrt-22.03'
export MAKEFLAGS= ;make -w -r json_overview_image_info
make[2]: Entering directory '/home/yejq/ftopenwrt/openwrt-22.03'
WORK_DIR=/home/yejq/ftopenwrt/openwrt-22.03/build_dir/target-riscv64-unknown-linux-gnu_glibc/json_info_files /home/yejq/ftopenwrt/openwrt-22.03/scripts/json_overview_image_info.py /home/yejq/ftopenwrt/openwrt-22.03/bin/targets/dongshanpi/awd1/profiles.json 
JSON info file script could not find any JSON files for target
make[2]: Leaving directory '/home/yejq/ftopenwrt/openwrt-22.03'
export MAKEFLAGS= ;make -w -r checksum
make[2]: Entering directory '/home/yejq/ftopenwrt/openwrt-22.03'
make[2]: Leaving directory '/home/yejq/ftopenwrt/openwrt-22.03'
make[1]: Leaving directory '/home/yejq/ftopenwrt/openwrt-22.03'
already configured: d1-h-nezha, skipped
'image/boot.fex' => 'boot.img'
'/home/yejq/ftopenwrt/openwrt-22.03/build_dir/target-riscv64-unknown-linux-gnu_glibc/linux-dongshanpi_awd1/root.squashfs' -> 'rootfs.img'
'image/rootfs.fex' => 'rootfs.img'
/home/yejq/ftopenwrt/tools/
/home/yejq/ftopenwrt/d1-h-nezha/image
Begin Parse sys_partion.fex
Add partion boot-resource.fex BOOT-RESOURCE_FEX
Add partion very boot-resource.fex BOOT-RESOURCE_FEX
FilePath: boot-resource.fex
FileLength=2f8c00Add partion env.fex ENV_FEX000000000
Add partion very env.fex ENV_FEX000000000
FilePath: env.fex
FileLength=20000Add partion env.fex ENV_FEX000000000
Add partion very env.fex ENV_FEX000000000
FilePath: env.fex
FileLength=20000Add partion boot.fex BOOT_FEX00000000
Add partion very boot.fex BOOT_FEX00000000
FilePath: boot.fex
FileLength=50f800Add partion rootfs.fex ROOTFS_FEX000000
Add partion very rootfs.fex ROOTFS_FEX000000
FilePath: rootfs.fex
FileLength=446aceAdd partion dsp0.fex DSP0_FEX00000000
Add partion very dsp0.fex DSP0_FEX00000000
FilePath: dsp0.fex
FileLength=3e38cBuildImg 0
Dragon execute image.cfg SUCCESS !
-rwxrwxr-x 1 yejq yejq 16M 9月  18 23:12 tina_d1-h-nezha_uart0.img

以上最后一行,是生成的烧写固件,在d1-h-nezha目录下;可使用PhoeniSuite工具烧写到东山派设备。

openwrt-22.03对外部工具链的支持

笔者对openwrt-22.03的修改,并未增加riscv64/gcc工具链的自动化构建功能,而是使用到了全志官方提供的交叉工具链;这样可以节约大量的时间,加快编译进程。据笔者所知,目前openwrt系统尚未支持riscv芯片设备。笔者为openwrt-22.03加入了一个重要的补丁,解决了openwrt系统对外部工具链的支持的一些问题。笔者在其他两个不重要补丁被接收后,曾尝试向开源社区邮件组提交该补丁,但未收到回应;此后笔者未再向openwrt开源社区提供补丁。加入该补丁后,需要注意openwrt-22.03配置文件的几个关键项:

CONFIG_TOOLCHAIN_BIN_PATH="./usr/bin ./bin"
CONFIG_TOOLCHAIN_INC_PATH="./sysroot/usr/include"
CONFIG_TOOLCHAIN_LIBC="glibc"
CONFIG_TOOLCHAIN_LIB_PATH="./sysroot/lib64xthread/lp64d"
CONFIG_TOOLCHAIN_LTO_ARCHIVE_FIXUP=y
CONFIG_TOOLCHAIN_PREFIX="riscv64-unknown-linux-gnu-"
CONFIG_TOOLCHAIN_ROOT="/opt/riscv64-glibc-gcc-thead_20200702"
CONFIG_USE_EXTERNAL_LIBC=y
CONFIG_USE_GLIBC=y
CONFIG_USE_STRIP=y

值得强调的是CONFIG_TOOLCHAIN_LTO_ARCHIVE_FIXUP配置项,务必使能,否则openwrt在编译过程中很多静态库会有问题。此外,还需要禁止pppd等软件包的编译,防止因新版本的glibc删除了相关的加密函数导致pppd编译失败。

正如上面提到的,笔者仅对openwrt系统进行了必要的修改,以实现完整的编译构建。目前很多功能暂时不可用,例如以太网、WiFi、sysupgrade升级(需要调整分区表)等等。鉴于笔者当前比较忙,以后有足够的业余时间再完善;也希望本文对想在东山派开发板上运行新版本openwrt的开发者有一定的帮助。

 类似资料: