- 文章假定读者一定程度了解 linux 基础知识
- 补充资料《嵌入式linux完全开发手册》- IMX6ull 开发板从零移植篇
本文描述从各个网站(官网)下载最新 ubuntu、交叉编译器、uboot、kernel、buildroot 从零开始构建,更接近实际工程环境
(可同时交叉参阅两份文章)
一、关于 ubuntu
- 下载安装最新桌面 LTS 版本 ubuntu
- 正常步骤安装(参考网络其它文章)
几个关键的设置
- 磁盘大小:60GB 以上
- 网络连接:使用桥接网络(复制网络连接状态)[路由器连接开发板和电脑]
二、关于交叉工具链
1、下载
ARM开发者中心下载交叉编译工具链
host 为 linux 👉 `x86_64 linux`
imx6ul 为 arm_A7 架构 👉 `AArch32`
imx6ul 支持硬件浮点 👉 `hard fllat`
需支持 linux 操作系统 👉 `none-linux`
2、配置
解压缩
tiansong@tiansong:~/100ask_imx6ull_pro$ ls
arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
tiansong@tiansong:~/100ask_imx6ull_pro$ tar -xvf arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
tiansong@tiansong:~/100ask_imx6ull_pro$ ls
arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
设置环境变量
tiansong@tiansong:~$ vim ~/.bashrc
# 在文件末尾追加
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabihf-
export PATH=$PATH:/home/tiansong/100ask_imx6ull_pro/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin
# 使环境变量在当前终端生效
tiansong@tiansong:~/100ask_imx6ull_pro$ source ~/.bashrc
验证是否配置成功
tiansong@tiansong:~/100ask_imx6ull_pro$ arm-none-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/tiansong/100ask_imx6ull_pro/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/../libexec/gcc/arm-none-linux-gnueabihf/11.3.1/lto-wrapper
Target: arm-none-linux-gnueabihf
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-11/src/gcc/configure --target=arm-none-linux-gnueabihf --prefix= --with-sysroot=/arm-none-linux-gnueabihf/libc --with-build-sysroot=/data/jenkins/workspace/GNU-toolchain/arm-11/build-arm-none-linux-gnueabihf/install//arm-none-linux-gnueabihf/libc --with-bugurl=https://bugs.linaro.org/ --enable-gnu-indirect-function --enable-shared --disable-libssp --disable-libmudflap --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-11/build-arm-none-linux-gnueabihf/host-tools --with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-11/build-arm-none-linux-gnueabihf/host-tools --with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-11/build-arm-none-linux-gnueabihf/host-tools --with-isl=/data/jenkins/workspace/GNU-toolchain/arm-11/build-arm-none-linux-gnueabihf/host-tools --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-mode=thumb --with-arch=armv7-a --with-pkgversion='Arm GNU Toolchain 11.3.Rel1'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.1 20220712 (Arm GNU Toolchain 11.3.Rel1)
三、关于 uboot
1、下载
# 下载
tiansong@tiansong:~/100ask_imx6ull_pro$ tiansong@tiansong:~/100ask_imx6ull_pro$ git clone https://source.codeaurora.cn/external/imx/uboot-imx
tiansong@tiansong:~/100ask_imx6ull_pro$ ls
arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf uboot-imx
# 查看仓库所有分支
tiansong@tiansong:~/100ask_imx6ull_pro$ cd uboot-imx/
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git branch -a
...
remotes/origin/imx_v2020.04_5.4.70_2.3.0
...
# 切换到 imx 最新分支
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git checkout remotes/origin/imx_v2020.04_5.4.70_2.3.0
Updating files: 100% (11834/11834), done.
Note: switching to 'remotes/origin/imx_v2020.04_5.4.70_2.3.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 62a81128c0 MLK-25878: imx8: scu: Increase sendmsg timeout for SCFW MU
# 确认是否却换成功
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git log -1
commit 62a81128c07c3efc123039f796ffc43b4eacbf04 (HEAD, origin/imx_v2020.04_5.4.70_2.3.0)
Author: Nitin Garg <nitin.garg@nxp.com>
Date: Fri Apr 29 10:54:20 2022 -0500
MLK-25878: imx8: scu: Increase sendmsg timeout for SCFW MU
Similar to receivemsg, sendmsg function should also
use 1 sec timeout for MU communication with SCFW.
Signed-off-by: Nitin Garg <nitin.garg@nxp.com>
Reviewed-by: Ye Li <ye.li@nxp.com>
2、开发板文件适配
前置说明:有多处关联,移植尽量一口气完成
默认的配置文件
复制公板提供的默认配置文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ cd configs/
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/configs$ ls *mx6ull_14x14_evk* -l
-rw-rw-r-- 1 tiansong tiansong 1988 8月 26 10:36 mx6ull_14x14_evk_defconfig # imx6ullevk公板默认的配置文件,默认只支持 SD 卡启动
-rw-rw-r-- 1 tiansong tiansong 1963 8月 26 10:36 mx6ull_14x14_evk_emmc_defconfig # imx6ull 支持 emmc 启动方式启动的配置文件
-rw-rw-r-- 1 tiansong tiansong 2095 8月 26 10:36 mx6ull_14x14_evk_nand_defconfig # imx6ull 支持 nand 启动方式启动的配置文件
-rw-rw-r-- 1 tiansong tiansong 2007 8月 26 10:36 mx6ull_14x14_evk_optee_defconfig # imx6ull 支持 optee 系统的配置文件
-rw-rw-r-- 1 tiansong tiansong 1958 8月 26 10:36 mx6ull_14x14_evk_plugin_defconfig # imx6ull 支持扩展功能的配置文件,主要是烧写功能
-rw-rw-r-- 1 tiansong tiansong 2057 8月 26 10:36 mx6ull_14x14_evk_qspi1_defconfig # imx6ull 支持扩展功能的配置文件,主要是烧写功能
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/configs$ cp mx6ull_14x14_evk_emmc_defconfig 100ask_imx6ull_pro_emmc_defconfig
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/configs$ ls 100ask_imx6ull_pro_emmc_defconfig -l
-rw-rw-r-- 1 tiansong tiansong 1982 8月 26 10:54 100ask_imx6ull_pro_emmc_defconfig
修改复制的配置文件 (三处)
CONFIG_TARGET_MX6ULL_14X14_EVK=y
👉
CONFIG_TARGET_100ASK_IMX6ULL_PRO_EMMC=y
CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6ullevk/imximage.cfg"
👉
CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/100ask/100ask_imx6ull_pro_emmc/imximage.cfg"
CONFIG_DEFAULT_DEVICE_TREE="imx6ull-14x14-evk-emmc"
👉
CONFIG_DEFAULT_DEVICE_TREE="100ask_imx6ull_pro_emmc"
板件级支持
头文件
复制公板提供的.h
文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ cd include/configs/
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ cd include/configs/
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/include/configs$ cp mx6ullevk.h 100ask_imx6ull_pro_emmc.h
修改复制的.h
文件 (两处)
#ifndef __MX6ULLEVK_CONFIG_H
#define __MX6ULLEVK_CONFIG_H
👉
#ifndef __100ASK_IMX6ULL_PRO_EMMC_CONFIG_H
#define __100ASK_IMX6ULL_PRO_EMMC_CONFIG_H
文件夹
复制公板提供的文件夹
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ cd board/
# 创建二级目录,100ask族和100ask_imx6ull_pro_emmc族
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board$ mkdir 100ask
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board$ mkdir 100ask/100ask_imx6ull_pro_emmc
# 复制 common 文件夹
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board$ cp freescale/common 100ask/
# 复制 freescale/mx6ullevk/* 下所有公板文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board$ cp freescale/mx6ullevk/* 100ask/100ask_imx6ull_pro_emmc/
# 查看文件数,确认是否操作成功
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board$ cd 100ask/
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board/100ask$ tree
.
├── 100ask_imx6ull_pro_emmc # 注重修改 !!
│ ├── 100ask_imx6ull_pro_emmc.c
│ ├── built-in.o
│ ├── imximage.cfg
│ ├── imximage_lpddr2.cfg
│ ├── Kconfig
│ ├── MAINTAINERS
│ ├── Makefile
│ ├── plugin.S
│ └── README
└── common
├── arm_sleep.c
├── built-in.o
├── cadmus.c
├── cadmus.h
├── cds_pci_ft.c
├── cds_via.c
...
...
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board/100ask$ cd 100ask_imx6ull_pro_emmc/
重命名 mx6ullevk.c
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/board/freescale/mx6ullevk$ mv mx6ullevk.c 100ask_imx6ull_pro_emmc.c
修改 100ask_imx6ull_pro_emmc.c
int checkboard(void)
{
else
puts("Board: MX6ULL 14x14 EVK\n");
👉
puts("Board: 100ASK_IMX6ULL_PRO_EMMC\n");
return 0;
}
修改 Makefile
obj-y := 100ask_imx6ull_pro_emmc.o
修改 Kconfig
if TARGET_100ASK_IMX6ULL_PRO_EMMC # 注意与 100ask_imx6ull_pro_emmc_defconfig 中 CONFIG_TARGET_100ASK_IMX6ULL_PRO_EMMC=y 对应
config SYS_BOARD
default "100ask_imx6ull_pro_emmc" # 100ask_imx6ull_pro_emmc 注意与后续多处对应
config SYS_VENDOR
default "100ask"
config SYS_CONFIG_NAME
default "100ask_imx6ull_pro_emmc"
config SYS_TEXT_BASE
default 0x87800000
endif
修改 MAINTAINERS
【注意路径填写正确】
MX6ULLEVK BOARD
M: Peng Fan <peng.fan@nxp.com>
S: Maintained
F: board/100ask/100ask_imx6ull_pro_emmc/
F: include/configs/100ask_imx6ull_pro.h
F: configs/100ask_imx6ull_pro_emmc_defconfig
修改 imximage.cfg
PLUGIN board/freescale/mx6ullevk/plugin.bin 0x00907000
👉
PLUGIN board/100ask/100ask_imx6ull_pro_emmc/plugin.bin 0x00907000
修改 imximage_lpddr2.cfg
PLUGIN board/freescale/mx6ullevk/plugin.bin 0x00907000
👉
PLUGIN board/100ask/100ask_imx6ull_pro_emmc/plugin.bin 0x00907000
增加图像化支持
修改 /home/tiansong/100ask_imx6ull_pro/uboot-imx/arch/arm/mach-imx/mx6/Kconfig
【注意路径】
config TARGET_MX6ULL_14X14_EVK
bool "Support mx6ull_14x14_evk"
select BOARD_LATE_INIT
select DM
select DM_THERMAL
select MX6ULL
imply CMD_DM
# 在 TARGET_MX6ULL_14X14_EVK 之下添加,注意与 100ask_imx6ull_pro_emmc_defconfig 中 CONFIG_TARGET_100ASK_IMX6ULL_PRO_EMMC=y 对应
config TARGET_100ASK_IMX6ULL_PRO_EMMC
bool "Support 100ask_imx6ull_pro_emmc"
select BOARD_LATE_INIT
select DM
select DM_THERMAL
select MX6ULL
imply CMD_DM
# 文件末尾添加,注意路径
source "board/100ask/100ask_imx6ull_pro_emmc/Kconfig"
默认的设备树
复制公版对应设备树文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/arch/arm/dts$ pwd
/home/tiansong/100ask_imx6ull_pro/uboot-imx/arch/arm/dts
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/arch/arm/dts$ cp imx6ull-14x14-evk-emmc.dts 100ask_imx6ull_pro_emmc.dts
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/arch/arm/dts$ cp imx6ull-14x14-evk.dts 100ask_imx6ull_pro.dts
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/arch/arm/dts$ cp imx6ull-14x14-evk.dtsi 100ask_imx6ull_pro.dtsi
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx/arch/arm/dts$ cp imx6ull-u-boot.dtsi 100ask_imx6ull_pro_u_boot.dtsi
修改 100ask_imx6ull_pro_emmc.dts
#include "imx6ull-14x14-evk.dts"
👉
#include "100ask_imx6ull_pro.dts"
修改 100ask_imx6ull_pro.dts
#include "imx6ull.dtsi"
#include "imx6ul-14x14-evk.dtsi"
#include "imx6ul-14x14-evk-u-boot.dtsi"
model = "i.MX6 ULL 14x14 EVK Board";
👉
#include "imx6ull.dtsi"
#include "100ask_imx6ull_pro.dtsi"
#include "100ask_imx6ull_pro_u_boot.dtsi"
model = "100ASK IMX6ULL PRO Board";
修改 100ask_imx6ull_pro.dtsi
# 1.新增 backlight_display 节点,注意在 / { 下
/ {
...
backlight_display: backlight-display { // 新增节点
compatible = "pwm-backlight";
pwms = <&pwm1 0 1000>;
brightness-levels = <0 4 8 16 32 64 128 255>;
default-brightness-level = <6>;
status = "okay";
};
...
}
# 2.修改网口节点
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet1>;
phy-mode = "rmii";
phy-handle = <ðphy0>;
status = "disabled"; // 修改
};
&fec2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet2>;
phy-mode = "rmii";
phy-handle = <ðphy1>;
phy-reset-gpios = <&gpio5 6 GPIO_ACTIVE_LOW>; // 新增
phy-reset-duration = <50>; // 新增
status = "okay";
mdio {
#address-cells = <1>;
#size-cells = <0>;
ethphy0: ethernet-phy@2 {
reg = <0>;
smsc,led-mode = <1>;
clocks = <&clks IMX6UL_CLK_ENET_REF>;
clock-names = "rmii-ref";
};
ethphy1: ethernet-phy@1 {
reg = <1>;
smsc,led-mode = <1>;
clocks = <&clks IMX6UL_CLK_ENET2_REF>;
clock-names = "rmii-ref";
};
};
};
pinctrl_enet2: enet2grp {
fsl,pins = <
MX6UL_PAD_GPIO1_IO07__ENET2_MDC 0x1b0b0
MX6UL_PAD_GPIO1_IO06__ENET2_MDIO 0x1b0b0
MX6UL_PAD_ENET2_RX_EN__ENET2_RX_EN 0x1b0b0
MX6UL_PAD_ENET2_RX_ER__ENET2_RX_ER 0x1b0b0
MX6UL_PAD_ENET2_RX_DATA0__ENET2_RDATA00 0x1b0b0
MX6UL_PAD_ENET2_RX_DATA1__ENET2_RDATA01 0x1b0b0
MX6UL_PAD_ENET2_TX_EN__ENET2_TX_EN 0x1b0b0
MX6UL_PAD_ENET2_TX_DATA0__ENET2_TDATA00 0x1b0b0
MX6UL_PAD_ENET2_TX_DATA1__ENET2_TDATA01 0x1b0b0
MX6UL_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 0x4001b031
/* used for phy reset*/
MX6ULL_PAD_SNVS_TAMPER6__GPIO5_IO06 0x79 // 增加复位引脚
>;
};
# 3.修改 lcd 节点
&lcdif {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lcdif_dat
&pinctrl_lcdif_ctrl>;
reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
display = <&display0>;
status = "okay";
display0: display@0 {
bits-per-pixel = <24>;
bus-width = <24>;
display-timings {
native-mode = <&timing0>;
timing0: timing0 {
clock-frequency = <50000000>;
hactive = <1024>;
vactive = <600>;
hfront-porch = <160>;
hback-porch = <140>;
hsync-len = <20>;
vback-porch = <20>;
vfront-porch = <12>;
vsync-len = <3>;
hsync-active = <0>;
vsync-active = <0>;
de-active = <1>;
pixelclk-active = <0>;
};
};
};
};
pinctrl_lcdif_ctrl: lcdifctrlgrp {
fsl,pins = <
MX6UL_PAD_LCD_CLK__LCDIF_CLK 0x79
MX6UL_PAD_LCD_ENABLE__LCDIF_ENABLE 0x79
MX6UL_PAD_LCD_HSYNC__LCDIF_HSYNC 0x79
MX6UL_PAD_LCD_VSYNC__LCDIF_VSYNC 0x79
/* used for lcd reset */
MX6UL_PAD_LCD_RESET__GPIO3_IO04 0x1b0b0 // 增加复位引脚
>;
};
修改 /home/tiansong/100ask_imx6ull_pro/uboot-imx/arch/arm/dts/Makefile
dtb-$(CONFIG_MX6ULL) += \
...
imx6ull-14x14-evk.dtb \
100ask_imx6ull_pro.dtb \ # 新增
imx6ull-14x14-evk-emmc.dtb \
100ask_imx6ull_pro_emmc.dtb \ # 新增
...
修改 /home/tiansong/100ask_imx6ull_pro/uboot-imx/drivers/net/phy/phy.c
int genphy_config_aneg(struct phy_device *phydev)
{
int result;
phy_reset(phydev); // 新增
if (phydev->autoneg != AUTONEG_ENABLE)
return genphy_setup_forced(phydev);
result = genphy_config_advert(phydev);
// ...
}
3、配置及编译
安装环境依赖
sudo apt install make
sudo apt install bison flex
生成 .config
文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ pwd
/home/tiansong/100ask_imx6ull_pro/uboot-imx
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ make distclean
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ make 100ask_imx6ull_pro_emmc_defconfig
图形化配置
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ make menuconfig
确认板级支持, 目录项 ARM architecture
确认默认的设备树,目录项Boot media
-->Device Tree Control
使能SD/EMMC
启动,目录项Boot media
使能随机MAC
地址生成,目录项Networking support
网卡支持
- 目录项
Device Drivers/Network device support
- 目录项
Device Drivers/Ethernet PHY(physical media interface) support
编译
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ make -j12
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ ls u-boot-dtb.imx
u-boot-dtb.imx
4、烧写测试
使用 100ASK IMX6ULL Flashing Tool
烧写 (烧写方式可参考 《嵌入式Linux完全开发手册》 )
查看开发板调试串口输出
- 启动日志
version
查看
dhcp
网卡测试
mmcinfo
测试
- lcd 观察
5、文件及代码管理
默认配置文件更新
# 根据当前配置生成默认配置文件
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ make savedefconfig
scripts/kconfig/conf --savedefconfig=defconfig Kconfig
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ ls defconfig -l
-rw-rw-r-- 1 tiansong tiansong 1748 8月 26 21:34 defconfig
# 覆盖更新 100ask_imx6ull_pro_emmc_defconfig
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ cp defconfig ./configs/100ask_imx6ull_pro_emmc_defconfig
本地 git 仓库提交
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git status
HEAD detached at origin/imx_v2020.04_5.4.70_2.3.0
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: arch/arm/dts/Makefile
modified: arch/arm/mach-imx/mx6/Kconfig
modified: drivers/net/phy/phy.c
Untracked files:
(use "git add <file>..." to include in what will be committed)
arch/arm/dts/100ask_imx6ull_pro_emmc.dts
board/100ask/
configs/100ask_imx6ull_pro_emmc_defconfig
include/configs/100ask_imx6ull_pro_emmc.h
no changes added to commit (use "git add" and/or "git commit -a")
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git add -A
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git commit -m "适配 100ask_imx6ull_pro 开发板"
tiansong@tiansong:~/100ask_imx6ull_pro/uboot-imx$ git log -1
commit 9f96361312aeeba348bf8b563a22479d6d2f6c23 (HEAD)
Author: TianSong <1508539502@qq.com>
Date: Fri Aug 26 21:38:36 2022 +0800
适配 100ask_imx6ull_pro 开发板
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。