编译全志V3S(荔枝派zero)整个系统流程

购买到的硬件

全志V3S(荔枝派zero)

官方5寸液晶屏

声明一下用的主线Uboot + 主线linux,如果你是小白不幸买到了本产品建议弃坑既浪费时间,又浪费生命,香橙派树莓派是你更好的选择

如果想使用主线的特性,可以使用 主线Uboot + 主线linux 开发环境。系统配置为dts设备树配置。
主线uboot: https://github.com/Lichee-Pi/u-boot
主线linux: https://github.com/Lichee-Pi/linux
官网教程 http://zero.lichee.pro/

Uboot 编译与烧录

安装交叉编译器

wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
tar xvf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
mv gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf /opt/
vim /etc/bash.bashrc
# add: PATH="$PATH:/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin"
source /etc/bash.bashrc
arm-linux-gnueabihf-gcc -v
sudo apt-get install device-tree-compiler

烧录TF卡之前需要分区,安装GParted后如下分区

在这里插入图片描述

全志sunxi-tools烧录工具安装(fex文件转为二进制bin文件,主线版本可以跳过这一步)

//安装依赖包(不安装会报错)
sudo apt-get install pkg-config pkgconf zlib1g-dev libusb-1.0-0-dev

//获取源码
//v3s 分支
git clone -b v3s https://github.com/Icenowy/sunxi-tools.git
//f1c100s-spiflash 分支
git clone -b f1c100s-spiflash https://github.com/Icenowy/sunxi-tools.git

//进入源码文件夹
cd sunxi-tools
//编译和安装
make && sudo make install

下载编译Uboot

git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-current
#or git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-spi-experimental
cd u-boot
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_800x480LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_480x272LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_defconfig
make ARCH=arm menuconfig
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log

编译完成后当前目录下会生成u-boot-sunxi-with-spl.bin

将u-boot-sunxi-with-spl.bin烧录到TF卡中
TF卡中的系统镜像一般分为三个区:

boot区或者引导区 - 该部分没有文件系统而是直接将二进制的bootloader(uboot)文件直接写入。

linux内核区 - fat文件系统,存放linux内核、内核参数文件还有设备数dtb文件。

rootfs分区 - 用来存放根文件系统和用户数据等,一般是ext4文件分区格式。

扫描二维码关注公众号,回复: 13085983 查看本文章

烧录到TF卡

//插入TF卡前后查询,确认设备名称
ls /dev/sd*

//删除TF/SD的分区信息
sudo dd if=/dev/zero of=/dev/sdb bs=512K count=1

//烧录到TF卡(`u-boot-sunxi-with-spl.bin`在uboot根目录下)
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8

写入并编译bootargs引导参数

在uboot根目录下新建 boot.cmd

vim boot.cmd
# 写入以下内容
setenv bootargs console=ttyS0,115200 panic=5 console=tty0 rootwait root=/dev/mmcblk0p2 earlyprintk rw
load mmc 0:1 0x41000000 zImage
load mmc 0:1 0x41800000 sun8i-v3s-licheepi-zero.dtb
bootz 0x41000000 - 0x41800000

# mmcblk0p2
# mmc TF卡
# blk(block,块设备)
# 0(第一个块设备,也就是第一张sd卡)
# p(partition,分区)
# 通过设置early_printk选项,可以在内核串口设备初始化之前,看到打印输出

mkimage工具在uboot/tools文件夹下

sudo cp ./tools/mkimage /usr/local/bin/mkimage # 拷贝到用户文件夹下,方便以后可以直接使用
mkimage -C none -A arm -T script -d boot.cmd boot.scr # 生成`boot.scr`,然后将其放入第一分区

编译Linux内核

使用最新的内核:
git clone -b zero-5.2.y https://github.com/Lichee-Pi/linux.git
cd linux
make ARCH=arm licheepi_zero_defconfig
make ARCH=arm menuconfig   #add bluethooth, etc.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules_install

编译完成后,zImage在arch/arm/boot/下,驱动模块在out/下

usb虚拟串口实现
->Device Drivers
->USB support
->USB Gadget Support
在这里插入图片描述
Zero通过otg与PC共享网络
composite gadget: Serial and Ethernet.

复制到TF卡

boot.scr(主线llinux)
sun8i-v3s-licheepi-zero.dtb(设备树文件在arch/arm/boot/dts/下)
u-boot-sunxi-with-spl.bin(Uboot 已烧录 )
zImage(Linux内核)

Buildroot 根文件系统构建

wget https://buildroot.org/downloads/buildroot-2021.02.tar.gz
tar xvf buildroot-2021.02.tar.gz
cd buildroot-2021.02
make menuconfig

开启wifi配置功能
buildroot
-> make menuconfig
-> Target packages -> Networking applications
在这里插入图片描述
然后我建立了一个脚本connect_wx.sh

#!/bin/sh
insmod /usr/lib/r8723bs.ko #加入驱动
ifconfig wlan0 up      #开启wifi
wpa_supplicant -B -d -i wlan0 -c /etc/wpa_supplicant.conf    #搜索wifi
udhcpc -i wlan0       #连接wifi

放到 /etc/init.d/中

再 vi /etc/init.d/rcS

添加以下内容让他开机启动

if [ -e /etc/init.d/connect_wx.sh ]; then
        /etc/init.d/connect_wx.sh
fi

然后重启,终于可以连接到我的WiFi了!

查询编译工具链所在位置:

which arm-linux-gnueabihf-gcc

读取编译工具链里的内核版本:

cat /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/linux/version.h

查询得到
#define LINUX_VERSION_CODE 264707
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

十进制数264707的十二进制为0x40A03,则对应的内核版本号为4.10.0。

基本配置:

Target options  --->
	Target Architecture (ARM (little endian))  --->
	Target Binary Format (ELF)  --->
	Target Architecture Variant (cortex-A7)  --->
	Target ABI (EABIhf)  --->
	Floating point strategy (VFPv4-D16)  --->
	ARM instruction set (ARM)  ---> 


### 编译工具链配置:
Toolchain  --->
	Toolchain type (External toolchain)  --->
	*** Toolchain External Options ***
	Toolchain (Custom toolchain)  --->
	Toolchain origin (Pre-installed toolchain)  --->
	/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/) 
	Toolchain path
	($(ARCH)-linux-gnueabihf) Toolchain prefix 改为工具链前缀是: arm-linux-gnueabihf
	External toolchain gcc version (7.0.x)  --->
	External toolchain kernel headers series (4.10.x)  --->
	External toolchain C library (glibc/eglibc)  --->
	[*] Toolchain has SSP support? (NEW)
	[*] Toolchain has RPC support? (NEW)
	[*] Toolchain has C++ support? 
	[*] Enable MMU support (NEW) 

编译

make

如果出错则使用make clean然后再编译。
编译完成后,生成的根文件系统在 output/images/rootfs.tar。

烧录

# 查询挂载名
df -h
# 把buildroot产生的rootfs.tar解压到第二分区根目录
sudo tar xvf output/images/rootfs.tar -C /挂载的tf卡第二个分区目录(例:/media/pjw/9009f48f-8b2b-4b4c-a7f8-21887dd8432b)

最后终于到了激动人心的环节了,插上TF卡电源启动

故障答疑

  • Uboot 如果烧录正常的话会有Uboot 界面
  • bootargs引导参数正常会有一排排代码出现
  • Buildroot正常会有顺利进入系统

无法识别虚拟串口CDC Composite Device

使用 Linux Gadget 复合设备共享网络与虚拟串口
配置文件默认启用了USB Gadget,并指定了一个名为 CDC Composite Device (Ethernet and ACM)。这个默认的配置文件会创建一个USB复合设备,这个复合设备同时有着ACM(虚拟串口)和ECM(网络共享)的功能。一切听起来是那么的美好,以至于似乎直接上电插上USB口就能识别到设备了。然而,要是真的有这么顺利就好了。插上设备后,设备管理器中会多出一个 CDC Composite Device 设备。首先遇到的问题就是,没有驱动。这个的解决方案其实非常的简单,只需使用Zadig为这个设备安装一个串口驱动。串口驱动安装完成后,你就可以发现设备管理器中多出了一个串口。这时候,你就可以使用你的串口连接软件进行连接了。
真的有这么简单吗?你连接上之后就会发现,并不能输入任何的文字,也不会有任何的反应。这个情况是因为我们没有在inittab中使能这个终端。我们只需编辑/etc/inittab文件,添加一行ttyGS0::respawn:/bin/getty -L ttyGS0 57600 vt100即可启用这个终端。
接下来是网络共享的问题。之前我们提到过,这个默认的配置文件启用的是一个复合设备,然而我们在这里并没有看到其他的设备。看到这里,你应该猜到是什么问题了吧——没错,是Windows没有正确识别这个复合设备。根据这里的提示,我们需要手动编写一个脚本,让其手工配置USB Gadget的各项参数。这个脚本可以在这里找到,不过需要修改一下一开始的部分。首先是去掉modprobe的部分,这个驱动在内核中已经自动加载了。然后是手动挂载ConfigFS,使用mount none /config -t configfs
可以将configFS挂载到/config目录。这个脚本编辑完毕后,可以在/etc/init.d/里面放一个起动脚本,让其开机自动启动。
脚本部分写完之后,需要到编译的地方修改一些编译参数。具体是取消预配置”USB Gadget precomposed configurations”,然后启用”USB Gadget functions configurable through configfs”,并按需启用下面的子项目(例如CDC ACM、RNDIS等)。
重新编译并放入配置脚本后,就可以在设备管理器中看到两个设备了。RNDIS设备又是没有驱动,不过这次可以安装“网络适配器-Microsoft-远程NDIS兼容设备”来使其工作。

添加Serial + RNDIS的功能

https://blog.csdn.net/lan120576664/article/details/101081608

wifi驱动配置问题

https://whycan.com/t_2388.html

还有问题?联系我QQ480694856

猜你喜欢

转载自blog.csdn.net/a480694856/article/details/115328891