From 20f2340387e3f40b3b97d5403d665935144e46d7 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 28 Jan 2014 17:04:15 +0100 Subject: mkimage: guess platform automatically, add new options to set fstype and boot fssize. --- mkimage.sh.in | 58 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 24 deletions(-) (limited to 'mkimage.sh.in') diff --git a/mkimage.sh.in b/mkimage.sh.in index 246693c..493f359 100644 --- a/mkimage.sh.in +++ b/mkimage.sh.in @@ -50,30 +50,38 @@ die() { } usage() { - echo "Usage: $PROGNAME [-b fstype] [-o filename] [-r fstype] [-hV] [size]" - echo - echo " The argument expects a file generated by void-mkrootfs." - echo " The argument expects a number (GB). If is not set, defaults to 2." - echo - echo "OPTIONS" - echo " -b Set /boot (defaults to FAT, 32MB)" - echo " -o Set output ." - echo " -r Set / (defaults to ext4, 32MB - )" - echo " -p Set platform type: cubieboard2, rpi, odroid-u2" - echo - echo " Resulting image will have 2 partitions, /boot and / of total ." + cat <<_EOF +Usage: $PROGNAME [options] + +The argument expects a tarball generated by void-mkrootfs. +The platform is guessed automatically by its name. + +Accepted sizes suffixes: K, M, G, T, E. + +OPTIONS + -b Set /boot filesystem type (defaults to FAT) + -B Set /boot filesystem size (defaults to 64MB) + -r Set / filesystem type (defaults to EXT4) + -s Set total image size (defaults to 2GB) + -o Set image filename (guessed automatically) + -h Show this help + -V Show version + +Resulting image will have 2 partitions, /boot and /. +_EOF exit 0 } # # main() # -while getopts "b:o:r:p:hV" opt; do +while getopts "b:B:o:r:s:hV" opt; do case $opt in b) BOOT_FSTYPE="$OPTARG";; + B) BOOT_FSSIZE="$OPTARG";; o) FILENAME="$OPTARG";; r) ROOT_FSTYPE="$OPTARG";; - p) PLATFORM="$OPTARG";; + s) IMGSIZE="$OPTARG";; V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;; h) usage;; esac @@ -87,6 +95,9 @@ elif [ ! -r "$ROOTFS_TARBALL" ]; then die "Cannot read rootfs tarball: $ROOTFS_TARBALL" fi +PLATFORM="${ROOTFS_TARBALL#void-}" +PLATFORM="${PLATFORM%-rootfs*}" + if [ "$(id -u)" -ne 0 ]; then die "need root perms to continue, exiting." fi @@ -98,19 +109,18 @@ else IMGSIZE="${2}G" fi -if [ -z "$BOOT_FSTYPE" ]; then - BOOT_FSTYPE="vfat" -fi -if [ -z "$ROOT_FSTYPE" ]; then - ROOT_FSTYPE="ext4" -fi +: ${BOOT_FSTYPE:=vfat} +: ${BOOT_FSSIZE:=64M} +: ${ROOT_FSTYPE:=ext4} + if [ -z "$FILENAME" ]; then - FILENAME="void-image-$(date +%Y%m%d).img" + FILENAME="void-${PLATFORM}-$(date +%Y%m%d).img" fi +# double check PLATFORM is supported... case "$PLATFORM" in cubieboard2|odroid-u2|rpi);; - *) die "Unknown platform or platform unset, set it with -p!" + *) die "The $PLATFORM is not supported, exiting..." esac for f in parted partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do @@ -135,8 +145,8 @@ if [ "$BOOT_FSTYPE" = "vfat" ]; then _btype="fat32" _args="-I" fi -parted $FILENAME mkpart primary ${_btype} 4096s 64M -parted $FILENAME mkpart primary ext2 64M 100% +parted $FILENAME mkpart primary ${_btype} 4096s ${BOOT_FSSIZE} +parted $FILENAME mkpart primary ext2 ${BOOT_FSSIZE} 100% parted $FILENAME toggle 1 boot LOOPDEV=$(losetup --show --find $FILENAME) partx -a $LOOPDEV -- cgit 1.4.1