-
Notifications
You must be signed in to change notification settings - Fork 184
/
build-multisquashfs-firmware.sh
executable file
·74 lines (57 loc) · 1.32 KB
/
build-multisquashfs-firmware.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
#!/bin/bash
DIR="$1"
if [ "$1" == "-h" ]; then
echo "Usage: $0 [FMK directory] [-nopad | -min]"
exit 1
fi
if [ "$DIR" == "" ] || [ "$DIR" == "-nopad" ] || [ "$DIR" == "-min" ]; then
DIR="fmk"
fi
DIR=$(readlink -f $DIR)
# Order matters here!
source shared-ng.inc
BINWALK=$(readlink -f $BINWALK)
if [ ! -d "$DIR" ]; then
echo -e "Usage: $0 [build directory] [-nopad]\n"
exit 1
fi
# Set Internal Field Separator (IFS) via two lines to newline only (bashism would be $'\n')
IFS='
'
FILES=""
FS_NAME=$(basename "${FWOUT}")
if [[ -f "${FWOUT}" ]]; then
if [[ "${FWOUT}" != "" ]] && [[ "${FWOUT}" != "/" ]]; then
rm ${FWOUT}
fi
fi
# Loop through log file,and build file
for LINE in $(cat ${CONFLOG})
do
./build-firmware.sh "${LINE}"
# remove append data on the tail
BIN_FS="${LINE}/${FS_NAME}"
FS=$(${BINWALK} "${BIN_FS}" | grep -i squashfs)
FS_SIZE=0
OFFSET=$(echo ${FS} | awk '{print $1}')
IFS=,
for fsparam in ${FS}
do
if [[ ${fsparam} = *size* ]] && [[ ${fsparam} != *blocksize* ]]; then
fsparam="${fsparam##*size: }"
FS_SIZE="${fsparam%* bytes}"
break
fi
done
if [[ ${FS_SIZE} != 0 ]]; then
COUNT=$((${FS_SIZE}+${OFFSET}))
truncate -s ${COUNT} ${BIN_FS}
fi
# link file together
if [[ -f "${FWOUT}" ]]; then
dd if=${BIN_FS} >> "${FWOUT}"
else
dd if=${BIN_FS} > "${FWOUT}"
fi
done
exit 0