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:
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)
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.
The following parses the @mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0 instruction.
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).
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.
So after executing this instruction, BOARD_NAME = "100ask24x0".
Then determine whether the number of parameters is less than 4. If so, exit. If greater than 6, also exit.
Then output a message on the interrupt.
Determine whether SRCTREE and OBJTREE are equal.
View Makefile, SRCTREE is the current directory.
OBJTREE is equal to $(BUILD_DIR) if BUILD_DIR is defined, otherwise it is equal to $(CURDIR).
Check BUILD_DIR. There is no definition of o, so BUILD_DIR is not defined either, and OBJTREE is also the current directory.
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)
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 Next, delete the asm-arm/arch folder. 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. Next is similar, $2 = arm, so delete the asm-arm/proc folder and create a link from asm-arm/proc to proc-armv. 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. APPEND defaults to no, so create a config.h file and add the relevant two lines to it. 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. 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. 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. 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. u-boot.bin depends on u-boot. The u-boot here is in elf format, and the target u-boot is binary. 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. As you can see, at the end of compilation there is the following expansion. 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. Open the u-boot.lds link script, and then analyze u-boot from start.S, which is an assembly file. 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. Check LDFLAGS, grep "LDFLAG" * -nR, a lot of information will appear, read from top to bottom. You can see that it is defined on line 189 of the config.mk file, which is consistent with the previous debugging information. 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.
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
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Communication between Yitong Chuanglian MODBUS to PROFIBUS gateway and Honeywell DCS system
- Let's take a look
- 【TI Wireless】Micro Dual-Mode Wireless Receiver
- PWM and PFM
- Let’s talk about whether Huawei can survive in the end.
- Can the network cable be directly soldered to the PCB without a crystal plug or can the network cable be plugged into the circuit board with terminals?
- [Revenge RVB2601 creative application development] helloworld_beginner's guide to debugging methods and processes
- What changes will occur if RFID technology is applied to clothing production?
- EEWORLD University Hall----30 Case Studies of MATLAB Intelligent Algorithms
- Flyback Power Supply Magnetic Core Calculation Method