(YDW)uboot移植----以Exynos 4412(Cortex-A9)为例

前言:当在公司做开发时,拿到一个裸板, 上边无BootLoader, 无操作系统内核。我们首先需要做的事情是:根据板子信息(SOC、Arch、CPU、Vendor、board、参考板等),移植Uboot,继而移植linux内核。下面是以Cortex-A9为例,uboot移植的具体步骤。 

1、确定开发板信息

目的:嵌入式的系统移植就是移植BootLoader、linux内核、根文件系统。针对不同开发板所移植的linux内核和根文件系统大体相同,但针对不同开发板,uboot移植根据平台架构不同而做出不同改动。换句话说,uboot移植与平台架构紧密相关,而linux内核和根文件系统与平台结构联系不那么紧密。(这其中又引出一个问题:做系统移植可以不移植uboot吗?答案是可以的,uboot做的工作是针对不同的开发板硬件做初始化,所以开发板不同所做的硬件初始化也不同。这个过程也可以放在linux内核中对硬件做初始化,但是这样linux内核就不具有普遍性,总不能依不同开发板裁剪不同内核吧,太复杂了。)因开发板的不同,想要移植uboot到开发板上,首先要对uboot进行软件裁剪,选取合适的参考板,所以首先要确认开发板相关信息。

SOC:Exynos 4412 (查Exynos 412芯片手册可知)

Arch:ARM (查芯片手册)

CPU:Cortex-A9(芯片手册中叫的名)        armv7(uboot源码中叫的名)

Vendor:Samsung(查芯片手册)

board:fs4412(公司自定义)

参考板: origen(百度输入Exynos 4412  arm  armv7  Samsung fs4412查找)

2、确定内存划分

目的:

查看Exynos 4412芯片手册----memory map 章节  如下图(部分)所示:

主要看对应地址及大小(如 iROM、iRAM、DDR(内存)等)

Exynos 4412内存划分
Exynos 4412芯片手册--内存划分部分截图

3、交叉开发

目的:因为如果在开发板上编译uboot源码,由于开发板硬件(CPU等)限制,可能导致编译时间过长,所以我们要安装交叉编译工具链,使uboot源码在个人PC机上编译,在开发板上执行。在Ubuntu上用gcc直接编译的是x86架构的,不能一直到ARM开发板上。

(1)获取交叉编译工具链源码

    有以下三种途径可以获得(推荐使用第二种或者第三种

(2)安装交叉编译工具链

    A、解压

    把下载好的交叉编译工具链放在Ubuntu下进行解压

linux@ubuntu:~/yudw2018/packages$ tar -xvf toolchain-4.5.1-farsight.tar.bz2

    B、配置环境变量 

    以下提供三种配置环境变量的方法(建议使用第三种

  • 对当前终端生效
linux@ubuntu:~/yudw2018$ export PATH=$PATH:/home/linux/yudw2018/toolchain-4.5.1/bin/
  •  对当前用户生效

         在家目录下的.bashrc文件中最后一行添加 export PATH=$PATH:/home/linux/yudw2018/toolchain-4.5.1/bin/

linux@ubuntu:~/yudw2018$ vi /home/linux/.bashrc
export PATH=$PATH:/home/linux/yudw2018/toolchain-4.5.1/bin/
  •  对所有用户生效

         在  /etc/bash.bashrc  文件中最后一行添加  export PATH=$PATH:/home/linux/yudw2018/toolchain-4.5.1/bin/  或者 /etc/environment 文件中添加交叉编译工具链的绝对路径  /home/linux/yudw2018/toolchain-4.5.1/bin/

linux@ubuntu:~/yudw2018$ sudo vi /etc/environment 
[sudo] password for linux: 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/linux/yudw2018/install/toolchain-4.5.1/bin/" 

     C、使设置的环境变量生效

linux@ubuntu:~$ sudo reboot

4、下载Uboot源码

    根据开发板出厂年份下载相近年份的Uboot源码稳定版,Uboot源码下载网址:Uboot源码下载 :ftp://ftp.denx.de/pub/u-boot/  注意:必须使用相匹配的交叉编译工具链,否则会编译报错。  在此使用的是uboot2013和toolchain-4.5.1

    放在Ubuntu下解压

linux@ubuntu:~/yudw2018$ tar -xvf u-boot-2013.01.tar.bz2

5、查看Uboot源码的目录结构

    确认哪些目录是Uboot移植用的到的,哪些是用不到的。(查看所有目录,确认哪些是和平台相关的文件:SOC、Arch、CPU、Vendor、board、参考板)在此开发板 Uboot移植用的到的目录为

    arch/arm/cpu/armv7    board/samsung/origen    boards.cfg    include/configs/origen.h    README    Makefile

6、配置

    首先进入Uboot源码顶层 目录下,执行make distclean (比使用make clean命令清除更彻底)清除可能存在的中间文件

linux@ubuntu:~/yudw2018$ cd u-boot-2013.01/
linux@ubuntu:~/yudw2018/u-boot-2013.01$ make distclean

    然后看进入顶层Makefile文件修改交叉编译工具链,修改后如下所示

183 # set default to nothing for native builds
184 ifeq (arm,$(ARCH))
185 CROSS_COMPILE ?=arm-none-linux-gnueabi-
186 endif 

    看README:

 263 Selection of Processor Architecture and Board Type:
 264 ---------------------------------------------------                                                             
 265 
 266 For all supported boards there are ready-to-use default
 267 configurations available; just type "make <board_name>_config".
 268 
 269 Example: For a TQM823L module type:
 270 
 271     cd u-boot
 272     make TQM823L_config
 273 
 274 For the Cogent platform, you need to specify the CPU type as well;
 275 e.g. "make cogent_mpc8xx_config". And also configure the cogent
 276 directory according to the instructions in cogent/README.

     此段README代码主要说明要执行 make <board_name>_config 命令。

    然后执行 make fs4412_config 遇到问题再解决

linux@ubuntu:~/yudw2018/u-boot-2013.01$ make fs4412_config

     此时会报错:(1)

linux@ubuntu:~/yudw2018/install/u-boot-2013.10$ make fs4412_config
make: *** No rule to make target `fs4412_config'.  Stop.
make: *** [fs4412_config] Error 1

    使用 grep "NO rule to make target" 查找报错信息出处

linux@ubuntu:~/yudw2018/install/u-boot-2013.10$ grep "No rule to make target" -nR

    查出此错误在mkconfig文件第25行定义:大意为在boards.cfg中查找fs4412_config没有找到

 24 if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then
 25     # Automatic mode                                                        
 26     line=`awk '($0 !~ /^#/ && $7 ~ /^'"$2"'$/) { print $1, $2, $3, $4, $5, $
 27     if [ -z "$line" ] ; then
 28         echo "make: *** No rule to make target \`$2_config'.  Stop." >&2
 29         exit 1
 30     fi
 31 
 32     set ${line}
 33     # add default board name if needed
 34     [ $# = 3 ] && set ${line} ${1}
 35 fi

    解决:在boards.cfg中添加 fs4412相关信息(复制参考板origen的信息,把origen换成fs4412)

    重新执行make    fs4412_config  出现如下结果表示修改配置成功。

linux@ubuntu:~/yudw2018/install/u-boot-2013.10$ make fs4412_config
Configuring for fs4412 board...

7、编译

    执行 make 

    报错(2)include/configs/ 没有找到 fs4412.h 头文件

linux@ubuntu:~/yudw2018/install/u-boot-2013.01$ make
Generating include/autoconf.mk
/home/linux/yudw2018/install/u-boot-2013.01/include/config.h:10:28: fatal error: configs/fs4412.h: No such file or directory
compilation terminated.
Generating include/autoconf.mk.dep
/home/linux/yudw2018/install/u-boot-2013.01/include/config.h:10:28: fatal error: configs/fs4412.h: No such file or directory
compilation terminated.
arm-none-linux-gnueabi-gcc -DDO_DEPS_ONLY \
		-g  -Os   -fno-common -ffixed-r8 -msoft-float  -D__KERNEL__ -I/home/linux/yudw2018/install/u-boot-2013.01/include -fno-builtin -ffreestanding -nostdinc -isystem /home/linux/yudw2018/install/gcc-4.6.4/bin/../lib/gcc/arm-arm1176jzfssf-linux-gnueabi/4.6.4/include -pipe  -DCONFIG_ARM -D__ARM__ -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fstack-usage   \
		-o lib/asm-offsets.s lib/asm-offsets.c -c -S
In file included from /home/linux/yudw2018/install/u-boot-2013.01/include/common.h:37:0,
                 from lib/asm-offsets.c:18:
/home/linux/yudw2018/install/u-boot-2013.01/include/config.h:10:28: fatal error: configs/fs4412.h: No such file or directory
compilation terminated.
make: *** [lib/asm-offsets.s] Error 1

解决:拷贝origen.h 改名为 fs4412.h

linux@ubuntu:~/yudw2018/install/u-boot-2013.01/include/configs$ cp origen.h fs4412.h

再次执行 make 

报错(3)board/samsung/fs4412 无此文件

make: *** board/samsung/fs4412/: No such file or directory.  Stop.

解决: 将board/samsung/ 下 cp origen fs4412 -r 

linux@ubuntu:~/yudw2018/install/u-boot-2013.01/board/samsung$ cp origen fs4412 -r

    并修改 fs4412 下 origen.c 文件 -> fs4412.h ;修改 fs4412/Makefile 里边 origen->fs4412(只需修改fs4412.h的名字和Makefile里面的内容(origen -> fs4412))

linux@ubuntu:~/yudw2018/install/u-boot-2013.01/board/samsung/fs4412$ mv origen.c fs4412.c
 30 ifndef CONFIG_SPL_BUILD
 31 COBJS   += fs4412.o                                                                            
 32 endif

再次执行make 在u-boot-2013.01/ 下生成 u-boot.bin 文件 ,说明编译成功。

linux@ubuntu:~/yudw2018/install/u-boot-2013.01$ ls
api         config.mk  drivers    include      mkconfig  rules.mk         tools       u-boot.srec
arch        COPYING    dts        lib          nand_spl  snapshot.commit  u-boot
board       CREDITS    examples   MAINTAINERS  net       spl              u-boot.bin
boards.cfg  disk       fs         MAKEALL      post      System.map       u-boot.lds
common      doc        helper.mk  Makefile     README    test             u-boot.map

8、剩下的就是修改 串口、网卡 等驱动了。(到第 7 步 uboot移植就已经成功了,可以下载到开发板上测试,启动开发板了)

猜你喜欢

转载自blog.csdn.net/weixin_42015463/article/details/81950149