0. Linux kernel startup process

1. Obtain and decompress the kernel source code

Linux kernel official website: www.kernel.org.

This tutorial is used in version 3.4.2, relatively old, so I put in the public number, please pay attention to the public number Mculover666 at the end of the article, reply keyword “kernel source code” to obtain.

Then put it on Linux and unzip it:

The tar - JXVF Linux - 3.4.2. Tar..bz2Copy the code

Linux kernel has more than 30,000 files, you can remove the V parameter, do not display decompression information.

2. Configure and compile

Enter the decompressed folder:

cdLinux - 3.4.2 /Copy the code

2.1. Configure the schema and compile work chain

Search ARCH in the makefile in the root directory to find two configurations as shown:

  • ARCH: CPU architecture to run Linux
  • CROSS_COMPILE: Cross-compiler name

2.2. Select the default configuration file

Enter the default configuration file directory of the ARM architecture board:

cd arch/arm/configs/
Copy the code

You can see the board configuration files of all current ARM architectures:



Go back to the root directory and sets3c2410_defconfigDefault configuration file:

cd. /.. /.. / make s3c2410_defconfigCopy the code

The configuration file is generated after execution.configFor compilation:



The list of supported boards in the file is as follows:

Compile 2.3.

make uImage
Copy the code

Wait for compilation to complete…

Error message:

After checking out the resources (see the blog), this is due to an error in compiling an older kernel version on a newer version of Linux:

Delete defined() in line 373 from the kernel/timeconst.pl file as follows:

vim kernel/timeconst.pl
Copy the code

To make:

make uImage
Copy the code

Another problem:



This is because the uImage package is not installed on the Linux host.

sudo apt-get install u-boot-tools
Copy the code

Compile again, compile successfully:

2.4. Test kernel images

Copy the compiled kernel file for easy download to the local:

cp arch/arm/boot/uImage .. /Copy the code

Download this file to the TFTP server directory and then get the file to memory in the uboot of the development board:

tftp 30000000 uImage
Copy the code

Start the kernel:

bootm 30000000
Copy the code

As you can see, the kernel started successfully:

3. Set up machid – Select machine

3.1. View machid in the Uboot

As can be seen from the boot log above, the board of kernel boot is SMDK2410. This is because there is no machid value in the current environment variable, so uboot uses the code default macro definition when booting the kernel. The code is as follows in the fileU - the boot - 2012.04.01 / the arch/arm/lib/bootm. CBoot_jump_linux:



Default machid value in uboot code is gd->bd-> bi_ARCH_number, global search bi_arch_number, in fileU - the boot - 2012.04.01 / board/samsung/smdk2440 smdk2440. CIn:



Again look for the macro defining the value of MACH_TYPE_SMDK2410 in the fileU - the boot - 2012.04.01 / arch/arm/include/asm/Mach - types. HIn:



So,The default value of machid passed by uboot is 193, or 0xC1.

3.2. View Machid in the Linux kernel

Machid = machid = machid = machid = machid = machid = machid = machid

Set a value of machid directly on the uboot command line. When this value is not in the list of supported machines, all currently supported machines will be listed:

set machid 0xff0
Copy the code

Do not execute saveenv.



Re-download the kernel image after successful setup and start the kernel:



In the list of support, you can see that the Machid of SMDK2440 is0x16a, there are two Settings:

  • < span style = “box-sizing: border-box; color: RGB (51, 51, 51); line-height: 22px; font-size: 13px! Important; word-break: inherit! Important;”
  • ② Set machid to 16A and run saveenv to save the machid.

Here we use the second method to modify machid and save it to an environment variable:



Then try to boot the kernel again, and the kernel will print garble:

4. Solve the startup garbled characters problem

The board file corresponding to the Machid is found in the kernel source codearch\arm\mach-s3c24xx\mach-smdk2440.cIn the smDK2440_map_io function, it can be seen that there is a problem with the crystal oscillator setting. The onboard crystal oscillator of JZ2440 is 12M, so the modification is as follows:



Reconfigure and compile the kernel, download it to the development board and start it, and the identified machine is SMDK2440. Success:



Kernel partitioning and mounting root file system errors will be addressed in the next few articles.

Welcome to subscribe to my wechat official account: “McUlover666”.