Linux基于IMX6ULL移植Buildroot

Posted ZHONGCAI0901

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux基于IMX6ULL移植Buildroot相关的知识,希望对你有一定的参考价值。

文章目录

1. Buildroot 简介

Buildroot是Linux平台上一个构建嵌入式Linux系统的框架。整个Buildroot是由Makefile脚本和Kconfig配置文件构成的。

你可以和编译Linux内核一样,通过buildroot配置,menuconfig修改,编译出一个完整的可以直接烧写到机器上运行的Linux系统软件(包含uboot、kernel、rootfs以及rootfs中的各种库和应用程序)。

官网使用手册:
https://buildroot.org/downloads/manual/manual.html

2. 获取 buildroot 源码

buildroot 官方下载地址:https://buildroot.org/download.html,可以直接点击红框的压缩包进行下载,如下:

也可以通过git clone最新的buildroot 源码,如下:

git clone git://git.buildroot.net/buildroot

3. 编译环境配置

在官网的第二章 System requirements , 它描述了对编译环境的要求。必须要安装的工具如下:

必须要安装的工具命令如下:

sudo apt install -y sed make binutils build-essential gcc g++ patch gzip bzip2 perl tar cpio unzip rsync file bc wget

安装完成结果如下:

官方提供一些可选的工具包:

可选安装的工具命令如下:

sudo apt install -y wget python libncurses5 bzr cvs git mercurial rsync subversion

安装完成结果如下:

4. 通过buildroot编译imx6ull

查看buildroot的配置文件,刚好它支持imx6ull公版开发板。如下:

首先拷贝 configs 目录下的 imx6ullevk_defconfig 配置文件到 imx6ullevk_zc_defconfig,之后我们直接在此配置文件上进行修改适配操作。

cp configs/imx6ullevk_defconfig  configs/imx6ullevk_zc_defconfig

拷贝成功后,使用 vim 或 cat 命令查看 imx6ullevk_zc_defconfig 配置文件内都做了那些操作,查看发现只有短短的几行配置,但是可以看出里面包含了 CPU 架构的配置 kernel uboot 以及 sd镜像和 ext4 镜像的支持,在里面并未看到文件系统的支持和增加了那些包,我们只能先认为这个配置文件使用了系统默认的配置。

# architecture
BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_NEON_VFPV4=y

# Linux headers same as kernel, a 5.7 series
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7=y

# system
BR2_TARGET_GENERIC_GETTY_PORT="ttymxc0"

# kernel
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.7.8"
BR2_LINUX_KERNEL_DEFCONFIG="imx_v6_v7"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="imx6ull-14x14-evk"
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y

# bootloader
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BOARDNAME="mx6ull_14x14_evk"
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2020.07"
BR2_TARGET_UBOOT_FORMAT_DTB_IMX=y
BR2_TARGET_UBOOT_NEEDS_DTC=y

# required tools to create the SD card image
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y

# filesystem / image
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/freescale/common/imx/post-image.sh"
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y

首先我们可以在 buildroot 根目录下执行 make help 命令来查看 buildroot 都支持那些编译命令,常用命令如下:

make clean // 表示删除编译生成的 build 缓存文件。
make all // 表示开始编译所有。
make menuconfig // 表示进入配置文件配置页面,用来选择增加或者删除某些包至目标(开发板)。
make <pkg> // 表示包名 - 后面为编译选项,可以使用 ls package/ 来查看都支持了那些软件包。
make busybox-menuconfig // 表示进入 busybox 配置菜单页面,用来增加/删除某些 busybox 配置。
make V=0|1 // 用来输出编译输出信息等级,一般使用 make <命令> V=1 来查看详细的编译步骤。

通过make help查看支持的指令:

编译buildroot命令:

make imx6ullevk_zc_defconfig
make all

执行结果如下:

编译成功后,会将uboot、kernel和rootfs一起打包成sdcard.img,然后将编译生成的 sdcard.img 文件使用 wind32diskimage 烧写至 sd 卡内,并设置开发板为 SD 卡启动,使用最新的固件:

5. 修改默认配置适配imx6ull bootloader

在配置buildroot的bootloader时,需要输入一下的命令:

make imx6ullevk_zc_defconfig  // 选择配置文件
make menuconfig // 通过界面配置

执行make menuconfig后的结果如下:

从主菜单选择Bootloader之后,进入二级菜单如下,红色的框是我们需要配置uboot的配置、uboot git仓库地址、选择uboot仓库的版本id。

Bootloaders  --->

首先我们修改编译 uboot 所需的配置配置文件名称,官方这里使用的是 mx6ull_14x14_evk 的配置,我们需要修改为自己板子的配置文件。

Bootloaders  --->
	(mx6ull_14x14_evk_emmc_zc) U-Boot board name

在uboot的源码中查看我们使用的配置文件为mx6ull_14x14_evk_emmc_zc_defconfig,上面配置时不需要加defconfig,所以上面填写board name为mx6ull_14x14_evk_emmc_zc

为了方便后面的修改,源码保存已经上传到我们自定义的 gitee 仓库内,所以需要先修改 uboot的版本获取方式,移动到 U-Boot Version 来修改使用自定义 git 仓库。

Bootloaders  --->
	U-Boot Version (Custom Git repository)  ---> 

修改自定义的仓库地址和版本:

Bootloaders  --->
	()URL of custom repository
	() Custom repository version

在配置好需要获取的 uboot 源码和使用的配置文件后,我们只需要指定一下编译生成的镜像文件格式,根据之前的编译烧写可知,imx6ull板子uboot 只需要一个 u-boot-dtb.imx 格式的文件即可,这里也只需要选中编译生成 u-boot-dtb.imx 即可,其它的无需选择。

Bootloaders  --->
	 U-Boot binary format  ---> 

最后保存后退出,配置bootloader完成。

单独编译uboot:make uboot-rebuild

make uboot-rebuild

6. 修改默认配置适配imx6ull kernel

首先确认配置文件没有被清理或者删除,接下来我们使用上面配置过 uboot 的配置文件继续配置 linux kernel 为支持 imx6ull,我们需要修改如下红框所示的配置。

Kernel  ---> 

首先还是先配置内核源码版本获取方式,这里我们参考下图所示选择使用自定义的 git 仓库地址。

Kernel  ---> 
	Kernel version (Custom Git repository)  --->

在配置完成使用自定义 git 仓库后,会自动新增两个输入框,首先输入我们内核源码所在的 gitee 地址和版本。

Kernel  ---> 
	() URL of custom repository (NEW)
	() Custom repository version (NEW)

输入完成获取源码所需的仓库地址和 commit id 后,需要修改配置所需的配置文件名称,修改为 imx_v7 (buildroot 编译时会自动加_defconfig 后缀)。

Kernel  ---> 
	(imx_v7) Defconfig name 

我们运行内核需要 zImage 和 imx6ull-14x14-evk 设备树文件才可以,此时需要修改增加需要编译生成安装的设备文件 imx6ull-14x14-evk 才可以自动编译生成我们需要的文件(buildroot 编译设备树文件时会自动增加.dtb 后缀)。

Kernel  ---> 
	(imx6ull-14x14-evk) In-tree Device Tree Source file names

配置 kernel 后的所有配置项后,可以执行保存退出到 buildroot 源码主目录继续执行编译名。

单独编译kernel:make linux-rebuild

make linux-rebuild

8. 编译烧录验证

所有都配置好后,可以执行进行全部编译验证:

make all

编译成功后,会将uboot、kernel和rootfs一起打包成sdcard.img,然后将编译生成的 sdcard.img 文件使用 wind32diskimage 烧写至 sd 卡内,并设置开发板为 SD 卡启动,使用最新的固件:

开机log:

U-Boot 2020.04 (Jul 05 2021 - 12:25:58 +0800)

CPU:   i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 45C
Reset cause: POR
Model: i.MX6 ULL 14x14 EVK Board
Board: MX6ULL 14x14 EVK
DRAM:  512 MiB
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... *** Warning - bad CRC, using default environment

[*]-Video Link 0 (1024 x 600)
[0] lcdif@21c8000, video
In:    serial
Out:   serial
Err:   serial
switch to partitions #0, OK
mmc0 is current device
flash target is MMC:0
Net:   eth1: ethernet@20b4000 [PRIME]
Fastboot: Normal
Normal Boot
Hit any key to stop autoboot:  3  2  1  0 
switch to partitions #0, OK
mmc0 is current device
switch to partitions #0, OK
mmc0 is current device
8189384 bytes read in 369 ms (21.2 MiB/s)
Booting from mmc ...
35442 bytes read in 17 ms (2 MiB/s)
Kernel image @ 0x80800000 [ 0x000000 - 0x7cf5c8 ]
## Flattened Device Tree blob at 83000000
   Booting using the fdt blob at 0x83000000
   Using Device Tree in place at 83000000, end 8300ba71
Modify /soc/aips-bus@2200000/epdc@228c000:status disabled
ft_system_setup for mx6

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.4.70 (benjamin@ubuntu) (gcc version 9.3.0 (Buildroot -g658cfb3-dirty)) #1 SMP PREEMPT Sun Jul 4 18:28:07 CST 2021
[    0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: Freescale i.MX6 ULL 14x14 EVK Board
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] Reserved memory: created CMA memory pool at 0x96000000, size 160 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] percpu: Embedded 15 pages/cpu s32076 r8192 d21172 u61440
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 129920
[    0.000000] Kernel command line: console=ttymxc0,115200 root=/dev/mmcblk0p2 rootwait rw
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 335464K/524288K available (12288K kernel code, 578K rwdata, 4288K rodata, 1024K init, 435K bss, 24984K reserved, 163840K cma-reserved, 0K highmem)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu: RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=1.
[    0.000000] Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] random: get_random_bytes called from start_kernel+0x2c8/0x488 with crng_init=0
[    0.000000] Switching to timer-based delay loop, resolution 41ns
[    0.000016] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.000056] clocksource: mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.002974] Console: colour dummy device 80x30
[    0.003045] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)
[    0.003079] pid_max: default: 32768 minimum: 301
[    0.003464] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.003500] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.005218] CPU: Testing write buffer coherency: ok
[    0.005947] CPU0: update cpu_capacity 1024
[    0.005980] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[    0.007428] Setting up static identity map for 0x80100000 - 0x80100060
[    0.007775] rcu: Hierarchical SRCU implementation.
[    0.008512] smp: Bringing up secondary CPUs ...
[    0.008543] smp: Brought up 1 node, 1 CPU
[    0.008566] SMP: Total of 1 processors activated (48.00 BogoMIPS).
[    0.008583] CPU: All CPU(s) started in SVC mode.
[    0.009488] devtmpfs: initialized
[    0.020837] Duplicate name in lcdif@21c8000, renamed to "display#1"
[    0.025209] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
[    0.026188] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.026241] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[    0.039182] pinctrl core: initialized pinctrl subsystem
[    0.041845] NET: Registered protocol family 16
[    0.059803] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.062644] cpuidle: using governor menu
[    0.080345] vdd3p0: supplied by regulator-dummy
[    0.081834] cpu: supplied by regulator-dummy
[    0.083230] vddsoc: supplied by regulator-dummy
[    0.108031] failed to find ocotp node
[    0.108389] No ATAGs?
[    0.108526] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
[    0.108558] hw-breakpoint: maximum watchpoint size is 8 bytes.
[    0.113002] imx6ul-pinctrl 20e0000.iomuxc: initialized IMX pinctrl driver
[    0.113694] imx6ul-pinctrl 2290000.iomuxc-snvs: no groups defined in /soc/aips-bus@2200000/iomuxc-snvs@2290000
[    0.113731] imx6ul-pinctrl 2290000.iomuxc-snvs: initialized IMX pinctrl driver
[    0.116482] imx mu driver is registered.
[    0.117522] imx rpmsg driver is registered.
[    0.190565] vgaarb: loaded
[    0.192732] SCSI subsystem initialized
[    0.193916] usbcore: registered new interface driver usbfs
[    0.194053] usbcore: registered new interface driver hub
[    0.194269] usbcore: registered new device driver usb
[    0.197617] i2c i2c-0: IMX I2C adapter registered
[    0.199706] i2c i2c-1: IMX I2C adapter registered
[    0.200610] mc: Linux media interface: v0.10
[    0.200727] videodev: Linux video capture interface: v2.00
[    0.200863] pps_core: LinuxPPS API ver. 1 registered
[    0.200884] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.200940] PTP clock support registered
[    0.204233] MIPI CSI2 driver module loaded
[    0.204372] Advanced Linux Sound Architecture Driver Initialized.
[    0.206205] Bluetooth: Core ver 2.22
[    0.206345] NET: Registered protocol family 31
[    0.206368] Bluetooth: HCI device and connection manager initialized
[    0.206407] Bluetooth: HCI socket layer initialized
[    0.206432] Bluetooth: L2CAP socket layer initialized
[    0.206486] Bluetooth: SCO socket layer initialized
[    0.207693] clocksource: Switched to clocksource mxc_timer1
[    0.208105] VFS: Disk quotas dquot_6.6.0
[    0.208318] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.231268] thermal_sys: Registered thermal governor 'step_wise'
[    0.231911] NET: Registered protocol family 2
[    0.233268] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[    0.233359] TCP established hash table entries: 4096 (order: 2, 16384 bytes, linear)
[    0.233480] TCP bind hash table entries: 4096 (order: 3, 32768 bytes, linear)
[    0.233637] TCP: Hash tables configured (established 4096 bind 4096)
[    0.233851] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.233920] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.234325] NET: Registered protocol family 1
[    0.235636] RPC: Registered named UNIX socket transport module.
[    0.235670] RPC: Registered udp transport module.
[    0.235689] RPC: Registered tcp transport module.
[    0.235707] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.237031] PCI: CLS 0 bytes, default 64
[    0.238737] hw perfevents: enabled with armv7_cortex_a7 PMU driver, 5 counters available
[    0.242663] Bus freq driver module loaded
[    0.245150] Initialise system trusted keyrings
[    0.245733] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    0.263062] NFS: Registering the id_resolver key type
[    0.263141] Key type id_resolver registered
[    0.263160] Key type id_legacy registered
[    0.263261] jffs2: version 2.2. (NAND) ?2001-2006 Red Hat, Inc.
[    0.264444] fuse: init (API version 7.31)
[    0.358310] Key type asymmetric registered
[    0.358346] Asymmetric key parser 'x509' registered
[    0.358414] io scheduler mq-deadline registered
[    0.358432] io scheduler kyber registered
[    0.368929] pwm-backlight backlight: backlight supply power not found, using dummy regulator
[    0.377339] mxsfb 21c8000.lcdif: 21c8000.lcdif supply lcd not found, using dummy regulator
[    0.487454] sii902x bound to mxs-lcdif from 21c8000.lcdif
[    0.511797] Console: switching to colour frame buffer device 128x37
[    0.615025] mxsfb 21c8000.lcdif: initialized
[    0.624822] imx-sdma 20ec000.sdma: Direct firmware load for imx/sdma/sdma-imx6q.bin failed with err

以上是关于Linux基于IMX6ULL移植Buildroot的主要内容,如果未能解决你的问题,请参考以下文章

基于imx6ull打造流媒体视频监控:ffmpeg + nginx + rtmp

i.MX6ULL应用移植 | 移植lvgl到imx6ull(基于framebuffer)

i.MX6ULL应用移植 | 移植lvgl到imx6ull(基于framebuffer)

手把手之如何在嵌入式Linux上运行QT应用程序(以百问网imx6ull开发板为例)

关于buildroot移植的思考

Linux | 移植NXP官方linux内核到imx6ull开发板(4.1.15)