# 1. IGKBoard 编译系统 **IGKBoard** ***(IoT Gateway Kit Board)*** 开发板是 **凌云物网智科实验室** 推出的一款ARM Linux物联网网关开发板。此开发板基于 ***NXP i.MX6ULL*** 系列 Cortex-A7 高性能处理器设计,适用于快速开发一系列具有创新性的产品如物联网网关、人机界面工业 4.0 扫描仪、车载终端以及便携式医疗设备。 凌云实验室针对该开发板从制作交叉编译器开始,从零构建了Buildroot、Yocto、Debian等Linux系统,所有系统相关源码维护在凌云实验室的官方git服务器上,接下来我们将讲解如何使用git仓库上的源码搭建交叉编译环境、编译制作系统镜像文件。 该项目测试开发环境为Ubuntu-20.04。 ## 1.1 项目源码介绍 首先在Linux服务器上使用 **git** 命令克隆下载该项目源码,如果没有 ***git*** 命令,则首先安装 **git** 命令并配置 **git** 的账号信息。 ``` guowenxue@5355ee897054:~$ sudo apt install git guowenxue@5355ee897054:~$ git config --global user.name guowenxue guowenxue@5355ee897054:~$ git config --global user.email "guowenxue@gmail.com" ``` 使用 **git** 命令克隆下载该项目源码: ``` guowenxue@5355ee897054:~$ git clone http://weike-iot.com:8088/r/imx6ull.git Cloning into 'imx6ull'... remote: Counting objects: 1505, done remote: Finding sources: 100% (1505/1505) remote: Getting sizes: 100% (680/680) remote: Total 1505 (delta 627), reused 1505 (delta 627) Receiving objects: 100% (1505/1505), 76.39 MiB | 371.00 KiB/s, done. Resolving deltas: 100% (627/627), done. ``` 下面是该项目当前源码目录结构的介绍: ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/ guowenxue@5355ee897054:~/imx6ull$ tree -L 2 . ├── README.md 本项目介绍文档 ├── 3rdparty 第三方开源库的交叉编译脚本 │   ├── evtest 输入设备驱动测试工具程序 │   └── QT5 知名的图形化界面开发库 ├── bsp Linux板级支持包源码目录 │   ├── build.sh BSP目录总的编译脚本,依次进入到子目录下编译 │   ├── bootloader U-boot编译目录及编译脚本 │   ├── images 制作系统镜像的脚本,编译生成文件的输出文件夹 │   ├── kernel Linux内核编译目录及编译脚本 │   ├── drivers Linux驱动目录及编译脚本 │   ├── rootfs 根文件系统制作脚本 │   ├── scripts 编译系统的一些工具脚本 │   ├── tarball Linux内核等源码下载目录及脚本 │   └── uapi Linux内核驱动测试脚本 ├── documents 文档目录 │   ├── datasheet 芯片datasheet │   ├── documents 使用手册说明文档 │   ├── NXP NXP官方文档 │   └── schematic 开发板原理图 ├── program 自己编写的一些应用程序 │   └── lvgl 另外一个跨平台、轻量级图形库 └── yocto Yocto项目支持目录 ├── build.sh Yocto的编译脚本 │   └── meta-igkboard Yocto移植的开发板meta-layer └── tools 本项目开发工具 ├── buildroot buildroot交叉编译器一键制作脚本 └── setup_tools.sh 开发环境安装脚本 ``` ## 1.2 编译环境安装 该项目源码路径 tools下有该项目的开发环境一键安装Shell脚本,以root权限执行该脚本将会自动下载并安装接下来开发过程中所依赖的系统命令工具。 ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/tools/ guowenxue@5355ee897054:~/imx6ull/tools$ sudo ./setup_tools.sh ``` # 2 自构建系统编译 ## 2.1 自构建系统介绍 该项目源码路径 ***bsp*** 文件夹下存放有U-boot、Linux内核、根文件系统树等编译制作脚本,同时顶层还有一个build.sh 的Shell脚本。该脚本用来一键编译所选择的目标源码,并将编译产生的烧录文件放到 images 路径下。 ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/bsp/ guowenxue@5355ee897054:~/imx6ull/bsp$ tree -L 2 . ├── build.sh 总的编译脚本 ├── bootloader │   ├── build.sh u-boot编译脚本 │   ├── igkboard.json u-boot编译的配置文件 │   └── patch u-boot修改补丁文件 ├── kernel │   ├── build.sh Linux内核编译脚本 │   ├── igkboard.json Linux内核编译的配置文件 │   └── patch Linux内核修改补丁文件 ├── drivers │   ├── build.sh Linux内核驱动编译脚本,WiFi模块驱动将会自动下载并编译 │   ├── igkboard.json Linux内核驱动编译的配置文件 │   └── users 用户编写的驱动文件将会放到这里 ├── images │   ├── boot 镜像里的boot分区配置文件 │   ├── build.sh 烧录的系统镜像制作脚本 │   └── igkboard.json 系统镜像制作脚本的配置文件 ├── rootfs │   ├── build.sh 根文件系统树制作脚本 │   ├── rootfs.json 制作根文件系统的配置文件 │   └── files 额外需要添加到根文件系统里的文件 ├── scripts │   └── setup_env.sh 编译系统的一些工具脚本 └── uapi └── test 驱动测试程序 ``` 下面是总的编译脚本的使用帮助信息: ``` guowenxue@5355ee897054:~/imx6ull/bsp$ ./build.sh Usage: ./build.sh [-b] [-c] [-h] bsp/image -b bsp/image: build BSP or system image -c bsp/image: clean BSP or system image -h : show this help message WARNNING: build/clean image need run as sudo Build Example: ./build.sh -b bsp && sudo ./build.sh -b image Clean Example: ./build.sh -c bsp && sudo ./build.sh -c image ``` ## 2.2 自构建系统编译 在总的编译脚本里,变量 ***SYSTEM*** 和 ***DISTRO*** 用来指定要编译的Linux系统类型。 ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/bsp/ guowenxue@5355ee897054:~/imx6ull/bsp$ vim build.sh ... ... # SYSTEM should be: buildroot, debian, yocto # DISTRO should be: v2021.02, bullseye, hardknott/honister/kirkstone SYSTEM=yocto DISTRO=kirkstone ... ... ``` * 如想使用 **yocto** 文件系统,则 ***SYSTEM*** 设置为 **yocto** ,***DISTRO*** 设置为其相应版本,如 **kirkstone**; * 如想使用 **debian** 文件系统,则 ***SYSTEM*** 设置为 **debian** ,***DISTRO*** 设置为 **bullseye(Debian11)** ; * 如想使用 **buildroot** 文件系统,则 ***SYSTEM*** 设置为 **buildroot** ,***DISTRO*** 设置为 **v2021.02** ; 接下来可以使用下面命令,一键下载、编译并制作系统烧录镜像文件。 ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/bsp/ guowenxue@5355ee897054:~/imx6ull/bsp$ ./build.sh -b bsp && sudo ./build.sh -b image --I-- start fetch /home/guowenxue/imx6ull/bsp/bootloader source code. --I-- wget http://weike-iot.com:2211/imx/bsp/lf-5.15.32-2.0.0/uboot-imx.tar.xz --I-- decompress /home/guowenxue/imx6ull/bsp/bootloader/../tarballs//uboot-imx.tar.xz --W-- Patch for uboot-imx source code --W-- Copy logo file: logo_uboot_364x128.bmp --W-- Modify cross compiler in Makefile: arm-linux-gnueabihf- --W-- Build for uboot-imx source code ... ... --W-- Install bootloader u-boot-igkboard.imx --I-- install u-boot-igkboard.imx => /home/guowenxue/imx6ull/bsp/bootloader/../images/ --I-- start fetch /home/guowenxue/imx6ull/bsp/kernel source code. --I-- wget http://weike-iot.com:2211/imx/bsp/lf-5.15.32-2.0.0/linux-imx.tar.xz --I-- decompress /home/guowenxue/imx6ull/bsp/kernel/../tarballs//linux-imx.tar.xz --W-- Patch for linux-imx source code --W-- Modify cross compiler in Makefile: arm-linux-gnueabihf- --W-- Build for linux-imx source code ... ... --I-- start fetch /home/guowenxue/imx6ull/bsp/drivers source code. --I-- wget http://weike-iot.com:2211/imx/igkboard/wifi/rtl8188fu.tar.bz2 --I-- decompress /home/guowenxue/imx6ull/bsp/drivers/../tarballs//rtl8188fu.tar.bz2 --W-- Build for users driver ... ... --W-- start fetch rootfs tree for yocto(kirkstone) --I-- start fetch rootfs_kirkstone source code. --I-- wget http://weike-iot.com:2211/imx/igkboard/rootfs/rootfs_kirkstone.tar.bz2 --I-- start fetch rootfs_kirkstone source code. --W-- start configure for yocto(kirkstone) rootfs --W-- configure for yocto(kirkstone) rootfs done ... ... --W-- Generate system image --W-- Partition system image --W-- format system image partition --W-- install u-boot image --W-- install linux kernel image --W-- install root filesystem /home/guowenxue/imx6ull/bsp/images/../rootfs/rootfs_kirkstone --W-- generate system image done Shell script exit now, do some clean work ``` 编译生成的文件将放到 ***images*** 文件夹下。 ``` guowenxue@5355ee897054:~/imx6ull/bsp$ ls images/ boot build.sh drivers igkboard.json linuxsys-yocto-igkboard.img u-boot-igkboard.imx ``` * **linuxsys-yocto-igkboard.img** 烧录到开发板上的系统镜像文件 * **u-boot-igkboard.imx** 编译生成的U-boot二进制镜像文件 接下来我们可以将 ***linuxsys-yocto-igkboard.img*** 和 ***u-boot-igkboard.imx*** 两个镜像文件,下载到 Windows系统下,参考烧录文档即可升级该系统镜像文件。 # 3. Yocto系统编译 凌云实验室针对 IGKBoard 开发板移植了Yocto ***Hardknott*** (Yocto 3.3)、***Honister***(Yocto 3.4) 和 ***Kirkstone***(Yocto 4.0)系统,该源码也托管在上面的 git 服务器上,接下来将讲解如何编译该系统。关于Yocto系统的详细使用,大家可以参考NXP官方的用户手册文档,[点此链接下载](https://www.nxp.com/docs/en/user-guide/IMX_YOCTO_PROJECT_USERS_GUIDE.pdf) 。 如果想源码编译Yocto系统的话,则系统需要满足: - 推荐使用 Ubuntu 20.04 系统(Hardknott不能在Ubuntu-22.04上编译); - 推荐使用 4核以上CPU,硬盘空间至少要求 200GB+; - Yocto系统编译需要从 github 等站点下载大量的源代码,而github有时在国内不能正常访问; ## 3.1 Yocto编译系统介绍 该项目源码路径 ***yocto*** 文件夹下存放有移植到 IGKBoard 开发板上的 Yocto 相关文件及其编译脚本。其目录结构如下: ``` guowenxue@5355ee897054:~$ cd ~/imx6ull/yocto/ guowenxue@5355ee897054:~/imx6ull/yocto$ tree -L 2 . ├── build.sh 一键编译Yocto脚本 └── meta-igkboard ├── hardknott 移植到IGKBoard的 Hardknott版本相关meta文件 ├── honister 移植到IGKBoard的 Honister 版本相关meta文件 └── kirkstone 移植到IGKBoard的 Kirkstone版本相关meta文件 ``` ## 3.2 Yocto系统编译 如果想编译相应的 Yocto 指定版本,只需要修改 ***build.sh*** 文件中的 ***VERSION*** 变量即可。 ``` guowenxue@5355ee897054:~/imx6ull/yocto$ vim build.sh ... ... # Version should be: hardknott(3.3) honister(3.4) kirkstone(4.0) VERSION=kirkstone ... ... ``` 接下来直接运行 ***build.sh*** 将会开始 Yocto的漫长编译过程。 ``` guowenxue@5355ee897054:~/imx6ull/yocto$ ./build.sh --I-- start fetch Yocto kirkstone --I-- decompress tarballs/imx-yocto-bsp-kirkstone.tar.xz --I-- start patch Yocto kirkstone --W-- Build Yocto kirkstone for linuxsys-image. --I-- Yocto kirkstone source meta. Build directory is igkboard /home/guowenxue/imx6ull/yocto/workspace-kirkstone Welcome LingYun IoT Gateway Kit Board Yocto BSP, You can run 'bitbake ' now. The targets should be: linuxsys-image core-image-minimal imx-image-full Loading cache: 100% | | ETA: --:--:-- Loaded 0 entries from dependency cache. Parsing recipes: 100% |#####################################################################################################################################################################| Time: 0:00:17 Parsing of 2930 .bb files complete (0 cached, 2930 parsed). 4440 targets, 525 skipped, 3 masked, 0 errors. NOTE: Resolving any missing task queue dependencies Build Configuration: BB_VERSION = "2.0.0" BUILD_SYS = "x86_64-linux" NATIVELSBSTRING = "ubuntu-22.04" TARGET_SYS = "arm-poky-linux-gnueabi" MACHINE = "igkboard" DISTRO = "fsl-imx-wayland" DISTRO_VERSION = "5.15-kirkstone" TUNE_FEATURES = "arm vfp cortexa7 neon thumb callconvention-hard" TARGET_FPU = "hard" meta meta-poky meta-oe meta-multimedia meta-python meta-freescale meta-freescale-3rdparty meta-freescale-distro meta-bsp meta-sdk meta-nxp-demo-experience meta-clang meta-networking meta-filesystems meta-qt6 meta-igkboard = "master:4f2e12e2a47981910cdfb85c480a31f3781f97b1" Initialising tasks: 100% |##################################################################################################################################################################| Time: 0:00:07 Sstate summary: Wanted 0 Local 0 Mirrors 0 Missed 0 Current 2437 (0% match, 100% complete) NOTE: Executing Tasks NOTE: Tasks Summary: Attempted 5897 tasks of which 5897 didn't need to be rerun and all succeeded. Summary: There was 1 WARNING message. --W-- List yocto build output images. ... ... ``` 编译生成的系统镜像文件将会存放在 `workspace-kirkstone/igkboard/tmp/deploy/images/igkboard/` 路径下。 ``` guowenxue@ubuntu22:~/imx6ull/yocto$ ls workspace-kirkstone/igkboard/tmp/deploy/images/igkboard/ linuxsys-image-igkboard-20221006114233.rootfs.manifest linuxsys-image-igkboard-20221006114233.rootfs.tar.bz2 linuxsys-image-igkboard-20221006114233.rootfs.wic.bz2 u-boot-igkboard.imx ``` * **linuxsys-image-igkboard-20221006114233.rootfs.manifest** 系统镜像里的各个软件包及其版本信息。 * **linuxsys-image-igkboard.tar.bz2** Yocto根文件系统树压缩包,它是一个符号链接,独立编译时需要。 * **linuxsys-image-igkboard.wic.bz2** 烧录到开发板上的系统镜像压缩包,它是一个符号链接。 * **u-boot-igkboard.imx** 编译生成的U-boot镜像文件,它是一个符号链接。 接下来我们可以将 ***linuxsys-image-igkboard.wic.bz2*** 和 ***u-boot-igkboard.imx*** 两个镜像文件,下载到 Windows系统下并解压缩,参考烧录文档即可升级该系统镜像文件。