U-boot(二):主Makefile

本文主要探讨210的主Makefile。

Makefile

uboot版本号:

VERSION:主板本号

PATCHLEVEL:次版本号

SUBLEVEL:再次版本号

EXTRAVERSION:附加信息

VERSION = 1
PATCHLEVEL = 3
SUBLEVEL = 4
EXTRAVERSION =
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_FILE = $(obj)include/version_autogenerated.h

root@kaxi-virtual-machine:~/qt_x210v3s_160307/uboot# cat include/version_autogenerated.h 
#define U_BOOT_VERSION "U-Boot 1.3.4"

宿主机参数

HOSTARCH:宿主机架构

HOSTOS:宿主机系统

HOSTARCH := $(shell uname -m | \
        sed -e s/i.86/i386/ \
            -e s/sun4u/sparc64/ \
            -e s/arm.*/arm/ \
            -e s/sa110/arm/ \
            -e s/powerpc/ppc/ \
            -e s/ppc64/ppc/ \
            -e s/macppc/ppc/)

HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
            sed -e 's/\(cygwin\).*/cygwin/')

export  HOSTARCH HOSTOS

静默编译

make -s

# Allow for silent builds
ifeq (,$(findstring s,$(MAKEFLAGS)))
XECHO = echo
else
XECHO = :
endif

指定编译结果路径

O参数(优先级高)

        make O=/tmp/build distclean
        make O=/tmp/build NAME_config
        make O=/tmp/build all

设置环境变量

        export BUILD_DIR=/tmp/build
        make distclean
        make NAME_config
        make all

OBJTREE:默认当前目录,O参数可指定输出目录

SRCTREE: 源码目录(uboot一级目录)

ifdef O
ifeq ("$(origin O)", "command line")
BUILD_DIR := $(O)
endif
endif

ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)

# Attempt to create a output directory.
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})

# Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)

OBJTREE         := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE         := $(CURDIR)
TOPDIR          := $(SRCTREE)
LNDIR           := $(OBJTREE)
export  TOPDIR SRCTREE OBJTREE

MKCONFIG        := $(SRCTREE)/mkconfig
export MKCONFIG

ifneq ($(OBJTREE),$(SRCTREE))
REMOTE_BUILD    := 1
export REMOTE_BUILD
endif

# $(obj) and (src) are defined in config.mk but here in main Makefile
# we also need them before config.mk is included which is the case for
# some targets like unconfig, clean, clobber, distclean, etc.
ifneq ($(OBJTREE),$(SRCTREE))
obj := $(OBJTREE)/
src := $(SRCTREE)/
else
obj :=
src :=
endif
export obj src

# Make sure CDPATH settings don't interfere
unexport CDPATH

开发板配置

ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk))

# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk
export  ARCH CPU BOARD VENDOR SOC

make x210_sd_config(调用mkconfig脚本) ==> include/config.mk

x210_nand_config :      unconfig
        @$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
        @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk

root@kaxi-virtual-machine:~/qt_x210v3s_160307/uboot# cat include/config.mk
ARCH   = arm
CPU    = s5pc11x
BOARD  = x210
VENDOR = samsung
SOC    = s5pc110

编译工具链

CROSS_COMPILE:工具链(可外部定义:路径(/usr/local/arm/arm-2009q3/bin/)+工具链标签(arm-none-linux-gnueabi-))

$(TOPDIR)/config.mk(94-107定义完整工具链:路径+工具链标签+gcc)

#
# Include the make variables (CC, etc...)
#
AS      = $(CROSS_COMPILE)as
LD      = $(CROSS_COMPILE)ld
CC      = $(CROSS_COMPILE)gcc
CPP     = $(CC) -E
AR      = $(CROSS_COMPILE)ar
NM      = $(CROSS_COMPILE)nm
LDR     = $(CROSS_COMPILE)ldr
STRIP   = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB  = $(CROSS_COMPILE)RANLIB

Makefile(291)开始编译目标

unconfig目标可多次配置

x210_nand_config :      unconfig
        @$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
        @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk

解析config.mk

$(TOPDIR)/config.mk(uboot/config.mk)

加载宏(开发板配置)(112)

# Load generated board configuration
sinclude $(OBJTREE)/include/autoconf.mk

文件指导uboot编译过程,包含CONFIG_xxx宏它由源码目录inlcude/configs/xxx.h头文件生成(其他开发板)

210使用include/configs/x210_sd.h

加载链接脚本(142-149,board/samsung/x210/u-boot.lds)

ifndef LDSCRIPT
#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
ifeq ($(CONFIG_NAND_U_BOOT),y)
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
else
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
endif

定义链接脚本地址(156-158,board/samsung/x210/config.mk)

ifneq ($(TEXT_BASE),)
CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
endif

root@kaxi-virtual-machine:~/qt_x210v3s_160307/uboot# cat board/samsung/x210/config.mk
TEXT_BASE = 0xc3e00000

TEXT_BASE是uboot链接地址由于启用虚拟地址映射,C3E00000地址等于0x23E00000

自动推导规则(239-256)

ifndef REMOTE_BUILD

%.s:    %.S
        $(CPP) $(AFLAGS) -o $@ $<
%.o:    %.S
        $(CC) $(AFLAGS) -c -o $@ $<
%.o:    %.c
        $(CC) $(CFLAGS) -c -o $@ $<

else

$(obj)%.s:      %.S
        $(CPP) $(AFLAGS) -o $@ $<
$(obj)%.o:      %.S
        $(CC) $(AFLAGS) -c -o $@ $<
$(obj)%.o:      %.c
        $(CC) $(CFLAGS) -c -o $@ $<
endif

解析mkconfig(uboot/mkconfig)

x210_nand_config :      unconfig
        @$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
        @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk

6个参数 :$(@:_config=) arm s5pc11x x210 samsung s5pc110

$1: x210_sd

$2: arm

$3: s5pc11x

$4: x210

$5: samsumg

$6: s5pc110

$# = 6

BOARD_NAME=x210_sd

创建符号链接(33-118,便于移植)

uboot/include:asm -> asm-arm

uboot/inlcude/asm-arm:arch->arch-s5pc11x

uboot/include:regs.h->s5pc110.h

uboot/include/asm-arm:proc->proc-armv

创建include/config.mk文件用于主Makefile配置开发板(123-129)

#
# Create include file for Make
#
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

默认追加#include <configs/x210_sd.h>(开发板配置宏)到include/config.h(134-141)

...

APPEND=no       # Default: Create new config file

...

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

链接脚本(uboot/board/samsung/x210/u-boot.lds)

ENTRY(_start)程序入口地址

指定链接地址:-Ttext 0x00000000;(优先级高),链接脚本SECTIONS中定义. = 0x00000000

uboot链接地址用-Ttext指定(make x210_sd_config ==> uboot/board/samsung/x210/config.mk(定义TEXT_BASE))

链接脚本*(.text)前部分为前16KB(基础的初始化)其余为16KB之后,便于烧录,

链接脚本除.text .data .rodata .bss段还有自定义段(.u_boot_cmd)

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
        . = 0x00000000;

        . = ALIGN(4);
        .text      :
        {
          cpu/s5pc11x/start.o   (.text)
          cpu/s5pc11x/s5pc110/cpu_init.o        (.text)
          board/samsung/x210/lowlevel_init.o    (.text)
          cpu/s5pc11x/onenand_cp.o      (.text)                 
          cpu/s5pc11x/nand_cp.o (.text)                     
          cpu/s5pc11x/movi.o (.text) 
          common/secure_boot.o (.text) 
          common/ace_sha1.o (.text)
          cpu/s5pc11x/pmic.o (.text)
          *(.text)
        }

        . = ALIGN(4);
        .rodata : { *(.rodata) }

        . = ALIGN(4);
        .data : { *(.data) }

        . = ALIGN(4);
        .got : { *(.got) }

        __u_boot_cmd_start = .;
        .u_boot_cmd : { *(.u_boot_cmd) }
        __u_boot_cmd_end = .;

        . = ALIGN(4);
        .mmudata : { *(.mmudata) }

        . = ALIGN(4);
        __bss_start = .;
        .bss : { *(.bss) }
        _end = .;
}
相关推荐
hairenjing11235 小时前
使用 Mac 数据恢复从 iPhoto 图库中恢复照片
windows·stm32·嵌入式硬件·macos·word
xiaozhiwise5 小时前
ARM base instruction -- ccmp (immediate)
汇编
模拟IC攻城狮6 小时前
华为海思招聘-芯片与器件设计工程师-模拟芯片方向- 机试题-真题套题题目——共8套(每套四十题)
嵌入式硬件·华为·硬件架构·芯片
IT B业生6 小时前
51单片机教程(六)- LED流水灯
单片机·嵌入式硬件·51单片机
一枝小雨7 小时前
51单片机学习心得2(基于STC89C52):串口通信(UART)
单片机·嵌入式硬件·51单片机
IT B业生8 小时前
51单片机教程(一)- 开发环境搭建
单片机·嵌入式硬件·51单片机
好想有猫猫10 小时前
【51单片机】串口通信原理 + 使用
c语言·单片机·嵌入式硬件·51单片机·1024程序员节
云卓科技10 小时前
无人车之路径规划篇
人工智能·嵌入式硬件·算法·自动驾驶
stm 学习ing11 小时前
C语言 循环高级
c语言·开发语言·单片机·嵌入式硬件·算法·嵌入式实时数据库
w微信1501350781212 小时前
小华一级 代理商 HC32F005C6PA-TSSOP20 HC32F005系列
c语言·arm开发·单片机·嵌入式硬件