Updates from #24560

This commit is contained in:
Keith Bennett
2022-07-29 04:12:38 -07:00
committed by Scott Lahteine
parent 752f3d440d
commit 2952f0be5d
23 changed files with 163 additions and 148 deletions

View File

@@ -13,9 +13,7 @@ which curl >/dev/null && TOOL='curl -L -s -S -f -o wgot'
which wget >/dev/null && TOOL='wget -q -O wgot'
CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
[[ $CURR == "bugfix-2.0.x" ]] && BRANCH=bugfix-2.0.x || BRANCH=bugfix-2.1.x
REPO=$BRANCH
REPO=bugfix-2.0.x
if [[ $# > 0 ]]; then
IFS=: read -r PART1 PART2 <<< "$@"

View File

@@ -70,10 +70,9 @@ if pioutil.is_pio_build():
feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
blab("[%s] lib_deps = %s" % (feature, dep), 3)
def load_config():
def load_features():
blab("========== Gather [features] entries...")
items = ProjectConfig().items('features')
for key in items:
for key in ProjectConfig().items('features'):
feature = key[0].upper()
if not feature in FEATURE_CONFIG:
FEATURE_CONFIG[feature] = { 'lib_deps': [] }
@@ -81,8 +80,7 @@ if pioutil.is_pio_build():
# Add options matching custom_marlin.MY_OPTION to the pile
blab("========== Gather custom_marlin entries...")
all_opts = env.GetProjectOptions()
for n in all_opts:
for n in env.GetProjectOptions():
key = n[0]
mat = re.match(r'custom_marlin\.(.+)', key)
if mat:
@@ -127,10 +125,10 @@ if pioutil.is_pio_build():
set_env_field('lib_ignore', lib_ignore)
def apply_features_config():
load_config()
load_features()
blab("========== Apply enabled features...")
for feature in FEATURE_CONFIG:
if not env.MarlinFeatureIsEnabled(feature):
if not env.MarlinHas(feature):
continue
feat = FEATURE_CONFIG[feature]
@@ -212,7 +210,7 @@ if pioutil.is_pio_build():
#
# Return True if a matching feature is enabled
#
def MarlinFeatureIsEnabled(env, feature):
def MarlinHas(env, feature):
load_marlin_features()
r = re.compile('^' + feature + '$')
found = list(filter(r.match, env['MARLIN_FEATURES']))
@@ -225,7 +223,7 @@ if pioutil.is_pio_build():
if val in [ '', '1', 'true' ]:
some_on = True
elif val in env['MARLIN_FEATURES']:
some_on = env.MarlinFeatureIsEnabled(val)
some_on = env.MarlinHas(val)
return some_on
@@ -239,7 +237,7 @@ if pioutil.is_pio_build():
#
# Add a method for other PIO scripts to query enabled features
#
env.AddMethod(MarlinFeatureIsEnabled)
env.AddMethod(MarlinHas)
#
# Add dependencies for enabled Marlin features

View File

@@ -10,7 +10,7 @@ if pioutil.is_pio_build():
Import("env")
if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"):
if env.MarlinHas("POSTMORTEM_DEBUGGING"):
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")

View File

@@ -4,5 +4,10 @@
# Make sure 'vscode init' is not the current command
def is_pio_build():
from SCons.Script import COMMAND_LINE_TARGETS
return "idedata" not in COMMAND_LINE_TARGETS and "_idedata" not in COMMAND_LINE_TARGETS
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
return not env.IsIntegrationDump()
def get_pio_version():
from platformio import util
return util.pioversion_to_intstr()

View File

@@ -40,7 +40,10 @@ def run_preprocessor(env, fn=None):
depcmd = cmd + [ filename ]
cmd = ' '.join(depcmd)
blab(cmd)
define_list = subprocess.check_output(cmd, shell=True).splitlines()
try:
define_list = subprocess.check_output(cmd, shell=True).splitlines()
except:
define_list = {}
preprocessor_cache[filename] = define_list
return define_list

View File

@@ -110,53 +110,15 @@ if [[ $ACTION == "init" ]]; then
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Commit for comparison" >/dev/null
# Init Cartesian/SCARA/TPARA configurations to default
echo "- Initializing Cartesian/SCARA/TPARA configs to default state..."
echo "- Initializing configs to default state..."
find "$CEXA" -name $BC ! -path */delta/* -print0 \
find "$CEXA" -name $BC -print0 \
| while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
find "$CEXA" -name $AC ! -path */delta/* -print0 \
find "$CEXA" -name $AC -print0 \
| while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
# DEBUG: Commit the reset for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Cartesian/SCARA/TPARA configs..." >/dev/null
# Create base Delta configurations
cp "$CDEF"/* "$CEXA/delta/generic"
# DEBUG: Commit the reset for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Generic Delta..." >/dev/null
cp -R "$TEMP/$CEXA/delta/generic"/Conf* "$CEXA/delta/generic"
# DEBUG: Commit Generic Delta changes for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Apply Generic Delta..." >/dev/null
# Reset all Delta configs to the generic version
find "$CEXA/delta" -name $BC ! -path */generic/* -print0 \
| while read -d $'\0' F ; do cp "$CEXA/delta/generic/$BC" "$F" ; done
find "$CEXA/delta" -name $AC ! -path */generic/* -print0 \
| while read -d $'\0' F ; do cp "$CEXA/delta/generic/$AC" "$F" ; done
# DEBUG: Commit the Delta reset for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Delta configs..." >/dev/null
# Reset all SCARA configs to the default cartesian
find "$CEXA/SCARA" -name $BC \
| while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
find "$CEXA/SCARA" -name $AC \
| while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
# DEBUG: Commit the SCARA reset for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset SCARA..." >/dev/null
# Reset all TPARA configs to the default cartesian
find "$CEXA/TPARA" -name $BC \
| while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
find "$CEXA/TPARA" -name $AC \
| while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
# DEBUG: Commit the TPARA reset for review
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset TPARA..." >/dev/null
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset configs..." >/dev/null
# Update the %VERSION% in the README.md file
VERS=$( echo $EXPORT | $SED 's/release-//' )

View File

@@ -376,11 +376,13 @@ class FileTransferProtocol(object):
token, data = self.await_response(1000)
if token == 'PFT:success':
print("File closed")
return
return True
elif token == 'PFT:ioerror':
print("Client storage device IO error")
return False
elif token == 'PFT:invalid':
print("No open file")
return False
def abort(self):
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.ABORT);
@@ -417,12 +419,23 @@ class FileTransferProtocol(object):
self.write(data[start:end])
kibs = (( (i+1) * block_size) / 1024) / (millis() + 1 - start_time) * 1000
if (i / blocks) >= dump_pctg:
print("\r{0:2.2f}% {1:4.2f}KiB/s {2} Errors: {3}".format((i / blocks) * 100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression_support else "", self.protocol.errors), end='')
print("\r{0:2.0f}% {1:4.2f}KiB/s {2} Errors: {3}".format((i / blocks) * 100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression_support else "", self.protocol.errors), end='')
dump_pctg += 0.1
print("\r{0:2.2f}% {1:4.2f}KiB/s {2} Errors: {3}".format(100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression_support else "", self.protocol.errors)) # no one likes transfers finishing at 99.8%
if self.protocol.errors > 0:
# Dump last status (errors may not be visible)
print("\r{0:2.0f}% {1:4.2f}KiB/s {2} Errors: {3} - Aborting...".format((i / blocks) * 100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression_support else "", self.protocol.errors), end='')
print("") # New line to break the transfer speed line
self.close()
print("Transfer aborted due to protocol errors")
#raise Exception("Transfer aborted due to protocol errors")
return False;
print("\r{0:2.0f}% {1:4.2f}KiB/s {2} Errors: {3}".format(100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression_support else "", self.protocol.errors)) # no one likes transfers finishing at 99.8%
self.close()
if not self.close():
print("Transfer failed")
return False
print("Transfer complete")
return True
class EchoProtocol(object):

View File

@@ -20,14 +20,18 @@ Import("env")
import MarlinBinaryProtocol
# Internal debug flag
Debug = False
#-----------------#
# Upload Callback #
#-----------------#
def Upload(source, target, env):
#-------#
# Debug #
#-------#
Debug = False # Set to True to enable script debug
def debugPrint(data):
if Debug: print(f"[Debug]: {data}")
#------------------#
# Marlin functions #
#------------------#
@@ -39,19 +43,35 @@ def Upload(source, target, env):
# Port functions #
#----------------#
def _GetUploadPort(env):
if Debug: print('Autodetecting upload port...')
debugPrint('Autodetecting upload port...')
env.AutodetectUploadPort(env)
port = env.subst('$UPLOAD_PORT')
if not port:
portName = env.subst('$UPLOAD_PORT')
if not portName:
raise Exception('Error detecting the upload port.')
if Debug: print('OK')
return port
debugPrint('OK')
return portName
#-------------------------#
# Simple serial functions #
#-------------------------#
def _OpenPort():
# Open serial port
if port.is_open: return
debugPrint('Opening upload port...')
port.open()
port.reset_input_buffer()
debugPrint('OK')
def _ClosePort():
# Open serial port
if port is None: return
if not port.is_open: return
debugPrint('Closing upload port...')
port.close()
debugPrint('OK')
def _Send(data):
if Debug: print(f'>> {data}')
debugPrint(f'>> {data}')
strdata = bytearray(data, 'utf8') + b'\n'
port.write(strdata)
time.sleep(0.010)
@@ -60,7 +80,7 @@ def Upload(source, target, env):
clean_responses = []
responses = port.readlines()
for Resp in responses:
# Test: suppress invaid chars (coming from debug info)
# Suppress invalid chars (coming from debug info)
try:
clean_response = Resp.decode('utf8').rstrip().lstrip()
clean_responses.append(clean_response)
@@ -73,24 +93,24 @@ def Upload(source, target, env):
# SDCard functions #
#------------------#
def _CheckSDCard():
if Debug: print('Checking SD card...')
debugPrint('Checking SD card...')
_Send('M21')
Responses = _Recv()
if len(Responses) < 1 or not any('SD card ok' in r for r in Responses):
raise Exception('Error accessing SD card')
if Debug: print('SD Card OK')
debugPrint('SD Card OK')
return True
#----------------#
# File functions #
#----------------#
def _GetFirmwareFiles(UseLongFilenames):
if Debug: print('Get firmware files...')
debugPrint('Get firmware files...')
_Send(f"M20 F{'L' if UseLongFilenames else ''}")
Responses = _Recv()
if len(Responses) < 3 or not any('file list' in r for r in Responses):
raise Exception('Error getting firmware files')
if Debug: print('OK')
debugPrint('OK')
return Responses
def _FilterFirmwareFiles(FirmwareList, UseLongFilenames):
@@ -114,6 +134,17 @@ def Upload(source, target, env):
raise Exception(f"Firmware file '{FirmwareFile}' not removed")
return Removed
def _RollbackUpload(FirmwareFile):
if not rollback: return
print(f"Rollback: trying to delete firmware '{FirmwareFile}'...")
_OpenPort()
# Wait for SD card release
time.sleep(1)
# Remount SD card
_CheckSDCard()
print(' OK' if _RemoveFirmwareFile(FirmwareFile) else ' Error!')
_ClosePort()
#---------------------#
# Callback Entrypoint #
@@ -121,6 +152,7 @@ def Upload(source, target, env):
port = None
protocol = None
filetransfer = None
rollback = False
# Get Marlin evironment vars
MarlinEnv = env['MARLIN_FEATURES']
@@ -204,9 +236,9 @@ def Upload(source, target, env):
if not marlin_custom_firmware_upload:
raise Exception(f"CUSTOM_FIRMWARE_UPLOAD must be enabled in 'Configuration_adv.h' for '{marlin_motherboard}'")
# Init serial port
# Init & Open serial port
port = serial.Serial(upload_port, baudrate = upload_speed, write_timeout = 0, timeout = 0.1)
port.reset_input_buffer()
_OpenPort()
# Check SD card status
_CheckSDCard()
@@ -228,24 +260,26 @@ def Upload(source, target, env):
print(' OK' if _RemoveFirmwareFile(OldFirmwareFile) else ' Error!')
# Close serial
port.close()
_ClosePort()
# Cleanup completed
if Debug: print('Cleanup completed')
debugPrint('Cleanup completed')
# WARNING! The serial port must be closed here because the serial transfer that follow needs it!
# Upload firmware file
if Debug: print(f"Copy '{upload_firmware_source_name}' --> '{upload_firmware_target_name}'")
debugPrint(f"Copy '{upload_firmware_source_name}' --> '{upload_firmware_target_name}'")
protocol = MarlinBinaryProtocol.Protocol(upload_port, upload_speed, upload_blocksize, float(upload_error_ratio), int(upload_timeout))
#echologger = MarlinBinaryProtocol.EchoProtocol(protocol)
protocol.connect()
# Mark the rollback (delete broken transfer) from this point on
rollback = True
filetransfer = MarlinBinaryProtocol.FileTransferProtocol(protocol)
filetransfer.copy(upload_firmware_source_name, upload_firmware_target_name, upload_compression, upload_test)
transferOK = filetransfer.copy(upload_firmware_source_name, upload_firmware_target_name, upload_compression, upload_test)
protocol.disconnect()
# Notify upload completed
protocol.send_ascii('M117 Firmware uploaded')
protocol.send_ascii('M117 Firmware uploaded' if transferOK else 'M117 Firmware upload failed')
# Remount SD card
print('Wait for SD card release...')
@@ -253,34 +287,56 @@ def Upload(source, target, env):
print('Remount SD card')
protocol.send_ascii('M21')
# Trigger firmware update
if upload_reset:
print('Trigger firmware update...')
protocol.send_ascii('M997', True)
# Transfer failed?
if not transferOK:
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
else:
# Trigger firmware update
if upload_reset:
print('Trigger firmware update...')
protocol.send_ascii('M997', True)
protocol.shutdown()
protocol.shutdown()
print('Firmware update completed')
print('Firmware update completed' if transferOK else 'Firmware update failed')
return 0 if transferOK else -1
except KeyboardInterrupt:
if port: port.close()
print('Aborted by user')
if filetransfer: filetransfer.abort()
if protocol: protocol.shutdown()
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
_ClosePort()
raise
except serial.SerialException as se:
if port: port.close()
print(f'Serial excepion: {se}')
# This exception is raised only for send_ascii data (not for binary transfer)
print(f'Serial excepion: {se}, transfer aborted')
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
_ClosePort()
raise Exception(se)
except MarlinBinaryProtocol.FatalError:
if port: port.close()
if protocol: protocol.shutdown()
print('Too many retries, Abort')
print('Too many retries, transfer aborted')
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
_ClosePort()
raise
except:
if port: port.close()
if protocol: protocol.shutdown()
except Exception as ex:
print(f"\nException: {ex}, transfer aborted")
if protocol:
protocol.disconnect()
protocol.shutdown()
_RollbackUpload(upload_firmware_target_name)
_ClosePort()
print('Firmware not updated')
raise