1.1 Obtain the Linux kernel source code
There are many ways to obtain the Linux kernel source code. If your Linux platform can access the Internet, you can directly enter the following command on the command line to obtain Linux-2.6.32.2:
#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.gz
Of course, you can also download it first using tools such as Thunder under the Windows system, and then copy it to Linux.
1.2 Unzip the kernel source code
Assume that we have just downloaded the kernel source code to the /root/mini2440 directory and execute the following decompression command
make:
#cd /opt/FriendlyARM/mini2440
#tar xvzf linux-2.6.32.2.tar.gz
1.3 Specify cross-compilation variables
Our purpose of transplantation is to enable Linux-2.6.32.2 to run on mini2440.
First, we need to make the default target platform of Linux-2.6.32.2 an ARM platform.
Modify the Makefile in the total directory
Original
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
Change to
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
Among them, ARCH specifies the target platform as arm, CROSS_COMPILE specifies the cross-compiler, and the system's default cross-compiler is specified here. If you want to use another one, you must write the full path of the compiler here.
Next, we need to test whether the Linux compilation can pass normally.
implement:
#make s3c2410_defconfig; Use the default kernel configuration file. s3c2410_defconfig is the default configuration file of SMDK2440. My s3c2410_defconfig file is located at /arch/arm/configs/s3c2410_defconfig
#make ;Compilation time is long
The compilation is passed. We don't need to program it to the development board to verify its correctness.
1.4 Clone and establish your own target platform
1.4.1 About machine code
The above compilation is based on the target platform configuration supported by the Linux kernel itself, which corresponds to SMDK2440. Now we have to refer to SMDK2440 to add our own development board platform. We are using mini2440, so it is named MINI2440. It should be noted that Linux-2.6.32.2 itself already contains support for mini2440, so there is a duplicate name. then what should we do? We still use the name MINI2440 here, but in the subsequent transplantation steps, we can directly delete the mini2440 code part that comes with the original kernel to avoid confusion with our own transplantation. First of all, a very critical point is that when the kernel starts, it determines which target platform should be started through the machine code (MACH_TYPE) passed in by the bootloader. Friendly Arm has applied for its own machine code of 1999 for mini2440, which is located in linux -2.6.32.2/arch/arm/tools/mach_types file.
If the kernel machine code does not match the one passed in by the bootloader, the following error will often occur:
Uncompressing Linux................................................ ................................................................. ........................ done, booting
the kernel.
Didn't it stop when it ran to this point?
Tip: You can see the machine code definition of mini2440 in U-boot/include/asm-arm/mach-types.h
Next, we noticed that there is a
The mach-mini2440.c file is actually the main content added by foreign enthusiasts for mini2440 transplantation, but we don’t need it and delete it directly. Copy mach-smdk2440.c in the linux-2.6.32.2/arch/arm/mach-s3c2440/ directory. Named mach-mini2440.c,
Find MACHINE_START(S3C2440, "SMDK2440") and modify it to
MACHINE_START(MINI2440, "FriendlyARM Mini2440 development board").
Tip: After the development board is running, enter: cat /proc/cpuinfo in the command line terminal to see the development board information we added.
1.4.2 Modify clock source frequency
Now let’s modify the system clock source, in mach-mini2440.c (which we just copied
mach-smdk2440.c) in the static void __init smdk2440_map_io(void) function, change the 16934400 (representing that the crystal oscillator on the original SMDK2440 target board is 16.9344MHz) to the 12,000,000 actually used on the mini2440 development board ( Represents the 12MHz crystal oscillator on the mini2440 development board, and the component number is X2)
1.4.3 From SMDK2440 to MINI2440
Because we want to make our own mini2440 platform system, we put all the files in mach-mini2440.c
Change the word smdk2440 to mini2440. You can use the batch command to modify it. In the command mode of vim, enter:
%s/smdk2440/mini2440/g
The meaning of the above sentence is: replace all strings matching "smdk2440" with "mini2440". The first "%s" represents string matching, and the last "g" represents global, which means global.
In addition, there is another place that needs to be changed. In the mini2440_machine_init(void) function, change
Comment out the smdk_machine_init() function call, because we will write our own initialization function later and do not need to call the original smdk2440.
1.4.4 Compilation and testing
Execute in the Linux source code root directory
#make mini2440_defconfig; Use the official mini2440 configuration that comes with Linux
#make zImage; Compiling the kernel takes a long time, and finally zImage will be generated.
My s3c2410_defconfig file is located at /arch/arm/configs/mini2440_defconfig
Recompile and download the generated kernel file zImage (located in the arch/arm/boot directory) to the board. You can see that the kernel can be started normally, but most hardware drivers have not been added at this time, and there is no file system. So I can't log in yet.
Notice:
(1) If you have compiled the kernel before, please clean it up first, otherwise you will be prompted that the compiled files are out of date.
(2) Note that MACHINE_START(S3C2440, "SMDK2440") was modified in the previous machine code item and was modified to
MACHINE_START(MINI2440, "FriendlyARM Mini2440 development board").
MINI2440 here must be capitalized. My own understanding is that it is consistent with the type in the machine code.
1.5 关于内核配置菜单中的mini2440选项
在开始移植其他驱动之前,我们再了解一些看起来比较“神秘”的常识,那就是运行make menuconfig时,内核配置菜单中的mini2440选项是如何出现的。
在命令行执行:
#make menuconfig ;前面已经执行了make mini2440_defconfig加载了缺省配置,因此这里可以直接执行该命令
按上下键移动到System Type,按回车进入该子菜单,再找到S3C2440 Machines,按回车进入该子菜单
在此就可以看到Linux天生内核对mini2440开发板的支持选项了,那么它们是从哪里来的呢?
打开Linux-2.6.32.2/arch/arm/mach-s3c2440/Kconfig文件可以找到相关信息。
现在明白了吧,“MINI2440 development board”正是在这个Kconfig文件中定义说明的,
当然你可以根据自己的喜好改为其他显示信息。
这里的显示信息只是在内核配置菜单中出现的,要让选择的配置实际起效,还需要根据此配置在Makefile中添加相应的代码文件,请看该目录下的Makefile。
这样,配置文件就跟实际的代码文件通过配置定义联系在一起了,这里的配置定义是“CONFIG_MACH_MINI2440”,内核中还有很多类似的配置定义,并且有的配置定义还存在依赖关系,我们在此就不对它们详细说明了,随着对内核代码结构的不断熟悉,你就会逐渐学会分析和查找你所需要的各种配置和定义等。
1.6 移植Nand驱动并更改分区信息
1.6.1 Linux-2.6.32.2内核所支持的Nand Flash类型
Linux2.6.32.2已经自带了大部分Nand Flash驱动,在
linux-2.6.32.2/drivers/mtd/nand/nand_ids.c文件中,定义了所支持的各种Nand Flash类型。
1.6.2 修改Nand Flash分区表
但是系统默认的分区不是我们所需的,所以要自已修改,除此之外,还有Nand Flash的结构信息需要增加填写,以便能够适合系统自带的Nand Flash驱动接口,这可以参考SMDK2440中关于Nand Flash设备注册的一些信息。
打开/arch/arm/plat-s3c24xx/common-smdk.c,可以看到这样一个结构体:
注意这里是参考这个文件夹的内容,改动还是在mach-mini2440.c
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "Boot Agent",
.size = SZ_16K,
.offset = 0,
},
[1] = {
.name = "S3C2410 flash partition 1",
.offset = 0,
.size = SZ_2M,
},
[2] = {
.name = "S3C2410 flash partition 2",
.offset = SZ_4M,
.size = SZ_4M,
},
[3] = {
.name = "S3C2410 flash partition 3",
.offset = SZ_8M,
.size = SZ_2M,
},
[4] = {
.name = "S3C2410 flash partition 4",
.offset = SZ_1M * 10,
.size = SZ_4M,
},
[5] = {
.name = "S3C2410 flash partition 5",
.offset = SZ_1M * 14,
.size = SZ_1M * 10,
},
[6] = {
.name = "S3C2410 flash partition 6",
.offset = SZ_1M * 24,
.size = SZ_1M * 24,
},
[7] = {
.name = "S3C2410 flash partition 7",
.offset = SZ_1M * 48,
.size = SZ_16M,
}
};
这其实就是Nand Flash的分区表,在Linux-2.6.32.2中,nand驱动是被注册为平台设备的,这同样可在/arch/arm/plat-24xx/common-smdk.c文件中看出,如下:
static struct s3c2410_platform_nand smdk_nand_info = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(smdk_nand_sets),
.sets = smdk_nand_sets,
};
/* devices we initialise */
static struct platform_device __initdata *smdk_devs[] = {
&s3c_device_nand,
&smdk_led4,
&smdk_led5,
&smdk_led6,
&smdk_led7,
};
参考以上结构信息,我们也在自己的mach-mini2440.c中照此添加实现,同时需要参考友善之臂原厂内核中的Nand分区表
因此,在mach-mini2440.c中加入以下代码:
首先添加几个头文件:
#include #include #include #include #include 然后加入以下代码: static struct mtd_partition mini2440_default_nand_part[] = { [0] = { .name = "supervivi", //这里是bootloader所在的分区,可以放置u-boot, supervivi等内容,对应/dev/mtdblock0 .size = 0x00040000, .offset = 0, }, [1] = { .name = "param", //这里是supervivi的参数区,其实也属于bootloader的一部分,如果u-boot比较大,可以把此区域覆盖掉,不会影响系统启动,对应/dev/mtdblock1 .offset = 0x00040000, .size = 0x00020000, }, [2] = { .name = "Kernel", //内核所在的分区,大小为5M,足够放下大部分自己定制的巨型内核了,比如内核使用了更大的Linux Logo图片等,对应/dev/mtdblock2 .offset = 0x00060000, .size = 0x00500000, }, [3] = { .name = "root", //文件系统分区,友善之臂主要用来存放yaffs2文件系统内容,对应/dev/mtdblock3 .offset = 0x00560000, .size = 1024 * 1024 * 1024, // }, [4] = { .name = "nand", //此区域代表了整片的nand flash,主要是预留使用,比如以后可以通过应用程序访问读取/dev/mtdblock4就能实现备份整片nand flash了。
Previous article:Linux2.6.32.2 mini2440 platform transplantation--Transplantation of DM9000 network card driver
Next article:linux2.6.32.2 mini2440 platform transplantation--serial port driver transplantation, I2C-EEPROM driver transplantation, watchdog driver transplantation
Recommended ReadingLatest update time:2024-11-23 15:07
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- DSP28335 performs FFT Fourier transform
- Secondary Controlled Single-Ended Forward Converter
- Thirty-three MCU (microcontroller) input/output interface circuits
- New battery charging mode
- I would like to hear everyone’s advice: Is it appropriate to quit your job during this period of time?
- Based on MSP430 infrared tracking car
- EEWORLD University Hall----Using JTAG with UCD3138
- I need to do some work on the telephone circuit recently, but I am not familiar with the voltage and operation of the telephone line, which is very troublesome.
- AltiumDesigner integrated library design based on Access database
- EEWORLD University Hall----Live Replay: TE explains the design trends of smart antennas and sensor application cases in the Internet of Things