前言

  • iMX6Q 支持多种启动方式,如 emmc启动、SD 卡启动等,这里简单的记录一下 SD卡启动的流程

下载u-boot

  • 使用 NXP 官方提供的 uboot-imx,代码地址为: ​​https://github.com/nxp-imx/uboot-imx​
  • 使用 git 下载 uboot-imx, ​​git clone https://github.com/nxp-imx/uboot-imx​
  • 切换到想要的分支,我切换到:​​imx_v2020.04_5.4.70_2.3.0​​,也就是 ​​u-boot 2020.04​​ 版本, 支持 ​​Linux 5.4.70​​ 版本,算是当前比较新的版本了
  • ​git checkout -b imx_v2020.04_5.4.70_2.3.0 origin/imx_v2020.04_5.4.70_2.3.0​
  • gcc 交叉编译工具链推荐:​​gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf​​,这个可以在 ARM 官方网站下载,较老或较新的gcc 版本,可能编译会报错
  • arm gcc 交叉编译工具链 官方下载:​​https://developer.arm.com/downloads/-/gnu-a​
  • ​arm-none-linux-gnueabihf-gcc -v​
zhangsz@zhangsz-virtual-machine:~/linux/imx6q/uboot/uboot-imx_2020.04/board/freescale/mx6sabresd$ arm-none-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/zhangsz/linux/tools/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/../libexec/gcc/arm-none-linux-gnueabihf/9.2.1/lto-wrapper
Target: arm-none-linux-gnueabihf
Configured with: /tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/src/gcc/configure --target=arm-none-linux-gnueabihf --prefix= --with-sysroot=/arm-none-linux-gnueabihf/libc --with-build-sysroot=/tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/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=/tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/build-arm-none-linux-gnueabihf/host-tools --with-mpfr=/tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/build-arm-none-linux-gnueabihf/host-tools --with-mpc=/tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/build-arm-none-linux-gnueabihf/host-tools --with-isl=/tmp/dgboter/bbs/rhev-vm7--rhe6x86_64/buildbot/rhe6x86_64--arm-none-linux-gnueabihf/build/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='GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)'
Thread model: posix
gcc version 9.2.1 20191025 (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10))

编译 u-boot

  • 使用 uboot-imx 里面的 ​​mx6qsabresd_defconfig​​,CPU : IMX6Q, SD 卡启动
  • board 对应:​​uboot-imx_2020.04/board/freescale/mx6sabresd​
zhangsz@zhangsz-virtual-machine:~/linux/imx6q/uboot/uboot-imx_2020.04/board/freescale/mx6sabresd$ ls -la
total 116
drwxrwxr-x 2 zhangsz zhangsz 4096 12月 28 16:59 .
drwxrwxr-x 126 zhangsz zhangsz 4096 12月 28 09:49 ..
-rw-rw-r-- 1 zhangsz zhangsz 227 12月 28 09:42 Kconfig
-rw-rw-r-- 1 zhangsz zhangsz 167 12月 28 09:42 MAINTAINERS
-rw-rw-r-- 1 zhangsz zhangsz 172 12月 28 09:42 Makefile
-rw-rw-r-- 1 zhangsz zhangsz 3920 12月 28 09:42 mx6dlsabresd.cfg
-rw-rw-r-- 1 zhangsz zhangsz 4221 12月 28 09:43 mx6q_4x_mt41j128.cfg
-rw-rw-r-- 1 zhangsz zhangsz 4539 12月 28 09:42 mx6qp.cfg
-rw-rw-r-- 1 zhangsz zhangsz 4495 12月 28 09:42 mx6qp_optee.cfg
-rw-rw-r-- 1 zhangsz zhangsz 43993 12月 28 09:43 mx6sabresd.c
-rw-rw-r-- 1 zhangsz zhangsz 3418 12月 28 09:42 mx6solo_4x_mt41j128.cfg
-rw-rw-r-- 1 zhangsz zhangsz 12799 12月 28 09:42 plugin.S
-rw-rw-r-- 1 zhangsz zhangsz 2548 12月 28 09:42 README
  • 迅为imx6q 开发板,2G RAM,所以需要更改 ​​mx6sabresd​​ 中的 DDR 配置文件:​​mx6q_4x_mt41j128.cfg​​,这个文件可以从 迅为imx6q 开发板提供的 android 源码中的 u-boot 代码中提取,也可以使用 NXP 的工具配置生成
  • u-boot 编译方法

$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- mx6qsabresd_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- -j4

u-boot 产物

  • uboot-2020.04 分支,uboot 是基于【设备树】的,产物是 ​​u-boot-dtb.imx​​,这个可以用于烧写到 SD卡或者 emmc 中, imx 后缀,是对 u-boot.bin 做了处理,用于 imx6q 的 ROM 启动引导 u-boot,直接烧写 u-boot.bin 到 emmc 中,默认无法正常启动

u-boot 烧写

  • 编译环境是: VMWare 虚拟机中的 ubuntu 22.04
  • SD卡 烧写 ​​u-boot-dtb.imx​​,并不是直接把文件复制到 SD卡中,而是通过 Linux ​​dd​​ 烧写命令写入到SD 卡指定的位置,此时 SD 卡可以不分区
  • 把 SD 卡插入读卡器,然后连接到 ubuntu 中,通过 ​​sudo df -l​​ 命令查看,找到 SD卡设备,如 ​​/dev/sdd1​
  • ​/dev/sdd1​​​ 代表 SD 卡 设备 ​​/dev/sdd​​ 的分区一,如果没有分区,可以使用 ​​sudo fdisk -l​​ 查看SD 卡设备
  • 烧写命令: ​​sudo dd if=u-boot-dtb.imx of=/dev/sdd bs=512 seek=2 && sync​
zhangsz@zhangsz-virtual-machine:~/linux/imx6q/uboot/uboot-imx_2020.04$ sudo dd if=u-boot-dtb.imx of=/dev/sdd bs=512 seek=2 && sync
[sudo] password for zhangsz:
1166+0 records in
1166+0 records out
596992 bytes (597 kB, 583 KiB) copied, 0.0877795 s, 6.8 MB/s

if=u-boot-dtb.imx 表示输入,u-boot-dtb.imx 是当前路径下的 u-boot 编译的产物
of=/dev/sdd , /dev/sdd,而不是 /dev/sdd1,表示 SD 卡设备,这里直接烧写到 SD卡指定位置,不是分区
sync 表示 同步,刷到 SD卡中

适配修改

  • ​mx6sabresd​​ 需要简单的修改,才能适配到 【迅为iMX6Q】开发板

一、关闭 ​​[ ] Enable the LDO bypass checking and setting ​​ 选项

→ ARM architecture
[ ] Enable the LDO bypass checking and setting

【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动_sd卡启动

二、关闭 :​​[ ] Enable Driver Model for PMIC PFUZE100​

→ Device Drivers
→ Power
[ ] Enable Driver Model for PMIC PFUZE100

【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动_sd卡启动_02

【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动_linux_03

三、修改 SD 卡 cd GPIO 引脚

  • 这里需要修改设备树文件 ​​arch/arm/dts/imx6qdl-sabresd.dtsi​

【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动_u-boot_04

四、DDR RAM 改为 2G

  • 修改文件:​​board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg​
  • 如下为 2G DDR ​​mx6q_4x_mt41j128.cfg​​ 文件内容
/*
* Copyright (C) 2011-2016 Freescale Semiconductor, Inc.
* Jason Liu <r64343@freescale.com>
*
* SPDX-License-Identifier: GPL-2.0+
*
* Refer doc/README.imximage for more details about how-to configure
* and create imximage boot image
*
* The syntax is taken as close as possible with the kwbimage
*/

#define __ASSEMBLY__
#include <config.h>

/* image version */
IMAGE_VERSION 2

/*
* Boot Device : one of
* spi, sd (the board has no nand neither onenand)
*/
BOOT_FROM sd

#ifdef CONFIG_USE_IMXIMG_PLUGIN
/*PLUGIN plugin-binary-file IRAM_FREE_START_ADDR*/
PLUGIN board/freescale/mx6q_topeet/plugin.bin 0x00907000
#else

#ifdef CONFIG_SECURE_BOOT
CSF CONFIG_CSF_SIZE
#endif

/*
* Device Configuration Data (DCD)
*
* Each entry must have the format:
* Addr-type Address Value
*
* where:
* Addr-type register length (1,2 or 4 bytes)
* Address absolute address of the register
* value value to be stored in the register
*/
#ifdef CONFIG_IMX_OPTEE
SET_BIT 4 0x20c4070 0x3c00000
DATA 4 0x20e0024 0x00000003
CHECK_BITS_SET 4 0x20e0024 0x3
#endif

DATA 4 0x020e0798 0x000C0000
DATA 4 0x020e0758 0x00000000
DATA 4 0x020e0588 0x00000030
DATA 4 0x020e0594 0x00000030
DATA 4 0x020e056c 0x00000030
DATA 4 0x020e0578 0x00000030
DATA 4 0x020e074c 0x00000030
DATA 4 0x020e057c 0x00000030
DATA 4 0x020e058c 0x00000000
DATA 4 0x020e059c 0x00000030
DATA 4 0x020e05a0 0x00000030
DATA 4 0x020e078c 0x00000030
DATA 4 0x020e0750 0x00020000
DATA 4 0x020e05a8 0x00000018
DATA 4 0x020e05b0 0x00000018
DATA 4 0x020e0524 0x00000018
DATA 4 0x020e051c 0x00000018
DATA 4 0x020e0518 0x00000018
DATA 4 0x020e050c 0x00000018
DATA 4 0x020e05b8 0x00000018
DATA 4 0x020e05c0 0x00000018
DATA 4 0x020e0774 0x00020000
DATA 4 0x020e0784 0x00000018
DATA 4 0x020e0788 0x00000018
DATA 4 0x020e0794 0x00000018
DATA 4 0x020e079c 0x00000018
DATA 4 0x020e07a0 0x00000018
DATA 4 0x020e07a4 0x00000018
DATA 4 0x020e07a8 0x00000018
DATA 4 0x020e0748 0x00000018
DATA 4 0x020e05ac 0x00000018
DATA 4 0x020e05b4 0x00000018
DATA 4 0x020e0528 0x00000018
DATA 4 0x020e0520 0x00000018
DATA 4 0x020e0514 0x00000018
DATA 4 0x020e0510 0x00000018
DATA 4 0x020e05bc 0x00000018
DATA 4 0x020e05c4 0x00000018
DATA 4 0x021b0800 0xa1390003
DATA 4 0x021b080c 0x001F001F
DATA 4 0x021b0810 0x001F001F
DATA 4 0x021b480c 0x001F001F
DATA 4 0x021b4810 0x001F001F
DATA 4 0x021b083c 0x43180330
DATA 4 0x021b0840 0x03180310
DATA 4 0x021b483c 0x43200330
DATA 4 0x021b4840 0x0320025C
DATA 4 0x021b0848 0x40363838
DATA 4 0x021b4848 0x38362E3C
DATA 4 0x021b0850 0x3E3C4840
DATA 4 0x021b4850 0x44364640
DATA 4 0x021b081c 0x33333333
DATA 4 0x021b0820 0x33333333
DATA 4 0x021b0824 0x33333333
DATA 4 0x021b0828 0x33333333
DATA 4 0x021b481c 0x33333333
DATA 4 0x021b4820 0x33333333
DATA 4 0x021b4824 0x33333333
DATA 4 0x021b4828 0x33333333
DATA 4 0x021b08b8 0x00000800
DATA 4 0x021b48b8 0x00000800
DATA 4 0x021b0004 0x00020036
DATA 4 0x021b0008 0x09444040
DATA 4 0x021b000c 0x8A8F7955
DATA 4 0x021b0010 0xFF328F64
DATA 4 0x021b0014 0x01FF00DB
DATA 4 0x021b0018 0x00001740
DATA 4 0x021b001c 0x00008000
DATA 4 0x021b002c 0x000026D2
DATA 4 0x021b0030 0x008F1023
DATA 4 0x021b0040 0x00000047
DATA 4 0x021b0000 0x841A0000
DATA 4 0x021b001c 0x04088032
DATA 4 0x021b001c 0x00008033
DATA 4 0x021b001c 0x00048031
DATA 4 0x021b001c 0x09408030
DATA 4 0x021b001c 0x04008040
DATA 4 0x021b0020 0x00005800
DATA 4 0x021b0818 0x00011117
DATA 4 0x021b4818 0x00011117
DATA 4 0x021b0004 0x00025576
DATA 4 0x021b0404 0x00011006
DATA 4 0x021b001c 0x00000000

/* set the default clock gate to save power */
DATA 4 0x020c4068 0x00C03F3F
DATA 4 0x020c406c 0x0030FC03
DATA 4 0x020c4070 0x0FFFC000
DATA 4 0x020c4074 0x3FF00000
DATA 4 0x020c4078 0x00FFF300
DATA 4 0x020c407c 0x0F0000C3
DATA 4 0x020c4080 0x000003FF

/* enable AXI cache for VDOA/VPU/IPU */
DATA 4 0x020e0010 0xF00000CF
/* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
DATA 4 0x020e0018 0x007F007F
DATA 4 0x020e001c 0x007F007F

/*
* Setup CCM_CCOSR register as follows:
*
* cko1_en = 1 --> CKO1 enabled
* cko1_div = 111 --> divide by 8
* cko1_sel = 1011 --> ahb_clk_root
*
* This sets CKO1 at ahb_clk_root/8 = 132/8 = 16.5 MHz
*/
DATA 4 0x020c4060 0x000000fb
#endif

启动信息

  • 【迅为iMX6Q】开发板,通过拨码开关,设置为 SD卡启动方式,插入 SD 卡
  • 重新上电或者按下【RESET】复位按钮,查看串口输出信息
  • u-boot 启动信息如下:
U-Boot 2020.04-00016-g637954f1b9-dirty (Dec 29 2022 - 21:11:58 +0800)

CPU: i.MX6Q rev1.3 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 25C
Reset cause: POR
Model: i.MX6 Quad SABRE Smart Device Board
Board: MX6-SabreSD
DRAM: 2 GiB
MMC: FSL_SDHC: 1, FSL_SDHC: 2, FSL_SDHC: 3
Loading Environment from MMC... *** Warning - bad CRC, using default environment

No panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc1 is current device
flash target is MMC:1
Net: Could not get PHY for FEC0: addr -19
Could not get PHY for FEC0: addr -19
No ethernet found.

Fastboot: Normal
Normal Boot
Hit any key to stop autoboot: 0
=>
=>
=> version
U-Boot 2020.04-00016-g637954f1b9-dirty (Dec 29 2022 - 21:11:58 +0800)

arm-none-linux-gnueabihf-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025
GNU ld (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 2.33.1.20191209
=>

小结

  • 本篇主要记录 imx6q 的 u-boot 2020.04 编译方法与 SD 卡启动方法
  • 可以基于 ​​mx6sabresd​​,通过新增一个 board 的方式,适配 迅为imx6q 开发板
  • 当前 u-boot 2020.04 初步适配并运行在 迅为 imx6q 开发板上,网络PHY还需要适配