Skip to content

Commit 5372c6c

Browse files
committed
Add chirpotle.sh flash command
1 parent 42d037e commit 5372c6c

File tree

2 files changed

+146
-38
lines changed

2 files changed

+146
-38
lines changed

chirpotle.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,97 @@ function chirpotle_deploy {
406406
echo "Nodes have been stopped during deployment. Remember calling \"chirpotle.sh restartnodes\" before using the framework."
407407
} # end of chirpotle_deploy
408408

409+
410+
function chirpotle_flash {
411+
# Default parameters
412+
FIRMWARE=""
413+
PORT="/dev/ttyUSB0"
414+
415+
# Parameter parsing
416+
while [[ $# -gt 0 ]]
417+
do
418+
KEY="$1"
419+
case "$KEY" in
420+
-p|--port)
421+
PORT="$2"
422+
shift
423+
shift
424+
;;
425+
-h|--help)
426+
echo " Usage: chirpotle.sh flash [--port <serial port>] <firmware>"
427+
echo ""
428+
echo " Build the firmware and flash it to a locally connected board."
429+
echo ""
430+
echo " firmware"
431+
echo " The name of the firmware variant."
432+
echo " Currently, the available options are:"
433+
grep -E '^ifeq \(\$\(PRECONF\),([^\)]+)\)' "$REPODIR/node/companion-app/riot-apps/chirpotle-companion/Makefile.preconf" \
434+
| sed -E 's/^ifeq \(\$\(PRECONF\),([^\)]+)\)$/ - \1/'
435+
echo ""
436+
echo " -p, --port"
437+
echo " The port the board is connected to"
438+
echo " Default: /dev/ttyUSB0"
439+
exit 0
440+
;;
441+
*)
442+
if [[ "$FIRMWARE" == "" ]]; then
443+
FIRMWARE="$1"
444+
shift
445+
else
446+
echo "Unexpected argument: $KEY" >&2
447+
echo "Call chirpotle.sh flash --help for usage information." >&2
448+
exit 1
449+
fi
450+
;;
451+
esac
452+
done
453+
454+
# Enter virtual environment
455+
source "$ENVDIR/bin/activate"
456+
457+
# Process localhost configuration
458+
export CONFDIR="$CONFDIR"
459+
export CONFFILE="$CONFFILE" # require original file for the lookup of node configuration files during deployment
460+
TMPCONFFILE="$CONFFILE"
461+
if [[ "$INCLUDE_LOCALHOST" == "0" ]]; then
462+
TMPCONFFILE="/tmp/$CONFIGNAME-$$.tmp"
463+
"$REPODIR/scripts/exclude-localhost.py" "$CONFFILE" > "$TMPCONFFILE"
464+
fi
465+
466+
# Check dependencies for firmware build
467+
# -------------------------------------
468+
# Find used platform
469+
PLATFORM=" $($REPODIR/scripts/list-used-firmwares.py platform-for "$FIRMWARE") "
470+
471+
# Toolchain for ESP32
472+
if [[ "$PLATFORM" == " esp32 " ]]; then
473+
export ESP32_SDK_DIR="$REPODIR/submodules/esp-idf"
474+
export PATH="$REPODIR/submodules/xtensa-esp32-elf/bin:$PATH"
475+
fi
476+
477+
# Toolchain for bare-metal ARM
478+
if [[ "$USED_PLATFORMS" == " arm_none " ]]; then
479+
chirpotle_check_req_gcc_arm_none
480+
fi
481+
482+
# Toolchain for Linux ARM
483+
if [[ "$USED_PLATFORMS" =~ " arm_linux " ]]; then
484+
chirpotle_check_req_gcc_arm_linux
485+
fi
486+
487+
# Build the companion application for various toolchains
488+
# ------------------------------------------------------
489+
APPDIR="$REPODIR/node/companion-app/riot-apps/chirpotle-companion"
490+
491+
# Build LoPy4 (UART mode)
492+
PRECONF="$FIRMWARE" PORT="$PORT" make -C "$APPDIR" clean all flash
493+
if [[ "$?" != "0" ]]; then
494+
echo "Building the companion application failed for $FIRMWARE" >&2
495+
exit 1
496+
fi
497+
498+
} # end of chirpotle_flash
499+
409500
function chirpotle_deploycheck {
410501
# Default parameters
411502
CONFIGNAME="default"
@@ -911,6 +1002,7 @@ function chirpotle_usage {
9111002
echo " confeditor - Launch interactive configration editor"
9121003
echo " deploy - Deploy ChirpOTLE to nodes"
9131004
echo " deploycheck - Check requirements on ChirpOTLE nodes"
1005+
echo " flash - Flash a preconfigured firmware to a locally connected board"
9141006
echo " help - Show this information"
9151007
echo " install - Install controller on this host in a virtual environment"
9161008
echo " interactive - Run an interactive evaluation session"
@@ -959,6 +1051,10 @@ do
9591051
shift
9601052
ACTION=chirpotle_deploycheck
9611053
;;
1054+
flash)
1055+
shift
1056+
ACTION=chirpotle_flash
1057+
;;
9621058
install)
9631059
shift
9641060
ACTION=chirpotle_install

scripts/list-used-firmwares.py

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
# Returns a list of unique firmware configurations for a given confname
77
# Call: list-used-firmwares.py <firmwares|platforms> confdir confname
88

9+
# Returns the platform for a specific firmware:
10+
# Call: list-used-firmwares.py platform-for <firmware>
11+
12+
# Map firmwares to platforms
13+
pmap = {
14+
"esp32-generic": "esp32",
15+
"lora-feather-m0": "arm_none",
16+
"lopy4-uart": "esp32",
17+
"lopy4": "esp32",
18+
"t-beam-uart": "esp32",
19+
"native-raspi": "arm_linux",
20+
}
21+
922
def conf_path_to_obj(d):
1023
"""
1124
Read configuration files from an input directory d into an object
@@ -18,43 +31,42 @@ def conf_path_to_obj(d):
1831
configs[cfgname] = c
1932
return configs
2033

21-
if sys.argv[1] not in ["firmwares", "platforms"]:
22-
print("First parameter must be \"firmwares\" or \"platforms\"")
23-
exit(1)
34+
if sys.argv[1] in ["firmwares", "platforms"]:
35+
36+
confdir = pathlib.Path(sys.argv[2])
37+
hostconf = conf_path_to_obj(confdir / "hostconf")[pathlib.Path(sys.argv[3]).stem]
38+
nodeconfs = conf_path_to_obj(confdir / "nodeconf")
2439

25-
confdir = pathlib.Path(sys.argv[2])
26-
hostconf = conf_path_to_obj(confdir / "hostconf")[pathlib.Path(sys.argv[3]).stem]
27-
nodeconfs = conf_path_to_obj(confdir / "nodeconf")
28-
29-
# Find all configs that are used
30-
used_nodeconfs = set()
31-
for sec in hostconf.sections():
32-
if "conf" in hostconf[sec]:
33-
used_nodeconfs.add(hostconf[sec]["conf"])
34-
used_confs = map(lambda confname: nodeconfs[confname],
35-
[pathlib.Path(c).stem for c in used_nodeconfs])
36-
37-
# Find all firmwares
38-
used_firmwares = set()
39-
for conf in used_confs:
40-
for sec in conf.sections():
41-
if "firmware" in conf[sec]:
42-
used_firmwares.add(conf[sec]["firmware"])
43-
44-
if sys.argv[1] == "firmwares":
45-
print(" ".join(used_firmwares))
40+
# Find all configs that are used
41+
used_nodeconfs = set()
42+
for sec in hostconf.sections():
43+
if "conf" in hostconf[sec]:
44+
used_nodeconfs.add(hostconf[sec]["conf"])
45+
used_confs = map(lambda confname: nodeconfs[confname],
46+
[pathlib.Path(c).stem for c in used_nodeconfs])
47+
48+
# Find all firmwares
49+
used_firmwares = set()
50+
for conf in used_confs:
51+
for sec in conf.sections():
52+
if "firmware" in conf[sec]:
53+
used_firmwares.add(conf[sec]["firmware"])
54+
55+
if sys.argv[1] == "firmwares":
56+
print(" ".join(used_firmwares))
57+
else:
58+
used_platforms = set()
59+
for fw in used_firmwares:
60+
if fw in pmap:
61+
used_platforms.add(pmap[fw])
62+
print(" ".join(used_platforms))
63+
elif sys.argv[1] == "platform-for":
64+
if sys.argv[2] in pmap:
65+
print(pmap[sys.argv[2]])
66+
exit(0)
67+
else:
68+
print("unknown firmware:", sys.argv[2], file=sys.stderr)
69+
exit(1)
4670
else:
47-
# Map firmwares to platforms
48-
pmap = {
49-
"esp32-generic": "esp32",
50-
"lora-feather-m0": "arm_none",
51-
"lopy4-uart": "esp32",
52-
"lopy4": "esp32",
53-
"t-beam-uart": "esp32",
54-
"native-raspi": "arm_linux",
55-
}
56-
used_platforms = set()
57-
for fw in used_firmwares:
58-
if fw in pmap:
59-
used_platforms.add(pmap[fw])
60-
print(" ".join(used_platforms))
71+
print("First parameter must be \"firmwares\", \"platforms\" or \"platform-for\".")
72+
exit(1)

0 commit comments

Comments
 (0)