Linux内核移植(6)

Linux3.8.3内核移植-根文件系统挂载

rootfs.yaffs已经制作完成,而rootfs.yaffs具体要放在什么地方?linux内核怎么识别?并成功挂载?本节将详细展开!

1、nand falsh分区

在制作yaffs2文件系统的时候,已经将256M的nand分成了四个区:
[0]uboot
[1]kernel
[2]rootfs
[3]user

********Nandflash:Type=SLC  ChipName:samsung-K9F2G08U0B or hynix-HY27UF082G2B******
S3C NAND Driver is using hardware ECC.
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64
Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000100000 : "uboot"
0x000000100000-0x000000600000 : "kernel"
0x000000600000-0x00000ce00000 : "rootfs"
0x00000ce00000-0x000010000000 : "user"

分区结构

	256M flash 0x000 0000 ~ 0xFFF FFFF
	
		
	0xfff ffff	┌────────────────┐   
				│	user 		 │	50M(0x320 0000)
	0xce0 0000	├────────────────┤
				│				 │
				│				 │
				│	rootfs		 │	200M(0xc80 0000)
				│				 │	[rootfs.yaffs:0x60 0000 ~ 0xce0 0000]
				│				 │
				│				 │
	0x060 0000	├────────────────┤
				│				 │
				│	kenerl		 │	5M(0x50 0000)
				│				 │	[uImage:0x010 0000 ~ 0x060 0000]
	0x010 0000	├────────────────┤
				│	uboot		 │	1M(0x10 0000)				
	0x000 0000	└────────────────┘	[	env:0x008 0000 - 0x008 4000]
									  [u-boot:0x000 0000 ~ 0x008 0000]

nand的分区可以看出,最终,是将uboot、uImage、rootfs.yaffs全部放入nand flash中启动的。

2、配置linux内核

eric@eric-PC:~/Documents/linux-3.8.3$ make menuconfig

Device Drivers  ---> 
    Generic Driver Options  ---> 
    [*] Maintain a devtmpfs filesystem to mount at /dev 
    [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs 
 [*] Miscellaneous filesystems  ---> 
	<*>   BeOS file system (BeFS) support (read only) (EXPERIMENTAL) 

保存,并make uImage生成新的uImage

2、将uImage、roofs.yaffs烧写至nand flash中。

之前启动uImage,为了方便调试,将uImage放到SD卡中直接启动了,现在要将uImage 直接写入nandflash中启动。借助u-boot命令,进行nand擦除、写入操作。

烧写uImage到nand中,需要下面三步命令

fatload mmc 0 50008000 uImage
nand erase 100000 500000
nand write 50008000 100000 500000

具体实现如下:

SMDK6410 # fatload mmc 0 50008000 uImage
reading uImage
1459896 bytes read in 54 ms (25.8 MiB/s)
SMDK6410 # nand erase 100000 500000

NAND erase: device 0 offset 0x100000, size 0x500000
Erasing at 0x5e0000 -- 100% complete.
OK
SMDK6410 # nand write 50008000 100000 500000

NAND write: device 0 offset 0x100000, size 0x500000
 5242880 bytes written: OK
SMDK6410 #

烧写rootfs的时候,需要用命令

fatload mmc 0 50008000 rootfs.yaffs
nand erase 600000 c800000
nand write.yaffs 50008000 600000 c800040

nand write.yaffs需要u-boot中cmd_cmd中添加支持,并在smdk6410.h中打开CONFIG_CMD_NAND_YAFFS宏定义

其中c800040=c800000+40,,40为obbsize,否则写入是会提示“Attempt to write incomplete page”,同时写入失败

680行,nand write.uboot命令后面添加

#ifdef CONFIG_CMD_NAND_YAFFS
		} else if (!strcmp(s, ".yaffs")) {
			if (read) {
				printf("Unknown nand command suffix '%s'.\n", s);
				return 1;
			}
			ret = nand_write_skip_bad(nand, off, &rwsize,
						(u_char *)addr,
						WITH_YAFFS_OOB);//WITH_INLINE_OOB);		//eric++2017-11-26
#endif

修改后,重新编译u-boot,并从SD卡启动,烧写至nand启动

具体烧写流程如下

SMDK6410 # fatload mmc 0 50008000 rootfs.yaffs
reading rootfs.yaffs
21356544 bytes read in 812 ms (25.1 MiB/s)
SMDK6410 # nand erase 600000 c800000

NAND erase: device 0 offset 0x600000, size 0xc800000
Skipping bad block at  0x02960000
Skipping bad block at  0x06860000
Skipping bad block at  0x07220000
Skipping bad block at  0x08d00000
Erasing at 0xcde0000 -- 100% complete.
OK
SMDK6410 # nand write.yaffs 50008000 600000 c800040

NAND write: device 0 offset 0x600000, size 0xc800040
Skip bad block 0x02960000
Skip bad block 0x06860000
Skip bad block 0x07220000
Skip bad block 0x08d00000
 209715264 bytes written: OK
SMDK6410 #

修改bootcmd和bootargs

SMDK6410 #
SMDK6410 # setenv bootcmd "nand read 0x50008000 0x100000 0x500000;bootm 50008000"
SMDK6410 # setenv bootargs "noinitrd root=/dev/mtdblock2 rootfstpye=yaffs2 init=/linuxrc console=ttySAC0,115200"
SMDK6410 #
SMDK6410 # printenv
baudrate=115200
bootargs=noinitrd root=/dev/mtdblock2 rootfstpye=yaffs2 init=/linuxrc console=ttySAC0,115200
bootcmd=nand read 0x50008000 0x100000 0x500000;bootm 50008000
bootdelay=3
ethact=dm9000
ethaddr=00:40:5c:26:0a:5b
filesize=145e000
gatewayip=192.168.1.1
ipaddr=192.168.1.2
serverip=192.168.1.136
stderr=serial
stdin=serial
stdout=serial

Environment size: 372/16380 bytes
SMDK6410 # saveenv
Saving Environment to NAND...
saveenv:env_new->crc=0x6b88002e
Erasing Nand...
Erasing at 0x80000 -- 100% complete.
Writing to Nand... done
SMDK6410 #

bootcmd 是u-boot完成使命后自动执行的一条命令。读取nand中的uImage加载到内存中,并启动

bootargs是传递给kernel的参数。其中root=/dev/mtdblock2,指定根文件系统对应的分区,mtdblock2就是对应的nand分区的第二个分区,即rootfs。这个也是根文件系统成功启动的关键

3、修改完成后,启动设备

出现以下大量信息

s3c-nand: SLC ECC uncorrectable error detected ???

3c_nand.c,屏蔽nand_ecc校验

#if defined(CONFIG_MTD_NAND_S3C_HWECC)
		nand->ecc.mode		= NAND_ECC_HW; //NAND_ECC_NONE;//eric++ 2017-11-26
		nand->ecc.hwctl		= s3c_nand_enable_hwecc;

再次,编译uImage、烧录内核、启动

VFS: Mounted root (yaffs filesystem) on device 31:2.
devtmpfs: mounted
Freeing init memory: 108K
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.
[<c0013fc4>] (unwind_backtrace+0x0/0xf4) from [<c01df34c>] (panic+0x8c/0x1dc)
[<c01df34c>] (panic+0x8c/0x1dc) from [<c01dee30>] (kernel_init+0xc0/0xe4)
[<c01dee30>] (kernel_init+0xc0/0xe4) from [<c000e558>] (ret_from_fork+0x14/0x3c)

Failed to execute /linuxrc,,busybox配置中,选择如下选项

Busybox Settings  ---> 
      Build Options  --->  
      [*] Build BusyBox as a static binary (no shared libs)  

再次制作根文件系统mkyaffs2image _install rootfs.yaffs
烧录rootfs.yaffs,并启动

********Nandflash:Type=SLC  ChipName:samsung-K9F2G08U0B or hynix-HY27UF082G2B******
S3C NAND Driver is using hardware ECC.
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64
NAND_ECC_NONE selected by board driver. This is not recommended!
Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000100000 : "uboot"
0x000000100000-0x000000600000 : "kernel"
0x000000600000-0x00000ce00000 : "rootfs"
0x00000ce00000-0x000010000000 : "user"
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)
s3c2410-ohci s3c2410-ohci: 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
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdhci s3c-sdhci.0: clock source 0: mmc_busclk.0 (133250000 Hz)
s3c-sdhci s3c-sdhci.0: clock source 2: mmc_busclk.2 (24000000 Hz)
mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using ADMA
s3c-sdhci s3c-sdhci.1: clock source 0: mmc_busclk.0 (133250000 Hz)
s3c-sdhci s3c-sdhci.1: clock source 2: mmc_busclk.2 (24000000 Hz)
mmc0: mmc_rescan_try_freq: trying to init card at 400000 Hz
mmc0: mmc_rescan_try_freq: trying to init card at 300000 Hz
mmc1: SDHCI controller on samsung-hsmmc [s3c-sdhci.1] using ADMA
mmc0: mmc_rescan_try_freq: trying to init card at 200000 Hz
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)
BeFS(mtdblock2): No write support. Marking filesystem read-only
BeFS(mtdblock2): invalid magic header
mmc0: mmc_rescan_try_freq: trying to init card at 100000 Hz
yaffs: dev is 32505858 name is "mtdblock2" rw
yaffs: passed flags ""
mmc1: mmc_rescan_try_freq: trying to init card at 400000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 300000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 200000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 100000 Hz
VFS: Mounted root (yaffs filesystem) on device 31:2.
devtmpfs: mounted
Freeing init memory: 108K
mount: mounting none on /proc/bus/usb failed: No such file or directory
/etc/init.d/rcS: line 21: /bin/hotplug: not found
hwclock: can't open '/dev/rtc': No such file or directory
/etc/init.d/rcS: line 38: /etc/rc.d/init.d/netd: not found
*************************************
 Welcome to Root FileSystem!

 http://write.blog.youkuaiyun.com/postlist
*************************************
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
mount: mounting /dev/mmcblk0p1 on /home/ failed: No such device
tar: can't open '/home/urbetter-rootfs-qt-2.2.0.tgz': No such file or directory
umount: can't umount /home/: Invalid argument
ifconfig: socket: Function not implemented
chmod: etc/init.d/ifconfig-eth0: No such file or directory
/etc/init.d/rcS: line 71: /etc/init.d/ifconfig-eth0: not found
/etc/init.d/rcS: line 72: /bin/qtopia: not found

Starting Qtopia, please waiting...

Please press Enter to activate this console.
[@hcm /]#
[@hcm /]#
[@hcm /]# ls
bin               home              mnt               sys
create_yaffs2.sh  lib               proc              tmp
dev               linuxrc           root              usr
etc               lost+found        sbin              var
[@hcm /]#

至此,linux根文件系统已经成功在6410上启动,并能够支持ls、cd等常用命令。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值