PF-build.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #!/bin/bash
  2. # This bash script is used to compile automatically the Prusa firmware with a dedecated build enviroment and settings
  3. #
  4. # Supported OS: Windows 10, Linux64 bit
  5. #
  6. # Linux:
  7. #
  8. # Windows:
  9. # To excecute this sciprt you gonna need few things on your Windows machine
  10. #
  11. # Linux Subsystem Ubuntu
  12. # 1. Follow these instructions
  13. # 2. Open Ubuntu bash and get latest updates with 'apt-get upgate'
  14. # 3. Install zip with 'apt-get install zip'
  15. # 4. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc'
  16. #
  17. # export OS="Linux"
  18. # export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true"
  19. # export GPG_TTY=$(tty)
  20. #
  21. # and confirm them. Restart Ubuntu bash
  22. #
  23. # Or GIT-BASH
  24. # 1. Download and install the correct (64bit or 32bit) Git version https://git-scm.com/download/win
  25. # 2. Also follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
  26. # 3. Download and install 7z-zip from its official website.
  27. # By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case.
  28. # 4. Run git Bash under Administrator privilege and navigate to the directory /c/Program Files/Git/mingw64/bin,
  29. # you can run the command ln -s /c/Program Files/7-Zip/7z.exe zip.exe
  30. #
  31. # Usefull things to edit and compare your custom Firmware
  32. # 1. Download and install current and correct (64bit or 32bit) Notepad++ version https://notepad-plus-plus.org/download
  33. # 2. Another great tool to compare your custom mod and stock firmware is WinMerge http://winmerge.org/downloads/?lang=en
  34. #
  35. # Example for MK3: open git bash and chage to your Firmware directory
  36. # <username>@<machinename> MINGW64 /<drive>/path
  37. # bash build.sh 1_75mm_MK3-EINSy10a-E3Dv6full
  38. #
  39. # Example for MK25: open git bash and chage to your directory
  40. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware/MK3
  41. # bash build.sh 1_75mm_MK25-RAMBo13a-E3Dv6full
  42. #
  43. # The compiled hex files can be found in the folder above like from the example
  44. # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware
  45. # FW351-Build1778-1_75mm_MK25-RAMBo13a-E3Dv6full.hex
  46. #
  47. # Version: 1.0.1-Build_8
  48. # Change log:
  49. # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt'
  50. # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is uknown
  51. # 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build enviroment
  52. # 10 Feb 2019, ropaha, Pull Request, Select variant from list while using build.sh
  53. # 10 Feb 2019, ropaha, change FW_DEV_VERSION automatically depending on FW_VERSION RC/BETA/ALPHA
  54. # 10 Feb 2019, 3d-gussner, 1st tests with english only
  55. # 10 Feb 2019, ropaha, added compiling of all variants and english only
  56. # 10 Feb 2019, 3d-gussner, Set OUTPUT_FOLDER for hex files
  57. # 11 Feb 2019, 3d-gussner/ropaha, Minor changes and fixes
  58. # 11 Feb 2019, 3d-gussner, Ready for RC
  59. # 12 Feb 2019, 3d-gussner, Check if wget and zip are installed. Thanks to Bernd to point it out
  60. # 12 Feb 2019, 3d-gussner, Changed OS check to OSTYPE as it is not supported on Ubuntu
  61. # Also added different BUILD_ENV folders depending on OS used so Windows
  62. # Users can use git-bash AND Windows Linux Subsystems at the same time
  63. # Cleanup compiler flags is only depends on OS version.
  64. # 12 Feb 2019, 3d-gussner, Added additional OSTYPE check
  65. # 15 feb 2019, 3d-gussner, Added zip files for miniRAMbo multi language hex files
  66. # 15 Feb 2019, 3d-gussner, Added more checks if
  67. # Compiled Hex-files
  68. # Configuration_prusa.h
  69. # language build files
  70. # multi language firmware files exist and clean them up
  71. # 15 Feb 2019, 3d-gussner, Fixed selction GOLD/UNKNOWN DEV_STATUS for ALL variants builds, so you have to choose only once
  72. # 15 Feb 2019, 3d-gussner, Added some colored output
  73. # 15 Feb 2019, 3d-gussner, troubleshooting and minor fixes
  74. # 16 Feb 2019, 3d-gussner, Script can be run using arguments
  75. # $1 = variant, example "1_75mm_MK3-EINSy10a-E3Dv6full.h" at this moment it is not possible to use ALL
  76. # $2 = multi language OR english only [ALL/EN_ONLY]
  77. # $3 = development status [GOLD/RC/BETA/ALPHA/DEVEL/DEBUG]
  78. # If one argument is wrong a list of valid one will be shown
  79. ###Check if OSTYPE is supported
  80. if [ $OSTYPE == "msys" ]; then
  81. if [ $(uname -m) == "x86_64" ]; then
  82. echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
  83. fi
  84. elif [ $OSTYPE == "linux-gnu" ]; then
  85. if [ $(uname -m) == "x86_64" ]; then
  86. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  87. fi
  88. else
  89. echo "$(tput setaf 1)This script doesn't support your Operating system!"
  90. echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
  91. echo "Read the notes of build.sh$(tput sgr0)"
  92. exit
  93. fi
  94. sleep 2
  95. ###Prepare bash enviroment and check if wget and zip are availible
  96. if ! type wget > /dev/null; then
  97. echo "$(tput setaf 1)Missing 'wget' which is important to run this script"
  98. echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)"
  99. exit
  100. fi
  101. if ! type zip > /dev/null; then
  102. if [ $OSTYPE == "msys" ]; then
  103. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  104. echo "Download and install 7z-zip from its official website https://www.7-zip.org/"
  105. echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case."
  106. echo "Run git Bash under Administrator privilege and"
  107. echo "navigate to the directory /c/Program Files/Git/mingw64/bin,"
  108. echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)"
  109. exit
  110. elif [ $OSTYPE == "linux-gnu" ]; then
  111. echo "$(tput setaf 1)Missing 'zip' which is important to run this script"
  112. echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)"
  113. exit
  114. fi
  115. fi
  116. ###End prepare bash enviroment
  117. BUILD_ENV="1.0.1"
  118. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  119. # List few useful data
  120. echo
  121. echo "Script path:" $SCRIPT_PATH
  122. echo "OS :" $OS
  123. echo "OS type :" $OSTYPE
  124. echo ""
  125. #### Start prepare building
  126. #Check if build exists and creates it if not
  127. if [ ! -d "../build-env" ]; then
  128. mkdir ../build-env || exit 2
  129. fi
  130. cd ../build-env || exit 3
  131. # Check if PF-build-env-<version> exists and downloads + creates it if not
  132. # The build enviroment is based on the Arduino IDE 1.8.5 portal vesion with some changes
  133. if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then
  134. echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)"
  135. mkdir ../PF-build-env-$BUILD_ENV
  136. sleep 5
  137. fi
  138. if [ $OSTYPE == "msys" ]; then
  139. if [ ! -f "PF-build-env-Win-$BUILD_ENV.zip" ]; then
  140. echo "$(tput setaf 6)Downloding Windows build enviroment...$(tput setaf 2)"
  141. sleep 2
  142. wget https://github.com/3d-gussner/PF-build-env/releases/download/Win-$BUILD_ENV/PF-build-env-Win-$BUILD_ENV.zip || exit 4
  143. #cp -f ../../PF-build-env/PF-build-env-Win-$BUILD_ENV.zip PF-build-env-Win-$BUILD_ENV.zip || exit4
  144. echo "$(tput sgr 0)"
  145. fi
  146. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  147. echo "$(tput setaf 6)Unzipping Windows build enviroment...$(tput setaf 2)"
  148. sleep 2
  149. unzip PF-build-env-Win-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  150. echo "$(tput sgr0)"
  151. fi
  152. fi
  153. if [ $OSTYPE == "linux-gnu" ]; then
  154. if [ ! -f "PF-build-env-Linux64-$BUILD_ENV.zip" ]; then
  155. echo "$(tput setaf 6)Downloading Linux 64 build enviroment...$(tput setaf 2)"
  156. sleep 2
  157. wget https://github.com/mkbel/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3
  158. echo "$(tput sgr0)"
  159. fi
  160. if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then
  161. echo "$(tput setaf 6)Unzipping Linux build enviroment...$(tput setaf 2)"
  162. sleep 2
  163. unzip PF-build-env-Linux64-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4
  164. echo "$(tput sgr0)"
  165. fi
  166. fi
  167. cd $SCRIPT_PATH
  168. # First argument defines which varaint of the Prusa Firmware will be compiled
  169. if [ -z "$1" ] ; then
  170. # Select which varaint of the Prusa Firmware will be compiled, like
  171. PS3="Select a variant: "
  172. while IFS= read -r -d $'\0' f; do
  173. options[i++]="$f"
  174. done < <(find Firmware/variants/ -maxdepth 1 -type f -name "*.h" -print0 )
  175. select opt in "${options[@]}" "All" "Quit"; do
  176. case $opt in
  177. *.h)
  178. VARIANT=$(basename "$opt" ".h")
  179. VARIANTS[i++]="$opt"
  180. break
  181. ;;
  182. "All")
  183. VARIANT="All"
  184. VARIANTS=${options[*]}
  185. break
  186. ;;
  187. "Quit")
  188. echo "You chose to stop"
  189. exit 1
  190. ;;
  191. *)
  192. echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)"
  193. ;;
  194. esac
  195. done
  196. else
  197. if [ -f "$SCRIPT_PATH/Firmware/variants/$1" ] ; then
  198. VARIANTS=$1
  199. else
  200. echo "$(tput setaf 1)$1 could not be found in Firmware/variants please choose a valid one$(tput setaf 2)"
  201. ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename
  202. echo "$(tput sgr0)"
  203. exit
  204. fi
  205. fi
  206. #Second argument defines if it is an english only version. Known values EN_ONLY / ALL
  207. #Check default language mode
  208. MULTI_LANGUAGE_CHECK=$(grep --max-count=1 "^#define LANG_MODE *" $SCRIPT_PATH/Firmware/config.h|sed -e's/ */ /g'|cut -d ' ' -f3)
  209. if [ -z "$2" ] ; then
  210. PS3="Select a language: "
  211. echo
  212. echo "Which lang-build do you want?"
  213. select yn in "Multi languages" "English only"; do
  214. case $yn in
  215. "Multi languages")
  216. LANGUAGES="ALL"
  217. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE 1/g" $SCRIPT_PATH/Firmware/config.h
  218. break
  219. ;;
  220. "English only")
  221. LANGUAGES="EN_ONLY"
  222. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE 0/g" $SCRIPT_PATH/Firmware/config.h
  223. break
  224. ;;
  225. *)
  226. echo "$(tput setaf 1)This is not a valid language$(tput sgr0)"
  227. ;;
  228. esac
  229. done
  230. else
  231. if [[ "$2" == "ALL" || "$2" == "EN_ONLY" ]] ; then
  232. LANGUAGES=$2
  233. else
  234. echo "$(tput setaf 1)Language agrument is wrong!$(tput sgr0)"
  235. echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_ONLY'$(tput sgr0) are allowed as 2nd argument!"
  236. exit
  237. fi
  238. fi
  239. #Check if DEV_STATUS is selected via argument 3
  240. if [ ! -z "$3" ] ; then
  241. if [[ "$3" == "GOLD" || "$3" == "RC" || "$3" == "BETA" || "$3" == "ALPHA" || "$3" == "DEVEL" || "$3" == "DEBUG" ]] ; then
  242. DEV_STATUS_SELECTED=$3
  243. else
  244. echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)"
  245. echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL' or 'DEBUG'$(tput sgr0) are allowed as 3rd argument!$(tput sgr0)"
  246. exit
  247. fi
  248. fi
  249. #Set BUILD_ENV_PATH
  250. cd ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 5
  251. BUILD_ENV_PATH="$( pwd -P )"
  252. cd ../..
  253. #Checkif BUILD_PATH exisits and if not creates it
  254. if [ ! -d "Prusa-Firmware-build" ]; then
  255. mkdir Prusa-Firmware-build || exit 6
  256. fi
  257. #Set the BUILD_PATH for Arduino IDE
  258. cd Prusa-Firmware-build || exit 7
  259. BUILD_PATH="$( pwd -P )"
  260. for v in ${VARIANTS[*]}
  261. do
  262. VARIANT=$(basename "$v" ".h")
  263. # Find firmware version in Configuration.h file and use it to generate the hex filename
  264. FW=$(grep --max-count=1 "\bFW_VERSION\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d '"' -f2|sed 's/\.//g')
  265. # Find build version in Configuration.h file and use it to generate the hex filename
  266. BUILD=$(grep --max-count=1 "\bFW_COMMIT_NR\b" $SCRIPT_PATH/Firmware/Configuration.h | sed -e's/ */ /g'|cut -d ' ' -f3)
  267. # Check if the motherboard is an EINSY and if so the only one hex file will generated
  268. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  269. # Check development status
  270. 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)
  271. if [ -z "$DEV_STATUS_SELECTED" ] ; then
  272. if [[ "$DEV_CHECK" == "RC1" || "$DEV_CHECK" == "RC2" ]] ; then
  273. DEV_STATUS="RC"
  274. elif [[ "$DEV_CHECK" == "ALPHA" ]]; then
  275. DEV_STATUS="ALPHA"
  276. elif [[ "$DEV_CHECK" == "BETA" ]]; then
  277. DEV_STATUS="BETA"
  278. elif [[ "$DEV_CHECK" == "DEVEL" ]]; then
  279. DEV_STATUS="DEVEL"
  280. elif [[ "$DEV_CHECK" == "DEBUG" ]]; then
  281. DEV_STATUS="DEBUG"
  282. else
  283. DEV_STATUS="UNKNOWN"
  284. echo
  285. echo "$(tput setaf 5)DEV_STATUS is UNKNOWN. Do you wish to set DEV_STATUS to GOLD?$(tput sgr0)"
  286. PS3="Select YES only if source code is tested and trusted: "
  287. select yn in "Yes" "No"; do
  288. case $yn in
  289. Yes)
  290. DEV_STATUS="GOLD"
  291. DEV_STATUS_SELECTED="GOLD"
  292. break
  293. ;;
  294. No)
  295. DEV_STATUS="UNKNOWN"
  296. DEV_STATUS_SELECTED="UNKNOWN"
  297. break
  298. ;;
  299. *)
  300. echo "$(tput setaf 1)This is not a valid DEV_STATUS$(tput sgr0)"
  301. ;;
  302. esac
  303. done
  304. fi
  305. else
  306. DEV_STATUS=$DEV_STATUS_SELECTED
  307. fi
  308. #Prepare hex files folders
  309. if [ ! -d "$SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then
  310. mkdir -p $SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD || exit 10
  311. fi
  312. OUTPUT_FOLDER="Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD"
  313. #Check if exacly the same hexfile already exsits
  314. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex" && "$LANGUAGES" == "ALL" ]]; then
  315. echo ""
  316. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex | xargs -n1 basename
  317. echo "$(tput setaf 6)This hex file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  318. read -t 10 -p "Press Enter to continue..."
  319. elif [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex" && "$LANGUAGES" == "EN_ONLY" ]]; then
  320. echo ""
  321. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex | xargs -n1 basename
  322. echo "$(tput setaf 6)This hex file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  323. read -t 10 -p "Press Enter to continue..."
  324. fi
  325. if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip" && "$LANGUAGES" == "ALL" ]]; then
  326. echo ""
  327. ls -1 $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip | xargs -n1 basename
  328. echo "$(tput setaf 6)This zip file to be comiled already exsits! To cancle this process press CRTL+C and rename existing hex file.$(tput sgr 0)"
  329. read -t 10 -p "Press Enter to continue..."
  330. fi
  331. #List some useful data
  332. echo "$(tput setaf 2)$(tput setab 7) "
  333. echo "Variant :" $VARIANT
  334. echo "Firmware :" $FW
  335. echo "Build # :" $BUILD
  336. echo "Dev Check :" $DEV_CHECK
  337. echo "DEV Status :" $DEV_STATUS
  338. echo "Motherboard:" $MOTHERBOARD
  339. echo "Languages :" $LANGUAGES
  340. echo "Hex-file Folder:" $OUTPUT_FOLDER
  341. echo "$(tput sgr0)"
  342. #Prepare Firmware to be compiled by copying variant as Configuration_prusa.h
  343. if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then
  344. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  345. else
  346. echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)"
  347. read -t 10 -p "Press Enter to continue..."
  348. cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11
  349. fi
  350. #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint
  351. sed -i -- "s/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/g" $SCRIPT_PATH/Firmware/Configuration.h
  352. # set FW_REPOSITORY
  353. sed -i -- 's/#define FW_REPOSITORY "Unknown"/#define FW_REPOSITORY "Prusa3d"/g' $SCRIPT_PATH/Firmware/Configuration.h
  354. #Prepare english only or multilanguage version to be build
  355. if [ $LANGUAGES == "ALL" ]; then
  356. echo " "
  357. echo "Multi-language firmware will be build"
  358. echo " "
  359. else
  360. echo " "
  361. echo "English only language firmware will be build"
  362. echo " "
  363. fi
  364. #Check if compiler flags are set to Prusa specific needs for the rambo board.
  365. if [ $OSTYPE == "msys" ]; then
  366. RAMBO_PLATFORM_FILE="rambo/hardware/avr/1.0.1/platform.txt"
  367. COMP_FLAGS="compiler.c.elf.flags={compiler.warning_flags} -Os -g -flto -fuse-linker-plugin -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"
  368. CHECK_FLAGS=$(grep --max-count=1 "$COMP_FLAGS" $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE)
  369. if [ -z "$CHECK_FLAGS" ]; then
  370. echo "Compiler flags not found, adding flags"
  371. if [ ! -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck ]; then
  372. echo "making a backup"
  373. ls -1 $BUILD_ENV_PATH/portable/packages/rambo/hardware/avr/1.0.1/
  374. cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck
  375. fi
  376. echo $COMP_FLAGS >> $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  377. else
  378. echo "Compiler flags are set in rambo platform.txt" $CHECK_FLAGS
  379. fi
  380. fi
  381. #### End of Prepare building
  382. #### Start building
  383. export ARDUINO=$BUILD_ENV_PATH
  384. #echo $BUILD_ENV_PATH
  385. export BUILDER=$ARDUINO/arduino-builder
  386. echo
  387. #read -t 5 -p "Press Enter..."
  388. echo
  389. if [ $OSTYPE == "msys" ]; then
  390. echo "Start to build Prusa Firmware under Windows..."
  391. echo "Using variant $VARIANT$(tput setaf 3)"
  392. sleep 2
  393. #$BUILDER -dump-prefs -logger=machine -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=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 12
  394. #$BUILDER -compile -logger=machine -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=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 13
  395. $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=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=default $SCRIPT_PATH/Firmware/Firmware.ino || exit 14
  396. echo "$(tput sgr 0)"
  397. fi
  398. if [ $OSTYPE == "linux-gnu" ] ; then
  399. echo "Start to build Prusa Firmware under Linux 64..."
  400. echo "Using variant $VARIANT$(tput setaf 3)"
  401. sleep 2
  402. $BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board rambo:avr:rambo --pref build.path=$BUILD_PATH || exit 14
  403. echo "$(tput sgr 0)"
  404. fi
  405. if [ $LANGUAGES == "ALL" ]; then
  406. echo "$(tput setaf 2)"
  407. echo "Building mutli language firmware" $MULTI_LANGUAGE_CHECK
  408. echo "$(tput sgr 0)"
  409. sleep 2
  410. cd $SCRIPT_PATH/lang
  411. echo "$(tput setaf 3)"
  412. ./config.sh || exit 15
  413. echo "$(tput sgr 0)"
  414. # Check if privious languages and firmware build exist and if so clean them up
  415. if [ -f "lang_en.tmp" ]; then
  416. echo ""
  417. echo "$(tput setaf 6)Previous lang build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  418. read -t 10 -p "Press Enter to continue..."
  419. echo "$(tput setaf 3)"
  420. ./lang-clean.sh
  421. echo "$(tput sgr 0)"
  422. fi
  423. if [ -f "progmem.out" ]; then
  424. echo ""
  425. echo "$(tput setaf 6)Previous firmware build files already exist these will be cleaned up in 10 seconds.$(tput sgr 0)"
  426. read -t 10 -p "Press Enter to continue..."
  427. echo "$(tput setaf 3)"
  428. ./fw-clean.sh
  429. echo "$(tput sgr 0)"
  430. fi
  431. # build languages
  432. echo "$(tput setaf 3)"
  433. ./lang-build.sh || exit 16
  434. # Combine compiled firmware with languages
  435. ./fw-build.sh || exit 17
  436. echo "$(tput sgr 0)"
  437. # Check if the motherboard is an EINSY and if so the only one hex file will generated
  438. MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3)
  439. # If the motherboard is an EINSY just copy one hexfile
  440. if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then
  441. echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to Hex-files folder$(tput sgr 0)"
  442. cp -f firmware.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex
  443. else
  444. echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to Hex-files folder$(tput sgr 0)"
  445. cp -f firmware_cz.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-cz.hex
  446. cp -f firmware_de.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-de.hex
  447. cp -f firmware_es.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-es.hex
  448. cp -f firmware_fr.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-fr.hex
  449. cp -f firmware_it.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-it.hex
  450. cp -f firmware_pl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-pl.hex
  451. if [ $OSTYPE == "msys" ]; then
  452. zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  453. rm $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  454. elif [ $OSTYPE == "linux-gnu" ]; then
  455. zip -m -j ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex
  456. fi
  457. fi
  458. # Cleanup after build
  459. echo "$(tput setaf 3)"
  460. ./fw-clean.sh || exit 18
  461. ./lang-clean.sh || exit 19
  462. echo "$(tput sgr 0)"
  463. else
  464. echo "$(tput setaf 2)Copying English only firmware to Hex-files folder$(tput sgr 0)"
  465. cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 20
  466. fi
  467. # Cleanup Firmware
  468. rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 17
  469. sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h
  470. sed -i -- 's/^#define FW_REPOSITORY "Prusa3d"/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h
  471. echo $MULTI_LANGUAGE_CHECK
  472. #sed -i -- "s/^#define LANG_MODE * /#define LANG_MODE $MULTI_LANGUAGE_CHECK/g" $SCRIPT_PATH/Firmware/config.h
  473. sed -i -- "s/^#define LANG_MODE *1/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  474. sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE ${MULTI_LANGUAGE_CHECK}/g" $SCRIPT_PATH/Firmware/config.h
  475. sleep 5
  476. done
  477. # Cleanup compiler flags are set to Prusa specific needs for the rambo board.
  478. #if [ $OSTYPE == "msys" ]; then
  479. # echo " "
  480. # echo "Restore Windows platform.txt"
  481. # echo " "
  482. # cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE
  483. #fi
  484. # Switch to hex path and list build files
  485. cd $SCRIPT_PATH
  486. cd ..
  487. echo "$(tput setaf 2) "
  488. echo " "
  489. echo "Build done, please use Slic3rPE > 1.41.0 to upload the firmware"
  490. echo "more information how to flash firmware https://www.prusa3d.com/drivers/ $(tput sgr 0)"
  491. #### End building