blob: d84b98ccf2f65cb9e8e327f8edf373c2a2c365a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/bin/sh
set -e
usage() {
cat <<EOF
Usage: `basename $0` [OPTIONS]
Create partition file to be used to flash GPT on DragonBoard
-d enable debug traces
-o <file> output file (will be destroyed if exists)
-i <file> GPT backup file
-x enable shell debug mode
-h display help
EOF
exit 1;
}
DEBUG=0
while getopts "o:i:s:dx" o; do
case "${o}" in
x|d)
set -x
DEBUG=1
;;
o)
OUT=${OPTARG}
;;
i)
IN=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "$OUT" ] || [ -z "$IN" ] ; then
echo "Please specify an output and input file"
echo ""
usage
exit 1
fi
# The GPT backup is a binary file consisting of the protective MBR,
# the main GPT header, the backup GPT header, and one copy of the
# partition table, in that order.
MBR=`mktemp`
PRIMARY=`mktemp`
SECONDARY=`mktemp`
DATA=`mktemp`
echo "=== Extract MBR, Primary and Secondary headers, and partition table"
dd if=$IN of=$MBR bs=512 count=1 &> /dev/null
dd if=$IN of=$PRIMARY bs=512 count=1 skip=1 &> /dev/null
dd if=$IN of=$SECONDARY bs=512 count=1 skip=2 &> /dev/null
dd if=$IN of=$DATA bs=512 count=32 skip=3 &> /dev/null
echo "=== Create $OUT file"
cat $MBR $PRIMARY $DATA $DATA $SECONDARY > $OUT
if [ "$DEBUG" = "1" ] ;then
ls -l $MBR $PRIMARY $DATA $DATA $SECONDARY $OUT
fi
rm -f $MBR $PRIMARY $DATA $SECONDARY
echo "=== Done"
|