Chinaunix首页 | 论坛 | 博客
  • 博客访问: 302814
  • 博文数量: 27
  • 博客积分: 422
  • 博客等级: 一等列兵
  • 技术积分: 2839
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-17 12:16
文章分类

全部博文(27)

文章存档

2013年(13)

2012年(14)

分类: LINUX

2012-12-03 23:53:09

1. 内核加入YAFFS2文件系统,编译

    参考前面这篇:YAFFS2移植到linux3.6.7

2. make menuconfig 配置如下:

    2.1Device Drivers配置

         2.1.1. Generic Driver Options选择

        [*] Maintain a devtmpfs filesystem to mount at /dev  
        [*] Automount devtmpfs at /dev, after the kernel mounted the ....  
         2.1.2 MTD-->Caching block device access to MTD devices

    2.2File Systems 配置

          取消 Second extended fs support 和 Ext3 journalling file system support 

          [*] Miscellaneous filesystems --->选择

2.3 Boot options配置

    输入"noinitrd root=/dev/mtdblock2 rootfstype=yaffs2 init=/linuxrc console=ttySAC0,115200"

3.制作mkyaffs2image工具

   进入yaffs2源码目录下utils目录,修改mkyaff2image.c:

#define chunkSize 2048
#define spareSize 64
#define pagesPerBlock 64

改为

#define chunkSize 4096
#define spareSize 218
#define pagesPerBlock 128

   进入yaffs2源码目录下direct目录,修改yportenv.h

增加#define CONFIG_YAFFS_DEFINES_TYPES

保存后make,这时就在utils目录生产mkyaffs2image文件,把这个文件拷贝到/usr/bin目录下

4.制作根文件系统

下面写的过程大部分是参考这篇文章:http://blog.csdn.net/longtian635241/article/details/8036099

  4.1解压busybox1.20.2,修改Makefile

      CROSS_COMPILE ?=/usr/local/arm/4.5.1/bin/arm-linux-

      ARCH ?= arm

  4.2配置busybox菜单如下:

   a、make defconfig(默认配置)
   b、make menuconfig
Busybox Settings --->Build Options --->(/usr/local/arm/4.5.1/bin/arm-linux-) Cross Compiler prefix
Busybox Settings --->General Configuration --->[*] Don't use /usr  

  4.3  编译、安装
  a、make
  b、make install(由于前面没设置安装位置将默认安装在本文件夹的_install文件夹下)

  4.4 进入_install建立其他根文件系统文件夹.我写了个脚本creat_initramfs.sh
#!/bin/sh
echo "--------Create root,dev......"
mkdir root dev etc bin sbin mnt sys proc lib home tmp var usr
mkdir usr/sbin usr/bin usr/lib usr/modules usr/etc
mkdir mnt/usb mnt/nfs mnt/etc mnt/etc/init.d
mkdir lib/modules
chmod 1777 tmp

sudo mknod -m 600 dev/console c 5 1
sudo mknod -m 666 dev/null c 1 3

echo "-------make direction done---------"
然后保存脚本修改权限:chmod +x creat_initramfs.sh
运行脚本!

    4.5建立相关文件

     4.5.1在 etc目录下创建profile文件,内容如下

# Ash profile
# vim: syntax=sh
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
USER="`id -un`"
LOGNAME=$USER
PS1='[\u@\h \W]\# '
PATH=$PATH
HOSTNAME=`/bin/hostname`
export USER LOGNAME PS1 PATH

     4.5.2在 etc目录下创建init.d文件夹,进入这个文件夹创建rcS文件,内容如下

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

#
# Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
#
trap ":" INT QUIT TSTP
/bin/hostname hcm

/bin/mount -n -t proc none /proc
/bin/mount -n -t sysfs none /sys
/bin/mount -n -t usbfs none /proc/bus/usb
/bin/mount -t ramfs none /dev

echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s
/bin/hotplug
# mounting file system specified in /etc/fstab
mkdir -p /dev/pts
mkdir -p /dev/shm
/bin/mount -n -t devpts none /dev/pts -o mode=0622
/bin/mount -n -t tmpfs tmpfs /dev/shm
/bin/mount -n -t ramfs none /tmp
/bin/mount -n -t ramfs none /var
mkdir -p /var/empty
mkdir -p /var/log
mkdir -p /var/lock
mkdir -p /var/run
mkdir -p /var/tmp

/sbin/hwclock -s -f /dev/rtc

syslogd
/etc/rc.d/init.d/netd start
echo " " > /dev/tty1
echo "Starting networking..." > /dev/tty1
#sleep 1
#/etc/rc.d/init.d/httpd start
#echo " " > /dev/tty1
#echo "Starting web server..." > /dev/tty1
#sleep 1
#/etc/rc.d/init.d/leds start
#echo " " > /dev/tty1
#echo "Starting leds service..." > /dev/tty1
#echo " "
#sleep 1
echo "*************************************"
echo " Welcome to Root FileSystem! "
echo " "
echo " http://write.blog.csdn.net/postlist "
echo "*************************************"


mkdir /mnt/disk
mount -t yaffs2 /dev/mtdblock3 /mnt/disk

mount -t vfat /dev/mmcblk0p1 /home/
mount -t yaffs2 /dev/mtdblock3 /mnt/
cd /mnt/
tar zxvf /home/urbetter-rootfs-qt-2.2.0.tgz
sync
cd /
umount /mnt/
umount /home/
/sbin/ifconfig lo 127.0.0.1
chmod +x etc/init.d/ifconfig-eth0 
/etc/init.d/ifconfig-eth0
/bin/qtopia &
echo " " > /dev/tty1
echo "Starting Qtopia, please waiting..." > /dev/tty1
echo " "
echo "Starting Qtopia, please waiting..."

注意修改这个文件权限:chmod +x /etc/init.d/rcS

4.5.3在 etc目录下创建fstab文件,内容如下

proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
none /var ramfs defaults 0 0
mdev /dev ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0


4.5.4在 etc目录下创建inittab文件,内容如下/
::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
::shutdown:/bin umount -a -r
::shutdown:/sbin/swapoff -a
4.5.5 在usr/etc/目录下创建init文件,内容如下
#!/bin/sh
ifconfig eth0 192.168.3.111 up
ifconfig lo 127.0.0.1

注意修改权限:chmod +x usr/etc/init

4.5.6创建 mdev.conf(空文件)

4.6 拷贝相应工具链中的库文件到lib当中
hcm@hcm-desktop:~/hcm/busybox-1.20.2/_install$ cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/lib/*so* lib

5. 用mkyaffs2image工具制作根文件系统

root@ubuntu:/home/my/busybox-1.20.2# mkyaffs2image _install rootfs.yaffs

这样就做好了根文件系统。

6.u-boot 2012.10修改yaffs2下载。

   经过试验,尽管前面已经做好了u-boot.bin 、uImage和rootfs.yaffs,但烧写进入后从NAND启动结果最后都会出现这个:

VFS: Mounted root (yaffs2 filesystem) on device 31:2.
devtmpfs: error mounting -2
Freeing init memory: 92K
Failed to execute /linuxrc. Attempting defaults...
Kernel panic - not syncing: No init found. Try passing init= option to kernel.

这个是反复比较后确定是u-boot 2012.10写yaffs时出了错,估计是个bug吧。

主要在这里:u-boot 2012.10源码中nand_util.c文件有个nand_write_skip_bad()函数,错误在这个地方

need_skip = check_skip_len(nand, offset, *length);
if (need_skip < 0) {
printf ("Attempt to write outside the flash area\n");
*length = 0;
return -EINVAL;
}

if (!need_skip && !(flags & WITH_DROP_FFS))
{
/*zxd bug do not call 'nand_write' below when we use write.yaffs option*/
if(flags & WITH_YAFFS_OOB)
{
printf ("NAND write to offset= %llx \n",offset);
}
else
{

rval = nand_write (nand, offset, length, buffer);
if (rval == 0)
return 0;
*length = 0;
printf ("NAND write to offset %llx failed %d\n",
offset, rval);
return rval;
}
}

红色部分是我后面加上去的。修改后把这三个文件写到NAND中,启动后运行如下:


## Booting kernel from Legacy Image at 50008000 ...

Image Name: Linux-3.6.7

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size: 1410288 Bytes = 1.3 MiB

Load Address: 50008000

Entry Point: 50008040

Verifying Checksum ... OK

XIP Kernel Image ... OK

OK


Starting kernel ...


Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0
Linux version 3.6.7 (root@ubuntu) (gcc version 4.5.1 (ctng-1.8.1-FA) ) #17 Mon Dec 3 00:30:47 CST 2012
CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: OK6410
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=533000000, M=533000000, E=24000000
S3C64XX: HCLK2=266500000, HCLK=133250000, PCLK=66625000
mout_apll: source is fout_apll (1), rate is 533000000
mout_epll: source is epll (1), rate is 24000000
mout_mpll: source is mpll (1), rate is 533000000
usb-bus-host: source is clk_48m (0), rate is 48000000
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
CPU: found DTCM0 8k @ 00000000, not enabled
CPU: moved DTCM0 8k to fffe8000, enabled
CPU: found DTCM1 8k @ 00000000, not enabled
CPU: moved DTCM1 8k to fffea000, enabled
CPU: found ITCM0 8k @ 00000000, not enabled
CPU: moved ITCM0 8k to fffe0000, enabled
CPU: found ITCM1 8k @ 00000000, not enabled
CPU: moved ITCM1 8k to fffe2000, enabled
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 65024
Kernel command line: noinitrd root=/dev/mtdblock2 rootfstype=yaffs2 init=/linuxrc console=ttySAC0,115200
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: 256892k/256892k available, 5252k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
DTCM : 0xfffe8000 - 0xfffec000 ( 16 kB)
ITCM : 0xfffe0000 - 0xfffe4000 ( 16 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
vmalloc : 0xd0800000 - 0xff000000 ( 744 MB)
lowmem : 0xc0000000 - 0xd0000000 ( 256 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0xc0008000 - 0xc02671f4 (2429 kB)
.init : 0xc0268000 - 0xc027f0cc ( 93 kB)
.data : 0xc0280000 - 0xc02ac780 ( 178 kB)
.bss : 0xc02ad024 - 0xc02de0cc ( 197 kB)
NR_IRQS:246
VIC @f6000000: id 0x00041192, vendor 0x41
VIC @f6010000: id 0x00041192, vendor 0x41
sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms
Console: colour dummy device 80x30
Calibrating delay loop... 353.89 BogoMIPS (lpj=1769472)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x501c7130 - 0x501c718c
devtmpfs: initialized
DMA: preallocated 256 KiB pool for atomic coherent allocations
OK6410: Option string ok6410=0
OK6410: selected LCD display is 480x272
s3c64xx_dma_init: Registering DMA channels
PL080: IRQ 73, at d0846000, channels 0..8
PL080: IRQ 74, at d0848000, channels 8..16
S3C6410: Initialising architecture
bio: create slab 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 = 69) is a S3C6400/10
console [ttySAC0] enabled
s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 70) is a S3C6400/10
s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 71) is a S3C6400/10
s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 72) is a S3C6400/10
brd: module loaded
loop: module loaded
S3C NAND Driver, (c) 2008 Samsung Electronics
NandFlash is busying.........
forlinx nandflash dev_id=d5
forlinx****Nandflash:ChipType= MLC ChipName=samsung-K9GAG08U0D************
S3C NAND Driver is using hardware ECC.
NAND device: Manufacturer ID: 0xec, Chip ID: 0xd5 (Samsung NAND 2GiB 3,3V 8-bit), page size: 4096, OOB size: 218
Driver must set ecc.strength when using hardware ECC
Creating 4 MTD partitions on "NAND 2GiB 3,3V 8-bit":
0x000000000000-0x000000200000 : "Bootloader"
0x000000200000-0x000000700000 : "Kernel"
0x000000700000-0x00000cf00000 : "File System"
0x00000cf00000-0x000080000000 : "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)
yaffs: dev is 32505858 name is "mtdblock2" rw
yaffs: passed flags ""
mmc0: mmc_rescan_try_freq: trying to init card at 100000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 400000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 300000 Hz
VFS: Mounted root (yaffs2 filesystem) on device 31:2.
devtmpfs: mounted the root filesystem.
Freeing init memory: 92K
mmc1: mmc_rescan_try_freq: trying to init card at 200000 Hz
mmc1: mmc_rescan_try_freq: trying to init card at 100000 Hz
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.csdn.net/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 74: /etc/init.d/ifconfig-eth0: not found

Starting Qtopia, please waiting...
/etc/init.d/rcS: line 76: /bin/qtopia: not found

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

终于看到梦想中的shell界面啦!~~

文件下载地址:



阅读(16097) | 评论(8) | 转发(12) |
给主人留下些什么吧!~~

k666已被人注册2014-08-05 19:54:33

我按你的方法还是不行!好几种方法都试了,也不行

lxglovelh2014-06-25 23:46:25

楼主想必多年了,这个devtmpfs: error mounting -2 问题解决了,求教什么问题??如果解决??

liuyajun12182013-08-04 22:28:58

samyoju:改了还是还是出现devtmpfs: error mounting -2 。能上传你的最新的u-boot代码或者u-boot-nand.bin吗?  不知问题出在u-boot还是内核还是文件系统!!

您好,能联系下我吗,qq:676989567,想跟您讨论点事

回复 | 举报

samyoju2013-01-03 20:47:26

改了还是还是出现devtmpfs: error mounting -2 。能上传你的最新的u-boot代码或者u-boot-nand.bin吗?  不知问题出在u-boot还是内核还是文件系统!!

samyoju2013-01-03 15:42:07

STANzxd: ”Attempt to write incomplete page in yaffs mode“:显然你的yaffs文件的大小不是u-boot中NAND 的page的倍数。即必须是yaffs文件大小=n*page.(比如我的开发.....
#define spareSize 218 应该是这个错了

应该是#define spareSize 128   吧。
这样改就是4096的陪数了!