rootfsinstall: added option for -bpi (partitioning only) and for multiple -cp options with @BOOT@ support

Restoring old partitioning for rpi because leaving space before first partition does not work
Also set boot flag to first partition
This commit is contained in:
Silvan Calarco 2014-10-17 12:12:35 +02:00
parent 7b55fdddd5
commit fb24bac0a1

View File

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