dnsmasq: full: disable ipset support by default
[openwrt/staging/mkresin.git] / target / linux / mvebu / image / gen_mvebu_sdcard_img.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 #
4 # Copyright (C) 2016 Josua Mayer
5
6 usage() {
7 echo "$0 <outfile> [<bootloader> <type_partitionN> <size_partitionN> <img_partitionN>]?"
8 }
9
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
14 usage
15 exit 1
16 else
17 BOOTLOADER="$2"
18 fi
19 fi
20
21 set -e
22
23 # parameters
24 OUTFILE="$1"; shift
25 if [ -n "$BOOTLOADER" ]; then
26 shift
27 fi
28
29 # generate image file
30 printf "Creating %s from /dev/zero: " "$OUTFILE"
31 dd if=/dev/zero of="$OUTFILE" bs=512 count=1 >/dev/null
32 printf "Done\n"
33
34 while [ "$#" -ge 3 ]; do
35 ptgen_args="$ptgen_args -t $1 -p $(($2 * 1024 + 256))"
36 parts="$parts$3 "
37 shift; shift; shift
38 done
39
40 head=16
41 sect=63
42
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)
46 printf "Done\n"
47
48 # install bootloader
49 if [ -n "$BOOTLOADER" ]; then
50 printf "Writing bootloader: "
51 dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc 2>/dev/null
52 printf "Done\n"
53 fi
54
55 i=1
56 while [ "$#" -ge 2 ]; do
57 img="${parts%% *}"
58 parts="${parts#* }"
59
60 printf "Writing %s to partition %i: " "$img" $i
61 (
62 cat "$img"
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
66 printf "Done\n"
67
68 i=$((i+1))
69 shift; shift
70 done