Advertisement
Guest User

Alternate Meshtastic flash script

a guest
Dec 24th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. PYTHON=${PYTHON:-$(which python3 python|head -n 1)}
  4.  
  5. set -e
  6.  
  7. # Usage info
  8. show_help() {
  9. cat << EOF
  10. Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME|FILENAME]
  11. Flash image file to device, but first erasing and writing system information"
  12.  
  13. -h Display this help and exit
  14. -p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerrous).
  15. -P PYTHON Specify alternate python interpreter to use to invoke esptool. (Default: "$PYTHON")
  16. -f FILENAME The .bin file to flash. Custom to your device type and region.
  17. EOF
  18. }
  19.  
  20.  
  21. while getopts ":hp:P:f:" opt; do
  22. case "${opt}" in
  23. h)
  24. show_help
  25. exit 0
  26. ;;
  27. p) export ESPTOOL_PORT=${OPTARG}
  28. ;;
  29. P) PYTHON=${OPTARG}
  30. ;;
  31. f) FILENAME=${OPTARG}
  32. ;;
  33. *)
  34. echo "Invalid flag."
  35. show_help >&2
  36. exit 1
  37. ;;
  38. esac
  39. done
  40. shift "$((OPTIND-1))"
  41.  
  42. [ -z "$FILENAME" -a -n "$1" ] && {
  43. FILENAME=$1
  44. shift
  45. }
  46.  
  47. if [ -f "${FILENAME}" ]; then
  48. echo "Trying to flash ${FILENAME}, but first erasing and writing system information"
  49. # edited to remove "--baud 921600" from each line below, after esptool to fix erase failed and other errors
  50. $PYTHON -m esptool erase_flash
  51. $PYTHON -m esptool write_flash 0x1000 system-info.bin
  52. $PYTHON -m esptool write_flash 0x00390000 spiffs-*.bin
  53. $PYTHON -m esptool write_flash 0x10000 ${FILENAME}
  54. else
  55. echo "Invalid file: ${FILENAME}"
  56. show_help
  57. fi
  58.  
  59. exit 0
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement