|
希望這篇文章,能為那些正在學(xué)習(xí)Linux內(nèi)核移植的朋友提供參考。
本文轉(zhuǎn)引自 飛凌嵌入式 FL2440技術(shù)交流專區(qū) www.witech.com.cn,
感謝作者japleak的無(wú)私奉獻(xiàn)。
參考:http://bbs.witech.com.cn/thread-468-1-1.html
宿主機(jī):Redhat Linux AS4
目標(biāo)機(jī):s3c2440
交叉編譯器:arm-linux-gcc-3.4.1
交叉編譯器路徑:/usr/local/arm/3.4.1
要移植的內(nèi)核版本:linux-2.6.33
文件系統(tǒng)類(lèi)型: yaffs2 (目前使用光盤(pán)中l(wèi)inux-2.6.28的文件系統(tǒng)touch.yaffs)
筆記作者:japleak
1、 下載內(nèi)核linux-2.6.33.tar.gz(http://www.kernel.org/pub/linux/kernel/v2.6/linux-
2.6.33.tar.gz 中可以找到),然后還需要下載yaffs2文件系統(tǒng),目的是為了給內(nèi)核打補(bǔ)丁。下載地址
為:http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2.tar.gz?view=tar (此步驟很重要,如果
yaffs2不正確,可能引起無(wú)法正常編譯通過(guò))。
2、 將下載的文件存放在/usr/src/中。
3、 分別解壓縮:
[root@WEB188 src]# tar xzf linux-2.6.33.tar.gz
[root@WEB188 src]# tar xzf yaffs2.tar.gz
4、 為內(nèi)核增加yaffs2補(bǔ)丁
[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、 修改機(jī)器碼。進(jìn)入內(nèi)核目錄,修改機(jī)器碼跟bootloader的機(jī)器碼一致(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、 指定目標(biāo)板machine、編譯器和編譯器路徑。修改Makefile文件,注意將CROSS_COMPILE對(duì)應(yīng)到
你系統(tǒng)中交叉編譯器地址
[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"
在此行后面增加以下內(nèi)容:
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、 修改晶振頻率( 可解決打印信息亂碼問(wèn)題 )。修改文件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分區(qū)。打開(kāi)文件arch/arm/plat-s3c24xx/common-smdk.c,此處注意兩個(gè)地方:一、必
須跟bootloader分區(qū)一樣,二、文件系統(tǒng)fs_yaffs必須在第4個(gè)分區(qū),即索引號(hào)為3。其他一些分區(qū)信息
可以不要,如下:
[root@WEB188 linux-2.6.33]# vi arch/arm/plat-s3c24xx/common-smdk.c
找到static struct mtd_partition smdk_default_nand_part[]的結(jié)構(gòu)體,將內(nèi)容修改為:
[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、 關(guān)閉ECC校驗(yàn)。修改文件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驅(qū)動(dòng),支持K9F1G08的nandflash。文件為:drivers/mtd/nand/nand_bbt.c
[root@WEB188 linux-2.6.33]# vi drivers/mtd/nand/nand_bbt.c
將以下兩個(gè)部分進(jìn)行修改
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的默認(rèn)配置寫(xiě)入config文件(有的yaffs2可能會(huì)出錯(cuò))。
[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] 錯(cuò)誤 1
make: *** [s3c2410_defconfig] 錯(cuò)誤 2
13、 以上出現(xiàn)錯(cuò)誤,主要是補(bǔ)丁造成,修改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、 配置內(nèi)核,注意System Type中,S3C2440中只選擇以下內(nèi)容即可。
[root@WEB188 linux-2.6.33]# make menuconfig
配置CPU選項(xiàng)(記得跟S3C2440 Machines平級(jí)的其它以及子項(xiàng)都不選)
System Type --->
S3C2440 Machines --->
SMDK2440
SMDK2440 with S3C2440 CPU module
配置yaffs2選項(xiàng)
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、 最后等著基本內(nèi)核大功告成把。
[root@WEB188 linux-2.6.33]# make zImage
16、 移植USB host驅(qū)動(dòng),僅僅需要修改配置即可
[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驅(qū)動(dòng)
[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
然后添加對(duì)設(shè)備的支持
[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驅(qū)動(dòng)
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2440/mach-smdk2440.c
在開(kāi)始添加頭文件
#include
#include
并在正文開(kāi)始區(qū)增加:
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,
}
};
將下面代碼添加到平臺(tái)中
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,//增加這里
};
配置內(nèi)核
[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驅(qū)動(dòng),修改 drivers/net/dm9000.c 文件
[root@WEB188 linux-2.6.33]# vi drivers/net/dm9000.c
#include
#include
#include
在dm9000_probe 函數(shù)開(kāi)始增加(注意是開(kāi)始處,而不是函數(shù)上面):
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);
在這個(gè)函數(shù)最后修改以下位置
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,添加設(shè)備
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
以及以下信息:
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
(如果無(wú)法發(fā)現(xiàn)網(wǎng)卡,請(qǐng)進(jìn)行操作:)修改arch/arm/mach-s3c2410/mach-smdk2410.c在smdk2410_devices
增加以下行
&s3c_device_dm9000,
另外在static struct map_desc smdk2410_iodesc[] __initdata增加以下內(nèi)容
[0] = {
.virtual = (unsigned long)S3C24XX_VA_DM9000,
.pfn = __phys_to_pfn(S3C24XX_PA_DM9000),
.length = SZ_1M,
.type = MT_DEVICE,
},
20、 移植LCD。打開(kāi)文件arch/arm/mach-s3c2410/mach-smdk2410.c
[root@WEB188 linux-2.6.33]# vi arch/arm/mach-s3c2410/mach-smdk2410.c
在以下兩個(gè)結(jié)構(gòu)體中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 = 5,
},
};
static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {
.displays = smdk2440_lcd_cfg,
.num_displays = ARRAY_SIZE(smdk2440_lcd_cfg),
.default_display = 0,
.lpcsel = 0,
} |
|