mini2440移植linux-3.4.2内核详细解说

时间:2022-04-11 06:35:30


cd /work/system
tar xjf linux-3.4.2.tar.bz2
cd linux-3.4.2/

1.1 修改Makefile
vi Makefile
/ARCH //搜索ARCH

ARCH ?=$(SUBARCH)
内核架构改为
ARCH ?=arm

CROSS COMPILE ?=$(CONFIG_CROSS_COMPILE:"%"=%)
交叉编译工具链改为
CROSS COMPILE ?=arm-linux-


//更换4.3.2编译器

 

find -name "*defconfig" //查找有哪些defconfig


vi arch/arm/mach-s3c24xx/mach-smdk2440.c
:169 //搜索169
16934400改为12000000


//修改d:work/linux-3.4.2/arch/arm/mach-s3c24xx/Common-smdk.c文件:
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "bootloader",
.size = SZ_256K,
.offset = 0,
},
[1] = {
.name = "params",
.offset = MTDPART_OFS_APPEND,
.size = SZ_128K,
},
[2] = {
.name = "kernel",
.offset = MTDPART_OFS_APPEND,
.size = SZ_2M,
},
[3] = {
.name = "rootfs",
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL,
}
};
改为
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "bootloader",
.size = SZ_256K,
.offset = 0,
},
[1] = {
.name = "params",
.offset = MTDPART_OFS_APPEND,
.size = SZ_128K,
},
[2] = {
.name = "kernel",
.offset = MTDPART_OFS_APPEND,
.size = SZ_4M,
},
[3] = {
.name = "rootfs",
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL,
}
};
//拷贝到linux内核中覆盖原文件


1.2 选择默认配置 :
make s3c2410_defconfig

1.3 生成uImage
make uImage
cp arch/arm/boot/uImage /work/nfs_root/uImage_new //拷贝到NFS挂载目录下

开发板上操作
set machid 16a // 设置smdk2440机器码
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
save


nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev.yaffs2 //先烧写yaffs2根文件系统
nand erase.part rootfs
nand write.yaffs 30000000 260000 889bc0

nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev.jffs2 //再烧录jffs2根文件系统
nand erase.part rootfs
nand write.jffs2 30000000 260000 $filesize //5b89a8
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2
save

nfs 32000000 192.168.31.202:/work/nfs_root/uImage_new //再烧写内核
bootm 32000000

grep "u-boot-env" * -nR //搜索u-boot-env关键字

 

 


制作文件系统
1. 交叉编译busybox-1.20.0
cd /work/system
rm -rf busybox-1.20.0
tar xjf busybox-1.20.0.tar.bz2 //解压busybox-1.20.0
cd /work/system/busybox-1.20.0
make menuconfig
//进入busybox configuration
->busybox settings
->build option
->cross compiler prefix(NEW) 改为 arm-linux-
//保存并退出
make //编译


//创建根文件系统目录
cd /work/nfs_root/
rm -rf fs_mini_mdev_new //删除原来的fs_mini_mdev_new目录
mkdir fs_mini_mdev_new //创建新fs_mini_mdev_new目录
cd fs_mini_mdev_new


在busybox-1.20.0目录下安装busybox:
make install CONFIG_PREFIX=/work/nfs_root/fs_mini_mdev_new

查询交叉编译工具链路径:
echo $PATH
显示:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.3.2/bin

cd /usr/local/arm/4.3.2/bin
cd ..
ls
find -name lib //查找库的路径

2. 安装库
mkdir /work/nfs_root/fs_mini_mdev_new/lib
mkdir /work/nfs_root/fs_mini_mdev_new/usr/lib -p

cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*so* /work/nfs_root/fs_mini_mdev_new/lib -d
cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*so* /work/nfs_root/fs_mini_mdev_new/usr/lib -d

3. 构建etc目录
cd /work/nfs_root
sudo cp tmp/fs_mini_mdev/etc fs_mini_mdev_new -rf
cd /work/nfs_root/fs_mini_mdev_new

//构造/etc/inittab
vi etc/inittab中
第3行:
s3c2410_serial0::askfirst:-/bin/sh
改为
console::askfirst:-/bin/sh

 

//构造etc/init.d/rcS
vi etc/init.d/rcS中
mount -a //装载/etc/fstab中的文件系统
echo /sbin/mdev > /proc/sys/kernel/hotplug //使/sbin/medv指向hotplug,从而支持热拔插
mdev -s //使用medv命令自动创建/dev下的所有设备节点

//并给rcS加上可执行权限:
sudo chmod +x etc/init.d/rcS //使脚本rcS能够执行命令

 

//构造etc/fstab //不采用
//PS:使用mdev命令需要sysfs、tmpfs、devpts这3个文件系统的支持
mkdir proc/ //创建proc要挂载的目录
mkdir sys/ //创建sysfs要挂载的目录,
mkdir dev/pts -p //创建devpts要挂载的目录
vi etc/fstab
//添加以下几句 //不采用
# device mount-point type options dump fsck order
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
devpts /dev/pts devpts defaults 0 0

 


4. 构建dev目录
cd /work/nfs_root/fs_mini_mdev_new
mkdir dev
ls -l /dev/console /dev/null //查看主次设备号
sudo mknod dev/console c 5 1 //c表示字符设备 5表示主设备号 1表示次设备号
sudo mknod dev/null c 1 3


5. 其他空目录
mkdir proc tmp mnt sys root

 

制作jffs2文件
cd /work/nfs_root/
sudo mkfs.jffs2 -n -s 2048 -e 128KiB -d fs_mini_mdev_new -o fs_mini_mdev_new.jffs2


重启开发板烧写:
nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev_new.jffs2
nand erase.part rootfs
nand write.jffs2 30000000 260000 $filesize
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2
save
nfs 32000000 192.168.31.202:/work/nfs_root/uImage_new
bootm 32000000

SIGILL illegal instruction
6. 重新配置内核支持EABI
cd /work/system/linux-3.4.2
make menuconfig
kernel configuration //配置内核
->kernel features
->use the ARM EABI to compile the kernel //选中
//保存并退出
make uImage
cp arch/arm/boot/uImage /work/nfs_root/uImage_eabi

//重启开发板烧录
nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev_new.jffs2
nand erase.part rootfs
nand write.jffs2 30000000 260000 $filesize
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2
nfs 32000000 192.168.31.202:/work/nfs_root/uImage_eabi
bootm 32000000

 

三. 移植YAFFS文件系统
1. 获得源码
cd /work/system
mkdir yaffs //创建新yaffs目录
cd yaffs
sudo apt-get install git //安装git命令
sudo apt-get install git-core //安装git-core命令
git clone git://www.aleph1.co.uk/yaffs2 //下载yaffs2

2. 打补丁
cd /work/system/yaffs/yaffs2
./patch-ker.sh c m /work/system/linux-3.4.2 //内核打补丁


3. 配置内核支持YAFFS
cd /work/system/linux-3.4.2
make menuconfig //配置内核
Location:
-> File systems
-> Miscellaneous filesystems (MISC_FILESYSTEMS [=y])
-> yaffs2 file system support (YAFFS_FS [=y])
//保存并退出


//linux-3.4.2/fs/yaffs2/Yaffs_vfs.c文件中修改
将yaffs_vfs.c文件2514~2515行的mtd->sync 改为: mtd->_sync
将yaffs_vfs.c文件2702行的mtd->erase改为: mtd->_erase
将yaffs_vfs.c文件2703行的mtd->read改为: mtd->_read
将yaffs_vfs.c文件2704行的mtd->write改为: mtd->_write
将yaffs_vfs.c文件2705行的mtd->read_oob改为: mtd->_read_oob
将yaffs_vfs.c文件2706行的mtd->write_oob改为: mtd->_write_oob
将yaffs_vfs.c文件2707行的mtd->block_isbad改为: mtd->_block_isbad
将yaffs_vfs.c文件2708行的mtd->block_markbad改为: mtd->_block_markbad
将yaffs_vfs.c文件2732行的
if (!mtd->erase ||
!mtd->block_isbad ||
!mtd->block_markbad || !mtd->read || !mtd->write ||
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
!mtd->read_oob || !mtd->write_oob) {
改为
if (!mtd->_erase ||
!mtd->_block_isbad ||
!mtd->_block_markbad || !mtd->_read || !mtd->_write ||
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
!mtd->_read_oob || !mtd->_write_oob) {


将yaffs_vfs.c文件2757行的
if (!mtd->erase || !mtd->read || !mtd->write ||
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
!mtd->read_oob || !mtd->write_oob) {
改为
if (!mtd->_erase || !mtd->_read || !mtd->_write ||
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
!mtd->_read_oob || !mtd->_write_oob) {


将yaffs_vfs.c文件2967行的
root = root = d_alloc_root(inode);
改为
root = root = d_make_root(inode);


将yaffs_vfs.c的第2967行的
root = d_alloc_rootretval = mtd->_erase(mtd, &ei);;
改为:
root = d_make_root(inode);


将yaffs_mtdif.c文件42行的
retval = mtd->erase(mtd, &ei);
改为
retval = mtd->_erase(mtd, &ei);


将yaffs_mtdif1.c文件138行的
retval = mtd->write_oob(mtd, addr, &ops);
改为
retval = mtd->_write_oob(mtd, addr, &ops);


将yaffs_mtdif1.c文件200行的
retval = mtd->read_oob(mtd, addr, &ops);
改为
retval = mtd->_read_oob(mtd, addr, &ops);


将yaffs_mtdif1.c文件223行的
etags->block_bad = (mtd->block_isbad) (mtd, addr);
改为
etags->block_bad = (mtd->_block_isbad) (mtd, addr);


将yaffs_mtdif1.c文件291行的
retval = mtd->block_markbad(mtd, (loff_t) blocksize * block_no);
改为
retval = mtd->_block_markbad(mtd, (loff_t) blocksize * block_no);


将yaffs_mtdif1.c文件341行的
etags.block_bad = (mtd->block_isbad) (mtd, addr);
改为
etags.block_bad = (mtd->_block_isbad) (mtd, addr);


将yaffs_mtdif2.c文件90行的
retval = mtd->write_oob(mtd, addr, &ops);
改为
retval = mtd->_write_oob(mtd, addr, &ops);


将yaffs_mtdif2.c文件145行的
retval = mtd->read(mtd, addr, dev->param.total_bytes_per_chunk,
&dummy, data);
改为
retval = mtd->_read(mtd, addr, dev->param.total_bytes_per_chunk,
&dummy, data);

将yaffs_mtdif2.c文件154行的
retval = mtd->read_oob(mtd, addr, &ops);
改为
retval = mtd->_read_oob(mtd, addr, &ops);


将yaffs_mtdif2.c文件218行的
mtd->block_markbad(mtd,
改为
mtd->_block_markbad(mtd,


将yaffs_mtdif2.c文件237行的
mtd->block_isbad(mtd,
改为
mtd->_block_isbad(mtd,

 


4. 编译、使用uImage
make uImage
cp arch/arm/boot/uImage /work/nfs_root/uImage_yaffs


5. 制作、烧写yaffs映象
cd /work/nfs_root
mkyaffs2image fs_mini_mdev_new fs_mini_mdev_new.yaffs2
重启开发板烧录:
nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev_new.yaffs2
nand erase.part rootfs
nand write.yaffs 30000000 260000 $filesize

6. 启动
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
save
nfs 32000000 192.168.31.202:/work/nfs_root/uImage_yaffs
bootm 32000000

7. 没成功,用替代法查找问题
7.1 UBOOT可能有问题:换上1.1.6的UBOOT
tftp 30000000 u-boot.bin
nand erase.part u-boot
nand write 30000000 u-boot
reset
nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev_new.yaffs2
nand erase rootfs
nand write.yaffs 30000000 260000 $(filesize)
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
nfs 32000000 192.168.31.202:/work/nfs_root/uImage_yaffs
bootm 32000000

发现1.1.6的UBOOT没问题,所以就是我们移植的新UBOOT有BUG:
drivers\mtd\nand\Nand_util.c

if (!need_skip && !(flags & WITH_DROP_FFS)) {
改为
if (!need_skip && !(flags & WITH_DROP_FFS) && !(flags & WITH_YAFFS_OOB)) {

 

 


内核裁剪:
cd /work/system/linux-3.4.2

//裁剪内核里无关的CPU/单板文件
make menuconfig //配置内核
Location:
-> System Type
-> SAMSUNG S3C24XX SoCs Support
//修改为下面所示:
*** S3C24XX SoCs *** │ │
│ │ [ ] SAMSUNG S3C2410 │ │
│ │ [ ] SAMSUNG S3C2412 │ │
│ │ [ ] SAMSUNG S3C2416/S3C2450 │ │
│ │ [*] SAMSUNG S3C2440 │ │
│ │ [ ] SAMSUNG S3C2442 │ │
│ │ [ ] SAMSUNG S3C2443 │ │
│ │ *** S3C2440 Boards *** │ │
│ │ [ ] Simtec Electronics ANUBIS │ │
│ │ [ ] Avantech AT2440EVB development board │ │
│ │ [*] MINI2440 development board │ │
│ │ [ ] NexVision NEXCODER 2440 Light Board │ │
│ │ [ ] Simtec IM2440D20 (OSIRIS) module │ │
│ │ [ ] HP iPAQ rx3715 │ │
│ │ [*] SMDK2440 │ │
│ │ [*] SMDK2440 with S3C2440 CPU module


//裁剪无关的文件系统ext2、ext3、ext4
//重新make menuconfig,进入File systems,去掉:
< > Second extended fs support //ext2
< > Ext3 journalling file system support
< > The Extended 4 (ext4) filesystem

//裁剪光盘文件系统CD-ROM
//进入File systems---> CD-ROM/DVD Filesystems,去掉:
< > ISO 9660 CDROM file system support


//裁剪不常用的杂项文件系统
//进入File systems---> Miscellaneous filesystems,去掉:
< > Compressed ROM file system support (cramfs) // cramfs压缩文件系统
[ ] Include support for ZLIB compressed file systems //zlib压缩文件系统
< > ROM file system support // Romfs


//裁剪掉PS2鼠标驱动:
//重新make menuconfig,进入Device Drivers-> Input device support,去掉:
[ ] Provide legacy /dev/psaux device //PS2鼠标鼠标指向的鼠标设备文件
[ ] Mice ---> //其它各种鼠标驱动,包括PS2鼠标、I2C鼠标、触摸板等
[ ] Keyboards

 


//接下来裁剪内核模块
make menuconfig
1)去掉CONFIG_TOUCHSCREEN_USB
-> Device Drivers
-> Input device support
-> Generic input layer
-> Touchscreens
<*> Samsung S3C2410/generic touchscreen input driver //加上自带的触摸屏驱动
< > USB Touchscreen Driver //去掉USB触摸屏驱动
2)去掉CONFIG_SSB_POSSIBLE
该宏是被别的选项设置,所以去掉不了:

3)去掉CONFIG_BCMA_POSSIBLE
该宏也没找到,所以去掉不了

4)去掉CONFIG_SND_USB
-> Device Drivers
-> Sound card support
-> Advanced Linux Sound Architecture
[ ] USB sound devices //去掉USB声卡驱动

5)去掉CONFIG_USB_LIBUSUAL
-> Device Drivers
-> USB support
[ ] The shared table of common (or usual) storage devices

 

//修改完成,编译内核
make uImage
cp arch/arm/boot/uImage /work/nfs_root/uImage_new

 

在u-boot-2012.04.01/include/configs/smdk2440.h文件中修改
#define MTDPARTS_DEFAULT "mtdparts=mini2440-0:256k(u-boot)," \
"128k(params)," \
"2m(kernel)," \
"-(rootfs)"
改为
#define MTDPARTS_DEFAULT "mtdparts=mini2440-0:256k(u-boot)," \
"128k(params)," \
"4m(kernel)," \
"-(rootfs)"
//内核分区2m改为4m,重新make
//生成新的u-boot.bin,并复制到PC机

 


//制作了u-boot_new.bin, uImage_new, fs_mini_mdev_new.yaffs
//重新烧写整个系统
//1.使用eop工具烧写u-boot
cmd
d:
cd /work
oflash u-boot_2012_180330_MINI2440.bin
0.openjtag
1.s4c2440
0.nand flash
0.nand flash program
0.烧录到0地址
等待烧录完成

或使用uboot-1.1.6的tftp来更新自己:
tftp 30000000 u-boot_2012_180330_mini2440.bin; nand erase.part u-boot; nand write 30000000 u-boot
启动uboot,用它来烧写内核、FS
tftp 30000000 uImage_new; nand erase.part kernel; nand write 30000000 kernel
tftp 30000000 fs_mini_mdev_new.yaffs2; nand erase.part rootfs; nand write.yaffs 30000000 460000 $filesize

或使用u-boot-1.1.6的nfs烧写
nfs 30000000 192.168.31.202:/work/nfs_root/u-boot_2012_180330_mini2440.bin
nand erase u-boot
nand write 30000000 u-boot


然后烧录yaffs2
reset
nfs 30000000 192.168.31.202:/work/nfs_root/fs_mini_mdev_new.yaffs2
nand erase.part rootfs
nand write.yaffs 30000000 260000 $filesize
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
save

然后烧录内核
nfs 32000000 192.168.31.202:/work/nfs_root/uImage_new
bootm 32000000


设置参数
set 'nand read 30000000 kernel;bootm 30000000'
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
set mtdparts 'mtdparts=mini2440-0:256k(u-boot),128k(params),4m(kernel),-(rootfs)'
set machid 16a
save
reset

 

 

 

6.给内核制作补丁

制作补丁之前,首先需要make distclean清除所有的配置文件,也包括了menuconfig菜单

而menuconfig菜单是通过读取.config文件来生成的.

所以我们需要保存.config文件

步骤如下:
cd /work/system/linux-3.4.2
cp .config config_ok //保存到config_ok文件
make distclean
cd ..
mv linux-3.4.2 linux-3.4.2_mini2440 //更改文件名
tar -xjf linux-3.4.2.tar.bz2 //解压需要比较的源文件
diff -urN linux-3.4.2 linux-3.4.2_mini2440 > linux-3.4.2_mini2440.patch //生成补丁文件linux-3.4.2_mini2440.patch

 

 

使用内核补丁:
cd /work/system/linux-3.4.2
patch -p1 < ../linux-3.4.2_mini2440.patch
cp config_ok .config

make uImage
cp arch/arm/boot/uImage /work/nfs_root/uImage_new //复制uImage到/work/nfs_root目录下