从0移植uboot(三) _编译最小可用uboot

前两篇介绍了uboot-2013.01的配置原理以及大致的运行流程,本文将讨论如何对uboot源码进行配置,将一个可用的uboot烧录到SD卡中。linux

定制本身的core board

市面上能买到的开发板的核心板基本都是基于官方参考板制做的,因此虽然标准操做是"定制"本身的core board,但鉴于个人板子的核心板是基于三星的参考板作的,因此咱们作的主要工做就是按照(一)中的原理,编写(山寨)咱们"本身的"核心板配置。咱们须要的目录是"board/samsung/origen/",这部分的主要功能就是将其中的文件"更名字"。首先来认识一下原版以示尊重redis

board/samsung/origen/

$ls board/samsung/origen/
lowlevel_init.S  Makefile  mem_setup.S  mmc_boot.c  origen.c  origen_setup.h  tools

接下来就开始咱们的山寨工做bash

//山寨参考板目录
$cp -arf ./board/samsung/origen ./board/samsung/xboot

//山寨关键文件
$mv ./board/samsung/xboot/origen.c ./board/samsung/xboot/xboot.c

uboot的编译系统和内核的相似,因此Makefile也得改(./board/samsung/xboot/Makefile)
fromide

30 ifndef CONFIG_SPL_BUILD
 31 COBJS   += origen.o
 32 endif

to工具

30 ifndef CONFIG_SPL_BUILD
 31 COBJS   += xboot.o
 32 endif

include/configs/origen.h

用于配置整个板子的头文件也不能放过ui

$cp include/configs/origen.h include/configs/xboot.h

fromcode

104 #define CONFIG_SYS_PROMPT               "ORIGEN # "
133 #define CONFIG_IDENT_STRING             " for ORIGEN"

toorm

104 #define CONFIG_SYS_PROMPT               "xboot # "
133 #define CONFIG_IDENT_STRING             " for xboot"

boards.cfg

最后,别忘了我在上文提到的boards.cfg文件,若是这里面不动手脚,咱们的板子是不会被Makefile找到的,So,blog

284 origen                       arm         armv7       origen              samsung        exynos
 285 xboot                        arm         armv7       xboot               samsung        exynos

和以前同样,至此,咱们就能够先编译一下过过手瘾(顺便检查一下配置^-^),开发

1 #!/bin/bash            
  2 CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')
  3 export ARCH=arm
  4 export CROSS_COMPILE=/opt/arm-cross-compile/arm-2014.05/bin/arm-none-linux-gnueabi-
  5 newName="xboot"
  6 make distclean
  7 make ${newName}_config
  8 make  -j${CPU_NUM}

上面是编译的小脚本,下面是编译的输出。

编译and烧录

按照(一)中介绍的,此时已经能够"make xboot_config;make -8"并获得uboot.bin,但此时这个uboot.bin是不能直接烧录的。但不管如何,请暂且记住它的大小:176568byte。接下来,咱们须要对uboot.bin进行一系列处理使它可以在exynos4412上运行,这其中要用到下面的几个命令或三星提供的工具软件,这些操做的目的就是根据三星的芯片的启动要求对uboot.bin 进行一些处理,包括在特定长度的位置加上和校验信息以及插入一些文件段。

$split -b 14336 uboot.bin bl2
$chksum
$add_padding
$rm bl2a*
$cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin >xboot.bin

注意到那个E4412_N.bl1.SCP2G.bin了吗,这个文件就是前文说的三星SoC启动过程的BL1阶段。咱们可使用脚本一次性完成上面的工做。

make -j${CPU_NUM}
 
cp tools/mkimage /usr/bin/
cp u-boot.bin ${ROOTDIR}/sdfuse_q

cd ${ROOTDIR}/sdfuse_q
split -b 14336 u-boot.bin bl2   #split u-boot to bl2a... why14336???==>参考三星bl2对uboot的校验方式,它会读取14336处的CS校验码
make     #编译chksum
${ROOTDIR}/sdfuse_q/chksum      #源码显示程序生成的校验码并无回写到uboot,即uboot仍是没有校验,不知道为何还成功了,可是这个>
${ROOTDIR}/sdfuse_q/add_padding
rm bl2a*
cp u-boot.bin ${ROOTDIR}/CodeSign4SecureBoot/

cd ${ROOTDIR}/CodeSign4SecureBoot
cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin > u-boot-${newName}.bin
rm ./u-boot.bin
cp -a ./u-boot-${newName}.bin $TFTPDIR
cp ./u-boot-${newName}.bin ../mk_sdboot/
 
cd ${ROOTDIR}/mk_sdboot
sudo ./sd_fusing_exynos4x12.sh /dev/sdb u-boot-${newName}.bin

至此,咱们就获得了一个能使用的镜像xboot.bin,这个xboot.bin的大小:527104byte!而后咱们就可使用另外的一些工具烧录到SD卡,注意若是你的开发主机对直接读取SD卡的支持不是很好的话,可使用读卡器,不管是虚拟机仍是Linux主机,对USB设备的支持仍是让人满意的,烧录很简单,咱们只须要执行下下面的"./sd_fusing_exynos4x12.sh /dev/your_SD_device u-boot-xboot.bin"便可,这个脚本是三星公司提供的,就是将镜像烧录到SD卡中,下面是我用的,贴出来供参考。

#!/bin/sh
#
# Copyright (C) 2010 Samsung Electronics Co., Ltd.
#              http://www.samsung.com/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# sd_fusing_exynos4x12.sh
####################################
reader_type1="/dev/sd"
reader_type2="/dev/mmcblk0"

if [ -z $2 ]
then
    echo "usage: ./sd_fusing.sh <SD Reader's device file> <filename>"
    exit 0
fi

param1=`echo "$1" | awk '{print substr($1,1,7)}'`

if [ "$param1" = "$reader_type1" ]
then
    partition=$1"1"
elif [ "$1" = "$reader_type2" ]
then
    partition=$1"p1"
else
    echo "Unsupported SD reader"
    exit 0
fi

if [ -b $1 ]       
then
    echo "$1 reader is identified."
else
    echo "$1 is NOT identified."
    exit 0
fi

####################################
echo "----------------------------------"
echo $partition
echo "----------------------------------"

# format
umount $partition 2> /dev/null

echo "$2 fusing..."
dd iflag=dsync oflag=dsync if=./$2 of=$1 seek=1 && \
        echo "$2 image has been fused successfully."

####################################
#<Message Display>
echo "Eject SD ca

将启动模式调整到从SD卡启动,uboot就能够跑起来了。

相关文章
相关标签/搜索