PF-build.sh 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #!/bin/bash
  2. # This bash script is used to compile automatically the Prusa firmware with a dedicated build environment and settings
  3. #
  4. # Supported OS: Windows 10, Linux64 bit
  5. # Beta OS: Linux32 bit
  6. #
  7. # Linux:
  8. #
  9. # Windows:
  10. # To execute this script you gonna need few things on your Windows machine
  11. #
  12. # Linux Subsystem Ubuntu
  13. # 1. Follow these instructions
  14. # 2. Open Ubuntu bash and get latest updates with 'apt-get upgate'
  15. # 3. Install zip with 'apt-get install zip'
  16. # 4. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc'
  17. #
  18. # export OS="Linux"
  19. # export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true"
  20. # export GPG_TTY=$(tty)
  21. #
  22. # and confirm them. Restart Ubuntu bash
  23. #
  24. # Or GIT-BASH
  25. # 1. Download and install the correct (64bit or 32bit) Git version https://git-scm.com/download/win
  26. # 2. Also follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
  27. # 3. Download and install 7z-zip from its official website.
  28. # By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case.
  29. # 4. Run git Bash under Administrator privilege and navigate to the directory /c/Program Files/Git/mingw64/bin,
  30. # you can run the command ln -s /c/Program Files/7-Zip/7z.exe zip.exe
  31. #
  32. # Useful things to edit and compare your custom Firmware
  33. # 1. Download and install current and correct (64bit or 32bit) Notepad++ version https://notepad-plus-plus.org/download
  34. # 2. Another great tool to compare your custom mod and stock firmware is WinMerge http://winmerge.org/downloads/?lang=en
  35. #
  36. # Example for MK3: open git bash and change to your Firmware directory
  37. # <username>@<machinename> MINGW64 /<drive>/path
  38. # bash build.sh 1_75mm_MK3-EINSy10a-E3Dv6full
  39. #
  40. # Example for MK25: open git bash and change to your directory
  41. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware/MK3
  42. # bash build.sh 1_75mm_MK25-RAMBo13a-E3Dv6full
  43. #
  44. # The compiled hex files can be found in the folder above like from the example
  45. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware
  46. # FW351-Build1778-1_75mm_MK25-RAMBo13a-E3Dv6full.hex
  47. #
  48. # Why make Arduino IDE portable?
  49. # To have a distinguished Prusa Firmware build environment I decided to use Arduino IDE in portable mode.
  50. # - Changes made to other Arduino instances do not change anything in this build environment.
  51. # By default Arduino IDE uses "users" and shared library folders which is useful as soon you update the Software.
  52. # But in this case we need a stable and defined build environment, so keep it separated it kind of important.
  53. # Some may argue that this is only used by a script, BUT as soon someone accidentally or on purpose starts Arduino IDE
  54. # it will use the default Arduino IDE folders and so can corrupt the build environment.
  55. #
  56. # Version: 1.0.6-Build_2
  57. # Change log:
  58. # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt'
  59. # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown
  60. # 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build environment
  61. # 10 Feb 2019, ropaha, Pull Request, Select variant from list while using build.sh
  62. # 10 Feb 2019, ropaha, change FW_DEV_VERSION automatically depending on FW_VERSION RC/BETA/ALPHA
  63. # 10 Feb 2019, 3d-gussner, 1st tests with english only
  64. # 10 Feb 2019, ropaha, added compiling of all variants and english only
  65. # 10 Feb 2019, 3d-gussner, Set OUTPUT_FOLDER for hex files
  66. # 11 Feb 2019, 3d-gussner/ropaha, Minor changes and fixes
  67. # 11 Feb 2019, 3d-gussner, Ready for RC
  68. # 12 Feb 2019, 3d-gussner, Check if wget and zip are installed. Thanks to Bernd to point it out
  69. # 12 Feb 2019, 3d-gussner, Changed OS check to OSTYPE as it is not supported on Ubuntu
  70. # Also added different BUILD_ENV folders depending on OS used so Windows
  71. # Users can use git-bash AND Windows Linux Subsystems at the same time
  72. # Cleanup compiler flags is only depends on OS version.
  73. # 12 Feb 2019, 3d-gussner, Added additional OSTYPE check
  74. # 15 feb 2019, 3d-gussner, Added zip files for miniRAMbo multi language hex files
  75. # 15 Feb 2019, 3d-gussner, Added more checks if
  76. # Compiled Hex-files
  77. # Configuration_prusa.h
  78. # language build files
  79. # multi language firmware files exist and clean them up
  80. # 15 Feb 2019, 3d-gussner, Fixed selction GOLD/UNKNOWN DEV_STATUS for ALL variants builds, so you have to choose only once
  81. # 15 Feb 2019, 3d-gussner, Added some colored output
  82. # 15 Feb 2019, 3d-gussner, troubleshooting and minor fixes
  83. # 16 Feb 2019, 3d-gussner, Script can be run using arguments
  84. # $1 = variant, example "1_75mm_MK3-EINSy10a-E3Dv6full.h" at this moment it is not possible to use ALL
  85. # $2 = multi language OR english only [ALL/EN_ONLY]
  86. # $3 = development status [GOLD/RC/BETA/ALPHA/DEVEL/DEBUG]
  87. # If one argument is wrong a list of valid one will be shown
  88. # 13 Mar 2019, 3d-gussner, MKbel updated the linux build environment to version 1.0.2 with an Fix maximum firmware flash size.
  89. # So did I
  90. # 11 Jul 2019, deliopoulos,Updated to v1.0.6 as Prusa needs a new board definition for Firmware 3.8.x86_64
  91. # - Splitted the Download of Windows Arduino IDE 1.8.5 and Prusa specific part
  92. # --> less download volume needed and saves some time
  93. #
  94. # 13 Jul 2019, deliopoulos,Splitting of Ardunio IDE and Prusa parts also for Linux64
  95. # 13 Jul 2019, 3d-gussner, Added Linux 32-bit version (untested yet)
  96. # MacOS could be added in future if needs
  97. # 14 Jul 2019, 3d-gussner, Update preferences and make it really portable
  98. # 15 Jul 2019, 3d-gussner, New PF-build-env gihub branch
  99. # 16 Jul 2019, 3d-gussner, New Arduino_boards github fork
  100. # 17 Jul 2019, 3d-gussner, Final tests under Windows 10 and Linux Subsystem for Windows
  101. #### Start check if OSTYPE is supported
  102. # Windows
  103. if [ $OSTYPE == "msys" ]; then
  104. if [ $(uname -m) == "x86_64" ]; then
  105. echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
  106. Processor="64"
  107. elif [ $(uname -m) == "i386" ]; then
  108. echo "$(tput setaf 2)Windows 32-bit found$(tput sgr0)"
  109. Processor="32"
  110. fi
  111. # Linux 64-bit
  112. elif [ $OSTYPE == "linux-gnu" ]; then
  113. if [ $(uname -m) == "x86_64" ]; then
  114. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  115. Processor="64"
  116. fi
  117. # Linux 32-bit
  118. elif [ $OSTYPE == "linux-gnu" ]; then
  119. if [ $(uname -m) == "i386" ]; then
  120. echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  121. Processor="32"
  122. fi
  123. else
  124. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  125. echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
  126. echo "Read the notes of build.sh$(tput sgr0)"
  127. exit
  128. fi
  129. sleep 2
  130. #### End check if OSTYPE is supported
  131. #### Prepare bash environment and check if wget, zip and other needed things are available
  132. # Check wget
  133. if ! type wget > /dev/null; then
  134. echo "$(tput setaf 1)Missing 'wget' which is important to run this script"
  135. echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)"
  136. exit
  137. fi
  138. # Check for zip
  139. if ! type zip > /dev/null; then
  140. if [ $OSTYPE == "msys" ]; then
  141. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  142. echo "Download and install 7z-zip from its official website https://www.7-zip.org/"
  143. echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case."
  144. echo "Run git Bash under Administrator privilege and"
  145. echo "navigate to the directory /c/Program Files/Git/mingw64/bin,"
  146. echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)"
  147. exit
  148. elif [ $OSTYPE == "linux-gnu" ]; then
  149. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  150. echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)"
  151. exit
  152. fi
  153. fi
  154. # Check python ... needed during language build
  155. #if ! type python > /dev/null; then
  156. # if [ $OSTYPE == "msys" ]; then
  157. # echo "$(tput setaf 1)Missing 'python' which is important to run this script"
  158. # exit
  159. # elif [ $OSTYPE == "linux-gnu" ]; then
  160. # echo "$(tput setaf 1)Missing 'python' which is important to run this script"
  161. # echo "install it with the command $(tput setaf 2)'sudo apt-get install python3'$(tput sgr0)"
  162. # exit
  163. # fi
  164. #fi
  165. #### End prepare bash environment
  166. #### Set build environment
  167. ARDUINO_ENV="1.8.5"
  168. BUILD_ENV="1.0.6"
  169. BOARD="PrusaResearchRambo"
  170. BOARD_VERSION="1.0.1"
  171. BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Fix_maximum_firmware_flash_size/IDE_Board_Manager/package_prusa3d_index.json"
  172. BOARD_FILENAME="prusa3drambo"
  173. BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Fix_maximum_firmware_flash_size/IDE_Board_Manager/prusa3drambo-1.0.1.tar.bz2"
  174. PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env/releases/download/1.0.6/PF-build-env-1.0.6.zip"
  175. LIB="PrusaLibrary"
  176. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  177. # List few useful data
  178. echo
  179. echo "Script path :" $SCRIPT_PATH
  180. echo "OS :" $OS
  181. echo "OS type :" $OSTYPE
  182. echo ""
  183. echo "Ardunio IDE :" $ARDUINO_ENV
  184. echo "Build env :" $BUILD_ENV
  185. echo "Board :" $BOARD
  186. echo "Specific Lib:" $LIB
  187. echo ""
  188. #### Start prepare building environment
  189. #Check if build exists and creates it if not
  190. if [ ! -d "../build-env" ]; then
  191. mkdir ../build-env || exit 2
  192. fi
  193. cd ../build-env || exit 3
  194. BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  195. # Check if PF-build-env-<version> exists and downloads + creates it if not
  196. # The build environment is based on the supported Arduino IDE portable version with some changes
  197. if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then
  198. echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  199. mkdir ../PF-build-env-$BUILD_ENV
  200. sleep 5
  201. fi
  202. # Download and extract supported Arduino IDE depending on OS
  203. # Windows
  204. if [ $OSTYPE == "msys" ]; then
  205. if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then
  206. echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  207. sleep 2
  208. wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || exit 4
  209. echo "$(tput sgr 0)"
  210. echo "$(tput sgr 0)"
  211. fi
  212. if [ ! -e "../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$OSTYPE-$Processor" ]; then
  213. echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  214. sleep 2
  215. unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env-$BUILD_ENV || exit 4
  216. mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor
  217. echo "# arduino-$ARDUINO_ENV-$OSTYPE-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$OSTYPE-$Processor
  218. echo "$(tput sgr0)"
  219. fi
  220. fi
  221. # Linux
  222. if [ $OSTYPE == "linux-gnu" ]; then
  223. # 32 or 64 bit version
  224. if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then
  225. echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  226. sleep 2
  227. wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || exit 4
  228. echo "$(tput sgr 0)"
  229. echo "$(tput sgr 0)"
  230. fi
  231. if [ ! -e "../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$OSTYPE-$Processor" ]; then
  232. echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  233. sleep 2
  234. tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env-$BUILD_ENV/ || exit 4
  235. mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor
  236. echo "# arduino-$ARDUINO_ENV-$OSTYPE-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$OSTYPE-$Processor
  237. echo "$(tput sgr0)"
  238. fi
  239. fi
  240. # Make Arduino IDE portable
  241. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/ ]; then
  242. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable
  243. fi
  244. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/output/ ]; then
  245. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/output
  246. fi
  247. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/ ]; then
  248. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages
  249. fi
  250. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/sketchbook/ ]; then
  251. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/sketchbook
  252. fi
  253. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/sketchbook/libraries/ ]; then
  254. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/sketchbook/libraries
  255. fi
  256. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/staging/ ]; then
  257. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/staging
  258. fi
  259. # Change Arduino IDE preferences
  260. if [ ! -e ../PF-build-env-$BUILD_ENV/Preferences-$OSTYPE-$Processor ]; then
  261. echo "$(tput setaf 6)Setting $OSTYPE-$Processor Arduino IDE preferences for portable GUI usage...$(tput setaf 2)"
  262. sleep 2
  263. echo "update.check"
  264. sed -i 's/update.check = true/update.check = false/g' ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  265. echo "board"
  266. sed -i 's/board = uno/board = rambo/g' ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  267. echo "editor.linenumbers"
  268. sed -i 's/editor.linenumbers = false/editor.linenumbers = true/g' ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  269. echo "boardsmanager.additional.urls"
  270. echo "boardsmanager.additional.urls=$BOARD_URL" >>../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  271. echo "build.verbose=true" >>../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  272. echo "compiler.cache_core=false" >>../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  273. echo "compiler.warning_level=all" >>../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/lib/preferences.txt
  274. echo "# Preferences-$OSTYPE-$Processor" >> ../PF-build-env-$BUILD_ENV/Preferences-$OSTYPE-$Processor
  275. echo "$(tput sgr0)"
  276. fi
  277. # Download and extract Prusa Firmware related parts
  278. # Download and extract PrusaResearchRambo board
  279. if [ ! -f "$BOARD_FILENAME-$BOARD_VERSION.tar.bz2" ]; then
  280. echo "$(tput setaf 6)Downloading Prusa Research AVR MK3 RAMBo EINSy build environment...$(tput setaf 2)"
  281. sleep 2
  282. wget $BOARD_FILE_URL || exit 5
  283. fi
  284. if [ ! -e "../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION-$OSTYPE-$Processor" ]; then
  285. echo "$(tput setaf 6)Unzipping $BOARD Arduino IDE portable...$(tput setaf 2)"
  286. sleep 2
  287. tar -xvf $BOARD_FILENAME-$BOARD_VERSION.tar.bz2 -C ../PF-build-env-$BUILD_ENV/ || exit 5
  288. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/ ]; then
  289. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD
  290. fi
  291. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD ]; then
  292. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD
  293. fi
  294. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/hardware ]; then
  295. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/hardware
  296. fi
  297. if [ ! -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/hardware/avr ]; then
  298. mkdir ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/hardware/avr
  299. fi
  300. mv ../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor/portable/packages/$BOARD/hardware/avr/$BOARD_VERSION
  301. echo "# $BOARD_FILENAME-$BOARD_VERSION" >> ../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION-$OSTYPE-$Processor
  302. echo "$(tput sgr 0)"
  303. fi
  304. # Download and extract Prusa Firmware specific library files
  305. if [ ! -f "PF-build-env-$BUILD_ENV.zip" ]; then
  306. echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)"
  307. sleep 2
  308. wget $PF_BUILD_FILE_URL || exit 4
  309. echo "$(tput sgr 0)"
  310. fi
  311. if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$OSTYPE-$Processor" ]; then
  312. echo "$(tput setaf 6)Unzipping Prusa Firmware build environment...$(tput setaf 2)"
  313. sleep 2
  314. unzip -o PF-build-env-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor || exit 4
  315. echo "# PF-build-env-$OSTYPE-$Processor-$BUILD_ENV" >> ../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$OSTYPE-$Processor
  316. echo "$(tput sgr0)"
  317. fi
  318. #exit
  319. #### End prepare building
  320. #### Start
  321. cd $SCRIPT_PATH
  322. # First argument defines which variant of the Prusa Firmware will be compiled
  323. if [ -z "$1" ] ; then
  324. # Select which variant of the Prusa Firmware will be compiled, like
  325. PS3="Select a variant: "
  326. while IFS= read -r -d $'\0' f; do
  327. options[i++]="$f"
  328. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  329. select opt in "${options[@]}" "All" "Quit"; do
  330. case $opt in
  331. *.h)
  332. VARIANT=$(basename "$opt" ".h")
  333. VARIANTS[i++]="$opt"
  334. break
  335. ;;
  336. "All")
  337. VARIANT="All"
  338. VARIANTS=${options[*]}
  339. break
  340. ;;
  341. "Quit")
  342. echo "You chose to stop"
  343. exit 1
  344. ;;
  345. *)
  346. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  347. ;;
  348. esac
  349. done
  350. else
  351. if [ -f "$SCRIPT_PATH/Firmware/variants/$1" ] ; then
  352. VARIANTS=$1
  353. else
  354. echo "$(tput setaf 1)$1 could not be found in Firmware/variants please choose a valid one$(tput setaf 2)"
  355. ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename
  356. echo "$(tput sgr0)"
  357. exit
  358. fi
  359. fi
  360. #Second argument defines if it is an english only version. Known values EN_ONLY / ALL
  361. #Check default language mode
  362. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  363. if [ -z "$2" ] ; then
  364. PS3="Select a language: "
  365. echo
  366. echo "Which lang-build do you want?"
  367. select yn in "Multi languages" "English only"; do
  368. case $yn in
  369. "Multi languages")
  370. LANGUAGES="ALL"
  371. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  372. break
  373. ;;
  374. "English only")
  375. LANGUAGES="EN_ONLY"
  376. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  377. break
  378. ;;
  379. *)
  380. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  381. ;;
  382. esac
  383. done
  384. else
  385. if [[ "$2" == "ALL" || "$2" == "EN_ONLY" ]] ; then
  386. LANGUAGES=$2
  387. else
  388. echo "$(tput setaf 1)Language argument is wrong!$(tput sgr0)"
  389. echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_ONLY'$(tput sgr0) are allowed as 2nd argument!"
  390. exit
  391. fi
  392. fi
  393. #Check if DEV_STATUS is selected via argument 3
  394. if [ ! -z "$3" ] ; then
  395. if [[ "$3" == "GOLD" || "$3" == "RC" || "$3" == "BETA" || "$3" == "ALPHA" || "$3" == "DEVEL" || "$3" == "DEBUG" ]] ; then
  396. DEV_STATUS_SELECTED=$3
  397. else
  398. echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)"
  399. echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL' or 'DEBUG'$(tput sgr0) are allowed as 3rd argument!$(tput sgr0)"
  400. exit
  401. fi
  402. fi
  403. #Set BUILD_ENV_PATH
  404. cd ../PF-build-env-$BUILD_ENV/$OSTYPE-$Processor || exit 5
  405. BUILD_ENV_PATH="$( pwd -P )"
  406. cd ../..
  407. #Checkif BUILD_PATH exists and if not creates it
  408. if [ ! -d "Prusa-Firmware-build" ]; then
  409. mkdir Prusa-Firmware-build || exit 6
  410. fi
  411. #Set the BUILD_PATH for Arduino IDE
  412. cd Prusa-Firmware-build || exit 7
  413. BUILD_PATH="$( pwd -P )"
  414. for v in ${VARIANTS[*]}
  415. do
  416. VARIANT=$(basename "$v" ".h")
  417. # Find firmware version in Configuration.h file and use it to generate the hex filename
  418. FW=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g')
  419. # Find build version in Configuration.h file and use it to generate the hex filename
  420. BUILD=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  421. # Check if the motherboard is an EINSY and if so only one hex file will generated
  422. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  423. # Check development status
  424. DEV_CHECK=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g'|cut -d '-' -f2)
  425. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  426. if [[ "$DEV_CHECK" == "RC1" || "$DEV_CHECK" == "RC2" ]] ; then
  427. DEV_STATUS="RC"
  428. elif [[ "$DEV_CHECK" == "ALPHA" ]]; then
  429. DEV_STATUS="ALPHA"
  430. elif [[ "$DEV_CHECK" == "BETA" ]]; then
  431. DEV_STATUS="BETA"
  432. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  433. DEV_STATUS="DEVEL"
  434. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  435. DEV_STATUS="DEBUG"
  436. else
  437. DEV_STATUS="UNKNOWN"
  438. echo
  439. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  440. PS3="Select YES only if source code is tested and trusted: "
  441. select yn in "Yes" "No"; do
  442. case $yn in
  443. Yes)
  444. DEV_STATUS="GOLD"
  445. DEV_STATUS_SELECTED="GOLD"
  446. break
  447. ;;
  448. No)
  449. DEV_STATUS="UNKNOWN"
  450. DEV_STATUS_SELECTED="UNKNOWN"
  451. break
  452. ;;
  453. *)
  454. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  455. ;;
  456. esac
  457. done
  458. fi
  459. else
  460. DEV_STATUS=$DEV_STATUS_SELECTED
  461. fi
  462. #Prepare hex files folders
  463. if [ ! -d "$SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  464. mkdir -p $SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD || exit 10
  465. fi
  466. OUTPUT_FOLDER="Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD"
  467. #Check if exactly the same hexfile already exists
  468. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex" && "$LANGUAGES" == "ALL" ]]; then
  469. echo ""
  470. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex | xargs -n1 basename
  471. echo "$(tput setaf 6)This hex file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  472. read -t 10 -p "Press Enter to continue..."
  473. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex" && "$LANGUAGES" == "EN_ONLY" ]]; then
  474. echo ""
  475. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex | xargs -n1 basename
  476. echo "$(tput setaf 6)This hex file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  477. read -t 10 -p "Press Enter to continue..."
  478. fi
  479. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip" && "$LANGUAGES" == "ALL" ]]; then
  480. echo ""
  481. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip | xargs -n1 basename
  482. echo "$(tput setaf 6)This zip file to be compiled already exists! To cancel this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  483. read -t 10 -p "Press Enter to continue..."
  484. fi
  485. #List some useful data
  486. echo "$(tput setaf 2)$(tput setab 7) "
  487. echo "Variant :" $VARIANT
  488. echo "Firmware :" $FW
  489. echo "Build # :" $BUILD
  490. echo "Dev Check :" $DEV_CHECK
  491. echo "DEV Status :" $DEV_STATUS
  492. echo "Motherboard:" $MOTHERBOARD
  493. echo "Languages :" $LANGUAGES
  494. echo "Hex-file Folder:" $OUTPUT_FOLDER
  495. echo "$(tput sgr0)"
  496. #Prepare Firmware to be compiled by copying variant as Configuration_prusa.h
  497. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  498. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  499. else
  500. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  501. read -t 10 -p "Press Enter to continue..."
  502. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  503. fi
  504. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  505. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  506. # set FW_REPOSITORY
  507. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  508. #Prepare english only or multilanguage version to be build
  509. if [ $LANGUAGES == "ALL" ]; then
  510. echo " "
  511. echo "Multi-language firmware will be built"
  512. echo " "
  513. else
  514. echo " "
  515. echo "English only language firmware will be built"
  516. echo " "
  517. fi
  518. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  519. if [ $OSTYPE == "msys" ]; then
  520. RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
  521. fi
  522. #### End of Prepare building
  523. #### Start building
  524. export ARDUINO=$BUILD_ENV_PATH
  525. #echo $BUILD_ENV_PATH
  526. export BUILDER=$ARDUINO/arduino-builder
  527. echo
  528. #read -t 5 -p "Press Enter..."
  529. echo
  530. echo "Start to build Prusa Firmware ..."
  531. echo "Using variant $VARIANT$(tput setaf 3)"
  532. sleep 2
  533. $BUILDER -compile -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=$BOARD:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=all $SCRIPT_PATH/Firmware/Firmware.ino || exit 14
  534. echo "$(tput sgr 0)"
  535. if [ $LANGUAGES == "ALL" ]; then
  536. echo "$(tput setaf 2)"
  537. echo "Building multi language firmware" $MULTI_LANGUAGE_CHECK
  538. echo "$(tput sgr 0)"
  539. sleep 2
  540. cd $SCRIPT_PATH/lang
  541. echo "$(tput setaf 3)"
  542. ./config.sh || exit 15
  543. echo "$(tput sgr 0)"
  544. # Check if previous languages and firmware build exist and if so clean them up
  545. if [ -f "lang_en.tmp" ]; then
  546. echo ""
  547. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  548. read -t 10 -p "Press Enter to continue..."
  549. echo "$(tput setaf 3)"
  550. ./lang-clean.sh
  551. echo "$(tput sgr 0)"
  552. fi
  553. if [ -f "progmem.out" ]; then
  554. echo ""
  555. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  556. read -t 10 -p "Press Enter to continue..."
  557. echo "$(tput setaf 3)"
  558. ./fw-clean.sh
  559. echo "$(tput sgr 0)"
  560. fi
  561. # build languages
  562. echo "$(tput setaf 3)"
  563. ./lang-build.sh || exit 16
  564. # Combine compiled firmware with languages
  565. ./fw-build.sh || exit 17
  566. echo "$(tput sgr 0)"
  567. # Check if the motherboard is an EINSY and if so only one hex file will generated
  568. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  569. # If the motherboard is an EINSY just copy one hexfile
  570. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  571. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to Hex-files folder$(tput sgr 0)"
  572. cp -f firmware.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex
  573. else
  574. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to Hex-files folder$(tput sgr 0)"
  575. cp -f firmware_cz.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-cz.hex
  576. cp -f firmware_de.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-de.hex
  577. cp -f firmware_es.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-es.hex
  578. cp -f firmware_fr.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-fr.hex
  579. cp -f firmware_it.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-it.hex
  580. cp -f firmware_pl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-pl.hex
  581. if [ $OSTYPE == "msys" ]; then
  582. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  583. rm $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  584. elif [ $OSTYPE == "linux-gnu" ]; then
  585. zip -m -j ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  586. fi
  587. fi
  588. # Cleanup after build
  589. echo "$(tput setaf 3)"
  590. ./fw-clean.sh || exit 18
  591. ./lang-clean.sh || exit 19
  592. echo "$(tput sgr 0)"
  593. else
  594. echo "$(tput setaf 2)Copying English only firmware to Hex-files folder$(tput sgr 0)"
  595. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 20
  596. fi
  597. # Cleanup Firmware
  598. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 17
  599. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  600. sed -i -- 's/^#define FW_REPOSITORY "Prusa3d"/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  601. echo $MULTI_LANGUAGE_CHECK
  602. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  603. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  604. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  605. sleep 5
  606. done
  607. # Switch to hex path and list build files
  608. cd $SCRIPT_PATH
  609. cd ..
  610. echo "$(tput setaf 2) "
  611. echo " "
  612. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  613. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  614. #### End building