玩了一段时间裸板开发,u-boot也移植好了,现在开始专注驱动开发,首先把linux最小系统搭建起来,移植网卡驱动,用NFS挂载文件系统,再完善其它驱动。
开发环境:
系统:ubuntu 10.04.4
单板:tq2440
NAND FLASH:K9F1216U0A 256MB
NOR Flash:EN29LV160AB 2MB
SDRAM:HY57V561620 x2 64MB
NET:DM9000AEP
编译器:arm-none-linux-gnueabi-
搭建开发环境详见ubuntu 10.04.4开发环境配置。
目标:
1.移植linux-3.0.62到单板,串口正常输出内核启动信息
2.移植网卡驱动
3.busybox制作最小文件系统
4.NFS挂载文件系统
一、移植linux-3.0.62到单板,串口正常输出内核启动信息
1.下载源码
linux源码https://www.kernel.org/pub/linux/kernel/v3.0/ 下载linux-3.0.62.tar.bz2。
获取交叉编译链 http://code.google.com/p/smp-on-qemu/downloads/list 选择arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2并下载。然后在ubuntu下直接解压即可
2.配置、编译
首先修改根目录下Makefile:195
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
改为:其中/home/change/tools/arm-2009q3是我的解压路径
ARCH ?= arm
CROSS_COMPILE ?= /home/change/tools/arm-2009q3/bin/arm-none-linux-gnueabi-
change@change:~/Si/linux-3.0.62$ make s3c2410_defconfig
change@change:~/Si/linux-3.0.62$ make uImage
编译成功,烧写内核到单板,启动会提示machid error,Please check your kernel config and/or bootloader.并且供支持单板的id,其中0000016a SMDK2440,OK设置id
U-Boot 2012.04.01 (May 04 2013 - 15:32:54)
CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
TQ2440 # mtdpart
device nand0 <TQ2440-0>, # parts = 4
#: name size offset mask_flags
0: u-boot 0x00040000 0x00000000 0
1: params 0x00020000 0x00040000 0
2: kernel 0x00400000 0x00060000 0
3: rootfs 0x0fba0000 0x00460000 0
active partition: nand0,0 - (u-boot) 0x00040000 @ 0x00000000
defaults:
mtdids : nand0=TQ2440-0
mtdparts: mtdparts=TQ2440-0:256k(u-boot),128k(params),4M(kernel),-(rootfs)
TQ2440 # tftp 0x32000000 uImage
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:4d:e4:f4
could not establish link
Using dm9000 device
TFTP from server 172.16.1.132; our IP address is 172.16.1.111
Filename 'uImage'.
Load address: 0x32000000
Loading: #################################################################
#################################################################
###########################
done
Bytes transferred = 2297920 (231040 hex)
TQ2440 # nand erase.part kernel
NAND erase.part: device 0 offset 0x60000, size 0x400000
Erasing at 0x440000 -- 100% complete.
OK
TQ2440 # nand write 0x32000000 kernel
NAND write: device 0 offset 0x60000, size 0x400000
4194304 bytes written: OK
TQ2440 # set machid 16a
TQ2440 # boot
NAND read: device 0 offset 0x60000, size 0x400000
4194304 bytes read: OK
## Booting kernel from Legacy Image at 30000000 ...
Image Name: Linux-3.0.62
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2297856 Bytes = 2.2 MiB
Load Address: 30108000
Entry Point: 30108000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Using machid 0x16a from environment
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
8??腛s?浄''d??G寑8?惴Lc;儳`納[?竾腛s?嫥''凣矴硨€D$ttD##[#[莽c?[?掣柠Ъ荂7?<{劎t?3'媚
下面修改源码,新建Source Insight工程。看到编译的uImage这么大,顺便把我的u-boot分区kernel分大了点。出现乱码应该时钟问题。配置文件*_defconfig在arch/arm/configs,machid在include/generated/mach-types.h.修改arch/arm/mach-s3c2440/mach-smdk2440.c:163:
s3c24xx_init_clocks(16934400);改为s3c24xx_init_clocks(12000000);//TQ2440单板的晶振是12M
再次配置编译生成的uImage就能正常输出启动信息了。
二、修改单板源码
1.增加NAND分区
修改arch/arm/pla-s3c24xxt/common-smdk.c.根据以前u-boot分区修改,将NAND分区改为如下
/* NAND parititon from 2.4.18-swl5 */
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "u-boot",
.size = SZ_256K,
.offset = 0,
},
[1] = {
.name = "u-boot-env",
.offset = SZ_256K,
.size = SZ_128K,
},
[2] = {
.name = "kernel",
.offset = SZ_256K + SZ_128K,
.size = SZ_4M,
},
[3] = {
.name = "rootfs",
.offset = SZ_256K + SZ_128K + SZ_4M,
.size = MTDPART_SIZ_FULL,
}
};
2.DM9000支持
其实现在linux内核自带DM9000网卡驱动,我们只需要配置即可,谈不上什么移植,参考别人代码修改eg:mach-mini2440.c。修改arch/arm/mach-s3c2440/mach-smdk2440.c.从mach-mini2440.c拷贝DM9000部分程序,并修改为TQ2440.
#include <linux/dm9000.h>
#define MACH_TQ2440_DM9K_BASE (S3C2410_CS4 + 0x300)
/* DM9000AEP 10/100 ethernet controller */
static struct resource TQ2440_dm9k_resource[] = {
[0] = {
.start = MACH_TQ2440_DM9K_BASE,
.end = MACH_TQ2440_DM9K_BASE + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = MACH_TQ2440_DM9K_BASE + 4,
.end = MACH_TQ2440_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 TQ2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
static struct platform_device TQ2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(TQ2440_dm9k_resource),
.resource = TQ2440_dm9k_resource,
.dev = {
.platform_data = &TQ2440_dm9k_pdata,
},
};
再将&TQ2440_device_eth,添加到static struct platform_device *smdk2440_devices[]
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&TQ2440_device_eth,
&s3c_device_nand,
};
开始编译,有问题再修改。make menuconfig 看到默认配置是支持DM9000的
change@change:~/Si/linux-3.0.62$ make uImage
编译成功,烧到NAND,内核启动输出如下
NAND read: device 0 offset 0x60000, size 0x400000
4194304 bytes read: OK
## Booting kernel from Legacy Image at 30000000 ...
Image Name: Linux-3.0.62
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2297764 Bytes = 2.2 MiB
Load Address: 30108000
Entry Point: 30108000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Using machid 0x16a from environment