-
Notifications
You must be signed in to change notification settings - Fork 322
/
build-firmware
executable file
·114 lines (94 loc) · 3.59 KB
/
build-firmware
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
function usage() {
echo
echo "usage: $0 [-h][-c]"
echo
echo ' -h displays usage information'
echo ' -c perform a clean build'
echo
echo 'Execute from the root dir of the repo. Upon successful completion the firmware image will be build/konnected-pro-fw_*'
echo " ex: '$0'"
exit 1
}
set -e
if ! git describe --exact-match --tags &> /dev/null; then
BRANCH="$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')"
else
BRANCH="$(git describe --exact-match --tags $(git log -n1 --pretty='%h'))"
fi
FW_TAG="3.0.0-release_20211229"
FIRMWARE_OVERLAY_PATH="firmware/nodemcu-firmware-overlay"
LFS_BASE="${PWD}/src/lfs"
OUTPUT_BASE="${PWD}/build"
OUTPUT_APP="${OUTPUT_BASE}/app"
FW_BASE="${PWD}/nodemcu-firmware"
IMAGE_NAME="konnected-firmware-${BRANCH}"
# process cmd args
while getopts "ch" opt; do
case ${opt} in
h )
usage
;;
c )
cd "${FW_BASE}"
make clean
cd -
# copy in our config overlay
cp -rf "${FIRMWARE_OVERLAY_PATH}"/* "${FW_BASE}/"
rm -f "${FW_BASE}/local/fs/*"
echo "performing clean build"
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
esac
done
rm -rf "${OUTPUT_BASE}"
mkdir -p "${OUTPUT_BASE}";
chown -R $USER "${OUTPUT_BASE}"
# pull and update the FW repo if not already existing
if [ ! -d "$FW_BASE" ] ; then
echo "Checking out nodemcu-firmware:${FW_TAG}"
git clone --recurse-submodules https://github.com/nodemcu/nodemcu-firmware.git \
"${FW_BASE}"
# Copy firmware configuration from this repository to the nodemcu-firmware repo
cp -rf "${FIRMWARE_OVERLAY_PATH}"/* "${FW_BASE}/"
rm -f "${FW_BASE}/local/fs/*"
cd "${FW_BASE}"
git checkout "${FW_TAG}"
git submodule update --recursive
cd -
fi
# Build it
cd "${FW_BASE}"
make
srec_cat -output "${OUTPUT_BASE}/${IMAGE_NAME}.bin" -binary bin/0x00000.bin -binary -fill 0xff 0x00000 0x10000 bin/0x10000.bin -binary -offset 0x10000
cd -
# Build spiffsimg tool (manual for now because of https://github.com/nodemcu/nodemcu-firmware/issues/2943)
make -C "${FW_BASE}"/tools/spiffsimg
# Build LFS image with application files
mkdir -p "${OUTPUT_APP}"
LUA_FILES=$(find ${LFS_BASE} -iname "*.lua")
echo Adding files to LFS:
echo ${LUA_FILES}
echo
"${FW_BASE}/luac.cross.int" -m 0x40000 -f -o "${OUTPUT_APP}/lfs.img" ${LUA_FILES}
# transfer source files not in the lfs to the build output (ignore the status)
cp -f ${LFS_BASE}/../* "${OUTPUT_APP}" 2>/dev/null || true; echo "Building SPIFFS..."
# create the fs list from /build/app
rm -rf "${OUTPUT_BASE}/spiffs.lst"
find "${OUTPUT_APP}" -type f | sed "s|${OUTPUT_APP}/||" | awk '{printf "import build/app/%s %s\n", $1, $1}' > "${OUTPUT_BASE}/spiffs.lst"
echo Adding files to spiffs:
cat "${OUTPUT_BASE}/spiffs.lst"
echo
"${FW_BASE}/tools/spiffsimg/spiffsimg" -f "${OUTPUT_BASE}/konnected-filesystem-0x100000-${BRANCH}.img" -S 10m -U 0x100000 -r "${OUTPUT_BASE}/spiffs.lst" -d
# Transfer firmware file
#cp "${FW_BASE}/bin/nodemcu_integer_${IMAGE_NAME}.bin" "${OUTPUT_BASE}/${IMAGE_NAME}.bin"
# Build full image
srec_cat -output "${OUTPUT_BASE}/konnected-esp8266-${BRANCH}.bin" -binary "${OUTPUT_BASE}/${IMAGE_NAME}.bin" -binary -fill 0xff 0x0000 0x100000 "${OUTPUT_BASE}/konnected-filesystem-0x100000-${BRANCH}.img" -binary -offset 0x100000
echo "Wrote ${OUTPUT_BASE}/konnected-esp8266-${BRANCH}.bin"
# Copy to common name for ease of flashing
cp "${OUTPUT_BASE}/konnected-esp8266-${BRANCH}.bin" "${OUTPUT_BASE}/konnected-esp8266-latest.bin"
echo "Build Complete:Flash this build with './scripts/flash ${BRANCH} <port>'"
echo "konnected-esp8266-${BRANCH}.bin"