The embedded linux Development uboot transplant （ Two ）——uboot Project source directory analysis
Analyzed in this paper uboot by uboot_smdkv210, It's officially released by Samsung based on S5PV210 Evaluate the development board corresponding to uboot.
One 、uboot Source directory structure analysis
The sub files in this folder are processor related , Each folder represents a CPU series . Each subdirectory contains cpu.c、interrupts.c、start.S file .
cpu.c Mainly used to initialize CPU、 Set command Cache And data Cache etc.
interrupt.c It is mainly used to set various interrupts and exceptions of the system
start.S yes U-boot The first file executed at startup , Mainly do the earliest system initialization , Code redirection and setting up the system stack , To enter U-boot The second stage C Procedures lay the foundation .
S5PV210 The folder corresponding to the chip is s5pc11x.
cpu/s5pc11x/s5pc110/cpu_init.S It is mainly used for SDRAM Memory initialization settings .
The sub files under this document are related to the development board , Each sub file represents a chip manufacturer , Every sub folder stored in the folder of chip manufacturer is a kind of development board , For historical reasons ,board There are still a large number of development board folders in the directory that have not been filed in the folder of the chip manufacturer , Keep compatibility , As a result, the whole is in a mess . Such as samsung Of smdk2400、smdk2410 The development board is located in samsung Out of the folder .
S5PV210 The folder corresponding to the chip is located in board/samsung/smdkc110, In the folder lowlevel_init.S Files are mainly used for clocks 、 A serial port 、MMU、Flash Bottom drive 、 Board level initialization ,u-boot.lds Files are linked script files , It's very important for the link phase in the later stage of project compilation , Determines the assembly of the program .
This folder contains general code unrelated to processor architecture ,uboot Command parsing code for /common/command.c、 The upper level code for all commands cmd_*.c、uboot Environment variable processing code env_*.c、CRC Check, etc. are located in this directory .
All peripheral chip drivers are stored in this directory , network card 、USB、 A serial port 、LCD、Nand Flash etc. .
This directory is stored in the partition processing code of disk drive
This directory stores the code related to the file system , Each subfolder represents a file system .
This directory is stored in the network protocol related code
It is stored in this catalogue uboot Description document .
External extension program API And examples
The header file , Includes a variety of CPU Register definition of , file system 、 Network, etc.
configs The files in the subdirectory are the configuration header files related to the target board
Each folder represents a CPU Architecture . And S5PV210 The related folders are lib_arm、lib_generic,lib_generic The directory holds all the CPU Architecture, general encryption algorithm 、 Compression algorithm 、 Character processing related codes . In each case CPU In the architecture folder board.c, yes uboot Start the second stage of code entry function and related initialization function storage place .
This directory is the number of devices related to the code .
compile S-Record or uboot Image and other related tools , Like making bootm Boot kernel image file tool mkimage Source code .
Power on self check related codes
Nand、onenand Start the relevant code .
This directory is stored in the burning related tool code
17、 Project compilation configuration file
Control the main part of the project compilation process Makefile Files and rule files
config.mk In file TEXT_BASE Specifies the address of the code in memory .
18、 edition 、 Copyright documents
Two 、uboot Project compilation configuration
uboot Project compilation configuration is mainly based on Makefile And sub configuration file configuration information control uboot Compilation process .
1、 Compile command analysis
uboot The compiler commands are make xxxx_config and make
make xxxx_config Configure commands for development board information ,make For compiling commands .make xxx_config in xxx_config The value of is determined by the specific development board , The corresponding configuration information is located in uboot Under the top directory Makefile.
Generally speaking , Samsung S5PV210 The corresponding value of the development board is smdkv210single_config, According to the different development board , You can also choose smdkv210vogue_config、smdkv210single_rev02_config、 smdkv210onenand_config etc. .smdkv210single_config The configuration information of the development board is as follows ：
@$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk
@$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110 The corresponding execution statement of the statement is mkconfig smdkv210single arm s5pc11x smdkc110 samsung s5pc110, According to the input arm s5pc11x smdkc110 samsung s5pc110 Parameters use the mkconfig Script generation include/config.mk Configuration file for .
@echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk Statement is used to create board/samsung/smdkc110/config.mk file , write in TEXT_BASE = 0xc3e00000 Content .
2、mkconfig Script analysis
mkconfig Scripts are used to configure... For a development board uboot Create header files and link files .mkconfig The main parameters of the script are Target Architecture CPU Board [VENDOR] [SOC].S5PV210 The development board execution script is ：mkconfig smdkv210single arm s5pc11x smdkc110 samsung s5pc110
mkconfig The main functions of the script are as follows ：
A、 establish CPU Architecture related link files
By default ,make The command does not specify the output directory , At the top level of the catalog include Create link file under Directory /include/asm Point to /include/asm_arm Catalog
B、 Create link files related to the development board
At the top level of the catalog include Create link file under Directory /include/regs.h Point to the development board include Directory development board header file /include/s5pv110.h
At the top level of the catalog include Under the asm-arm Create link file under Directory arch, Point to include In the catalog arch-s5pc11x Catalog .
C、 Generate include/config.mk file
According to the selected development board , The configuration information of the development board smdkv210single arm s5pc11x smdkc110 samsung s5pc110 As mkconfig Input parameters , And write these parameters as the values of the variables to the created include/config.mk In file ,config.mk The contents of the document are listed below ：
ARCH = arm
CPU = s5pc11x
BOARD = smdkc110
VENDOR = samsung
SOC = s5pc110
D、 Create the header file of the development board configuration
At the top level of the catalog include Create under directory config.h file , Write file contents ：
/* Automatically generated - do not edit */
3、 Development board configuration header file analysis
The development board configuration header file is include/configs/smdkv210single_config.h
smdkv210single_config.h The header file mainly defines two kinds of variables with macro , One is options , use CONFIG_ Make prefixes , Used to select the processor 、 Device interface 、 command 、 Properties, etc . Such as ：
One is parameters , use CFG_ Make prefixes , Used to define the bus frequency 、 Serial port baud rate 、Flash Address and other parameters . Such as ： The main configuration information in the file is ： Memory base address 、 Machine code 、 Starting mode 、 A serial port 、I2C、 Internet Information 、 The system clock 、 Memory parameters, etc .
4、Makefile File analysis
Makefile The main function is to control uboot Compilation process ,Makefile The configuration information in includes the configuration of version information , call mkconfig Script generation configuration information , Cross compile toolchain settings （ Generally, you need to set CROSS_COMPILE = arm-linux-）、 Configure the header file according to the development board information include/configs/smdkv210single.h call config.mk Script generation /include/autoconf.mk Control the compilation process . The codes of the main functions are as follows ：
uboot Version setting options ：
VERSION = 1
PATCHLEVEL = 3
SUBLEVEL = 4
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_FILE = $(obj)include/version_autogenerated.h// Generate automatic files based on configuration options
Cross compiler tool settings ：
# modify CROSS_COMPILE = arm-linux-
CROSS_COMPILE = arm-linux-
#CROSS_COMPILE = /usr/local/arm/4.4.1-eabi-cortex-a8/usr/bin/arm-linux-
#CROSS_COMPILE = /usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-
#CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
Cross compile toolchain configuration 、 After the development board is configured, it can be compiled
This article mainly refers to Samsung smdkv210 The official development board uboot Source code .