移植准备工作
本次移植基于ubuntu1804环境
- 去uboot官网下载最新版本u-boot-2020.10.tar.bz2
- 在TI官网下载ARM交叉编译工具本次版本为gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf
- 解压ARM ToolChain 命令:tar -Jxvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz
- 解压uboot 命令:tar -xvf u-boot-2020.10.tar.bz2
- 设置交叉编译环境 命令:vi /etc/profile 在末尾追加以下行:
export PATH=$PATH:/workplace/tool/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
路径根据自己的实际情况修改
最后:wq保存退出,在命令窗口输入命令,确认环境变量生效
source /etc/profile
接着在命令窗口输入命令:检查环境变量是否生效
arm-linux-gnueabihf-gcc -v
出现以下显示,则说明设置成功
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/workplace/tool/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-gnueabihf/8.3.0/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/src/gcc/configure --target=arm-linux-gnueabihf --prefix= --with-sysroot=/arm-linux-gnueabihf/libc --with-build-sysroot=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/install//arm-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-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpfr=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpc=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-isl=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-arch=armv7-a --with-pkgversion='GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)'
Thread model: posix
gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))
至此,基本的准备工作完成,未准备到的,遇到情况再解决。
进行UBOOT移植
- 进入到uboot的解压目录
- 改变解压后的uboot文件属性,方便后面涉及的部分文件修改稿
chmod 777 -R ./u-boot-2020.10
找到属于板子的归属
目前的UBOOT源码庞大且复杂,如果去把源码浏览一遍,先了解大概后,再来修改,这是不现实的,先不说能不能真的看懂,所需要的时间和精力可能也不允许我们这么做。
我板子所用的芯片是属于TI的,所以先到源码目录./board中去找有没有TI相关的文件夹,可以找到,ti文件夹下包含如下开发板
板子的芯片型号是AM4377,显而易见是属于am43xx文件夹。此刻,找到了目标板的归属,移植将在这个基础上进行。
按照惯例,一般是将需要修改的文件先复制一份,再修改,这样出问题后好恢复,但是,我这是第一移植,复制后,文件名肯定不能重复,命名成其他的名字,后面要修改哪些地方才能使编译不报错,一概不知,所以我就先在源码上直接修改了,如果改后不能恢复,就删除,在重新解压一次出来 修改备份是个好习惯*
找到板子的defconfig配置文件
在源码的根目的configs文件夹,保存着所有板子的配置文件,直接搜索该目录下am43字符相关的文件
观其文件名,大概能了解到,其他4个文件,都是am43xx_evm_defconfig衍生出来的,所以,我选择am43xx_evm_defconfig这个原始配置文件作为我板子的配置文件的母版。
确认源码能否编译通过
首先需要将源码编译一次,目的在于了解,下载的这份源码,有没有问题,用它官方的配置文件进行配置后,编译。如果出现错误,那可能就得更换源码了,因为我尚且不清楚错误原因,而且还要在此基础上进行修改,可能错误会越来越多,心很累。牛X大神可以,但我不是。
执行以下命令,清理干净残余的编译文件,避免干扰后面的编译
make mrproper
接着
root@ubuntu:/workplace/uboot/u-boot-2020.10# make am43xx_evm_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
root@ubuntu:/workplace/uboot/u-boot-2020.10#
配置文件编译通过,接着执行下面的命令:
make -j4
四个线程,增加编译速度,我虚拟机设置的4个核,错误的参数,可能会导致编译出错
最后部分编译结果如下:没有错误,可以在此源码基础上进行修改
接下来进行真正的代码移植修改,借助VSCode进行代码查看
board.h文件修改
打开/board/ti/am43xx目录,能够得到如下信息
board.c -----------------------------------------------》板子相关初始化配置
board.h -----------------------------------------------》确定板子名称及函数声明
Kconfig -----------------------------------------------》配置菜单相关
MAINTAINERS -------------------------------------》源码维护相关
Makefile -----------------------------------------------》文件编译相关
mux.c --------------------------------------------------》引脚配置相关
从这几个文件,可以看到,板子的绝大多数硬件配置将在board.c中,而所必须的硬件引脚配置在mux.c中,board.h文件,决定目标板的名称,而名称将决定后面编译的编译流程,这些都可以在看到这几个文件的内容后得知。
那么接下来,很重要的一步,是要为uboot指定一块板子,然后uboot才能根据你指定的板子,去决定如何编译相关文件,因此首先得先看board.h的具体内容:
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* board.h
*
* TI AM437x boards information header
* Derived from AM335x board.
*
* Copyright (C) 2013, Texas Instruments, Incorporate