real6410移植linux2.6.39.4内核(2)-添加nand flash驱动及启动cramfs文件系统

real6410移植linux2.6.39.4内核(2)-添加nand flash驱动及启动cramfs文件系统


又经过了一天的奋战,搜索了无数资料,今天终于VFS: Mounted root (cramfs filesystem) 了 ,这句话的意思就是说内核已近发现了cramfs文件系统,之前一直有的问题就是当我修改内核启动参数使其从cramfs启动后,总是出现这种提示
VFS: Cannot open root device "mtdblock0" or unknown-block(31,0)
意思就是根文件系统根本就没有被挂在成功。所以当看到VFS: Mounted root (cramfs filesystem)提示后,我觉得nand flash应该已近成功了吧!下面记录一下详细的移植步骤.


PS.这里记录的都是我弄成功的步骤,显然不会这么容易的自己就OK了,在这一天里我遇到了很多各种各样的提示,甚至有些提示根本就不懂是哪里出了问题。反正自己知道肯定是nand flash出的问题,就慢慢修改.


1.在/arch/arm/mach-s3c64xx/mach-real6410.c中添加如下内容(nand flash的分区信息)
(我是从real官方给出的2.6.36内核中的改文件中提取出来的)


/* MMC/SD config */
static struct s3c_sdhci_platdata real6410_hsmmc0_pdata = {
.max_width      = 4,
.cd_type        = S3C_SDHCI_CD_INTERNAL,
};
static struct s3c_sdhci_platdata real6410_hsmmc1_pdata = {
.max_width      = 4,
.cd_type        = S3C_SDHCI_CD_PERMANENT,
};
/* Nand flash */
struct mtd_partition real6410_nand_part[] = {
#if 0
{
.name = "Bootloader",
.offset = 0,
.size = (256*SZ_1K),
.mask_flags = MTD_CAP_NANDFLASH,
},
{
.name = "Kernel",
.offset = (256*SZ_1K),
.size = (4*SZ_1M) - (256*SZ_1K),
.mask_flags = MTD_CAP_NANDFLASH,
},
#endif
{
.name = "cramfs",
.offset = (4*SZ_1M),
.size = (5*SZ_1M),
},
{
.name = "ubifs",
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL,
}
};

2.至于其他的教程中有的说要添加下面内容


staticstruct s3c2410_nand_set real6410_nand_sets[] = {
[0]= {
.name ="nand",
.nr_chips =1,
.nr_partitions =ARRAY_SIZE(real6410_nand_part),
.partitions =real6410_nand_part,
},
};
staticstruct s3c2410_platform_nand real6410_nand_info ={
.tacls =25,
.twrph0 =55,
.twrph1 =40,
.nr_sets =ARRAY_SIZE(real6410_nand_sets),
.sets =real6410_nand_sets,
};
但是 我的是最新内核里面包含了一个real6410的班级支持,如果你移植的内核没有的话
就必须自己添加了,上面的real6410_nand_info结构体的得数据是读写nand的时钟信息,
在S3C6410手册中查找到的数据,所以这些信息都有,就不用重复添加,只需第一步的
修改分区信息就行了。


3.注册nand flash 驱动


在static void __init real6410_machine_init(void)函数中添加如下:
s3c_nand_set_platdata(&real6410_nand_info);
这样内核在运行的时候就会去加载上面的分区信息。

4.为内核添加nandflash设备驱动


当然我本来是想自己编写这驱动的,但是我得选了解一下整个内核的移植过程,等了解
以后再逐一的来学习编写这些平台驱动程序,不然调试都不知道是步骤问题、内核配置
问题、还是自己写的驱动问题,所以现在我使用官方的驱动程序来移植。
a.拷贝s3c_nand.c(该文件我是从real官方的2.6.36内核drivers/mtd/nand/文件夹中
 提取出来的)到linux-2.6.39.4/drivers/mtd/nand/目录下。
b.当然只这样拷贝了对内核来说不起任何作用,内核根本不会去编译它,所以现在需要
 修改drivers/mtd/nand/目录下的配置文件Kconfig和Makfile告知内核来编译s3c_nand.c驱
 动程序文件。
c.在Kconfig中添加如下信息,这样在内核配置的menuconfig中就能看到选项了:
config MTD_NAND_S3C
tristate "NAND Flash support for S3C SoC"
depends on (ARCH_S3C64XX || ARCH_S5P64XX || ARCH_S5PC1XX) && MTD_NAND
help
 This enables the NAND flash controller on the S3C.


 No board specfic support is done by this driver, each board
 must advertise a platform_device for the driver to attach.


config MTD_NAND_S3C_DEBUG
bool "S3C NAND driver debug"
depends on MTD_NAND_S3C
help
 Enable debugging of the S3C NAND driver


config MTD_NAND_S3C_HWECC
bool "S3C NAND Hardware ECC"
depends on MTD_NAND_S3C
help
 Enable the use of the S3C's internal ECC generator when
 using NAND. Early versions of the chip have had problems with
 incorrect ECC generation, and if using these, the default of
 software ECC is preferable.


 If you lay down a device with the hardware ECC, then you will
 currently not be able to switch to software, as there is no
 implementation for ECC method used by the S3C
d.然后在Makefile中添加如下信息:
obj-$(CONFIG_MTD_NAND_S3C)        += s3c_nand.o
e.然后#make menuconfig中配置如下
System Type->
DEIVER DEIVERs->
Memory Technology Device(MTD) support->
NAND Device Support-->
NAND Flsah support for S3C SoC(该选项选中后会太难出两个新的都一起选中)
这样就配置配刚刚添加的NAND FLASH驱动了。

5.编译内核#make bzImage遇到的ERROR


此时编译器编译到s3c_nand.o时,会出现很多类似于未定义错误。
那是因为还没有给6410的nand flash寄存器定义,但是在s3c_nand中使用了。
然后我就对着real官方的2.6.36内核的s3c_nand.c文件中的包含的头文件
挨着挨着一个一个的对着找,结果是在
#include <plat/regs-nand.h>头文件中定义了这些宏。然后我将其复制到
我的2.6.39.4内核中的同一文件内。

解决方法如下:
在arch/arm/plat-samsung/include/plat/regs-nand.h中添加

/* for s3c_nand.c */
#define S3C_NFCONF S3C2410_NFREG(0x00)
#define S3C_NFCONT S3C2410_NFREG(0x04)
#define S3C_NFCMMD S3C2410_NFREG(0x08)
#define S3C_NFADDR S3C2410_NFREG(0x0c)
#define S3C_NFDATA8 S3C2410_NFREG(0x10)
#define S3C_NFDATA S3C2410_NFREG(0x10)
#define S3C_NFMECCDATA0 S3C2410_NFREG(0x14)
#define S3C_NFMECCDATA1 S3C2410_NFREG(0x18)
#define S3C_NFSECCDATA S3C2410_NFREG(0x1c)
#define S3C_NFSBLK S3C2410_NFREG(0x20)
#define S3C_NFEBLK S3C2410_NFREG(0x24)
#define S3C_NFSTAT S3C2410_NFREG(0x28)
#define S3C_NFMECCERR0 S3C2410_NFREG(0x2c)
#define S3C_NFMECCERR1 S3C2410_NFREG(0x30)
#define S3C_NFMECC0 S3C2410_NFREG(0x34)
#define S3C_NFMECC1 S3C2410_NFREG(0x38)
#define S3C_NFSECC S3C2410_NFREG(0x3c)
#define S3C_NFMLCBITPT S3C2410_NFREG(0x40)


#define S3C_NFCONF_NANDBOOT (1<<31)
#define S3C_NFCONF_ECCCLKCON (1<<30)
#define S3C_NFCONF_ECC_MLC (1<<24)
#define S3C_NFCONF_ECC_1BIT (0<<23)
#define S3C_NFCONF_ECC_4BIT (2<<23)
#define S3C_NFCONF_ECC_8BIT (1<<23)
#define S3C_NFCONF_TACLS(x) ((x)<<12)
#define S3C_NFCONF_TWRPH0(x) ((x)<<8)
#define S3C_NFCONF_TWRPH1(x) ((x)<<4)
#define S3C_NFCONF_ADVFLASH (1<<3)
#define S3C_NFCONF_PAGESIZE (1<<2)
#define S3C_NFCONF_ADDRCYCLE (1<<1)
#define S3C_NFCONF_BUSWIDTH (1<<0)


#define S3C_NFCONT_ECC_ENC (1<<18)
#define S3C_NFCONT_LOCKTGHT (1<<17)
#define S3C_NFCONT_LOCKSOFT (1<<16)
#define S3C_NFCONT_MECCLOCK (1<<7)
#define S3C_NFCONT_SECCLOCK (1<<6)
#define S3C_NFCONT_INITMECC (1<<5)
#define S3C_NFCONT_INITSECC (1<<4)
#define S3C_NFCONT_nFCE1 (1<<2)
#define S3C_NFCONT_nFCE0 (1<<1)
#define S3C_NFCONT_INITECC (S3C_NFCONT_INITSECC | S3C_NFCONT_INITMECC)


#define S3C_NFSTAT_ECCENCDONE (1<<7)
#define S3C_NFSTAT_ECCDECDONE (1<<6)
#define S3C_NFSTAT_BUSY (1<<0)


#define S3C_NFECCERR0_ECCBUSY (1<<31)


6.修改内核启动参数
setenv bootargs noinitrd root=/dev/mtdblock0 console=ttySAC0 init=/linuxrc video=fb:WX4300F 
上面的参数是从real的linux使用手册中得知的。

7.再次编译内核


此时没有再报错了,zImage生成了,然后我下载进开发板,cramfs挂载成功。


Starting kernel ...




Uncompressing Linux... done, booting the kernel.
Linux version 2.6.39.4-heyong@yifan (root@yifan) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #16 Fri Mar 23 17:58:51 CST 2012
CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387f
CPU: VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: REAL6410
Memory policy: ECC disabled, Data cache writeback
CPU S3C6410 (id 0x36410101)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
camera: no parent clock specified
S3C64XX: PLL settings, A=532000000, M=532000000, E=24000000
S3C64XX: HCLK2=266000000, HCLK=133000000, PCLK=66500000
mout_apll: source is fout_apll (1), rate is 532000000
mout_epll: source is epll (1), rate is 24000000
mout_mpll: source is mpll (1), rate is 532000000
mmc_bus: source is mout_epll (0), rate is 24000000
mmc_bus: source is mout_epll (0), rate is 24000000
mmc_bus: source is mout_epll (0), rate is 24000000
usb-bus-host: source is clk_48m (0), rate is 48000000
uclk1: source is dout_mpll (1), rate is 66500000
spi-bus: source is mout_epll (0), rate is 24000000
spi-bus: source is mout_epll (0), rate is 24000000
audio-bus: source is mout_epll (0), rate is 24000000
audio-bus: source is mout_epll (0), rate is 24000000
audio-bus: source is mout_epll (0), rate is 24000000
irda-bus: source is mout_epll (0), rate is 24000000
camera: no parent clock specified
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 65024
Kernel command line: noinitrd root=/dev/mtdblock0 console=ttySAC0 init=linuxrc video=fb:WX4300F
PID hash table entries: 1024 (order: 0, 4096 bytes)
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 256MB = 256MB total
Memory: 256448k/256448k available, 5696k reserved, 0K highmem
Virtual kernel memory layout:
vector  : 0xffff0000 - 0xffff1000   (   4 kB)
fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
DMA     : 0xff600000 - 0xffe00000   (   8 MB)
vmalloc : 0xd0800000 - 0xf6000000   ( 600 MB)
lowmem  : 0xc0000000 - 0xd0000000   ( 256 MB)
modules : 0xbf000000 - 0xc0000000   (  16 MB)
 .init : 0xc0008000 - 0xc0025000   ( 116 kB)
 .text : 0xc0025000 - 0xc02f49b8   (2879 kB)
 .data : 0xc02f6000 - 0xc031a240   ( 145 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:246
VIC @f6000000: id 0x00041192, vendor 0x41
VIC @f6010000: id 0x00041192, vendor 0x41
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 528.79 BogoMIPS (lpj=2643968)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
REAL6410: Option string real6410=0
REAL6410: selected LCD display is 480x272
s3c64xx_dma_init: Registering DMA channels
PL080: IRQ 73, at d0808000, channels 0..8
PL080: IRQ 74, at d080c000, channels 8..16
S3C6410: Initialising architecture
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
ROMFS MTD (C) 2007 Red Hat, Inc.
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
start plist test
end plist test
s3c-fb s3c-fb: window 0: fb 
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
s3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 16) is a S3C6400/10
s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 20) is a S3C6400/10
s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 24) is a S3C6400/10
s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 28) is a S3C6400/10
brd: module loaded
loop: module loaded
S3C NAND Driver, (c) 2008 Samsung Electronics
S3C NAND Driver is using hardware ECC.
NAND device: Manufacturer ID: 0xec, Chip ID: 0xd3 (Samsung NAND 1GiB 3,3V 8-bit)
Creating 2 MTD partitions on "NAND 1GiB 3,3V 8-bit":
0x000000400000-0x000000900000 : "cramfs"
0x000000900000-0x000040000000 : "ubifs"
No valid DiskOnChip devices found
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
[nandsim] warning: read_byte: unexpected data output cycle, state is STATE_READY return 0x0
NAND device: Manufacturer ID: 0x98, Chip ID: 0x39 (Toshiba NAND 8MiB 1,8V 8-bit)
flash size: 8 MiB
page size: 512 bytes
OOB area size: 16 bytes
sector size: 8 KiB
pages number: 16384
pages per sector: 16
bus width: 8
bits in sector size: 13
bits in page size: 9
bits in OOB size: 4
flash size with OOB: 8448 KiB
page address bytes: 3
sector address bytes: 2
options: 0x62
Scanning device for bad blocks
Creating 1 MTD partitions on "NAND 8MiB 1,8V 8-bit":
0x000000000000-0x000000800000 : "NAND simulator partition 0"
GPIO NAND driver, 漏 2004 Simtec Electronics
usbcore: registered new interface driver alauda
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 79, io mem 0x74300000
s3c2410-ohci s3c2410-ohci: init err (00000000 0000)
ohci_hcd: can't start s3c24xx
s3c2410-ohci s3c2410-ohci: startup error -75
s3c2410-ohci s3c2410-ohci: USB bus 1 deregistered
s3c2410-ohci: probe of s3c2410-ohci failed with error -75
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdhci s3c-sdhci.0: clock source 0: hsmmc (133000000 Hz)
s3c-sdhci s3c-sdhci.0: clock source 1: hsmmc (133000000 Hz)
s3c-sdhci s3c-sdhci.0: clock source 2: mmc_bus (24000000 Hz)
mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using ADMA
s3c-sdhci s3c-sdhci.1: clock source 0: hsmmc (133000000 Hz)
s3c-sdhci s3c-sdhci.1: clock source 1: hsmmc (133000000 Hz)
s3c-sdhci s3c-sdhci.1: clock source 2: mmc_bus (24000000 Hz)
mmc0: mmc_rescan_try_freq: trying to init card at 400000 Hz
mmc1: SDHCI controller on samsung-hsmmc [s3c-sdhci.1] using ADMA
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
mmc0: mmc_rescan_try_freq: trying to init card at 300000 Hz
cramfs: empty filesystem
VFS: Mounted root (cramfs filesystem) readonly on device 31:0.
(这句应该就能说明挂载成功了,后面的错误在慢慢解决)
Freeing init memory: 116K
Failed to execute linuxrc.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.


















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值