2 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Copyright (C) 2016 Josua Mayer
7 echo "$0 <outfile> [<bootloader> <type_partitionN> <size_partitionN> <img_partitionN>]?"
10 # always require first 2 or 3 arguments
11 # then in pairs up to 8 more for a total of up to 4 partitions
12 if [ $# -lt 1 ] ||
[ $# -gt 14 ] ||
[ $
((($# - 1) % 3)) -ne 0 ]; then
13 if [ $# -lt 2 ] ||
[ $# -gt 15 ] ||
[ $
((($# - 2) % 3)) -ne 0 ]; then
25 if [ -n "$BOOTLOADER" ]; then
30 printf "Creating %s from /dev/zero: " "$OUTFILE"
31 dd if=/dev
/zero of
="$OUTFILE" bs
=512 count
=1 >/dev
/null
34 while [ "$#" -ge 3 ]; do
35 ptgen_args
="$ptgen_args -t $1 -p $(($2 * 1024 + 256))"
43 # create real partition table using fdisk
44 printf "Creating partition table: "
45 set $
(ptgen
-o "$OUTFILE" -h $head -s $sect -l 1024 -S 0x
$SIGNATURE $ptgen_args)
49 if [ -n "$BOOTLOADER" ]; then
50 printf "Writing bootloader: "
51 dd of
="$OUTFILE" if="$BOOTLOADER" bs
=512 seek
=1 conv
=notrunc
2>/dev
/null
56 while [ "$#" -ge 2 ]; do
60 printf "Writing %s to partition %i: " "$img" $i
63 # add padding to avoid leaving behind old overlay fs data
64 dd if=/dev
/zero bs
=128k count
=1 2>/dev
/null
65 ) |
dd of
="$OUTFILE" bs
=512 seek
=$
(($1 / 512)) conv
=notrunc
2>/dev
/null