微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > ARM技术讨论 > 编译BUSYBOX建立根文件系统

编译BUSYBOX建立根文件系统

时间:10-02 整理:3721RD 点击:
1,编译BUSYBOX
A,传送文件包到LINUX系统并解压
     利用SecureCRT 5.1.3登陆,传送文件到系统
  root@yuanxh-desktop:~# cd /home/yuanxh/at91_works/
  root@yuanxh-desktop:/home/yuanxh/at91_works# rz
  在SecureCRT弹出的窗口中选择busybox-1.8.2.tar.bz2包;
B,解压及指定编译器
  root@yuanxh-desktop:/home/yuanxh/at91_works# tar xjvf busybox-1.8.2.tar.bz2
  root@yuanxh-desktop:/home/yuanxh/at91_works# cd busybox-1.8.2
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# vi Makefile
        把 EXTRAVERSION = -9gsam9260ek 写上自己版本标识,指定体系结构和编译器
        ARCH           ?= arm
        CROSS_COMPILE  ?= /usr/local/arm/eldk-4.1/usr/bin/arm-linux-
C,编译生成全部目标码
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make help
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make defconfig
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make install
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# mv _install/ rootfs
        root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# cp -dpR examples/bootfloppy/etc rootfs/
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# tar czvf busybox-9gsam9260ek.tar.gz rootfs/
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# sz busybox-9gsam9260ek.tar.gz
D,个性化配置BUSYBOX
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make menuconfig
E,清除内核目标码恢复未配置状态
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make clean
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make distclean
  root@yuanxh-desktop:/home/yuanxh/at91_works/busybox-1.8.2# make mrproper
2,编译RZSZ软件包
A,在http://ftp.uni-koeln.de/util/comm/
  上下载rzsz-3.49.zip
B,上传到LINUX系统
  root@yuanxh-desktop:/home/yuanxh/at91_works# rz
C,解压软件包
  在虚拟机窗口中右击rzsz-3.49.zip,选择“解压到此处”来解压,
D,进入软件包
  root@yuanxh-desktop:/home/yuanxh/at91_works# cd rzsz-3.49
E,指定编译器
  root@yuanxh-desktop:/home/yuanxh/at91_works/rzsz-3.49# vi makefile
  修改如下内容
  CC=/usr/local/arm/eldk-4.1/usr/bin/arm-linux-gcc
F,编译生成目标码
  root@yuanxh-desktop:/home/yuanxh/at91_works/rzsz-3.49# make posix
  root@yuanxh-desktop:/home/yuanxh/at91_works/rzsz-3.49# tar czvf rzsz-9gsam9260ek.tar.gz rz sz
  root@yuanxh-desktop:/home/yuanxh/at91_works/rzsz-3.49# sz rzsz-9gsam9260ek.tar.gz
  注意:此软件有版权保护,软件中REGISTERED如果没有被宏定义,程序在使用中提示使用越权;
3,建立根文件系统
A,建立BUSYBOX基本目录
  root@yuanxh-desktop:/home/yuanxh/at91_works# mkdir rootfs-9g9sam9260ek
  root@yuanxh-desktop:/home/yuanxh/at91_works# cd rootfs-9g9sam9260ek/
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rz
  传送上节编译生成的busybox-9gsam9260ek.tar.gz目标码包
B,建立树型根目录
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# tar xzvf busybox-9gsam9260ek.tar.gz
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# cd rootfs/
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# mkdir -pv app dev home mnt proc sys tmp var opt
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# install -dv -m 0750 root
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# mkdir -pv var/{lock,log,lib,run,tmp}
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# mkdir -pv usr/{lib,share}
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# chmod 1777 tmp var/tmp
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# mkdir -pv dev/pts  
C,添加动态库文件
  root@yuanxh-desktop:/home/yuanxh# cd /usr/local/arm/eldk-4.1/arm
  root@yuanxh-desktop:/usr/local/arm/eldk-4.1/arm# tar czvf lib-eldk-4.1.tar.gz lib/
  root@yuanxh-desktop:/usr/local/arm/eldk-4.1/arm# mv lib-eldk-4.1.tar.gz /home/yuanxh/at91_works/rootfs-9g9sam9260ek
  root@yuanxh-desktop:/usr/local/arm/eldk-4.1/arm# cd /home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# tar xzvf ../lib-eldk-4.1.tar.gz
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# arm-linux-strip --remove-section=.note --remove-section=.comment lib/*.so
  注意:可以删除部分不常用字的库以减小体积。
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/lib# rm -rf *.a *.o security gconv
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/lib# rm -rf *.7f *.79 libnss*  libmudflap*
D,添加设备节点
     root@yuanxh-desktop:/home/yuanxh/at91_works# cd rootfs-9g9sam9260ek/rootfs/
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# cp -dpR /dev/* dev/
E,添加系统配置
     在etc/inittab中加入以下内容
     #id:3:initdefault:
     #su:S016:once:/sbin/sulogin
     #si::sysinit:/etc/rc.d/init.d/rc sysinit
        #l0:0:wait:/etc/rc.d/init.d/rc 0
        
        3:12345:respawn:/sbin/getty -L ttyS0 115200 vt100
//        ::respawn:/sbin/getty -L ttyS1 115200 vt100
//  ::respawn:/sbin/getty -L ttyS2 115200 vt100
//  ::respawn:/usr/sbin/telnetd
  ::respawn:/usr/sbin/inetd -f
        ::shutdown:/bin/mount / o remount,ro
        #::ctrlaltdel:/sbin/reboot
        #::shutdown:/bin/umount ar
        #ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
        在etc/fstab中添加入以下内容
        tmpfs   /tmp    tmpfs   defaults    0 0
        sysfs   /sys    sysfs   defaults    0 0
        none    /dev/pts devpts  mode=0622  0 0
        #devpts /dev/pts     devpts gid=4,mode=620  0     0
        #shm    /dev/shm     tmpfs  defaults        0     0
        在etc/profile中添加入以下内容
        #set patch
        PATH=/bin:/sbin:/usr/bin:/usr/sbin
        export PATH
        #alias command
        alias ll='ls -l'
        alias la='ls -a'
        alias du='du -h'
        alias df='df -h'
        在/etc/init.d/rcS中添加入以下内容
        /sbin/ifconfig lo 127.0.0.1
        /sbin/ifconfig eth0 192.168.1.10
        /bin/mount /dev/pts
        dmesg > /var/log/dmesg
        #hostname F /etc/hostname
        hostname 9gsam9260-Linux
        # mount fs
        /bin/mount -o remount,rw /
        # display
        echo 'rootfs version 2.6.23-9gsam9260ek (yuanxihua@y21cn.com) (gcc version 4.0.0 (DENX ELDK 4.1 4.0.0))' > /dev/ttyS0
        cat /root/build_time > /dev/ttyS0
        /app/appinit.sh
        启动/etc/init.d/rcS可执行权限
        root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs# chmod a+x /etc/init.d/rcS
        
        命令建立etc/passwd文件
        
  cat > etc/passwd << "EOF"
  root:x:0:0:root:/root:/bin/sh
  EOF
  
  复制部分配置文件
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# cd rootfs/etc/
//  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/etc# cp /etc/nsswitch.conf .
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/etc# cp /etc/group .
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/etc# cp /etc/shadow .
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/etc# cp /etc/inetd.conf .
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/etc# cp /etc/passwd .
   
  修改etc/passwd,使root登陆后执行程序为bin/sh
F,添加可加载模块
     root@yuanxh-desktop:/home/yuanxh/at91_works# cd rootfs-9g9sam9260ek
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rz
     利用SecureCRT发送modules-2.6.23-9gsam9260ek.tar.gz
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# tar xzvf modules-2.6.23-9gsam9260ek.tar.gz
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rm -rf rootfs/lib/modules/*
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# mv modules-2.6.23-9gsam9260ek/lib/modules/*  rootfs/lib/modules/
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rm -rf modules-2.6.23-9gsam9260ek
     
G,添加其它命令和应用程序
     root@yuanxh-desktop:/home/yuanxh/at91_works# cd rootfs-9g9sam9260ek
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rz
     root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# cd rootfs/bin/
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek/rootfs/bin# tar xzvf ../../rzsz-9gsam9260ek.tar.gz
  
4,打包成RAMDISK根文件系统
A,进入根文件系统目录
  root@yuanxh-desktop:/home/yuanxh/at91_works# cd rootfs-9g9sam9260ek
B,然后执行如下脚本:
  mkdir ramdisk
  dd if=/dev/zero of=ramdisk.img bs=1k count=8192
  mke2fs -F -v -m 0 -N 2000 ramdisk.img
  mount -t ext2 -o loop ramdisk.img  ramdisk
  cp -av rootfs/* ramdisk/
  umount ramdisk
  gzip -9 < ramdisk.img > initrd.bin
  #mv ramdisk.img initrd.bin
  rm -rf ramdisk-2.6.23-9gsam9260ek.bin
  mv initrd.bin  ramdisk-2.6.23-9gsam9260ek.bin
  cp ramdisk-2.6.23-9gsam9260ek.bin /tftpboot/
  rm -rf ramdisk.img
  rm -rf ramdisk
C,发送RAMDISK文件系统目标码
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# sz ramdisk-2.6.23-9gsam9260ek.bin
5,打包成JFFS2根文件系统
A,利用ELDK-4.1中的mkfs.jffs2命令打包
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# mkfs.jffs2 -d rootfs/ -o jffs2-2.6.23-9gsam9260ek.bin
B,发送目标码
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# sz jffs2-2.6.23-9gsam9260ek.bin
C,本机测试JFFS2文件系统
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# rmmod mtdram
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# modprobe mtdram total_size=29568 erase_size=128
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# modprobe mtdblock     
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# modprobe mtdchar
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# cat /proc/mtd
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# dd if=jffs2-2.6.23-9gsam9260ek.bin of=/dev/mtd0
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# mount -t jffs2 /dev/mtdblock0 /mnt
D,修改JFFS2文件系统内容
  添加内容到/mnt,然后执行如下命令:
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# umount /mnt
  root@yuanxh-desktop:/home/yuanxh/at91_works/rootfs-9g9sam9260ek# dd if=/dev/mtd0 of=jffs2-2.6.23-9gsam9260ek.new.bin

好东西

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top