#! /bin/sh
myPWD=`pwd`
DRIVE=$1
umount ${DRIVE}*
dd if=/dev/zero of=$DRIVE bs=1024 count=1024

SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`

echo DISK SIZE - $SIZE bytes

CYLINDERS=`echo $SIZE/255/63/512 | bc`

echo CYLINDERS - $CYLINDERS

{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE

mkfs.vfat -F 32 -n "boot" ${DRIVE}1
mke2fs -j -L "rootfs" ${DRIVE}2
mount ${DRIVE}1 /mnt/sdcard1
mount ${DRIVE}2 /mnt/sdcard2
cp uImage /mnt/sdcard1 
cp MLO  /mnt/sdcard1 
cp u-boot.bin  /mnt/sdcard1 
cd /mnt/sdcard2
echo "dir is ${myPWD}"
tar zxvf ${myPWD}/test-rootfs.tar.gz 
cd -
umount ${DRIVE}1 ${DRIVE}2
