-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flash script for NiceNano with DFU
This is an alternative flashing method for the Nice Nano V2's. It will work with other nrf52 devices with some extending. The user only needs to put the n!n into bootloader mode and they will able to be flashed without requiring additional steps. As well, because the system no-longer has a mounted filesystem just up and disappearing there wont be left behind dead device references and the user doesn't have to worry about umount getting locked up into uninterruptible sleep, which means the user needs to reboot with a system that cannot cleanly unmount the root filesystem anymore.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ lib | ||
, writeShellApplication | ||
, systemd | ||
, adafruit-nrfutil | ||
, firmware | ||
}: | ||
|
||
writeShellApplication { | ||
name = "zmk-nicenano-dfu-flash"; | ||
|
||
runtimeInputs = [ | ||
adafruit-nrfutil | ||
# udevadm is from systemd | ||
systemd | ||
]; | ||
|
||
text = '' | ||
TTY_PREFIXES=(ttyUSB ttyACM) | ||
available() { | ||
shopt -s nullglob | ||
for prefix in "''${TTY_PREFIXES[@]}"; do | ||
for tty in /dev/"''${prefix}"*; do | ||
if [ "$(udevadm info --query=property --property=ID_MODEL --value "$tty")" == "nice_nano_v2" ]; then | ||
echo "$tty" | ||
shopt -u nullglob | ||
return | ||
fi | ||
done | ||
done | ||
shopt -u nullglob | ||
return 1 | ||
} | ||
flash=("$@") | ||
parts=(${toString firmware.parts or ""}) | ||
if [ "''${#flash[@]}" -eq 0 ]; then | ||
if [ "''${#parts[@]}" -eq 0 ]; then | ||
flash=("") | ||
else | ||
flash=("''${parts[@]}") | ||
fi | ||
else | ||
for part in "''${flash[@]}"; do | ||
if ! printf '%s\0' "''${parts[@]}" | grep -Fxqz -- "$part"; then | ||
echo "The '$part' part does not exist in the firmware '"'${firmware.name}'"'" | ||
exit 1 | ||
fi | ||
done | ||
fi | ||
cleanup() { | ||
for p in "''${flash[@]}"; do | ||
rm -f "''${upgradedir}/''${p}.zip" | ||
done | ||
rmdir "''${upgradedir}" | ||
} | ||
upgradedir="$(mktemp -d)" | ||
trap cleanup EXIT | ||
for part in "''${flash[@]}"; do | ||
echo -n "Double tap reset and plug in$([ -n "$part" ] && echo " the '$part' part of") the keyboard via USB" | ||
while ! device="$(available)"; do | ||
echo -n . | ||
sleep 3 | ||
done | ||
echo | ||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application ${firmware}/*"$([ -n "$part" ] && echo "_$part")".hex "''${upgradedir}/''${part}.zip" | ||
adafruit-nrfutil dfu serial --package "''${upgradedir}/''${part}.zip" --port "$device" -b 115200 | ||
echo "Firmware copy complete." | ||
sleep 1 | ||
echo | ||
done | ||
''; | ||
|
||
meta = with lib; { | ||
description = "ZMK nicenano DFU firmware flasher"; | ||
license = licenses.mit; | ||
platforms = platforms.linux; | ||
maintainers = with maintainers; [ ]; | ||
}; | ||
} |