diff --git a/src/rootfsinstall.sh b/src/rootfsinstall.sh index a071fb2..7889112 100755 --- a/src/rootfsinstall.sh +++ b/src/rootfsinstall.sh @@ -11,13 +11,15 @@ function usage() { echo "Usage: $0 device rootfs-archive [-rpi|-cubox] [-a archive] [-c command] [-fs fstype] [-k kernel] [-p password] [-y]" echo echo "Target platform (optional):" + echo "-bpi : make a BananaPi SD with boot partition" echo "-rpi : make a RaspberryPi SD with boot partition" echo "-cubox : make a Cubox SD with boot partition" echo echo "Options:" echo "-a archive : additional archive to unpack in rootfs root" - echo "-cp command : command to run before chroot. Use @ROOT@ as reference to rootfs path" - echo "-c command : command to run through chroot in rootfs (maybe specified multiple times)" + echo "-cp command : command to run before chroot (may be specified multiple times)" + echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path" + echo "-c command : command to run through chroot in rootfs (may be specified multiple times)" echo "-fs fstype : filesystem type for system partition (default: ext4)" echo "-h hostname : set given hostname" echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot" @@ -38,6 +40,7 @@ while [ "$1" ]; do case $1 in -y) ASSUMEYES=1 ;; -cubox) TARGETDEVICE=cubox ;; + -bpi) TARGETDEVICE=bpi ;; -rpi) TARGETDEVICE=rpi ;; -fs) [ "$2" ] || { echo "Error: -fs option requires an argument; aborting." @@ -65,10 +68,10 @@ while [ "$1" ]; do shift ;; -cp) [ "$2" ] || { - echo "Error: -p option requires a command string as argument; aborting." + echo "Error: -cp option requires a command string as argument; aborting." exit 1 } - PRECHROOTCOMMAND=$2 + PRECHROOTCOMMANDS[${#PRECHROOTCOMMANDS[*]}]="$2" shift ;; -k) [ "$2" ] || { @@ -125,13 +128,21 @@ else fi case $TARGETDEVICE in - rpi) BOOTFSTYPE=fat32 + bpi) BOOTFSTYPE=fat32 BOOTFSSIZE=22M + BOOTFSSTART=1049k + [ "$USEKERNEL" ] || USEKERNEL=uImage-sunxi + KERNELDEST="@BOOT@/kernel.img" + ;; + rpi) BOOTFSTYPE=fat32 + BOOTFSSIZE=40M + BOOTFSSTART=0 [ "$USEKERNEL" ] || USEKERNEL=zImage-3.6.11-rpi KERNELDEST="@BOOT@/kernel.img" ;; cubox) BOOTFSTYPE=ext3 - BOOTFSSIZE=22M + BOOTFSSIZE=20M + BOOTFSSTART=0 [ "$USEKERNEL" ] || USEKERNEL=uImage-3.6.9-cubox KERNELDEST="@BOOT@/boot/uImage" ;; @@ -170,10 +181,14 @@ fi if [ "$BOOTFSTYPE" ]; then # FAT partition - sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE 1049k $BOOTFSSIZE + sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE if [ "$?" != "0" ]; then echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting." fi + sudo parted -s -- ${DRIVE} toggle 1 boot + if [ "$?" != "0" ]; then + echo "ERROR: parted exited with error $? while setting boot flag on ${DRIVE} boot partition; aborting." + fi # rootfs partition sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE $BOOTFSSIZE -1 if [ "$?" != "0" ]; then @@ -181,7 +196,7 @@ if [ "$BOOTFSTYPE" ]; then fi else # rootfs partition - sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 1049k -1 + sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 0 -1 if [ "$?" != "0" ]; then echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting." fi @@ -203,7 +218,7 @@ if [ "$BOOTFSTYPE" ]; then fi echo "Formatting $PARTITION2 ($SYSTEMFSTYPE)..." -mke2fs -q -t $SYSTEMFSTYPE -j -L "openmamba" $PARTITION2 || { +mke2fs -q -F -t $SYSTEMFSTYPE -j -L "openmamba" $PARTITION2 || { echo "ERROR: unable to format $PARTITION2; aborting." exit 1 } @@ -260,7 +275,10 @@ fi [ $? -eq 0 ] || exit $? -if [ "$TARGETDEVICE" = "rpi" ]; then +if [ "$TARGETDEVICE" = "bpi" ]; then + # TODO + : +elif [ "$TARGETDEVICE" = "rpi" ]; then # fetch and install firmware files if missing if [ -e $ROOTMP/boot/bootcode.bin -a -e $ROOTMP/boot/fixup_x.dat -a -e $ROOTMP/boot/start_x.elf ]; then for f in bootcode.bin fixup_x.dat start_x.elf; do @@ -377,13 +395,13 @@ if [ "$ROOTPASSWORD" ]; then } fi -if [ "$PRECHROOTCOMMAND" ]; then - PRECHROOTCOMMAND=`echo $PRECHROOTCOMMAND | sed "s|@ROOT@|$ROOTMP|g"` +for c in `seq 1 ${#PRECHROOTCOMMANDS[*]}`; do + PRECHROOTCOMMAND=`echo ${PRECHROOTCOMMANDS[c-1]} | sed "s|@ROOT@|$ROOTMP|g;s|@BOOT@|$BOOTMP|g"` $PRECHROOTCOMMAND || { - echo "ERROR: error running pre-chroot command; aborting." + echo "ERROR: error running pre-chroot command '${PRECHROOTCOMMANDS[c-1]}'; aborting." exit 1 } -fi +done for c in `seq 1 ${#CHROOTCOMMANDS[*]}`; do chroot $ROOTMP ${CHROOTCOMMANDS[c-1]} || {