PF-build.sh 74 KB

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