2008-11-28 12:16:40 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# 6410 SD Boot formatter
|
|
|
|
# (C) 2008 Openmoko, Inc
|
|
|
|
# Author: Andy Green <andy@openmoko.com>
|
|
|
|
|
|
|
|
# LAYOUT
|
|
|
|
# Partition table, then
|
|
|
|
# VFAT takes up remaining space here
|
|
|
|
# then...
|
|
|
|
#
|
2009-01-19 03:37:08 +02:00
|
|
|
EXT3_ROOTFS_SECTORS=$(( 256 * 1024 * 2 ))
|
2008-11-28 12:16:40 +02:00
|
|
|
EXT3_BACKUP_FS_SECTORS=$(( 8 * 1024 * 2 ))
|
|
|
|
QI_ALLOCATION=$(( 256 * 2 ))
|
|
|
|
#
|
|
|
|
# lastly fixed stuff: 8KByte initial boot, sig, padding
|
|
|
|
|
|
|
|
# ----------------------
|
|
|
|
|
|
|
|
echo "s3c6410 bootable SD partitioning utility"
|
|
|
|
echo "(C) Openmoko, Inc Andy Green <andy@openmoko.com>"
|
|
|
|
echo
|
|
|
|
|
|
|
|
# these are fixed in iROM
|
|
|
|
QI_INITIAL=$(( 8 * 2 ))
|
|
|
|
SIG=1
|
|
|
|
|
|
|
|
FDISK_SCRIPT=/tmp/_fds
|
|
|
|
|
2008-11-28 12:16:40 +02:00
|
|
|
if [ -z "$1" -o -z "$2" -o -z "$3" ] ; then
|
2008-11-28 12:16:40 +02:00
|
|
|
echo "This formats a SD card for usage on SD Card boot"
|
|
|
|
echo " on 6410 based systems"
|
|
|
|
echo
|
|
|
|
echo "Usage:"
|
|
|
|
echo
|
|
|
|
echo "$0 <device for SD, eg, sde> <sd|sdhc> <bootloader>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $2 = "sdhc" ] ; then
|
|
|
|
PADDING=1025
|
|
|
|
else
|
|
|
|
PADDING=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
EXT3_TOTAL_SECTORS=$(( $EXT3_ROOTFS_SECTORS + $EXT3_BACKUP_FS_SECTORS ))
|
|
|
|
REARSECTORS=$(( $QI_ALLOCATION + $QI_INITIAL + $SIG + $PADDING ))
|
|
|
|
|
|
|
|
if [ ! -z "`grep $1 /proc/mounts`" ] ; then
|
|
|
|
echo "ERROR $1 seems to be mounted, that ain't right"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2008-11-28 12:16:44 +02:00
|
|
|
# set CUT_COLUMN for each OS
|
2009-01-07 12:07:46 +02:00
|
|
|
# set USE_SED=some editing command
|
|
|
|
# default: use cat as a no-op
|
|
|
|
USE_SED='cat'
|
2008-11-28 12:16:44 +02:00
|
|
|
case "$(lsb_release --short --description)" in
|
2009-02-25 17:09:43 +02:00
|
|
|
Ubuntu\ 7*|Debian\ *)
|
2008-11-28 12:16:44 +02:00
|
|
|
CUT_COLUMN=5
|
|
|
|
;;
|
|
|
|
Ubuntu\ 8.04*)
|
|
|
|
CUT_COLUMN=5
|
2009-01-07 12:07:46 +02:00
|
|
|
USE_SED='sed s/^\[[[:space:]]*/[/'
|
2008-11-28 12:16:44 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CUT_COLUMN=4
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-01-07 12:07:46 +02:00
|
|
|
DMESG_LINE=$(dmesg | ${USE_SED} | grep "$1" | grep "512-byte hardware" | tail -n 1)
|
2008-11-28 12:16:44 +02:00
|
|
|
SECTORS=$(echo "${DMESG_LINE}" | cut -d' ' -f"${CUT_COLUMN}")
|
|
|
|
|
|
|
|
if ! echo "${SECTORS}" | grep '^[[:digit:]]\+$'
|
|
|
|
then
|
|
|
|
echo "problem finding size for /dev/$1 check CUT_COLUMN value for your os"
|
|
|
|
echo "CUT_COLUMN=${CUT_COLUMN} --> ${SECTORS}"
|
|
|
|
echo "dmesg line was:"
|
|
|
|
echo "${DMESG_LINE}"
|
|
|
|
exit 3
|
|
|
|
fi
|
2008-11-28 12:16:40 +02:00
|
|
|
|
|
|
|
if [ $SECTORS -le 0 ] ; then
|
|
|
|
echo "problem finding size for /dev/$1"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2008-11-28 12:16:44 +02:00
|
|
|
echo "$1 is $SECTORS 512-byte blocks"
|
|
|
|
|
2008-11-28 12:16:40 +02:00
|
|
|
if [ -z "$4" ] ; then
|
|
|
|
|
|
|
|
|
|
|
|
FATSECTORS=$(( $SECTORS - $EXT3_TOTAL_SECTORS + $REARSECTORS ))
|
|
|
|
FATMB=$(( $FATSECTORS / 2048 - 16 ))
|
|
|
|
|
|
|
|
echo "Creating VFAT section $FATMB MB"
|
|
|
|
|
|
|
|
# create the script for fdisk
|
|
|
|
# clear the existing partition table
|
|
|
|
echo "o" >$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# add main VFAT storage partition
|
|
|
|
echo "n" >>$FDISK_SCRIPT
|
|
|
|
echo "p" >>$FDISK_SCRIPT
|
|
|
|
echo "1" >>$FDISK_SCRIPT
|
|
|
|
# first partition == 1
|
2009-02-19 05:30:56 +02:00
|
|
|
echo "" >>$FDISK_SCRIPT
|
2008-11-28 12:16:40 +02:00
|
|
|
echo "+$FATMB"M >>$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# add the normal EXT3 rootfs
|
|
|
|
echo "n" >>$FDISK_SCRIPT
|
|
|
|
echo "p" >>$FDISK_SCRIPT
|
|
|
|
echo "2" >>$FDISK_SCRIPT
|
|
|
|
# continue after last
|
|
|
|
echo "" >>$FDISK_SCRIPT
|
|
|
|
echo "+$(( $EXT3_ROOTFS_SECTORS / 2048 ))"M >>$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# add the backup EXT3 rootfs
|
|
|
|
echo "n" >>$FDISK_SCRIPT
|
|
|
|
echo "p" >>$FDISK_SCRIPT
|
|
|
|
echo "3" >>$FDISK_SCRIPT
|
|
|
|
# continue after last
|
|
|
|
echo "" >>$FDISK_SCRIPT
|
|
|
|
echo "+$(( $EXT3_BACKUP_FS_SECTORS / 2048 ))"M >>$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# commit it and exit
|
|
|
|
echo "w" >>$FDISK_SCRIPT
|
|
|
|
echo "q" >>$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# do the partitioning action
|
|
|
|
fdisk /dev/$1 <$FDISK_SCRIPT
|
|
|
|
|
|
|
|
# prep the filesystems
|
|
|
|
|
|
|
|
mkfs.vfat "/dev/$1"1 -n main-vfat
|
|
|
|
mkfs.ext3 "/dev/$1"2 -L rootfs
|
|
|
|
mkfs.ext3 "/dev/$1"3 -L backupfs
|
|
|
|
|
|
|
|
fi # if -z $4
|
|
|
|
|
|
|
|
# copy the full bootloader image to the right place after the
|
|
|
|
# partitioned area
|
|
|
|
dd if=$3 of=/dev/$1 bs=512 count=512 \
|
|
|
|
seek=$(( $SECTORS - $REARSECTORS ))
|
|
|
|
dd if=$3 of=/dev/$1 bs=512 \
|
|
|
|
seek=$(( $SECTORS - $REARSECTORS + $QI_ALLOCATION )) \
|
|
|
|
count=$QI_INITIAL
|
|
|
|
dd if=/dev/zero of=/dev/$1 bs=512 \
|
|
|
|
seek=$(( $SECTORS - $REARSECTORS + $QI_ALLOCATION + $QI_INITIAL )) \
|
|
|
|
count=$(( $SIG + $PADDING ))
|
|
|
|
|
|
|
|
# done
|
|
|
|
echo
|
|
|
|
echo "**** completed"
|