[IMX6Q]u-boot_v2009.08编译过程


先看如何使用,然后以此为入口。

写一个脚本,这里以mx6q_sabreauto_config为例。

#!/bin/bash
export ARCH=arm
export CROSS_COMPILE=<path to cross compiler prefix> 
make distclean;
make mx6q_sabreauto_config
make

然后编译:$./build_u-boot.sh就可以生成u-boot.bin了。

我们看其顶层Makefile:

mx6q_sabreauto_config    : unconfig
	@$(MKCONFIG) $(@:_config=) arm arm_cortexa8 mx6q_sabreauto freescale mx6

@$(MKCONFIG) 为当前目录下的mkconfig脚本。
$(@:_config=)会过滤掉_config后缀,最终mx6q_sabreauto

来看mkconfig:

#!/bin/sh -e

# Script to create header files and links to configure
# U-Boot for a specific board.
#
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
#
# (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <[email protected]>
#
APPEND=no	# Default: Create new config file
BOARD_NAME=""	# Name to print in make output

/*注意脚本这行注释 
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
看名字大概知道意思了!*/

/*
$1: mx6q_sabreauto
$2: arm
$3: arm_cortexa8
$4: mx6q_sabreauto
$5: freescale
$6: mx6
*/

while [ $# -gt 0 ] ; do
	case "$1" in
	--) shift ; break ;;
	-a) shift ; APPEND=yes ;;
	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
	*)  break ;;
	esac
done


/*BOARD_NAME=mx6q_sabreauto*/
[ "${BOARD_NAME}" ] || BOARD_NAME="$1"

[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1

echo "Configuring for ${BOARD_NAME} board..."

#
# Create link to architecture specific headers
#
/*默认两个tree路径一样*/
if [ "$SRCTREE" != "$OBJTREE" ] ; then
	mkdir -p ${OBJTREE}/include
	mkdir -p ${OBJTREE}/include2
	cd ${OBJTREE}/include2
	rm -f asm
	ln -s ${SRCTREE}/include/asm-$2 asm
	LNPREFIX="../../include2/asm/"
	cd ../include
	rm -rf asm-$2
	rm -f asm
	mkdir asm-$2
	ln -s asm-$2 asm
else
	cd ./include
	/*删除原来的,根据架构名字重新链接*/
	rm -f asm
	ln -s asm-$2 asm
fi

/*删除架构下对应的arch*/
rm -f asm-$2/arch

/*ln -s ${LNPREFIX}arch-mx6 asm-arm/arch */
if [ -z "$6" -o "$6" = "NULL" ] ; then
	ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
	ln -s ${LNPREFIX}arch-$6 asm-$2/arch
fi

/*proc对应的是proc-armv目录*/
if [ "$2" = "arm" ] ; then
	rm -f asm-$2/proc
	ln -s ${LNPREFIX}proc-armv asm-$2/proc
fi

#
# Create include file for Make
#
/*保存到config.mk*/
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

#
# 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
/*#include <configs/$mx6q_sabreauto.h>*/
echo "#include <configs/$1.h>" >>config.h
echo "#include <asm/config.h>" >>config.h

exit 0
回到Makefile:

# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk
export	ARCH CPU BOARD VENDOR SOC
包含了刚才生成的config.mk文件。

# load other configuration
include $(TOPDIR)/config.mk
包含顶层config.mk,看它做了什么。
sinclude $(OBJTREE)/include/autoconf.mk

ifdef	ARCH
sinclude $(TOPDIR)/lib_$(ARCH)/config.mk	# include architecture dependend rules
endif
ifdef	CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk		# include  CPU	specific rules
endif
ifdef	SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk	# include  SoC	specific rules
endif
ifdef	VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef	BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk	# include board specific rules
endif

包含cpu, board等目录下的config.mk。
$(TOPDIR)/board/$(BOARDDIR)/config.mk
里有包含了u-boot.lds

LDSCRIPT := $(SRCTREE)/board/$(VENDOR)/$(BOARD)/u-boot.lds
ENTRY(_start)
SECTIONS
{
	. = 0x00000000;

	. = ALIGN(4);
	.text	   :
	{
	  /* WARNING - the following is hand-optimized to fit within	*/
	  /* the sector layout of our flash chips!	XXX FIXME XXX	*/
	  board/freescale/mx6q_sabreauto/flash_header.o	(.text.flasheader)
	  cpu/arm_cortexa8/start.o
	  board/freescale/mx6q_sabreauto/libmx6q_sabreauto.a	(.text)
	  lib_arm/libarm.a		(.text)
	  net/libnet.a			(.text)
	  drivers/mtd/libmtd.a		(.text)
	  drivers/mmc/libmmc.a		(.text)

	  . = DEFINED(env_offset) ? env_offset : .;
	  common/env_embedded.o(.text)

	  *(.text)
	}
......
}

说明第一个运行的文件start.S, 回到Makefile:
OBJS  = cpu/$(CPU)/start.o

确实被编译进去了,download到板子之后就可以开启u-boot之旅了!


refer to :

http://www.360doc.com/content/12/0816/10/7775902_230452499.shtml

你可能感兴趣的:([IMX6Q]u-boot_v2009.08编译过程)