当前位置: 首页 > article >正文

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 = .;
}


http://www.kler.cn/a/132379.html

相关文章:

  • macOS 的目录结构
  • 博客文章怎么设计分类与标签
  • 编程语言02:语法基础
  • HTML and CSS Support HTML 和 CSS 支持
  • 智谱AI清影升级:引领AI视频进入音效新时代
  • 计算机前沿技术-人工智能算法-大语言模型-最新研究进展-2024-11-04
  • 大型且复杂项目的资源管理怎么做?
  • 模拟实现一个Linux中的简单版shell
  • 6.docker运行mysql容器-理解容器数据卷
  • 邀请报名|11月24日阿里云原生 Serverless 技术实践营 深圳站
  • 概率论和数理统计(四)方差分析与回归分析
  • Windows10下Mysql8.0安装教程
  • 圆弧插补-逐点比较法
  • 【机器学习Python实战】线性回归
  • 计算机视觉的应用16-基于pytorch框架搭建的注意力机制,在汽车品牌与型号分类识别的应用
  • 力扣:168. Excel表列名称(Python3)
  • Qt退出界面
  • 微信小程序Error: ENOENT: no such file
  • Django学习日志04
  • py 动态输入参数
  • 什么是跨境电子商务综合试验区?成为综试区有何好处?
  • 现货黄金职业交易员怎么使用技术分析?
  • 【数据结构 | 链表】leetcode 2. 两数相加
  • Os-ByteSec
  • Oracle 存储过程数据插入临时表慢以及SQL语句查询慢
  • 【第2章 Node.js基础】2.7 Node.js 的流(一)可写流