Uboot 1.3.4 learning notes uboot configuration process

Keywords: Makefile less REST C

/mkconfig file analysis:

Six important parameters of mkconfig script:
Configure in the main makefile file:

x210_sd_config :	unconfig
#$(@:_ config =) for the target_ config is replaced by "" to get x210_sd
	@$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110
	#Output TEXT_BASE variable value to.. / x210/config.mk
	@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/x210/config.mk
  1. The above code determines six parameters of the mkconfig script
    $1: x210_sd
    $2: arm
    $3: s5pc11x
    $4: x210
    $5: samsumg
    $6: s5pc110

So $Chen: s5pc110

Next, analyze the mkconfig file as a comment:

Lines 11-21:

APPEND=no	# Default: Create new config file
BOARD_NAME=""	# Name to print in make output

while [ $# -gt 0 ] ; do   # $#=6. True in square brackets
	case "$1" in          # $1 is x21_sd
	--) shift ; break ;;
	-a) shift ; APPEND=yes ;;
	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
	*)  break ;;          #Jump out of while
done                      #So I didn't do anything

Lines 23-28:

[ "${BOARD_NAME}" ] || BOARD_NAME="$1"       #BOARD_NAME is empty, the previous does not hold, so give BOARD_NAME is assigned to x21_sd

[ $# -lt 4 ] && exit 1          #If $#Less than 4, exit
[ $# -gt 6 ] && exit 1          #If $#Greater than 6, exit

echo "Configuring for ${BOARD_NAME} board..."   #Print this, we execute make x210_ Sd_ This sentence is printed in config

Lines 33-118:

Are creating symbolic links:

Lines 33-57:

if [ "$SRCTREE" != "$OBJTREE" ] ; then        #This is the second way to compile. The source file is different from the target file. Some folders will be created and some files will be cleaned up
	mkdir -p ${OBJTREE}/include
	mkdir -p ${OBJTREE}/include2
	cd ${OBJTREE}/include2
	rm -f asm
	ln -s ${SRCTREE}/include/asm-$2 asm
	cd ../include
	rm -rf asm-$2
	rm -f asm
	mkdir asm-$2
	ln -s asm-$2 asm
else                                        #This is the first method (default) compilation,
	cd ./include                            #Jump to. / include directory. The following operations are performed in this directory. The following.. all represent include
	rm -f asm                               #Delete asm
	ln -s asm-$2 asm                        #Create a symlink asm file to point to asm arm 1. The first symlink
rm -f asm-$2/arch                           #Delete arch file (folder) under ASM arm
if [ -z "$6" -o "$6" = "NULL" ] ; then      #$6 is empty or $6="NULL" condition is not valid
	ln -s ${LNPREFIX}arch-$3 asm-$2/arch
	ln -s ${LNPREFIX}arch-$6 asm-$2/arch    #Create the link file.. / ASM arm / arch to.. / ASM arm / arch-s5pc110,
fi											#This file needs to be deleted. It may be patched. 2. The second symbolic link

83-89 lines: find the corresponding SOC part, and other lines are ignored by conditional compilation:

# create link for s5pc11x SoC         #Find the corresponding SOC, and the others are removed by conditional compilation
if [ "$3" = "s5pc11x" ] ; then        
        rm -f regs.h                  #Remove regs.h
        ln -s $6.h regs.h             #Create symbolic link regs.h points to.. / s5pc110. H 3. The third symbolic link
        rm -f asm-$2/arch			  #Delete the second symbolic link
        ln -s arch-$3 asm-$2/arch     #Re create an arch file under inlcude / ASM arm, point to include / ASM arm / arch-s5pc11x 2. Re create the second symbolic link

Line 107-110:

if [ "$2" = "arm" ] ; then                 #Conditions established
	rm -f asm-$2/proc                      #Remove.. / ASM arm / proc
	ln -s ${LNPREFIX}proc-armv asm-$2/proc #Create a proc file under inlcude / ASM arm and point to the 4th symbolic link of include / ASM arm / proc armv 4


  1. The first one is to create an asm file in the include directory, pointing to asm arm. (lines 46-48)

  2. Second: create an arch file under inlcude / ASM arm, point to include / ASM arm / arch-s5pc110

  3. Third, create the regs.h file in the include directory and point to include/s5pc110.h
    Delete the second.

  4. Fourth: create an arch file under inlcude / ASM arm, point to include / ASM arm / arch-s5pc11x
    Fifth: create a proc file under include / ASM arm, point to include / ASM arm / proc armv

  5. A total of 4 symbolic links have been created. These four symbolic links will be very useful when the header file is included in the code writing process in the future. If a header file contains, it may be: "include < ASM / XX. H >, that is, it represents ASM arm / XX. H"

Lines 121-143:

# Create include file for Make          
echo "ARCH   = $2" >  config.mk         #Create include/config.mk File, output arch = arm
echo "CPU    = $3" >> config.mk         #Additional output CPU= s5pc11x
echo "BOARD  = $4" >> config.mk         #Append output BOARD = x210

[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk #Append output vendor = Samsung

[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk #The five parameters SOC = s5pc110 are added to guide the compilation

# Create board specific header file                  #Create header file for development board
if [ "$APPEND" = "yes" ]	# Append to existing config file
	echo >> config.h
	> config.h		# Create new config file       #Create config.h
echo "/* Automatically generated - do not edit */" >>config.h  #Add these two sentences
echo "#include <configs/$1.h>" >>config.h

exit 0


  1. Create include/config.mk file
    /include/ config.mk The contents are as follows:
ARCH   = arm
CPU    = s5pc11x
BOARD  = x210
VENDOR = samsung
SOC    = s5pc110
  1. Create include/config.mk The file is for the main Makefile to be included on line 133
  2. The configuration of uboot and the coordination of compilation process. During compilation, ARCH=arm, CPU=xx and other variables are required to guide compilation. During configuration, these variables are provided for compilation phase
  3. Create (default mode) / append (in the second compilation mode) the include/config.h file, whose contents are as follows:
/* Automatically generated - do not edit */
#include <configs/x210_sd.h>

1) . the content in this file is one line, including < configs / x210_ SD. H >, this header file is the macro definition configuration file for the development board when we migrate the x210 development board. This file is the main file when we migrate x210
2). x210_ The SD. H file will be used to generate a autoconfig.mk File, which will be introduced by the main Makefile to guide the entire compilation process. These macro definitions will affect our selection of conditional compilation in most. c files of uboot. For ultimate portability

matters needing attention:

  1. During the whole configuration process of uboot, many files are related (sometimes this file is created in that file; sometimes this file is included in that file; sometimes this file is determined by the content of that file)
  2. During the process of configuration and compilation in uboot, all files or global variables are in the form of strings (not referring to the concept of C language string, but referring to the sequence of characters). This means that the whole process of uboot configuration is string matching, so we must pay attention to details, case, and do not enter wrong characters. Once there is an error, it is difficult to troubleshoot.

Link script for UBOOT:


OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
ENTRY(_start)   #Specify program entry address
	. = 0x00000000;  #Link address

	. = ALIGN(4);  #4-byte alignment
	.text      :  #Code snippet
	  cpu/s5pc11x/start.o	(.text)           #Code snippet sorting
	  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)                 #Leave the rest at will

	. = ALIGN(4);
	.rodata : { *(.rodata) }    #Read only data segment

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

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

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

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

	. = ALIGN(4);
	__bss_start = .;
	.bss : { *(.bss) }             #bss segment
	_end = .;

  1. ENTRY(_start) is used to specify the entry address of the entire program. The so-called entry address is the beginning address of the whole program, which can be considered as the first instruction of the whole program. It's a bit like main in C.
  2. There are two ways to specify the link address of the program: one is to specify the flags of ld in the Makefile with - Ttext 0x20000000; the other is to specify the links with. = 0x20000000 at the beginning of the SECTIONS of the link script. Both can achieve the same effect. In fact, these two techniques can be used together, that is to say, they can be specified both in the link script and in the ld flags with - Ttext. When both are specified, the one specified by - Ttext shall prevail.
  3. The final link starting address of uboot is specified in makefile with - Ttext. Note that TEXT_BASE variable. The final source is to configure the corresponding command in Makefile, in make xxx_config.
  4. Note the order in which the files are arranged in the code snippet. The files that must be placed in the previous section are those that must be arranged in the first 16 KB, and the functions in these files will be called in the first 16 KB. In the latter second parts (after 16KB), the programs invoked are indifferent.
  5. In addition to the. Text. Data. Rodata. BSS section and other sections of the compiler in the link script, the compiler also allows us to customize the sections. For example, the total. U of uboot_ boot_ The CMD segment is a custom segment. The custom segment is very important. We will analyze it later.

Posted by jtapoling on Fri, 19 Jun 2020 22:28:33 -0700