http://www.cublog.cn/u2/86601/showart_1970963.html
#!/bin/bash
# environment variables
ARCH=powerpc
#ARCH=ppc
CROSS_COMPILE=ppc_4xx-
#The Linux kernel pointed at with the KERNEL_DIR environment variable should be
#configured for the evaluation board and have been compiled (or at least readied with
#a '# make prepare' command). If this is not the case, one or more of the packages
#will likely fail to build and scripts will abort.
KERNEL_DIR=~/405ex/linux/kernel/linux-2.6.30-rc8
FS_FILES_PATH=/opt/eldk/ppc_4xx
#The ELDK binaries should be included in the PATH environment variable
PATH=$PATH:/opt/eldk/bin:/opt/eldk/usr/bin
export ARCH CROSS_COMPILE KERNEL_DIR FS_FILES_PATH PATH
#/rebuild_static 脚本分析 主要是准备制作文件系统前应用程序的准备
#!/bin/bash
############## extract static ball #############
#删除上一次制作的目 录 解压一个压缩包,里面包涵了基本的文件系统
rm -rf static
tar jxvf static.tar.bz2
############## add your files into static #############
cp user_files/iptables static/other/
#cp user_files/RT2860STA.dat static/etc/ #ralink2860sta的配置,现在不用
#cp user_files/RT2860AP.dat static/etc/ #ralink2860AP的配置,现在不用
cp user_files/udhcpd.leases static/other/
cp -rf user_files/atheros-tools/* static/atheros-tools/
cp -rf user_files/RT2860AP.dat static/other/
cp -rf user_files/modules/* static/modules/
cp -rf user_files/hostapd static/sbin/
cp -rf user_files/hostapd_cli static/sbin/
cp -rf user_files/wpa_cli static/sbin/
cp -rf user_files/wpa_passphrase static/sbin/
cp -rf user_files/wpa_supplicant static/sbin/
#cp -rf user_files/hostapd.conf static/etc/ #xingye
#cp -rf user_files/hostapd.deny static/etc/ #xingye
#cp -rf user_files/hostapd.eap_user static/etc/ #xingye
#cp -rf user_files/hostapd.radius_clients static/etc/ #xingye
#cp -rf user_files/hostapd.sim_db static/etc/ #xingye
#cp -rf user_files/hostapd.vlan static/etc/ #xingye
#cp -rf user_files/hostapd.wpa_psk static/etc/ #xingye
#cp -rf user_files/wpa_supplicant.conf static/etc/ #xingye
#cp -rf user_files/snmp* static/sbin/ #xingye
#cp -rf user_files/snmpd.conf static/etc/ #xingye
#<<<<<<< .mine
#=======
cp user_files/rcS static/etc/rc.d/ #这个将是未来目标板的启动脚本
cp user_files/ralink_adhoc.sh static/etc/ #peter
cp user_files/setup_adhoc_ralink_405 static/etc/ #peter
#>>>>>>> .r30
############## change read/write right #############
chmod -R 775 static
chown -R nobody:developer static
#/rebuild_static 脚本分析 主要是制作文件系统
#!/bin/bash
#
# make_rootfs.sh
#
# Constructs the base root file systems for the AMCC ship image.
# Based on the busybox 1.0/examples/bootfloppy/mkrootfs.sh script.
# NOTE: Must have root privileges (or possibly utilize a fakeroot package)
#
# Constructs two file systems.
# - initrd of 64MB
# - JFFS2 of 4MB
# Configuration variables.
# - TARGET_NAME = friendly name for target platform
# - REVISION = revision of file system; used for reference
# - WORK_DIR = temporary mount point (this is added to the current path)
# - RAM_DIR = temporary ramdisk mount point
# - FLASH_DIR = temporary flash file system mount point
# - RAMSIZE = this is the ramdisk size in 1k blocks (uncompressed)
# - FLASHBLOCK = this is the flash file system block size (for padding)
# - FLASHSIZE = size of flash file system
# - RAM_MKFS = is the make filesystem command to be used for ramdisk creation
# - FLASH_MKFS = is the make fielsystem command for the flash
# - UB_DESC = U-Boot wrapper description text
# - FL_FNAME = flash file system file name
#[ ! $TARGET_NAME ] && TARGET_NAME=kilauea #tony
[ ! $TARGET_NAME ] && TARGET_NAME=makalu #判断此变量是否存在,不存在则定义并赋值
[ ! $REVISION ] && REVISION=003
[ ! $WORK_DIR ] && WORK_DIR=amcc_work
[ ! $RAM_DIR ] && RAM_DIR=amcc_ramdisk
[ ! $FLASH_DIR ] && FLASH_DIR=amcc_flash
[ ! $RAMSIZE ] && RAMSIZE=65536 #tony
#[ ! $RAMSIZE ] && RAMSIZE=20000
[ ! $FLASHBLOCK ] && FLASHBLOCK=0x20000
#[ ! $FLASHSIZE ] && FLASHSIZE=0x400000 #tony
[ ! $FLASHSIZE ] && FLASHSIZE=0x4000
[ ! $RAM_MKFS ] && RAM_MKFS="/sbin/mke2fs -F -m0"
[ ! $FLASH_MKFS ] && FLASH_MKFS="mkfs.jffs2 --big-endian"
[ ! $UB_DESC ] && UB_DESC="$TARGET_NAME Ramdisk Rev $REVISION"
[ ! $FL_FNAME ] && FL_FNAME="$TARGET_NAME".flashfs
INSTRUCT=$1
if [ ! $INSTRUCT ]; then
INSTRUCT="full"
fi
if [ $INSTRUCT = full ]; then
BUILDRD="yes"
BUILDFFS="yes"
fi
if [ $INSTRUCT = ramdisk ]; then
BUILDRD="yes"
BUILDFFS="no"
fi
if [ $INSTRUCT = jffs2 ]; then
BUILDRD="no"
BUILDFFS="yes"
fi
# The current path.
BASE_DIR=`pwd` #获取当前目录作为主目录
# splash
echo
echo You have executed the 'AMCC 4xx file system creation' script.
echo This script can create and populate the ramdisk and flash
echo file systems that are shipped on the 4xx evaluation boards.
echo This script may be useful as a model in creating a similar
echo custom implementation.
echo
echo The build ramdisk feature is set to "$BUILDRD".
if [ "$BUILDRD" = yes ]; then #判断字符串是否相等
echo The ramdisk file size is: "$RAMSIZE"k
echo The ramdisk file will be mounted at: $BASE_DIR/$RAM_DIR
echo
fi
echo The build JFFS2 file system feature is set to "$BUILDFFS".
if [ "$BUILDFFS" = yes ]; then
echo The flash file system will use a block size of: $FLASHBLOCK
echo The flash file system size is: "$FLASHSIZE"k
echo The flash file system will be created from: $BASE_DIR/$FLASH_DIR
echo
fi
echo Press [ ENTER ] to continue, or CTRL-C to abort.
read
ABORT=0
# Verify user id matches super user
if [ $UID -ne 0 ]; then #判断是不是超级用户
echo You must be root for this script to complete successfully.
echo If that is not possible, you should contact your administrator
echo and request perission to create device nodes via 'mknod' and
echo mount loop devices for RW. Then disable this ID check in the
echo script.
echo
ABORT=1
fi
# Verify the environment is as expected
if [ ! $CROSS_COMPILE ]; then #判断是否存在交叉编译环境
echo To complete this root filesystem build, the DENX
echo EDLK tools need to be properly configured.
echo The CROSS_COMPILE environment variable does not
echo appear to be set.
echo Eg. CROSS_COMPILE=ppc_xxxxxx-
echo
ABORT=1
fi
# Check for ARCH variable
if [ ! $ARCH ]; then
echo One or more of the packages built by this script
echo needs the ARCH variable defined. For an AMCC PowerPC
echo file system, this should be ARCH=ppc.
echo
ABORT=1
fi
# Check for KERNEL_DIR variable
if [ ! $KERNEL_DIR ]; then
echo One or more of the packages built by this script
echo needs the KERNEL_DIR defined. This environment
echo variable should be defined as the full path to
echo to the root of the AMCC kernel "(eg. /linux/amcc-2.6.11)."
echo It is used to build compiler include paths.
echo
ABORT=1
fi
# Check for FS_FILES_PATH variable
if [ ! $FS_FILES_PATH ]; then
echo The FS_FILES_PATH environment variable is not set.
echo This variable is needed to copy pre-built libraries
echo and binaries from the ELDK or similar source.
echo Eg. /path/to/eldk/ppc_xxxxxx
echo
ABORT=1
fi
# Test that the compiler will execute
"$CROSS_COMPILE"gcc > /dev/null 2>&1
if [ ! $? = 1 ]; then #如果返回值不为1,则没有交叉编译环境
echo The "$CROSS_COMPILE"gcc compiler is apparently not
echo in the path. The DENX EDLK toolchain needs to be
echo properly configured before this script is executed.
echo
ABORT=1
fi
if [ $ABORT -eq 1 ]; then #判断值是否等于1
echo
echo ERROR: Configuration errors were detected. Please resolve and re-execute
echo the script.
exit 1
fi
# Verify we do not already have the
# ramdisk mounted. If so, notify the user
# we are unmounting and deleting it.
#
# NOTE: efficency has been removed for
# readability.
if [ "$BUILDRD" = yes ]; then
echo Checking for mounted $RAM_DIR
mount | grep -q $RAM_DIR
if [ $? -eq 0 ]; then
echo " $RAM_DIR is currently mounted."
echo " Unmounting '$RAM_DIR'."
umount $BASE_DIR/$RAM_DIR
fi
fi
echo Checking for work directories
if [ "$BUILDFFS" = yes ]; then
if [ -d $BASE_DIR/$FLASH_DIR ]; then
echo " $FLASH_DIR is present."
echo " Removing '$FLASH_DIR'."
rm -rf $BASE_DIR/$FLASH_DIR
fi
fi
if [ -d $BASE_DIR/$WORK_DIR ]; then
echo " $WORK_DIR is present."
echo " Removing '$WORK_DIR'."
rm -rf $BASE_DIR/$WORK_DIR
fi
if [ "$BUILDRD" = yes ]; then
if [ -d $BASE_DIR/$RAM_DIR ]; then
echo " $RAM_DIR is present."
echo " Removing '$RAM_DIR'."
rm -rf $BASE_DIR/$RAM_DIR
fi
fi
echo Checking for ramdisk, ramdisk.gz and $FL_FNAME files
if [ "$BUILDRD" = yes ]; then
if [ -f ramdisk ]; then
echo " Deleting ramdisk file"
rm -f ramdisk
fi
if [ -f ramdisk.image.gz ]; then
echo " Deleting ramdisk.image.gz file"
rm -f ramdisk.image.gz
fi
if [ -f ramdisk.img ]; then
echo " Deleting U-Boot ramdisk.img file"
rm -f ramdisk.img
fi
fi
if [ "$BUILDFFS" = yes ]; then
if [ -f $FL_FNAME ]; then
echo " Deleting $FL_FNAME file"
rm -f $FL_FNAME
fi
fi
if [ $BUILDRD = yes ]; then
# Create the ramdisk file. This file is initially
# zero-filled for compression benefits.
echo Creating ramdisk file
dd if=/dev/zero of=ramdisk.image bs=1k count=$RAMSIZE > /dev/null 2>&1
$RAM_MKFS ramdisk.image > /dev/null 2>&1
# Create a temporary mount point and mount
# the ramdisk as a loop device.
echo Creating temporary mount point: $BASE_DIR/$RAM_DIR
mkdir $BASE_DIR/$RAM_DIR
echo Mounting ramdisk to $BASE_DIR/$RAM_DIR
mount -o loop,exec ramdisk.image $BASE_DIR/$RAM_DIR
fi
# Populate the work area.
echo Populating work area...
# Make the base directory structure.
mkdir $BASE_DIR/$WORK_DIR
if [ "$BUILDRD" = yes ]; then
mkdir $BASE_DIR/$WORK_DIR/bin
mkdir -p $BASE_DIR/$WORK_DIR/dev/pts
mkdir $BASE_DIR/$WORK_DIR/etc
mkdir $BASE_DIR/$WORK_DIR/proc
mkdir $BASE_DIR/$WORK_DIR/sbin
mkdir $BASE_DIR/$WORK_DIR/tmp
mkdir $BASE_DIR/$WORK_DIR/lib
mkdir $BASE_DIR/$WORK_DIR/home
mkdir $BASE_DIR/$WORK_DIR/opt
mkdir $BASE_DIR/$WORK_DIR/root
mkdir -p $BASE_DIR/$WORK_DIR/usr/share
mkdir -p $BASE_DIR/$WORK_DIR/var/ftp
mkdir -p $BASE_DIR/$WORK_DIR/usr/sbin
mkdir -p $BASE_DIR/$WORK_DIR/usr/lib
mkdir -p $BASE_DIR/$WORK_DIR/usr/bin
mkdir $BASE_DIR/$WORK_DIR/mnt
mkdir -p $BASE_DIR/$WORK_DIR/etc/Wireless/RT2860STA
mkdir -p $BASE_DIR/$WORK_DIR/etc/Wireless/RT2860AP #xingye
mkdir -p $BASE_DIR/$WORK_DIR/usr/local/share/snmp/mibs
fi
if [ "$BUILDFFS" = yes ]; then
mkdir $BASE_DIR/$FLASH_DIR
mkdir -p $BASE_DIR/$WORK_DIR/mnt/jffs2/amcc_apps
mkdir -p $BASE_DIR/$WORK_DIR/mnt/jffs2/www/cgi-bin
fi
cd $BASE_DIR/$WORK_DIR
if [ "$BUILDRD" = yes ]; then
# Add our basic dev nodes.
# If the kernel is configured to use devfs,
# these nodes will be ignored or removed.
cd $BASE_DIR
echo Calling script to make /dev nodes
./scripts/make_devs.sh $BASE_DIR/$WORK_DIR/dev
# Add libraries and pre-built binaries.
echo Calling script to copy pre-built files
./scripts/copy_files.sh $FS_FILES_PATH $BASE_DIR/$WORK_DIR
# Make certain we are in our base directory.
cd $BASE_DIR
# Copy our static files into the work area.
mkdir $BASE_DIR/$WORK_DIR/lib/modules
mkdir -p $BASE_DIR/$WORK_DIR/etc/Wireless/RT2860STA/ #peter
cp -ar ./static/etc/RT2860STA.dat $BASE_DIR/$WORK_DIR/etc/Wireless/RT2860STA/ #peter
cp -ar ./static/etc/* $BASE_DIR/$WORK_DIR/etc/.
cp -ar ./static/usr/* $BASE_DIR/$WORK_DIR/usr/.
cp -ar ./static/other/*.jpg $BASE_DIR/$WORK_DIR/var/ftp/.
cp -ar ./static/other/license.txt $BASE_DIR/$WORK_DIR/usr/.
cp -ar ./static/other/slad.ko $BASE_DIR/$WORK_DIR/lib/modules/.
# Create the links we need
# For now, some of these will point into the host file system.
# We could also build relative paths, but this is easier
# (unless the targets don't exist on the host).
cd $BASE_DIR/$WORK_DIR
ln -s ./usr/license.txt ./license.txt
cd $BASE_DIR/$WORK_DIR/var
ln -s /tmp lock
ln -s lock locks
ln -s /tmp log
ln -s /tmp run
ln -s /tmp tmp
cd $BASE_DIR/$WORK_DIR/usr/share
ln -s /tmp empty
fi
cd $BASE_DIR
# Build and install the packages.
echo Calling script to build and install packages
BUILDRD=$BUILDRD BUILDFFS=$BUILDFFS ./scripts/build_packages.sh $BASE_DIR/$WORK_DIR
if [ ! $? -eq 0 ]; then
# build_packages reported a failure, abort
exit 1;
fi
cd $BASE_DIR
# Remove a couple of install directories that just take up space
rm -r -f -d $BASE_DIR/$WORK_DIR/man
rm -r -f -d $BASE_DIR/$WORK_DIR/share
rm -r -f -d $BASE_DIR/$WORK_DIR/usr/share/xenomai
rm -r -f -d $BASE_DIR/$WORK_DIR/usr/share/doc
if [ "$BUILDFFS" = yes ]; then
# Pull items from work area for flashfs
mv $BASE_DIR/$WORK_DIR/mnt/jffs2/* $BASE_DIR/$FLASH_DIR/.
cp -r $BASE_DIR/$WORK_DIR/usr/local/www/* $BASE_DIR/$FLASH_DIR/www/.
rm -r -f $BASE_DIR/$WORK_DIR/usr/local/www/cgi-bin
fi
if [ "$BUILDRD" = yes ]; then
# Pull items from work area for initrd
cp -ar $BASE_DIR/$WORK_DIR/* $BASE_DIR/$RAM_DIR/.
fi
# Do cleanup: unmount the ramdisk; remove
# the work directory; remove the temporary
# mount point; compress the the ramdisk;
# generate the flash file system file (if appropriate).
echo "Cleaning up"
rm -rf $WORK_DIR
if [ "$BUILDRD" = yes ]; then
umount $RAM_DIR
rm -rf $RAM_DIR
gzip -9 ramdisk.image
chown $USER ramdisk.image.gz
fi
if [ "$BUILDFFS" = yes ]; then
echo "Making flash file system archive (for manual upgrade option)"
tar -czf "$TARGET_NAME"_archive.tar.gz $BASE_DIR/$FLASH_DIR
echo "Making flash file"
# try and make the flash file systme file (expecting to use mk.jffs2)
$FLASH_MKFS --eraseblock=$FLASHBLOCK --pad=$FLASHSIZE --root=$BASE_DIR/$FLASH_DIR --output=$FL_FNAME
rm -rf $FLASH_DIR
fi
if [ "$BUILDRD" = yes ]; then
echo "Making ramdisk U-Boot image"
# try and make U-Boot friendly image
mkimage -n "$UB_DESC" -A ppc -O linux -T ramdisk -C gzip -d ramdisk.image.gz ramdisk.img
fi
echo Done.
./rebuild_static
./make_rootfs.sh
sudo cp makalu.flashfs /tftpboot/lxq_makalu_flashfs_test
sudo cp ramdisk.img /tftpboot/lxq_makalu_ramdisk_test
#从webserver取出并执行相关配置脚本
adhoc_IF=`nvram_get 2860 AdhocInterface`
adhoc_SSID=`nvram_get 2860 AdhocSSID`
adhoc_IP=`nvram_get 2860 AdhocIP`
adhoc_CHANNEL=`nvram_get 2860 AdhocChannel`
adhoc_mode=`nvram_get 2860 MODE`
#控制台显示接收到的值
echo "############Adhoc Config Information#############"
echo $adhoc_IF
echo $adhoc_SSID
echo $adhoc_IP
echo $adhoc_CHANNEL
echo $adhoc_mode
if [ "$adhoc_IF" = "" ] || [ "$adhoc_SSID" = "" ] || [ "$adhoc_CHANNEL" = "" ] || [ "$adhoc_IP" = "" ] || [ "$adhoc_mode" = "" ]; then
echo "=========Interface or SSID or Channel or IP or MODE is empty!Please Set!!=================="
exit 1
else
#执行脚本,根据传入的值
/etc/setup_adhoc_ralink_405 ${adhoc_IF} ${adhoc_SSID} ${adhoc_IP} ${adhoc_CHANNEL} ${adhoc_mode}
echo "===============Adhoc Config Setting ok!!!!!================"
exit 1
fi