From f82d4861e68d0622fc10137daaf30d0a59ecc916 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 28 Nov 2008 10:16:40 +0000 Subject: [PATCH] qi-add-6410-bootable-sdcard-generator.patch This patch adds a small script that knows how to partition, format and prepare with a bootloader image an SD Card for usage with SD Card boot on 6410. You use it like this: ./6410-partition-sd.sh sde sdhc ./image/qi-s3c6410-andy_495294c60f2f1432 This will prepare your card with three partitions and put the bootloader images at the end as required by 6410 iROM. If you put anything on the fourth parameter, it skips the fdisk and the formatting stages and just updates the bootloader. Signed-off-by: Andy Green --- qiboot/6410-partition-sd.sh | 125 ++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 qiboot/6410-partition-sd.sh diff --git a/qiboot/6410-partition-sd.sh b/qiboot/6410-partition-sd.sh new file mode 100755 index 0000000..a3399a7 --- /dev/null +++ b/qiboot/6410-partition-sd.sh @@ -0,0 +1,125 @@ +#!/bin/sh +# 6410 SD Boot formatter +# (C) 2008 Openmoko, Inc +# Author: Andy Green + +# LAYOUT +# Partition table, then +# VFAT takes up remaining space here +# then... +# +EXT3_ROOTFS_SECTORS=$(( 64 * 1024 * 2 )) +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 " +echo + +# these are fixed in iROM +QI_INITIAL=$(( 8 * 2 )) +SIG=1 + +FDISK_SCRIPT=/tmp/_fds + +if [ -z $1 -o -z $2 -o -z $3 ] ; then + echo "This formats a SD card for usage on SD Card boot" + echo " on 6410 based systems" + echo + echo "Usage:" + echo + echo "$0 " + 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 + +SECTORS=`dmesg | grep $1 | grep "512-byte hardware" | tail -n 1 | cut -d' ' -f4` + +if [ $SECTORS -le 0 ] ; then + echo "problem finding size for /dev/$1" + exit 3 +fi + +if [ -z "$4" ] ; then + + echo "$1 is $SECTORS 512-byte blocks" + + 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 + echo "1" >>$FDISK_SCRIPT + 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"