您尚未登录。

楼主 # 2024-05-24 09:34:17

打盹的消防车
会员
注册时间: 2020-08-10
已发帖子: 5
积分: 104.5

V3S与f1c100基于最新u-boot+linux开发记录

# V3S与f1c100基于最新u-boot+linux开发记录

## 准备工作

先更新下本地软件包列表,是否更新软件自己决定

sudo apt-get update
sudo apt-get upgrade

### 安装编译工具链

安装编译工具链(这里直接使用apt安装的13版本)

#不带FPU(f1c100)
sudo apt-get install gcc-arm-linux-gnueabi
#带FPU(v3s)
sudo apt-get install gcc-arm-linux-gnueabihf

检查工具链版本,测试是否安装成功

arm-linux-gnueabi-gcc -v
arm-linux-gnueabihf-gcc -v

手动安装方式:
上面安装的是linaro出的编译器,所以这里以arm出的编译器为例,
先在官网 https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads 下载编译器 ,这里下载 13.2 rel1版本

tar -xvf arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz -C /home/name/toolchain/arm-gnu-toolchain-x86_64-arm-none-linux-gnueabihf

在 /etc/profile 中添加

export PATH="$PATH:/home/lqy/toolchain/arm-gnu-toolchain-x86_64-arm-none-linux-gnueabihf/bin"

重新加载环境变量的配置文件

source /etc/profile

检查是否生效

arm-none-linux-gnueabihf-gcc -v

### 安装编译必要的依赖库和工具

sudo apt-get install libncurses5-dev swig bison flex gparted libssl-dev
sudo apt-get install python3-pip
sudo apt-get install git


## uboot编译

### 克隆uboot仓库

git clone https://github.com/Lichee-Pi/u-boot.git

上面是荔枝派仓库,这里我们使用u-boot主线仓库

git clone https://github.com/u-boot/u-boot.git

切换到最新的v2024.01标签并创建分支

git checkout -b v2024.01 v2024.01

注意:因为不想编译时输入那么多命令,故修改根目录下Makefile中

ifeq ($(HOSTARCH),$(ARCH))
CROSS_COMPILE ?=
endif

下添加

ARCH ?=arm
CROSS_COMPILE ?=arm-linux-gnueabihf-

这样可以省略 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

使用荔枝派Zero配置

make licheepi_nano_defconfig
make LicheePi_Zero_defconfig

### uboot配置

图形配置:

make menuconfig

f1c100s的话修改以下(可选):

`arch/arm/mach-sunxi/dram_suniv.c` 中
`struct dram_para suniv_dram_para` 中 .clk的156 换成 CONFIG_DRAM_CLK

`ARM architecture > (156) sunxi dram clock speed` 修改为 240 (若上面没修改则在此处修改)

`General setup > (408000000) CPU clock frequency` 主频修改为 720000000

`boot 16/32M fat16` (大小自己根据kernel/dtb大小决定)
rootfs -- ext4

#### 启动配置:


如果需要flash启动,勾选 `Device Drivers > SPI Support 和 Device Drivers > MTD Support > SPI Flash Support`
之后根据自己flash厂家勾选对应支持,我这里勾选`Winbond SPI flash support`
若不支持也别着急搞驱动,勾选`SFDP table parsing support for SPI NOR flashes (NEW)`可以支持SFDP协议的flash,基本上都支持
若flash大于16M,勾选上 `SPI flash Bank/Extended address register support (NEW)`
S`PI Flash default speed in Hz`自行修改



勾选 Boot options > Enable boot arguments
如果需要TF启动,Boot arguments (NEW)修改为

console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 earlyprintk rw

如果需要flash启动,Boot arguments (NEW)修改为

console=ttyS0,115200 panic=5 rootwait;mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=31:03 earlyprintk rw rootfstype=jffs2

勾选 Boot options > Enable a default value for bootcmd
如果需要TF启动,bootcmd value 修改为

#f1c
load mmc 0:1 0x80008000 zImage;load mmc 0:1 0x80c08000 suniv-f1c100s-licheepi-nano.dtb;bootz 0x80008000 - 0x80c08000
#v3s
load mmc 0:1 0x41000000 zImage;load mmc 0:1 0x41800000 sun8i-v3s-licheepi-zero.dtb;bootz 0x41000000 - 0x41800000

如果需要flash启动,bootcmd value 修改为

sf probe 0;sf read 0x41800000 0x100000 0x10000;sf read 0x41000000 0x110000 0x400000;bootz 0x41000000 - 0x41800000

**flash启动环境命令解析:**
sf probe 0; //初始化Flash设备(CS拉低)
sf read 0x41800000 0x100000 0x10000;//从flash 0x100000(1MB)位置读取dtb放到内存0x41800000偏移处。
sf read 0x41000000 0x110000 0x400000;//从flash 0x110000(1MB+64KB)位置读取dtb放到内存0x41000000偏移处。
bootz 0x41000000 (内核地址)- 0x41800000(dtb地址) 启动内核

默认延迟2s启动,不想等待可以修改
Boot options > Autoboot options > (2)   delay in seconds before automatically booting

**注意:delay 参数首次启动时候会写入配置文件,后续启动会优先按照配置中启动,所以后续修改要清理配置文件才会生效**

编译

make -j24

至此u-boot编译完毕,编译成功后得到 `u-boot-sunxi-with-spl.bin`





## linux编译

### 克隆linux仓库

git clone https://github.com/Lichee-Pi/linux.git

上面是荔枝派仓库,这里我们使用linux主线仓库

git clone https://github.com/torvalds/linux.git

切换到最新的v6.7标签并创建分支

git checkout -b v6.7 v6.7

此处clone需要大量时间,推荐直接在 kernel.org 下载

注意:同u-boot,因为不想输入那么多命令,故修改根目录下Makefile中

ARCH		?= $(SUBARCH)

改为

ARCH ?=arm
CROSS_COMPILE ?=arm-linux-gnueabihf-

这样可以省略 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

复制Lichee-Pi的arch/arm/configs/licheepi_xxx_defconfig配置到linux主线对应目录下随后使用荔枝派配置


make licheepi_nano_defconfig
make licheepi_zero_defconfig

### 内核配置

图形配置

make menuconfig



编译

make -j24

make dtbs

make -j24 INSTALL_MOD_PATH=out modules
make -j24 INSTALL_MOD_PATH=out modules_install

至此linux内核编译完成,生成内核文件zImage在arch/arm/boot下,设备树文件sun8i-v3s-licheepi-zero.dtb在arch/arm/boot/dts/allwinner下,驱动模块在out/下



## 根文件系统编译

### 下载最新buildroot

wget https://buildroot.org/downloads/buildroot-2023.11.tar.gz

解压

tar xvf buildroot-2023.11.tar.gz

### 根文件系统配置:

图形配置

make menuconfig

下载源
Build options → Mirrors and Download locations

(https://sources.buildroot.net) Backup download site
(https://cdn.kernel.org/pub) Kernel.org mirror
(http://ftpmirror.gnu.org) GNU Software mirror
(http://rocks.moonscript.org) LuaRocks mirror
(https://cpan.metacpan.org) CPAN mirror (Perl packages)

修改为

(https://sources.buildroot.net) Backup download site
(https://mirrors.ustc.edu.cn/kernel.org) Kernel.org mirror
(https://mirrors.ustc.edu.cn/gnu) GNU Software mirror
(https://luarocks.cn) LuaRocks mirror
(https://mirrors.ustc.edu.cn/CPAN) CPAN mirror (Perl packages)

工具链:

Toolchain
  -> Toolchain type = External toolchain
  -> Toolchain = Custom toolchain
  -> Toolchain origin = Pre-installed toolchain
  -> Toolchain path =
  -> Toolchain prefix = $(ARCH)-linux-gnueabihf
  -> External toolchain gcc version = 11.9.x
  -> External toolchain kernel headers series = 4.1.x
  -> External toolchain C library = glibc
  -> [*] Toolchain has SSP support? (NEW)
  -> [*] Toolchain has RPC support? (NEW) 
  -> [*] Toolchain has C++ support? 

系统配置:

System configuration
 -> System hostname = Jasonangel //平台名字,自行设置
 -> System banner = Welcome to xxxxx //欢迎语
 -> Init system = BusyBox //使用 busybox
 -> /dev management = Dynamic using devtmpfs + mdev //使用 mdev
 -> [*] Enable root login with password (NEW) //使能登录密码
  -> Root password = 123456 //登录密码为 123456

文件系统格式:

-> Filesystem images
 -> [*] ext2/3/4 root filesystem //如果是 EMMC 或 SD 卡的话就用 ext3/ext4
  -> ext2/3/4 variant = ext4 //选择 ext4 格式
 -> [*] ubi image containing an ubifs root filesystem //如果使用 NAND 的话就用 ubifs

等等,按需配置


编译

make

## 其他功能/应用配置

### 显示

DRM:

linux内核配置:

Memory Management options -> Contiguous Memory Allocator 
Library routines -> DMA Contiguous Memory Allocator
(256) Size in Mega Bytes

rgb屏幕为例:

Device Drivers > Graphics support > Display Panels -> support for simple panels (other than eDP ones)

如果还想使用fb*设备,勾选 `Enable legacy fbdev support for your modesetting driver`

设备树添加:

/ {
	backlight: backlight {
		compatible = "pwm-backlight";
		pwms = <&pwm 0 1000000 0>;
		brightness-levels = <0 30 40 50 60 70 100>;
		default-brightness-level = <6>;
	};
	

	panel: panel {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "qiaodian,qd43003c0-40", "simple-panel";//480x272
	
		port@0 {
			reg = <0>;
			backlight = <&backlight>;
			#address-cells = <1>;
			#size-cells = <0>;
	
			panel_input: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&tcon0_out_lcd>;
			};
		};
	};

};

&de {
	status = "okay";
};

&pwm {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm0_pin>;
	status = "okay";
};

&tcon0 {
	pinctrl-names = "default";
	pinctrl-0 = <&lcd_rgb666_pins_a>;
	status = "okay";
};

&tcon0_out {
	tcon0_out_lcd: endpoint@0 {
		reg = <0>;
		remote-endpoint = <&panel_input>;
	};
};


如果想屏幕显示linux小企鹅

Device Drivers > Graphics support > Bootup logo

[*]   Standard black and white Linux logo (NEW)
[*]   Standard 16-color Linux logo (NEW)
[*]   Standard 224-color Linux logo (NEW)

如果想显示log则需要boot arguments里添加tty0即 console=ttyS0 改为 console=tty0 console=ttyS0

### 触屏

Device Drivers > Input device support >
Horizontal screen resolution
Vertical screen resolution

Touchscreens

Goodix I2C touchscree



### 音频

#### 配置

因为设备树里已经有codec了,我们只需要在设备树里开启即可

&codec {
	allwinner,audio-routing =
		"Headphone", "HP",
		"Headphone", "HPCOM",
		"MIC1", "Mic",
		"Mic",  "HBIAS";
	status = "okay";
};

初始化会看到

ALSA device list:
[    1.410776]   #0: V3s Audio Codec

执行 `ls /dev/snd/`可以看到

controlC0  pcmC0D0c   pcmC0D0p   timer

alsamixer 解除静音

### 视频播放

根文件系统配置:

Target packages → Audio and video applications → ffmpeg

Build ffmpeg (the command line application)
Build ffplay
Build ffprobe

Target packages → Graphic libraries and applications (graphic/text)

mesa3d
Gallium lima driver
OpenGL EGL 
OpenGL ES

软解播放视频:

mpv --no-video test.mp3

ffmpeg -i test.mp4 -s 480x272 -pix_fmt bgra -f fbdev /dev/fb0

mpv --vo=drm --drm-draw-surface-size=480x272 test.mp4

改为200为双缓冲
`Device Drivers > Graphics support > (100) Overallocation of the fbdev buffer`

硬解播放视频配置:

Device Drivers > Staging drivers > Media staging drivers 
Allwinner sunXi family Video Devices 
Allwinner Cedrus VPU driver 
<*>     Allwinner A31 Image Signal Processor (ISP) Driver 
Device Drivers > Multimedia support > Media drivers 
[*] Media platform devices (NEW)  --->
	[*]   V4L platform devices
	[*]   Memory-to-memory multimedia devices 
	<*>     Deinterlace support
	<*>   Video Multiplexer 
<*>   Allwinner Deinterlace driver
[*] V4L test drivers  ---> 
	<*>   Virtual Memory-to-Memory Driver      
	<*>   Virtual Codec Driver                                                   
	<*>   Virtual Media Controller Driver (VIMC)                                 
	<*>   Virtual Video Test Driver                                               
		[ ]     Enable CEC emulation support (NEW)                                    
		(64)    Maximum number of devices (NEW)            
	< >   Virtual Stateless Decoder Driver (visl) 

硬解播放视频:

ffmpeg -hwaccel drm -hwaccel_device /dev/dri/card0 -s 480x272 -pix_fmt bgra -f fbdev /dev/fb0 -i /home/test.mp4

mpv --vo=drm --hwdec=auto --drm-draw-surface-size=480x272 /home/test.mp4


## 烧录



### 准备工作:

安装gparted
sudo apt install gparted
选择TF卡卸载删除全部分区

首先新建linux分区,之前可用空间预留1M为uboot,新建32M fat16文件系统,卷标boot



### 烧录uboot

使用dd命令烧录u-boot到TF卡8K偏移处:

sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8
如果不是第一次烧录,会有uboot env参数已经写入,会导致比如修改启动延迟不生效等问题,清除uboot分区
sudo dd if=/dev/zero of=/dev/sdb bs=1024 count=1024 seek=8

**注意:/dev/sdb 指的是TF卡,可能是sdb也有可能是sdc,主要还是用命令 fdisk -l 来查看**

### 拷贝kernel以及设备树

拷贝kernel

sudo cp arch/arm/boot/zImage /media/lqy/BOOT/
拷贝设备树
sudo cp arch/arm/boot/dts/allwinner/sun8i-v3s-licheepi-zero.dtb /media/lqy/BOOT/

### 解压根文件系统

sudo tar -xvf rootfs.tar -C /media/lqy/rootfs/

离线

楼主 #1 2024-05-24 09:38:30

打盹的消防车
会员
注册时间: 2020-08-10
已发帖子: 5
积分: 104.5

Re: V3S与f1c100基于最新u-boot+linux开发记录

感谢晕哥赠送的V3S芯片~~~ big_smile big_smile big_smile

最近编辑记录 打盹的消防车 (2024-05-24 09:39:14)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn