本文是基于韦东山视频的学习笔记
配置内核
需要修改默认的的 gcc 编译器,这里用的是gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)
vim Makefile
# 进去使用命令'/CROSS' 搜索到这两句
ARCH ?= ...
CROSS_COMPILE ?= ...
# 改为
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
用命令 find -name "*defconfig"
看下内核支持哪些板子的默认配置。
刚好找到s3c2410_defconfig
,就使用这个吧
#或者进去 /arch/arm/configs 目录找
@ubuntu:~/work/system/linux-3.4.2/arch/arm/configs$ ls *2440*
mini2440_defconfig
@ubuntu:~/work/system/linux-3.4.2/arch/arm/configs$ ls *2410*
s3c2410_defconfig
直接make s3c2410_defconfig
进行配置
然后make uImage
进行编译
利用nfs服务进行烧写,需要启动nfs服务
nfs启动可以参考最后一小节-> 最小根文件系统(未完)
修改machine ID
# 在u-boot执行命令
nfs 32000000 192.168.3.100:/home/rjm/mnt/uImage
bootm 32000000
.......
# 但是输出以下错误信息
Error: unrecognized/unsupported machine ID (r1 = 0x00654615).
Available machine support:
ID (hex) NAME
00000400 AML_M5900
0000014b Simtec-BAST
0000015b IPAQ-H1940
0000039f Acer-N35
00000290 Acer-N30
000002a8 Nex Vision - Otom 1.1
00000454 QT2410
000000c1 SMDK2410
000005b4 TCT_HAMMER
000001db Thorcom-VR1000
000005d2 JIVE
000003fe SMDK2413
000003f1 SMDK2412
00000377 S3C2413
00000474 VSTMS
00000695 SMDK2416
000002de Simtec-Anubis
00000707 AT2440EVB
000007cf MINI2440
000002a9 NexVision - Nexcoder 2440
0000034a Simtec-OSIRIS
00000250 IPAQ-RX3715
0000016a SMDK2440
00000518 GTA02
000003b8 HP iPAQ RX1950
0000043c SMDK2443
这里其实是机器 id 不匹配,其中 SMDK2440
为16a
我们就要设置为16a
,set machid 16a
把 uImage
烧进去后输出了错误信息Verifying Checksum ... Bad Data CRC
其实是因为u-boot配置的内核分区只有2m,但其实我们的内核是2m以上的
# 在内核目录
@ubuntu:~/work/system/linux-3.4.2_$ ls arch/arm/boot/ -l
...
-rw-rw-r-- 1 rjm rjm 2399696 Dec 16 06:23 uImage
...
# 进入u-boot 输入命令 print 输出配置信息
mtdparts=mtdparts=nandflash0:256k@0(bootloader),128k(params),2m(kernel),-(root)
# 改为
mtdparts=mtdparts=nandflash0:256k@0(bootloader),128k(params),3m(kernel),-(root)
修改内核时钟
可以看到有信息输出了,但是是乱码啊
需要修改arch/arm/mach-s3c24xx/mach-smdk2440.c
165: s3c24xx_init_clocks(16934400);
# 改为
165: s3c24xx_init_clocks(12000000);
配置支持yaffs2
再次输出错误信息 No filesystem could mount root
因为不支持yaffs2系统啊,那就支持他
# 下载yaffs2 补丁,并打进内核
git clone git://www.aleph1.co.uk/yaffs2
cd yaffs-dir
# 使用方法是 "./patch-ker.sh c m linux-tree"
./patch-ker.sh c m ~/work/system/linux-3.4.2
# 需要重新配置内核
make menuconfig
->File systems
-->Miscellaneous filesystems
--->yaffs2 file system support
make uImage
编译时有错误信息,其实是名字不适配内核而已,yaffs2文件是没有下划线的,但是内核里面有,所以改过来就好
fs/yaffs2/yaffs_vfs.c:2514: error: 'struct mtd_info' has no member named 'sync'
fs/yaffs2/yaffs_vfs.c:2515: error: 'struct mtd_info' has no member named 'sync'
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_internal_read_super':
fs/yaffs2/yaffs_vfs.c:2702: error: 'struct mtd_info' has no member named 'erase'
fs/yaffs2/yaffs_vfs.c:2703: error: 'struct mtd_info' has no member named 'read'
...
fs/yaffs2/yaffs_vfs.c:2967: warning: assignment makes pointer from integer without a cast
scripts/Makefile.build:307: recipe for target 'fs/yaffs2/yaffs_vfs.o' failed
make[2]: *** [fs/yaffs2/yaffs_vfs.o] Error 1
scripts/Makefile.build:443: recipe for target 'fs/yaffs2' failed
make[1]: *** [fs/yaffs2] Error 2
Makefile:945: recipe for target 'fs' failed
make: *** [fs] Error 2
...
# 还有一个函数名不对的,需要改过来
fs/yaffs2/yaffs_vfs.c:2967: error: implicit declaration of function 'd_alloc_root'
root = d_make_root(inode);
但是要改的地方比较多,这里直接给出改完的三个文件
- yaffs_mtdif1.c
- yaffs_mtdif2.c
- yaffs_vfs.c
参考->yaffs2补丁
然后还需要去内核配置支持yaffs2
系统和eabi
编译(因为gcc编译器是eabi的)
配置路径:
- yaffs2 -> File systems -> Miscellaneous filesystems -> [*] yaffs2 file system support
- Kernel Features -> [*] Use the ARM EABI to compile the kernel
修改分区
分区信息文件位于arch/arm/mach-s3c24xx/common-smdk.c
,把smdk_default_nand_part
改成以下所示。
/* NAND parititon from 2.4.18-swl5 */
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,
}
};
启动
最后编译,用以下网络命令启动
nfs 30000000 192.168.3.100:/home/rjm/mnt/fs_mini_mdev_new.yaffs2
nand erase.part rootfs
nand write.yaffs 30000000 260000 889bc0
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
nfs 32000000 192.168.3.100:/home/book/mnt/uImage_new
bootm 32000000
支持DM9000网卡
启动内核后执行命令ifconfig -a
,会发现没有网卡,那是因为还不支持网卡DM9000。
Please press Enter to activate this console.
/ # ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
事实上内核已经有支持DM9000的代码,在arch/arm/mach-s3c24xx/mach-mini2440.c
里面已经有相关平台设备platform_device
的代码了,复制去arch/arm/mach-s3c24xx/mach-smdk2440.c
加以修改就可以用了。
#include "common.h"
#define MACH_SMDK2440_DM9K_BASE (S3C2410_CS4 + 0x300)
...
...
/* DM9000AEP 10/100 ethernet controller */
static struct resource smdk2440_dm9k_resource[] = {
[0] = {
.start = MACH_SMDK2440_DM9K_BASE,
.end = MACH_SMDK2440_DM9K_BASE + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = MACH_SMDK2440_DM9K_BASE + 4,
.end = MACH_SMDK2440_DM9K_BASE + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};
/*
* The DM9000 has no eeprom, and it's MAC address is set by
* the bootloader before starting the kernel.
*/
static struct dm9000_plat_data smdk2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
static struct platform_device smdk2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(smdk2440_dm9k_resource),
.resource = smdk2440_dm9k_resource,
.dev = {
.platform_data = &smdk2440_dm9k_pdata,
},
};
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&smdk2440_device_eth,
};
一些驱动的简单移植
参考 -> 按键驱动移植到3.4.2内核