build_flash_cmd.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. echo
  3. echo =================================================================
  4. echo Build flash command
  5. echo =================================================================
  6. # Location of partitions.csv relative to this script
  7. partitionsCsv="../partitions.csv"
  8. # File to output readme instructions to
  9. outputReadme="./flash_cmd.txt"
  10. # File to output bash script to
  11. outputBashScript="./writeSequeezeEsp.sh"
  12. # File to output bat script to
  13. outputBatScript="./writeSequeezeEsp.bat"
  14. # The name of partitions to ignore from partitions.csv
  15. paritionsToIgnore=(
  16. "nvs"
  17. "phy_init"
  18. "storage"
  19. "coredump"
  20. "settings"
  21. )
  22. # Function that maps partition name to actual bin file
  23. # defaults to "[PARTION_NAME_FROM_CSV].bin"
  24. function partitionNameToBinFile {
  25. if [[ "$1" == "otadata" ]]; then
  26. echo "ota_data_initial.bin"
  27. elif [[ "$1" == "ota_0" || "$1" == "factory" ]]; then
  28. echo "squeezelite.bin"
  29. else
  30. echo $1.bin
  31. fi
  32. }
  33. # write parameters for esptool.py
  34. writeParameters="$writeParameters write_flash"
  35. writeParameters="$writeParameters --flash_mode dio --flash_freq 80m --flash_size detect"
  36. # bootloader.bin and partitions.bin not in partitions.csv so manually add here
  37. partitionsParameters=" 0x1000 bootloader/bootloader.bin"
  38. partitionsParameters="$partitionsParameters 0x8000 partitions.bin"
  39. # ==============================================================================
  40. # Loop over partitions.csv and add partition bins and offsets to partitionsParameters
  41. for line in $($IDF_PATH/components/partition_table/gen_esp32part.py --quiet build/partitions.bin | grep '^[^#]')
  42. do
  43. partitionName=$(echo $line | awk -F',' '{printf "%s", $1}' )
  44. partitionOffset=$(echo $line |awk -F',' '{printf "%s", $4}' )
  45. partitionFile=$(partitionNameToBinFile $partitionName)
  46. if [[ " ${paritionsToIgnore[@]} " =~ " ${partitionName} " ]]; then
  47. continue
  48. fi
  49. partitionsParameters="$partitionsParameters $partitionOffset $partitionFile"
  50. echo "$partitionsParameters"
  51. done
  52. # Write README Instructions
  53. if [ ! -f "$outputReadme" ]; then
  54. touch $outputReadme
  55. fi
  56. echo "" >> $outputReadme
  57. echo "====LINUX====" >> $outputReadme
  58. echo "To flash sequeezelite run the following script:" >> $outputReadme
  59. echo "$outputBashScript [PORT_HERE] [BAUD_RATE]" >> $outputReadme
  60. echo "e.g. $outputBashScript /dev/ttyUSB0 115200" >> $outputReadme
  61. echo "" >> $outputReadme
  62. echo "====WINDOWS====" >> $outputReadme
  63. echo "To flash sequeezelite run the following script:" >> $outputReadme
  64. echo "$outputBatScript [PORT_HERE] [BAUD_RATE]" >> $outputReadme
  65. echo "e.g. $outputBatScript COM11 115200" >> $outputReadme
  66. echo "" >> $outputReadme
  67. echo "If you don't know how to run the BAT file with arguments then you can" >> $outputReadme
  68. echo "edit the bat file in Notepad. Open the file up and edit the following:" >> $outputReadme
  69. echo "Change 'set port=%1' to 'set port=[PORT_HERE]'. E.g. 'set port=COM11'" >> $outputReadme
  70. echo "Change 'set baud=%2' to 'set baud=[BAUD_RATE]'. E.g. 'set baud=115200'" >> $outputReadme
  71. echo "" >> $outputReadme
  72. echo "====MANUAL====" >> $outputReadme
  73. echo "Python esptool.py --port [PORT_HERE] --baud [BAUD_RATE] $writeParameters $partitionsParameters" >> $outputReadme
  74. # Write Linux BASH File
  75. if [ ! -f "$outputBashScript" ]; then
  76. touch $outputBashScript
  77. fi
  78. echo "#!/bin/bash" >> $outputBashScript
  79. echo >> $outputBashScript
  80. echo "port=\$1" >> $outputBashScript
  81. echo "baud=\$2" >> $outputBashScript
  82. linuxFlashCommand="Python esptool.py --port \$port --baud \$baud"
  83. echo "$linuxFlashCommand $writeParameters $partitionsParameters" >> $outputBashScript
  84. # Write Windows BAT File
  85. if [ ! -f "$outputBatScript" ]; then
  86. touch $outputBatScript
  87. fi
  88. echo "echo off" >> $outputBatScript
  89. echo "" >> $outputBatScript
  90. echo "set port=%1" >> $outputBatScript
  91. echo "set baud=%2" >> $outputBatScript
  92. windowsFlashCommand="Python esptool.py --port %port% --baud %baud%"
  93. echo "$windowsFlashCommand $writeParameters $partitionsParameters" >> $outputBatScript