1. 程式人生 > >從0移植uboot(三) _編譯最小可用uboot

從0移植uboot(三) _編譯最小可用uboot

for 移植 腳本 wid fine been dbo 設備 var

來源:Linux社區 作者:xiaojiang1025 :http://www.linuxidc.com/Linux/2017-02/141020.htm

前兩篇介紹了uboot-2013.01的配置原理以及大體的運行流程,本文將討論如何對uboot源碼進行配置,將一個可用的uboot燒錄到SD卡中。

定制自己的core board

市面上能買到的開發板的核心板基本都是基於官方參考板制作的,所以雖然標準操作是"定制"自己的core board,但鑒於我的板子的核心板是基於三星的參考板做的,所以我們做的主要工作就是按照(一)中的原理,編寫(山寨)我們"自己的"核心板配置。我們需要的目錄是"board/samsung/origen/"

,這部分的主要功能就是將其中的文件"改名字"。首先來認識一下原版以示尊重

board/samsung/origen/

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

接下來就開始我們的山寨工作

//山寨參考板目錄
$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)
from

 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

用於配置整個板子的頭文件也不能放過

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

from

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

to

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

boards.cfg

最後,別忘了我在上文提到的boards.cfg文件,如果這裏面不動手腳,我們的板子是不會被Makefile找到的,So,

 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

我們可以使用腳本一次性完成上面的工作。

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就可以跑起來了。

從0移植uboot(三) _編譯最小可用uboot