Linux 2.6.32.2 mini2440 platform transplantation-kernel transplantation, yaffs2 file system transplantation

Publisher:码梦小子Latest update time:2022-10-18 Source: csdnKeywords:linux  6  mini2440  yaffs2 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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了。

[1] [2]
Keywords:linux  6  mini2440  yaffs2 Reference address:Linux 2.6.32.2 mini2440 platform transplantation-kernel transplantation, yaffs2 file system transplantation

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

Wireless bus measurement and control system based on LPC2132
introduction     At present, wireless communication is not only widely used in the communication industry, but also is being continuously applied and promoted in the field of detection and control. As the mainstream communication network of modern industrial control systems, the industrial field bus uses optical fib
[Microcontroller]
Wireless bus measurement and control system based on LPC2132
Step by step STM32 startup code
For those who are familiar with computers, BIOS (the blue interface) may not be too unfamiliar. This thing is the computer's startup code. A computer without BIOS is destined to be a brick! BIOS is mainly used to do some preparatory work before booting, such as system time setting and boot sequence...     In fact, the
[Microcontroller]
Step by step STM32 startup code
You want the iPhone SE2 with A13 chip, it's worth looking forward to
iPhone SE is a product that some users like very much. Not only is it relatively cheaper, but the most important thing is that the configuration is sufficient, and the small screen is very easy to operate, and the IOS system experience is also very good. Just after the release of iPhone 11, many users are still paying
[Mobile phone portable]
Lite Storage Technology’s CL6 series solid state drives are the first industrial-grade SSD equipped with KIOXIA’s sixth-generation BiCS FLASH™ technology
Digital transformation is imperative. With the continued development of artificial intelligence (AI) and the rapid advancement of cloud computing technology, enterprises have an increasing demand for data computing and storage space. How to reduce energy consumption while maintaining high-speed transmission and making
[Embedded]
Lite Storage Technology’s CL6 series solid state drives are the first industrial-grade SSD equipped with KIOXIA’s sixth-generation BiCS FLASH™ technology
Is the pure electric market going to change? Japan has developed a fluoride-ion battery that is 6 times more powerful than lithium-ion batteries!
There is no doubt that in the current pure electric vehicle market, the core energy of most pure electric vehicles comes from lithium-ion batteries . Through the continuous efforts of major manufacturers, they have also made better and better use of the capabilities of lithium-ion electronics. However, This is not eno
[Automotive Electronics]
Is the pure electric market going to change? Japan has developed a fluoride-ion battery that is 6 times more powerful than lithium-ion batteries!
ViewSonic's 4K gaming monitor XG320U is launched to help you overcome all difficulties!
ViewSonic has announced the launch of a new 4K HD monitor in its ELITE series, the XG320U. As another new masterpiece of ViewSonic's high-end gaming monitor, the XG320U has a 31.5-inch screen with micro-frames on three sides, plus an ultra-high-definition color display of 3840 x 2160 UHD, which presents delicate image
[Embedded]
ViewSonic's 4K gaming monitor XG320U is launched to help you overcome all difficulties!
stm32 learning four
systick (tick timer):  An example of testing the system tick timer is to light up the LEDs on the development board in turn (I chose to light up three LEDs in turn every 1s).  First of all, the characteristic of the system tick timer is that if the timer is set to start, it will automatically count. At this time, whe
[Microcontroller]
Embedded Development Learning (2)
Basic concepts: Memory: SRAM static memory features: small capacity, high price, advantages: no software initialization required, can be used as soon as power is turned on. DRAM dynamic memory Features: large capacity, low price, disadvantages: cannot be used after power-on, requires software initiali
[Microcontroller]
Embedded Development Learning (2)<s5pv210启动过程详解></s5pv210启动过程详解>
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号