分类:
2012-07-04 09:00:23
原文地址:linux内核移植以及yaffs2文件系统的挂载 作者:自语的骆驼
Yaffs页结构说明 |
#gedit include/configs/my2440.h //添加到文件末尾即可 |
#define CONFIG_MTD_NAND_YAFFS2 1 //定义一个管理对Yaffs2支持的宏 //开启Nand Flash默认分区,注意此处的分区要和你的内核中的分区保持一致 |
②、在原来对Nand操作的命令集列表中添加Yaffs2对Nand的写命令,如下:
#gedit common/cmd_nand.c //在U_BOOT_CMD中添加 |
U_BOOT_CMD(nand, CONFIG_SYS_MAXARGS, 1, do_nand, //注意:这里只添加了yaffs2的写命令,因为我们只用u-boot下载(即写)功能,所以我们没有添加yaffs2读的命令
|
接着,在该文件中对nand操作的do_nand函数中添加yaffs2对nand的操作,如下:
if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) if (argc < 4) addr = (ulong)simple_strtoul(argv[2], NULL, 16); read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */ s = strchr(cmd, '.'); //添加yaffs2相关操作,注意该处又关联到nand_write_skip_bad函数 #if defined(CONFIG_MTD_NAND_YAFFS2) else if (!strcmp(s, ".oob")) if (read) printf(" %zu bytes %s: %s\n", size, read ? "read" : "written", ret ? "ERROR" : "OK"); return ret == 0 ? 0 : 1; |
#gedit include/linux/mtd/mtd.h //在mtd_info结构体中添加 |
#if defined(CONFIG_MTD_NAND_YAFFS2) |
#gedit drivers/mtd/nand/nand_util.c //在nand_write_skip_bad函数中添加 |
int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, u_char *buffer) #if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support if (((*length)%(nand->oobsize+nand->writesize)) != 0) datapages = *length/(datasize+oobsize); /* Reject writes, which are not page aligned */ len_incl_bad = get_len_incl_bad (nand, offset, *length); if ((offset + len_incl_bad) >= nand->size) { #if !defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support return rval; while (left_to_write > 0) { WATCHDOG_RESET (); if (nand_block_isbad (nand, offset & ~(nand->erasesize - 1))) { #if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support if (left_to_write < (nand->erasesize - block_offset)) printf("\rWriting at 0x%llx -- ",offset); //add yaffs2 file system support
left_to_write -= write_size; #if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support } return 0; |
#gedit drivers/mtd/nand/nand_base.c //在nand_write函数中添加 |
static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const uint8_t *buf)
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support int oldopsmode = 0; if(mtd->rw_oob==1) size_t oobsize = mtd->oobsize; uint8_t oobtemp[oobsize]; for(i = 0; i < (datapages); i++)
/* Do not allow reads past end of device */ nand_get_device(chip, mtd, FL_WRITING); chip->ops.len = len;
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support if(mtd->rw_oob!=1)
ret = nand_do_write_ops(mtd, to, &chip->ops); *retlen = chip->ops.retlen; nand_release_device(mtd);
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support chip->ops.mode = oldopsmode;
return ret; |
⑥、使用nand write[.yaffs2]命令把事前制作好的yaffs2文件系统下载到Nand Flash中(yaffs2文件系统的制作请参考:Linux-2.6.30.4在2440上的移植之文件系统),下载操作步骤和效果图如下:
tftp 0x30000000 root_mini.img //用tftp将yaffs2文件系统下载到内存的0x30000000位置 |
#mkdir my2440 |
#tar -zxvf cvs-root.tar.gz |
#cd linux-2.6.30.4 |
2.3 修改系统平台时钟为12MHz(即:12000000)
#gedit arch/arm/mach-s3c2440/mach-smdk2440.c |
2.4. 修改Nand Flash分区。这里只创建4个分区,其他多余的分区屏蔽掉
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "My2440 boot",
.size = 0x00040000,
.offset = 0,
},
[1] = {
.name = "param",
.offset = 0x00040000,
.size = 0x00020000,
},
[2] = {
.name = "M2440 kernel",
.offset = 0x00060000,
.size = 0x00200000,
},
[3] = {
.name = "YAFFS2",
.offset = 0x04000000,
.size = 0x04000000,
}
/*,
[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 = SZ_16M,
}*/
};
第1个分区放的是给u-boot,第2个分区给环境变量,第3个分区给linux内核,第4个分区是用来挂载yaffs2文件系统的(注意:.offset = 0x04000000这个值要与先前root_mini.img烧写的位置一致)切记!!!
2.5 配置内核选项
#make menuconfig |
首先加载s3c24xx系列的通用配置,然后在此基础上修改
各配置选项如下。这里只列出了要修改的项,其他的默认
boot option-->Default kernel command string
这里的挂载点很重要,结合前面的分区情况,我们需将内核启动参数设置为:(noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0)
File systems ---> |
#make zImage |
如果没有任何错误,编译出来的内核在arch/arm/boot/目录下,文件zImage即是,zImage文件是不能直接被 u--boot引导的,我们还需如下的修改。
使用: 中括号括起来的是可选的 mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image 选项: |
mkimage -n 'linux-2.6.30.4' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage uImage.img |
tftp 0x30000000 uImage.img //将uImage.img下载到内存0x30000000处 |
//设置启动参数,意思是将nand中0x60000-0x00200000(和kernel分区一致)的内容读到内存0x31000000中,然后用bootm命令来执行 set bootcmd 'nand read 0x31000000 0x60000 0x00200000;bootm 0x31000000' saveenv //保存设置 |
重启开发板,文件系统能够挂载成功了,里面还有些问题,但已无大碍,
显示如下信息:
U-Boot 2009.08 (11鏈?25 2011 - 17:01:47)
DRAM: 64 MB
Flash: 2 MB
NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
128 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0x60000, size 0x200000
2097152 bytes read: OK
## Booting kernel from Legacy Image at 31000000 ...
Image Name: linux-2.6.30.4
Created: 2011-11-25 1:30:11 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1874936 Bytes = 1.8 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux.............................................................
............................................................ done, booting the k
ernel.
Linux version 2.6.30.4 (root@localhost.localdomain) (gcc version 3.4.5) #1 Fri N
ov 25 09:27:02 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 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/mtdblock3 init=/linuxrc console=ttySAC0,
115200
NR_IRQS:85
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
console [ttySAC0] enabled
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: 60896KB available (3496K code, 316K data, 136K init, 0K highmem)
Calibrating delay loop... 50.38 BogoMIPS (lpj=125952)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 936 bytes
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
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
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (extended precision)
JFFS2 version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
yaffs Nov 25 2011 09:24:38 Installing.
msgmni has been set to 119
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
fb0: s3c2410fb frame buffer device
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
loop: module loaded
Uniform Multi-Platform E-IDE driver
ide-gd driver 1.18
ide-cd driver 5.00
Driver 'sd' needs updating - please use bus_type methods
dm9000 Ethernet Driver, V1.31
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bi
t)
Scanning device for bad blocks
Bad eraseblock 20 at 0x000000280000
Bad eraseblock 21 at 0x0000002a0000
Bad eraseblock 22 at 0x0000002c0000
Bad eraseblock 23 at 0x0000002e0000
Bad eraseblock 24 at 0x000000300000
Bad eraseblock 25 at 0x000000320000
Bad eraseblock 26 at 0x000000340000
Bad eraseblock 27 at 0x000000360000
Bad eraseblock 28 at 0x000000380000
Bad eraseblock 29 at 0x0000003a0000
Bad eraseblock 30 at 0x0000003c0000
Bad eraseblock 31 at 0x0000003e0000
Bad eraseblock 32 at 0x000000400000
Bad eraseblock 33 at 0x000000420000
Bad eraseblock 34 at 0x000000440000
Bad eraseblock 35 at 0x000000460000
Bad eraseblock 36 at 0x000000480000
Bad eraseblock 37 at 0x0000004a0000
Bad eraseblock 38 at 0x0000004c0000
Bad eraseblock 39 at 0x0000004e0000
Bad eraseblock 40 at 0x000000500000
Bad eraseblock 41 at 0x000000520000
Bad eraseblock 42 at 0x000000540000
Bad eraseblock 43 at 0x000000560000
Bad eraseblock 44 at 0x000000580000
Bad eraseblock 45 at 0x0000005a0000
Bad eraseblock 46 at 0x0000005c0000
Bad eraseblock 47 at 0x0000005e0000
Bad eraseblock 48 at 0x000000600000
Bad eraseblock 49 at 0x000000620000
Bad eraseblock 50 at 0x000000640000
Bad eraseblock 51 at 0x000000660000
Bad eraseblock 52 at 0x000000680000
Bad eraseblock 53 at 0x0000006a0000
Bad eraseblock 54 at 0x0000006c0000
Bad eraseblock 55 at 0x0000006e0000
Bad eraseblock 56 at 0x000000700000
Bad eraseblock 57 at 0x000000720000
Bad eraseblock 58 at 0x000000740000
Bad eraseblock 59 at 0x000000760000
Bad eraseblock 60 at 0x000000780000
Bad eraseblock 61 at 0x0000007a0000
Bad eraseblock 62 at 0x0000007c0000
Bad eraseblock 63 at 0x0000007e0000
Bad eraseblock 64 at 0x000000800000
Bad eraseblock 65 at 0x000000820000
Bad eraseblock 66 at 0x000000840000
Bad eraseblock 67 at 0x000000860000
Bad eraseblock 68 at 0x000000880000
Bad eraseblock 69 at 0x0000008a0000
Bad eraseblock 70 at 0x0000008c0000
Bad eraseblock 71 at 0x0000008e0000
Bad eraseblock 72 at 0x000000900000
Bad eraseblock 73 at 0x000000920000
Bad eraseblock 74 at 0x000000940000
Bad eraseblock 75 at 0x000000960000
Bad eraseblock 76 at 0x000000980000
Bad eraseblock 77 at 0x0000009a0000
Bad eraseblock 78 at 0x0000009c0000
Bad eraseblock 79 at 0x0000009e0000
Bad eraseblock 80 at 0x000000a00000
Bad eraseblock 81 at 0x000000a20000
Bad eraseblock 82 at 0x000000a40000
Bad eraseblock 83 at 0x000000a60000
Bad eraseblock 84 at 0x000000a80000
Bad eraseblock 85 at 0x000000aa0000
Bad eraseblock 86 at 0x000000ac0000
Bad eraseblock 87 at 0x000000ae0000
Bad eraseblock 88 at 0x000000b00000
Bad eraseblock 89 at 0x000000b20000
Bad eraseblock 90 at 0x000000b40000
Bad eraseblock 91 at 0x000000b60000
Bad eraseblock 92 at 0x000000b80000
Bad eraseblock 93 at 0x000000ba0000
Bad eraseblock 94 at 0x000000bc0000
Bad eraseblock 95 at 0x000000be0000
Bad eraseblock 96 at 0x000000c00000
Bad eraseblock 97 at 0x000000c20000
Bad eraseblock 98 at 0x000000c40000
Bad eraseblock 99 at 0x000000c60000
Bad eraseblock 100 at 0x000000c80000
Bad eraseblock 101 at 0x000000ca0000
Bad eraseblock 102 at 0x000000cc0000
Bad eraseblock 103 at 0x000000ce0000
Bad eraseblock 104 at 0x000000d00000
Bad eraseblock 105 at 0x000000d20000
Bad eraseblock 106 at 0x000000d40000
Bad eraseblock 107 at 0x000000d60000
Bad eraseblock 108 at 0x000000d80000
Bad eraseblock 109 at 0x000000da0000
Bad eraseblock 110 at 0x000000dc0000
Bad eraseblock 111 at 0x000000de0000
Bad eraseblock 112 at 0x000000e00000
Bad eraseblock 113 at 0x000000e20000
Bad eraseblock 114 at 0x000000e40000
Bad eraseblock 115 at 0x000000e60000
Bad eraseblock 116 at 0x000000e80000
Bad eraseblock 117 at 0x000000ea0000
Bad eraseblock 118 at 0x000000ec0000
Bad eraseblock 119 at 0x000000ee0000
Bad eraseblock 120 at 0x000000f00000
Bad eraseblock 121 at 0x000000f20000
Bad eraseblock 122 at 0x000000f40000
Bad eraseblock 123 at 0x000000f60000
Bad eraseblock 124 at 0x000000f80000
Bad eraseblock 125 at 0x000000fa0000
Bad eraseblock 126 at 0x000000fc0000
Bad eraseblock 127 at 0x000000fe0000
Bad eraseblock 128 at 0x000001000000
Bad eraseblock 129 at 0x000001020000
Bad eraseblock 130 at 0x000001040000
Bad eraseblock 131 at 0x000001060000
Bad eraseblock 132 at 0x000001080000
Bad eraseblock 133 at 0x0000010a0000
Bad eraseblock 134 at 0x0000010c0000
Bad eraseblock 135 at 0x0000010e0000
Bad eraseblock 136 at 0x000001100000
Bad eraseblock 137 at 0x000001120000
Bad eraseblock 138 at 0x000001140000
Bad eraseblock 139 at 0x000001160000
Bad eraseblock 140 at 0x000001180000
Bad eraseblock 141 at 0x0000011a0000
Bad eraseblock 142 at 0x0000011c0000
Bad eraseblock 143 at 0x0000011e0000
Bad eraseblock 144 at 0x000001200000
Bad eraseblock 145 at 0x000001220000
Bad eraseblock 146 at 0x000001240000
Bad eraseblock 147 at 0x000001260000
Bad eraseblock 148 at 0x000001280000
Bad eraseblock 149 at 0x0000012a0000
Bad eraseblock 150 at 0x0000012c0000
Bad eraseblock 151 at 0x0000012e0000
Bad eraseblock 152 at 0x000001300000
Bad eraseblock 464 at 0x000003a00000
Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "My2440 boot"
0x000000040000-0x000000060000 : "param"
0x000000060000-0x000000260000 : "M2440 kernel"
0x000004000000-0x000008000000 : "YAFFS2"
usbmon: debugfs is not available
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
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
USB Serial support registered for generic
usbcore: registered new interface driver usbserial_generic
usbserial: USB Serial Driver core
USB Serial support registered for FTDI USB Serial Device
usbcore: registered new interface driver ftdi_sio
ftdi_sio: v1.4.3:USB FTDI Serial Converters Driver
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Advanced Linux Sound Architecture Driver Version 1.0.20.
ALSA device list:
No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
uncorrectable error : <3>end_request: I/O error, dev mtdblock3, sector 256
isofs_fill_super: bread failed, dev=mtdblock3, iso_blknum=64, block=128
yaffs: dev is 32505859 name is "mtdblock3"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.3, "mtdblock3"
yaffs: auto selecting yaffs2
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 136K
hwclock: Could not access RTC: No such file or directory
mknod: /dev/pts/0: No such file or directory
/etc/init.d/rcS: /etc/init.d/rcS: 44: cannot create /dev/vc/0: Directory nonexis
tent
/etc/init.d/rcS: /etc/init.d/rcS: 45: cannot create /dev/vc/0: Directory nonexis
tent
/etc/rc.d/init.d/httpd: /etc/rc.d/init.d/httpd: 16: /sbin/boa: not found
/etc/init.d/rcS: /etc/init.d/rcS: 48: cannot create /dev/vc/0: Directory nonexis
tent
/etc/init.d/rcS: /etc/init.d/rcS: 49: cannot create /dev/vc/0: Directory nonexis
tent
/etc/init.d/rcS: /etc/init.d/rcS: 52: cannot create /dev/vc/0: Directory nonexis
tent
/etc/init.d/rcS: /etc/init.d/rcS: 53: cannot create /dev/vc/0: Directory nonexis
tent
/etc/rc.d/init.d/leds: /etc/rc.d/init.d/leds: 16: /sbin/led-player: not found
SIOCSIFADDR: No such device
SIOCGIFFLAGS: No such device
/etc/init.d/rcS: /etc/init.d/rcS: 59: /sbin/madplay: not found
Please press Enter to activate this console.
-sh: can't access tty; job control turned off
id: unknown uid 0
[@ajaxhe /]# ls
bin home lost+found sbin var
dev lib mnt tmp www
etc linuxrc proc usr
[@ajaxhe /]#