uboot的目的 启动内核
内核的目的是运行应用程序
应用程序放在根文件系统那里 我们这节课 就是构建根文件系统
init_post // 执行应用程序的函数
内核怎么样启动第一个应用程序
sys_open((const char __user *) "/dev/console",
(void) sys_dup(0);
(void) sys_dup(0);
if (execute_command) {
run_init_process(execute_command);
printk(KERN_WARNING "Failed to execute %s. Attempting "
"defaults...\n", execute_command);
}
run_init_process("/sbin/init");
run_init_process("/etc/init");
run_init_process("/bin/init");
run_init_process("/bin/sh");
执行命令行 init
block 1931 is bad
VFS: Mounted root (yaffs filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 764, tty '': '/etc/init.d/rcS'
Please press Enter to activate this console. tsdev (compaq touchscreen emulation) is scheduled for removal.
See Documentation/feature-removal-schedule.txt for details.
Warning: TimeZone::data Can't create a valid data object for 'Europe/Oslo'
Warning: could not register server
starting pid 772, tty '/dev/s3c2410_serial0': '/bin/sh'
#
#
#
#
#
#
#
#
# ps
执行 ls 就相当于执行 busybox ls
# ls -l /bin/ls
lrwxrwxrwx 1 0 0 7 Dec 24 2010 /bin/ls -> busybox
# ls -l /bin/cp
lrwxrwxrwx 1 0 0 7 Dec 24 2010 /bin/cp -> busybox
# busybox ls
bin lib mnt root tmp
dev linuxrc opt sbin usr
etc lost+found proc sys
# ls /sbin/init -l
lrwxrwxrwx 1 0 0 14 Dec 24 2010 /sbin/init -> ../bin/busybox
init 程序
读取配置文件
解析配置文件
执行 用户应用程序
busybox-----init_main
parase_inittab
file = fopen(INITTAB, "r"); //打开配置文件/etc/inittab
inittab 格式
<id>:<runlevels>:<action>:<process>
id=> /dev/id, 用作终端:stdin stdout stderr : printf scanf err
runlevels:忽略
action:执行时机
process:应用程序或脚本
new_init_action
-/bin/sh
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
new_init_action(ASKFIRST, "-/bin/sh" ,VC_2);
new_init_action(ASKFIRST, "-/bin/sh" ,"/dev/vc/2");
static void new_init_action(int action, const char *command, const char *cons)
作用
创建一个new_init_action结构 填充
把这个结构放入new_init_action_list
从默认的 new_init_action结构 反推出配置文件
/* Reboot on Ctrl-Alt-Del */
new_init_action(CTRLALTDEL, "reboot", "");
/* Umount all filesystems on halt/reboot */
new_init_action(SHUTDOWN, "umount -a -r", "");
/* Swapoff on halt/reboot */
if (ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", "");
/* Prepare to restart init when a HUP is received */
new_init_action(RESTART, "init", "");
/* Askfirst shell on tty1-4 */
new_init_action(ASKFIRST, bb_default_login_shell, "");
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
/* sysinit */
new_init_action(SYSINIT, INIT_SCRIPT, "");
run_actions(SYSINIT);
run_actions(WAIT);
run_actions(ONCE);
while (1) {
/* run the respawn stuff */
run_actions(RESPAWN);
/* run the askfirst stuff */
run_actions(ASKFIRST);
配置 编译 busybox
root@liuhehe-machine:/home/system# tar xjf busybox-1.7.0.tar.bz2
root@liuhehe-machine:/home/system/busybox-1.7.0# make menuconfig
root@liuhehe-machine:/home/system/busybox-1.7.0# vi Makefile
CROSS
CROSS_COMPILE
CROSS_COMPILE ?=arm-linux-
TAB补全功能
# cd /l
/lib/ /lost+found/
# cd /lost\+found/
#
root@liuhehe-machine:/home/system/busybox-1.7.0# ls /home/rootfs/
liuhehe-machine_test.c uImage_4.3
root@liuhehe-machine:/home/system/busybox-1.7.0# mkdir -p /home/rootfs/first_fs
root@liuhehe-machine:/home/system/busybox-1.7.0# ls /home/rootfs
first_fs liuhehe-machine_test.c uImage_4.3
root@liuhehe-machine:/home/system/busybox-1.7.0# make CONFIG_PREFIX=/home/rootfs/first_fs install
root@liuhehe-machine:/home/system/busybox-1.7.0# cd /home/rootfs/first_fs
root@liuhehe-machine:/home/rootfs/first_fs# ls
bin linuxrc sbin usr
root@liuhehe-machine:/home/rootfs/first_fs# ls bin/ls -l
lrwxrwxrwx 1 root root 7 4月 24 13:13 bin/ls -> busybox
构建根文件系统
root@liuhehe-machine:/home/rootfs/first_fs# ls /dev/console /dev/null -l
crw------- 1 root root 5, 1 4月 24 09:18 /dev/console
crw-rw-rw- 1 root root 1, 3 4月 24 09:13 /dev/null
root@liuhehe-machine:/home/rootfs/first_fs# ls
bin dev linuxrc sbin usr
root@liuhehe-machine:/home/rootfs/first_fs# cd dev/
root@liuhehe-machine:/home/rootfs/first_fs/dev# mknod console c 5 1
root@liuhehe-machine:/home/rootfs/first_fs/dev#
root@liuhehe-machine:/home/rootfs/first_fs/dev# mknod null c 1 3
root@liuhehe-machine:/home/rootfs/first_fs/dev# ls -l
总用量 0
crw-r--r-- 1 root root 5, 1 4月 24 13:23 console
crw-r--r-- 1 root root 1, 3 4月 24 13:24 null
创建完毕
root@liuhehe-machine:/home/rootfs/first_fs/dev# cd ..
root@liuhehe-machine:/home/rootfs/first_fs# ls
bin dev linuxrc sbin usr
root@liuhehe-machine:/home/rootfs/first_fs# mkdir etc
root@liuhehe-machine:/home/rootfs/first_fs# vi etc/inittab
console::askfirst:-/bin/sh
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- 插入 --
root@liuhehe-machine:/home/rootfs/first_fs# cat etc/inittab
console::askfirst:-/bin/sh
root@liuhehe-machine:/home/rootfs/first_fs# cd /opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib
root@liuhehe-machine:/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib# ls -l
root@liuhehe-machine:/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib# mkdir /home/rootfs/first_fs/lib
root@liuhehe-machine:/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib# ls /home/rootfs/first_fs/
bin dev etc lib linuxrc sbin usr
root@liuhehe-machine:/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib# cd /home/rootfs/first_fs
root@liuhehe-machine:/home/rootfs/first_fs# ls
bin dev etc lib linuxrc sbin usr
root@liuhehe-machine:/home/rootfs/first_fs# ls dev lib
dev:
console null
lib:
ld-2.9.so libgomp.so.1.0.0 libmudflapth.so libnss_nis.so.2 libssp.so.0
ld-linux.so.3 libid3tag.so libmudflapth.so.0 libpcprofile.so libssp.so.0.0.0
libanl-2.9.so libid3tag.so.0 libmudflapth.so.0.0.0 libpng12.so libstdc++.so
libanl.so.1 libid3tag.so.0.3.0 libnsl-2.9.so libpng12.so.0 libstdc++.so.6
libBrokenLocale-2.9.so libjpeg.so libnsl.so.1 libpng12.so.0.35.0 libstdc++.so.6.0.13
libBrokenLocale.so.1 libjpeg.so.62 libnss_compat-2.9.so libpng.so libthread_db-1.0.so
libc-2.9.so libjpeg.so.62.0.0 libnss_compat.so.2 libpng.so.3 libthread_db.so.1
libcrypt-2.9.so libm-2.9.so libnss_dns-2.9.so libpng.so.3.35.0 libts-0.0.so.0
libcrypt.so.1 libmad.so libnss_dns.so.2 libpthread-2.9.so libts-0.0.so.0.1.1
libc.so.6 libmad.so.0 libnss_files-2.9.so libpthread.so.0 libts.so
libdl-2.9.so libmad.so.0.2.1 libnss_files.so.2 libresolv-2.9.so libutil-2.9.so
libdl.so.2 libmemusage.so libnss_hesiod-2.9.so libresolv.so.2 libutil.so.1
libgcc_s.so libm.so.6 libnss_hesiod.so.2 librt-2.9.so libuuid.so
libgcc_s.so.1 libmudflap.so libnss_nis-2.9.so librt.so.1 libuuid.so.1
libgomp.so libmudflap.so.0 libnss_nisplus-2.9.so libSegFault.so libuuid.so.1.2
libgomp.so.1 libmudflap.so.0.0.0 libnss_nisplus.so.2 libssp.so
这就是最小的根文件系统 怎么烧到开发板上 做一个映像文件
root@liuhehe-machine:/home/rootfs/first_fs# cd /home/system/
root@liuhehe-machine:/home/system# ls
busybox-1.7.0 linux-2.6.22.6.tar.bz2 uImage_4.3
busybox-1.7.0.tar.bz2 s3c_mci_patch.tar.bz2 VMwareTools-9.6.2-1688356.tar.gz
examples.desktop u-boot-1.1.6 vmware-tools-distrib
linux-2.6.22.6 u-boot-1.1.6_jz2440.patch yaffs_source.tar.gz
linux-2.6.22.6_jz2440.patch u-boot-1.1.6_jz2440.tar.bz2 yaffs_source_util_larger_small_page_nand.tar.bz2
linux-2.6.22.6_jz2440.tar.bz2 u-boot-1.1.6.tar.bz2 yaffs_util_mkyaffsimage.patch
root@liuhehe-machine:/home/system# tar xjf yaffs_source_util_larger_small_page_nand.tar.bz2
root@liuhehe-machine:/home/system# ls
busybox-1.7.0 linux-2.6.22.6.tar.bz2 VMwareTools-9.6.2-1688356.tar.gz
busybox-1.7.0.tar.bz2 s3c_mci_patch.tar.bz2 vmware-tools-distrib
Development_util_ok u-boot-1.1.6 yaffs_source.tar.gz
examples.desktop u-boot-1.1.6_jz2440.patch yaffs_source_util_larger_small_page_nand.tar.bz2
linux-2.6.22.6 u-boot-1.1.6_jz2440.tar.bz2 yaffs_util_mkyaffsimage.patch
linux-2.6.22.6_jz2440.patch u-boot-1.1.6.tar.bz2
linux-2.6.22.6_jz2440.tar.bz2 uImage_4.3
root@liuhehe-machine:/home/system# cd Development_util_ok
root@liuhehe-machine:/home/system/Development_util_ok# ls
yaffs yaffs2
root@liuhehe-machine:/home/system/Development_util_ok# cd yaffs2
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2# ls
devextras.h README-linux yaffs_ecc.c yaffs_mtdif1.h yaffs_nand.h yaffs_qsort.o
direct README-linux-patch yaffs_ecc.h yaffs_mtdif1.o yaffs_nand.o yaffs_tagscompat.c
Kconfig utils yaffs_ecc.o yaffs_mtdif2.c yaffs_packedtags1.c yaffs_tagscompat.h
Makefile yaffs2.ko yaffs_fs.c yaffs_mtdif2.h yaffs_packedtags1.h yaffs_tagscompat.o
Makefile.kernel yaffs2.mod.c yaffs_fs.o yaffs_mtdif2.o yaffs_packedtags1.o yaffs_tagsvalidity.c
moduleconfig.h yaffs2.mod.o yaffs_guts.c yaffs_mtdif.c yaffs_packedtags2.c yaffs_tagsvalidity.h
Module.symvers yaffs2.o yaffs_guts.h yaffs_mtdif.h yaffs_packedtags2.h yaffs_tagsvalidity.o
mtdemul yaffs_checkptrw.c yaffs_guts.o yaffs_mtdif.o yaffs_packedtags2.o yportenv.h
patches yaffs_checkptrw.h yaffsinterface.h yaffs_nand.c yaffs_qsort.c
patch-ker.sh yaffs_checkptrw.o yaffs_mtdif1.c yaffs_nandemul2k.h yaffs_qsort.h
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2# cd utils/
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# pwd
/home/system/Development_util_ok/yaffs2/utils
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# ls
Makefile mkyaffs2image.c mkyaffsimage.c nand_ecc.c yaffs_packedtags1.
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# make
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# ls -l
总用量 132
-rw------- 1 liuhehe liuhehe 1770 7月 8 2008 Makefile
-rwxr-xr-x 1 root root 17661 4月 24 14:14 mkyaffs2image
-rw------- 1 liuhehe liuhehe 19669 7月 8 2008 mkyaffs2image.c
-rw-r--r-- 1 root root 8936 4月 24 14:14 mkyaffs2image.o
-rwxr-xr-x 1 root root 17272 4月 24 14:14 mkyaffsimage
-rw------- 1 liuhehe liuhehe 16206 2月 29 2008 mkyaffsimage.c
-rw-r--r-- 1 root root 7720 4月 24 14:14 mkyaffsimage.o
-rw------- 1 liuhehe liuhehe 6731 2月 29 2008 nand_ecc.c
-rw-r--r-- 1 root root 2020 4月 24 14:14 nand_ecc.o
lrwxrwxrwx 1 root root 14 4月 24 14:14 yaffs_ecc.c -> ../yaffs_ecc.c
-rw-r--r-- 1 root root 2912 4月 24 14:14 yaffs_ecc.o
-rw------- 1 liuhehe liuhehe 1416 2月 29 2008 yaffs_packedtags1.c
-rw-r--r-- 1 root root 1560 4月 24 14:14 yaffs_packedtags1.o
lrwxrwxrwx 1 root root 22 4月 24 14:14 yaffs_packedtags2.c -> ../yaffs_packedtags2.c
-rw-r--r-- 1 root root 2504 4月 24 14:14 yaffs_packedtags2.o
lrwxrwxrwx 1 root root 23 4月 24 14:14 yaffs_tagsvalidity.c -> ../yaffs_tagsvalidity.c
-rw-r--r-- 1 root root 1100 4月 24 14:14 yaffs_tagsvalidity.o
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# ls /usr/local/bin
leds_0x31000000.bin uImage_4.3
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# cp mkyaffs2image /usr/local/bin/
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# chmod +x /usr/local/bin/mkyaffs2image
root@liuhehe-machine:/home/system/Development_util_ok/yaffs2/utils# cd /home
root@liuhehe-machine:/home# ls
liuhehe rootfs system tftp tools
root@liuhehe-machine:/home# cd rootfs
root@liuhehe-machine:/home/rootfs# ls
first_fs liuhehe-machine_test.c uImage_4.3
root@liuhehe-machine:/home/rootfs# mkyaffs2image
mkyaffs2image: image building tool for YAFFS2 built Apr 24 2015
usage: mkyaffs2image dir image_file [convert]
dir the directory tree to be converted
image_file the output file to hold the image
'convert' produce a big-endian image from a little-endian machine
root@liuhehe-machine:/home/rootfs# mkyaffs2image first_fs first_fs.yaffs2
root@liuhehe-machine:/home/rootfs# ls
first_fs first_fs.yaffs2 liuhehe-machine_test.c uImage_4.3
OpenJTAG> tftp 0x30000000 first_fs.yaffs2
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
could not establish link
TFTP from server 192.168.1.101; our IP address is 192.168.1.103
Filename 'first_fs.yaffs2'.
Load address: 0x30000000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
######################################checksum bad
###########################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
##########################################################
done
Bytes transferred = 10610688 (a1e800 hex)
OpenJTAG> nand erase 0x200000 0x800000
NAND erase: device 0 offset 0x200000, size 0x800000
Erasing at 0x9e0000 -- 100% complete.
OK
OpenJTAG> nand write.yaffs2 0x30000000 0x200000 $(filesize)
OpenJTAG> nand write.yaffs2 0x30000000 0x200000 $(filesize)
NAND write: device 0 offset 0x200000, size 0xa1e800
10610688 bytes written: OK
# ls
bin lib mnt root tmp
dev linuxrc opt sbin usr
etc lost+found proc sys
# cat /etc/inittab
# /etc/inittab
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
# ls
bin lib mnt root tmp
dev linuxrc opt sbin usr
mount -t proc none /proc //不是qt时用的
# ps
PID Uid VSZ Stat Command
1 0 3092 S init
2 0 SW< [kthreadd]
3 0 SWN [ksoftirqd/0]
4 0 SW< [watchdog/0]
5 0 SW< [events/0]
6 0 SW< [khelper]
55 0 SW< [kblockd/0]
56 0 SW< [ksuspend_usbd]
59 0 SW< [khubd]
61 0 SW< [kseriod]
73 0 SW [pdflush]
74 0 SW [pdflush]
75 0 SW< [kswapd0]
76 0 SW< [aio/0]
710 0 SW< [mtdblockd]
745 0 SW< [kmmcd]
773 0 3096 S -sh
774 0 15980 S qpe
795 0 9044 S < /opt/Qtopia/bin/qss
796 0 11492 S N /opt/Qtopia/bin/quicklauncher
799 0 3096 R ps
# cd /proc/
# ls
1 745 cpuinfo kallsyms slabinfo
2 75 crypto kmsg stat
3 76 devices loadavg swaps
4 773 diskstats locks sys
5 774 driver meminfo sysrq-trigger
55 795 execdomains misc sysvipc
56 796 fb modules timer_list
59 800 filesystems mounts tty
6 asound fs mtd uptime
61 buddyinfo interrupts net version
710 bus iomem partitions vmstat
73 cmdline ioports scsi yaffs
74 cpu irq self zoneinfo
# cd 1
# ls -l fd
lrwx------ 1 0 0 64 Jan 1 00:04 0 -> /dev/console 输出
lrwx------ 1 0 0 64 Jan 1 00:04 1 -> /dev/console 输入
lrwx------ 1 0 0 64 Jan 1 00:04 2 -> /dev/console 错误
root@liuhehe-machine:/home/rootfs/fs_qtopia# ls
bin dev etc lib linuxrc mnt opt proc root sbin sys tmp usr
root@liuhehe-machine:/home/rootfs/fs_qtopia#
root@liuhehe-machine:/home/rootfs/fs_qtopia#
root@liuhehe-machine:/home/rootfs/fs_qtopia# vi etc/inittab
# /etc/inittab
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"etc/inittab" 6L, 132C
root@liuhehe-machine:/home/rootfs/fs_qtopia# cat etc/fstab
# device mount-point type options dump fsck order
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
查看当前挂载了哪些根文件系统
# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / yaffs rw 0 0
proc /proc proc rw 0 0
tmpfs /tmp tmpfs rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
udev 自动创建 /Dev/设备节点
mdv
# ifconfig eth0 192.168.1.17
从flash 上启动根文件系统 再用 命令挂接NFS
挂接NFS
服务器允许那个目录 可被挂接 在/etc/exports下定义
单板去挂接
/etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
/home/rootfs *(rw,sync,no_root_squash)
# chmod 777 -R /home/rootfs
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
挂接 必须先配置好 nfs 服务
root@liuhehe-machine:~# mount -t nfs 192.168.1.102:/home/rootfs/fs_qtopia /mnt 自己 挂载自己看看可以挂载吗
挂接成功
挂载开发板
# mount -t nfs -o nolock 192.168.1.102:/home/rootfs/fs_qtopia /mnt
# ls /mnt
bin etc linuxrc opt root sys usr
dev lib mnt proc sbin tmp
#
挂载好了
这是我们在 linux 服务器 挂载目录下 创建一个文件 我们在 开发板 挂载 目录下 就可以看到
root@liuhehe-machine:/home/rootfs/fs_qtopia# ls
bin dev etc lib linuxrc mnt opt proc root sbin sys tmp usr
root@liuhehe-machine:/home/rootfs/fs_qtopia# echo hello > test.txt
root@liuhehe-machine:/home/rootfs/fs_qtopia# ls
bin dev etc lib linuxrc mnt opt proc root sbin sys test.txt tmp usr
# ls /mnt
bin etc linuxrc opt root sys tmp
dev lib mnt proc sbin test.txt usr
# cat /mnt/test.txt
hello