一、简介
硬件平台:开发板的SoC是三星公司的S5PV210,属于210系列开发板。
uboot:选择uboot官方u-boot-2013.10版本进行移植。
在uboot的board/samsung文件夹中选择与210相近的开发板作为模板进行移植,这里选择的是goni文件,该开发板对应的头文件是include/configs文件夹中的s5p_goni.h。
二、uboot的配置
%_config:: unconfig
@$(MKCONFIG) -A $(@:_config=)
uboot编译之前要进行配置。配置时执行make %_config。这里的%是通配符,根据第三部分的介绍可以知道在配置时这里的%具体用什么来代替。配置实际上是执行mkconfig脚本,脚本传参两个,$1 = -A;$2 = %(通配符)。
三、uboot中配置脚本(mkconfig)介绍
if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then
# Automatic mode
line=`awk '($0 !~ /^#/ && $7 ~ /^'"$2"'$/) { print $1, $2, $3, $4, $5, $6, $7, $8 }' boards.cfg`
if [ -z "$line" ] ; then
echo "make: *** No rule to make target \`$2_config'. Stop." >&2
exit 1
fi
set ${line}
# add default board name if needed
[ $# = 3 ] && set ${line} ${1}
fi
上面这段代码采用正则表达式从boards.cfg配置文件中提取域7与$2相等的那一行赋值给line。
awk读取boards.cfg文件,一次一行;$0 !~ /^#/读取的这一行不以#号开头,即没有被注释掉,$0表示所有的域,!~表示不匹配;$7 ~ /^'"$2"'$/表示域7与第二个位置参数匹配;print $1, $2, $3, $4, $5, $6, $7, $8条件满足则打印这一行。
查看boards.cfg文件后可以发现比较合适的一行是:
Active arm armv7 s5pc1xx samsung goni s5p_goni -
set ${line}后改变位置参数:
$# = 8
$1 = Active
$2 = arm
$3 = armv7
$4 = s5pc1xx
$5 = samsung
$6 = goni
$7 = s5p_goni
$8 = -
从这里可以印证我们在配置时执行的make %_config中的%是s5p_goni。因为是域7进行匹配。直接执行make s5p_goni_config。
while [ $# -gt 0 ] ; do
case "$1" in
--) shift ; break ;;
-a) shift ; APPEND=yes ;;
-n) shift ; BOARD_NAME="${7%_config}" ; shift ;;
-t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
*) break ;;
esac
done
[ $# -lt 7 ] && exit 1
[ $# -gt 8 ] && exit 1
同上面比对,这个while循环在这里什么也没有做。
# Strip all options and/or _config suffixes
CONFIG_NAME="${7%_config}"
[ "${BOARD_NAME}" ] || BOARD_NAME="${7%_config}"
arch="$2"
cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`
spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`
if [ "$6" = "-" ] ; then
board=${BOARD_NAME}
else
board="$6"
fi
[ "$5" != "-" ] && vendor="$5"
[ "$4" != "-" ] && soc="$4"
[ $# -gt 7 ] && [ "$8" != "-" ] && {
# check if we have a board config name in the options field
# the options field mave have a board config name and a list
# of options, both separated by a colon (':'); the options are
# separated by commas (',').
#
# Check for board name
tmp="${8%:*}"
if [ "$tmp" ] ; then
CONFIG_NAME="$tmp"
fi
# Check if we only have a colon...
if [ "${tmp}" != "$8" ] ; then
options=${8#*:}
TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"
fi
}
if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then
echo "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2
exit 1
fi
if [ "$options" ] ; then
echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"
else
echo "Configuring for ${BOARD_NAME} board..."
fi
上面的代码定义了几个变量:
CONFIG_NAME = s5p_goni
BOARD_NAME = s5p_goni
arch = arm
cpu = armv7
spl_cpu = 空
board = goni
vendor = samsung
soc = s5pc1xx
最后打印:echo "Configuring for ${BOARD_NAME} board..."
if [ "$SRCTREE" != "$OBJTREE" ] ; then
mkdir -p ${OBJTREE}/include
mkdir -p ${OBJTREE}/include2
cd ${OBJTREE}/include2
rm -f asm
ln -s ${SRCTREE}/arch/${arch}/include/asm asm
LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/
cd ../include
mkdir -p asm
else
cd ./include
rm -f asm
ln -s ../arch/${arch}/include/asm asm
fi
rm -f asm/arch
if [ -z "${soc}" ] ; then
ln -s ${LNPREFIX}arch-${cpu} asm/arch
else
ln -s ${LNPREFIX}arch-${soc} asm/arch
fi
if [ "${arch}" = "arm" ] ; then
rm -f asm/proc
ln -s ${LNPREFIX}proc-armv asm/proc
fi
这部分代码创建了几个比较重要的符号链接:
include/asm -> arch/arm/include/asm
asm/arch -> asm/arch-s5pc1xx
asm/proc -> asm/proc-armv
( echo "ARCH = ${arch}"
if [ ! -z "$spl_cpu" ] ; then
echo 'ifeq ($(CONFIG_SPL_BUILD),y)'
echo "CPU = ${spl_cpu}"
echo "else"
echo "CPU = ${cpu}"
echo "endif"
else
echo "CPU = ${cpu}"
fi
echo "BOARD = ${board}"
[ "${vendor}" ] && echo "VENDOR = ${vendor}"
[ "${soc}" ] && echo "SOC = ${soc}"
exit 0 ) > config.mk
# Assign board directory to BOARDIR variable
if [ -z "${vendor}" ] ; then
BOARDDIR=${board}
else
BOARDDIR=${vendor}/${board}
fi
#
# Create board specific header file
#
if [ "$APPEND" = "yes" ] # Append to existing config file
then
echo >> config.h
else
> config.h # Create new config file
fi
echo "/* Automatically generated - do not edit */" >>config.h
for i in ${TARGETS} ; do
i="`echo ${i} | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'`"
echo "#define CONFIG_${i}" >>config.h ;
done
echo "#define CONFIG_SYS_ARCH \"${arch}\"" >> config.h
echo "#define CONFIG_SYS_CPU \"${cpu}\"" >> config.h
echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h
[ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h
[ "${soc}" ] && echo "#define CONFIG_SYS_SOC \"${soc}\"" >> config.h
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/${CONFIG_NAME}.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
EOF
上面的代码创建了两个文件config.mk和include/config.h
config.mk:
ARCH = arm
CPU = armv7
BOARD = goni
VENDOR = samsung
SOC = s5pc1xx
include/config.h:
/* Automatically generated - do not edit */
#define CONFIG_SYS_ARCH "arm"
#define CONFIG_SYS_CPU "armv7"
#define CONFIG_SYS_BOARD "goni"
#define CONFIG_SYS_VENDOR "samsung"
#define CONFIG_SYS_SOC "s5pc1xx"
#define CONFIG_BOARDDIR board/samsung/goni
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/s5p_goni.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
四、删除uboot中的无关文件夹
uboot的可移植性建立在其支持很多开发板,也就是说其针对不同的开发板有专门特有的文件夹。具体的针对性主要体现在arch与board文件夹下,前者针对不同的cpu架构,后者针对不同的开发板。
Makefile中主要通过CPUDIR=arch/$(ARCH)/cpu/$(CPU)与SOC=s5pc1xx VENDOR=samsung BOARD=goni这几个变量来指导进入哪个文件夹下进行编译。以此为指导依据可以删除不必要的文件夹。最终保留如下:
arch文件夹中只保留arm文件夹;arm/cpu下面只保留armv7文件夹;arm/cpu/armv7文件夹下保留s5pc1XX与s5p-common文件夹;board文件夹下保留samsung文件夹;board/samsung文件夹下保留common与goni文件夹。
以上是移植的第一个阶段,裁剪后执行配置编译,此时得到的u-boot.bin肯定不能启动我们自己的开发板,这一步只是先使裁剪后的整个uboot先编译通过。