如何使用TinyVision去手动构建Linux 6.1+Debian 12镜像呢?

描述

SyterKit是一个纯裸机框架,可以用于TinyVision或者v851se/v851s/v853等芯片的开发板,SyterKit使用CMake作为构建系统构建,支持多种应用与多种外设驱动。同时SyterKit也具有启动引导的功能,可以替代U-Boot实现快速启动。

在开始系统构建前需要准备TinyVision开发板及如下线材,

  TF卡

使用40Gbps数据线连接TinyVision开发板和TypeC-SUB调试器,如下图所示:

  TF卡

使用两条Type-C连接TypeC UART调试器和电脑端,连接完成后即可按照下文步骤构建系统。

从零构建SyterKit

构建 SyterKit 非常简单,只需要在 Linux 操作系统中安装配置环境即可编译。SyterKit 需要的软件包有:

gcc-arm-none-eabi

CMake

对于常用的 Ubuntu 系统,可以通过如下命令安装:

 

sudo apt-get update
sudo apt-get install gcc-arm-none-eabi cmake build-essential -y

 

然后新建一个文件夹存放编译的输出文件,并且进入这个文件夹

 

mkdir build
cd build

 

然后运行命令编译 SyterKit

 

cmake ..
make
  TF卡   

 

编译后的可执行文件位于 build/app 中,这里包括 SyterKit 的多种APP可供使用。

   TF卡

这里我们使用的是 syter_boot 作为启动引导。进入 syter_boot 文件夹,可以看到这些文件

  TF卡

由于 TinyVision 是 TF 卡启动,所以我们需要用到 syter_boot_bin_card.bin

   TF卡    

编译Linux-6.1内核

由于 Debian 12 配套的内核是 Linux 6.1 LTS,所以这里我们选择构建 Linux 6.1 版本内核。

搭建编译环境

安装一些必要的安装包

 

sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf build-essential libncurses5-dev zlib1g-dev gawk flex bison quilt libssl-dev xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip lsof
   

 

获取内核源码

内核源码托管在 Github 上,可以直接获取到,这里使用 --depth=1 指定 git 深度为 1 加速下载。

 

git clone http://github.com/YuzukiHD/TinyVision --depth=1

 

然后进入内核文件夹

 

cd kernel/linux-6.1
   

 

配置内核选项

应用 defconfig

 

CROSS_COMPILE=arm-linux-gnueabihf- make ARCH=arm tinyvision_defconfig

 

进入 menuconfig 配置选项

 

CROSS_COMPILE=arm-linux-gnueabihf- make ARCH=arm menuconfig

 

进入General Setup,

选中Control Group Support,

TF卡TF卡

前往File Systems,

找到FUSE support,

TF卡

前往File Systems,

找到Inotify support for userspace,

TF卡

编译内核

 

CROSS_COMPILE=arm-linux-gnueabihf- make ARCH=arm

 

使用debootstrap

构建debian rootfs

下载安装依赖环境

 

sudo apt install debootstrap qemu qemu-user-static qemu-system qemu-utils qemu-system-misc binfmt-support dpkg-cross debian-ports-archive-keyring --no-install-recommends

 

生成目标镜像,配置环境,这里我们生成一个 1024M 的镜像文件用于存放 rootfs

 

dd if=/dev/zero of=rootfs.img bs=1M count=1024
mkdir rootfs
mkfs.ext4 rootfs.img
sudo mount rootfs.img rootfs

 

这里我们选择最新的 debian12 (bookwarm) 作为目标镜像,使用清华源来构建,输出到目标目录 rootfs_data 文件夹中。新版本的 debootstrap 只需要运行一次即可完成两次 stage 的操作,相较于老版本方便许多。

 

sudo debootstrap --arch=armhf bookworm rootfs_data https://mirrors.tuna.tsinghua.edu.cn/debian/
   TF卡   

 

等待构建完成后,使用chroot进入到目录,这里编写一个挂载脚本方便挂载使用,新建文件 ch-mount.sh 并写入以下内容:

   TF卡

然后赋予脚本执行的权限,执行挂载,可以看到进入了 debian 的 rootfs

   TF卡

配置系统字符集,选择 en_US 作为默认字符集,选择一个就可以

 

export LC_ALL=en_US.UTF-8
apt-get install locales
dpkg-reconfigure locales
   TF卡       TF卡  

 

安装Linux基础工具

 

apt install sudo ssh openssh-server net-tools ethtool wireless-tools network-manager iputils-ping rsyslog alsa-utils bash-completion gnupg busybox kmod wget git curl --no-install-recommends
   

 

安装编译工具

 

apt install build-essential
   

 

安装Linux nerd工具

 

apt install vim nano neofetch
   

 

设置本机入口ip地址

 

cat < /etc/hosts
127.0.0.1       localhost
127.0.1.1       $HOST
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
EOF
   

 

配置网卡

 

mkdir -p /etc/network
cat >/etc/network/interfaces <
   

 

配置DNS地址

 

cat >/etc/resolv.conf <
   

 

配置分区

 

cat >/etc/fstab <               
/dev/mmcblk0p1  /boot   vfat    defaults                0       0
/dev/mmcblk0p2  /       ext4    defaults,noatime        0       1
EOF
   

 

配置root密码

 

passwd
   

 

配置主机名

 

echo TinyVision > /etc/hostname
   

 

取消挂载chroot

 

./ch-mount.sh -u rootfs_data/
   

 

拷贝rootfs到镜像中

 

sudo cp -raf rootfs_data/* rootfs
   

 

取消挂载

 

sudo umount rootfs
   

 

打包固件

完成以上步骤debian rootfs就制作好了。

编译完成 bootloader,内核,rootfs 后,还需要打包固件成为可以 dd 写入的固件,这里我们使用 genimage 工具来生成构建。

生成刷机镜像

编译内核后,就可以生成sun8i-v851se-tinyvision.dtb和zImage文件,我们把他们拷贝出来。

  TF卡

然后将sun8i-v851se-tinyvision.dtb改名为sunxi.dtb,这个设备树名称是定义在SyterKit源码中的,如果之前修改了SyterKit的源码需要修改到对应的名称,SyterKit会去读取这个设备树。

然后编写一个config.txt作为配置文件

 

[configs]
bootargs=root=/dev/mmcblk0p2 earlyprintk=sunxi-uart,0x02500000 loglevel=2 initcall_debug=0 rootwait console=ttyS0 init=/sbin/init
mac_addr=4a:13f9:79:75
bootdelay=3

 

安装genimage作为打包工具。

 

sudo apt-get install libconfuse-dev #安装genimage依赖库
sudo apt-get install genext2fs      # 制作镜像时genimage将会用到
git clone https://github.com/pengutronix/genimage.git
cd genimage
./autogen.sh                        # 配置生成configure
./configure                         # 配置生成makefile
make
sudo make install

 

编译后运行试一试,这里正常

   TF卡

编写 genimage.cfg 作为打包的配置

   TF卡

由于genimage的脚本比较复杂,所以编写一个 genimage.sh 作为简易使用的工具

   TF卡

准备完成,文件如下所示

   TF卡

运行命令进行打包

 

chmod 777 genimage.sh
./genimage.sh -c genimage.cfg
  TF卡  

 

打包完成,可以找到img文件,使用软件烧录固件到TF卡上。

   TF卡

本文内容均转载自https://www.gloomyghost.com/live/20231220.aspx


 

审核编辑:刘清

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分