Kernel transplantation is actually very simple, because the kernel is developed and maintained by the Linux kernel development team led by Linus. We only need to cross-compile it with our platform to use it. However, kernel transplantation is not simple, because any problems may be stuck during kernel transplantation. Because the kernel code is very large, we cannot read the kernel code. The following are various tragic problems and solutions I encountered during the transplantation. The first is the necessary development environment:
a) Linux kernel code, version 3.8.3
b) S5PV210 development board (mine is TQ210)
c) The HOST environment is an Ubuntu virtual machine (12.10) installed under WIN7 (64-bit)
1. Kernel compilation
Download the kernel code from the Linux kernel website (kernel.org), unzip it and enter the kernel directory
(1) Modify the Makefile and change lines 195 and 196 to:
- ARCH = arm
- CROSS_COMPILE ?= arm-linux-
- make s5pv210_defconfig
- make zImage
- make uImage
a. The compiled kernel type is wrong. For example, your uboot uses uImage, but you compiled zImage.
b. There is a problem with the transplanted uboot, which fails to correctly copy the kernel to the correct memory address and start it.
c. The kernel has some configurations that we do not have.
After checking the kernel configuration items, we know that the kernel uses UART1 by default to print debugging information. Therefore, execute:
- make menuconfig
After compiling the kernel, download and try to run it again. At this time, you can see the information printed by the kernel. If you unfortunately only see "Uncompressing Linux... done, booting the kernel." and no other output, then check whether the machine code passed by uboot matches the kernel machine code. If they do not match, please correct them, and then recompile and run the kernel or uboot. If you still cannot see other output after the correction, then check the bootargs parameter of uboot. Console=ttySAC0 must be configured in bootargs, otherwise you will not see the printed information.
If the above error does not appear, your kernel can print a lot of information, but because the kernel does not provide support for Nand or network card by default, the file system cannot be mounted, so it still cannot run normally. In order to enable the kernel to enter the console and provide an environment for subsequent driver development, we first make the file system, then transplant the network card driver, let the kernel mount the file system in NFS mode, and then we can develop other drivers, such as Nand, LCD, sound card, etc.
2. Build the file system
In fact, building a file system is relatively simple. Just pay attention to a few points and follow the steps.
(1) To create the root file system directory structure, you can use the following script:
- #!/bin/sh
- echo "------Create rootfs directons start...--------"
- mkdir rootfs
- cd rootfs
- echo "--------Create root,dev....----------"
- mkdir root dev etc boot tmp var sys proc lib mnt home usr
- mkdir etc/init.d etc/rc.d etc/sysconfig
- mkdir usr/sbin usr/bin usr/lib usr/modules
- echo "make node in dev/console dev/null"
- sudo mknod -m 600 dev/console c 5 1
- sudo mknod -m 600 dev/null c 1 3
- mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
- mkdir var/lib var/lock var/run var/tmp
- chmod 1777 tmp
- chmod 1777 var/tmp
- echo "-------make direction done---------"
Here I named the script mkrootfs.sh, then gave it executable permissions (chmod a+x mkrootfs) and ran it. My script runs in the /nfsroot directory, so the root directory of my root file system is /nfsroot/rootfs, and this directory is used as an example in the following descriptions.
(2) Compile Busybox
Go to Busybox to download the latest version of Busybox source code. I used version 1.21.0. After downloading, unzip it and enter the busybox directory. The first step is to configure busybox.
- make menuconfig
The configuration menu is similar to the kernel configuration. Enter Busybox Settings => Build Options => Cross Compiler prefix (NEW) and set it to the compiler prefix. I use arm-linux-. Some friends on the Internet also recommend selecting Busybox Settings => Build Options => Build BusyBox as a static binary (no shared libs), but if we have copied the compiler runtime library correctly, it is also OK not to set it. Now we can compile Busybox. Execute
- make
The compilation process went smoothly and I did not encounter any errors. Next, install the compiled Busybox to /nfsroot/rootfs and execute
- make CONFIG_PREFIX=/nfsroot/rootfs install
(3) Copy the compiler runtime library
My compiler is version 4.5.1. Copy all dynamic libraries of arm-none-linux-gnueabi/sys-root/lib to /nfsroot/rootfs/lib. In order not to copy the link, you should add the "-d" option and execute
- cp *so* /nfsroot/rootfs/lib -d
Similarly, copy all dynamic libraries under arm-none-linux-gnueabi/sys-root/usr/lib to /nfsroot/rootfs/usr/lib and execute
- cp *so* /nfsroot/rootfs/usr/lib -d
(4) Build etc directory
[page]
Create an Inittab file in the etc directory with the following content
- ::sysinit:/etc/init.d/rcS
- console::askfirst:-/bin/sh
- ::restart:/sbin/init
- ::ctrlaltdel:/sbin/reboot
- ::shutdown:/bin/umount -a -r
- ::shutdown:/sbin/swapoff -a
Create the rcS file in the etc/init.d/ directory with the following content
- echo "----------mount all.........."
- mount -a
- echo "----------Starting mdev......"
- echo /sbin/mdev > /proc/sys/kernel/hotplug
- mdev -s
- /bin/hostname -F /etc/sysconfig/HOSTNAME
Add executable permissions to inittab and rcS files
- chmod a+x inittab
- chmod a+x rcS
Create the fstab file in the etc directory with the following content
- #evice mount-point type option dump fsck order
- proc /proc proc defaults 0 0
- none /tmp ramfs defaults 0 0
- mdev /dev ramfs defaults 0 0
- sysfs /sys sysfs defaults 0 0
Create a profile file in the etc directory with the following content
- PATH=/bin:/sbin:/usr/bin:/usr/sbin
- export PATH
- #set hostname
- HOSTNAME='/bin/hostname'
- export HOSTNAME
- # Set PS1
- PS1='[u@h W]$'
- export PS1
Copy the passwd and group files in the host's /etc directory to the etc directory.
(5) Set up the HOSTNAME file
Create a HOSTNAME file in the etc/sysconfig directory and write the host name in the file. I wrote bruce here.
(6) Install kernel modules
Enter the kernel source directory and execute
- make modules
After the compilation is complete, install the modules and execute the command
- make modules_install INSTALL_MOD_PATH=/nfsroot/rootfs
At this point, the root file system is built.
3. Set uboot startup parameters
My nfs root directory is /nfsroot, and my root file system directory is under this directory, that is, /nfsroot/rootfs directory, so the uboot startup parameters are set as follows
- noinitrd console=ttySAC0 root=
:/nfsroot/rootfs rw ip= : : : ::eth0:off init=/linuxrc
It should be noted that all colons ":" cannot be omitted.
4. Network card driver transplantation (DM9000)
The reason why we choose to transplant the network card is that the network card driver is relatively simple, and it is even simpler for DM9000, because the kernel itself provides the DM9000 driver, but there is no management configuration for the development board. Therefore, we can complete the transplantation of the network card driver by configuring the development board related things. Open the arch/arm/mach-s5pv210/mach-smdkv210.c file and make the following changes:
(1) Modify the definition of smdkv210_dm9000_resources as follows
- static struct resource smdkv210_dm9000_resources[] = {
- [0] = {
- .start = 0x88000000,
- .end = 0x88000000 + 3,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = 0x88000000 + 4,
- .end = 0x88000000 + 4 + 3,
- .flags = IORESOURCE_MEM,
- },
- [2] = {
- .start = IRQ_EINT(10),
- .end = IRQ_EINT(10),
- .flags = IORESOURCE_IRQ|IORESOURCE_IRQ_HIGHLEVEL,
- }
- };
(2) Modify the smdkv210_dm9000_init function as follows
- static void __init smdkv210_dm9000_init(void)
- {
- unsigned long* srom_bw = ioremap(0xE8000000, 4);
- unsigned long* srom_bc1 = ioremap(0xE8000004, 4);
- *srom_bc1 = ((0<<28)|(0<<24)|(5<<16)|(0<<12)|(0<<8)|(0<<4)|(0<<0));
- *srom_bw &= ~(0xf << 4);
- *srom_bw |= (1<<4)|(1<<5);
- gpio_request(S5PV210_MP01(1), "nCS1");
- s3c_gpio_cfgpin(S5PV210_MP01(1), S3C_GPIO_SFN(2));
- gpio_free(S5PV210_MP01(1));
- iounmap(srom_bw);
- iounmap(srom_bc1);
- }
In this way, the transplantation of the DM9000 network card driver is completed. In fact, this modification is logical. According to the schematic diagram of TQ210, we can know that the chip select of the DM9000 connection is nCS1, that is, the network card is connected to BANK1 of the ROM controller.
According to the memory mapping table of S5PV210, the address space of BANK1 of SROMC is 0x88000000~0x8FFFFFFF, so the chip select nCS1 will be enabled only when the CPU addresses the address space within this range. Therefore, we use the address 0x88000000. [page]
In addition, from the DM9000 part of the TQ210 schematic diagram, we can also see that DM9000 uses external interrupt 10, so the interrupt number is changed to 10.
Finally, it is necessary to explain the modification of the smdkv210_dm9000_init function. This is because the data access and command sending of DM9000 work according to a certain timing, and DM9000 is connected to SROMC, so the SROMC timing needs to be configured so that it can correctly drive DM9000. I haven't studied the detailed configuration of the timing yet, but Mr. Wei Dongshan's second video talks about the driver transplantation of DM9000 and the timing configuration. You can refer to it if you need it.
Five Mounting File Systems
Now that we have configured the network card driver, we still need to configure the kernel slightly to enable it to support network file system mounting. For details, please refer to the following configuration.
(1) Configuring network support
(2) Configuring network card device support
- Device Drivers --->
- [*] Network device support --->
- [*] Ethernet driver support --->
- <*> DM9000 support
(3) Configuring network file system support
- File systems --->
- [*] Network File Systems --->
- <*> NFS client support
- <*> NFS client support for NFS version 2
- <*> NFS client support for NFS version 3
- [*] NFS client support for the NFSv3 ACL protocol extension
- <*> NFS client support for NFS version 4
- [*] Root file system on NFS
After configuring the above three items, save the configuration, then compile the kernel again and execute the make command directly.
At this time, re-download the kernel and test it. If there are no unexpected problems, the kernel can now work normally. If unfortunately, there are problems, then the problem should be the configuration of the NFS server. It is very simple to configure the NFS server under Ubuntu.
- sudo apt-get install nfs-kernel-server
Then open the /etc/exports file with root privileges. My NFS root directory is /nfsroot, so I set export to
- /nfsroot/ *(rw,sync,no_root_squash)
After the settings are completed, you need to restart the NFS service. Execute in Ubuntu
- sudo service nfs-kernel-server restart
When you restart, you will see some warnings, as shown below
However, the above warning does not affect the use. On the contrary, if it is set to no_subtree_check, although the system can be mounted normally, it cannot perform write operations such as creating files. In other words, the mounted file system is read-only. Finally, you need to modify the permissions of /nfsroot for future convenience.
- chmod a+x /nfsroot -R
At this point, the kernel transplantation based on TQ210 has been preliminarily completed, and then we can proceed to driver development.
Summary of Six Questions
I encountered many problems during the configuration process, and now I will summarize them briefly.
(1) The serial port interrupt prints "Starting kernel..." and then there is no more output
Configure the kernel and specify the debug information output port as UART0. The detailed configuration is described in the article.
(2) There is no output after decompressing the kernel
a. Check whether the bootargs environment variable is set correctly. You must set console=ttySAC0
b. Check whether the machine code root kernel passed by uboot corresponds
c. Check whether the taglist passed by uboot to the kernel is correct
(3) The kernel cannot mount the NFS file system
a. Correctly transplant the DM9000 network card driver
b. Configure the network part of the kernel, the network card device and the network file system in the file system
c. Confirm whether the configuration of the NFS server is correct. Use another Linux or a Linux that has been transplanted to test it (mount -o nolock xx.xx.xx.xx:/nfsroot/rootfs).
(4) The file system is mounted successfully, but /linuxrc cannot be executed
a. Check the NFS configuration file. It is best to configure it in NFSv2 mode. Problems will occur if the kernel does not support it.
b. It is best to configure the NFS server in the manner recommended in this article.
c. After the configuration is complete, you need to restart the NFS service or restart the system.
7. Other issues
If you have other questions during the transplantation process, please leave a message for discussion.
Previous article:S5PV210 (TQ210) Study Notes - Key Driver
Next article:S5PV210 (TQ210) study notes - Nand configuration
- Popular Resources
- Popular amplifiers
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
- New neopixel usage on STM32
- Excitation reset of half-bridge (including full-bridge/push-pull)
- Switching AC-DC Conversion in Power Supplies
- 【FAQ】Microchip Live: GoodLock Project using SAM L11 and TrustFLEX ATECC608 security devices
- Detailed explanation of terminal device state switching in TI ZigBee protocol stack
- #Free application for evaluation#DFRobot AS7341 visible spectrum sensor
- One picture lets you understand TE's various industrial motor sensors
- [Project Source Code] How to forcefully delete the device driver when a device driver conflict causes a blue screen
- A beginner is asking for help. The source code of two different LPC1768 chips, the QEIPOS register is not used
- I2C Controlled 6A Three-Level Switch-Mode Single Cell Battery Charger