-
Host: VMWare--Fedora 9
-
Development board: Mini2440--64MB Nand, Kernel: 2.6.30.4
-
Compiler: arm-linux-gcc-4.3.2.tgz
-
u-boot:u-boot-2009.08.tar.bz2
2. Transplantation Steps
-
Installation, configuration and testing of tftp service;
-
Installation, configuration and testing of nfs service;
-
Parameter passing from u-boot to kernel (key point).
We know that the benefit of using tftp to download the kernel and using nfs to mount the file system is that when we recompile the kernel or file system, we do not need to burn these image files to the flash again. Instead, we put these image files in the main directory of the tftp or nfs service of the development host and load them through the network. We do not need to burn them to the flash frequently. This can protect the service life of the flash and facilitate the debugging of the kernel or file system to improve the development efficiency. It can be seen that it is a very meaningful thing to let u-boot realize this function.
It is very simple to implement such a function, and there is a lot of information on the Internet. However, there are many details that can lead to failure if you don't pay attention to them. Here I will describe the process of my implementation and analyze some problems.
-
Installation, configuration and testing of tftp service
To use the tftp service and test it, you need to install two software packages, one is the tftp server, and the other is the tftp client. The client is installed here only to test whether the tftp server is running normally on the local host to ensure that u-boot can access the tftp service (u-boot already has the function of the tftp client. In fact, tftp has been used in the previous articles to download the kernel or file system to the development board. If you have done it there, you can skip it here).
First, use the rpm command to check whether the tftp server and client have been installed on your host. If not, download the two software packages to install them or use the yum command to install them online. Yum will automatically search for the latest software package suitable for your host platform to download and install. If the host has already installed it, it will prompt that the latest version of the software package has been installed. As shown in the figure below:
Configuring the tftp server mainly involves configuring the home directory and access rights of tftp. Since the tftp service depends on the xinetd service, its configuration files are usually located in the /etc/xinetd.d/ directory after the tftp service is installed:
-
Installation, configuration and testing of nfs service
As root, enter setup in the console and select nfs service in the system service options, as shown below:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032542.png" style="padding:0px;margin:0px;border:0px;" />
When configuring the shared home directory of the NFS server, also pay attention to the permission issue:
-
Parameter passing from u-boot to kernel
We know that there is a Default kernel command string parameter item in the kernel configuration option Boot options, and there is also a bootargs parameter item in the u-boot parameter. They are both used for kernel startup, so what is the difference between them? Which one is used when the kernel is started? The two parameter items are shown in the following figure (the parameters in the kernel specify that the file system is mounted from the Flash partition of the development board, and the parameters in the u-boot specify that the file system is mounted from NFS):
So, how does u-boot pass parameter information to the kernel? And how does the kernel receive the parameters passed by u-boot? This involves a little knowledge of ARM registers.
We know that ARM has 7 working modes and 37 registers (31 general registers and 6 status registers), as shown below:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032545.png" style="padding:0px;margin:0px;border:0px;" />
The conversion between ARM working modes is carried out by using these registers, and the transmission of u-boot parameters also uses three general registers R0, R1 and R2. I will not talk about ARM working modes and registers here, and will talk about them later. Here you can understand that u-boot stores the parameters in these three registers when starting, and then takes out the parameters in the registers when the kernel starts. Of course, they are not so simple operations. Let's look at the code and analyze them one by one.
First, let's analyze how u-boot processes and sends the parameters to be passed, and what are the parameters that u-boot wants to pass? In addition to the most easily known bootargs (kernel commandline) parameter item, the parameters to be passed include MACH_TYPE (what we call machine code), system root device information (flags, page size), memory information (starting address, size), RAMDISK information (starting address, size), and compressed RAMDISK root file system information (starting address, size). It can be seen that there are many parameters to be passed. At this time, u-boot provides a method called parameter linked list (tagged list) to organize these parameters. The linked list structure is defined in: include/asm-arm/setup.h, and the implementation of the linked list organization is in lib_arm/bootm.c:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032546.png" style="padding:0px;margin:0px;border:0px;" />650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032547.png" style="padding:0px;margin:0px;border:0px;" />
We can see that the organization of the linked list is implemented by a series of functions. U-boot stipulates that the linked list must start with the ATAG_CORE tag and end with the ATAG_NONE tag. In the middle are some parameter tag items, which can be reflected in the code. Then in these functions there is a bd parameter which is crucial, it is a bd_info type structure, defined in include/asm-arm/u-boot.h, and this structure is referenced by a global_data type structure, defined in include/asm-arm/global_data.h, as follows:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032548.png" style="padding:0px;margin:0px;border:0px;" />650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/1032549.png" style="padding:0px;margin:0px;border:0px;" />
So, what is the bd parameter used for? From the definition, we can know that bd records the machine code, the address of the u-boot parameter list in the memory and other information. Then, where is it recorded? It is recorded in the initialization code of our own development board, such as: board/samsung/my2440/my2440.c650
) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325410.png" style="padding:0px;margin:0px;border:0px;" />
Note: bd_t is referenced by gd_t, and in global_data.h we can see that u-boot defines a global pointer variable *gd of gd_t, so here we can directly use gd to set bd.
OK, let's analyze how the parameter list is passed. The series of functions that organize the parameter list are called in a function called do_bootm_linux, which is also defined in lib_arm/bootm.c.
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325411.png" style="padding:0px;margin:0px;border:0px;" />
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325412.png" style="padding:0px;margin:0px;border:0px;" />650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325413.png" style="padding:0px;margin:0px;border:0px;" />
mkimage [-x]-A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image Options: For example: |
Haha, I believe you have seen the light at this moment! This entry address is 0x30008000, which is one of the reasons why u-boot must use the uImage format to start the kernel. Note: There is a kernel entry address 0x30008000, and it is mentioned above that a u-boot parameter list in the memory address 0x30000100, imagine what will happen if the kernel entry address specified here covers the address of the parameter list?
Well, by looking at each step above from bottom to top, you can know the entire process of transferring u-boot parameter items on the u-boot side. Then, let's analyze how u-boot parameter items are received on the kernel side.
start: .word 0x016f2818 @ Magic numbers to help the loader wont_overwrite: mov r0, r4 ...... call_kernel: bl cache_clean_flush ...... |
First, save r1 (machine code) and r2 (physical address of parameter list in kernel) passed by u-boot to ARM registers r7 and r8 respectively, and then pass r7 as a parameter to decompression function decompress_kernel(), in which r7 is passed to global variable __machine_arch_type, and then restore r7 and r8 to r1 and r2 before jumping to vmlinux entry.
In the arch/arm/kernel/head.S file, part of the code for the kernel vmlinux entry is as follows:
ENTRY(stext) ...... |
First, get the type of ARM kernel from the ARM special register (CP15), and check whether there is this ARM kernel type from the processor kernel descriptor (proc_info_list) table (__proc_info_begin—__proc_info_end). If not, exit with an error. The processor kernel descriptor is defined in include/asm-arm/procinfo.h, and the specific function is implemented in arch/arm/mm/proc-xxx.S. Various processor kernel descriptors are combined into a table during the compilation and linking process. Then check whether there is the machine code specified by the r1 register from the machine description (machine_desc) table (__mach_info_begin—__mach_info_end). If not, exit with an error. This also explains why the machine code specified in u-boot must be consistent with that specified in the kernel, otherwise the kernel cannot be started. The machine number mach_type_xxx is described in the arch/arm/tools/mach-types file. Each machine descriptor includes a unique machine number. The machine descriptor is defined in include/asm-arm/mach/arch.h and implemented in the arch/arm/mach-xxxx folder. During the compilation and linking process, different machine descriptors based on the same processor are combined into a table. For example, the machine descriptor of the S3C2440 processor with machine code 1008 is as follows:
MACHINE_START(SMDK2440,"SMDK2440") .init_irq = s3c24xx_init_irq, |
Finally, the MMU is turned on and the system is initialized by jumping to the start_kernel() function in init/main.c. Part of the code of the start_kernel() function is as follows:
asmlinkage void __init start_kernel(void) |
The function setup_arch is implemented in arch/arm/kernel/setup.c. Some of the code is as follows:
void __init setup_arch(char**cmdline_p) |
The setup_processor() function finds the matching descriptor from the processor kernel descriptor table and initializes some processor
variables. The setup_machine() returns the machine descriptor with the machine number (assigned in the decompression function decompress_kernel) as a parameter. The physical address of the kernel parameter is obtained from the machine descriptor and assigned to the tags variable. Then the parse_tags() function is called to analyze the kernel parameter list and pass each parameter value to the global variable. In this way, the kernel receives the parameters passed by u-boot.
-
TFTP downloads the kernel and NFS mounts the file system
OK, the tftp service and nfs service are ready, and the parameter transfer from u-boot to kernel is also OK. Next, we need to set the parameter items in the u-boot environment variable and the kernel configuration options so that it can use tftp to automatically download the kernel and automatically mount the nfs file system through the network. The u-boot environment variable settings are as follows:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325416.png" style="padding:0px;margin:0px;border:0px;" />
The bootcmd parameter item uses tftp to download the uImage in the host tftp main directory to the 0x31000000 position in the development board SDRAM, and then uses the bootm command to execute the boot kernel startup.
The bootargs parameter is the command line parameter for kernel startup. u-boot passes this parameter to the kernel and mounts the file system through nfs. Here you must pay attention to the settings of serverip and ipaddr (that is, the server IP or the development host IP and the development board IP). In addition, please note that the kernel must also configure the corresponding options to use nfs, as follows:
File systems ---> |
The results are as follows:
a. Download the kernel through tftp and start the kernel:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325417.png" style="padding:0px;margin:0px;border:0px;" />
b. The command line parameters passed by u-boot are received by the kernel:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325418.png" style="padding:0px;margin:0px;border:0px;" />
c. The kernel mounts the file system through nfs:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325419.png" style="padding:0px;margin:0px;border:0px;" />
d. Check the mounted nfs file system and find that it is completely consistent with the file system in the host nfs server's main directory, indicating success!
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325420.png" style="padding:0px;margin:0px;border:0px;" />
[root@localhost home]# vi /etc/exports //If this file does not exist, create it and add the following line of configuration information. Note that the format must be correct, otherwise the service will not work properly. /home/filesystem *(rw,no_root_squash,sync) Note: "/home/filesystem" is the home directory of the NFS server. Pay attention to the permissions of the directory. "*" means all IP addresses can access the NFS home directory "rw" means read and write "no_root_squash" means that if the user who logs in to the NFS host is a ROOT user, he has ROOT permissions "sync" means synchronization [root@localhost home]# service nfs restart //Restart the NFS service to make the configuration file take effect |
Test whether the NFS service is normal. Put the prepared file system into the NFS home directory as follows:
[root@localhost home]# ls /home/filesystem/ //Test the NFS service locally on the host, mount the file system under the NFS home directory to the /mnt directory, 192.168.1.101 is the host IP [root@localhost home]#mount -o nolock -t nfs 192.168.1.101:/home/filesystem /mnt |
You can see that the contents of the /mnt directory are exactly the same as those of the NFS home directory /home/filesystem, indicating that the NFS service is normal:
650) this.width=650;" src="http://www.embeddedlinux.org.cn/uploads/allimg/130316/10325421.png" style="padding:0px;margin:0px;border:0px;" />
[root@localhost home]# vi /etc/xinetd.d/tftp service tftp |
Create the tftp server home directory just specified, and also pay attention to the read and write permissions of the home directory:
[root@localhost home]#mkdir /home/tftp-root |
Start and test the tftp service:
[root@localhost home]#service xinetd restart //Restarting the xinetd service will start all its services, including the tftp service tftp>put the file to upload tftp>q |
Previous article:Detailed explanation of ucosii transplantation on stm32 5
Next article:Detailed explanation of Uboot transplantation on S3C2440 (V)
Recommended ReadingLatest update time:2024-11-16 15:04
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Use of hardware multiplier in MSP430 library
- UPD78F0888A Renesas MCU peripheral settings
- ST Motor_by Changjianze1
- Release of Yi Camera (already released)
- How can LM3447 achieve constant power control?
- 【Nucleo G071 Review】 Final Conclusion
- Differences between CPU and CLA and Error Handling Techniques
- Automobile crankshaft dynamic balance problem-N600
- zstack protocol stack serial port problem
- MY-8188EUS Linux-3.14.52 Test