当前目录:/home/xhq/(正在学习)
#mkdir build
#cd build
#mkdir rootfs
#mkdir scripts
#mkdir user
#ls
build linux rootfs scripts user Makefile
下文中的环境变量
-----------------------------------------------------------------------------------------------
CROSS_COMPILE=arm-linux-gnueabihf-
-----------------------------------------------------------------------------------------------
一、下载最新busybox 放到user/下
#cd user/busybox
1、#make menuconfig
Busybox Setting--->|
|General Configuration---><*>Don't use /usr
|
|Build Options--->|<*>Bulid Busbox as a static binary()
| |
| |(arm-linux-gnueabihf-)Cross Compiler prefix 解释:配置交叉编译工具
|
|Installation Options--->(../../rootfs)Bustbox installation prefix 解释:配置安装目录
Init Utilities--->|
|[ ]Support running init from within an initrd(not initramfs) 解释:去掉生成 linuxrc
2、#make
3、#make install
在../../rootfs 下产生/bin,/sbin
二、配置rootfs
#cd rootfs/
1、#ln -fs bin/busybox init (配置init 进程)
2、#mkdir -p dev etc etc/init.d home lib proc sys tmp user
3、使用busybox 中的 mdev(在sbin/下) 来自动创建设备节点,所以只需要先创建如下两个设备文件
#cd dev/
#mknod -m 660 console c 5 1
#mknod -m 660
null c 1 3
将busybox/examples/mdev.conf 拷贝到 etc/下
4、inittab
将busybox/examples/inittab 拷贝到 etc/下
-
# Boot-time system configuration/initialization script.
-
# This is run first except when booting in single-user mode.
-
#
-
::sysinit:/etc/init.d/rcS
-
# Start an "askfirst" shell on the console (whatever that may be)
-
::askfirst:-/bin/sh
-
# Stuff to do when restarting the init process
-
::restart:/sbin/init
-
-
# Stuff to do before rebooting
-
::ctrlaltdel:/sbin/reboot
-
::shutdown:/bin/umount -a -r
-
::shutdown:/sbin/swapoff -a
5、创建etc/init.d/rcS
内容:
-
#!/bin/sh
-
-
#add setting here for auto start program
-
PATH=/sbin:/bin:/usr/sbin:/usr/bin
-
runlevel=S
-
prevlevel=N
-
umask 022
-
export PATH runlevel prevlevel
-
-
#See docs/mdev.txt
-
#mount all fs in fstab,proc and sysfs are must for mdev
-
mount -a
-
-
#create device nodes
-
echo /sbin/mdev > /proc/sys/kernel/hotplug
-
-
#seed all device nodes
-
mdev -s
-
-
#create pts directory for remote login such as SSH and telnet
-
mkdir -p /dev/pts
-
mount -t devpts devpts /dev/pts
-
-
-
-
if [ -f /etc/hostname ]; then
-
/bin/hostname -F /etc/hostname
-
fi
-
-
if [ -e /sys/class/net/eth0 ]; then
-
ifconfig eth0 192.168.1.15
-
fi
-
-
echo "rcS done!"
6、创建etc/fstab (由rcS中 mount -a 调用)
内容:
-
#
-
# /etc/fstab: static file system information.
-
#
-
#
-
#
-
# file system mount type options dump pass
-
-
#for mdev
-
proc /proc proc defaults 0 0
-
sysfs /sys sysfs defaults 0 0
-
-
#make sure /dev /tmp /var are tmpfs(tmpfs use ram as media) thus can be r/w
-
tmpfs /tmp tmpfs defaults 0 0
-
tmpfs /dev tmpfs defaults 0 0
-
tmpfs /var tmpfs defaults 0 0
-
-
#usbfs /proc/bus/usb usbfs defaults 0 0
三、将roofs编译进内核
#cd linux
1、make menuconfig
General setup--->|
|[*]Initial RAM filesystem and RAM disk (initramfs / initrd) support
|(../rootfs)Initramfs source file(s)
|
|
|[*]support initial ramdisks compressed using gzip
|
|Build-in initramfs compression mode (Gzip)
2、编译并安装内核模块到rootfs/
make -C linux O=build ARCH=arm CROSS_COMPILE=${CROSS_COMPILE} -j4 INSTALL_MOD_PATH=output modules
make -C linux O=build ARCH=arm CROSS_COMPILE=${CROSS_COMPILE} -j4 INSTALL_MOD_PATH=output modules_install
3、生成uImage
make -C linux O=build ARCH=arm CROSS_COMPILE=${CROSS_COMPILE} -j4 INSTALL_MOD_PATH=output uImage
cd build/ && ${CROSS_COMPILE}objcopy -R .note.gnu.build-id -S -O binary vmlinux bImage
阅读(2656) | 评论(0) | 转发(0) |