分享

【精选】WSL2Linux 子系统(三)_error: running build_extboot failed!

 logicsoft 2023-10-28 发布于浙江

WLS2Linux 子系统编译 Linux

上一篇文章中讲解 WSL2Linux 子系统的编译 Openwrt。有轻便子系统还可以再编译 buildroot,或者 Unbntu Debian 等 Linux 系统的 BSP(Board support package);再折腾个 rootfs,拼凑起来就是一个完成的 Ubuntu 或者 Debian 系统终端机。


提示:WSL2Linux 编译 rk3288 buildroot 源码。


1. 编译准备

1.1 获取 uboot kernel 源码

如果有 buildroot 完整代码,可直接用 repo 下载全部;获取源码和工具步骤可以跳过。
a) uboot 源码 由原厂 rkbin u-boot 共同组成

cd ~/inux
git clone https://github.com/rockchip-linux/rkbin.git #获取 rkbin
git clone https://github.com/rockchip-linux/u-boot.git #获取 uboot

b) kernel 源码

cd ~/inux
git clone https://github.com/rockchip-linux/kernel.git

c) 交叉编译工具链和下载工具 需借用buildroot的相关文件

# prebuilts/gcc/linux-x86/aarch64/
cd buildroot
cp -rf prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/ --parents ~/linux
# prebuilts/gcc/linux-x86/arm/
cp -rf prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/ --parents ~/linux
# linux 系统中升级工具
cp -rf tools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool --parents ~/linux
cp rkflash.sh ~/linux
# linux 系统打包工具
cp -rf tools/linux/Linux_Pack_Firmware/rockdev/ --parents ~/linux
# windows
tools/windows/RKDevTool #下载工具
tools/windows/DriverAssitant_v5.0.zip #驱动包 下载前需安装

提示:下载或解包源码时,请勿使用 root 权限操作。

1.2 编译依赖包安装

a) uboot 编译依赖包

安装 uboot 编译依赖包

sudo apt-get install gcc make device-tree-compiler gawk

如不安装编译需要依赖包,报错提示以及相关提示命令

  • make
Command 'make' not found, but can be installed with:

sudo apt install make # version 4.2.1-1.2, or
sudo apt install make-guile # version 4.2.1-1.2

手动安装 make

sudo apt install make
  • gcc
gcc -DCURSES_LOC="<curses.h>" -DLOCALE -DKBUILD_NO_NLS -I/home/fish/356x-linux/buildroot/output/rockchip_rk3568/build/buildroot-config -DCONFIG_=\"\" -c conf.c -o /home/fish/356x-linux/buildroot/output/rockchip_rk3568/build/buildroot-config/conf.o
/bin/sh: 1: gcc: not found

手动安装 gcc

sudo apt install gcc
  • device-tree-compiler
ERROR: No 'dtc', please: apt-get install device-tree-compiler
ERROR: Running build_uboot failed!
ERROR: exit code 1 from line 515:
./make.sh $RK_UBOOT_DEFCONFIG $UBOOT_COMPILE_COMMANDS

手动安装 device-tree-compiler

sudo apt install device-tree-compiler

awk 命令缺失

awk: line 2: function strtonum never defined
$sudo apt install gwak

b) kernel 编译依赖包

单次安装

sudo apt install gcc make bison cpio flex openssl libssl-dev liblz4-tool -y

如有遗漏或者未安装错误提示

  • bison
/bin/sh: 1: bison: not found
make[1]: *** [scripts/Makefile.lib:196: scripts/kconfig/zconf.tab.c] Error 127
make: *** [Makefile:578: rockchip_linux_defconfig] Error 2
ERROR: Running build_kernel failed!
ERROR: exit code 2 from line 573:
make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT

手动安装 bision

$ sudo apt install bison
  • flex
/bin/sh: 1: flex: not found
make[1]: *** [scripts/Makefile.lib:188: scripts/kconfig/zconf.lex.c] Error 127
make: *** [Makefile:578: rockchip_linux_defconfig] Error 2
ERROR: Running build_kernel failed!
ERROR: exit code 2 from line 573:
make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT

手动安装 flex

sudo apt install flex -y
  • libssl-dev
scripts/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory
21 | #include <openssl/bio.h>

手动安装 libssl-dev

sudo apt install libssl-dev
  • lz4c
/bin/sh: 1: lz4c: not found
make[1]: *** [arch/arm64/boot/Makefile:31:arch/arm64/boot/Image.lz4] 错误 1
make: *** [arch/arm64/Makefile:139:Image.lz4] 错误 2

手动安装 lz4c

sudo apt install liblz4-tool -y

c) 编译 recovery

单次安装依赖工具

sudo apt install expect g++ -y

如有遗漏或者未安装错误提示

  • expect
====Start build rockchip_rk356x_recovery====
you need to install 'unbuffer' (from package expect or expect-dev)
log saved on /home/skysi/rk3566-xf8/br.log
====Build rockchip_rk356x_recovery failed!====
tail: cannot open '/home/skysi/rk3566-xf8/br.log' for reading: No such file or directory
Command exited with non-zero status 1
you take 0:04.91 to build recovery
ERROR: Running build_recovery failed!
ERROR: exit code 1 from line 858:
/usr/bin/time -f "you take %E to build recovery" $COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY

手动安装 expect

sudo apt install expect -y
  • g++
2023-04-23T12:31:29 make[2]: g++: Command not found
$ sudo apt install g++

d) 编译 rootfs

单次安装依赖环境变量

sudo apt install fakeroot unbuffer expect unzip -y

如有遗漏或者未安装错误提示

  • fakeroot
 pack image tools
processing option: firmware
Install fakeroot First.
sudo apt-get install fakeroot
ERROR: Running build_firmware failed!
ERROR: exit code 255 from line 949:
./mkfirmware.sh $BOARD_CONFIG

手动安装 fakeroot

sudo apt install fakeroot -y
  • unbuffer
make: Leaving directory '/home/fish/356x-linux/buildroot'
you need to install 'unbuffer' (from package expect or expect-dev)
log saved on /home/fish/356x-linux/br.log
tail: cannot open '/home/fish/356x-linux/br.log' for reading: No such file or directory
Command exited with non-zero status 1
you take 0:02.53 to build builroot
ERROR: Running build_buildroot failed!
ERROR: exit code 1 from line 628:
/usr/bin/time -f "you take %E to build builroot" $COMMON_DIR/mk-buildroot.sh $BOARD_CONFIG
$ unbuffer

Command 'unbuffer' not found, but can be installed with:

sudo apt install expect

手动安装 unbuffer

$ sudo apt install expect unbuffer -y
  • unzip
2022-05-30T14:14:11 You must install 'unzip' on your build machine

手动安装 unbuffer

sudo apt install unzip

e) 安装python环境变量

/bin/bash: 行 1: python: 未找到命令
sudo apt install python2
cd /usr/bin
sudo ln -s python2.7 python

2. 编译源码

2.1 uboot

编译 uboot 和 MiniLoader.bin

cd ~/linux/u-boot
# 编译 rk3568
./make.sh rk3568
# 编译 rk3288
./make.sh rk3288
......
 load addr is 0x8400000!
pack input bin/rk32/rk3288_tee_ta_v2.01.bin 
pack file size: 734592(717 KB)
crc = 0x69d0e887
trustos version: Trust os
pack ./trust.img success! 
pack trust okay! Input: /home/fish/linux/rkbin/RKTRUST/RK3288TOS.ini

/home/fish/linux/u-boot
pack loader ok.(rk3288_loader_v1.09.263.bin)(0.02)
pack loader okay! Input: /home/fish/linux/rkbin/RKBOOT/RK3288MINIALL.ini

# 编译完成后生成 uboot.img 和 rk3288_loader_v1.09.263.bin

2.2 编译 kernel

cd ~/linux/kernel
# 编译 rk3568 为 64bit A55,可选用 aarch64
make ARCH=arm rockchip_linux_defconfig -j4
make ARCH=arm rk3568-evb2-lp4x-v10.img -j16
# 编译 rk3288 为 32bit A17, 须使用 arm
make ARCH=arm rockchip_linux_defconfig -j4
make ARCH=arm rk3288-evb-rk808-linux.img -j16
......
 LD [M]  drivers/net/wireless/marvell/mwifiex/mwifiex_sdio.ko
  LD [M]  drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd.ko
  LD [M]  drivers/net/wireless/marvell/mwifiex/mwifiex.ko
  Image:  resource.img (with rk3288-evb-rk808-linux.dtb logo.bmp logo_kernel.bmp) is ready
  Image:  boot.img (with Image  resource.img) is ready
  Image:  zboot.img (with zImage  resource.img) is ready

#编译完成后生成 4个镜像文件
# boot.img ---> 内核完整镜像
# kernel.img ---> 内核
# resource.img ---> logo 和 dtb
# zboot.img --> 最小内核

2.3 刷机

2.3.1 映射刚刚生成的镜像文件以及分区表

mdkir rockdev
cd rockdev
ln -s ../u-boot/rk3288_loader_v1.09.258.bin MiniLoaderAll.bin
ln -s ../u-boot/uboot.img uboot.img
ln -s ../kernel/zboot.img uboot.img
# buildroot
ln -s ../device/rockchip/rk3288/parameter.txt parameter.txt
# github 获取 uboot和kernel
cp /build/buildroot/device/rockchip/rk3288/parameter.txt ./parameter.txt

2.3.2 刷机

刷机过程可先刷 uboot,正常运行后再刷 boot;待内核正常运行后再刷文件系统;文件系统正常运行后终端设备则正常变身终端机。

Linux 刷机借助 rkflash.sh 脚本

# 刷loader
./rkflash.sh loader
# 刷分区表
./rkflash.sh parameter
./rkflash.sh uboot
./rkflash.sh boot
# 刷文件系统时 需手动映射或者拷贝 rootfs 到 rockdev 目录
./rkflash.sh rootfs

WSL2 子系统无法执行 mount 和 chroot 命令,故需要拷贝到 Windows 目录,使用相关工具刷机。

2.4 升级后以前驱动无法加载

错误提示:

wlan_mt7668_sdio: version magic '4.19.193 SMP mod_unload aarch64' should be '5.10.66 SMP mod_unload aarch64'

此问题因当前系统内核与升级前版本差异,致使驱动无法加载。此问题解决方法:刷机到 4.19.193 版本内核。


总结

WSL2 子系统终究是子系统,编译 uboot kernel openwrt 还可以胜任;如果编译 Android 和 Linux rootfs 则受系统和 CPU 限制,建议使用 Ubuntu PC或者服务器。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多