详细讲解移植u-boot.2022.10版本移植到开发板基本方法

 大家好,我是ST​。​

今天给大家讲一讲如何将u-boot.2022.10版本移植到imx6ull开发板上。

环境

选项 内容
编译主机 UbuntuLTS 18.04
目标板 ATK I.MX6ULL(512MB DDR3 + 8GB EMMC)
u-boot版本 2022.10
交叉编译工具链 gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf

一、u-boot编译环境准备

1.u-boot源码包下载

1.1、本次使用的uboot版本为2022.10版本u-boot-2022.10.tar.bz2
1.2、下载链接:https://ftp.denx.de/pub/u-boot/

图片

2.编译

2.1、通过共享文件夹或FTP服务将u-boot-2022.10.tar.bz2拷贝到ubuntu中
2.2、源码压缩包解压

tar -jxvf u-boot-2022.10.tar.bz2

3.安装依赖库

3.1、使用默认配置进行编译u-boot时报下面错误

toto@toto:~/workspace/uboot/u-boot-2022.10$ make mx6ull_14x14_evk_defconfig
YACC    scripts/kconfig/zconf.tab.c
/bin/sh: 1: bison: not found
scripts/Makefile.lib:222: recipe for target 'scripts/kconfig/zconf.tab.c' failed
make[1]: *** [scripts/kconfig/zconf.tab.c] Error 127
Makefile:578: recipe for target 'mx6ull_14x14_evk_defconfig' failed
make: *** [mx6ull_14x14_evk_defconfig] Error 2

解决办法:
该错误是由于缺少一些相关库文件导致,安装上即可正常编译,安装命令:

sudo apt install bison flex

3.2、然后继续编译又报错

图片

解决办法,安装lib32z1依赖库

sudo apt-get install lib32z1

3.3、继续编译make,报错

图片

解决方法:
继续安装依赖库libssl-dev

sudo apt-get install libssl-dev

3.4、编译通过,u-boot所有依赖库已全部安装完毕

图片

二、U-Boot中添加自己的开发板

在U-Boot中添加自己的开发板NXP官方uboot中默认都是 NXP 自己的开发板,虽说我们可以直接在官方的开发板上直接修改,使u-boot可以完整的运行在我们的板子上。但是从学习的角度来讲,这样我们就不能了解到uboot是如何添加新平台的。接下来我们就参考NXP官方的I.MX6ULL EVK 开发板学习如何在u-boot中添加我们的开发板或者开发平台。

1、添加开发板默认配置文件

先在 configs 目录下创建默认配置文件,复制 mx6ull_14x14_evk_defconfig,然后重命名为 mx6ull_toto_defconfig,命令如下:

cd configs
cp mx6ull_14x14_evk_defconfig mx6ull_toto_defconfig

然后将文件 mx6ull_toto_defconfig 中的内容改成下面的:

CONFIG_ARM=y
CONFIG_ARCH_MX6=y
CONFIG_SYS_TEXT_BASE=0x87800000
CONFIG_SYS_MALLOC_LEN=0x1000000
CONFIG_NR_DRAM_BANKS=1
CONFIG_ENV_SIZE=0x2000
CONFIG_ENV_OFFSET=0xC0000
CONFIG_MX6ULL=y
CONFIG_TARGET_MX6ULL_TOTO=y
...

可以看出,mx6ull_toto_defconfig 基本和 mx6ull_14x14_evk_defconfig中的内容一样,只是第9行做了修改

2、添加开发板对应的头文件

在目录 include/configs 下添加 I.MX6ULL-ALPHA 开 发 板 对 应 的 头 文 件 , 复 制 include/configs/mx6ullevk.h,并重命名为 mx6ull_toto.h,命令如下:

cp include/configs/mx6ullevk.h include/configs/mx6ull_toto.h

拷贝完成以后将:

#ifndef __MX6ULLEVK_CONFIG_H
#define __MX6ULLEVK_CONFIG_H

改为:

#ifndef __MX6ULL_TOTO_CONFIG_H
#define __MX6ULL_TOTO_CONFIG_H

mx6ull_toto.h 里面有很多宏定义,如配置uboot默认串口打印使用uart的第几个口,网口默认使用哪个网口等,也有一些u-boot环境变量的的默认配置。如果我们想要改变默认的uart和enet口,那就在 mx6ull_toto.h 里面做修改即可。

3、添加开发板对应的板级文件夹

uboot 中每个板子都有一个对应的文件夹来存放板级文件,比如开发板上外设驱动文件等 等。NXP 的 I.MX 系列芯片的所有板级文件夹都存放在 board/freescale 目录下,在这个目录下 有个名为 mx6ullevk 的文件夹,这个文件夹就是 NXP 官方 I.MX6ULL EVK 开发板的板级文件 夹。复制 mx6ullevk,将其重命名为 mx6ull_toto,命令如下:

cd board/freescale
cp -r mx6ullevk/ mx6ull_toto

进 入 mx6ull_toto 目 录 中 , 将 其 中 的 mx6ullevk.c 文 件 重 命 名 为mx6ull_toto.c,命令如下:

cd mx6ull_toto
mv mx6ullevk.c mx6ull_toto.c

我们还需要对 mx6ull_toto 目录下的文件做一些修改:

3.1、修改 mx6ull_toto 目录下的 Makefile 文件

将 mx6ull_alientek_emmc 下的 Makefile 文件内容改为如下所示:

 
 

# SPDX-License-Identifier: GPL-2.0+
# (C) Copyright 2016 Freescale Semiconductor, Inc.

obj-y  := mx6ull_toto.o

重点是第 4行的 obj-y,改为 mx6ull_toto.o,这样才会编译 mx6ull_toto.c 这个文件。

3.2、修改 mx6ull_toto 目录下的 imximage.cfg 文件

将 imximage.cfg 中的下面一句:

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

改为:

 
 

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

3.3、修改 mx6ull_toto 目录下的 Kconfig 文件

修改 Kconfig 文件,修改后的内容如下:

 
 

if TARGET_MX6ULL_TOTO

config SYS_BOARD
    default "mx6ull_toto"

config SYS_VENDOR
    default "freescale"

config SYS_CONFIG_NAME
    default "mx6ull_toto"

config IMX_CONFIG
    default "board/freescale/mx6ull_toto/imximage.cfg"

endif

3.4、修改 mx6ull_toto 目录下的 MAINTAINERS 文件

修改 MAINTAINERS 文件,修改后的内容如下:

 
 

MX6ULLTOTO BOARD
M:    Peng Fan <[email protected]>
S:    Maintained
F:    board/freescale/mx6ull_toto/
F:    include/configs/mx6ull_toto.h
F:    configs/mx6ull_toto_defconfig
F:    configs/mx6ull_14x14_evk_plugin_defconfig
F:    configs/mx6ulz_14x14_evk_defconfig

4、修改 arch/arm/mach-imx/mx6/Kconfig

修改文件arch/arm/mach-imx/mx6/Kconfig,在 468 行加入如下内容:

config TARGET_MX6ULL_TOTO
    bool "Support mx6ull_toto"
    depends on MX6ULL
    select BOARD_LATE_INIT
    select DM
    select DM_THERMAL
    imply CMD_DM

717行添加如下内容:

 
 

source "board/freescale/mx6ull_toto/Kconfig"

5、其他需要修改的地方

在 uboot 启动信息中会有“Board: MX6ULL 14x14 EVK”这一句,也就是说板子名字为“MX6ULL 14x14 EVK”。那么如果要将其改为我们想要的名字,就需打开文件 mx6ull_toto.c,找到函数checkboard,将其改为如下所示内容:

 
 

int checkboard(void)
{
    if (is_cpu_type(MXC_CPU_MX6ULZ))
        puts("Board: MX6ULZ 14x14 EVK\n");
    else
        puts("Board: MX6ULL TOTO\n");
    return 0;
}

6、使用新添加的板子配置编译uboot

在 uboot 根目录下新建一个名为 build.sh 的 shell 脚本,在这个 shell 脚本里面输入如下内容:

#!/bin/bash
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_toto_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8

build.sh添加可执行权限,命令如下:

chmod 777 build.sh

三、编译、下载、验证

1、编译

./build.sh

2、编译成功

  ...
  DTC     arch/arm/dts/imx6ulz-bsh-smm-m2.dtb
  DTC     arch/arm/dts/imx6ulz-14x14-evk.dtb
  DTC     arch/arm/dts/imx6q-apalis-eval.dtb
  DTC     arch/arm/dts/imx6dl-colibri-eval-v3.dtb
  SHIPPED dts/dt.dtb
  CAT     u-boot-dtb.bin
  COPY    u-boot.dtb
  COPY    u-boot.bin
  CFGS    u-boot-dtb.cfgout
  MKIMAGE u-boot-dtb.imx

3、下载验证

使用imxdownload将新编译出来的u-boot.bin烧写到SD卡中测试,SecureCRT 输出结果如下:

sudo ./imxdownload u-boot.bin /dev/sdbU-Boot 2022.10-gaef9f25a-dirty (Apr 05 2023 - 17:49:18 +0800)

CPU:   Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 26C
Reset cause: POR
Model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
Board: MX6ULL TOTO
DRAM:  512 MiB
Core:  65 devices, 17 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... OK
In:    serial
Out:   serial
Err:   serial
Net:   Could not get PHY for FEC1: addr 1
Could not get PHY for FEC1: addr 1
Get shared mii bus on ethernet@2188000
Could not get PHY for FEC1: addr 2
Get shared mii bus on ethernet@2188000
Could not get PHY for FEC1: addr 2
No ethernet found.

Hit any key to stop autoboot: 
=> 

从输出结果可以看出除网络没有识别出来外,其他均正常。

u-boot下网络调试将在下一篇文章进行详细介绍,关注我,下期文章及时观看!

猜你喜欢

转载自blog.csdn.net/weixin_41114301/article/details/132571764