-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack.sh
executable file
·85 lines (66 loc) · 1.59 KB
/
unpack.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
XIMAGE_FILE="xImage"
UBI_FILE="system.ubi"
quit() {
echo "Cleaning up ${workdir}..."
rm -rf "$workdir"
echo "Done."
exit 1
}
if [ "$#" -ne 1 ]; then
echo "Usage: $0 [file.bin]"
exit 1
fi
origdir="$(pwd)"
fwfile="${origdir}/$1"
if [ ! -f "$fwfile" ]; then
echo "Error: file not found: $1"
exit 1
fi
workdir="$(mktemp -d)"
cd "$workdir"
echo "Started working on ${workdir}"
trap quit EXIT
echo "Extracting $(basename -- "$fwfile") to $(pwd)..."
tar xf "$fwfile"
echo "Done."
fwfile_gz="$(find . -name "firmware_v[0-1].tar.gz" | head -n 1)"
if [ -z "$fwfile_gz" ]; then
echo "Error: cannot find firmware_v0|v1.tar.gz in archive"
quit
fi
echo "Extracting $(basename -- "$fwfile_gz") from $fwfile to $(pwd)..."
tar xf "$fwfile_gz"
echo "Done."
nand_dir="$(pwd)/recovery-update/nand"
if [ ! -d "$nand_dir" ]; then
echo "Error: cannot find recovery-update/nand directory in $fwfile_gz"
quit
fi
cd "$nand_dir"
echo "Extracting firmware chunks..."
for file in update0[0-9][0-9].zip; do
unzip -n "$file" >/dev/null
done
echo "Done."
echo "Generating xImage file..."
cat update0[0-9][0-9]/"$XIMAGE_FILE"_0[0-9][0-9] > "$XIMAGE_FILE"
echo "Done."
echo "Generating UBI image..."
cat update0[0-9][0-9]/"$UBI_FILE"_0[0-9][0-9] > "$UBI_FILE"
echo "Done."
outdirbase="${fwfile}-unpack"
outdir="$outdirbase"
cnt=1
while [ -d "$outdir" ]; do
outdir="${outdirbase}.${cnt}"
cnt=$(($cnt+1))
done
echo "Copying extracted files to $outdir..."
mkdir "$outdir"
mv -- */*.xml "$outdir"/
mv "$XIMAGE_FILE" "${outdir}/${XIMAGE_FILE}"
mv "$UBI_FILE" "${outdir}/${UBI_FILE}"
echo "Done."
echo "Bye."