PF-build.sh 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  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 python > /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 'python' which is important to run this script"
  502. echo "As Python 2.x will not be maintained from 2020 please,"
  503. echo "install it with the command $(tput setaf 2)'sudo apt-get install python3'."
  504. echo "Check which version of Python3 has been installed using 'ls /usr/bin/python3*'"
  505. echo "Use 'sudo ln -sf /usr/bin/python3.x /usr/bin/python' (where 'x' is your version number) to make it default.$(tput sgr0)"
  506. #sudo apt-get update && apt-get install python3 && ln -sf /usr/bin/python3 /usr/bin/python
  507. failures 4
  508. fi
  509. fi
  510. }
  511. # End: Check python ... needed during language build
  512. #Start: Check gawk ... needed during language build
  513. check_gawk()
  514. {
  515. if ! type gawk > /dev/null; then
  516. if [ $TARGET_OS == "linux" ]; then
  517. echo "$(tput setaf 1)Missing 'gawk' which is important to run this script"
  518. echo "install it with the command $(tput setaf 2)'sudo apt-get install gawk'."
  519. #sudo apt-get update && apt-get install gawk
  520. failures 4
  521. fi
  522. fi
  523. }
  524. #End: Check gawk ... needed during language build
  525. #### Start: Set build environment
  526. set_build_env_variables()
  527. {
  528. BUILD_ENV="1.0.8"
  529. BOARD="prusa_einsy_rambo"
  530. BOARD_PACKAGE_NAME="PrusaResearch"
  531. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  532. BOARD_VERSION="1.0.5-2"
  533. else
  534. BOARD_VERSION="1.0.4"
  535. fi
  536. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  537. BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/devel/IDE_Board_Manager/package_prusa3d_index.json"
  538. #BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/devel/IDE_Board_Manager/package_prusa3d_index.json"
  539. else
  540. BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
  541. fi
  542. BOARD_FILENAME="prusa3dboards"
  543. if [ "$ARDUINO_ENV" == "1.8.19" ]; then
  544. BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/devel/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  545. #BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/devel/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  546. else
  547. BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-$BOARD_VERSION.tar.bz2"
  548. fi
  549. #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"
  550. if [[ "$BOARD_VERSION" == "1.0.3" || "$BOARD_VERSION" == "1.0.2" || "$BOARD_VERSION" == "1.0.1" ]]; then
  551. PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip"
  552. fi
  553. LIB="PrusaLibrary"
  554. }
  555. #### End: Set build environment
  556. #### Start: List few useful data
  557. output_useful_data()
  558. {
  559. echo
  560. echo "Script path :" $SCRIPT_PATH
  561. echo "OS :" $OS
  562. echo "OS type :" $TARGET_OS
  563. echo ""
  564. echo "Arduino IDE :" $ARDUINO_ENV
  565. echo "Build env :" $BUILD_ENV
  566. echo "Board :" $BOARD
  567. if [ ! -z "$BOARD_FLASH" ] ; then
  568. echo "Board flash :" $BOARD_FLASH
  569. fi
  570. if [ ! -z "$BOARD_MEM" ] ; then
  571. echo "Board mem :" $BOARD_MEM
  572. fi
  573. echo "Package name:" $BOARD_PACKAGE_NAME
  574. echo "Board v. :" $BOARD_VERSION
  575. echo "Specific Lib:" $LIB
  576. echo ""
  577. }
  578. #### End: List few useful data
  579. #### Start: Prepare building environment
  580. # Start: Check if build exists and creates it if not
  581. check_create_build_folders()
  582. {
  583. if [ ! -d "../PF-build-dl" ]; then
  584. mkdir ../PF-build-dl || failures 9
  585. fi
  586. cd ../PF-build-dl || failures 10
  587. BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  588. # Check if PF-build-env-<version> exists and downloads + creates it if not
  589. # The build environment is based on the supported Arduino IDE portable version with some changes
  590. if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then
  591. echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  592. mkdir ../PF-build-env-$BUILD_ENV
  593. if [ $OUTPUT == "1" ] ; then
  594. sleep 2
  595. fi
  596. fi
  597. }
  598. # End: Check if build exists and creates it if not
  599. # Start: Download and extract supported Arduino IDE depending on OS
  600. download_prepare_arduinoIDE()
  601. {
  602. # Windows
  603. if [ $TARGET_OS == "windows" ]; then
  604. if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then
  605. echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  606. if [ $OUTPUT == "1" ] ; then
  607. sleep 2
  608. fi
  609. wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || failures 8
  610. echo "$(tput sgr 0)"
  611. fi
  612. 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
  613. echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
  614. if [ $OUTPUT == "1" ] ; then
  615. sleep 2
  616. fi
  617. unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env-$BUILD_ENV || failures 11
  618. mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
  619. echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  620. echo "$(tput sgr0)"
  621. fi
  622. fi
  623. # Linux
  624. if [ $TARGET_OS == "linux" ]; then
  625. # 32 or 64 bit version
  626. if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then
  627. echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  628. if [ $OUTPUT == "1" ] ; then
  629. sleep 2
  630. fi
  631. wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || failures 8
  632. echo "$(tput sgr 0)"
  633. fi
  634. 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
  635. echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)"
  636. if [ $OUTPUT == "1" ] ; then
  637. sleep 2
  638. fi
  639. tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env-$BUILD_ENV/ || failures 11
  640. mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
  641. echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  642. echo "$(tput sgr0)"
  643. fi
  644. fi
  645. }
  646. # End: Download and extract supported Arduino IDE depending on OS
  647. # Start: Make Arduino IDE portable
  648. portable_ArduinoIDE()
  649. {
  650. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/ ]; then
  651. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/
  652. fi
  653. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/ ]; then
  654. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable
  655. fi
  656. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/output/ ]; then
  657. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/output
  658. fi
  659. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/ ]; then
  660. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages
  661. fi
  662. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/ ]; then
  663. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook
  664. fi
  665. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/libraries/ ]; then
  666. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/sketchbook/libraries
  667. fi
  668. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/staging/ ]; then
  669. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/staging
  670. fi
  671. }
  672. # End: Make Arduino IDE portable
  673. # Start: Change Arduino IDE preferences
  674. change_ArduinoIDEpreferances()
  675. {
  676. if [ ! -e ../PF-build-env-$BUILD_ENV/Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt ]; then
  677. echo "$(tput setaf 6)Setting $ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor Arduino IDE preferences for portable GUI usage...$(tput setaf 2)"
  678. if [ $OUTPUT == "1" ] ; then
  679. sleep 2
  680. fi
  681. echo "update.check"
  682. 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
  683. echo "board"
  684. sed -i "s/board = uno/board = $BOARD/g" ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  685. echo "editor.linenumbers"
  686. 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
  687. echo "boardsmanager.additional.urls"
  688. echo "boardsmanager.additional.urls=$BOARD_URL" >>../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  689. echo "build.verbose=true" >>../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  690. echo "compiler.cache_core=false" >>../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  691. echo "compiler.warning_level=all" >>../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt
  692. echo "# Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  693. echo "$(tput sgr0)"
  694. fi
  695. }
  696. # End: Change Arduino IDE preferences
  697. # Start: Download and extract Prusa Firmware related parts
  698. download_prepare_Prusa_build_files()
  699. {
  700. # Download and extract PrusaResearchRambo board
  701. if [ ! -f "$BOARD_FILENAME-$BOARD_VERSION.tar.bz2" ]; then
  702. echo "$(tput setaf 6)Downloading Prusa Research AVR MK3 RAMBo EINSy build environment...$(tput setaf 2)"
  703. if [ $OUTPUT == "1" ] ; then
  704. sleep 2
  705. fi
  706. wget $BOARD_FILE_URL || failures 8
  707. fi
  708. 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
  709. echo "$(tput setaf 6)Unzipping $BOARD_PACKAGE_NAME Arduino IDE portable...$(tput setaf 2)"
  710. if [ $OUTPUT == "1" ] ; then
  711. sleep 2
  712. fi
  713. tar -xvf $BOARD_FILENAME-$BOARD_VERSION.tar.bz2 -C ../PF-build-env-$BUILD_ENV/ || failures 11
  714. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME ]; then
  715. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME
  716. fi
  717. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME ]; then
  718. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME
  719. fi
  720. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware ]; then
  721. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware
  722. fi
  723. if [ ! -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr ]; then
  724. mkdir ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr
  725. fi
  726. 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
  727. echo "# $BOARD_FILENAME-$BOARD_VERSION" >> ../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
  728. echo "$(tput sgr 0)"
  729. fi
  730. # Download and extract Prusa Firmware specific library files
  731. if [[ "$BOARD_VERSION" == "1.0.3" || "$BOARD_VERSION" == "1.0.2" || "$BOARD_VERSION" == "1.0.1" ]]; then
  732. if [ ! -f "PF-build-env-WinLin-$BUILD_ENV.zip" ]; then
  733. echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)"
  734. if [ $OUTPUT == "1" ] ; then
  735. sleep 2
  736. fi
  737. wget $PF_BUILD_FILE_URL || failures 8
  738. echo "$(tput sgr 0)"
  739. fi
  740. if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]; then
  741. echo "$(tput setaf 6)Unzipping Prusa Firmware build environment...$(tput setaf 2)"
  742. if [ $OUTPUT == "1" ] ; then
  743. sleep 2
  744. fi
  745. unzip -o PF-build-env-WinLin-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor || failures 11
  746. 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
  747. echo "$(tput sgr0)"
  748. fi
  749. fi
  750. }
  751. # End: Download and extract Prusa Firmware related parts
  752. # Start: Check if User updated Arduino IDE 1.8.5 boardsmanager and tools
  753. check_ArduinoIDE_User_interaction()
  754. {
  755. if [ -d "../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/portable/packages/arduino/tools" ]; then
  756. echo "$(tput setaf 6)Arduino IDE boards / tools have been manually updated...$"
  757. echo "Please don't update the 'Arduino AVR boards' as this will prevent running this script (tput setaf 2)"
  758. if [ $OUTPUT == "1" ] ; then
  759. sleep 2
  760. fi
  761. fi
  762. 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
  763. echo "$(tput setaf 6)PrusaReasearch compatible tools have been manually updated...$(tput setaf 2)"
  764. if [ $OUTPUT == "1" ] ; then
  765. sleep 2
  766. fi
  767. echo "$(tput setaf 6)Copying Prusa Firmware build environment to manually updated boards / tools...$(tput setaf 2)"
  768. if [ $OUTPUT == "1" ] ; then
  769. sleep 2
  770. fi
  771. 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
  772. 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
  773. echo "$(tput sgr0)"
  774. fi
  775. 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
  776. echo "$(tput setaf 1)Arduino IDE tools have been updated manually to a non supported version!!!"
  777. echo "Delete ../PF-build-env-$BUILD_ENV and start the script again"
  778. echo "Script will not continue until this have been fixed $(tput setaf 2)"
  779. if [ $OUTPUT == "1" ] ; then
  780. sleep 2
  781. fi
  782. echo "$(tput sgr0)"
  783. failures 4
  784. fi
  785. }
  786. # End: Check if User updated Arduino IDE 1.8.5 boardsmanager and tools
  787. #
  788. #### End: prepare bash / Linux environment
  789. #### End prepare building
  790. #### Start: Getting arguments for command line compiling
  791. get_arguments()
  792. {
  793. # Check if git is available
  794. if type git > /dev/null; then
  795. git_available="1"
  796. fi
  797. #
  798. # '-v' argument defines which variant of the Prusa Firmware will be compiled
  799. if [ -z "$variant_flag" ] ; then
  800. # Select which variant of the Prusa Firmware will be compiled, like
  801. PS3="Select a variant: "
  802. while IFS= read -r -d $'\0' f; do
  803. options[i++]="$f"
  804. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  805. IFS=$'\n' sorted=($(sort -n <<<"${options[*]}")); unset IFS
  806. select opt in "${sorted[@]}" "All" "Quit"; do
  807. case $opt in
  808. *.h)
  809. VARIANT=$(basename "$opt" ".h")
  810. VARIANTS[i++]="$opt"
  811. break
  812. ;;
  813. "All")
  814. VARIANT="All"
  815. VARIANTS=${options[*]}
  816. variant_flag="All"
  817. break
  818. ;;
  819. "Quit")
  820. echo "You chose to stop"
  821. failures 20
  822. ;;
  823. *)
  824. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  825. ;;
  826. esac
  827. done
  828. else
  829. if [ -f "$SCRIPT_PATH/Firmware/variants/$variant_flag" ] ; then
  830. VARIANTS=$variant_flag
  831. elif [ "$variant_flag" == "All" ] ; then
  832. while IFS= read -r -d $'\0' f; do
  833. options[i++]="$f"
  834. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  835. VARIANT="All"
  836. VARIANTS=${options[*]}
  837. else
  838. echo "$(tput setaf 1)Argument $variant_flag could not be found in Firmware/variants please choose a valid one.$(tput sgr0)"
  839. echo "Only $(tput setaf 2)'All'$(tput sgr0) and file names below are allowed as variant '-v' argument.$(tput setaf 2)"
  840. ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename
  841. echo "$(tput sgr0)"
  842. failures 4
  843. fi
  844. fi
  845. #'-l' argument defines if it is an English only version. Known values EN_FARM / ALL
  846. #Check default language mode
  847. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  848. if [ -z "$language_flag" ] ; then
  849. PS3="Select a language: "
  850. echo
  851. echo "Which lang-build do you want?"
  852. select yn in "Multi languages" "English only"; do
  853. case $yn in
  854. "Multi languages")
  855. LANGUAGES="ALL"
  856. break
  857. ;;
  858. "English only")
  859. LANGUAGES="EN_FARM"
  860. break
  861. ;;
  862. *)
  863. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  864. ;;
  865. esac
  866. done
  867. else
  868. if [[ "$language_flag" == "ALL" || "$language_flag" == "EN_FARM" ]] ; then
  869. LANGUAGES=$language_flag
  870. else
  871. echo "$(tput setaf 1)Language argument is wrong!$(tput sgr0)"
  872. echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_FARM'$(tput sgr0) are allowed as language '-l' argument!"
  873. failures 5
  874. fi
  875. fi
  876. #Check if DEV_STATUS is selected via argument '-d'
  877. if [ ! -z "$devel_flag" ] ; then
  878. if [[ "$devel_flag" == "GOLD" || "$devel_flag" == "RC" || "$devel_flag" == "BETA" || "$devel_flag" == "ALPHA" || "$devel_flag" == "DEVEL" || "$devel_flag" == "DEBUG" || "$devel_flag" == "UNKNOWN" ]] ; then
  879. DEV_STATUS_SELECTED=$devel_flag
  880. elif [[ "$devel_flag" == "atmega404" || "$devel_flag" == "atmega404_no_bootloader" ]] ; then
  881. MK404_DEBUG=$devel_flag
  882. else
  883. echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)"
  884. echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL', 'DEBUG' or 'UNKNOWN' $(tput sgr0) are allowed as devel '-d' argument!$(tput sgr0)"
  885. failures 5
  886. fi
  887. fi
  888. #Check if Build is selected via argument '-b'
  889. if [ ! -z "$build_flag" ] ; then
  890. if [[ "$build_flag" == "Auto" && "$git_available" == "1" ]] ; then
  891. BUILD=$(git rev-list --count HEAD)
  892. elif [[ $build_flag =~ ^[0-9]+$ ]] ; then
  893. BUILD=$build_flag
  894. else
  895. echo "$(tput setaf 1)Build number argument is wrong!$(tput sgr0)"
  896. echo "Only $(tput setaf 2)'Auto' (git needed) or numbers $(tput sgr0) are allowed as build '-b' argument!$(tput sgr0)"
  897. failures 5
  898. fi
  899. fi
  900. #Check git branch has changed
  901. if [ ! -z "git_available" ]; then
  902. BRANCH=$(git branch --show-current)
  903. echo "Current branch is:" $BRANCH
  904. if [ ! -f "$SCRIPT_PATH/../PF-build.branch" ]; then
  905. #echo "$BRANCH" >| $SCRIPT_PATH/../PF-build.branch
  906. echo "created PF-build.branch file"
  907. else
  908. PRE_BRANCH=$(cat "$SCRIPT_PATH/../PF-build.branch")
  909. #echo "Previous branch was:" $PRE_BRANCH
  910. if [ ! "$BRANCH" == "$PRE_BRANCH" ] ; then
  911. CLEAN_PF_FW_BUILD=1
  912. echo "$BRANCH" >| $SCRIPT_PATH/../PF-build.branch
  913. fi
  914. fi
  915. else
  916. BRANCH=""
  917. CLEAN_PF_FW_BUILD=0
  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. FW_FLAVREV=$(grep --max-count=1 "//#define FW_FLAVERSION\b" $SCRIPT_PATH/Firmware/Configuration.h|cut -d ' ' -f1)
  975. if [[ "$FW_FLAV" == "//#define" && -z $FW_FLAVREV ]];then
  976. failures 26
  977. fi
  978. #echo "FLAV:$FW_FLAV"
  979. if [[ "$FW_FLAV" != "//#define" ]] ; then
  980. FW_FLAVOR=$(grep --max-count=1 "\bFW_FLAVOR\b" $SCRIPT_PATH/Firmware/Configuration.h| sed -e's/ */ /g'|cut -d ' ' -f3)
  981. #echo "FLAVOR:$FW_FLAVOR"
  982. if [[ "$FW_FLAVREV" != "//#define" ]] ; then
  983. FW_FLAVERSION=$(grep --max-count=1 "\bFW_FLAVERSION\b" $SCRIPT_PATH/Firmware/Configuration.h| sed -e's/ */ /g'|cut -d ' ' -f3)
  984. FW="$FW-$FW_FLAVOR"
  985. DEV_CHECK="$FW_FLAVOR"
  986. echo "DEV:$DEV_CHECK"
  987. if [ ! -z "$FW_FLAVERSION" ] ; then
  988. FW="$FW$FW_FLAVERSION"
  989. fi
  990. else
  991. failures 26
  992. fi
  993. fi
  994. #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)
  995. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  996. if [[ "$DEV_CHECK" == *"RC"* ]] ; then
  997. DEV_STATUS="RC"
  998. elif [[ "$DEV_CHECK" == *"ALPHA"* ]]; then
  999. DEV_STATUS="ALPHA"
  1000. elif [[ "$DEV_CHECK" == *"BETA"* ]]; then
  1001. DEV_STATUS="BETA"
  1002. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  1003. DEV_STATUS="DEVEL"
  1004. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  1005. DEV_STATUS="DEBUG"
  1006. else
  1007. DEV_STATUS="UNKNOWN"
  1008. echo
  1009. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  1010. PS3="Select YES only if source code is tested and trusted: "
  1011. select yn in "Yes" "No"; do
  1012. case $yn in
  1013. Yes)
  1014. DEV_STATUS="GOLD"
  1015. DEV_STATUS_SELECTED="GOLD"
  1016. break
  1017. ;;
  1018. No)
  1019. DEV_STATUS="UNKNOWN"
  1020. DEV_STATUS_SELECTED="UNKNOWN"
  1021. break
  1022. ;;
  1023. *)
  1024. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  1025. ;;
  1026. esac
  1027. done
  1028. fi
  1029. else
  1030. DEV_STATUS=$DEV_STATUS_SELECTED
  1031. fi
  1032. }
  1033. #### End: Prepare code for compiling
  1034. prepare_hex_folders()
  1035. {
  1036. if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  1037. mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD || failures 9
  1038. fi
  1039. OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD"
  1040. if [ "$BOARD" != "prusa_einsy_rambo" ]; then
  1041. if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD" ]; then
  1042. mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD || failures 9
  1043. fi
  1044. OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$BOARD"
  1045. fi
  1046. #Define OUTPUT_FILENAME
  1047. OUTPUT_FILENAME=FW$FW-Build$BUILD-$VARIANT
  1048. #Check for OUTPUT_FILENAME_SUFFIX and add it
  1049. if [ ! -z $OUTPUT_FILENAME_SUFFIX ]; then
  1050. OUTPUT_FILENAME="${OUTPUT_FILENAME}$OUTPUT_FILENAME_SUFFIX"
  1051. fi
  1052. #Check if exactly the same hexfile already exists
  1053. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex" && "$LANGUAGES" == "ALL" ]]; then
  1054. echo ""
  1055. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex | xargs -n1 basename
  1056. 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)"
  1057. if [ $OUTPUT == "1" ] ; then
  1058. read -t 10 -p "Press Enter to continue..."
  1059. fi
  1060. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex" && "$LANGUAGES" == "EN_FARM" ]]; then
  1061. echo ""
  1062. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex | xargs -n1 basename
  1063. 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)"
  1064. if [ $OUTPUT == "1" ] ; then
  1065. read -t 10 -p "Press Enter to continue..."
  1066. fi
  1067. fi
  1068. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip" && "$LANGUAGES" == "ALL" ]]; then
  1069. echo ""
  1070. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip | xargs -n1 basename
  1071. 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)"
  1072. if [ $OUTPUT == "1" ] ; then
  1073. read -t 10 -p "Press Enter to continue..."
  1074. fi
  1075. fi
  1076. }
  1077. #### End: Prepare hex files folder
  1078. #### Start: List usefull data
  1079. list_usefull_data()
  1080. {
  1081. echo "$(tput setaf 2)$(tput setab 7) "
  1082. echo "Printer :" $MK404_PRINTER
  1083. echo "Variant :" $VARIANT
  1084. echo "Firmware :" $FW
  1085. echo "Build # :" $BUILD
  1086. echo "Dev Check :" $DEV_CHECK
  1087. echo "DEV Status :" $DEV_STATUS
  1088. echo "Motherboard :" $MOTHERBOARD
  1089. echo "Board flash :" $BOARD_FLASH
  1090. echo "Board mem :" $BOARD_MEM
  1091. echo "Languages :" $LANGUAGES
  1092. echo "Hex-file Folder:" $OUTPUT_FOLDER
  1093. echo "Hex filename :" $OUTPUT_FILENAME
  1094. echo "$(tput sgr0)"
  1095. }
  1096. #### End: List usefull data
  1097. #### Start: Prepare Firmware to be compiled
  1098. prepare_variant_for_compiling()
  1099. {
  1100. # Copy variant as Configuration_prusa.h
  1101. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  1102. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 12
  1103. else
  1104. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  1105. if [ $OUTPUT == "1" ] ; then
  1106. read -t 10 -p "Press Enter to continue..."
  1107. fi
  1108. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 12
  1109. fi
  1110. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  1111. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_.*/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  1112. # set FW_REPOSITORY
  1113. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  1114. #Prepare English only or multi-language version to be build
  1115. if [ $LANGUAGES == "EN_FARM" ]; then
  1116. echo " "
  1117. echo "English only language firmware will be built"
  1118. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  1119. echo " "
  1120. else
  1121. echo " "
  1122. echo "Multi-language firmware will be built"
  1123. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  1124. echo " "
  1125. fi
  1126. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  1127. #if [ $TARGET_OS == "windows" ]; then
  1128. #RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
  1129. #fi
  1130. #New fresh PF-Firmware-build
  1131. if [ "$new_build_flag" == "1" ]; then
  1132. rm -r -f $BUILD_PATH/* || failures 13
  1133. fi
  1134. }
  1135. #### End: Prepare Firmware to be compiled
  1136. #### End of Prepare building
  1137. #### Start: Compiling EN Prusa Firmware
  1138. compile_en_firmware()
  1139. {
  1140. ## Check board mem size
  1141. 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')
  1142. if [ $CURRENT_BOARD_MEM != "0x21FF" ] ; then
  1143. echo "$(tput setaf 1)Board mem has been modified or not reset$(tput sgr 0)"
  1144. echo "Current:" $CURRENT_BOARD_MEM
  1145. PS3="Select $(tput setaf 2)Yes$(tput sgr 0) if you want to reset it."
  1146. select yn in "Yes" "No"; do
  1147. case $yn in
  1148. Yes)
  1149. echo "Resetting board mem size"
  1150. sed -i -- "s/^#define RAMEND .*$/#define RAMEND 0x21FF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1151. BOARD_MEM_MODIFIED=0
  1152. break
  1153. ;;
  1154. *)
  1155. echo "Continuing with modified mem size"
  1156. BOARD_MEM_MODIFIED=1
  1157. break
  1158. ;;
  1159. esac
  1160. done
  1161. else
  1162. BOARD_MEM_MODIFIED=0
  1163. fi
  1164. ## Modify board mem size
  1165. if [[ ! -z $BOARD_MEM && "$BOARD_MEM" != "0x21FF" ]] ; then
  1166. echo "$(tput setaf 3)Modifying board memory size (hex):$(tput sgr 0)"
  1167. echo "Old:" $CURRENT_BOARD_MEM
  1168. echo "New:" $BOARD_MEM
  1169. read -t 5 -p "To cancel press $(tput setaf 1)CRTL+C$(tput sgr 0)"
  1170. echo ""
  1171. sed -i -- "s/^#define RAMEND 0x21FF/#define RAMEND ${BOARD_MEM}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1172. BOARD_MEM_MODIFIED=1
  1173. fi
  1174. ## Check board flash size
  1175. 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')
  1176. 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')
  1177. if [[ $CURRENT_BOARD_FLASH != "0x3FFFF" || $CURRENT_BOARD_maximum_size != "253952" ]] ; then
  1178. echo "$(tput setaf 1)Board flash has been modified or not reset$(tput sgr 0)"
  1179. echo "Current flash size:" $CURRENT_BOARD_FLASH
  1180. echo "Current max. size:" $CURRENT_BOARD_maximum_size
  1181. PS3="Select $(tput setaf 2)Yes$(tput sgr 0) if you want to reset it."
  1182. select yn in "Yes" "No"; do
  1183. case $yn in
  1184. Yes)
  1185. echo "$(tput setaf 1)Resetting board flash size$(tput sgr 0)"
  1186. sed -i -- "s/^#define FLASHEND .*$/#define FLASHEND 0x3FFFF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1187. 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
  1188. BOARD_FLASH_MODIFIED=0
  1189. break
  1190. ;;
  1191. *)
  1192. echo "$(tput setaf 3)Continuing with modified flash size$(tput sgr 0)"
  1193. BOARD_FLASH_MODIFIED=1
  1194. break
  1195. ;;
  1196. esac
  1197. done
  1198. else
  1199. BOARD_FLASH_MODIFIED=1
  1200. fi
  1201. ## Modify boad flash size
  1202. if [[ ! -z $BOARD_FLASH && "$BOARD_FLASH" != "0x3FFFF" ]] ; then
  1203. echo "$(tput setaf 3)Modifying board flash size (hex):$(tput sgr 0)"
  1204. echo "Old flash size:" $CURRENT_BOARD_FLASH
  1205. echo "New flash size:" $BOARD_FLASH
  1206. echo "Old max. size:" $CURRENT_BOARD_maximum_size
  1207. echo "New max. size:" $BOARD_maximum_size
  1208. read -t 5 -p "To cancel press $(tput setaf 1)CRTL+C$(tput sgr 0)"
  1209. sed -i -- "s/^#define FLASHEND .*/#define FLASHEND ${BOARD_FLASH}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1210. 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
  1211. BOARD_FLASH_MODIFIED=1
  1212. fi
  1213. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  1214. # if [ $TARGET_OS == "windows" ]; then
  1215. # RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
  1216. # fi
  1217. #### End of Prepare building
  1218. #### Start building
  1219. export ARDUINO=$BUILD_ENV_PATH
  1220. #echo $BUILD_ENV_PATH
  1221. #export BUILDER=$ARDUINO/arduino-builder
  1222. echo
  1223. #read -t 5 -p "Press Enter..."
  1224. echo
  1225. echo "Start to build Prusa Firmware ..."
  1226. echo "Using variant $VARIANT$(tput setaf 3)"
  1227. if [ $OUTPUT == "1" ] ; then
  1228. sleep 2
  1229. fi
  1230. if [ $verbose_IDE == "1" ]; then
  1231. $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
  1232. fi
  1233. $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
  1234. }
  1235. #### End: Compiling EN Prusa Firmware
  1236. #### Start: Create and save Multi Language Prusa Firmware
  1237. create_multi_firmware()
  1238. {
  1239. #if [ $LANGUAGES == "ALL" ]; then
  1240. echo "$(tput setaf 2)"
  1241. echo "Building multi language firmware" $MULTI_LANGUAGE_CHECK
  1242. echo "$(tput sgr 0)"
  1243. if [ $OUTPUT == "1" ] ; then
  1244. sleep 2
  1245. fi
  1246. cd $SCRIPT_PATH/lang
  1247. echo "$(tput setaf 3)"
  1248. ./config.sh || failures 25
  1249. echo "$(tput sgr 0)"
  1250. # Check if previous languages and firmware build exist and if so clean them up
  1251. if [ -f "lang_en.tmp" ]; then
  1252. echo ""
  1253. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  1254. if [ $OUTPUT == "1" ] ; then
  1255. read -t 10 -p "Press Enter to continue..."
  1256. fi
  1257. echo "$(tput setaf 3)"
  1258. ./lang-clean.sh
  1259. echo "$(tput sgr 0)"
  1260. fi
  1261. if [ -f "progmem.out" ]; then
  1262. echo ""
  1263. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  1264. if [ $OUTPUT == "1" ] ; then
  1265. read -t 10 -p "Press Enter to continue..."
  1266. fi
  1267. echo "$(tput setaf 3)"
  1268. ./fw-clean.sh
  1269. echo "$(tput sgr 0)"
  1270. fi
  1271. # Combine compiled firmware with languages
  1272. echo "$(tput setaf 3)"
  1273. ./fw-build.sh || failures 25
  1274. echo "$(tput sgr 0)"
  1275. # Check if the motherboard is an EINSY and if so only one hex file will generated
  1276. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  1277. # If the motherboard is an EINSY just copy one hexfile
  1278. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  1279. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to PF-build-hex folder$(tput sgr 0)"
  1280. # End of "lang.bin" for MK3 and MK3S copy
  1281. cp -f Firmware-intl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex
  1282. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.elf
  1283. else
  1284. #Search for created firmware languages
  1285. langs=$(find Firmware-intl-en_*.hex | cut -d "_" -f2 | cut -d "." -f1)
  1286. #Copy found firmware_*.hex files
  1287. for la in $langs; do
  1288. cp -f Firmware-intl-en_$la.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-$la.hex
  1289. done
  1290. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.elf
  1291. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to PF-build-hex folder$(tput sgr 0)"
  1292. if [ $TARGET_OS == "windows" ]; then
  1293. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1294. #rm $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1295. elif [ $TARGET_OS == "linux" ]; then
  1296. zip -j ../../$OUTPUT_FOLDER/$OUTPUT_FILENAME.zip ../../$OUTPUT_FOLDER/$OUTPUT_FILENAME-??.hex
  1297. fi
  1298. fi
  1299. # Cleanup after build
  1300. if [[ -z "$clean_flag" || "$clean_flag" == "0" ]]; then
  1301. echo "$(tput setaf 3)"
  1302. ./fw-clean.sh || failures 25
  1303. echo "$(tput sgr 0)"
  1304. fi
  1305. }
  1306. #### End: Create and save Multi Language Prusa Firmware
  1307. #### Start: Save EN_FARM language Prusa Firmware
  1308. save_en_firmware()
  1309. {
  1310. #else
  1311. echo "$(tput setaf 2)Copying English only firmware to PF-build-hex folder$(tput sgr 0)"
  1312. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex || failures 12
  1313. echo "$(tput setaf 2)Copying English only elf file to PF-build-hex folder$(tput sgr 0)"
  1314. cp -f $BUILD_PATH/Firmware.ino.elf $SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.elf || failures 12
  1315. #fi
  1316. }
  1317. #### End: Save EN_FARM language Prusa Firmware
  1318. #### Start: Cleanup Firmware
  1319. cleanup_firmware()
  1320. {
  1321. if [[ -z "$prusa_flag" || "$prusa_flag" == "0" ]]; then
  1322. if [ -e "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  1323. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || failures 13
  1324. fi
  1325. fi
  1326. # Delete dupblicates
  1327. if find $SCRIPT_PATH/lang/ -name '*RAMBo10a*.txt' -printf 1 -quit | grep -q 1
  1328. then
  1329. rm $SCRIPT_PATH/lang/*RAMBo10a*.txt || failures 13
  1330. fi
  1331. # MK2 not supported in this branch
  1332. if find $SCRIPT_PATH/lang/ -name '*MK2-RAMBo13a*' -printf 1 -quit | grep -q 1
  1333. then
  1334. rm $SCRIPT_PATH/lang/*MK2-RAMBo13a*.txt || failures 13
  1335. fi
  1336. if find $SCRIPT_PATH/lang/ -name 'not_tran.txt' -printf 1 -quit | grep -q 1
  1337. then
  1338. rm $SCRIPT_PATH/lang/not_tran.txt || failures 13
  1339. fi
  1340. if find $SCRIPT_PATH/lang/ -name 'not_used.txt' -printf 1 -quit | grep -q 1
  1341. then
  1342. rm $SCRIPT_PATH/lang/not_used.txt || failures 13
  1343. fi
  1344. #New fresh PF-Firmware-build
  1345. if [ "$new_build_flag" == "1" ]; then
  1346. rm -r -f $BUILD_PATH/* || failures 13
  1347. fi
  1348. # Restore files to previous state
  1349. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_.*/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  1350. sed -i -- 's/^#define FW_REPOSITORY.*/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  1351. if [ ! -z "$BUILD_ORG" ] ; then
  1352. sed -i -- "s/^#define FW_COMMIT_NR.*/#define FW_COMMIT_NR $BUILD_ORG/g" $SCRIPT_PATH/Firmware/Configuration.h
  1353. fi
  1354. echo $MULTI_LANGUAGE_CHECK
  1355. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  1356. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  1357. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  1358. if [ $OUTPUT == "1" ] ; then
  1359. sleep 2
  1360. fi
  1361. #Check for "Configuration.tmp" and delete it
  1362. if [ -e "$SCRIPT_PATH/Firmware/Configuration.tmp" ]; then
  1363. rm $SCRIPT_PATH/Firmware/Configuration.tmp
  1364. fi
  1365. #Check for "config.tmp" and delete it
  1366. if [ -e "$SCRIPT_PATH/Firmware/config.tmp" ]; then
  1367. rm $SCRIPT_PATH/Firmware/config.tmp
  1368. fi
  1369. if [ $OUTPUT == "1" ] ; then
  1370. sleep 2
  1371. fi
  1372. # Restore build env files to previous state
  1373. if [ "$BOARD_MEM_MODIFIED" == "1" ]; then
  1374. sed -i -- "s/^#define FLASHEND .*$/#define FLASHEND 0x3FFFF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1375. echo "$(tput setaf 2)Restored Board Mem$(tput sgr 0)"
  1376. fi
  1377. if [ "$BOARD_FLASH_MODIFIED" == "1" ]; then
  1378. 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
  1379. sed -i -- "s/^#define RAMEND.*/#define RAMEND 0x21FF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
  1380. echo "$(tput setaf 2)Restored Board Flash$(tput sgr 0)"
  1381. fi
  1382. }
  1383. #### End: Prepare code for compiling
  1384. #done
  1385. #### Start: Finish script
  1386. # List hex path and list build files
  1387. finish_pf-build()
  1388. {
  1389. cd $SCRIPT_PATH
  1390. cd ..
  1391. echo "$(tput setaf 2) "
  1392. echo " "
  1393. failures 0
  1394. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  1395. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  1396. echo
  1397. echo "Files:"
  1398. ls -r -h $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/*
  1399. }
  1400. #### End: Finish script
  1401. #### End: building
  1402. ####Start: MK404 Simulator
  1403. MK404_SIM()
  1404. {
  1405. cd $SCRIPT_PATH
  1406. # Check/compile MK404 sim
  1407. if [[ "$output_flag" == "1" || -z "$output_flag" ]]; then
  1408. if [[ -z "$mk404_flag" && "$variant_flag" != "All" ]]; then
  1409. echo
  1410. read -t 10 -n 1 -p "Do you want to start MK404? Y/$(tput setaf 2)n$(tput sgr 0)" mk404_start
  1411. if [[ "$mk404_start" == "Y" || "$mk404_start" == "y" ]]; then
  1412. echo
  1413. 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
  1414. if [ "$mk404_choose1" == "1" ]; then
  1415. mk404_flag=1
  1416. elif [ "$mk404_choose1" == "2" ]; then
  1417. mk404_flag=2
  1418. else
  1419. mk404_flag=1 #default
  1420. fi
  1421. echo
  1422. echo "Choose MK404 graphics"
  1423. echo "0 = no graphics"
  1424. echo "1 = lite"
  1425. echo "2 = fancy"
  1426. echo "3 = lite with Quad_HR"
  1427. echo "4 = fancy lite with Quad_HR"
  1428. read -t 10 -n 1 -p "Which one do you want? $(tput setaf 2)0$(tput sgr 0)/1/2/3/4" mk404_choose2
  1429. if [ "$mk404_choose2" == "1" ]; then
  1430. mk404_graphics_flag=1
  1431. elif [ "$mk404_choose2" == "2" ]; then
  1432. mk404_graphics_flag=2
  1433. elif [ "$mk404_choose2" == "3" ]; then
  1434. mk404_graphics_flag=3
  1435. elif [ "$mk404_choose2" == "4" ]; then
  1436. mk404_graphics_flag=4
  1437. elif [ "$mk404_choose2" == "0" ]; then
  1438. mk404_graphics_flag=""
  1439. else
  1440. mk404_graphics_flag="" #default
  1441. fi
  1442. fi
  1443. echo
  1444. fi
  1445. fi
  1446. # For MMU2S
  1447. if [[ "$mk404_flag" == "2" || "$mk404_flag" == "MMU2" || "$mk404_flag" == "MMU2S" ]]; then # Check if MMU2 is selected only for MK3/S
  1448. mk404_flag=2
  1449. fi
  1450. if [[ ! -z "$mk404_flag" && "$variant_flag" != "All " ]]; then
  1451. # Run MK404 with 'debugcore' and/or 'bootloader-file'
  1452. if [ ! -z "$board_mem_flag" ]; then
  1453. MK404_options="-x $board_mem_flag"
  1454. fi
  1455. if [ ! -z "$board_flash_flag" ]; then
  1456. MK404_options="${MK404_options} -y $board_flash_flag"
  1457. fi
  1458. # Run MK404 with graphics
  1459. if [ ! -z "$mk404_graphics_flag" ]; then
  1460. if [[ "$mk404_graphics_flag" == "1" || "$mk404_graphics_flag" == "2" || "$mk404_graphics_flag" == "3" || "$mk404_graphics_flag" == "4" ]]; then
  1461. MK404_options="${MK404_options} -g $mk404_graphics_flag"
  1462. else
  1463. echo "$(tput setaf 1)Unsupported MK404 graphics option $mk404_graphics_flag$(tput sgr 0)"
  1464. fi
  1465. fi
  1466. # Output some useful data
  1467. echo "Printer: $MK404_PRINTER"
  1468. echo "Options: $MK404_options"
  1469. echo ""
  1470. #read -t 5 -p "Press $(tput setaf 2)Enter$(tput sgr 0) to start MK404"
  1471. echo ""
  1472. # Change to MK404 build folder
  1473. #cd ../MK404/master/build
  1474. #Decide which hex file to use EN_FARM or Multi language
  1475. if [ "$LANGUAGES" == "ALL" ]; then
  1476. if [[ "$MK404_PRINTER" == "MK3" || "$MK404_PRINTER" == "MK3S" ]]; then
  1477. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME.hex
  1478. else
  1479. PS3="Select a language:"
  1480. select lan in ${langs[@]}
  1481. do
  1482. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-$lan.hex
  1483. break
  1484. done
  1485. fi
  1486. else
  1487. MK404_firmware_file=$SCRIPT_PATH/../$OUTPUT_FOLDER/$OUTPUT_FILENAME-EN_FARM.hex
  1488. fi
  1489. # Start MK404
  1490. # default with serial output and terminal to manipulate it via terminal
  1491. #echo ""
  1492. #echo "./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options -f $MK404_firmware_file"
  1493. #sleep 5
  1494. #./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options -f $MK404_firmware_file || exit 62
  1495. echo ""
  1496. echo "./MK404-build.sh -m $mk404_flag -p $MK404_PRINTER $MK404_options -f $MK404_firmware_file"
  1497. if [ $OUTPUT == "1" ] ; then
  1498. sleep 2
  1499. fi
  1500. ./MK404-build.sh -m $mk404_flag -p $MK404_PRINTER $MK404_options -f $MK404_firmware_file|| failures 25
  1501. fi
  1502. }
  1503. #### End: MK404 Simulator
  1504. #### Check OS and needed apps
  1505. echo "Check OS"
  1506. check_OS
  1507. check_wget
  1508. check_zip
  1509. check_python
  1510. check_gawk
  1511. #### Check for options/flags
  1512. echo "Check for options"
  1513. #### Prepare build environment
  1514. echo "Prepare build env"
  1515. get_arguments
  1516. set_build_env_variables
  1517. output_useful_data
  1518. check_create_build_folders
  1519. #### Download/set needed apps and dependencies
  1520. download_prepare_arduinoIDE
  1521. portable_ArduinoIDE
  1522. change_ArduinoIDEpreferances
  1523. download_prepare_Prusa_build_files
  1524. check_ArduinoIDE_User_interaction
  1525. #### Start
  1526. set_paths
  1527. check_branch_changed
  1528. for v in ${VARIANTS[*]}
  1529. do
  1530. check_script_failed_nr1
  1531. check_script_failed_nr2
  1532. make_backup1
  1533. make_backup2
  1534. prepare_code_for_compiling
  1535. prepare_hex_folders
  1536. list_usefull_data
  1537. prepare_variant_for_compiling
  1538. compile_en_firmware
  1539. if [ $LANGUAGES == "ALL" ]; then
  1540. create_multi_firmware
  1541. else
  1542. save_en_firmware
  1543. fi
  1544. cleanup_firmware
  1545. done
  1546. finish_pf-build
  1547. if [ $TARGET_OS == "linux" ]; then
  1548. MK404_SIM
  1549. fi