4624l1 Listing 1. Creating a Linux RD Image #!/bin/sh #--------------------------------------------------------------------------- # Create a Linux RD image # # Based upon the Bootdisk HOW-TO. Additional support for configuration and # networking. # # M. Tim Jones (mtj@mtjones.com) # # The emphasis is size, so the minimal libraries are introduced and all # binaries and libraries are stripped. # # At the end of the build, a file 'image.map' is created which contains the # sizes of the overall ramdisk image and individual size of the subdirs in # the ramdisk (such as /bin, /lib, etc.). This is useful in understanding # the size that results from introducing new elements. # #--------------------------------------------------------------------------- # export PATH=$PATH:/opt12/hardhat/devkit/ppc/8xx/bin STRIP=ppc_8xx-strip # # Configuration parameters [may need tailoring or your environment] # LIB=/root/fwall12/target/lib BIN=/root/fwall12/target/bin ETC=../../target/etc RDSIZE=4000 # # General Cleanup... # rm -f /tmp/ramdisk.image rm -f /tmp/ramdisk.image.gz # # Create the blank ramdisk image # dd if=/dev/zero of=/tmp/ramdisk.image bs=1024 count=$RDSIZE # # Make it a mountable file system (ext2) # /sbin/mke2fs -F -m 0 -b 1024 /tmp/ramdisk.image $RDSIZE # # Mount it using the loop device (allows the file to be treated as a device) # mount /tmp/ramdisk.image /mnt -t ext2 -o loop=/dev/loop0 # # Fill in the /bin section # mkdir /mnt/bin echo Copying the bin elements # $STRIP $BIN/bash -o /mnt/bin/bash pushd /mnt/bin ln -s bash sh popd $STRIP $BIN/ls -o /mnt/bin/ls $STRIP $BIN/pwd -o /mnt/bin/pwd $STRIP $BIN/cat -o /mnt/bin/cat $STRIP $BIN/mount -o /mnt/bin/mount $STRIP $BIN/login -o /mnt/bin/login $STRIP $BIN/ps -o /mnt/bin/ps $STRIP $BIN/hostname -o /mnt/bin/hostname $STRIP $BIN/cp -o /mnt/bin/cp $STRIP $BIN/rm -o /mnt/bin/rm $STRIP $BIN/mv -o /mnt/bin/mv $STRIP $BIN/init -o /mnt/bin/init $STRIP $BIN/echo -o /mnt/bin/echo $STRIP $BIN/killall -o /mnt/bin/killall $STRIP $BIN/mkdir -o /mnt/bin/mkdir cp testapp /mnt/bin/testapp # # Add in networking stuff # $STRIP $BIN/ifconfig -o /mnt/bin/ifconfig $STRIP $BIN/inetd -o /mnt/bin/inetd $STRIP $BIN/telnet -o /mnt/bin/telnet $STRIP $BIN/ftp -o /mnt/bin/ftp $STRIP $BIN/telnetd -o /mnt/bin/telnetd $STRIP $BIN/ftpd -o /mnt/bin/ftpd $STRIP $BIN/ping -o /mnt/bin/ping $STRIP $BIN/route -o /mnt/bin/route $STRIP $BIN/netstat -o /mnt/bin/netstat # # Create the sbin soft link (to bin) # pushd /mnt ln -s bin sbin popd # # Create and fill in the required /dev sections # mkdir /mnt/dev echo Building the dev elements # mknod /mnt/dev/kmem c 1 2 chmod 640 /mnt/dev/kmem mknod /mnt/dev/mem c 1 1 chmod 640 /mnt/dev/mem mknod /mnt/dev/null c 1 3 chmod 666 /mnt/dev/null mknod /mnt/dev/tty c 5 0 chmod 666 /mnt/dev/tty mknod /mnt/dev/ttyS0 c 4 64 chmod 600 /mnt/dev/ttyS0 mknod /mnt/dev/ttyS1 c 4 65 chmod 600 /mnt/dev/ttyS1 mknod /mnt/dev/eeprom c 80 246 chmod 644 /mnt/dev/eeprom pushd /mnt/dev ln -s ttyS0 console popd cp -dpR /opt/hardhat/devkit/ppc/8xx/target/dev/initctl /mnt/dev/initctl # # Create and fill in the required etc sections # [These may be tailored in your HHL tree.] # mkdir /mnt/etc # cp $ETC/fstab /mnt/etc cp $ETC/group /mnt/etc cp $ETC/inittab /mnt/etc cp $ETC/mtab /mnt/etc cp $ETC/passwd /mnt/etc cp $ETC/hosts /mnt/etc cp $ETC/services /mnt/etc cp $ETC/resolv.conf /mnt/etc cp $ETC/inetd.conf /mnt/etc cp $ETC/protocols /mnt/etc # # Create the rc.sysinit inline # # Note, the RPX Net has two ethernet interfaces (eth0 = Hub, eth1 FEC). # cp rc.sysinit /mnt/etc/rc.sysinit # # Create and fill in the lib section # mkdir /mnt/lib echo Copying the lib elements # $STRIP $LIB/libc-2.1.3.so -o /mnt/lib/libc-2.1.3.so $STRIP $LIB/ld-2.1.3.so -o /mnt/lib/ld-2.1.3.so $STRIP $LIB/libtermcap.so.2.0.8 -o /mnt/lib/libtermcap.so.2.0.8 $STRIP $LIB/libdl-2.1.3.so -o /mnt/lib/libdl-2.1.3.so $STRIP $LIB/libproc.so.2.0.0 -o /mnt/lib/libproc.so.2.0.0 $STRIP $LIB/libcrypt.so.1 -o /mnt/lib/libcrypt.so.1 $STRIP $LIB/librt-2.1.3.so -o /mnt/lib/librt-2.1.3.so $STRIP $LIB/libutil-2.1.3.so -o /mnt/lib/libutil-2.1.3.so $STRIP $LIB/libm-2.1.3.so -o /mnt/lib/libm-2.1.3.so $STRIP $LIB/libpthread-0.8.so -o /mnt/lib/libpthread-0.8.so $STRIP $LIB/libnss_files-2.1.3.so -o /mnt/lib/libnss_files-2.1.3.so $STRIP $LIB/libresolv-2.1.3.so -o /mnt/lib/libresolv-2.1.3.so # pushd /mnt/lib ln -s libc-2.1.3.so libc.so.6 ln -s ld-2.1.3.so ld.so.1 ln -s libdl-2.1.3.so libdl.so.2 ln -s libdl.so.2 libdl.so ln -s libutil-2.1.3.so libutil.so.1 ln -s libutil.so.1 libutil.so ln -s libm-2.1.3.so libm.so.6 ln -s libm.so.6 libm.so ln -s libtermcap.so.2.0.8 libtermcap.so.2 ln -s libpthread-0.8.so libpthread.so.0 ln -s libpthread.so.0 libpthread.so ln -s libnss_files-2.1.3.so libnss_files.so.2 ln -s libnss_files.so.2 libnss_files.so ln -s libresolv-2.1.3.so libresolv.so.2 ln -s libresolv.so.2 libresolv.so popd # # Workaround for odd library problem... # pushd /mnt/lib mkdir -p /mnt/opt/hardhat/devkit/ppc/8xx/powerpc-hardhat-linux cd /mnt/opt/hardhat/devkit/ppc/8xx/powerpc-hardhat-linux ln -s /lib lib popd # # Create the /var section # echo Copying the var elements # mkdir /mnt/var mkdir /mnt/var/lock mkdir /mnt/var/lock/subsys mkdir /mnt/var/log/ mkdir /mnt/var/log/subsys # mkdir /mnt/var/run # # Create the /proc section # mkdir /mnt/proc # # Create the /tmp section # mkdir /mnt/tmp # # Summarize the size of the entire tree # echo "The Entire tree size is " echo "------------------------" du -s -b /mnt echo "------------------------" # echo "-----------------------------------------------" > image.map echo "Here are the sizes for the ramdisk image:" >> image.map du -s -h /mnt/lib >> image.map du -s -h /mnt/bin >> image.map du -s -h /mnt/etc >> image.map du -s -h /mnt/dev >> image.map du -s -h /mnt/var >> image.map echo "-----------------" >> image.map du -s -h /mnt >> image.map # # Finish up the ramdisk image # umount /mnt gzip /tmp/ramdisk.image ln -sf /tmp/ramdisk.image.gz ./arch/ppc/mbxboot/ramdisk.image.gz # # Build the kernel initrd image # make zImage.initrd # # Bind the final ramdisk image with the EP burner image to allow burning onto # the board. [Contact EP for the burner.srec and srecfix2 images.] # BURNLOC=FF840000 TARGET=./fImage.mot ./zsrec arch/ppc/mbxboot/zImage.initrd > zImage.srec IINFO=`ppc_8xx-objdump zImage.srec -h` I=0 # The objdump creates .sec1 somewhere in the image. for FI in ${IINFO} do case "$I" in 0) [ $FI = ".sec1" ] && I=1 ;; 1) LEN=$FI I=$((I+1)) ;; 2) START=$FI I=$((I+1)) ;; esac done SREC=`echo 00100090${START}${BURNLOC}${LEN}` # ./srecfix2 001000800010009000000000 ${SREC} ${TARGET} ./srecfix2 -n >${TARGET} chmod og+w ${TARGET} cp -f ${TARGET} /tftpboot