前兩篇介紹了uboot-2013.01的配置原理以及大致的運行流程,本文將討論如何對uboot源碼進行配置,將一個可用的uboot燒錄到SD卡中。linux
市面上能買到的開發板的核心板基本都是基於官方參考板製做的,因此雖然標準操做是"定製"本身的core board,但鑑於個人板子的核心板是基於三星的參考板作的,因此咱們作的主要工做就是按照(一)中的原理,編寫(山寨)咱們"本身的"核心板配置。咱們須要的目錄是"board/samsung/origen/",這部分的主要功能就是將其中的文件"更名字"。首先來認識一下原版以示尊重redis
$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
用於配置整個板子的頭文件也不能放過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文件,若是這裏面不動手腳,咱們的板子是不會被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}
上面是編譯的小腳本,下面是編譯的輸出。
按照(一)中介紹的,此時已經能夠"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就能夠跑起來了。