1、主機環境:VMare下Ubuntu10.04 ,1G內存。
2、編譯編譯環境:arm-linux-gcc
3、開發板:Micro2440,2M nor flash,256M nand flash。
4、u-boot-version:u-boot-2010.06
5、linux -version:Linux-2.6.39
一、下載並解壓內核源碼
a)在命令行終端中可以通過下列方式下載,當然用其它下載工具下載
root@bootloader:/home/eilian/development/Android#cd ../Linux
root@bootloader:/home/eilian/development/Linux# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.tar.gz
b)解壓源碼
root@bootloader:/home/eilian/development/Linux#
root@bootloader:/home/eilian/development/Linux# tar zxvf linux-2.6.39.tar.gz
root@bootloader:/home/eilian/development/Linux# ls
linux-2.6.32.2 linux-2.6.36.2.tar.gz linux-2.6.39 linux-2.6.39.tar.gz
root@bootloader:/home/eilian/development/Linux# cd linux-2.6.39
root@bootloader:/home/eilian/development/Linux/linux-2.6.39#
c)指定交叉編譯器
移植目的讓 Linux-2.6.39 可以在mini2440 上運行。首先,使得Linux-2.6.39的缺省目標平台成為ARM 的平台,修改主目錄下的Makefile。
用vi打開Makefile,定位到196行,修改如下:
root@bootloader:/home/eilian/development/Linux/linux-2.6.39# vi Makefile
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
# Architecture as present in compile.h
UTS_MACHINE := $(ARCH)
SRCARCH := $(ARCH)
修改完成後退出保存
/********************************************************************************************************************************/
d)創建目標平台
個性移植從SMDK2440到eilian240
root@bootloader:/home/eilian/development/Linux/linux-2.6.39#cd arch/arm/mach-s3c2440
root@bootloader:/home/eilian/development/Linux/linux-2.6.39/arch/arm/mach-s3c2440#cp mach-smd2440.c mach-eilian240.c
將mach-eilian240.c文件中的所有smdk2440改成eilian240
root@bootloader:/home/eilian/development/Linux/linux-2.6.39/arch/arm/mach-s3c2440#vi mach-eilian240.c
操作如下:在vi的命令模式下輸入
修改mach-s3c2440目錄下的Makefile,打開Makefile定位到38行做如下修改
obj-$(CONFIG_MACH_ANUBIS) += mach-anubis.o
obj-$(CONFIG_MACH_OSIRIS) += mach-osiris.o
obj-$(CONFIG_MACH_RX3715) += mach-rx3715.o
obj-$(CONFIG_ARCH_S3C2440) += mach-smdk2440.o
obj-$(CONFIG_MACH_NEXCODER_2440) += mach-nexcoder.o
obj-$(CONFIG_MACH_AT2440EVB) += mach-at2440evb.o
obj-$(CONFIG_MACH_MINI2440) += mach-mini2440.o
obj-$(CONFIG_MACH_NEO1973_GTA02) += mach-gta02.o
obj-$(CONFIG_MACH_RX1950) += mach-rx1950.o
obj-$(CONFIG_MACH_MINI2440) += mach-eilian240.o #為何這樣修改呢?後面慢慢解釋
修改mach-s3c2440目錄下的Kconfig 添加如下代碼
config MACH_MINI2440
bool "MINI2440 development board"
select CPU_S3C2440
select EEPROM_AT24
select NEW_LEDS
select LEDS_CLASS
select LEDS_TRIGGER
select LEDS_TRIGGER_BACKLIGHT
select S3C_DEV_NAND
select S3C_DEV_USB_HOST
help
Say Y here to select support for the MINI2440. Is a 10cm x 10cm board
available via various sources. It can come with a 3.5" or 7" touch LCD.
config MACH_EILIAN240
bool "eilian240 development board"
select CPU_S3C2440
select EEPROM_AT24
select NEW_LEDS
select LEDS_CLASS
select LEDS_TRIGGER
select LEDS_TRIGGER_BACKLIGHT
select S3C_DEV_NAND
select S3C_DEV_USB_HOST
help
Say Y here to select support for the eilian240. Is a 10cm x 10cm board
available via various sources. It can come with a 3.5" or 7" touch LCD.
這樣修改之後在選擇配置缺省文件的時候直接選擇mini2440_defconfig了
除此之外,還有一個地方需要改動,在eilian240_machine_init(void)函數中,把smdk_machine_init()函數調用注釋掉,因為我們後面會編寫自己的初始化函數,不需要調用smdk2440 原來的,同時修改時鐘頻率,修改如下:
static void __init eilian240_machine_init(void)
{
s3c24xx_fb_set_platdata(&eilian240_fb_info);
s3c_i2c0_set_platdata(NULL);
s3c_nand_set_platdata(&eilian240_nand_info);
platform_add_devices(eilian240_devices, ARRAY_SIZE(eilian240_devices));
// smdk_machine_init();
}
修改時鐘頻率
static void __init eilian240_map_io(void)
{
s3c24xx_init_io(eilian240_iodesc, ARRAY_SIZE(eilian240_iodesc));
s3c24xx_init_clocks(12000000);
s3c24xx_init_uarts(eilian240_uartcfgs, ARRAY_SIZE(eilian240_uartcfgs));
}
e)關於機器碼
首先,很關鍵的一點,內核在啟動時,是通過bootloader 傳入的機器碼(MACH_TYPE)確定應啟動哪種目標平台的。
打開/arch/arm/tools/mach-types 定位到最後一行添加機器碼(深藍色部分):
ctbu_gen2 MACH_CTBU_GEN2 CTBU_GEN2 3410
kmp_am17_01 MACH_KMP_AM17_01 KMP_AM17_01 3411
wtplug MACH_WTPLUG WTPLUG 3412
mx27su2 MACH_MX27SU2 MX27SU2 3413
nb31 MACH_NB31 NB31 3414
hjsdu MACH_HJSDU HJSDU 3415
td3_rev1 MACH_TD3_REV1 TD3_REV1 3416
eag_ci4000 MACH_EAG_CI4000 EAG_CI4000 3417
net5big_nand_v2 MACH_NET5BIG_NAND_V2 NET5BIG_NAND_V2 3418
cpx2 MACH_CPX2 CPX2 3419
net2big_nand_v2 MACH_NET2BIG_NAND_V2 NET2BIG_NAND_V2 3420
ecuv5 MACH_ECUV5 ECUV5 3421
hsgx6d MACH_HSGX6D HSGX6D 3422
dawad7 MACH_DAWAD7 DAWAD7 3423
sam9repeater MACH_SAM9REPEATER SAM9REPEATER 3424
eilian240 MACH_EILIAN240 EILIAN240 8000
在u-boot-2010.06/arch/arm/include/asm/mach-types.h 中定義相對應的機器碼,這裡注意這個機器碼是我自己移植UBOOT的時候定義的
#define MACH_TYPE_CAYENNE 2874
#define MACH_TYPE_FUJI 2875
#define MACH_TYPE_SYNOLOGY_6282 2876
#define MACH_TYPE_EM1SY 2877
#define MACH_TYPE_M502 2878
#define MACH_TYPE_MATRIX518 2879
#define MACH_TYPE_TINY_GURNARD 2880
#define MACH_TYPE_SPEAR1310 2881
#define MACH_TYPE_EILIAN240 8000
這需要兩者相匹配,如果內核的機器碼和bootloader 傳入的不匹配,就會經常出現下面的錯誤:
Uncompressing Linux................................................................................................................................. done, booting
the kernel. 不動了
接著修改linux-2.6.39/arch/arm/mach-s3c2440/eilian240.c定位到文件末尾處
notes:開發板運行後,在命令行終端輸入:cat /proc/cpuinfo 可以看到我們添加的開發板信息,當然這個信息可以定制成我們需要的信息。
f)內核配置菜單中的MINI2440 選項和實際代碼是如何關聯的
在開始移植其他驅動之前,了解一些看起來比較“神秘”的常識,那就是運行make menuconfig 時,內核配置菜單中的MINI2440 選項是如何出現的。
加載缺省文件因為在x86平台下下執行此操作,系統默認的是x86平台,操作如下:
root@bootloader:/home/eilian/development/Linux/linux-2.6.39#cp arch/arm/configs/mini2440_defconfig .config
root@bootloader:/home/eilian/development/Linux/linux-2.6.39#make menuconfig
出現下圖所示內核配置根菜單
按上下箭頭鍵移動到 System Type,按回車進入該子菜單,如圖
再找到S3C2440 Machines,按回車進入該子菜單,如圖
這樣明白上面修改Linux-2.6.39/arch/arm/mach-s3c2440/目錄下的Makefile和Kconfig為什麼那樣修改了吧。。
再打開 Linux-2.6.39/arch/arm/mach-s3c2440/Kconfig 看看
現在明白了吧“eilian240 development board”正是在這個Kconfig 文件中定義說明的,當然你可以根據自己的喜好改為其他顯示信息。這裡的顯示信息只是在內核配置菜單中出現的,記住“要讓選擇的配置實際起效,還需要根據此配置在Makefile 中添加相應的代碼文件”再次打開Makefile看看:
# Machine support這樣,配置文件就跟實際的代碼文件通過配置定義聯系在一起了,這裡的配置定義是“CONFIG_MACH_EILIAN240”,內核中還有很多類似的配置定義,並且有的配置定義還存在依賴關系,我們在此就不對它們詳細說明了,隨著對內核代碼結構的不斷熟悉,你就會逐漸學會分析和查找你所需要的各種配置和定義等。
g)移植Nand 驅動並更改分區信息(我總感覺NANDFLASH是linux設備驅動中比較復雜的了)
g.1:了解釋內核已經支持的NANDFLASH類型
Linux2.6.39 已經自帶了大部分Nand Flash 驅動,在linux-2.6.39/drivers/mtd/nand/nand_ids.c 文件中,定義了所支持的各種Nand Flash 類型
struct nand_flash_dev nand_flash_ids[] = {
#ifdef CONFIG_MTD_NAND_MUSEUM_IDS
{"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, 0},
{"NAND 2MiB 5V 8-bit", 0x64, 256, 2, 0x1000, 0},
{"NAND 4MiB 5V 8-bit", 0x6b, 512, 4, 0x2000, 0},
{"NAND 1MiB 3,3V 8-bit", 0xe8, 256, 1, 0x1000, 0},
{"NAND 1MiB 3,3V 8-bit", 0xec, 256, 1, 0x1000, 0},
{"NAND 2MiB 3,3V 8-bit", 0xea, 256, 2, 0x1000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xd5, 512, 4, 0x2000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, 0},
{"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, 0},
{"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, 0},
{"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, 0},
{"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, NAND_BUSWIDTH_16},
{"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, NAND_BUSWIDTH_16},
#endif
{"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, 0},
{"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, 0},
{"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, NAND_BUSWIDTH_16},
{"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, NAND_BUSWIDTH_16},
{"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, 0},
{"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, 0},
{"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, NAND_BUSWIDTH_16},
{"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, NAND_BUSWIDTH_16},
{"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, 0},
{"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, 0},
{"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, NAND_BUSWIDTH_16},
{"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0},
{"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0},
{"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0},
{"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0},
/*
* These are the new chips with large page size. The pagesize and the
* erasesize is determined from the extended id bytes,對於我們的是大頁的NANDFLASH
*/
#define LP_OPTIONS (NAND_SAMSUNG_LP_OPTIONS | NAND_NO_READRDY | NAND_NO_AUTOINCR)
#define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16)
/*512 Megabit */
{"NAND 64MiB 1,8V 8-bit", 0xA2, 0, 64, 0, LP_OPTIONS},
{"NAND 64MiB 1,8V 8-bit", 0xA0, 0, 64, 0, LP_OPTIONS},
{"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, LP_OPTIONS},
{"NAND 64MiB 3,3V 8-bit", 0xD0, 0, 64, 0, LP_OPTIONS},
{"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, LP_OPTIONS16},
{"NAND 64MiB 1,8V 16-bit", 0xB0, 0, 64, 0, LP_OPTIONS16},
{"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, LP_OPTIONS16},
{"NAND 64MiB 3,3V 16-bit", 0xC0, 0, 64, 0, LP_OPTIONS16},
/* 1 Gigabit */
{"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, LP_OPTIONS},
{"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, LP_OPTIONS},
{"NAND 128MiB 3,3V 8-bit", 0xD1, 0, 128, 0, LP_OPTIONS},
{"NAND 128MiB 1,8V 16-bit", 0xB1, 0, 128, 0, LP_OPTIONS16},
{"NAND 128MiB 3,3V 16-bit", 0xC1, 0, 128, 0, LP_OPTIONS16},
{"NAND 128MiB 1,8V 16-bit", 0xAD, 0, 128, 0, LP_OPTIONS16},
/* 2 Gigabit */
{"NAND 256MiB 1,8V 8-bit", 0xAA, 0, 256, 0, LP_OPTIONS},
{"NAND 256MiB 3,3V 8-bit", 0xDA, 0, 256, 0, LP_OPTIONS},
{"NAND 256MiB 1,8V 16-bit", 0xBA, 0, 256, 0, LP_OPTIONS16},
{"NAND 256MiB 3,3V 16-bit", 0xCA, 0, 256, 0, LP_OPTIONS16},
/* 4 Gigabit */
{"NAND 512MiB 1,8V 8-bit", 0xAC, 0, 512, 0, LP_OPTIONS},
{"NAND 512MiB 3,3V 8-bit", 0xDC, 0, 512, 0, LP_OPTIONS},
{"NAND 512MiB 1,8V 16-bit", 0xBC, 0, 512, 0, LP_OPTIONS16},
{"NAND 512MiB 3,3V 16-bit", 0xCC, 0, 512, 0, LP_OPTIONS16},
/* 8 Gigabit */
{"NAND 1GiB 1,8V 8-bit", 0xA3, 0, 1024, 0, LP_OPTIONS},
{"NAND 1GiB 3,3V 8-bit", 0xD3, 0, 1024, 0, LP_OPTIONS},
{"NAND 1GiB 1,8V 16-bit", 0xB3, 0, 1024, 0, LP_OPTIONS16},
{"NAND 1GiB 3,3V 16-bit", 0xC3, 0, 1024, 0, LP_OPTIONS16},
/* 16 Gigabit */
{"NAND 2GiB 1,8V 8-bit", 0xA5, 0, 2048, 0, LP_OPTIONS},
{"NAND 2GiB 3,3V 8-bit", 0xD5, 0, 2048, 0, LP_OPTIONS},
{"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, LP_OPTIONS16},
{"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, LP_OPTIONS16},
/* 32 Gigabit */
{"NAND 4GiB 1,8V 8-bit", 0xA7, 0, 4096, 0, LP_OPTIONS},
{"NAND 4GiB 3,3V 8-bit", 0xD7, 0, 4096, 0, LP_OPTIONS},
{"NAND 4GiB 1,8V 16-bit", 0xB7, 0, 4096, 0, LP_OPTIONS16},
{"NAND 4GiB 3,3V 16-bit", 0xC7, 0, 4096, 0, LP_OPTIONS16},
/* 64 Gigabit */
{"NAND 8GiB 1,8V 8-bit", 0xAE, 0, 8192, 0, LP_OPTIONS},
{"NAND 8GiB 3,3V 8-bit", 0xDE, 0, 8192, 0, LP_OPTIONS},
{"NAND 8GiB 1,8V 16-bit", 0xBE, 0, 8192, 0, LP_OPTIONS16},
{"NAND 8GiB 3,3V 16-bit", 0xCE, 0, 8192, 0, LP_OPTIONS16},
/* 128 Gigabit */
{"NAND 16GiB 1,8V 8-bit", 0x1A, 0, 16384, 0, LP_OPTIONS},
{"NAND 16GiB 3,3V 8-bit", 0x3A, 0, 16384, 0, LP_OPTIONS},
{"NAND 16GiB 1,8V 16-bit", 0x2A, 0, 16384, 0, LP_OPTIONS16},
{"NAND 16GiB 3,3V 16-bit", 0x4A, 0, 16384, 0, LP_OPTIONS16},
/* 256 Gigabit */
{"NAND 32GiB 1,8V 8-bit", 0x1C, 0, 32768, 0, LP_OPTIONS},
{"NAND 32GiB 3,3V 8-bit", 0x3C, 0, 32768, 0, LP_OPTIONS},
{"NAND 32GiB 1,8V 16-bit", 0x2C, 0, 32768, 0, LP_OPTIONS16},
{"NAND 32GiB 3,3V 16-bit", 0x4C, 0, 32768, 0, LP_OPTIONS16},
/* 512 Gigabit */
{"NAND 64GiB 1,8V 8-bit", 0x1E, 0, 65536, 0, LP_OPTIONS},
{"NAND 64GiB 3,3V 8-bit", 0x3E, 0, 65536, 0, LP_OPTIONS},
{"NAND 64GiB 1,8V 16-bit", 0x2E, 0, 65536, 0, LP_OPTIONS16},
{"NAND 64GiB 3,3V 16-bit", 0x4E, 0, 65536, 0, LP_OPTIONS16},
/*
* Renesas AND 1 Gigabit. Those chips do not support extended id and
* have a strange page/block layout ! The chosen minimum erasesize is
* 4 * 2 * 2048 = 16384 Byte, as those chips have an array of 4 page
* planes 1 block = 2 pages, but due to plane arrangement the blocks
* 0-3 consists of page 0 + 4,1 + 5, 2 + 6, 3 + 7 Anyway JFFS2 would
* increase the eraseblock size so we chose a combined one which can be
* erased in one go There are more speed improvements for reads and
* writes possible, but not implemented now
*/
{"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000,
NAND_IS_AND | NAND_NO_AUTOINCR |NAND_NO_READRDY | NAND_4PAGE_ARRAY |
BBT_AUTO_REFRESH
},
{NULL,}
};
/*
* Manufacturer ID list
*/
struct nand_manufacturers nand_manuf_ids[] = {
{NAND_MFR_TOSHIBA, "Toshiba"},
{NAND_MFR_SAMSUNG, "Samsung"},
{NAND_MFR_FUJITSU, "Fujitsu"},
{NAND_MFR_NATIONAL, "National"},
{NAND_MFR_RENESAS, "Renesas"},
{NAND_MFR_STMICRO, "ST Micro"},
{NAND_MFR_HYNIX, "Hynix"},
{NAND_MFR_MICRON, "Micron"},
{NAND_MFR_AMD, "AMD"},
{0x0, "Unknown"}
};
既然對於ARM920T的核,Linux內核已經對大部分的NANDFLASH完美支持了,那還需修改什麼呢?分區系統雖然對NANDFLASH進行了默認的分區,但這可能不是我們想要的,我們的分區得和UBOOT中對NANDFLASH的分區保持一致
g.2修改Nand Flash 分區表:那我怎麼知道如何分啊?參考系統默認的,那系統默認的分區又在那裡定義了?
對於S3C24XX這個CPU ,對於NANDFLASH這樣的平台設備打開arch/arm/plat-s3c24xx/comm-smdk.c
/* NAND parititon from 2.4.18-swl5 */
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "Boot Agent",
.size = SZ_16K,
.offset = 0,
},
[1] = {
.name = "S3C2410 flash partition 1",
.offset = 0,
.size = SZ_2M,
},
[2] = {
.name = "S3C2410 flash partition 2",
.offset = SZ_4M,
.size = SZ_4M,
},
[3] = {
.name = "S3C2410 flash partition 3",
.offset = SZ_8M,
.size = SZ_2M,
},
[4] = {
.name = "S3C2410 flash partition 4",
.offset = SZ_1M * 10,
.size = SZ_4M,
},
[5] = {
.name = "S3C2410 flash partition 5",
.offset = SZ_1M * 14,
.size = SZ_1M * 10,
},
[6] = {
.name = "S3C2410 flash partition 6",
.offset = SZ_1M * 24,
.size = SZ_1M * 24,
},
[7] = {
.name = "S3C2410 flash partition 7",
.offset = SZ_1M * 48,
.size = MTDPART_SIZ_FULL,
}
};
static struct s3c2410_nand_set smdk_nand_sets[] = {
[0] = {
.name = "NAND",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(smdk_default_nand_part),
.partitions = smdk_default_nand_part,
},
};
/* choose a set of timings which should suit most 512Mbit
* chips and beyond.
*/
static struct s3c2410_platform_nand smdk_nand_info = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(smdk_nand_sets),
.sets = smdk_nand_sets,
};
好了不多想了直接參考這個依葫蘆畫瓢的修改回到自己的板層文件
root@bootloader:/home/eilian/development/Linux/linux-2.6.39/arch/arm/mach-s3c2440#
打開mach-eilian240.c根據自己移植的UBOOT在裡面添加對NANDFLASH分區的代碼,代碼如下
/* NAND Flash on eilian240 board */
static struct mtd_partition eilian240_nand_part[] __initdata = {
[0] = {
.name = "bootloader",
.size = SZ_1M, //UBOOT大小1M
.offset = 0,
},
[1] = {
.name = "params", //存放參數
.size = SZ_128K,
.offset = SZ_1M,
},
[2] = {
.name = "kernel",
.size = 0x00500000,
.offset = SZ_1M + SZ_128K, //內核
},
[3] = {
.name = "root",
.offset = SZ_1M + SZ_128K + 0x00500000,//根文件系統
.size = 1024 * 1024 * 1024,
},
[4] = {
.name = "nand",
.offset = 0,
.size = SZ_256M, //整個NANDFLASH 可有可無
},
};
static struct s3c2410_nand_set eilian240_nand_sets[] __initdata = {
[0] = {
.name = "nand",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(eilian240_nand_part),
.partitions = eilian240_nand_part,
.flash_bbt = 1, /* we use u-boot to create a BBT */
},
};
static struct s3c2410_platform_nand eilian240_nand_info __initdata = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(eilian240_nand_sets),
.sets = eilian240_nand_sets,
.ignore_unset_ecc = 1,
};
將nand flash 設備注冊到系統中
static struct platform_device *eilian240_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand,
};
傳入eilian240_nand_info結構體��始化參數到內核中去
static void __init eilian240_machine_init(void)
{
s3c24xx_fb_set_platdata(&eilian240_fb_info);
s3c_i2c0_set_platdata(NULL);
s3c_nand_set_platdata(&eilian240_nand_info);
platform_add_devices(eilian240_devices, ARRAY_SIZE(eilian240_devices));
// smdk_machine_init();
}
加入必要的頭文件
/*********nand*****/
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>
#include <plat/nand.h>
/*********nand*****/
保存退出
h)編譯測試
root@bootloader:/home/eilian/development/Linux/linux-2.6.39# make uImage
等待很久!!!!!!!!
Kernel: arch/arm/boot/Image is ready
AS arch/arm/boot/compressed/head.o
GZIP arch/arm/boot/compressed/piggy.gzip
AS arch/arm/boot/compressed/piggy.gzip.o
CC arch/arm/boot/compressed/misc.o
CC arch/arm/boot/compressed/decompress.o
SHIPPED arch/arm/boot/compressed/lib1funcs.S
AS arch/arm/boot/compressed/lib1funcs.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-2.6.39
Created: Fri Dec 2 02:55:06 2011
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2144304 Bytes = 2094.05 kB = 2.04 MB
Load Address: 30008000
Entry Point: 30008000
Image arch/arm/boot/uImage is ready
root@bootloader:/home/eilian/development/Linux/linux-2.6.39# cparch/arm/boot/uImage /tftpboot
下載uImage到板子上運行
打開超級終端(我這已經將uboot燒入到NANDFLASH)
U-Boot 2010.06 (Nov 29 2011 - 21:13:28)
DRAM: 64 MiB
Flash: 512 KiB
NAND: dev_id = 218
NAND 256MiB 3,3V 8-bit256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Device nand0 not found!
Hit any key to stop autoboot: 0
bootloader# tftp 32000000 uImage
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at unknown: 0 mode
Using dm9000 device
TFTP from server 211.67.217.136; our IP address is 211.67.217.138
Filename 'uImage'.
Load address: 0x32000000
Loading: T #################T ################################################
#################################################################
#############################################################T ##T ##
#############################################T #################T ###
##T ###################T ############################################
##############T ############T ################################T #######T
#############################
done
Bytes transferred = 2144368 (20b870 hex)
bootloader# bootm 32000000
## Booting kernel from Legacy Image at 32000000 ...
Image Name: Linux-2.6.39
Created: 2011-12-01 18:55:06 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2144304 Bytes = 2 MiB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 2.6.39 (root@bootloader) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #1 Fri Dec 2 02:54:32 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: eilian240 development board
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0 mem=64M
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60464k/60464k available, 5072k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.init : 0xc0008000 - 0xc0029000 ( 132 kB)
.text : 0xc0029000 - 0xc03f7f30 (3900 kB)
.data : 0xc03f8000 - 0xc041bc80 ( 144 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.24.
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Creating 5 MTD partitions on "nand":
0x000000000000-0x000000100000 : "bootloader"
uncorrectable error :
0x000000100000-0x000000120000 : "params"
ftl_cs: FTL header not found.
0x000000120000-0x000000620000 : "kernel"
ftl_cs: FTL header not found.
0x000000620000-0x000040620000 : "root"
mtd: partition "root" extends beyond the end of device "nand" -- size truncated to 0xf9e0000
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "nand" -- size truncated to 0x10000000
uncorrectable error :
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
ALSA device list:
No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
Registering the dns_resolver key type
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
List of all partitions:
1f00 1024 mtdblock0 (driver?)
1f01 128 mtdblock1 (driver?)
1f02 5120 mtdblock2 (driver?)
1f03 255872 mtdblock3 (driver?)
1f04 262144 mtdblock4 (driver?) //因為沒有文件系統所以出錯啊
No filesystem could mount root, tried: ext3 cramfs vfat msdos romfs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)
[<c002e198>] (unwind_backtrace+0x0/0xec) from [<c02f9b08>] (panic+0x54/0x184)
[<c02f9b08>] (panic+0x54/0x184) from [<c0008e70>] (mount_block_root+0x1d0/0x210)
[<c0008e70>] (mount_block_root+0x1d0/0x210) from [<c0008f50>] (mount_root+0xa0/0xc0)
[<c0008f50>] (mount_root+0xa0/0xc0) from [<c00090d4>] (prepare_namespace+0x164/0x1bc)
[<c00090d4>] (prepare_namespace+0x164/0x1bc) from [<c0008400>] (kernel_init+0xfc/0x138)
[<c0008400>] (kernel_init+0xfc/0x138) from [<c002a7d4>] (kernel_thread_exit+0x0/0x8)
/*********************************************************************************************************************************
關注上面深藍色字體哈。。是否發現點什麼。。。