一、准备源码包
busybox-1.21.1.tar.bz2
yaffs2-source.tar
二、编译busybox
1.解压busybox-1.21.1.tar.bz2到Ubuntu的家目录
tar -jxf /mnt/hgfs/share/busybox-1.21.1.tar.bz2 -C ~
cd busybox-1.21.1
2.设置顶层目录的Makefile文件
a.修改交叉编译
CROSS_COMPILE ?= /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
b.指定当前运行硬件平台为arm
ARCH ?= arm
3.阅读说明文档README,有以下描述,
Using busybox:
BusyBox is extremely configurable. This allows you to include only the
components and options you need, thereby reducing binary size. Run ‘make
config’ or ‘make menuconfig’ to select the functionality that you wish to
enable. (See ‘make help’ for more commands.)
4.输入make menuconfig
a.将busybox编译为静态库可执行文件,运行时候可以独立于其他库
Busybox Settings —>
Build Options —>
[*] Build BusyBox as a static binary
b.添加vi工具
Busybox Settings —>
Busybox Library Tuning —>
[*] vi-style line editing commands
c.添加insmod、rmmod、lsmod等这命令
Linux Module Utilities —>
[ ] Simplified modutils
[] insmod
[] rmmod
[] lsmod
[] Pretty output
[] modprobe
[] Blacklist support
[*] depmod
保存所有信息退出。
5.输入make 命令进行编译文件系统源代码
6.执行make install命令
/_install//usr/bin/flock -> …/…/bin/busybox
./_install//usr/bin/fold -> …/…/bin/busybox
./_install//usr/bin/free -> …/…/bin/busybox
./_install//usr/bin/ftpget -> …/…/bin/busybox
./_install//usr/bin/ftpput -> …/…/bin/busybox
./_install//usr/bin/fuser -> …/…/bin/busybox
./_install//usr/bin/groups -> …/…/bin/busybox
./_install//usr/bin/hd -> …/…/bin/busybox
将生成的工具安装到当前目录下的_install目录。
三、补全根文件系统文件夹
这里我们使用脚本一次性生成
#!/bin/sh
echo "------1.Create root directons starting--------"
#mkdir bin sbin usr
mkdir lib etc dev sys proc tmp var opt mnt home root media
mkdir home/gec
echo "------2.Create usr sub-directons starting--------"
cd usr
#mkdir bin sbin
mkdir lib local
echo "------3.Create usr/local sub-directons starting--------"
cd local
mkdir bin sbin lib
cd ../..
echo "------4.Create etc sub-directons file starting--------"
cd etc
touch inittab
touch fstab
touch profile
touch passwd
touch group
touch shadow
touch resolv.conf
touch mdev.conf
touch inetd.conf
mkdir rc.d
mkdir init.d
touch init.d/rcS
chmod +x init.d/rcS
mkdir sysconfig
touch sysconfig/HOSTNAME
cd ..
echo "------5.Create dev inode starting--------"
cd dev
mknod console c 5 1
chmod 777 console
mknod null c 1 3
chmod 777 null
cd ..
echo "------6.Create var sub-directons starting--------"
cd var
mkdir log
cd ..
echo "------7.Create etc sub-directons file starting--------"
mkdir etc/hotplug/usb -p
mkdir etc/hotplug/sd -p
touch etc/hotplug/usb/udisk_insert
touch etc/hotplug/usb/udisk_remove
touch etc/hotplug/sd/sd_insert
touch etc/hotplug/sd/sd_remove
chmod +x etc/hotplug/usb/udisk_insert
chmod +x etc/hotplug/usb/udisk_remove
chmod +x etc/hotplug/sd/sd_insert
chmod +x etc/hotplug/sd/sd_remove
四、添加运行库文件
这里根据自己交叉编译器路径进行操作:我的交叉编译路径是/usr/local/arm/
执行
cp /usr/local/arm/arm-none-linux-gnueabi/libc/lib/so lib -rdf
还有usr/lib的也要拷贝过来
cp /usr/local/arm/arm-none-linux-gnueabi/libc/usr/lib so usr/lib -rdf
五、修改系统配置文件
主要修改etc以下文件
1、etc/inittab
2、etc/profile
3、etc/init.d/rcS
4、etc/sysconfig/HOSTNAME
…
修改的文件太多,我打包好了
解压etc.tgz到etc下
六、制作mkyaffs2image
解压yaffs2-source
tar xvf yaffs2-source.tar
进入utils目录
cd utils
make
得到mkyaffsimage和mkyaffs2image,mkyaffsimage和mkyaffs2image是制作2中不同文件系统的命令,我们需要制作的是yaffs2
把mkyaffs2image丢到环境变量PATH中
sudo cp mkyaffs2image /usr/local/bin/
七、制作镜像
进入刚才的busybox目录
mkyaffs2image _install/ rootfs.img
八、烧写文件系统
tftp 0x40000000 rootfs.img
nand erase 0xe00000 0x1F200000
nand write.yaffs 0x40000000 0xe00000 0x6c1680
0x1F200000是剩余FLASH大小(除去uboot、kernel这些)
0x6c1680是文件大小
九、重启运行
boot或者重启电源也可以
shell命令显示异常,没有用户名
id: unknown ID 0
解决方法:
1、添加root用户,输入以下命令
adduser root
提示:passwd: unknown uid 0
2、修改用户ID与组ID,输入以下命令:
vi /etc/passwd
将
root:x:1000:1000:Linux User,,,:/home/root:/bin/sh
修改为
root:x:0:0:Linux User,,,:/home/root:/bin/sh
十、测试
#include <stdio.h>
int main(int argc,char *argv[])
{
printf("hello world\n");
return 0;
}
arm-linux-gcc test.c -o test
丢到开发板运行
chmod 777 test
./test
打印如下
[root@linuxbd /]# chmod 777 test
[root@linuxbd /]# ./test
hello world