Chinaunix首页 | 论坛 | 博客
  • 博客访问: 306465
  • 博文数量: 111
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 672
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-05 23:41
文章分类

全部博文(111)

文章存档

2017年(111)

我的朋友

分类: LINUX

2017-06-23 19:31:14

一、主机环境

   version 2.4.20-8, RedHat9, VMWare5.5.3;

  gcc version 3.4.4, Thread model: posix;

  GNU Make 3.81;

  arm--gcc 4.2.1 (此创建过程见另贴用crosstool脚本编译针对Linux2.6内核的交叉编译工具链)

  所需源文件:

  busybox-1.11.1.tar.bz2;

二、用Busybox创建nfs文件系统

1、解压busybox-1.11.1.tar.bz2,路径为

[root@Sure busybox-1.11.1]# pwd

/home/jacky/busybox-1.11.1

修改Makefilez中的ARCH和CROSS_COMPILE与本机的路径一致:

CROSS_COMPILE ?= /opt/crosstool/bin/arm-s3c2410-linux-gnu-

...

ARCH ?= arm

 

2、编译busybox。先make menuconfig,修改以下:

Busybox Settings --->

    Build Options --->

        [*] Build BusyBox as a static binary (no shared libs)

        //直接编译成静态库,省事点

        (/opt/crosstool/bin/arm-s3c2410-linux-gnu-) Cross Compiler prefix

        //这里和Makefile里保持一致,应该写一处就行了

    Installation Options --->

        [*] Don't use /usr

        //不用本机的目录

Shells --->

    Choose your default shell (ash) --->

    //这里选择shell为ash,应该是默认选中的

        --- ash

        //把ash这档的选项全部选上

保存退出,直接make,make install。

 

3、用shell脚本创建根文件系统的目录结构,并在想要建立根文件系统的地方运行此脚本。我是用root用户登陆的,直接创建了设备节点。

[root@Sure root-s3c2410]# vim makedir.sh

#!/bin/sh

  echo "makeing rootdir"

  mkdir rootfs

  cd rootfs

 

  echo "makeing dir: bin dev etc lib proc sbin sys usr"

  mkdir bin dev etc lib proc sbin sys usr #8 dirs

  mkdir usr/bin usr/lib usr/sbin lib/modules

 

#Don't use mknod, unless you run this Script as

  mknod -m 600 dev/console c 5 1

  mknod -m 666 dev/null c 1 3

 

  echo "making dir: mnt tmp var"

  mkdir mnt tmp var

  chmod 1777 tmp

  mkdir mnt/etc mnt/jiffs2 mnt/yaffs mnt/data mnt/temp

  mkdir var/lib var/lock var/log var/run var/tmp

  chmod 1777 var/tmp

 

  echo "making dir: home root boot"

  mkdir home root boot

  echo "done"

执行这个sh:

[root@Sure root-s3c2410]# sh makedir.sh

创建出一个主文件夹rootfs,里面有一批文件:

[root@Sure rootfs]# ls

bin  boot  dev  etc  home  lib  mnt  proc  root  sbin  sys  tmp  usr  var

 

4、把busybox源码目录下的etc的内容拷贝到这里的etc下

[root@Sure rootfs]# cd etc/

[root@Sure etc]# cp -a /home/jacky/busybox-1.11.1/examples/bootfloppy/etc/* ./

 

5、修改拷贝过来的profile文件

[root@Sure etc]# vim profile

# /etc/profile: system-wide .profile file for the Bourne shells

 

echo "Processing /etc/profile"

# no-op

 

# Set search library path

echo " Set search library path"

export LD_LIBRARY_PATH=/lib:/usr/lib

 

# Set user path

echo " Set user path"

PATH=/bin:/sbin:/usr/bin:/usr/sbin

export PATH

 

# Set PS1

echo " Set PS1"

HOSTNAME=`/bin/hostname`

# 此处让shell提示符显示host名称的。是`,不是’,要注意

# 会在进入根系统后显示Jacky

 

export PS1="\\e[32m[$USER@$HOSTNAME \\w\\a]\\$\\e[00;37m "

# 此处\\e[32m是让后面的“[$USER@$HOSTNAME \\w\\a]”显示为绿色

# \\e[00是关闭效果

# \\e[05是闪烁

# 37m是让后面的显示为白色

# 多个命令可以;号隔开

 

echo "All done!"

echo

6、修改初始化文件inittab和fstab

[root@Sure etc]# vim inittab

::sysinit:/etc/init.d/rcS

::respawn:-/bin/sh

::restart:/sbin/init

 

tty2::askfirst:-/bin/sh

::ctrlaltdel:/bin/umount -a -r

::shutdown:/bin/umount -a -r

::shutdown:/sbin/swapoff –a

[root@Sure etc]# vim fstab

proc /proc proc defaults 0 0

none /tmp ramfs defaults 0 0

mdev /dev ramfs defaults 0 0

sysfs /sys sysfs defaults 0 0

 

7、修改初始化的脚本文件init.d/rcS

[root@Sure etc]# vim init.d/rcS

#! /bin/sh

echo "Processing etc/init.d/rc.S"

 

#hostname ${HOSTNAME}

 

echo " Mount all"

/bin/mount -a

 

echo " Start mdev...."

/bin/echo /sbin/mdev > proc/sys/kernel/hotplug

mdev -s

 

echo "****************************************************"

echo " RootFS by NFS, s3c2410"

echo " Created by Jacky Xu @ 2008.7.13"

echo " Enjoy it!!!"

echo "****************************************************"

echo

 

8、创建一个空的mdev.conf文件,在挂载根文件系统时会用到的

[root@Sure etc]# touch mdev.conf

 

9、从本机拷贝passwd、shadow、group文件。

[root@Sure etc]# cp /etc/passwd .

[root@Sure etc]# cp /etc/shadow .

[root@Sure etc]# cp /etc/group .

修改passwd文件,把第一行和最后一行的bash修改成ash。

 

10、把busybox默认安装目录中的文件全部复制到这里的rootfs中。会发现多了linuxrc -> bin/busybox文件,这是挂载文件系统需要执行的。

[root@Sure etc]# cd ..

[root@Sure rootfs]# cp -Rfv /home/jacky/busybox-1.11.1/_install/ ./

 

OK,以上用busybox创建了一个基本的文件系统。

PS:

    如果编译busybox时选择动态库方式编译,则需要查看生成的busybox使用哪些动态库,然后把它们拷贝到rootfs/lib目录下。

[root@Sure lib]# arm-s3c2410-linux-gnu-readelf -d ../bin/busybox

Dynamic section at offset 0xc1014 contains 21 entries:

  Tag Type Name/Value

 0x00000001 (NEEDED) Shared library: [libm.so.6]

 0x00000001 (NEEDED) Shared library: [libc.so.6]

 0x0000000c (INIT) 0xc2ec

 0x0000000d (FINI) 0xa96b8

 0x00000004 (HASH) 0x80e8

 0x00000005 (STRTAB) 0xa4c4

 0x00000006 (SYMTAB) 0x8b64

 0x0000000a (STRSZ) 3505 (bytes)

 0x0000000b (SYMENT) 16 (bytes)

 0x00000015 (DEBUG) 0x0

 0x00000003 (PLTGOT) 0xd10e4

 0x00000002 (PLTRELSZ) 3112 (bytes)

 0x00000014 (PLTREL) REL

 0x00000017 (JMPREL) 0xb6c4

 0x00000011 (REL) 0xb674

 0x00000012 (RELSZ) 80 (bytes)

 0x00000013 (RELENT) 8 (bytes)

 0x6ffffffe (VERNEED) 0xb5a4

 0x6fffffff (VERNEEDNUM) 2

 0x6ffffff0 (VERSYM) 0xb276

 0x00000000 (NULL) 0x0

可以看出,使用了libm.so.6和libc.so.6两个库。发现只拷贝这两个库还不够,还需要ld-linux.so.2和libgcc_s.so.1,也就是我编译出来的这个busybox需要4个动态库文件。

# cp /opt/crosstool/arm-s3c2410-linux-gnu/sys-root/lib/libm.so.6 .

# cp /opt/crosstool/arm-s3c2410-linux-gnu/sys-root/lib/libc.so.6 .

# cp /opt/crosstool/arm-s3c2410-linux-gnu/sys-root/lib/ld-linux.so.2 .

# cp /opt/crosstool/arm-s3c2410-linux-gnu/lib/libgcc_s.so.1 .

这样,使用动态库可以节省一半左右的空间,不过效率有所降低。

 

三、

1、在本机修改/etc/export文件,重启NFS服务:

[root@Sure rootfs]# vim /etc/exports

/home/jacky/root-s3c2410/rootfs 192.168.1.*(rw,sync,no_root_squash)

[root@Sure rootfs]# service nfs restart

 

2、在Bootloader中传递以下参数给Kernel:

root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s3c2410/rootfs ip=192.168.1.199:192.168.1.249:192.168.1.1:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd

 

3、启动目标板,串口输出显示根文件系统已经加载成功:

Boot Parameters: root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s3c2410/rootfs ip=192.168.1.199:192.168.1.249:192.168.1.1:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd

Now, booting Linux...

Uncompressing Linux........................................................................................................... done, booting the kernel.

Linux version 2.6.24.7 (root@Sure) (gcc version 4.2.1) #5 Sat Jul 12 17:26:16 CST 2008

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177

Machine: SMDK2410

ATAG_INITRD is deprecated; please update your bootloader.

Memory policy: ECC disabled, Data cache writeback

CPU S3C2410A (id 0x32410002)

S3C2410: core 200.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz

S3C24XX Clocks, (c) 2004 Simtec Electronics

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

CPU0: D VIVT write-back cache

CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256

Kernel command line: root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s3c2410/rootfs ip=192.168.1.199:192.168.1.249:192.168.1.1:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd

irq: clearing subpending status 00000003

PID hash table entries: 256 (order: 8, 1024 bytes)

timer tcon=00000000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8

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: 61440KB available (3048K code, 314K data, 128K init)

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

net_namespace: 64 bytes

NET: Registered protocol family 16

S3C2410 Power Management, (c) 2004 Simtec Electronics

S3C2410: Initialising architecture

S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics

DMA channel 0 at c4800000, irq 33

DMA channel 1 at c4800040, irq 34

DMA channel 2 at c4800080, irq 35

DMA channel 3 at c48000c0, irq 36

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

Bluetooth: Core ver 2.11

NET: Registered protocol family 31

Bluetooth: HCI device and connection manager initialized

Bluetooth: HCI socket layer initialized

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

NetWinder Floating Point Emulator V0.97 (double precision)

JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.

JFS: nTxBlock = 480, nTxLock = 3840

io scheduler noop registered

io scheduler anticipatory registered (default)

io scheduler deadline registered

io scheduler cfq registered

s3c2410-lcd s3c2410-lcd: no platform data for lcd, cannot attach

s3c2410-lcd: probe of s3c2410-lcd failed with error -22

lp: driver loaded but no devices found

ppdev: user-space parallel port driver

Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled

s3c2410-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2410

s3c2410-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2410

s3c2410-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2410

RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

loop: module loaded

Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)

eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0

Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2

ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx

S3C24XX NAND Driver, (c) 2004 Simtec Electronics

s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns

NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)

Scanning device for bad blocks

Creating 5 MTD partitions on "NAND 64MiB 3,3V 8-bit":

0x00000000-0x00100000 : "Bootloader"

0x00100000-0x00400000 : "Kernel"

0x00400000-0x03400000 : "Root"

0x03400000-0x03fe0000 : "ExtRoot"

0x03fe0000-0x04000000 : "Param"

usbmon: debugfs is not available

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

mice: PS/2 mouse device common for all mice

S3C24XX RTC, (c) 2004,2006 Simtec Electronics

s3c2410-i2c s3c2410-i2c: slave address 0x10

s3c2410-i2c s3c2410-i2c: bus frequency set to 390 KHz

s3c2410-i2c s3c2410-i2c: i2c-0: S3C I2C adapter

S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics

s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled

TCP cubic registered

NET: Registered protocol family 1

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)

IP-Config: Complete:

      device=eth0, addr=192.168.1.199, mask=255.255.255.0, gw=192.168.1.1,

     host=Jacky, domain=, nis-domain=(none),

     bootserver=192.168.1.249, rootserver=192.168.1.249, rootpath=

Looking up port of RPC 100003/2 on 192.168.1.249

Looking up port of RPC 100005/1 on 192.168.1.249

VFS: Mounted root (nfs filesystem).

Freeing init memory: 128K

init started: BusyBox v1.11.1 (2008-07-13 14:46:21 CST)

starting pid 789, tty '': '/etc/init.d/rcS'

Processing etc/init.d/rc.S

  Mount all

  Start mdev....

****************************************************

              RootFS by NFS, s3c2410

         Created by Jacky Xu @ 2008.7.13

                   Enjoy

****************************************************

 

starting pid 793, tty '': '-/bin/sh'

Processing /etc/profile

  Set search library path

  Set user path

  Set PS1

All

 

[root@Jacky /]# ls

bin dev home linuxrc proc sbin tmp var

boot etc lib mnt root sys usr

[root@Jacky /]#

 

已经直接进入了nfs文件系统!

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