1_5.1.2_U-boot analysis and use_u-boot analysis Makefile structure analysis_P

Publisher:lxy64420245Latest update time:2021-08-19 Source: eefocusKeywords:U-boot Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When we analyze a file, the best way is to look at its makefile.


When we experienced compiling uboot before, our first step was to configure uboot and the second step was to compile.


Analyze and configure uboot instructions

The command used to configure uboot is make 100ask24x0_config.


First find the Makefile, open it with vim, search for 100ask24x0_config, and locate it as follows:

insert image description here

Then make 100ask24x0_config actually executes the @$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0 instruction. The following is an analysis of this instruction.


The @ symbol on the far left indicates that the command will not be displayed in the terminal when it is executed. Then there is a variable MKCONFIG. Find the definition of this variable and you can see that it points to the mkconfig file in the current directory. (The CURDIR variable is a built-in variable of the makefile, which indicates the current directory)

insert image description here

Then the @ symbol in $(@:_config=) represents the target file, and (@:_config=) replaces the _config in the target file name with nothing. Here, 100askx0_config is replaced with 100ask24x0.


So @$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0 instruction is actually

@./mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0.

insert image description here

The following parses the @mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0 instruction.

insert image description here

Open the mkconfig file and start analyzing it from top to bottom.


Here, "$#" represents the number of all parameters (PS: "$@" represents all parameters), and -gt means greater than 0 (greater than), so this while loop means that if the number of parameters is greater than 0, then do is executed. If the first variable conforms to which format, then the corresponding operation is performed. Here, $1 is 100ask24x0, so a direct break does not perform any operation and exits directly.


-gt means greater than.

-eq means equal.

-ne means not equal.

-ge means greater than or equal to (greater equal).

-lt means less than.

-le means less than or equal to (less equal).

insert image description here

The instruction flow of this instruction is left side first, if the left side is established, the subsequent operations will not be executed.


At the beginning of the file, BOARD_NAME is set to "", so the following operation will be executed here, setting BOARD_NAME to $1, which is 100ask24x0.

insert image description here

So after executing this instruction, BOARD_NAME = "100ask24x0".

insert image description here

Then determine whether the number of parameters is less than 4. If so, exit. If greater than 6, also exit.

insert image description here

Then output a message on the interrupt.

insert image description here
insert image description here

Determine whether SRCTREE and OBJTREE are equal.

insert image description here

View Makefile, SRCTREE is the current directory.

insert image description here

OBJTREE is equal to $(BUILD_DIR) if BUILD_DIR is defined, otherwise it is equal to $(CURDIR).

insert image description here

Check BUILD_DIR. There is no definition of o, so BUILD_DIR is not defined either, and OBJTREE is also the current directory.

insert image description here

So SRCTREE == OBJTREE, then execute the else operation. Switch to the include folder in the current directory, delete the asm folder, and link asm-arm to asm, that is, in the future, when executing asm, it will be replaced by executing asm-arm. (ln is the link instruction, -s means to create a symbolic link, which is a soft link, similar to the shortcut in the Windows system, the command format is ln -s source file name soft link file name)

insert image description here
insert image description here

Why do we need to link like this? This is because when compiling MCUs of different architectures, the asm used is different.


For example, if there is a line of instruction #include , then the type.h file in the asm-arm folder should be called in the arm architecture, and the type.h file in the asm-i386 folder should be called in the i386 architecture. When using MCUs of different architectures, you need to call files of different architectures. Using such soft links, you can easily compile files of different architectures.


Next, delete the asm-arm/arch folder.

insert image description here

Then, -z means true if the length is 0, that is, true if the string is empty. Here $6 is s3c24x0, so the else operation is executed.


Looking at the makefile, LNPREFIX is empty, so ln -s ${LNPREFIX}arch-$6 asm-$2/arch is ln -s arch-s3c24x0 asm-arm/arch.


That is to create a link and point asm-arm/arch to arch-s3c24x0.

insert image description here
insert image description here

Next is similar, $2 = arm, so delete the asm-arm/proc folder and create a link from asm-arm/proc to proc-armv.

insert image description here

Then create a config.mk file. The first line of the file is ARCH = arm, the second line is CPU = arm920t, the third line is BOARD = 100ask24x0, and the fourth line is SOC = s3c24x0.


Among them, > means creating a file, and >> means adding some information to the end of the file.

insert image description here
insert image description here

APPEND defaults to no, so create a config.h file and add the relevant two lines to it.

insert image description here
insert image description here
insert image description here

It can be seen that the main operation of configuration is to set relevant variables and include the required files.


Analyze and compile uboot instructions

The command used to compile uboot is: make


Open the makefile and look from top to bottom. You can see that it contains the config.mk file generated by make 100ask24x0_config. This code links the two instructions together.

insert image description here
insert image description here

Then the cpu/arm920t/start.o file is included. This file is compiled from the start.S file. This file is transferred back to the local computer and will be used when analyzing the source code. Note the instructions in the comments. The order of the obj files cannot be changed at will, and the start file must be placed first.

insert image description here

Looking further down, you can find that there are many .a files. .a files are static library files. These library files are compiled and packaged into libraries, and then called during compilation.


LIBS += board/( BOARDDIR ) / lib (BOARDDIR)/lib(BOARDDIR)/lib(BOARD).a is LIBS += board/100ask24x0/lib100ask24x0.a.


LIBS += cpu/(CPU)/lib (CPU)/lib(CPU)/lib(CPU).a is LIBS += cpu/arm920t/libarm920t.a.

insert image description here
insert image description here
insert image description here

Then there is all. When we use the make command without adding any parameters, the makefile will take the first target in the file as a parameter, which is usually all. Here we mainly want to generate the u-boot.bin file.

insert image description here

u-boot.bin depends on u-boot. The u-boot here is in elf format, and the target u-boot is binary.

insert image description here

You can see that u-boot depends on many files. You can directly expand to analyze the statement, or you can execute the make command. There should be expansion of these instructions at the end of the compilation.

insert image description here

As you can see, at the end of compilation there is the following expansion.

insert image description here

Through this instruction, you can see the link script specified by makefile, the base address of the code segment used, and the file location distribution of the generated u-boot. The start.o file should be at the front.

insert image description here

Open the u-boot.lds link script, and then analyze u-boot from start.S, which is an assembly file.

insert image description here

Analyzing the compilation process: make, we can know:


The first compiled file: cpu/arm920t/start.S

Link script: /home/book/Desktop/test/042_uboot_test/u-boot-1.1.6/board/100ask24x0/u-boot.lds

Link address: 0x0+0x33f80000

How does this 0x33f80000 come from? You can search it by greo "0x33F80000" * -nR.


As you can see, this value is based on the TEXT_BASE variable, which is defined in line 25 of the board/100ask24xc/config.mk file.

The variable is defined in line 25 of the board/100ask24xc/config.mk file.
insert image description here

Check LDFLAGS, grep "LDFLAG" * -nR, a lot of information will appear, read from top to bottom.

insert image description here

You can see that it is defined on line 189 of the config.mk file, which is consistent with the previous debugging information.

insert image description here

board/100ask24c0/config.mk is included, and this file defines TEXT_BASE as 0x33f80000. If you want u-boot to change its location, just modify the TEXT_BASE variable in this file.

insert image description here

Keywords:U-boot Reference address:1_5.1.2_U-boot analysis and use_u-boot analysis Makefile structure analysis_P

Previous article:1_5.1.1_U-boot analysis and use_u-boot analysis compilation experience_P
Next article:1_5.1.3_U-boot analysis and use_u-boot analysis source code stage 1_P

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号