【转帖】FL2440开发板内核移植笔记 | 希望这篇**,能为那些正在学习Linux内核移植的朋友提供参考。
本文转引自 飞凌嵌入式 FL2440技术交流专区 www.witech.com.cn,
感谢作者japleak的无私奉献。
参考:http://bbs.witech.com.cn/thread-468-1-1.html
宿主机:Redhat Linux AS4
目标机:s3c2440
交叉编译器:arm-linux-gcc-3.4.1
交叉编译器路径:/usr/local/arm/3.4.1
要移植的内核版本:linux-2.6.33
文件系统类型: yaffs2 (目前使用光盘中linux-2.6.28的文件系统touch.yaffs)
笔记作者:japleak
1、 下载内核linux-2.6.33.tar.gz(http://www.kernel.org/pub/linux/kernel/v2.6/linux-
2.6.33.tar.gz 中可以找到),然后还需要下载yaffs2文件系统,目的是为了给内核打补丁。下载地址
为:http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2.tar.gz?view=tar (此步骤很重要,如果
yaffs2不正确,可能引起无**常编译通过)。
2、 将下载的文件存放在/usr/src/中。
3、 分别解压缩:
[root@WEB188 src]# tar xzf linux-2.6.33.tar.gz
[root@WEB188 src]# tar xzf yaffs2.tar.gz
4、 为内核增加yaffs2补丁
[root@WEB188 src]# cd yaffs2
[root@WEB188 yaffs2]# ./patch-ker.sh c ../linux-2.6.33/
Updating ../linux-2.6.33//fs/Kconfig
Updating ../linux-2.6.33//fs/Makefile
5、 修改机器码。进入内核目录,修改机器码跟bootloader的机器码一致(FL2440为193)
[root@WEB188 yaffs2]# cd ../linux-2.6.33
[root@WEB188 linux-2.6.33]#vi arch/arm/tools/mach-types
首先删除以下行:
s3c2410 ARCH_S3C2410 S3C2410 182
然后将以下行:
s3c2440 ARCH_S3C2440 S3C2440 362
修改为:
s3c2440 ARCH_S3C2440 S3C2440 193
6、 指定目标板machine、编译器和编译器路径。修改Makefile文件,注意将CROSS_COMPILE对应到
你系统中交叉编译器地址
[root@WEB188 yaffs2]# vi Makefile
将两行:
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
修改为以下两行:
ARCH ?= arm
CROSS_COMPILE ?=/usr/local/arm/3.4.1/bin/arm-linux-
7、 增加devfs文件管理器的支持。
[root@WEB188 linux-2.6.33]# vi fs/Kconfig
找到以下行:
menu "Pseudo filesystems"
在此行后面增加以下内容:
config DEVFS_FS
bool "/dev file system support (OBSOLETE)"
default y
config DEVFS_MOUNT
bool "Automatically mount at boot"
default y
depends on DEVFS_FS
8、 修改晶振频率( 可解决打印信息乱码问题 )。修改文件arch/arm/mach-s3c2440/mach-
smdk2440.c
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2440/mach-smdk2440.c
将如下行:
s3c24xx_init_clocks(16934400);
修改为:
s3c24xx_init_clocks(12000000);
9、 修改MTD分区。打开文件arch/arm/plat-s3c24xx/common-smdk.c,此处注意两个地方:一、必
须跟bootloader分区一样,二、文件系统fs_yaffs必须在第4个分区,即索引号为3。其他一些分区信息
可以不要,如下:
[root@WEB188 linux-2.6.33]# vi arch/arm/plat-s3c24xx/common-smdk.c
找到static struct mtd_partition smdk_default_nand_part[]的结构体,将内容修改为:
[0] = {
.name = "boot",
.size = 0x00020000,
.offset = 0
},
[1] = {
.name = "bootParam",
.size = 0x00060000,
.offset = 0x00020000,
},
[2] = {
.name = "Kernel",
.size = 0x00300000,
.offset = 0x00500000,
},
[3] = {
.name = "fs_yaffs",
.size = 0x03c00000,
.offset = 0x00800000,
},
[4] = {
.name = "eboot",
.size = 0x00080000,
.offset = 0x04400000,
},
[5] = {
.name = "WINCE",
.size = 0x03b80000,
.offset = 0x04480000,
}
10、 关闭ECC校验。修改文件drivers/mtd/nand/s3c2410.c
[root@WEB188 linux-2.6.33]# vi drivers/mtd/nand/s3c2410.c
将以下行:
chip->ecc.mode = NAND_ECC_SOFT;
修改为:
chip->ecc.mode = NAND_ECC_NONE;
11、 修改nandflash驱动,支持K9F1G08的nandflash。文件为:drivers/mtd/nand/nand_bbt.c
[root@WEB188 linux-2.6.33]# vi drivers/mtd/nand/nand_bbt.c
将以下两个部分进行修改
static struct nand_bbt_descr largepage_memorybased = {
.options = 0,
.offs = 0,
.len = 1, //原始值为2,改成1
.pattern = scan_ff_pattern
};
static struct nand_bbt_descr largepage_flashbased = {
.options = NAND_BBT_SCAN2NDPAGE,
.offs = 0,
.len = 2, //原始值为2,改成1
.pattern = scan_ff_pattern
};
12、 把s3c2410的默认配置写入config文件(有的yaffs2可能会出错)。
[root@WEB188 linux-2.6.33]# make s3c2410_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/kxgettext.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
fs/yaffs2/Kconfig:179: unknown option "boot"
make[1]: *** [s3c2410_defconfig] 错误 1
make: *** [s3c2410_defconfig] 错误 2
13、 以上出现错误,主要是补丁造成,修改fs/yaffs2/Kconfig的179行,将boot改成bool,即改成
如下:
bool "Disable yaffs2 block refreshing"
[root@WEB188 linux-2.6.33]# make s3c2410_defconfig
#
# configuration written to .config
#
14、 配置内核,注意System Type中,S3C2440中只选择以下内容即可。
[root@WEB188 linux-2.6.33]# make menuconfig
配置CPU选项(记得跟S3C2440 Machines平级的其它以及子项都不选)
System Type --->
S3C2440 Machines --->
SMDK2440
SMDK2440 with S3C2440 CPU module
配置yaffs2选项
File systems --->
Miscellaneous filesystems --->
<*> YAFFS2 file system support
-*- 512 byte / page devices
-*- 2048 byte (or larger) / page devices
Autoselect yaffs2 format
Cache short names in RAM
15、 最后等着基本内核大功告成把。
[root@WEB188 linux-2.6.33]# make zImage
16、 移植USB host驱动,仅仅需要修改配置即可
[root@WEB188 linux-2.6.33]# make menuconfig
Device Drivers --->
USB support --->
{*} Support for Host-side USB
USB device filesystem (DEPRECATED)
USB device class-devices (DEPRECATED)
<*> OHCI HCD support
<*> USB Mass Storage support
HID Devices --->
{*} Generic HID support
/dev/hidraw raw HID device support
SCSI device support --->
<*> SCSI device support
legacy /proc/scsi/ support
<*> SCSI disk support
<*> SCSI tape support
17、 移植RTC驱动
[root@WEB188 linux-2.6.33]# make menuconfig
Device Drivers --->
<*> Real Time Clock --->
Set system time from RTC on startup and resume
(rtc0) RTC used to set the system time
[ ] RTC debug support
*** RTC interfaces ***
/sys/class/rtc/rtcN (sysfs)
/proc/driver/rtc (procfs for rtc0)
/dev/rtcN (character devices)
<*> Samsung S3C series SoC RTC
然后添加对设备的支持
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2440/mach-smdk2440.c
将smdk2440_devices增加一行&s3c_device_rtc,。最终效果如下:
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc,//新增的一行
};
18、 移植UDA1341驱动
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2440/mach-smdk2440.c
在开始添加头文件
#include <sound/s3c24xx_uda134x.h>
#include <mach/gpio-fns.h>
并在正文开始区增加:
static struct s3c24xx_uda134x_platform_data s3c24xx_uda134x_data = {
.l3_clk = S3C2410_GPB(4),
.l3_data = S3C2410_GPB(3),
.l3_mode = S3C2410_GPB(2),
.model = UDA134X_UDA1341,
};
static struct platform_device s3c24xx_uda134x = {
.name = "s3c24xx_uda134x",
.dev = {
.platform_data = &s3c24xx_uda134x_data,
}
};
将下面代码添加到平台中
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc,
&s3c24xx_uda134x,//增加这里
};
配置内核
[root@WEB188 linux-2.6.33]# make menuconfig
Device Drivers --->
<*> Sound card support --->
<*> Advanced Linux Sound Architecture --->
<*> OSS Mixer API
<*> OSS PCM (digital audio) API
OSS PCM (digital audio) API - Include plugin system
Support old ALSA API
Verbose procfs contents
Verbose printk
Generic sound devices --->
<*> ALSA for SoC audio support --->
<*> SoC Audio for the Samsung S3C24XX chips
<*> SoC I2S Audio support UDA134X wired to a S3C24XX
19、 移植DM9000驱动,修改 drivers/net/dm9000.c 文件
[root@WEB188 linux-2.6.33]# vi drivers/net/dm9000.c
#include <mach/regs-gpio.h>
#include <mach/irqs.h>
#include <mach/hardware.h>
在dm9000_probe 函数开始增加(注意是开始处,而不是函数上面):
unsigned char ne_def_eth_mac_addr[]={0x00,0x12,0x34,0x56,0x80,0x49};
static void *bwscon;
static void *gpfcon;
static void *extint0;
static void *intmsk;
#define BWSCON (0x48000000)
#define GPFCON (0x56000050)
#define EXTINT0 (0x56000088)
#define INTMSK (0x4A000008)
bwscon=ioremap_nocache(BWSCON,0x0000004);
gpfcon=ioremap_nocache(GPFCON,0x0000004);
extint0=ioremap_nocache(EXTINT0,0x0000004);
intmsk=ioremap_nocache(INTMSK,0x0000004);
writel(readl(bwscon)|0xc0000,bwscon);
writel( (readl(gpfcon) & ~(0x3 << 14)) | (0x2 << 14), gpfcon);
writel( readl(gpfcon) | (0x1 << 7), gpfcon); // Disable pull-up
writel( (readl(extint0) & ~(0xf << 28)) | (0x4 << 28), extint0); //rising edge
writel( (readl(intmsk)) & ~0x80, intmsk);
在这个函数最后修改以下位置
if (!is_valid_ether_addr(ndev->dev_addr)) {
/* try reading from mac */
mac_src = "chip";
for (i = 0; i < 6; i++)
//ndev->dev_addr = ior(db, i+DM9000_PAR);
ndev->dev_addr = ne_def_eth_mac_addr;//修改这里
}
修改arch/arm/mach-s3c2440/mach-smdk2440.c,添加设备
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc,
&s3c24xx_uda134x,
&s3c_device_dm9000,//此处添加
};
修改文件arch/arm/plat-s3c24xx/devs.c
[root@WEB188 linux-2.6.33]# vi arch/arm/plat-s3c24xx/devs.c
添加头文件:
#include <linux/dm9000.h>
以及以下信息:
static struct resource s3c_dm9000_resource[] = {
[0] = {
.start = S3C24XX_PA_DM9000,
.end = S3C24XX_PA_DM9000+ 0x3,
.flags = IORESOURCE_MEM
},
[1]={
.start = S3C24XX_PA_DM9000 + 0x4, //CMD pin is A2
.end = S3C24XX_PA_DM9000 + 0x4 + 0x7c,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ
},
};
static struct dm9000_plat_data s3c_device_dm9000_platdata = {
.flags= DM9000_PLATF_16BITONLY,
};
struct platform_device s3c_device_dm9000 = {
.name= "dm9000",
.id= 0,
.num_resources= ARRAY_SIZE(s3c_dm9000_resource),
.resource= s3c_dm9000_resource,
.dev= {
.platform_data = &s3c_device_dm9000_platdata,
}
};
EXPORT_SYMBOL(s3c_device_dm9000);
修改arch/arm/plat-s3c/include/plat/devs.h 45行附近,添加
[root@WEB188 linux-2.6.33]# vi arch/arm/plat-s3c/include/plat/devs.h
extern struct platform_device s3c_device_dm9000;
修改arch/arm/mach-s3c2410/include/mach/map.h
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2410/include/mach/map.h
新增
/* DM9000 */
#define S3C24XX_PA_DM9000 0x20000300
#define S3C24XX_VA_DM9000 0xE0000000
(如果无法发现网卡,请进行操作:)修改arch/arm/mach-s3c2410/mach-smdk2410.c在smdk2410_devices
增加以下行
&s3c_device_dm9000,
另外在static struct map_desc smdk2410_iodesc[] __initdata增加以下内容
[0] = {
.virtual = (unsigned long)S3C24XX_VA_DM9000,
.pfn = __phys_to_pfn(S3C24XX_PA_DM9000),
.length = SZ_1M,
.type = MT_DEVICE,
},
20、 移植LCD。打开文件arch/arm/mach-s3c2410/mach-smdk2410.c
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2410/mach-smdk2410.c
在以下两个结构体中static struct s3c2410fb_display smdk2440_lcd_cfg[] __initdata,static
struct s3c2410fb_mach_info smdk2440_fb_info __initdata,改成如下代码
static struct s3c2410fb_display smdk2440_lcd_cfg[] __initdata = {
{
/* Config for 320x240 LCD */
.lcdcon5 = S3C2410_LCDCON5_FRM565 |
S3C2410_LCDCON5_INVVLINE |
S3C2410_LCDCON5_INVVFRAME |
S3C2410_LCDCON5_PWREN |
S3C2410_LCDCON5_HWSWP,
.type = S3C2410_LCDCON1_TFT,
.width = 320,
.height = 240,
.pixclock = 270000,
.xres = 320,
.yres = 240,
.bpp = 16,
.left_margin = 8,
.right_margin = 5,
.hsync_len = 63,
.upper_margin = 15,
.lower_margin = 3,
.vsync_len
|
|