summaryrefslogtreecommitdiff
path: root/target/linux/mvebu/image
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2016-09-01 15:29:48 +0200
committerFelix Fietkau <nbd@nbd.name>2016-09-02 14:43:53 +0200
commit2d7d9baf1990dca93a2b200caf84eb782f23965d (patch)
treebba51625185d745c438021ff3824064376b96971 /target/linux/mvebu/image
parent7130833a27929de8c66c4d65bc4b520ecfaf6ea8 (diff)
downloadmtk-20170518-2d7d9baf1990dca93a2b200caf84eb782f23965d.zip
mtk-20170518-2d7d9baf1990dca93a2b200caf84eb782f23965d.tar.gz
mtk-20170518-2d7d9baf1990dca93a2b200caf84eb782f23965d.tar.bz2
mvebu: use ptgen instead of fdisk to make the clearfog image script more portable
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'target/linux/mvebu/image')
-rwxr-xr-xtarget/linux/mvebu/image/gen_mvebu_sdcard_img.sh72
1 files changed, 17 insertions, 55 deletions
diff --git a/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh b/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
index 8725a37..1d874df 100755
--- a/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
+++ b/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
@@ -31,62 +31,27 @@ fi
set -e
# parameters
-IMGSIZE=$1
-OUTFILE="$2"
-BOOTLOADER="$3"
-
-# calculate number of partitions from argument list
-NUMPARTS=$#
-((NUMPARTS=(NUMPARTS-3)/3))
-
-# find required applications
-FDISK=$(env PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH" which fdisk)
+IMGSIZE=$1; shift
+OUTFILE="$1"; shift
+BOOTLOADER="$1"; shift
# generate image file
printf "Creating $OUTFILE from /dev/zero: "
dd if=/dev/zero of="$OUTFILE" bs=512 count=1 >/dev/null
printf "Done\n"
-# generate fdisk argument list
-printf "Generating fdisk argument list: "
-ARGSFILE=$(mktemp)
-
-# empty partition table
-printf "o\n" >> $ARGSFILE
-
-# actual partitions
-offset=2048
-for i in $(seq 1 1 $NUMPARTS); do
- ((n=3+3*i-2)); type=$(eval echo \${$n})
- ((n=3+3*i-1)); size=$(eval echo \${$n})
- ((end=offset+size-1))
-
- printf "n\np\n%i\n\n%i\n" $i $end >> $ARGSFILE
-
- # special case on first aprtition: fdisk wont ask which one
- if [ $i -eq 1 ]; then
- printf "t\n%s\n" $type >> $ARGSFILE
- else
- printf "t\n%i\n%s\n" $i $type >> $ARGSFILE
- fi
-
- # add this partitions size to offset for next partition
- ((offset=end+1))
+while [ "$#" -ge 3 ]; do
+ ptgen_args="$ptgen_args -p $(($2 / 2)) -S 0x$1"
+ parts="$parts$3 "
+ shift; shift; shift
done
-# write and exit
-printf "w\n" >> $ARGSFILE
-
-printf "Done\n"
+head=16
+sect=63
# create real partition table using fdisk
printf "Creating partition table: "
-cat $ARGSFILE | $FDISK "$OUTFILE" >/dev/null
-printf "Done\n"
-
-# remove temporary files
-printf "Cleaning up: "
-rm -f $ARGSFILE
+set `ptgen -o "$OUTFILE" -h $head -s $sect -l 1024 $ptgen_args`
printf "Done\n"
# install bootloader
@@ -94,18 +59,15 @@ printf "Writing bootloader: "
dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc 2>/dev/null
printf "Done\n"
-# write partition data
-
-# offset of first partition is 2048
-offset=2048
-for i in $(seq 1 1 $NUMPARTS); do
- ((n=3+3*i-1)); size=$(eval echo \${$n})
- ((n=3+3*i)); img="$(eval echo \${$n})"
+i=1
+while [ "$#" -ge 2 ]; do
+ img="${parts%% *}"
+ parts="${parts#* }"
printf "Writing %s to partition %i: " "$img" $i
- dd if="$img" of="$OUTFILE" bs=512 seek=$offset conv=notrunc 2>/dev/null
+ dd if="$img" of="$OUTFILE" bs=512 seek=$(($1 / 512)) conv=notrunc 2>/dev/null
printf "Done\n"
- # add this partitions size to offset for next partition
- ((offset=offset+size))
+ let i=i+1
+ shift; shift
done