From 2f814079d8a02c64438156e3e76f8201c02b8745 Mon Sep 17 00:00:00 2001
From: Bob Kuhn <bob.kuhn@att.net>
Date: Thu, 23 Jun 2022 23:58:26 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Lerdge=20build=20/=20encry?=
 =?UTF-8?q?pt=20(#24391)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
---
 buildroot/share/PlatformIO/scripts/lerdge.py  | 10 +--
 buildroot/share/PlatformIO/scripts/marlin.py  |  4 +-
 .../PlatformIO/scripts/offset_and_rename.py   | 10 +--
 ini/stm32f1.ini                               | 36 ++++-----
 ini/stm32f4.ini                               | 80 +++++++++----------
 5 files changed, 70 insertions(+), 70 deletions(-)

diff --git a/buildroot/share/PlatformIO/scripts/lerdge.py b/buildroot/share/PlatformIO/scripts/lerdge.py
index 505a935560a..06e45439307 100644
--- a/buildroot/share/PlatformIO/scripts/lerdge.py
+++ b/buildroot/share/PlatformIO/scripts/lerdge.py
@@ -26,10 +26,10 @@ if pioutil.is_pio_build():
 			input_file[i] = encryptByte(input_file[i])
 		output_file.write(input_file)
 
-	# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
+	# Encrypt ${PROGNAME}.bin and save it with the name given in build.crypt_lerdge
 	def encrypt(source, target, env):
 		fwpath = target[0].path
-		enname = board.get("build.encrypt")
+		enname = board.get("build.crypt_lerdge")
 		print("Encrypting %s to %s" % (fwpath, enname))
 		fwfile = open(fwpath, "rb")
 		enfile = open(target[0].dir.path + "/" + enname, "wb")
@@ -41,9 +41,9 @@ if pioutil.is_pio_build():
 		enfile.close()
 		os.remove(fwpath)
 
-	if 'encrypt' in board.get("build").keys():
-		if board.get("build.encrypt") != "":
+	if 'crypt_lerdge' in board.get("build").keys():
+		if board.get("build.crypt_lerdge") != "":
 			marlin.add_post_action(encrypt)
 	else:
-		print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter")
+		print("LERDGE builds require output file via board_build.crypt_lerdge = 'filename' parameter")
 		exit(1)
diff --git a/buildroot/share/PlatformIO/scripts/marlin.py b/buildroot/share/PlatformIO/scripts/marlin.py
index 8ac36b7d59b..580268c4232 100644
--- a/buildroot/share/PlatformIO/scripts/marlin.py
+++ b/buildroot/share/PlatformIO/scripts/marlin.py
@@ -41,8 +41,8 @@ def custom_ld_script(ldname):
 		elif flag == "-T":
 			env["LINKFLAGS"][i + 1] = apath
 
-# Encrypt ${PROGNAME}.bin and save it with a new name
-# Called by specific encrypt() functions, mostly for MKS boards
+# Encrypt ${PROGNAME}.bin and save it with a new name. This applies (mostly) to MKS boards
+# This PostAction is set up by offset_and_rename.py for envs with 'build.encrypt_mks'.
 def encrypt_mks(source, target, env, new_name):
 	import sys
 
diff --git a/buildroot/share/PlatformIO/scripts/offset_and_rename.py b/buildroot/share/PlatformIO/scripts/offset_and_rename.py
index ddbb786fecd..6f445246190 100644
--- a/buildroot/share/PlatformIO/scripts/offset_and_rename.py
+++ b/buildroot/share/PlatformIO/scripts/offset_and_rename.py
@@ -39,15 +39,15 @@ if pioutil.is_pio_build():
 				env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)
 
 	#
-	# For build.encrypt rename and encode the firmware file.
+	# For build.encrypt_mks rename and encode the firmware file.
 	#
-	if 'encrypt' in board_keys:
+	if 'encrypt_mks' in board_keys:
 
-		# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt
+		# Encrypt ${PROGNAME}.bin and save it with the name given in build.encrypt_mks
 		def encrypt(source, target, env):
-			marlin.encrypt_mks(source, target, env, board.get("build.encrypt"))
+			marlin.encrypt_mks(source, target, env, board.get("build.encrypt_mks"))
 
-		if board.get("build.encrypt") != "":
+		if board.get("build.encrypt_mks") != "":
 			marlin.add_post_action(encrypt)
 
 	#
diff --git a/ini/stm32f1.ini b/ini/stm32f1.ini
index a4ad79adfaf..8835c1acd8c 100644
--- a/ini/stm32f1.ini
+++ b/ini/stm32f1.ini
@@ -89,22 +89,22 @@ board_upload.offset_address = 0x08005000
 # Uses HAL STM32 to support Marlin UI for TFT screen with optional touch panel
 #
 [env:mks_robin]
-extends              = stm32_variant
-board                = genericSTM32F103ZE
-board_build.variant  = MARLIN_F103Zx
-board_build.encrypt  = Robin.bin
-board_build.offset   = 0x7000
-build_flags          = ${stm32_variant.build_flags}
-                       -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
-build_unflags        = ${stm32_variant.build_unflags}
-                       -DUSBCON -DUSBD_USE_CDC
+extends                 = stm32_variant
+board                   = genericSTM32F103ZE
+board_build.variant     = MARLIN_F103Zx
+board_build.encrypt_mks = Robin.bin
+board_build.offset      = 0x7000
+build_flags             = ${stm32_variant.build_flags}
+                          -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5
+build_unflags           = ${stm32_variant.build_unflags}
+                          -DUSBCON -DUSBD_USE_CDC
 
 #
 # MKS Robin E3/E3D (STM32F103RCT6) with TMC2209
 #
 [env:mks_robin_e3]
 extends                     = common_STM32F103RC_variant
-board_build.encrypt         = Robin_e3.bin
+board_build.encrypt_mks     = Robin_e3.bin
 board_build.offset          = 0x5000
 board_upload.offset_address = 0x08005000
 build_flags                 = ${common_STM32F103RC_variant.build_flags}
@@ -205,7 +205,7 @@ build_unflags     = ${stm32_variant.build_unflags} -DUSBD_USE_CDC
 extends                     = stm32_variant
 board                       = genericSTM32F103VE
 board_build.variant         = MARLIN_F103Vx
-board_build.encrypt         = Robin_mini.bin
+board_build.encrypt_mks     = Robin_mini.bin
 board_build.offset          = 0x7000
 board_upload.offset_address = 0x08007000
 build_flags                 = ${stm32_variant.build_flags}
@@ -221,7 +221,7 @@ build_unflags               = ${stm32_variant.build_unflags}
 extends                     = stm32_variant
 board                       = genericSTM32F103VE
 board_build.variant         = MARLIN_F103Vx
-board_build.encrypt         = Robin_nano35.bin
+board_build.encrypt_mks     = Robin_nano35.bin
 board_build.offset          = 0x7000
 board_upload.offset_address = 0x08007000
 build_flags                 = ${stm32_variant.build_flags}
@@ -274,7 +274,7 @@ build_flags                 = ${stm32_variant.build_flags} -DSS_TIMER=4
 extends                     = stm32_variant
 board                       = genericSTM32F103VE
 board_build.variant         = MARLIN_F103Vx
-board_build.encrypt         = Robin_mini.bin
+board_build.encrypt_mks     = Robin_mini.bin
 board_build.offset          = 0x7000
 board_upload.offset_address = 0x08007000
 build_flags                 = ${stm32_variant.build_flags}
@@ -287,7 +287,7 @@ build_flags                 = ${stm32_variant.build_flags}
 extends                     = stm32_variant
 board                       = genericSTM32F103RC
 board_build.variant         = MARLIN_F103Rx
-board_build.encrypt         = mksLite.bin
+board_build.encrypt_mks     = mksLite.bin
 board_build.offset          = 0x5000
 board_upload.offset_address = 0x08005000
 
@@ -296,14 +296,14 @@ board_upload.offset_address = 0x08005000
 #
 [env:mks_robin_lite3]
 extends                     = env:mks_robin_lite
-board_build.encrypt         = mksLite3.bin
+board_build.encrypt_mks     = mksLite3.bin
 
 #
 # MKS Robin Pro (STM32F103ZET6)
 #
 [env:mks_robin_pro]
-extends             = env:mks_robin
-board_build.encrypt = Robin_pro.bin
+extends                 = env:mks_robin
+board_build.encrypt_mks = Robin_pro.bin
 
 #
 # MKS Robin E3p (STM32F103VET6)
@@ -313,7 +313,7 @@ board_build.encrypt = Robin_pro.bin
 extends                     = stm32_variant
 board                       = genericSTM32F103VE
 board_build.variant         = MARLIN_F103Vx
-board_build.encrypt         = Robin_e3p.bin
+board_build.encrypt_mks     = Robin_e3p.bin
 board_build.offset          = 0x7000
 board_upload.offset_address = 0x08007000
 build_flags                 = ${stm32_variant.build_flags}
diff --git a/ini/stm32f4.ini b/ini/stm32f4.ini
index 688cc105473..8bcbb88d944 100644
--- a/ini/stm32f4.ini
+++ b/ini/stm32f4.ini
@@ -113,7 +113,7 @@ extra_scripts     = ${stm32_variant.extra_scripts}
 extends                     = stm32_variant
 board                       = marlin_STM32F407VGT6_CCM
 board_build.variant         = MARLIN_F4x7Vx
-board_build.encrypt         = firmware.srec
+board_build.encrypt_mks     = firmware.srec
 board_build.offset          = 0x10000
 board_upload.offset_address = 0x08010000
 build_flags                 = ${stm32_variant.build_flags}
@@ -302,24 +302,24 @@ build_flags       = ${stm_flash_drive.build_flags}
 # Lerdge base
 #
 [lerdge_common]
-extends             = stm32_variant
-board               = marlin_STM32F407ZGT6
-board_build.variant = MARLIN_LERDGE
-board_build.offset  = 0x10000
-build_flags         = ${stm32_variant.build_flags}
-                      -DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
-                      -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
-build_unflags       = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
-extra_scripts       = ${common_stm32.extra_scripts}
-                      pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
-                      buildroot/share/PlatformIO/scripts/lerdge.py
+extends                  = stm32_variant
+board                    = marlin_STM32F407ZGT6
+board_build.variant      = MARLIN_LERDGE
+board_build.crypt_lerdge = firmware.bin
+board_build.offset       = 0x10000
+build_flags              = ${stm32_variant.build_flags}
+                           -DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
+                           -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
+build_unflags            = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
+extra_scripts            = ${stm32_variant.extra_scripts}
+                           buildroot/share/PlatformIO/scripts/lerdge.py
 
 #
 # Lerdge X (STM32F407VE)
 #
 [env:LERDGEX]
-extends             = lerdge_common
-board_build.encrypt = Lerdge_X_firmware_force.bin
+extends                  = lerdge_common
+board_build.crypt_lerdge = Lerdge_X_firmware_force.bin
 
 #
 # Lerdge X with USB Flash Drive Support
@@ -333,8 +333,8 @@ build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
 # Lerdge S (STM32F407ZG)
 #
 [env:LERDGES]
-extends             = lerdge_common
-board_build.encrypt = Lerdge_firmware_force.bin
+extends                  = lerdge_common
+board_build.crypt_lerdge = Lerdge_firmware_force.bin
 
 #
 # Lerdge S with USB Flash Drive Support
@@ -348,9 +348,9 @@ build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
 # Lerdge K (STM32F407ZG)
 #
 [env:LERDGEK]
-extends             = lerdge_common
-board_build.encrypt = Lerdge_K_firmware_force.bin
-build_flags         = ${lerdge_common.build_flags} -DLERDGEK
+extends                  = lerdge_common
+board_build.crypt_lerdge = Lerdge_K_firmware_force.bin
+build_flags              = ${lerdge_common.build_flags} -DLERDGEK
 
 #
 # Lerdge K with USB Flash Drive Support
@@ -364,17 +364,17 @@ build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}
 # RUMBA32
 #
 [env:rumba32]
-extends              = stm32_variant
-board                = rumba32_f446ve
-board_build.variant  = MARLIN_F446VE
-board_build.offset   = 0x0000
-build_flags          = ${stm32_variant.build_flags}
-                       -Os -DHAL_PCD_MODULE_ENABLED
-                       -DDISABLE_GENERIC_SERIALUSB
-                       -DHAL_UART_MODULE_ENABLED
-                       -DTIMER_SERIAL=TIM9
-monitor_speed        = 500000
-upload_protocol      = dfu
+extends             = stm32_variant
+board               = rumba32_f446ve
+board_build.variant = MARLIN_F446VE
+board_build.offset  = 0x0000
+build_flags         = ${stm32_variant.build_flags}
+                      -Os -DHAL_PCD_MODULE_ENABLED
+                      -DDISABLE_GENERIC_SERIALUSB
+                      -DHAL_UART_MODULE_ENABLED
+                      -DTIMER_SERIAL=TIM9
+monitor_speed       = 500000
+upload_protocol     = dfu
 
 #
 # MKS Robin Pro V2
@@ -547,17 +547,17 @@ build_unflags     = -DUSBD_USE_CDC
 # TH3D EZBoard v2.0 (STM32F405RGT6 ARM Cortex-M4)
 #
 [env:TH3D_EZBoard_V2]
-extends             = stm32_variant
-board               = genericSTM32F405RG
-board_build.variant = MARLIN_TH3D_EZBOARD_V2
-board_build.encrypt = firmware.bin
-board_build.offset  = 0xC000
+extends                     = stm32_variant
+board                       = genericSTM32F405RG
+board_build.variant         = MARLIN_TH3D_EZBOARD_V2
+board_build.encrypt_mks     = firmware.bin
+board_build.offset          = 0xC000
 board_upload.offset_address = 0x0800C000
-build_flags         = ${stm32_variant.build_flags} -DHSE_VALUE=12000000U -O0
-debug_tool          = stlink
-upload_protocol     = stlink
-extra_scripts       = ${stm32_variant.extra_scripts}
-                      buildroot/share/PlatformIO/scripts/openblt.py
+build_flags                 = ${stm32_variant.build_flags} -DHSE_VALUE=12000000U -O0
+debug_tool                  = stlink
+upload_protocol             = stlink
+extra_scripts               = ${stm32_variant.extra_scripts}
+                              buildroot/share/PlatformIO/scripts/openblt.py
 
 #
 # BOARD_MKS_ROBIN_NANO_V1_3_F4