SDWriter

#!/bin/bash
# created by jhk,
SDCARD=/dev/$1

MMC=mmc.bin
UBOOT=u-boot.bin
KERNEL_210=zImage
ROOTFS=rootfs.yaffs2


echo "SD Card Writer program V1.0"
echo "Create by jhk"


if [ -b "$SDCARD" ]; then


# Check SDCARD Sectors
SDCARD_SECTORS=`fdisk -l -u $SDCARD | grep sectors | head -n 1 \
| cut -d',' -f4 | cut -d' ' -f3`

OFFSET_BL1_210=1


FL210_FREE=20480
FL6410_FREE=20480
SIZE_FAT=$(($SDCARD_SECTORS-$FL210_FREE-$FL210_FREE-2))

OFFSET_FAT=$(($SIZE_FAT-1))
#end reserved block 1 (512byte)

# Ask for correct calculation
echo "SDCARD-device:$SDCARD"
echo "NSectors:$SDCARD_SECTORS, Do you want to continue(yes/no): "
read ANS
if [ "$ANS" != "yes" ]; then
    exit -1
fi

print_success()
{
    if [ "$1" == 0 ]; then
echo "success"
    else
echo "failed"
exit -1
    fi
}

partition_add()
{
    echo n
    echo p
    echo $1
    echo $2
    echo +$3
}


sdcard_format()
{
    START_FAT=20480

# Pre Umount 
    umount /media/*


    (

# Pre Partition Delete
echo d
echo 6
echo d
echo 5
echo d
echo 4
echo d
echo 3
echo d
echo 2
echo d

# Partition Create
partition_add 1 $START_FAT $OFFSET_FAT

echo w
echo q
    ) | fdisk -u $SDCARD > /dev/null 2>&1

# Partition Format
    mkfs.vfat -n "FL-disk" "$SDCARD"1 > /dev/null 2>&1
  
}

echo
echo -n "Partition Create : "
sdcard_format
print_success "$?"
#size 1M
dd bs=512 seek=$OFFSET_BL1_210 if=/dev/zero of=$SDCARD count=2048 > /dev/null 2>&1
echo
echo -n "mmc.bin : "
dd bs=512 seek=$OFFSET_BL1_210 if=$MMC of=$SDCARD > /dev/null 2>&1
print_success "$?"
echo "copy Filesystem"
mkdir temp
mount "$SDCARD"1 temp
cd temp
mkdir sd_fusing
cp ../$UBOOT sd_fusing > /dev/null 2>&1
print_success "$?"
cp ../$KERNEL_210 sd_fusing > /dev/null 2>&1
print_success "$?"
cp ../$ROOTFS sd_fusing > /dev/null 2>&1
print_success "$?"
cd ..
umount temp
rm -rf  temp

else
    echo "Usage: $0 device"
    echo "ex) $0 sdb"
    exit 1
fi

你可能感兴趣的:(byte)