Browse Source

Hack to get more flash and ram for MK404 debug

3d-gussner 3 years ago
parent
commit
f8bec339e2
1 changed files with 196 additions and 72 deletions
  1. 196 72
      PF-build.sh

+ 196 - 72
PF-build.sh

@@ -244,17 +244,121 @@ fi
 
 
 #### End prepare bash / Linux environment
 #### End prepare bash / Linux environment
 
 
+# Check for options/flags
+while getopts v:l:d:b:f:x:r:o:c:p:n:?h flag
+	do
+	    case "${flag}" in
+	        v) variant_flag=${OPTARG};;
+	        l) language_flag=${OPTARG};;
+	        d) devel_flag=${OPTARG};;
+			b) build_flag=${OPTARG};;
+            f) board_flash_flag=${OPTARG};;
+            x) board_mem_flag=${OPTARG};;
+			o) output_flag=${OPTARG};;
+			c) clean_flag=${OPTARG};;
+			p) prusa_flag=${OPTARG};;
+			n) new_build_flag=${OPTARG};;
+			?) help_flag=1;;
+			h) help_flag=1;;
+	    esac
+	done
+#echo "variant_flag: $variant_flag";
+#echo "language_flag: $language_flag";
+#echo "devel_flag: $devel_flag";
+#echo "build_flag: $build_flag";
+#echo "output_flag: $output_flag";
+#echo "board_mem_flag: $board_mem_flag";
+#echo "board_flash_flag: $board_flash_flag";
+#echo "help_flag: $help_flag"
+#echo "clean_flag: $clean_flag"
+#echo "prusa_flag: $prusa_flag"
+#echo "new_build_flag: $new_build_flag"
+
+#
+# '?' 'h' argument usage and help
+if [ "$help_flag" == "1" ] ; then
+echo "***************************************"
+echo "* PF-build.sh Version: 1.0.6-Build_33 *"
+echo "***************************************"
+echo "Arguments:"
+echo "$(tput setaf 2)-v$(tput sgr0) Variant '$(tput setaf 2)All$(tput sgr0)' or variant file name"
+echo "$(tput setaf 2)-l$(tput sgr0) Languages '$(tput setaf 2)ALL$(tput sgr0)' for multi language or '$(tput setaf 2)EN_ONLY$(tput sgr0)' for English only"
+echo "$(tput setaf 2)-d$(tput sgr0) Devel build '$(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)'"
+echo "$(tput setaf 2)-b$(tput sgr0) Build/commit number '$(tput setaf 2)Auto$(tput sgr0)' needs git or a number"
+echo "$(tput setaf 2)-o$(tput sgr0) Output '$(tput setaf 2)1$(tput sgr0)' force or '$(tput setaf 2)0$(tput sgr0)' block output and delays"
+echo "$(tput setaf 2)-c$(tput sgr0) Do not clean up lang build'$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
+echo "$(tput setaf 2)-p$(tput sgr0) Keep Configuration_prusa.h '$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
+echo "$(tput setaf 2)-n$(tput sgr0) New fresh build '$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
+echo "$(tput setaf 2)-?$(tput sgr0) Help"
+echo "$(tput setaf 2)-h$(tput sgr0) Help"
+echo 
+echo "Brief USAGE:"
+echo "  $(tput setaf 2)./PF-build.sh$(tput sgr0)  [-v] [-l] [-d] [-b] [-o] [-c] [-p] [-n]"
+echo
+echo "Example:"
+echo "  $(tput setaf 2)./PF-build.sh -v All -l ALL -d GOLD$(tput sgr0)"
+echo "  Will build all variants as multi language and final GOLD version"
+echo
+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)"
+echo "  Will build MK3S multi language final GOLD firmware "
+echo "  with current commit count number and output extra information,"
+echo "  not delete lang build temporary files, keep Configuration_prusa.h and build with new fresh build folder."
+echo
+exit 6
+
+fi
+#Check if Build is selected with argument '-f'
+if [ ! -z "$board_flash_flag" ] ; then
+	if [ "$board_flash_flag" == "256" ] ; then
+        BOARD_FLASH="0x3FFFF"
+        BOARD_maximum_size="253952"
+		echo "Board flash size :   $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
+	elif [ "$board_flash_flag" == "384" ] ; then
+        BOARD_FLASH="0x5FFFF"
+        BOARD_maximum_size="385024"
+		echo "Board flash size :   $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
+	elif [ "$board_flash_flag" == "512" ] ; then
+        BOARD_FLASH="0x7FFFF"
+        BOARD_maximum_size="516096"
+		echo "Board flash size :   $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
+	elif [ "$board_flash_flag" == "1024" ] ; then
+        BOARD_FLASH="0xFFFFF"
+        BOARD_maximum_size="1040384"
+		echo "Board flash size :   $board_flash_flag Kb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
+	elif [[ "$board_flash_flag" == "32M" || "$board_flash_flag" == "32768" ]] ; then
+        BOARD_FLASH="0x1FFFFFF"
+        BOARD_maximum_size="33546240"
+		echo "Board flash size :    32 Mb, $BOARD_maximum_size bytes, $BOARD_FLASH (hex)"
+	else
+		echo "Unsupported board flash size chosen. Only '256', '384', '512', '1024' and '32M' are allowed."
+		exit 7
+	fi
+fi
+
+#Check if Build is selected with argument '-x'
+if [ ! -z "$board_mem_flag" ] ; then
+	if [ "$board_mem_flag" == "8" ] ; then
+        BOARD_MEM="0x21FF"
+		echo "Board mem size   :     $board_mem_flag Kb, $BOARD_MEM (hex)"
+    elif [ "$board_mem_flag" == "64" ] ; then
+        BOARD_MEM="0xFFFF"
+		echo "Board mem size   :    $board_mem_flag Kb, $BOARD_MEM (hex)"
+	else
+		echo "Unsupported board mem size chosen. Only '8', '64' are allowed."
+		exit 8
+	fi
+fi
 
 
 #### Set build environment 
 #### Set build environment 
-ARDUINO_ENV="1.8.5"
+ARDUINO_ENV="1.8.13"
 BUILD_ENV="1.0.6"
 BUILD_ENV="1.0.6"
 BOARD="prusa_einsy_rambo"
 BOARD="prusa_einsy_rambo"
 BOARD_PACKAGE_NAME="PrusaResearch"
 BOARD_PACKAGE_NAME="PrusaResearch"
 BOARD_VERSION="1.0.3"
 BOARD_VERSION="1.0.3"
-#BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Prusa_Merge_v1.0.3/IDE_Board_Manager/package_prusa3d_index.json"
+#BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
 BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
 BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json"
 BOARD_FILENAME="prusa3dboards"
 BOARD_FILENAME="prusa3dboards"
-#BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Prusa_Merge_v1.0.3/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2"
+#BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2"
 BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2"
 BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2"
 #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"
 #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"
 PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip"
 PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip"
@@ -270,6 +374,12 @@ echo ""
 echo "Arduino IDE :" $ARDUINO_ENV
 echo "Arduino IDE :" $ARDUINO_ENV
 echo "Build env   :" $BUILD_ENV
 echo "Build env   :" $BUILD_ENV
 echo "Board       :" $BOARD
 echo "Board       :" $BOARD
+if [ ! -z "$BOARD_FLASH" ] ; then
+    echo "Board flash :" $BOARD_FLASH
+fi
+if [ ! -z "$BOARD_MEM" ] ; then
+    echo "Board mem   :" $BOARD_MEM
+fi
 echo "Package name:" $BOARD_PACKAGE_NAME
 echo "Package name:" $BOARD_PACKAGE_NAME
 echo "Board v.    :" $BOARD_VERSION
 echo "Board v.    :" $BOARD_VERSION
 echo "Specific Lib:" $LIB
 echo "Specific Lib:" $LIB
@@ -279,10 +389,10 @@ echo ""
 
 
 #Check if build exists and creates it if not
 #Check if build exists and creates it if not
 if [ ! -d "../PF-build-dl" ]; then
 if [ ! -d "../PF-build-dl" ]; then
-    mkdir ../PF-build-dl || exit 6
+    mkdir ../PF-build-dl || exit 9
 fi
 fi
 
 
-cd ../PF-build-dl || exit 7
+cd ../PF-build-dl || exit 10
 BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
 BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
 
 
 # Check if PF-build-env-<version> exists and downloads + creates it if not
 # Check if PF-build-env-<version> exists and downloads + creates it if not
@@ -299,13 +409,13 @@ if [ $TARGET_OS == "windows" ]; then
 	if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then
 	if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then
 		echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
 		echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
 		sleep 2
 		sleep 2
-		wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || exit 8
+		wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || exit 11
 		echo "$(tput sgr 0)"
 		echo "$(tput sgr 0)"
 	fi
 	fi
 	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
 	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
 		echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
 		echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)"
 		sleep 2
 		sleep 2
-		unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env-$BUILD_ENV || exit 8
+		unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env-$BUILD_ENV || exit 11
 		mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
 		mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
 		echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
 		echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
 		echo "$(tput sgr0)"
 		echo "$(tput sgr0)"
@@ -317,13 +427,13 @@ if [ $TARGET_OS == "linux" ]; then
 	if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then
 	if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then
 		echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)"
 		echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)"
 		sleep 2
 		sleep 2
-		wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || exit 8
+		wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || exit 11
 		echo "$(tput sgr 0)"
 		echo "$(tput sgr 0)"
 	fi
 	fi
 	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
 	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
 		echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)"
 		echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)"
 		sleep 2
 		sleep 2
-		tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env-$BUILD_ENV/ || exit 8
+		tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env-$BUILD_ENV/ || exit 11
 		mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
 		mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor
 		echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
 		echo "# arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt
 		echo "$(tput sgr0)"
 		echo "$(tput sgr0)"
@@ -406,7 +516,7 @@ fi
 if [ ! -f "PF-build-env-WinLin-$BUILD_ENV.zip" ]; then
 if [ ! -f "PF-build-env-WinLin-$BUILD_ENV.zip" ]; then
 	echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)"
 	echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)"
 	sleep 2
 	sleep 2
-	wget $PF_BUILD_FILE_URL || exit 11
+	wget $PF_BUILD_FILE_URL || exit 12
 	echo "$(tput sgr 0)"
 	echo "$(tput sgr 0)"
 fi
 fi
 if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]; then
 if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]; then
@@ -453,65 +563,6 @@ if type git > /dev/null; then
 	git_available="1"
 	git_available="1"
 fi
 fi
 
 
-while getopts v:l:d:b:o:c:p:n:?h flag
-	do
-	    case "${flag}" in
-	        v) variant_flag=${OPTARG};;
-	        l) language_flag=${OPTARG};;
-	        d) devel_flag=${OPTARG};;
-			b) build_flag=${OPTARG};;
-			o) output_flag=${OPTARG};;
-			c) clean_flag=${OPTARG};;
-			p) prusa_flag=${OPTARG};;
-			n) new_build_flag=${OPTARG};;
-			?) help_flag=1;;
-			h) help_flag=1;;
-	    esac
-	done
-#echo "variant_flag: $variant_flag";
-#echo "language_flag: $language_flag";
-#echo "devel_flag: $devel_flag";
-#echo "build_flag: $build_flag";
-#echo "output_flag: $output_flag";
-#echo "help_flag: $help_flag"
-#echo "clean_flag: $clean_flag"
-#echo "prusa_flag: $prusa_flag"
-#echo "new_build_flag: $new_build_flag"
-
-#
-# '?' 'h' argument usage and help
-if [ "$help_flag" == "1" ] ; then
-echo "***************************************"
-echo "* PF-build.sh Version: 1.0.6-Build_33 *"
-echo "***************************************"
-echo "Arguments:"
-echo "$(tput setaf 2)-v$(tput sgr0) Variant '$(tput setaf 2)All$(tput sgr0)' or variant file name"
-echo "$(tput setaf 2)-l$(tput sgr0) Languages '$(tput setaf 2)ALL$(tput sgr0)' for multi language or '$(tput setaf 2)EN_ONLY$(tput sgr0)' for English only"
-echo "$(tput setaf 2)-d$(tput sgr0) Devel build '$(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)'"
-echo "$(tput setaf 2)-b$(tput sgr0) Build/commit number '$(tput setaf 2)Auto$(tput sgr0)' needs git or a number"
-echo "$(tput setaf 2)-o$(tput sgr0) Output '$(tput setaf 2)1$(tput sgr0)' force or '$(tput setaf 2)0$(tput sgr0)' block output and delays"
-echo "$(tput setaf 2)-c$(tput sgr0) Do not clean up lang build'$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
-echo "$(tput setaf 2)-p$(tput sgr0) Keep Configuration_prusa.h '$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
-echo "$(tput setaf 2)-n$(tput sgr0) New fresh build '$(tput setaf 2)0$(tput sgr0)' no '$(tput setaf 2)1$(tput sgr0)' yes"
-echo "$(tput setaf 2)-?$(tput sgr0) Help"
-echo "$(tput setaf 2)-h$(tput sgr0) Help"
-echo 
-echo "Brief USAGE:"
-echo "  $(tput setaf 2)./PF-build.sh$(tput sgr0)  [-v] [-l] [-d] [-b] [-o] [-c] [-p] [-n]"
-echo
-echo "Example:"
-echo "  $(tput setaf 2)./PF-build.sh -v All -l ALL -d GOLD$(tput sgr0)"
-echo "  Will build all variants as multi language and final GOLD version"
-echo
-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)"
-echo "  Will build MK3S multi language final GOLD firmware "
-echo "  with current commit count number and output extra information,"
-echo "  not delete lang build temporary files, keep Configuration_prusa.h and build with new fresh build folder."
-echo
-exit 14
-
-fi
-
 #
 #
 # '-v' argument defines which variant of the Prusa Firmware will be compiled 
 # '-v' argument defines which variant of the Prusa Firmware will be compiled 
 if [ -z "$variant_flag" ] ; then
 if [ -z "$variant_flag" ] ; then
@@ -710,7 +761,7 @@ do
 						DEV_STATUS_SELECTED="GOLD"
 						DEV_STATUS_SELECTED="GOLD"
 						break
 						break
 						;;
 						;;
-					No) 
+					No)
 						DEV_STATUS="UNKNOWN"
 						DEV_STATUS="UNKNOWN"
 						DEV_STATUS_SELECTED="UNKNOWN"
 						DEV_STATUS_SELECTED="UNKNOWN"
 						break
 						break
@@ -729,6 +780,12 @@ do
 		mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD || exit 28
 		mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD || exit 28
 	fi
 	fi
 	OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD"
 	OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD"
+    if [ "$BOARD" != "prusa_einsy_rambo" ]; then
+	    if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD" ]; then
+		    mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$BOARD || exit 28
+	    fi
+        OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$BOARD"
+    fi
 	
 	
 	#Check if exactly the same hexfile already exists
 	#Check if exactly the same hexfile already exists
 	if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex"  &&  "$LANGUAGES" == "ALL" ]]; then
 	if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex"  &&  "$LANGUAGES" == "ALL" ]]; then
@@ -763,6 +820,8 @@ do
 	echo "Dev Check  :" $DEV_CHECK
 	echo "Dev Check  :" $DEV_CHECK
 	echo "DEV Status :" $DEV_STATUS
 	echo "DEV Status :" $DEV_STATUS
 	echo "Motherboard:" $MOTHERBOARD
 	echo "Motherboard:" $MOTHERBOARD
+    echo "Board flash:" $BOARD_FLASH
+    echo "Board mem  :" $BOARD_MEM
 	echo "Languages  :" $LANGUAGES
 	echo "Languages  :" $LANGUAGES
 	echo "Hex-file Folder:" $OUTPUT_FOLDER
 	echo "Hex-file Folder:" $OUTPUT_FOLDER
 	echo "$(tput sgr0)"
 	echo "$(tput sgr0)"
@@ -796,7 +855,72 @@ do
 		sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE              1/g" $SCRIPT_PATH/Firmware/config.h
 		sed -i -- "s/^#define LANG_MODE *0/#define LANG_MODE              1/g" $SCRIPT_PATH/Firmware/config.h
 		echo " "
 		echo " "
 	fi
 	fi
-		
+
+    # Prepare Board mem and flash modifications
+    ## Check board mem size
+    CURRENT_BOARD_MEM=$(grep "#define RAMEND" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h | sed -e's/.* //g'|cut -d ' ' -f3|tr -d $'\n')
+    if [ $CURRENT_BOARD_MEM != "0x21FF" ] ; then
+        echo "Board mem has been already modified or not reset"
+        echo "Current:" $CURRENT_BOARD_MEM
+        PS3="Select Yes if you want to reset it."
+        select yn in "Yes" "No"; do
+            case $yn in
+                Yes)
+                    echo "Resetting board mem size"
+                    sed -i -- "s/^#define RAMEND .*$/#define RAMEND          0x21FF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
+                    break
+                    ;;
+                *)
+                    echo "Continuing with modified mem size"
+                    break
+                    ;;
+            esac
+        done
+    fi
+    ## Modify board mem size
+    if [[ ! -z $BOARD_MEM && "$BOARD_MEM" != "0x21FF" ]] ; then
+        echo "Modifying board memory size (hex):"
+        echo "Old:" $CURRENT_BOARD_MEM
+        echo "New:" $BOARD_MEM
+        read -t 5 -p "To cancel press CRTL+C"
+        sed -i -- "s/^#define RAMEND          0x21FF/#define RAMEND          ${BOARD_MEM}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
+    fi
+
+    ## Check board flash size
+    CURRENT_BOARD_FLASH=$(grep "#define FLASHEND" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h | sed -e's/.* //g'|cut -d ' ' -f3|tr -d $'\n')
+    CURRENT_BOARD_maximum_size=$(grep "prusa_einsy_rambo.upload.maximum_size" $BUILD_ENV_PATH/portable/packages/$BOARD_PACKAGE_NAME/hardware/avr/$BOARD_VERSION/boards.txt |cut -d '=' -f2|tr -d $'\n')
+    if [[ $CURRENT_BOARD_FLASH != "0x3FFFF" || $CURRENT_BOARD_maximum_size != "253952" ]] ; then
+        echo "Board flash has been already modified or not reset"
+        echo "Current flash size:" $CURRENT_BOARD_FLASH
+        echo "Current max.  size:" $CURRENT_BOARD_maximum_size
+        PS3="Select Yes if you want to reset it."
+        select yn in "Yes" "No"; do
+            case $yn in
+                Yes)
+                    echo "Resetting board flash size"
+                    sed -i -- "s/^#define FLASHEND .*$/#define FLASHEND        0x3FFFF/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
+                    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
+                    break
+                    ;;
+                *)
+                    echo "Continuing with modified flash size"
+                    break
+                    ;;
+            esac
+        done
+    fi
+    ## Modify boad flash size
+    if [[ ! -z $BOARD_FLASH && "$BOARD_FLASH" != "0x3FFFF" ]] ; then
+        echo "Modifying board flash size (hex):"
+        echo "Old flash size:" $CURRENT_BOARD_FLASH
+        echo "New flash size:" $BOARD_FLASH
+        echo "Old max.  size:" $CURRENT_BOARD_maximum_size
+        echo "New max.  size:" $BOARD_maximum_size
+        read -t 5 -p "To cancel press CRTL+C"
+        sed -i -- "s/^#define FLASHEND .*/#define FLASHEND        ${BOARD_FLASH}/g" $BUILD_ENV_PATH/hardware/tools/avr/avr/include/avr/iom2560.h
+        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
+    fi
+
 	#Check if compiler flags are set to Prusa specific needs for the rambo board.
 	#Check if compiler flags are set to Prusa specific needs for the rambo board.
 #	if [ $TARGET_OS == "windows" ]; then
 #	if [ $TARGET_OS == "windows" ]; then
 #		RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
 #		RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt"
@@ -825,7 +949,7 @@ do
 		rm -r -f $BUILD_PATH/* || exit 36
 		rm -r -f $BUILD_PATH/* || exit 36
 	fi
 	fi
 
 
-	#$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 || exit 30
+	$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 || exit 30
 	$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 $SCRIPT_PATH/Firmware/Firmware.ino || exit 30
 	$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 $SCRIPT_PATH/Firmware/Firmware.ino || exit 30
 	echo "$(tput sgr 0)"
 	echo "$(tput sgr 0)"