PF-build.sh 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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 update'
  15. # 3. Install zip with 'apt-get install zip'
  16. # 4. Install python3 with 'apt-get install python3'
  17. # 5. Add command 'ln -sf /usr/bin/python3.5 /usr/bin/python' to link python3 to python.
  18. # Do not install 'python' as python 2.x has end of life see https://pythonclock.org/
  19. # 6. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc'
  20. #
  21. # export OS="Linux"
  22. # export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true"
  23. # export GPG_TTY=$(tty)
  24. #
  25. # and confirm them. Restart Ubuntu bash
  26. #
  27. # Or GIT-BASH
  28. # 1. Download and install the correct (64bit or 32bit) Git version https://git-scm.com/download/win
  29. # 2. Also follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
  30. # 3. Download and install 7z-zip from its official website.
  31. # By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case.
  32. # 4. Run git Bash under Administrator privilege and navigate to the directory /c/Program Files/Git/mingw64/bin,
  33. # you can run the command ln -s /c/Program Files/7-Zip/7z.exe zip.exe
  34. #
  35. # Useful things to edit and compare your custom Firmware
  36. # 1. Download and install current and correct (64bit or 32bit) Notepad++ version https://notepad-plus-plus.org/download
  37. # 2. Another great tool to compare your custom mod and stock firmware is WinMerge http://winmerge.org/downloads/?lang=en
  38. #
  39. # Example for MK3: open git bash and change to your Firmware directory
  40. # <username>@<machine name> MINGW64 /<drive>/path
  41. # bash build.sh 1_75mm_MK3-EINSy10a-E3Dv6full
  42. #
  43. # Example for MK25: open git bash and change to your directory
  44. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware/MK3
  45. # bash build.sh 1_75mm_MK25-RAMBo13a-E3Dv6full
  46. #
  47. # The compiled hex files can be found in the folder above like from the example
  48. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware
  49. # FW351-Build1778-1_75mm_MK25-RAMBo13a-E3Dv6full.hex
  50. #
  51. # Why make Arduino IDE portable?
  52. # To have a distinguished Prusa Firmware build environment I decided to use Arduino IDE in portable mode.
  53. # - Changes made to other Arduino instances do not change anything in this build environment.
  54. # By default Arduino IDE uses "users" and shared library folders which is useful as soon you update the Software.
  55. # But in this case we need a stable and defined build environment, so keep it separated it kind of important.
  56. # Some may argue that this is only used by a script, BUT as soon someone accidentally or on purpose starts Arduino IDE
  57. # it will use the default Arduino IDE folders and so can corrupt the build environment.
  58. #
  59. # Version: 2.0.2-Build_80
  60. # Change log:
  61. # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt'
  62. # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown
  63. # 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build environment
  64. # 10 Feb 2019, ropaha, Pull Request, Select variant from list while using build.sh
  65. # 10 Feb 2019, ropaha, change FW_DEV_VERSION automatically depending on FW_VERSION RC/BETA/ALPHA
  66. # 10 Feb 2019, 3d-gussner, 1st tests with English only
  67. # 10 Feb 2019, ropaha, added compiling of all variants and English only
  68. # 10 Feb 2019, 3d-gussner, Set OUTPUT_FOLDER for hex files
  69. # 11 Feb 2019, 3d-gussner/ropaha, Minor changes and fixes
  70. # 11 Feb 2019, 3d-gussner, Ready for RC
  71. # 12 Feb 2019, 3d-gussner, Check if wget and zip are installed. Thanks to Bernd to point it out
  72. # 12 Feb 2019, 3d-gussner, Changed OS check to OSTYPE as it is not supported on Ubuntu
  73. # Also added different BUILD_ENV folders depending on OS used so Windows
  74. # Users can use git-bash AND Windows Linux Subsystems at the same time
  75. # Cleanup compiler flags is only depends on OS version.
  76. # 12 Feb 2019, 3d-gussner, Added additional OSTYPE check
  77. # 15 feb 2019, 3d-gussner, Added zip files for miniRAMbo multi language hex files
  78. # 15 Feb 2019, 3d-gussner, Added more checks if
  79. # Compiled Hex-files
  80. # Configuration_prusa.h
  81. # language build files
  82. # multi language firmware files exist and clean them up
  83. # 15 Feb 2019, 3d-gussner, Fixed selection GOLD/UNKNOWN DEV_STATUS for ALL variants builds, so you have to choose only once
  84. # 15 Feb 2019, 3d-gussner, Added some colored output
  85. # 15 Feb 2019, 3d-gussner, troubleshooting and minor fixes
  86. # 16 Feb 2019, 3d-gussner, Script can be run using arguments
  87. # $1 = variant, example "1_75mm_MK3-EINSy10a-E3Dv6full.h" at this moment it is not possible to use ALL
  88. # $2 = multi language OR English only [ALL/EN_FARM]
  89. # $3 = development status [GOLD/RC/BETA/ALPHA/DEVEL/DEBUG]
  90. # If one argument is wrong a list of valid one will be shown
  91. # 13 Mar 2019, 3d-gussner, MKbel updated the Linux build environment to version 1.0.2 with an Fix maximum firmware flash size.
  92. # So did I
  93. # 11 Jul 2019, deliopoulos,Updated to v1.0.6 as Prusa needs a new board definition for Firmware 3.8.x86_64
  94. # - Split the Download of Windows Arduino IDE 1.8.5 and Prusa specific part
  95. # --> less download volume needed and saves some time
  96. #
  97. # 13 Jul 2019, deliopoulos,Splitting of Arduino IDE and Prusa parts also for Linux64
  98. # 13 Jul 2019, 3d-gussner, Added Linux 32-bit version (untested yet)
  99. # MacOS could be added in future if needs
  100. # 14 Jul 2019, 3d-gussner, Update preferences and make it really portable
  101. # 15 Jul 2019, 3d-gussner, New PF-build-env GitHub branch
  102. # 16 Jul 2019, 3d-gussner, New Arduino_boards GitHub fork
  103. # 17 Jul 2019, 3d-gussner, Final tests under Windows 10 and Linux Subsystem for Windows
  104. # 18 Jul 2019, 3d-gussner, Added python check
  105. # 18 Jul 2019, deliopoulos, No need more for changing 'platform.txt' file as it comes with the Arduino Boards.
  106. # 18 Jul 2019, deliopoulos, Modified 'PF_BUILD_FILE_URL' to use 'BUILD_ENV' variable
  107. # 22 Jul 2019, 3d-gussner, Modified checks to check folder and/or installation output exists.
  108. # 22 Jul 2019, 3d-gussner, Added check if Arduino IDE 1.8.5 boards have been updated
  109. # 22 Jul 2019, 3d-gussner, Changed exit numbers 1-13 for prepare build env 21-28 for prepare compiling 31-36 compiling
  110. # 22 Jul 2019, 3d-gussner, Changed BOARD_URL to DRracers repository after he pulled my PR https://github.com/DRracer/Arduino_Boards/pull/1
  111. # 23 Jul 2019, 3d-gussner, Changed Build-env path to "PF-build-dl" as requested in PR https://github.com/prusa3d/Prusa-Firmware/pull/2028
  112. # Changed Hex-files folder to PF-build-hex as requested in PR
  113. # 23 Jul 2019, 3d-gussner, Added Finding OS version routine so supporting new OS should get easier
  114. # 26 Jul 2019, 3d-gussner, Change JSON repository to prusa3d after PR https://github.com/prusa3d/Arduino_Boards/pull/1 was merged
  115. # 23 Sep 2019, 3d-gussner, Prepare PF-build.sh for coming Prusa3d/Arduino_Boards version 1.0.2 Pull Request
  116. # 17 Oct 2019, 3d-gussner, Changed folder and check file names to have separated build environments depending on Arduino IDE version and
  117. # board-versions.
  118. # 15 Dec 2019, 3d-gussner, Prepare for switch to Prusa3d/PF-build-env repository
  119. # 15 Dec 2019, 3d-gussner, Fix Arduino user preferences for the chosen board.
  120. # 17 Dec 2019, 3d-gussner, Fix "timer0_fract = 0" warning by using Arduino_boards v1.0.3
  121. # 28 Apr 2020, 3d-gussner, Added RC3 detection
  122. # 03 May 2020, deliopoulos, Accept all RCx as RC versions
  123. # 05 May 2020, 3d-gussner, Make a copy of `not_tran.txt`and `not_used.txt` as `not_tran_$VARIANT.txt`and `not_used_$VARIANT.txt`
  124. # After compiling All multi-language variants it makes it easier to find missing or unused translations.
  125. # 12 May 2020, DRracer , Cleanup double MK2/s MK25/s `not_tran` and `not_used` files
  126. # 13 May 2020, leptun , If cleanup files do not exist don't try to.
  127. # 01 Oct 2020, 3d-gussner, Bug fix if using argument EN_FARM. Thank to @leptun for pointing out.
  128. # Change Build number to script commits 'git rev-list --count HEAD PF-build.sh'
  129. # 02 Oct 2020, 3d-gussner, Add UNKNOWN as argument option
  130. # 05 Oct 2020, 3d-gussner, Disable pause and warnings using command line with all needed arguments
  131. # Install needed apps under linux if needed.
  132. # Clean PF-Firmware build when changing git branch
  133. # 02 Nov 2020, 3d-gussner, Check for "gawk" on Linux
  134. # Add argument to change build number automatically to current commit or define own number
  135. # Update exit numbers 1-13 for prepare build env 21-29 for prepare compiling 30-36 compiling
  136. # 08 Jan 2021, 3d-gussner, Comment out 'sudo' auto installation
  137. # Add '-?' '-h' help option
  138. # 27 Jan 2021, 3d-gussner, Add `-c`, `-p` and `-n` options
  139. # 12 Feb 2021, 3d-gussner, Add MK404-build.sh
  140. # 13 Feb 2021, 3d-gussner, Indentations
  141. # 13 Feb 2021, 3d-gussner, MK404 improvements like "flash" MK3, MK3S languages files to MK404 xflash.
  142. # 27 Feb 2021, 3d-gussner, Add './lang-community.sh' and update exits
  143. # 03 May 2021, 3d-gussner, Update exit numbers
  144. # 01-14 prepare build env
  145. # 21-32 prepare compiling
  146. # 41-47 compiling
  147. # 51-54 cleanup
  148. # 61-62 MK404
  149. # 03 May 2021, 3d-gussner, Update documentation and change version to v1.2.0
  150. # 03 May 2021, 3d-gussner, Add SIM atmega404
  151. # 17 Jun 2021, 3d-gussner, Update PF-build.sh to work after DRracer Remove FW version parsing PR
  152. # 17 Jun 2021, 3d-gussner, Save ELF files for FW3.10.1 debugging PRs
  153. # 17 Jun 2021, 3d-gussner, Add verbose_IDE to output more information during build
  154. # 17 Jun 2021, 3d-gussner, Change version to v2.0.0
  155. # 18 Jun 2021, 3d-gussner, Use atmega404 if extanded RAM or FLASH size are chosen
  156. # 18 Jun 2021, 3d-gussner, Remove MK404 copy of lang file as it has been fixed in MK404
  157. # 21 Jun 2021, 3d-gussner, Change atmega404 board flash argument to y
  158. # Use newer version of MK404-build.sh instead start the program
  159. # 22 Jun 2021, 3d-gussner, Added _RAM-<value> and _FLASH-<value> as OUTPUT_FILE_SUFFIX if someone builds an atmega404 firmware
  160. # Added some logic if IDE 1.8.13 is used
  161. # Added some logic if Arduino_boards 1.0.4 is used
  162. # Fixed typo
  163. # Restore original `Configuration.h` and `config.h` in case of cannceled script or failed compiling during next start of this script.
  164. # use function
  165. # 23 Jun 2021, 3d-gussner, Improve MK404 usage
  166. # 24 Jun 2021, 3d-gussner, Fix MK404 user interaction not to show if compiling 'All' variants
  167. # 24 Jun 2021, 3d-gussner, MK404 is only supported on Linux at this moment.
  168. # 03 Jan 2022, 3d-gussner, Remove calling lang-community.sh as not needed anymore
  169. # 21 Jan 2022, 3d-gussner, Sort variants
  170. # Add Arduino 1.8.19 as an option
  171. # 25 Jan 2022, 3d-gussner, Allow upper and lower case for MK404
  172. # 09 Feb 2022, 3d-gussner, Add community language firmware files for MK2.5/S
  173. # Add selection of language in MK404 for MK2.5/S
  174. # 10 Feb 2022, 3d-gussner, Add SRCDIR for compatibility with build server
  175. # 13 Feb 2022, leptun , Fix -o for "Restoring" messages after failure
  176. # 24 Feb 2022, 3d-gussner, Change to Arduino IDE 1.8.19 and Arduino boards 1.0.5
  177. # Fix DEV_STATUS to set correctly on RC/BETA/ALPHA/DEVEL
  178. # Fix atmegaMK404 Board mem and flash modifications
  179. # Limit atmegaMK404 boards mem to 8,16,32
  180. # 20 Jun 2022, 3d-gussner, Change to Ardunio_boards v1.0.5-1
  181. # 20 Jun 2022, wavexx , New PO-based language translation support
  182. # 20 Jun 2022, 3d-gussner, fix Mk2.5/S zip after change PO-based language translation support
  183. # 06 Jul 2022, 3d-gussner, Change to v1.0.8 and Ardunio_boards v1.0.5-2
  184. # 06 Jul 2022, 3d-gussner, Fix branch check
  185. # 12 Jul 2022, 3d-gussner, Check if FW_FLAVAVOR and FW_FLAVERSION are correct
  186. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  187. export SRCDIR=$SCRIPT_PATH
  188. #### Start: Failures
  189. failures()
  190. {
  191. case "$1" in
  192. 0) echo "$(tput setaf 2)PF-build.sh finished with success$(tput sgr0)" ;;
  193. 1) echo "$(tput setaf 1)This script doesn't support your Operating system!$(tput sgr0)" ; exit 1 ;;
  194. 4) echo "$(tput setaf 5)Follow the instructions above $(tput sgr0)" ; exit 4 ;;
  195. 5) echo "$(tput setaf 5)Invalid argument $(tput sgr0)" ; exit 5 ;;
  196. 8) echo "$(tput setaf 5)Failed to download $(tput sgr0)" ; exit 8 ;;
  197. 9) echo "$(tput setaf 5)Failed to create folder $(tput sgr0)" ; exit 9 ;;
  198. 10) echo "$(tput setaf 5)Failed to change folder $(tput sgr0)"; exit 10 ;;
  199. 11) echo "$(tput setaf 5)Failed to unzip $(tput sgr0)" ; exit 11 ;;
  200. 12) echo "$(tput setaf 5)Failed to copy file $(tput sgr0)" ; exit 12 ;;
  201. 13) echo "$(tput setaf 5)Failed to delete $(tput sgr0)" ; exit 13 ;;
  202. 20) echo "$(tput setaf 2)Conditional stop initiated by user $(tput sgr0)" ; exit 20 ;;
  203. 21) echo "$(tput setaf 1)PF-build.sh has been interrupted/failed. $(tput setaf 6)Restoring 'Configuration.h'$(tput sgr0)" ; if [ $OUTPUT == "1" ] ; then sleep 5 ; fi ;;
  204. 22) echo "$(tput setaf 1)PF-build.sh has been interrupted/failed. $(tput setaf 6)Restoring 'config.h'$(tput sgr0)" ; if [ $OUTPUT == "1" ] ; then sleep 5 ; fi ;;
  205. 24) echo "$(tput setaf 1)PF-build.sh stopped due to compiling errors! Try to restore modified files.$(tput sgr0)"; check_script_failed_nr1 ; check_script_failed_nr2 ; cleanup_firmware ; exit 24 ;;
  206. 25) echo "$(tput setaf 1)Failed to execute $(tput sgr0)" ; exit 25 ;;
  207. 26) echo "$(tput setaf 1)FW_FLAVAVOR or FW_FLAVERSION commented out in 'Firmware/Configuration.h'$(tput sgr0)"; check_script_failed_nr1 ; check_script_failed_nr2 ; cleanup_firmware ; exit 26 ;;
  208. esac
  209. }
  210. #### End: Failures
  211. #### Start: Check for options/flags
  212. ##check_options()
  213. ##{
  214. while getopts b:c:d:g:h:i:j:l:m:n:o:p:v:x:y:?h flag
  215. do
  216. case "${flag}" in
  217. b) build_flag=${OPTARG};;
  218. c) clean_flag=${OPTARG};;
  219. d) devel_flag=${OPTARG};;
  220. g) mk404_graphics_flag=${OPTARG};;
  221. h) help_flag=1;;
  222. i) IDE_flag=${OPTARG};;
  223. j) verbose_IDE_flag=${OPTARG};;
  224. l) language_flag=${OPTARG};;
  225. m) mk404_flag=${OPTARG};;
  226. n) new_build_flag=${OPTARG};;
  227. o) output_flag=${OPTARG};;
  228. p) prusa_flag=${OPTARG};;
  229. v) variant_flag=${OPTARG};;
  230. x) board_mem_flag=${OPTARG};;
  231. y) board_flash_flag=${OPTARG};;
  232. ?) help_flag=1;;
  233. esac
  234. done
  235. #
  236. # '?' 'h' argument usage and help
  237. if [ "$help_flag" == "1" ] ; then
  238. echo "***************************************"
  239. echo "* PF-build.sh Version: 2.0.2-Build_80 *"
  240. echo "***************************************"
  241. echo "Arguments:"
  242. echo "$(tput setaf 2)-b$(tput sgr0) Build/commit number"
  243. echo "$(tput setaf 2)-c$(tput sgr0) Do not clean up lang build"
  244. echo "$(tput setaf 2)-d$(tput sgr0) Devel build"
  245. echo "$(tput setaf 2)-g$(tput sgr0) Start MK404 graphics"
  246. echo "$(tput setaf 2)-i$(tput sgr0) Arduino IDE version"
  247. echo "$(tput setaf 2)-j$(tput sgr0) Arduino IDE verbose output"
  248. echo "$(tput setaf 2)-l$(tput sgr0) Languages"
  249. echo "$(tput setaf 2)-m$(tput sgr0) Start MK404 sim"
  250. echo "$(tput setaf 2)-n$(tput sgr0) New fresh build"
  251. echo "$(tput setaf 2)-o$(tput sgr0) Output"
  252. echo "$(tput setaf 2)-p$(tput sgr0) Keep Configuration_prusa.h"
  253. echo "$(tput setaf 2)-v$(tput sgr0) Variant"
  254. echo "$(tput setaf 2)-x$(tput sgr0) Board memory size"
  255. echo "$(tput setaf 2)-y$(tput sgr0) Board flash size"
  256. echo "$(tput setaf 2)-?$(tput sgr0) Help"
  257. echo
  258. echo "Brief USAGE:"
  259. echo " $(tput setaf 2)./PF-build.sh$(tput sgr0) [-b] [-c] [-d] [-g] [-i] [-j] [-l] [-m] [-n] [-o] [-p ] -[v] [-x] [-y] [-h] [-?]"
  260. echo
  261. echo " -b : '$(tput setaf 2)Auto$(tput sgr0)' needs git or a number"
  262. echo " -c : '$(tput setaf 2)0$(tput sgr0)' clean up, '$(tput setaf 2)1$(tput sgr0)' keep"
  263. echo " -d : '$(tput setaf 2)GOLD$(tput sgr0)', '$(tput setaf 2)RC$(tput sgr0)', '$(tput setaf 2)BETA$(tput sgr0)', '$(tput setaf 2)ALPHA$(tput sgr0)', '$(tput setaf 2)DEBUG$(tput sgr0)', '$(tput setaf 2)DEVEL$(tput sgr0)' and '$(tput setaf 2)UNKNOWN$(tput sgr0)'"
  264. echo " -g : '$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' lite '$(tput setaf 2)2$(tput sgr0)' fancy '$(tput setaf 2)3$(tput sgr0)' lite with Quad_HR '$(tput setaf 2)4$(tput sgr0)' fancy with Quad_HR"
  265. echo " -i : '$(tput setaf 2)1.8.5$(tput sgr0)', '$(tput setaf 2)1.8.19$(tput sgr0)'"
  266. echo " -j : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  267. echo " -l : '$(tput setaf 2)ALL$(tput sgr0)' for multi language or '$(tput setaf 2)EN_FARM$(tput sgr0)' for English only"
  268. echo " -m : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes '$(tput setaf 2)2$(tput sgr0)' with MMU2"
  269. echo " -n : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  270. echo " -o : '$(tput setaf 2)1$(tput sgr0)' force or '$(tput setaf 2)0$(tput sgr0)' block output and delays"
  271. echo " -p : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  272. echo " -v : '$(tput setaf 2)All$(tput sgr0)' or variant file name"
  273. echo " -x : '$(tput setaf 2)8$(tput sgr0)','$(tput setaf 2)16$(tput sgr0)'or'$(tput setaf 2)32$(tput sgr0)' Kb."
  274. echo " -y : '$(tput setaf 2)256$(tput sgr0)','$(tput setaf 2)384$(tput sgr0)','$(tput setaf 2)512$(tput sgr0)','$(tput setaf 2)1024$(tput sgr0)''$(tput setaf 2)32M$(tput sgr0)'"
  275. echo
  276. echo "Example:"
  277. echo " $(tput setaf 2)./PF-build.sh -v All -l ALL -d GOLD$(tput sgr0)"
  278. echo " Will build all variants as multi language and final GOLD version"
  279. echo
  280. echo " $(tput setaf 2) ./PF-build.sh -v 1_75mm_MK3S-EINSy10a-E3Dv6full.h -b Auto -l ALL -d GOLD -o 1 -c 1 -p 1 -n 1$(tput sgr0)"
  281. echo " Will build MK3S multi language final GOLD firmware "
  282. echo " with current commit count number and output extra information,"
  283. echo " not delete lang build temporary files, keep Configuration_prusa.h and build with new fresh build folder."
  284. echo
  285. exit 6
  286. fi
  287. #Check if verbose_IDE is selected with argument '-j'
  288. if [ ! -z "$verbose_IDE_flag" ]; then
  289. if [ $verbose_IDE_flag == "1" ]; then
  290. verbose_IDE="1"
  291. elif [ $verbose_IDE_flag == "0" ]; then
  292. verbose_IDE="0"
  293. else
  294. echo "Only '0' and '1' are valid verbose_IDE values."
  295. failures 5
  296. fi
  297. else
  298. verbose_IDE="0"
  299. fi
  300. #Check if Build is selected with argument '-f'
  301. if [ ! -z "$board_flash_flag" ] ; then
  302. if [ "$board_flash_flag" == "256" ] ; then
  303. BOARD_FLASH="0x3FFFF"
  304. BOARD_maximum_size="253952"
  305. echo "Board flash size : $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
  306. elif [ "$board_flash_flag" == "384" ] ; then
  307. BOARD_FLASH="0x5FFFF"
  308. BOARD_maximum_size="385024"
  309. echo "Board flash size : $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
  310. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_FLASH-$board_flash_flag"
  311. elif [ "$board_flash_flag" == "512" ] ; then
  312. BOARD_FLASH="0x7FFFF"
  313. BOARD_maximum_size="516096"
  314. echo "Board flash size : $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
  315. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_FLASH-$board_flash_flag"
  316. elif [ "$board_flash_flag" == "1024" ] ; then
  317. BOARD_FLASH="0xFFFFF"
  318. BOARD_maximum_size="1040384"
  319. echo "Board flash size : $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
  320. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_FLASH-$board_flash_flag"
  321. elif [[ "$board_flash_flag" == "32M" || "$board_flash_flag" == "32768" ]] ; then
  322. BOARD_FLASH="0x1FFFFFF"
  323. BOARD_maximum_size="33546240"
  324. echo "Board flash size : 32 Mb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
  325. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_FLASH-$board_flash_flag"
  326. else
  327. echo "Unsupported board flash size chosen. Only '256', '384', '512', '1024' and '32M' are allowed."
  328. failures 5
  329. fi
  330. fi
  331. #Check if Build is selected with argument '-x'
  332. if [ ! -z "$board_mem_flag" ] ; then
  333. if [ "$board_mem_flag" == "8" ] ; then
  334. BOARD_MEM="0x21FF"
  335. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  336. elif [ "$board_mem_flag" == "16" ] ; then
  337. BOARD_MEM="0x3DFF"
  338. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  339. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_RAM-$board_mem_flag"
  340. elif [ "$board_mem_flag" == "32" ] ; then
  341. BOARD_MEM="0x7DFF"
  342. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  343. OUTPUT_FILENAME_SUFFIX="${OUTPUT_FILENAME_SUFFIX}_RAM-$board_mem_flag"
  344. else
  345. echo "Unsupported board mem size chosen. Only '8', '16' and '32' are allowed."
  346. failures 5
  347. fi
  348. fi
  349. #Start: Check if Arduino IDE version is correct
  350. if [ ! -z "$IDE_flag" ]; then
  351. if [[ "$IDE_flag" == "1.8.5" || "$IDE_flag" == "1.8.19" ]]; then
  352. ARDUINO_ENV="${IDE_flag}"
  353. else
  354. ARDUINO_ENV="1.8.19"
  355. fi
  356. else
  357. ARDUINO_ENV="1.8.19"
  358. fi
  359. #End: Check if Arduino IDE version is correct
  360. #Start: Check if Output is selecetd via argument '-o'
  361. if [[ -z "$output_flag" || "$output_flag" == 1 ]] ; then
  362. OUTPUT=1
  363. else
  364. OUTPUT=0
  365. fi
  366. #End: Check if Output is selecetd via argument '-o'
  367. ##}
  368. #### End: Check for options/flags
  369. #### Start: Make backup of Configuration.h
  370. make_backup1()
  371. {
  372. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration.tmp" ]; then
  373. cp -f $SCRIPT_PATH/Firmware/Configuration.h $SCRIPT_PATH/Firmware/Configuration.tmp
  374. fi
  375. }
  376. #### End: Make backup of Configuration.h
  377. #### Start: Make backup of config.h
  378. make_backup2()
  379. {
  380. if [ ! -f "$SCRIPT_PATH/Firmware/config.tmp" ]; then
  381. cp -f $SCRIPT_PATH/Firmware/config.h $SCRIPT_PATH/Firmware/config.tmp
  382. fi
  383. }
  384. #### End: Make backup of config.h
  385. #### Start: Check Check if script has been canceled or failed nr1.
  386. check_script_failed_nr1()
  387. {
  388. #Check for "Configuration.tmp"
  389. if [ -f "$SCRIPT_PATH/Firmware/Configuration.tmp" ]; then
  390. cp -f $SCRIPT_PATH/Firmware/Configuration.tmp $SCRIPT_PATH/Firmware/Configuration.h
  391. #echo "Found Configuration.tmp restore Configuration.h"
  392. failures 21
  393. fi
  394. }
  395. #### End: Check Check if script has been canceled or failed nr1.
  396. #### Start: Check if script has been canceled or failed nr2.
  397. check_script_failed_nr2()
  398. {
  399. #Check for "config.tmp"
  400. #echo "No config.tmp"
  401. if [ -f "$SCRIPT_PATH/Firmware/config.tmp" ]; then
  402. cp -f $SCRIPT_PATH/Firmware/config.tmp $SCRIPT_PATH/Firmware/config.h
  403. #echo "Found config.tmp restore config.h"
  404. failures 22
  405. fi
  406. }
  407. #### End: Check if script has been canceled or failed nr2.
  408. #### Start: Check if OSTYPE is supported
  409. check_OS()
  410. {
  411. OS_FOUND=$( command -v uname)
  412. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  413. linux*)
  414. TARGET_OS="linux"
  415. ;;
  416. msys*|cygwin*|mingw*)
  417. # or possible 'bash on windows'
  418. TARGET_OS='windows'
  419. ;;
  420. nt|win*)
  421. TARGET_OS='windows'
  422. ;;
  423. *)
  424. TARGET_OS='unknown'
  425. ;;
  426. esac
  427. # Windows
  428. if [ $TARGET_OS == "windows" ]; then
  429. if [ $(uname -m) == "x86_64" ]; then
  430. echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
  431. Processor="64"
  432. elif [ $(uname -m) == "i386" ]; then
  433. echo "$(tput setaf 2)Windows 32-bit found$(tput sgr0)"
  434. Processor="32"
  435. else
  436. echo "$(tput setaf 1)Unsupported OS: Windows $(uname -m)"
  437. failures 1
  438. fi
  439. # Linux
  440. elif [ $TARGET_OS == "linux" ]; then
  441. if [ $(uname -m) == "x86_64" ]; then
  442. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  443. Processor="64"
  444. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  445. echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  446. Processor="32"
  447. else
  448. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  449. failures 1
  450. fi
  451. else
  452. #echo "$(tput setaf 1)This script doesn't support your Operating system!"
  453. #echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
  454. #echo "Read the notes of build.sh$(tput sgr0)"
  455. failures 1
  456. fi
  457. if [ $OUTPUT == "1" ] ; then
  458. sleep 2
  459. fi
  460. }
  461. #### End: Check if OSTYPE is supported
  462. #### Start: Prepare bash environment and check if wget, zip and other needed things are available
  463. # Start: Check wget
  464. check_wget()
  465. {
  466. if ! type wget > /dev/null; then
  467. echo "$(tput setaf 1)Missing 'wget' which is important to run this script"
  468. echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)"
  469. failures 4
  470. fi
  471. }
  472. # End: Check wget
  473. # Start: Check for zip
  474. check_zip()
  475. {
  476. if ! type zip > /dev/null; then
  477. if [ $TARGET_OS == "windows" ]; then
  478. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  479. echo "Download and install 7z-zip from its official website https://www.7-zip.org/"
  480. echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case."
  481. echo "Run git Bash under Administrator privilege and"
  482. echo "navigate to the directory /c/Program Files/Git/mingw64/bin,"
  483. echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)"
  484. failures 4
  485. elif [ $TARGET_OS == "linux" ]; then
  486. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  487. echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)"
  488. failures 4
  489. fi
  490. fi
  491. }
  492. # End: Check for zip
  493. # Start: Check python ... needed during language build
  494. check_python()
  495. {
  496. if ! type python3 > /dev/null; then
  497. if [ $TARGET_OS == "windows" ]; then
  498. echo "$(tput setaf 1)Missing 'python3' which is important to run this script"
  499. failures 4
  500. elif [ $TARGET_OS == "linux" ]; then
  501. echo "$(tput setaf 1)Missing 'python3' which is important to run this script"
  502. echo "Install it with the command $(tput setaf 2)'sudo apt-get install python3'."
  503. failures 4
  504. fi
  505. fi
  506. }
  507. # End: Check python ... needed during language build
  508. #### Start: Set build environment
  509. set_build_env_variables()
  510. {
  511. BUILD_ENV="1.0.8"
  512. BOARD="prusa_einsy_rambo"
  513. BOARD_PACKAGE_NAME="PrusaResearch"
  514. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  515. BOARD_VERSION="1.0.6"
  516. else
  517. BOARD_VERSION="1.0.4"
  518. fi
  519. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  520. BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
  521. #BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
  522. else
  523. BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
  524. fi
  525. BOARD_FILENAME="prusa3dboards"
  526. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  527. BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  528. #BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  529. else
  530. BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  531. fi
  532. #PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env-1/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip"
  533. if [[ "$BOARD_VERSION" == "1.0.3" || "$BOARD_VERSION" == "1.0.2" || "$BOARD_VERSION" == "1.0.1" ]]; then
  534. PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip"
  535. fi
  536. LIB="PrusaLibrary"
  537. }
  538. #### End: Set build environment
  539. #### Start: List few useful data
  540. output_useful_data()
  541. {
  542. echo
  543. echo "Script path :" $SCRIPT_PATH
  544. echo "OS :" $OS
  545. echo "OS type :" $TARGET_OS
  546. echo ""
  547. echo "Arduino IDE :" $ARDUINO_ENV
  548. echo "Build env :" $BUILD_ENV
  549. echo "Board :" $BOARD
  550. if [ ! -z "$BOARD_FLASH" ] ; then
  551. echo "Board flash :" $BOARD_FLASH
  552. fi
  553. if [ ! -z "$BOARD_MEM" ] ; then
  554. echo "Board mem :" $BOARD_MEM
  555. fi
  556. echo "Package name:" $BOARD_PACKAGE_NAME
  557. echo "Board v. :" $BOARD_VERSION
  558. echo "Specific Lib:" $LIB
  559. echo ""
  560. }
  561. #### End: List few useful data
  562. #### Start: Prepare building environment
  563. # Start: Check if build exists and creates it if not
  564. check_create_build_folders()
  565. {
  566. # Check if PF-build-env/<version> exists and downloads + creates it if not
  567. # The build environment is based on the supported Arduino IDE portable version with some changes
  568. if [ ! -d "../PF-build-env/$BUILD_ENV" ]; then
  569. echo "$(tput setaf 6)PF-build-env/$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  570. mkdir -p ../PF-build-env/$BUILD_ENV
  571. if [ $OUTPUT == "1" ] ; then
  572. sleep 2
  573. fi
  574. fi
  575. }
  576. # End: Check if build exists and creates it if not
  577. # Start: Download and extract supported Arduino IDE depending on OS
  578. download_prepare_arduinoIDE()
  579. {
  580. if [ ! -d "../PF-build-dl" ]; then
  581. mkdir ../PF-build-dl || failures 9
  582. fi
  583. cd ../PF-build-dl || failures 10
  584. BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  585. # Windows
  586. if [ $TARGET_OS == "windows" ]; then
  587. if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then
  588. echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  589. if [ $OUTPUT == "1" ] ; then
  590. sleep 2
  591. fi
  592. wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || failures 8
  593. echo "$(tput sgr 0)"
  594. fi
  595. if [[ ! -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" && ! -e "../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]]; then
  596. echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  597. if [ $OUTPUT == "1" ] ; then
  598. sleep 2
  599. fi
  600. unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env/$BUILD_ENV || failures 11
  601. mv ../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
  602. echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  603. echo "$(tput sgr0)"
  604. fi
  605. fi
  606. # Linux
  607. if [ $TARGET_OS == "linux" ]; then
  608. # 32 or 64 bit version
  609. if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then
  610. echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  611. if [ $OUTPUT == "1" ] ; then
  612. sleep 2
  613. fi
  614. wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || failures 8
  615. echo "$(tput sgr 0)"
  616. fi
  617. if [[ ! -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" && ! -e "../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]]; then
  618. echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  619. if [ $OUTPUT == "1" ] ; then
  620. sleep 2
  621. fi
  622. tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env/$BUILD_ENV/ || failures 11
  623. mv ../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
  624. echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env/$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  625. echo "$(tput sgr0)"
  626. fi
  627. fi
  628. }
  629. # End: Download and extract supported Arduino IDE depending on OS
  630. # Start: Make Arduino IDE portable
  631. portable_ArduinoIDE()
  632. {
  633. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/ ]; then
  634. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/
  635. fi
  636. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/ ]; then
  637. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable
  638. fi
  639. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/output/ ]; then
  640. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/output
  641. fi
  642. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/ ]; then
  643. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages
  644. fi
  645. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/ ]; then
  646. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook
  647. fi
  648. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/libraries/ ]; then
  649. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/libraries
  650. fi
  651. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/staging/ ]; then
  652. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/staging
  653. fi
  654. }
  655. # End: Make Arduino IDE portable
  656. # Start: Change Arduino IDE preferences
  657. change_ArduinoIDEpreferances()
  658. {
  659. if [ ! -e ../PF-build-env/$BUILD_ENV/Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt ]; then
  660. echo "$(tput setaf 6)Setting $ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor Arduino IDE preferences for portable GUI usage...$(tput setaf 2)"
  661. if [ $OUTPUT == "1" ] ; then
  662. sleep 2
  663. fi
  664. echo "update.check"
  665. sed -i 's/update.check = true/update.check = false/g' ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  666. echo "board"
  667. sed -i "s/board = uno/board = $BOARD/g" ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  668. echo "editor.linenumbers"
  669. sed -i 's/editor.linenumbers = false/editor.linenumbers = true/g' ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  670. echo "boardsmanager.additional.urls"
  671. echo "boardsmanager.additional.urls=$BOARD_URL" >>../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  672. echo "build.verbose=true" >>../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  673. echo "compiler.cache_core=false" >>../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  674. echo "compiler.warning_level=all" >>../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  675. echo "# Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env/$BUILD_ENV/Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  676. echo "$(tput sgr0)"
  677. fi
  678. }
  679. # End: Change Arduino IDE preferences
  680. # Start: Download and extract Prusa Firmware related parts
  681. download_prepare_Prusa_build_files()
  682. {
  683. # Download and extract PrusaResearchRambo board
  684. if [ ! -f "$BOARD_FILENAME-$BOARD_VERSION.tar.bz2" ]; then
  685. echo "$(tput setaf 6)Downloading Prusa Research AVR MK3 RAMBo EINSy build environment...$(tput setaf 2)"
  686. if [ $OUTPUT == "1" ] ; then
  687. sleep 2
  688. fi
  689. wget $BOARD_FILE_URL || failures 8
  690. fi
  691. if [[ ! -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION" || ! -e "../PF-build-env/$BUILD_ENV/$BOARD_FILENAME-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]]; then
  692. echo "$(tput setaf 6)Unzipping $BOARD_PACKAGE_NAME Arduino IDE portable...$(tput setaf 2)"
  693. if [ $OUTPUT == "1" ] ; then
  694. sleep 2
  695. fi
  696. tar -xvf $BOARD_FILENAME-$BOARD_VERSION.tar.bz2 -C ../PF-build-env/$BUILD_ENV/ || failures 11
  697. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME ]; then
  698. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME
  699. fi
  700. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME ]; then
  701. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME
  702. fi
  703. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware ]; then
  704. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware
  705. fi
  706. if [ ! -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr ]; then
  707. mkdir ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr
  708. fi
  709. mv ../PF-build-env/$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION
  710. echo "# $BOARD_FILENAME-$BOARD_VERSION" >> ../PF-build-env/$BUILD_ENV/$BOARD_FILENAME-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  711. echo "$(tput sgr 0)"
  712. fi
  713. # Download and extract Prusa Firmware specific library files
  714. if [[ "$BOARD_VERSION" == "1.0.3" || "$BOARD_VERSION" == "1.0.2" || "$BOARD_VERSION" == "1.0.1" ]]; then
  715. if [ ! -f "PF-build-env-WinLin-$BUILD_ENV.zip" ]; then
  716. echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)"
  717. if [ $OUTPUT == "1" ] ; then
  718. sleep 2
  719. fi
  720. wget $PF_BUILD_FILE_URL || failures 8
  721. echo "$(tput sgr 0)"
  722. fi
  723. if [ ! -e "../PF-build-env/$BUILD_ENV/PF-build-env/$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]; then
  724. echo "$(tput setaf 6)Unzipping Prusa Firmware build environment...$(tput setaf 2)"
  725. if [ $OUTPUT == "1" ] ; then
  726. sleep 2
  727. fi
  728. unzip -o PF-build-env-WinLin-$BUILD_ENV.zip -d ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor || failures 11
  729. echo "# PF-build-env-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor-$BUILD_ENV" >> ../PF-build-env/$BUILD_ENV/PF-build-env/$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  730. echo "$(tput sgr0)"
  731. fi
  732. fi
  733. }
  734. # End: Download and extract Prusa Firmware related parts
  735. # Start: Check if User updated Arduino IDE 1.8.5 boardsmanager and tools
  736. check_ArduinoIDE_User_interaction()
  737. {
  738. if [ -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/arduino/tools" ]; then
  739. echo "$(tput setaf 6)Arduino IDE boards / tools have been manually updated...$"
  740. echo "Please don't update the 'Arduino AVR boards' as this will prevent running this script (tput setaf 2)"
  741. if [ $OUTPUT == "1" ] ; then
  742. sleep 2
  743. fi
  744. fi
  745. if [ -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2" ]; then
  746. echo "$(tput setaf 6)PrusaReasearch compatible tools have been manually updated...$(tput setaf 2)"
  747. if [ $OUTPUT == "1" ] ; then
  748. sleep 2
  749. fi
  750. echo "$(tput setaf 6)Copying Prusa Firmware build environment to manually updated boards / tools...$(tput setaf 2)"
  751. if [ $OUTPUT == "1" ] ; then
  752. sleep 2
  753. fi
  754. cp -f ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/hardware/tools/avr/avr/lib/ldscripts/avr6.xn ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/avr/lib/ldscripts/avr6.xn
  755. echo "# PF-build-env-portable-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor-$BUILD_ENV" >> ../PF-build-env/$BUILD_ENV/PF-build-env-portable-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  756. echo "$(tput sgr0)"
  757. fi
  758. if [ -d "../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2" ]; then
  759. echo "$(tput setaf 1)Arduino IDE tools have been updated manually to a non supported version!!!"
  760. echo "Delete ../PF-build-env/$BUILD_ENV and start the script again"
  761. echo "Script will not continue until this have been fixed $(tput setaf 2)"
  762. if [ $OUTPUT == "1" ] ; then
  763. sleep 2
  764. fi
  765. echo "$(tput sgr0)"
  766. failures 4
  767. fi
  768. }
  769. # End: Check if User updated Arduino IDE 1.8.5 boardsmanager and tools
  770. #
  771. #### End: prepare bash / Linux environment
  772. #### End prepare building
  773. #### Start: Getting arguments for command line compiling
  774. get_arguments()
  775. {
  776. # Check if git is available
  777. if type git > /dev/null; then
  778. git_available="1"
  779. fi
  780. #
  781. # '-v' argument defines which variant of the Prusa Firmware will be compiled
  782. if [ -z "$variant_flag" ] ; then
  783. # Select which variant of the Prusa Firmware will be compiled, like
  784. PS3="Select a variant: "
  785. while IFS= read -r -d $'\0' f; do
  786. options[i++]="$f"
  787. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  788. IFS=$'\n' sorted=($(sort -n <<<"${options[*]}")); unset IFS
  789. select opt in "${sorted[@]}" "All" "Quit"; do
  790. case $opt in
  791. *.h)
  792. VARIANT=$(basename "$opt" ".h")
  793. VARIANTS[i++]="$opt"
  794. break
  795. ;;
  796. "All")
  797. VARIANT="All"
  798. VARIANTS=${options[*]}
  799. variant_flag="All"
  800. break
  801. ;;
  802. "Quit")
  803. echo "You chose to stop"
  804. failures 20
  805. ;;
  806. *)
  807. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  808. ;;
  809. esac
  810. done
  811. else
  812. if [ -f "$SCRIPT_PATH/Firmware/variants/$variant_flag" ] ; then
  813. VARIANTS=$variant_flag
  814. elif [ "$variant_flag" == "All" ] ; then
  815. while IFS= read -r -d $'\0' f; do
  816. options[i++]="$f"
  817. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  818. VARIANT="All"
  819. VARIANTS=${options[*]}
  820. else
  821. echo "$(tput setaf 1)Argument $variant_flag could not be found in Firmware/variants please choose a valid one.$(tput sgr0)"
  822. echo "Only $(tput setaf 2)'All'$(tput sgr0) and file names below are allowed as variant '-v' argument.$(tput setaf 2)"
  823. ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename
  824. echo "$(tput sgr0)"
  825. failures 4
  826. fi
  827. fi
  828. #'-l' argument defines if it is an English only version. Known values EN_FARM / ALL
  829. #Check default language mode
  830. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  831. if [ -z "$language_flag" ] ; then
  832. PS3="Select a language: "
  833. echo
  834. echo "Which lang-build do you want?"
  835. select yn in "Multi languages" "English only"; do
  836. case $yn in
  837. "Multi languages")
  838. LANGUAGES="ALL"
  839. break
  840. ;;
  841. "English only")
  842. LANGUAGES="EN_FARM"
  843. break
  844. ;;
  845. *)
  846. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  847. ;;
  848. esac
  849. done
  850. else
  851. if [[ "$language_flag" == "ALL" || "$language_flag" == "EN_FARM" ]] ; then
  852. LANGUAGES=$language_flag
  853. else
  854. echo "$(tput setaf 1)Language argument is wrong!$(tput sgr0)"
  855. echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_FARM'$(tput sgr0) are allowed as language '-l' argument!"
  856. failures 5
  857. fi
  858. fi
  859. #Check if DEV_STATUS is selected via argument '-d'
  860. if [ ! -z "$devel_flag" ] ; then
  861. if [[ "$devel_flag" == "GOLD" || "$devel_flag" == "RC" || "$devel_flag" == "BETA" || "$devel_flag" == "ALPHA" || "$devel_flag" == "DEVEL" || "$devel_flag" == "DEBUG" || "$devel_flag" == "UNKNOWN" ]] ; then
  862. DEV_STATUS_SELECTED=$devel_flag
  863. elif [[ "$devel_flag" == "atmega404" || "$devel_flag" == "atmega404_no_bootloader" ]] ; then
  864. MK404_DEBUG=$devel_flag
  865. else
  866. echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)"
  867. echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL', 'DEBUG' or 'UNKNOWN' $(tput sgr0) are allowed as devel '-d' argument!$(tput sgr0)"
  868. failures 5
  869. fi
  870. fi
  871. #Check if Build is selected via argument '-b'
  872. if [ ! -z "$build_flag" ] ; then
  873. if [[ "$build_flag" == "Auto" && "$git_available" == "1" ]] ; then
  874. BUILD=$(git rev-list --count HEAD)
  875. elif [[ $build_flag =~ ^[0-9]+$ ]] ; then
  876. BUILD=$build_flag
  877. else
  878. echo "$(tput setaf 1)Build number argument is wrong!$(tput sgr0)"
  879. echo "Only $(tput setaf 2)'Auto' (git needed) or numbers $(tput sgr0) are allowed as build '-b' argument!$(tput sgr0)"
  880. failures 5
  881. fi
  882. fi
  883. #Check git branch has changed
  884. if [ ! -z "git_available" ]; then
  885. BRANCH=$(git branch --show-current)
  886. echo "Current branch is:" $BRANCH
  887. if [ ! -f "$SCRIPT_PATH/../PF-build.branch" ]; then
  888. #echo "$BRANCH" >| $SCRIPT_PATH/../PF-build.branch
  889. echo "created PF-build.branch file"
  890. else
  891. PRE_BRANCH=$(cat "$SCRIPT_PATH/../PF-build.branch")
  892. #echo "Previous branch was:" $PRE_BRANCH
  893. if [ ! "$BRANCH" == "$PRE_BRANCH" ] ; then
  894. CLEAN_PF_FW_BUILD=1
  895. echo "$BRANCH" >| $SCRIPT_PATH/../PF-build.branch
  896. fi
  897. fi
  898. else
  899. BRANCH=""
  900. CLEAN_PF_FW_BUILD=0
  901. fi
  902. }
  903. #### End: Getting arguments for command line compiling
  904. #### Start: Set needed Paths
  905. set_paths()
  906. {
  907. cd ../PF-build-env/$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor || failures 10
  908. BUILD_ENV_PATH="$( pwd -P )"
  909. cd ../../..
  910. #Checkif BUILD_PATH exists and if not creates it
  911. if [ ! -d "Prusa-Firmware-build" ]; then
  912. mkdir Prusa-Firmware-build || failures 9
  913. fi
  914. #Set the BUILD_PATH for Arduino IDE
  915. cd Prusa-Firmware-build || failures 10
  916. BUILD_PATH="$( pwd -P )"
  917. }
  918. #### End: Set needed Paths
  919. #### Start: Check git branch has changed
  920. check_branch_changed()
  921. {
  922. if [ "$CLEAN_PF_FW_BUILD" == "1" ]; then
  923. read -t 10 -p "Branch changed, cleaning Prusa-Firmware-build folder"
  924. rm -r *
  925. else
  926. echo "Nothing to clean up"
  927. fi
  928. }
  929. #### End: Check git branch has changed
  930. #### Start: Prepare code for compiling
  931. prepare_code_for_compiling()
  932. {
  933. VARIANT=$(basename "$v" ".h")
  934. MK404_PRINTER=$(grep --max-count=1 "\bPRINTER_TYPE\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3 | cut -d '_' -f2)
  935. # Find firmware version in Configuration.h file and use it to generate the hex filename
  936. FW_MAJOR=$(grep --max-count=1 "\bFW_MAJOR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  937. FW_MINOR=$(grep --max-count=1 "\bFW_MINOR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  938. FW_REVISION=$(grep --max-count=1 "\bFW_REVISION\b" $SCRIPT_PATH/Firmware/Configuration.h| sed -e's/ */ /g'|cut -d ' ' -f3)
  939. FW="$FW_MAJOR$FW_MINOR$FW_REVISION"
  940. #FW=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g')
  941. if [ -z "$BUILD" ] ; then
  942. # Find build version in Configuration.h file and use it to generate the hex filename
  943. BUILD=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  944. else
  945. # Find and replace build version in Configuration.h file
  946. BUILD_ORG=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  947. echo "Original build number: $BUILD_ORG"
  948. if [ "$BUILD_ORG" != "$BUILD" ]; then
  949. echo "New build number : $BUILD"
  950. sed -i -- "s/^#define FW_COMMIT_NR.*/#define FW_COMMIT_NR $BUILD/g" $SCRIPT_PATH/Firmware/Configuration.h
  951. fi
  952. fi
  953. # Check if the motherboard is an EINSY and if so only one hex file will generated
  954. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  955. # Check development status
  956. FW_FLAV=$(grep --max-count=1 "//#define FW_FLAVOR\b" $SCRIPT_PATH/Firmware/Configuration.h|cut -d ' ' -f1)
  957. FW_FLAVREV=$(grep --max-count=1 "//#define FW_FLAVERSION\b" $SCRIPT_PATH/Firmware/Configuration.h|cut -d ' ' -f1)
  958. if [[ "$FW_FLAV" == "//#define" && -z $FW_FLAVREV ]];then
  959. failures 26
  960. fi
  961. #echo "FLAV:$FW_FLAV"
  962. if [[ "$FW_FLAV" != "//#define" ]] ; then
  963. FW_FLAVOR=$(grep --max-count=1 "\bFW_FLAVOR\b" $SCRIPT_PATH/Firmware/Configuration.h| sed -e's/ */ /g'|cut -d ' ' -f3)
  964. #echo "FLAVOR:$FW_FLAVOR"
  965. if [[ "$FW_FLAVREV" != "//#define" ]] ; then
  966. FW_FLAVERSION=$(grep --max-count=1 "\bFW_FLAVERSION\b" $SCRIPT_PATH/Firmware/Configuration.h| sed -e's/ */ /g'|cut -d ' ' -f3)
  967. FW="$FW-$FW_FLAVOR"
  968. DEV_CHECK="$FW_FLAVOR"
  969. echo "DEV:$DEV_CHECK"
  970. if [ ! -z "$FW_FLAVERSION" ] ; then
  971. FW="$FW$FW_FLAVERSION"
  972. fi
  973. else
  974. failures 26
  975. fi
  976. fi
  977. #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)
  978. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  979. if [[ "$DEV_CHECK" == *"RC"* ]] ; then
  980. DEV_STATUS="RC"
  981. elif [[ "$DEV_CHECK" == *"ALPHA"* ]]; then
  982. DEV_STATUS="ALPHA"
  983. elif [[ "$DEV_CHECK" == *"BETA"* ]]; then
  984. DEV_STATUS="BETA"
  985. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  986. DEV_STATUS="DEVEL"
  987. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  988. DEV_STATUS="DEBUG"
  989. else
  990. DEV_STATUS="UNKNOWN"
  991. echo
  992. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  993. PS3="Select YES only if source code is tested and trusted: "
  994. select yn in "Yes" "No"; do
  995. case $yn in
  996. Yes)
  997. DEV_STATUS="GOLD"
  998. DEV_STATUS_SELECTED="GOLD"
  999. break
  1000. ;;
  1001. No)
  1002. DEV_STATUS="UNKNOWN"
  1003. DEV_STATUS_SELECTED="UNKNOWN"
  1004. break
  1005. ;;
  1006. *)
  1007. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  1008. ;;
  1009. esac
  1010. done
  1011. fi
  1012. else
  1013. DEV_STATUS=$DEV_STATUS_SELECTED
  1014. fi
  1015. }
  1016. #### End: Prepare code for compiling
  1017. prepare_hex_folders()
  1018. {
  1019. if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  1020. mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD || failures 9
  1021. fi
  1022. OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD"
  1023. if [ "$BOARD" != "prusa_einsy_rambo" ]; then
  1024. if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD" ]; then
  1025. mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD || failures 9
  1026. fi
  1027. OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$BOARD"
  1028. fi
  1029. #Define OUTPUT_FILENAME
  1030. OUTPUT_FILENAME=FW$FW-Build$BUILD-$VARIANT
  1031. #Check for OUTPUT_FILENAME_SUFFIX and add it
  1032. if [ ! -z $OUTPUT_FILENAME_SUFFIX ]; then
  1033. OUTPUT_FILENAME="${OUTPUT_FILENAME}$OUTPUT_FILENAME_SUFFIX"
  1034. fi
  1035. #Check if exactly the same hexfile already exists
  1036. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex" && "$LANGUAGES" == "ALL" ]]; then
  1037. echo ""
  1038. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex | xargs -n1 basename
  1039. 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)"
  1040. if [ $OUTPUT == "1" ] ; then
  1041. read -t 10 -p "Press Enter to continue..."
  1042. fi
  1043. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex" && "$LANGUAGES" == "EN_FARM" ]]; then
  1044. echo ""
  1045. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex | xargs -n1 basename
  1046. 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)"
  1047. if [ $OUTPUT == "1" ] ; then
  1048. read -t 10 -p "Press Enter to continue..."
  1049. fi
  1050. fi
  1051. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip" && "$LANGUAGES" == "ALL" ]]; then
  1052. echo ""
  1053. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip | xargs -n1 basename
  1054. 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)"
  1055. if [ $OUTPUT == "1" ] ; then
  1056. read -t 10 -p "Press Enter to continue..."
  1057. fi
  1058. fi
  1059. }
  1060. #### End: Prepare hex files folder
  1061. #### Start: List usefull data
  1062. list_usefull_data()
  1063. {
  1064. echo "$(tput setaf 2)$(tput setab 7) "
  1065. echo "Printer :" $MK404_PRINTER
  1066. echo "Variant :" $VARIANT
  1067. echo "Firmware :" $FW
  1068. echo "Build # :" $BUILD
  1069. echo "Dev Check :" $DEV_CHECK
  1070. echo "DEV Status :" $DEV_STATUS
  1071. echo "Motherboard :" $MOTHERBOARD
  1072. echo "Board flash :" $BOARD_FLASH
  1073. echo "Board mem :" $BOARD_MEM
  1074. echo "Languages :" $LANGUAGES
  1075. echo "Hex-file Folder:" $OUTPUT_FOLDER
  1076. echo "Hex filename :" $OUTPUT_FILENAME
  1077. echo "$(tput sgr0)"
  1078. }
  1079. #### End: List usefull data
  1080. #### Start: Prepare Firmware to be compiled
  1081. prepare_variant_for_compiling()
  1082. {
  1083. # Copy variant as Configuration_prusa.h
  1084. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  1085. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 12
  1086. else
  1087. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  1088. if [ $OUTPUT == "1" ] ; then
  1089. read -t 10 -p "Press Enter to continue..."
  1090. fi
  1091. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 12
  1092. fi
  1093. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  1094. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_.*/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  1095. # set FW_REPOSITORY
  1096. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  1097. #Prepare English only or multi-language version to be build
  1098. if [ $LANGUAGES == "EN_FARM" ]; then
  1099. echo " "
  1100. echo "English only language firmware will be built"
  1101. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  1102. echo " "
  1103. else
  1104. echo " "
  1105. echo "Multi-language firmware will be built"
  1106. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  1107. echo " "
  1108. fi
  1109. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  1110. #if [ $TARGET_OS == "windows" ]; then
  1111. #RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
  1112. #fi
  1113. #New fresh PF-Firmware-build
  1114. if [ "$new_build_flag" == "1" ]; then
  1115. rm -r -f $BUILD_PATH/* || failures 13
  1116. fi
  1117. }
  1118. #### End: Prepare Firmware to be compiled
  1119. #### End of Prepare building
  1120. #### Start: Compiling EN Prusa Firmware
  1121. compile_en_firmware()
  1122. {
  1123. ## Check board mem size
  1124. CURRENT_BOARD_MEM=$(grep "#define RAMEND" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h | sed -e's/.* //g'|cut -d ' ' -f2 |tr -d ' \t\n\r')
  1125. if [ $CURRENT_BOARD_MEM != "0x21FF" ] ; then
  1126. echo "$(tput setaf 1)Board mem has been modified or not reset$(tput sgr 0)"
  1127. echo "Current:" $CURRENT_BOARD_MEM
  1128. PS3="Select $(tput setaf 2)Yes$(tput sgr 0) if you want to reset it."
  1129. select yn in "Yes" "No"; do
  1130. case $yn in
  1131. Yes)
  1132. echo "Resetting board mem size"
  1133. sed -i -- "s/^#define RAMEND .*$/#define RAMEND 0x21FF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1134. BOARD_MEM_MODIFIED=0
  1135. break
  1136. ;;
  1137. *)
  1138. echo "Continuing with modified mem size"
  1139. BOARD_MEM_MODIFIED=1
  1140. break
  1141. ;;
  1142. esac
  1143. done
  1144. else
  1145. BOARD_MEM_MODIFIED=0
  1146. fi
  1147. ## Modify board mem size
  1148. if [[ ! -z $BOARD_MEM && "$BOARD_MEM" != "0x21FF" ]] ; then
  1149. echo "$(tput setaf 3)Modifying board memory size (hex):$(tput sgr 0)"
  1150. echo "Old:" $CURRENT_BOARD_MEM
  1151. echo "New:" $BOARD_MEM
  1152. read -t 5 -p "To cancel press $(tput setaf 1)CRTL+C$(tput sgr 0)"
  1153. echo ""
  1154. sed -i -- "s/^#define RAMEND 0x21FF/#define RAMEND ${BOARD_MEM}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1155. BOARD_MEM_MODIFIED=1
  1156. fi
  1157. ## Check board flash size
  1158. CURRENT_BOARD_FLASH=$(grep "#define FLASHEND" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h | sed -e's/.* //g'|cut -d ' ' -f2 |tr -d ' \t\n\r')
  1159. CURRENT_BOARD_maximum_size=$(grep "prusa_einsy_rambo.upload.maximum_size" $BUILD_ENV_PATH/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION/boards.txt |cut -d '=' -f2|tr -d ' \t\n\r')
  1160. if [[ $CURRENT_BOARD_FLASH != "0x3FFFF" || $CURRENT_BOARD_maximum_size != "253952" ]] ; then
  1161. echo "$(tput setaf 1)Board flash has been modified or not reset$(tput sgr 0)"
  1162. echo "Current flash size:" $CURRENT_BOARD_FLASH
  1163. echo "Current max. size:" $CURRENT_BOARD_maximum_size
  1164. PS3="Select $(tput setaf 2)Yes$(tput sgr 0) if you want to reset it."
  1165. select yn in "Yes" "No"; do
  1166. case $yn in
  1167. Yes)
  1168. echo "$(tput setaf 1)Resetting board flash size$(tput sgr 0)"
  1169. sed -i -- "s/^#define FLASHEND .*$/#define FLASHEND 0x3FFFF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1170. sed -i -- "s/^prusa_einsy_rambo.upload.maximum_size.*/prusa_einsy_rambo.upload.maximum_size=253952/g" $BUILD_ENV_PATH/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION/boards.txt
  1171. BOARD_FLASH_MODIFIED=0
  1172. break
  1173. ;;
  1174. *)
  1175. echo "$(tput setaf 3)Continuing with modified flash size$(tput sgr 0)"
  1176. BOARD_FLASH_MODIFIED=1
  1177. break
  1178. ;;
  1179. esac
  1180. done
  1181. else
  1182. BOARD_FLASH_MODIFIED=1
  1183. fi
  1184. ## Modify boad flash size
  1185. if [[ ! -z $BOARD_FLASH && "$BOARD_FLASH" != "0x3FFFF" ]] ; then
  1186. echo "$(tput setaf 3)Modifying board flash size (hex):$(tput sgr 0)"
  1187. echo "Old flash size:" $CURRENT_BOARD_FLASH
  1188. echo "New flash size:" $BOARD_FLASH
  1189. echo "Old max. size:" $CURRENT_BOARD_maximum_size
  1190. echo "New max. size:" $BOARD_maximum_size
  1191. read -t 5 -p "To cancel press $(tput setaf 1)CRTL+C$(tput sgr 0)"
  1192. sed -i -- "s/^#define FLASHEND .*/#define FLASHEND ${BOARD_FLASH}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1193. sed -i -- "s/^prusa_einsy_rambo.upload.maximum_size.*/prusa_einsy_rambo.upload.maximum_size=${BOARD_maximum_size}/g" $BUILD_ENV_PATH/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION/boards.txt
  1194. BOARD_FLASH_MODIFIED=1
  1195. fi
  1196. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  1197. # if [ $TARGET_OS == "windows" ]; then
  1198. # RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
  1199. # fi
  1200. #### End of Prepare building
  1201. #### Start building
  1202. export ARDUINO=$BUILD_ENV_PATH
  1203. #echo $BUILD_ENV_PATH
  1204. #export BUILDER=$ARDUINO/arduino-builder
  1205. echo
  1206. #read -t 5 -p "Press Enter..."
  1207. echo
  1208. echo "Start to build Prusa Firmware ..."
  1209. echo "Using variant $VARIANT$(tput setaf 3)"
  1210. if [ $OUTPUT == "1" ] ; then
  1211. sleep 2
  1212. fi
  1213. if [ $verbose_IDE == "1" ]; then
  1214. $BUILD_ENV_PATH/arduino-builder -dump-prefs -debug-level 10 -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_PACKAGE_NAME:avr:$BOARD -build-path=$BUILD_PATH -warnings=all $SCRIPT_PATH/Firmware/Firmware.ino || failures 24
  1215. fi
  1216. $BUILD_ENV_PATH/arduino-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_PACKAGE_NAME:avr:$BOARD -build-path=$BUILD_PATH -warnings=all -verbose=$verbose_IDE $SCRIPT_PATH/Firmware/Firmware.ino || failures 24
  1217. }
  1218. #### End: Compiling EN Prusa Firmware
  1219. #### Start: Create and save Multi Language Prusa Firmware
  1220. create_multi_firmware()
  1221. {
  1222. #if [ $LANGUAGES == "ALL" ]; then
  1223. echo "$(tput setaf 2)"
  1224. echo "Building multi language firmware" $MULTI_LANGUAGE_CHECK
  1225. echo "$(tput sgr 0)"
  1226. if [ $OUTPUT == "1" ] ; then
  1227. sleep 2
  1228. fi
  1229. cd $SCRIPT_PATH/lang
  1230. echo "$(tput setaf 3)"
  1231. ./config.sh || failures 25
  1232. echo "$(tput sgr 0)"
  1233. # Check if previous languages and firmware build exist and if so clean them up
  1234. if [ -f "lang_en.tmp" ]; then
  1235. echo ""
  1236. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  1237. if [ $OUTPUT == "1" ] ; then
  1238. read -t 10 -p "Press Enter to continue..."
  1239. fi
  1240. echo "$(tput setaf 3)"
  1241. ./lang-clean.sh
  1242. echo "$(tput sgr 0)"
  1243. fi
  1244. if [ -f "progmem.out" ]; then
  1245. echo ""
  1246. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  1247. if [ $OUTPUT == "1" ] ; then
  1248. read -t 10 -p "Press Enter to continue..."
  1249. fi
  1250. echo "$(tput setaf 3)"
  1251. ./fw-clean.sh
  1252. echo "$(tput sgr 0)"
  1253. fi
  1254. # Combine compiled firmware with languages
  1255. echo "$(tput setaf 3)"
  1256. ./fw-build.sh || failures 25
  1257. echo "$(tput sgr 0)"
  1258. # Check if the motherboard is an EINSY and if so only one hex file will generated
  1259. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  1260. # If the motherboard is an EINSY just copy one hexfile
  1261. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  1262. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to PF-build-hex folder$(tput sgr 0)"
  1263. # End of "lang.bin" for MK3 and MK3S copy
  1264. cp -f Firmware-intl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex
  1265. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.elf
  1266. else
  1267. #Search for created firmware languages
  1268. langs=$(find Firmware-intl-en_*.hex | cut -d "_" -f2 | cut -d "." -f1)
  1269. #Copy found firmware_*.hex files
  1270. for la in $langs; do
  1271. cp -f Firmware-intl-en_$la.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-$la.hex
  1272. done
  1273. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.elf
  1274. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to PF-build-hex folder$(tput sgr 0)"
  1275. if [ $TARGET_OS == "windows" ]; then
  1276. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1277. #rm $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1278. elif [ $TARGET_OS == "linux" ]; then
  1279. zip -j ../../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip ../../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1280. fi
  1281. fi
  1282. # Cleanup after build
  1283. if [[ -z "$clean_flag" || "$clean_flag" == "0" ]]; then
  1284. echo "$(tput setaf 3)"
  1285. ./fw-clean.sh || failures 25
  1286. echo "$(tput sgr 0)"
  1287. fi
  1288. }
  1289. #### End: Create and save Multi Language Prusa Firmware
  1290. #### Start: Save EN_FARM language Prusa Firmware
  1291. save_en_firmware()
  1292. {
  1293. #else
  1294. echo "$(tput setaf 2)Copying English only firmware to PF-build-hex folder$(tput sgr 0)"
  1295. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex || failures 12
  1296. echo "$(tput setaf 2)Copying English only elf file to PF-build-hex folder$(tput sgr 0)"
  1297. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.elf || failures 12
  1298. #fi
  1299. }
  1300. #### End: Save EN_FARM language Prusa Firmware
  1301. #### Start: Cleanup Firmware
  1302. cleanup_firmware()
  1303. {
  1304. if [[ -z "$prusa_flag" || "$prusa_flag" == "0" ]]; then
  1305. if [ -e "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  1306. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 13
  1307. fi
  1308. fi
  1309. # Delete dupblicates
  1310. if find $SCRIPT_PATH/lang/ -name '*RAMBo10a*.txt' -printf 1 -quit | grep -q 1
  1311. then
  1312. rm $SCRIPT_PATH/lang/*RAMBo10a*.txt || failures 13
  1313. fi
  1314. # MK2 not supported in this branch
  1315. if find $SCRIPT_PATH/lang/ -name '*MK2-RAMBo13a*' -printf 1 -quit | grep -q 1
  1316. then
  1317. rm $SCRIPT_PATH/lang/*MK2-RAMBo13a*.txt || failures 13
  1318. fi
  1319. if find $SCRIPT_PATH/lang/ -name 'not_tran.txt' -printf 1 -quit | grep -q 1
  1320. then
  1321. rm $SCRIPT_PATH/lang/not_tran.txt || failures 13
  1322. fi
  1323. if find $SCRIPT_PATH/lang/ -name 'not_used.txt' -printf 1 -quit | grep -q 1
  1324. then
  1325. rm $SCRIPT_PATH/lang/not_used.txt || failures 13
  1326. fi
  1327. #New fresh PF-Firmware-build
  1328. if [ "$new_build_flag" == "1" ]; then
  1329. rm -r -f $BUILD_PATH/* || failures 13
  1330. fi
  1331. # Restore files to previous state
  1332. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_.*/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  1333. sed -i -- 's/^#define FW_REPOSITORY.*/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  1334. if [ ! -z "$BUILD_ORG" ] ; then
  1335. sed -i -- "s/^#define FW_COMMIT_NR.*/#define FW_COMMIT_NR $BUILD_ORG/g" $SCRIPT_PATH/Firmware/Configuration.h
  1336. fi
  1337. echo $MULTI_LANGUAGE_CHECK
  1338. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  1339. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  1340. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  1341. if [ $OUTPUT == "1" ] ; then
  1342. sleep 2
  1343. fi
  1344. #Check for "Configuration.tmp" and delete it
  1345. if [ -e "$SCRIPT_PATH/Firmware/Configuration.tmp" ]; then
  1346. rm $SCRIPT_PATH/Firmware/Configuration.tmp
  1347. fi
  1348. #Check for "config.tmp" and delete it
  1349. if [ -e "$SCRIPT_PATH/Firmware/config.tmp" ]; then
  1350. rm $SCRIPT_PATH/Firmware/config.tmp
  1351. fi
  1352. if [ $OUTPUT == "1" ] ; then
  1353. sleep 2
  1354. fi
  1355. # Restore build env files to previous state
  1356. if [ "$BOARD_MEM_MODIFIED" == "1" ]; then
  1357. sed -i -- "s/^#define FLASHEND .*$/#define FLASHEND 0x3FFFF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1358. echo "$(tput setaf 2)Restored Board Mem$(tput sgr 0)"
  1359. fi
  1360. if [ "$BOARD_FLASH_MODIFIED" == "1" ]; then
  1361. sed -i -- "s/^prusa_einsy_rambo.upload.maximum_size.*/prusa_einsy_rambo.upload.maximum_size=253952/g" $BUILD_ENV_PATH/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION/boards.txt
  1362. sed -i -- "s/^#define RAMEND.*/#define RAMEND 0x21FF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1363. echo "$(tput setaf 2)Restored Board Flash$(tput sgr 0)"
  1364. fi
  1365. }
  1366. #### End: Prepare code for compiling
  1367. #done
  1368. #### Start: Finish script
  1369. # List hex path and list build files
  1370. finish_pf-build()
  1371. {
  1372. cd $SCRIPT_PATH
  1373. cd ..
  1374. echo "$(tput setaf 2) "
  1375. echo " "
  1376. failures 0
  1377. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  1378. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  1379. echo
  1380. echo "Files:"
  1381. ls -r -h $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/*
  1382. }
  1383. #### End: Finish script
  1384. #### End: building
  1385. ####Start: MK404 Simulator
  1386. MK404_SIM()
  1387. {
  1388. cd $SCRIPT_PATH
  1389. # Check/compile MK404 sim
  1390. if [[ "$output_flag" == "1" || -z "$output_flag" ]]; then
  1391. if [[ -z "$mk404_flag" && "$variant_flag" != "All" ]]; then
  1392. echo
  1393. read -t 10 -n 1 -p "Do you want to start MK404? Y/$(tput setaf 2)n$(tput sgr 0)" mk404_start
  1394. if [[ "$mk404_start" == "Y" || "$mk404_start" == "y" ]]; then
  1395. echo
  1396. read -t 10 -n 1 -p "Do you want to start MK404 with or without MMU2S? $(tput setaf 2)1$(tput sgr 0)/2" mk404_choose1
  1397. if [ "$mk404_choose1" == "1" ]; then
  1398. mk404_flag=1
  1399. elif [ "$mk404_choose1" == "2" ]; then
  1400. mk404_flag=2
  1401. else
  1402. mk404_flag=1 #default
  1403. fi
  1404. echo
  1405. echo "Choose MK404 graphics"
  1406. echo "0 = no graphics"
  1407. echo "1 = lite"
  1408. echo "2 = fancy"
  1409. echo "3 = lite with Quad_HR"
  1410. echo "4 = fancy lite with Quad_HR"
  1411. read -t 10 -n 1 -p "Which one do you want? $(tput setaf 2)0$(tput sgr 0)/1/2/3/4" mk404_choose2
  1412. if [ "$mk404_choose2" == "1" ]; then
  1413. mk404_graphics_flag=1
  1414. elif [ "$mk404_choose2" == "2" ]; then
  1415. mk404_graphics_flag=2
  1416. elif [ "$mk404_choose2" == "3" ]; then
  1417. mk404_graphics_flag=3
  1418. elif [ "$mk404_choose2" == "4" ]; then
  1419. mk404_graphics_flag=4
  1420. elif [ "$mk404_choose2" == "0" ]; then
  1421. mk404_graphics_flag=""
  1422. else
  1423. mk404_graphics_flag="" #default
  1424. fi
  1425. fi
  1426. echo
  1427. fi
  1428. fi
  1429. # For MMU2S
  1430. if [[ "$mk404_flag" == "2" || "$mk404_flag" == "MMU2" || "$mk404_flag" == "MMU2S" ]]; then # Check if MMU2 is selected only for MK3/S
  1431. mk404_flag=2
  1432. fi
  1433. if [[ ! -z "$mk404_flag" && "$variant_flag" != "All " ]]; then
  1434. # Run MK404 with 'debugcore' and/or 'bootloader-file'
  1435. if [ ! -z "$board_mem_flag" ]; then
  1436. MK404_options="-x $board_mem_flag"
  1437. fi
  1438. if [ ! -z "$board_flash_flag" ]; then
  1439. MK404_options="${MK404_options} -y $board_flash_flag"
  1440. fi
  1441. # Run MK404 with graphics
  1442. if [ ! -z "$mk404_graphics_flag" ]; then
  1443. if [[ "$mk404_graphics_flag" == "1" || "$mk404_graphics_flag" == "2" || "$mk404_graphics_flag" == "3" || "$mk404_graphics_flag" == "4" ]]; then
  1444. MK404_options="${MK404_options} -g $mk404_graphics_flag"
  1445. else
  1446. echo "$(tput setaf 1)Unsupported MK404 graphics option $mk404_graphics_flag$(tput sgr 0)"
  1447. fi
  1448. fi
  1449. # Output some useful data
  1450. echo "Printer: $MK404_PRINTER"
  1451. echo "Options: $MK404_options"
  1452. echo ""
  1453. #read -t 5 -p "Press $(tput setaf 2)Enter$(tput sgr 0) to start MK404"
  1454. echo ""
  1455. # Change to MK404 build folder
  1456. #cd ../MK404/master/build
  1457. #Decide which hex file to use EN_FARM or Multi language
  1458. if [ "$LANGUAGES" == "ALL" ]; then
  1459. if [[ "$MK404_PRINTER" == "MK3" || "$MK404_PRINTER" == "MK3S" ]]; then
  1460. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex
  1461. else
  1462. PS3="Select a language:"
  1463. select lan in ${langs[@]}
  1464. do
  1465. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-$lan.hex
  1466. break
  1467. done
  1468. fi
  1469. else
  1470. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex
  1471. fi
  1472. # Start MK404
  1473. # default with serial output and terminal to manipulate it via terminal
  1474. #echo ""
  1475. #echo "./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options -f $MK404_firmware_file"
  1476. #sleep 5
  1477. #./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options -f $MK404_firmware_file || exit 62
  1478. echo ""
  1479. echo "./MK404-build.sh -m $mk404_flag -p $MK404_PRINTER $MK404_options -f $MK404_firmware_file"
  1480. if [ $OUTPUT == "1" ] ; then
  1481. sleep 2
  1482. fi
  1483. ./MK404-build.sh -m $mk404_flag -p $MK404_PRINTER $MK404_options -f $MK404_firmware_file|| failures 25
  1484. fi
  1485. }
  1486. #### End: MK404 Simulator
  1487. #### Check OS and needed apps
  1488. echo "Check OS"
  1489. check_OS
  1490. check_wget
  1491. check_zip
  1492. check_python
  1493. #### Check for options/flags
  1494. echo "Check for options"
  1495. #### Prepare build environment
  1496. echo "Prepare build env"
  1497. get_arguments
  1498. set_build_env_variables
  1499. output_useful_data
  1500. #### Download/set needed apps and dependencies
  1501. if [ ! -d "../PF-build-env/$BUILD_ENV" ]; then
  1502. check_create_build_folders
  1503. download_prepare_arduinoIDE
  1504. portable_ArduinoIDE
  1505. change_ArduinoIDEpreferances
  1506. download_prepare_Prusa_build_files
  1507. check_ArduinoIDE_User_interaction
  1508. fi
  1509. #### Start
  1510. set_paths
  1511. check_branch_changed
  1512. for v in ${VARIANTS[*]}
  1513. do
  1514. check_script_failed_nr1
  1515. check_script_failed_nr2
  1516. make_backup1
  1517. make_backup2
  1518. prepare_code_for_compiling
  1519. prepare_hex_folders
  1520. list_usefull_data
  1521. prepare_variant_for_compiling
  1522. compile_en_firmware
  1523. if [ $LANGUAGES == "ALL" ]; then
  1524. create_multi_firmware
  1525. else
  1526. save_en_firmware
  1527. fi
  1528. cleanup_firmware
  1529. done
  1530. finish_pf-build
  1531. if [ $TARGET_OS == "linux" ]; then
  1532. MK404_SIM
  1533. fi