PF-build.sh 74 KB

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