环境:
交叉编译环境:4.3.3 (存放路径/opt/EmbedSky/4.3.3)
开发平台:TQ2440,Ubuntu11
1,编译busybox
获取busybox源码busybox-1.17.2.tar ()
置于目录/opt/embed下
#tar jxvf busybox-1.17.2.tar.bz2
#cd busybox-1.17.2
#vim Makefile
将164行改为CROSS_COMPILE = arm-linux- 将190行改为ARCH = arm
保存推出进入配置菜单
#make men onfig 采用默认配置保存推出
#make
#make install
在busybox-1.17.2的根目录下出现了一个_install目录在该目录下又有三个目录文件bin sbin usr 和一个链接文件 linuxrc 。
2,创建根文件系统必要的目录
回到/opt/embed目录下创建根文件系统必要的目录
#mkdir root_fs
#cd root_fs
将刚才生成的三个目录bin sbin usr和一个链接文件linuxrc考到目录root_fs下
#cp -rf ../busybox-1.17.2/_install/* ./
#mkdir dev etc home lib mnt opt proc root sys tmp var
创建几个必要的二级目录
#mkdir usr/lib usr/share
#mkdir etc/rc.d
#mkdir var/lib var/lock var/run var/tmp
3,创建必要文件
(1), 获取库文件 (我的交叉编译工具链放在目录 /opt/EmbedSky/下的)
#cp -rf /opt/EmbedSky/4.3.3/arm-none-linux-gn?i/libc/armv4t/lib/*so* lib -a
(2),将主机 etc 目录下的passwd、group、shadow文件拷贝到 root_fs/etc目录下
#cp -f /etc/passwd /etc/group /etc/shadow etc
将目录/opt/embed/busybox-1.17.2/examples/bootfloppy/etc下的所有文件拷贝到
root_fs/etc下。在这个目录下有三个文件fstab, inittab, profile和一个目录init.d,
在目录init.d中有一个文件rcS。
#cp -rf ../busybox-1.17.2/examples/bootfloppy/etc/* etc
在目录etc下创建文件mdev.conf。mdev是?v的一个简化版本,我们可以通过文件mdev.conf自定义一些设备节点的名称或链接来满足特定的需要,但在此处让它为空。
#to h etc/mdev.conf
(3)创建两个设备文件dev/console dev/null。
在linux内核源码文件init/main.c中有打开设备文件dev/console的操作如下:
static noinline int init_post(void)
__releases(kernel_lock)
{
………………………………
if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
printk(KERN_WARNING "Warning: unable to open an initial console.\n");
………………………………
}
内核启动执行到这里时mdev还没有构建dev目录,如果没有创建设备文件dev/console就将会打印警告Warning: unable to open an initial console。
在内核启动的过程中要将产生的一些垃圾信息丢弃就需要空设备dev/null。
#mknod dev/console c 5 1
#mknod dev/null c 1 3
4,几个必要文件的修改
在启动过程中bootloader会传递参数init=/linuxrc给内核的main( )函数,所以在文件系统被挂在后,运行的第一个程序是linuxrc,而linuxrc是一个指向/bin/busybox的链接文件,也就是说文件系统被挂在后运行的第一个程序是busybox。Busybox首先会解析文件/etc/inittab,这个文件中存放的是系统的配置信息,这些配置信息指明了接下来将要启动那些程序。
(1),修改文件etc/inittab如下
::sysinit:/etc/init.d/rcS
tq2440_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
/etc/inittab 文件中每个条目用来定义一个子进程,并确定它的启动方法,格式如下
文件etc/inittab配置条目说明如下:
::sysinit:/etc/init.d/rcS
启动系统初始化文件/etc/init.d/rcS。字段sysinit表明文件/etc/init.d/rcS在系统启动后最先执行,并且只执行一次,init进程等待它结束才继续执行其它动作。
(脚本文件名一般为rc,后缀S代表单用户运行级别脚本)
tq2440_serial0::askfirst:-/bin/sh
在串口tq2440_serial0上启动askfirst动作的shell。S3C2410的串口名在/dev下是s3c2410_serialx。此时还没有移植自己的内核,用天嵌科技的内核所以串口名为tq2440_serial0。askfirst表明init进程先输出“Please press Enter to actvie this console”,等用户输入回车键之后才启动-/bin/sh。
::ctrlaltdel:/sbin/reboot
当按下Ctrl+Alt+Delete组合键时,init重启执行程序。字段ctrlaltdel表明当按下Ctrl+Alt+Delete组合键时,执行相应的进程。
::shutdown:/bin/umount -a -r
告诉init在关机时运行umount命令卸载所有的文件系统,如果卸载失败,试图以只读方式重新挂载。字段shutdown表明在重启关闭系统命令时执行相应进程。
(2),当解析完文件etc/inittab后就将启动这些进程,首先要执行的是启动脚本etc/init.d/rcS。
修改文件etc/init.d/rcS如下:
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
/bin/hostname cyembed
echo "----------mount all----------"
/bin/mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
echo "**************************************"
echo "**************************************"
echo "Kernel version:linux-2.6.30.4"
echo "Date:2010.09.16"
echo "**************************************"
说明如下:
#! /bin/sh 用busybox的shell
PATH=/sbin:/bin:/usr/sbin:/usr/bin //shell命令的搜索路径
runlevel=S //运行在单用户模式
prevlevel=N //前一个级别为n表示没有前一个级别
umask 022 //权限位掩码
export PATH runlevel prevlevel //将设置的变量导出到环境中
/bin/hostname cyembed //主机名,cyembed将出现在shell提示符中[root@cyembed/]#
/bin/mount -a //将文件etc/fstab中指明的文件系统挂载到对应挂载点上
echo /sbin/mdev>/proc/sys/kernel/hotplug //用mdev来处理内核的热插拔事件。
当有热插拔事件产生时, 内核就会调用位于/sbin目录的 mdev。 这时 mdev通过环境变量中的 ACTION 和 DEVPATH, (这两个变量是系统自带的)来确定此次热插拔事件的动作以及影响了/sys 中的那个目录。接着会看看这个目录中是否有“dev”的属性文件,如果有就利用这些信息为 这个设备在/dev 下创建设备节点文件。
mdev -s //建立dev目录。以‘-s’为参数调用位于/sbin 目录写的 mdev(其实是个链接,作用是传递参数给/bin目录下的busybox 程序并调用它) ,mdev扫描 /sys/class 和/sys/block中所有的类设备目录,如果在目录中含有名为“dev”的文件,且文件中包含的是设备号,则 mdev 就利用这些信息为这个设备在/dev下创建设备节点文件。一般只在启动时才执行一次 “mdev -s” 。
(3),修改文件etc/fstab如下:
#device mount-point type option dump fsck order
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
在系统启动初始化文件/etc/init.d/rcS中有执行挂载命令/bin/mount -a ,这便是
将文件etc/fstab中指定的文件系统挂载到对应的挂载点上。这些文件系统的挂在是执行
mdev -s命令建立dev目录的前提。
(4),在启动脚本etc/init.d/rcS执行完后将在串口tq2440_serial0启动一个shell。Shell启动过程中会根据文件/etc/profile配置登陆环境。
文件/etc/profile修改如下:
USER=" 'id -un' "
LOGNAME=$USER
PS1='[\u@\h \W]#'
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH
具体说明:
USER="id -un" //获取用户名id-un与whoami命令有相同的功能
PS1='[\u@\h \W]#' //PS1指定sh提示符的格式在本环境下将是[root@cyembed /]#
export USER LOGNAME PS1 PATH 将这些变量导出到环境。
(5),在用户登录时将在/etc下寻找三个文件passwd ,shadow, group匹配相关信息。
这三个文件修改如下:
/etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
/etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
ftp:x:50:
nobody:x:99:
/etc/shadow
root:$6$hnswPTgxzFaZHlLl$WMMV0Av6O6c4RA4pwpVSgcKSiURhUlP5dxF3/MKEZlGzNXhoWMQeZA1rdf1z7VQbrrmOZe7YHw1rIQmAc8BNK/:14819:0:99999:7:::
bin:*:14715:0:99999:7:::
daemon:*:14715:0:99999:7:::
ftp:*:14715:0:99999:7:::
nobody:*:14715:0:99999:7:::
5,制作yaffs2根文件系统镜像
用天嵌科技提供的yaffs2文件系统镜像制作工具mkyaffs2image,制作根文件系统镜像。
#./mkyaffs2image root_fs root_fs.bin
6,将根文件系统镜像下载到nand flash并启动
启动信息如下:
Start Linux ...
Copy linux kernel from 0x00200000 to 0x30008000, size = 0x00200000 ... Copy Kernel to SDRAM done,NOW, Booting Linux......
Uncompressing Linux.......................................................................................................................... done, booting the kernel.
Linux version 2.6.30.4-EmbedSky (root@EmbedSky) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203) ) #9 Wed Aug 26 15:49:19 CST 2009
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instr tion cache
Machine: TQ2440
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 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/mtdblock2 init=/linuxrc console=ttySAC0
NR_IRQS:85
irq: clearing pending ext status 00080000
irq: clearing s pending status 00000003
irq: clearing s pending 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: 60876KB available (3440K code, 374K data, 180K init, 0K highmem)
SL : Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)
Mount-cache hash table entries: 512
CPU: Testing write b?r coherency: ok
net_namespace: 296 bytes
NET: Registered protocol family 16
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 s system initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver h
usbcore: registered new device driver usb
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus freqncy set to 97 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
cfg80211: Calling CRDA to update world regulatory domain
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
yaffs Aug 26 2009 15:25:31 Installing.
msgmni has been set to 119
alg: No test for stdrng (krng)
io scheduler noop registered (default)
Console: switching to colour frame b?r device 40x15
fb0: s3c2410fb frame b?r device
backlight initialized
GPIO-Control initialized
PWM-Test initialized
adc initialized
s3c2440- rt.0: tq2440_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440- rt.1: tq2440_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440- rt.2: tq2440_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
loop: module loaded
Driver 'sd' needs updating - please use bus_type methods
dm9000 Ethernet Driver, V1.31
Now use the default MAC address: 10:23:45:67:89:ab
eth0 (dm9000): not using net_device_ops yet
eth0: dm9000e at c4814000,c4818004 IRQ 51 MAC: 10:23:45:67:89:ab (EmbedSky)
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns
NAND device: Man?turer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 1275 at 0x000009f60000
Bad eraseblock 1987 at 0x00000f860000
Creating 3 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "EmbedSky_Board_ oot"
0x000000200000-0x000000400000 : "EmbedSky_Board_kernel"
0x000000400000-0x00000ff80000 : "EmbedSky_Board_yaffs2"
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: New USB device found, idVendor=1d6b, idProd t=0001
usb usb1: New USB device strings: Mfr=3, Prod t=2, SerialNumber=1
usb usb1: Prod t: S3C24XX OHCI
usb usb1: Man?turer: Linux 2.6.30.4-EmbedSky ohci_hcd
usb usb1: SerialNumber: s3c24xx
usb usb1: configuration #1 chosen from 1 choice
h 1-0:1.0: USB h found
h 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver usbserial
usbserial: USB Serial Driver core
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
s3c2410_?: debugfs dir creation failed -19
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
mice: PS/2 mouse device common for all mice
TQ2440 To hScreen s cessfully loaded
input: TQ2440 To hScreen as /devices/virt l/input/input0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
Linux video capture interface: v2.00
zc0301: V4L2 driver for ZC0301[P] Image Processor and Control Chip v1:1.10
usbcore: registered new interface driver zc0301
gspca: main v2.5.0 registered
usbcore: registered new interface driver zc3xx
zc3xx: registered
usbcore: registered new interface driver uvcvideo
USB Video Class driver (v0.1.0)
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
mapped channel 0 to 0
s3c2440-sdi s3c2440-sdi: powered down.
s3c2440-sdi s3c2440-sdi: initialisation done.
s3c2440-sdi s3c2440-sdi: powered down.
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.18a.
No device for DAI ?X
No device for DAI s3c24xx-i2s
S3C24XX_?X SoC A io driver
?X SoC A io Codec
asoc: ?X <-> s3c24xx-i2s mapping ok
ALSA device list:
#0: S3C24XX_?X (?X)
TCP c ic registered
RPC: Registered p transport module.
RPC: Registered tcp transport module.
lib80211: common routines for IEEE802.11 drivers
s3c2410-rtc s3c2410-rtc: setting system clock to 2028-01-02 05:53:00 UTC (1830405180)
yaffs: dev is 32505858 name is "mtdblock2"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.2, "mtdblock2"
yaffs: auto selecting yaffs2
block 1244 is bad
block 1956 is bad
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:2.
Freeing init memory: 180K
----------mount all----------
**************************************
**************************************
Kernel version:linux-2.6.30.4
Date:2010.09.16
**************************************
Please press Enter to activate this console.