U-Boot Hacking 1
时间:2007-02-08 来源:jarodwang
最近又在试着将U-Boot移植到一个硬件配置类似于smdk2410的开发板(深圳优龙ST2410)上,但尚未成功。但对于U-Boot的又有了新的认识,记录于此。
本文以u-boot-1.1.4为例进行分析,其源代码可以在ftp://ftp.denx.de/pub/u-boot/处下载。U-Boot的配置以make smdk2410_config为例,交叉编译工具链使用cross-2.95.3。
首先来看看在u-boot-1.1.4目录下make smdk2410_config命令的执行过程。Makefile第1506行开始处有:
[code]
smdk2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
[/code]
而unconfig依赖的内容出现在Makefile的第210行:
[code]
unconfig :
@rm -f include/config.h include/config.mk board/*/config.tmp
[/code]
可以看到unconfig中的命令内容是强制删除上次配置过程中生成的一些配置文件。 我们再回到smdk2410_config中来,它所执行的命令则是u-boot-1.1.4/mkconfig这个shell脚本,并给这个脚本传递了6个参数,依次是smdk2410, arm, arm920t, smdk2410, NULL和s3c24x0。查看mkconfig脚本的内容,第6行的注释给出了这些参数的意义:Target Architecture CPU Board [VENDOR] [SOC],并且可以看出最后两个参数的值可以是NULL。
第24行会使得终端命令行显示“Configuring for smdk2410 board...”:
[code]
echo "Configuring for $1 board..."
[/code]
第26行使得当前工作目录转换到u-boot-1.1.4/include目录:
[code]
cd ./include
[/code]
第31行到第44行的代码用于建立针对特定体系结构的头文件目录的符号链接:
[code]
rm -f asm
ln -s asm-$2 asm
rm -f asm-$2/arch if [ -z "$6" -o "$6" = "NULL" ] ; then
ln -s arch-$3 asm-$2/arch
else
ln -s arch-$6 asm-$2/arch
fi if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc
ln -s proc-armv asm-$2/proc
fi
[/code]
以上这段代码执行完毕之后将建立的符号链接有:
include/asm -> include/asm-arm
include/asm-arm/arch -> include/asm-arm/arch-s3c24x0
include/asm-arm/proc -> include/asm-arm/proc-armv
接下来的第49行到第55行的代码利用echo命令生成include/config.mk文件并使用传递的6个参数来填充其中的内容:
[code]
echo "ARCH = $2" > config.mk
echo "CPU = $3" >> config.mk
echo "BOARD = $4" >> config.mk [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
[/code]
最后的第60行到第67行的代码同样利用了echo命令来生成include/config.h文件:
[code]
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
echo "#include <configs/$1.h>" >>config.h
[/code]
[code]
smdk2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
[/code]
而unconfig依赖的内容出现在Makefile的第210行:
[code]
unconfig :
@rm -f include/config.h include/config.mk board/*/config.tmp
[/code]
可以看到unconfig中的命令内容是强制删除上次配置过程中生成的一些配置文件。 我们再回到smdk2410_config中来,它所执行的命令则是u-boot-1.1.4/mkconfig这个shell脚本,并给这个脚本传递了6个参数,依次是smdk2410, arm, arm920t, smdk2410, NULL和s3c24x0。查看mkconfig脚本的内容,第6行的注释给出了这些参数的意义:Target Architecture CPU Board [VENDOR] [SOC],并且可以看出最后两个参数的值可以是NULL。
第24行会使得终端命令行显示“Configuring for smdk2410 board...”:
[code]
echo "Configuring for $1 board..."
[/code]
第26行使得当前工作目录转换到u-boot-1.1.4/include目录:
[code]
cd ./include
[/code]
第31行到第44行的代码用于建立针对特定体系结构的头文件目录的符号链接:
[code]
rm -f asm
ln -s asm-$2 asm
rm -f asm-$2/arch if [ -z "$6" -o "$6" = "NULL" ] ; then
ln -s arch-$3 asm-$2/arch
else
ln -s arch-$6 asm-$2/arch
fi if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc
ln -s proc-armv asm-$2/proc
fi
[/code]
以上这段代码执行完毕之后将建立的符号链接有:
include/asm -> include/asm-arm
include/asm-arm/arch -> include/asm-arm/arch-s3c24x0
include/asm-arm/proc -> include/asm-arm/proc-armv
接下来的第49行到第55行的代码利用echo命令生成include/config.mk文件并使用传递的6个参数来填充其中的内容:
[code]
echo "ARCH = $2" > config.mk
echo "CPU = $3" >> config.mk
echo "BOARD = $4" >> config.mk [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
[/code]
最后的第60行到第67行的代码同样利用了echo命令来生成include/config.h文件:
[code]
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
echo "#include <configs/$1.h>" >>config.h
[/code]
相关阅读 更多 +