diff --git a/.editorconfig b/.editorconfig index b8f6ef7f8e..57a5b2fb5e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,6 +14,10 @@ end_of_line = lf indent_style = space indent_size = 2 -[{*.py,*.conf,*.sublime-project}] +[{*.py}] +indent_style = space +indent_size = 4 + +[{*.conf,*.sublime-project}] indent_style = tab indent_size = 4 diff --git a/Marlin/src/HAL/DUE/upload_extra_script.py b/Marlin/src/HAL/DUE/upload_extra_script.py index 4f7a494512..ca12b3b54f 100644 --- a/Marlin/src/HAL/DUE/upload_extra_script.py +++ b/Marlin/src/HAL/DUE/upload_extra_script.py @@ -6,14 +6,14 @@ # import pioutil if pioutil.is_pio_build(): - import platform - current_OS = platform.system() + import platform + current_OS = platform.system() - if current_OS == 'Windows': + if current_OS == 'Windows': - Import("env") + Import("env") - # Use bossac.exe on Windows - env.Replace( - UPLOADCMD="bossac --info --unlock --write --verify --reset --erase -U false --boot $SOURCE" - ) + # Use bossac.exe on Windows + env.Replace( + UPLOADCMD="bossac --info --unlock --write --verify --reset --erase -U false --boot $SOURCE" + ) diff --git a/Marlin/src/HAL/LPC1768/upload_extra_script.py b/Marlin/src/HAL/LPC1768/upload_extra_script.py index 7975f151f7..1b78bb1289 100755 --- a/Marlin/src/HAL/LPC1768/upload_extra_script.py +++ b/Marlin/src/HAL/LPC1768/upload_extra_script.py @@ -9,119 +9,119 @@ from __future__ import print_function import pioutil if pioutil.is_pio_build(): - target_filename = "FIRMWARE.CUR" - target_drive = "REARM" + target_filename = "FIRMWARE.CUR" + target_drive = "REARM" - import os,getpass,platform + import os,getpass,platform - current_OS = platform.system() - Import("env") + current_OS = platform.system() + Import("env") - def print_error(e): - print('\nUnable to find destination disk (%s)\n' \ - 'Please select it in platformio.ini using the upload_port keyword ' \ - '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \ - 'or copy the firmware (.pio/build/%s/firmware.bin) manually to the appropriate disk\n' \ - %(e, env.get('PIOENV'))) + def print_error(e): + print('\nUnable to find destination disk (%s)\n' \ + 'Please select it in platformio.ini using the upload_port keyword ' \ + '(https://docs.platformio.org/en/latest/projectconf/section_env_upload.html) ' \ + 'or copy the firmware (.pio/build/%s/firmware.bin) manually to the appropriate disk\n' \ + %(e, env.get('PIOENV'))) - def before_upload(source, target, env): - try: - # - # Find a disk for upload - # - upload_disk = 'Disk not found' - target_file_found = False - target_drive_found = False - if current_OS == 'Windows': - # - # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:' - # Windows - doesn't care about the disk's name, only cares about the drive letter - import subprocess,string - from ctypes import windll + def before_upload(source, target, env): + try: + # + # Find a disk for upload + # + upload_disk = 'Disk not found' + target_file_found = False + target_drive_found = False + if current_OS == 'Windows': + # + # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:' + # Windows - doesn't care about the disk's name, only cares about the drive letter + import subprocess,string + from ctypes import windll - # getting list of drives - # https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python - drives = [] - bitmask = windll.kernel32.GetLogicalDrives() - for letter in string.ascii_uppercase: - if bitmask & 1: - drives.append(letter) - bitmask >>= 1 + # getting list of drives + # https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python + drives = [] + bitmask = windll.kernel32.GetLogicalDrives() + for letter in string.ascii_uppercase: + if bitmask & 1: + drives.append(letter) + bitmask >>= 1 - for drive in drives: - final_drive_name = drive + ':\\' - # print ('disc check: {}'.format(final_drive_name)) - try: - volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)) - except Exception as e: - print ('error:{}'.format(e)) - continue - else: - if target_drive in volume_info and not target_file_found: # set upload if not found target file yet - target_drive_found = True - upload_disk = final_drive_name - if target_filename in volume_info: - if not target_file_found: - upload_disk = final_drive_name - target_file_found = True + for drive in drives: + final_drive_name = drive + ':\\' + # print ('disc check: {}'.format(final_drive_name)) + try: + volume_info = str(subprocess.check_output('cmd /C dir ' + final_drive_name, stderr=subprocess.STDOUT)) + except Exception as e: + print ('error:{}'.format(e)) + continue + else: + if target_drive in volume_info and not target_file_found: # set upload if not found target file yet + target_drive_found = True + upload_disk = final_drive_name + if target_filename in volume_info: + if not target_file_found: + upload_disk = final_drive_name + target_file_found = True - elif current_OS == 'Linux': - # - # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive' - # - drives = os.listdir(os.path.join(os.sep, 'media', getpass.getuser())) - if target_drive in drives: # If target drive is found, use it. - target_drive_found = True - upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), target_drive) + os.sep - else: - for drive in drives: - try: - files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive)) - except: - continue - else: - if target_filename in files: - upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep - target_file_found = True - break - # - # set upload_port to drive if found - # + elif current_OS == 'Linux': + # + # platformio.ini will accept this for a Linux upload port designation: 'upload_port = /media/media_name/drive' + # + drives = os.listdir(os.path.join(os.sep, 'media', getpass.getuser())) + if target_drive in drives: # If target drive is found, use it. + target_drive_found = True + upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), target_drive) + os.sep + else: + for drive in drives: + try: + files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive)) + except: + continue + else: + if target_filename in files: + upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep + target_file_found = True + break + # + # set upload_port to drive if found + # - if target_file_found or target_drive_found: - env.Replace( - UPLOAD_FLAGS="-P$UPLOAD_PORT" - ) + if target_file_found or target_drive_found: + env.Replace( + UPLOAD_FLAGS="-P$UPLOAD_PORT" + ) - elif current_OS == 'Darwin': # MAC - # - # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive' - # - drives = os.listdir('/Volumes') # human readable names - if target_drive in drives and not target_file_found: # set upload if not found target file yet - target_drive_found = True - upload_disk = '/Volumes/' + target_drive + '/' - for drive in drives: - try: - filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected - except: - continue - else: - if target_filename in filenames: - if not target_file_found: - upload_disk = '/Volumes/' + drive + '/' - target_file_found = True + elif current_OS == 'Darwin': # MAC + # + # platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive' + # + drives = os.listdir('/Volumes') # human readable names + if target_drive in drives and not target_file_found: # set upload if not found target file yet + target_drive_found = True + upload_disk = '/Volumes/' + target_drive + '/' + for drive in drives: + try: + filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected + except: + continue + else: + if target_filename in filenames: + if not target_file_found: + upload_disk = '/Volumes/' + drive + '/' + target_file_found = True - # - # Set upload_port to drive if found - # - if target_file_found or target_drive_found: - env.Replace(UPLOAD_PORT=upload_disk) - print('\nUpload disk: ', upload_disk, '\n') - else: - print_error('Autodetect Error') + # + # Set upload_port to drive if found + # + if target_file_found or target_drive_found: + env.Replace(UPLOAD_PORT=upload_disk) + print('\nUpload disk: ', upload_disk, '\n') + else: + print_error('Autodetect Error') - except Exception as e: - print_error(str(e)) + except Exception as e: + print_error(str(e)) - env.AddPreAction("upload", before_upload) + env.AddPreAction("upload", before_upload) diff --git a/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py b/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py index e7442f2485..4cd553a3da 100644 --- a/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py +++ b/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py @@ -4,17 +4,17 @@ # import pioutil if pioutil.is_pio_build(): - from os.path import join, isfile - import shutil + from os.path import join, isfile + import shutil - Import("env") + Import("env") - mf = env["MARLIN_FEATURES"] - rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0" - txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0" + mf = env["MARLIN_FEATURES"] + rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0" + txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0" - serialBuf = str(max(int(rxBuf), int(txBuf), 350)) + serialBuf = str(max(int(rxBuf), int(txBuf), 350)) - build_flags = env.get('BUILD_FLAGS') - build_flags.append("-DSERIAL_BUFFER_SIZE=" + serialBuf) - env.Replace(BUILD_FLAGS=build_flags) + build_flags = env.get('BUILD_FLAGS') + build_flags.append("-DSERIAL_BUFFER_SIZE=" + serialBuf) + env.Replace(BUILD_FLAGS=build_flags) diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py index 551f4c6316..7766435fed 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py @@ -4,17 +4,17 @@ import pioutil if pioutil.is_pio_build(): - import os - Import("env", "projenv") + import os + Import("env", "projenv") - flash_size = 0 - vect_tab_addr = 0 + flash_size = 0 + vect_tab_addr = 0 - for define in env['CPPDEFINES']: - if define[0] == "VECT_TAB_ADDR": - vect_tab_addr = define[1] - if define[0] == "STM32_FLASH_SIZE": - flash_size = define[1] + for define in env['CPPDEFINES']: + if define[0] == "VECT_TAB_ADDR": + vect_tab_addr = define[1] + if define[0] == "STM32_FLASH_SIZE": + flash_size = define[1] - print('Use the {0:s} address as the marlin app entry point.'.format(vect_tab_addr)) - print('Use the {0:d}KB flash version of stm32f103rct6 chip.'.format(flash_size)) + print('Use the {0:s} address as the marlin app entry point.'.format(vect_tab_addr)) + print('Use the {0:d}KB flash version of stm32f103rct6 chip.'.format(flash_size)) diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py index c9794702c3..c9fbd9cdc0 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py @@ -3,26 +3,26 @@ # import pioutil if pioutil.is_pio_build(): - import os - from os.path import join - from os.path import expandvars - Import("env") + import os + from os.path import join + from os.path import expandvars + Import("env") - # Custom HEX from ELF - env.AddPostAction( - join("$BUILD_DIR", "${PROGNAME}.elf"), - env.VerboseAction(" ".join([ - "$OBJCOPY", "-O ihex", "$TARGET", - "\"" + join("$BUILD_DIR", "${PROGNAME}.hex") + "\"", # Note: $BUILD_DIR is a full path - ]), "Building $TARGET")) + # Custom HEX from ELF + env.AddPostAction( + join("$BUILD_DIR", "${PROGNAME}.elf"), + env.VerboseAction(" ".join([ + "$OBJCOPY", "-O ihex", "$TARGET", + "\"" + join("$BUILD_DIR", "${PROGNAME}.hex") + "\"", # Note: $BUILD_DIR is a full path + ]), "Building $TARGET")) - # In-line command with arguments - UPLOAD_TOOL="stm32flash" - platform = env.PioPlatform() - if platform.get_package_dir("tool-stm32duino") != None: - UPLOAD_TOOL=expandvars("\"" + join(platform.get_package_dir("tool-stm32duino"),"stm32flash","stm32flash") + "\"") + # In-line command with arguments + UPLOAD_TOOL="stm32flash" + platform = env.PioPlatform() + if platform.get_package_dir("tool-stm32duino") != None: + UPLOAD_TOOL=expandvars("\"" + join(platform.get_package_dir("tool-stm32duino"),"stm32flash","stm32flash") + "\"") - env.Replace( - UPLOADER=UPLOAD_TOOL, - UPLOADCMD=expandvars(UPLOAD_TOOL + " -v -i rts,-dtr,dtr -R -b 115200 -g 0x8000000 -w \"" + join("$BUILD_DIR","${PROGNAME}.hex")+"\"" + " $UPLOAD_PORT") - ) + env.Replace( + UPLOADER=UPLOAD_TOOL, + UPLOADCMD=expandvars(UPLOAD_TOOL + " -v -i rts,-dtr,dtr -R -b 115200 -g 0x8000000 -w \"" + join("$BUILD_DIR","${PROGNAME}.hex")+"\"" + " $UPLOAD_PORT") + ) diff --git a/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py b/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py index 592fa50e5e..e41c15a661 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py +++ b/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py @@ -3,30 +3,30 @@ # import pioutil if pioutil.is_pio_build(): - import os,shutil,marlin - from SCons.Script import DefaultEnvironment - from platformio import util + import os,shutil,marlin + from SCons.Script import DefaultEnvironment + from platformio import util - env = DefaultEnvironment() - platform = env.PioPlatform() - board = env.BoardConfig() + env = DefaultEnvironment() + platform = env.PioPlatform() + board = env.BoardConfig() - FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32-maple") - assert os.path.isdir(FRAMEWORK_DIR) + FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32-maple") + assert os.path.isdir(FRAMEWORK_DIR) - source_root = os.path.join("buildroot", "share", "PlatformIO", "variants") - assert os.path.isdir(source_root) + source_root = os.path.join("buildroot", "share", "PlatformIO", "variants") + assert os.path.isdir(source_root) - variant = board.get("build.variant") - variant_dir = os.path.join(FRAMEWORK_DIR, "STM32F1", "variants", variant) + variant = board.get("build.variant") + variant_dir = os.path.join(FRAMEWORK_DIR, "STM32F1", "variants", variant) - source_dir = os.path.join(source_root, variant) - assert os.path.isdir(source_dir) + source_dir = os.path.join(source_root, variant) + assert os.path.isdir(source_dir) - if os.path.isdir(variant_dir): - shutil.rmtree(variant_dir) + if os.path.isdir(variant_dir): + shutil.rmtree(variant_dir) - if not os.path.isdir(variant_dir): - os.mkdir(variant_dir) + if not os.path.isdir(variant_dir): + os.mkdir(variant_dir) - marlin.copytree(source_dir, variant_dir) + marlin.copytree(source_dir, variant_dir) diff --git a/buildroot/share/PlatformIO/scripts/chitu_crypt.py b/buildroot/share/PlatformIO/scripts/chitu_crypt.py index b28156bfb9..cd909f55bd 100644 --- a/buildroot/share/PlatformIO/scripts/chitu_crypt.py +++ b/buildroot/share/PlatformIO/scripts/chitu_crypt.py @@ -4,114 +4,114 @@ # import pioutil if pioutil.is_pio_build(): - import os,random,struct,uuid,marlin - # Relocate firmware from 0x08000000 to 0x08008800 - marlin.relocate_firmware("0x08008800") + import os,random,struct,uuid,marlin + # Relocate firmware from 0x08000000 to 0x08008800 + marlin.relocate_firmware("0x08008800") - def calculate_crc(contents, seed): - accumulating_xor_value = seed; + def calculate_crc(contents, seed): + accumulating_xor_value = seed; - for i in range(0, len(contents), 4): - value = struct.unpack('> ip + # shift the xor_seed left by the bits in IP. + xor_seed = xor_seed >> ip - # load a byte into IP - ip = r0[loop_counter] + # load a byte into IP + ip = r0[loop_counter] - # XOR the seed with r7 - xor_seed = xor_seed ^ r7 + # XOR the seed with r7 + xor_seed = xor_seed ^ r7 - # and then with IP - xor_seed = xor_seed ^ ip + # and then with IP + xor_seed = xor_seed ^ ip - #Now store the byte back - r1[loop_counter] = xor_seed & 0xFF + #Now store the byte back + r1[loop_counter] = xor_seed & 0xFF - #increment the loop_counter - loop_counter = loop_counter + 1 + #increment the loop_counter + loop_counter = loop_counter + 1 - def encrypt_file(input, output_file, file_length): - input_file = bytearray(input.read()) - block_size = 0x800 - key_length = 0x18 + def encrypt_file(input, output_file, file_length): + input_file = bytearray(input.read()) + block_size = 0x800 + key_length = 0x18 - uid_value = uuid.uuid4() - file_key = int(uid_value.hex[0:8], 16) + uid_value = uuid.uuid4() + file_key = int(uid_value.hex[0:8], 16) - xor_crc = 0xEF3D4323; + xor_crc = 0xEF3D4323; - # the input file is exepcted to be in chunks of 0x800 - # so round the size - while len(input_file) % block_size != 0: - input_file.extend(b'0x0') + # the input file is exepcted to be in chunks of 0x800 + # so round the size + while len(input_file) % block_size != 0: + input_file.extend(b'0x0') - # write the file header - output_file.write(struct.pack(">I", 0x443D2D3F)) - # encrypt the contents using a known file header key + # write the file header + output_file.write(struct.pack(">I", 0x443D2D3F)) + # encrypt the contents using a known file header key - # write the file_key - output_file.write(struct.pack("= level: - print("[deps] %s" % str) + def blab(str,level=1): + if verbose >= level: + print("[deps] %s" % str) - def add_to_feat_cnf(feature, flines): + def add_to_feat_cnf(feature, flines): - try: - feat = FEATURE_CONFIG[feature] - except: - FEATURE_CONFIG[feature] = {} + try: + feat = FEATURE_CONFIG[feature] + except: + FEATURE_CONFIG[feature] = {} - # Get a reference to the FEATURE_CONFIG under construction - feat = FEATURE_CONFIG[feature] + # Get a reference to the FEATURE_CONFIG under construction + feat = FEATURE_CONFIG[feature] - # Split up passed lines on commas or newlines and iterate - # Add common options to the features config under construction - # For lib_deps replace a previous instance of the same library - atoms = re.sub(r',\s*', '\n', flines).strip().split('\n') - for line in atoms: - parts = line.split('=') - name = parts.pop(0) - if name in ['build_flags', 'extra_scripts', 'src_filter', 'lib_ignore']: - feat[name] = '='.join(parts) - blab("[%s] %s=%s" % (feature, name, feat[name]), 3) - else: - for dep in re.split(r',\s*', line): - lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0) - lib_re = re.compile('(?!^' + lib_name + '\\b)') - feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep] - blab("[%s] lib_deps = %s" % (feature, dep), 3) + # Split up passed lines on commas or newlines and iterate + # Add common options to the features config under construction + # For lib_deps replace a previous instance of the same library + atoms = re.sub(r',\s*', '\n', flines).strip().split('\n') + for line in atoms: + parts = line.split('=') + name = parts.pop(0) + if name in ['build_flags', 'extra_scripts', 'src_filter', 'lib_ignore']: + feat[name] = '='.join(parts) + blab("[%s] %s=%s" % (feature, name, feat[name]), 3) + else: + for dep in re.split(r',\s*', line): + lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0) + lib_re = re.compile('(?!^' + lib_name + '\\b)') + feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep] + blab("[%s] lib_deps = %s" % (feature, dep), 3) - def load_features(): - blab("========== Gather [features] entries...") - for key in ProjectConfig().items('features'): - feature = key[0].upper() - if not feature in FEATURE_CONFIG: - FEATURE_CONFIG[feature] = { 'lib_deps': [] } - add_to_feat_cnf(feature, key[1]) + def load_features(): + blab("========== Gather [features] entries...") + for key in ProjectConfig().items('features'): + feature = key[0].upper() + if not feature in FEATURE_CONFIG: + FEATURE_CONFIG[feature] = { 'lib_deps': [] } + add_to_feat_cnf(feature, key[1]) - # Add options matching custom_marlin.MY_OPTION to the pile - blab("========== Gather custom_marlin entries...") - for n in env.GetProjectOptions(): - key = n[0] - mat = re.match(r'custom_marlin\.(.+)', key) - if mat: - try: - val = env.GetProjectOption(key) - except: - val = None - if val: - opt = mat[1].upper() - blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val )) - add_to_feat_cnf(opt, val) + # Add options matching custom_marlin.MY_OPTION to the pile + blab("========== Gather custom_marlin entries...") + for n in env.GetProjectOptions(): + key = n[0] + mat = re.match(r'custom_marlin\.(.+)', key) + if mat: + try: + val = env.GetProjectOption(key) + except: + val = None + if val: + opt = mat[1].upper() + blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val )) + add_to_feat_cnf(opt, val) - def get_all_known_libs(): - known_libs = [] - for feature in FEATURE_CONFIG: - feat = FEATURE_CONFIG[feature] - if not 'lib_deps' in feat: - continue - for dep in feat['lib_deps']: - known_libs.append(PackageSpec(dep).name) - return known_libs + def get_all_known_libs(): + known_libs = [] + for feature in FEATURE_CONFIG: + feat = FEATURE_CONFIG[feature] + if not 'lib_deps' in feat: + continue + for dep in feat['lib_deps']: + known_libs.append(PackageSpec(dep).name) + return known_libs - def get_all_env_libs(): - env_libs = [] - lib_deps = env.GetProjectOption('lib_deps') - for dep in lib_deps: - env_libs.append(PackageSpec(dep).name) - return env_libs + def get_all_env_libs(): + env_libs = [] + lib_deps = env.GetProjectOption('lib_deps') + for dep in lib_deps: + env_libs.append(PackageSpec(dep).name) + return env_libs - def set_env_field(field, value): - proj = env.GetProjectConfig() - proj.set("env:" + env['PIOENV'], field, value) + def set_env_field(field, value): + proj = env.GetProjectConfig() + proj.set("env:" + env['PIOENV'], field, value) - # All unused libs should be ignored so that if a library - # exists in .pio/lib_deps it will not break compilation. - def force_ignore_unused_libs(): - env_libs = get_all_env_libs() - known_libs = get_all_known_libs() - diff = (list(set(known_libs) - set(env_libs))) - lib_ignore = env.GetProjectOption('lib_ignore') + diff - blab("Ignore libraries: %s" % lib_ignore) - set_env_field('lib_ignore', lib_ignore) + # All unused libs should be ignored so that if a library + # exists in .pio/lib_deps it will not break compilation. + def force_ignore_unused_libs(): + env_libs = get_all_env_libs() + known_libs = get_all_known_libs() + diff = (list(set(known_libs) - set(env_libs))) + lib_ignore = env.GetProjectOption('lib_ignore') + diff + blab("Ignore libraries: %s" % lib_ignore) + set_env_field('lib_ignore', lib_ignore) - def apply_features_config(): - load_features() - blab("========== Apply enabled features...") - for feature in FEATURE_CONFIG: - if not env.MarlinHas(feature): - continue + def apply_features_config(): + load_features() + blab("========== Apply enabled features...") + for feature in FEATURE_CONFIG: + if not env.MarlinHas(feature): + continue - feat = FEATURE_CONFIG[feature] + feat = FEATURE_CONFIG[feature] - if 'lib_deps' in feat and len(feat['lib_deps']): - blab("========== Adding lib_deps for %s... " % feature, 2) + if 'lib_deps' in feat and len(feat['lib_deps']): + blab("========== Adding lib_deps for %s... " % feature, 2) - # feat to add - deps_to_add = {} - for dep in feat['lib_deps']: - deps_to_add[PackageSpec(dep).name] = dep - blab("==================== %s... " % dep, 2) + # feat to add + deps_to_add = {} + for dep in feat['lib_deps']: + deps_to_add[PackageSpec(dep).name] = dep + blab("==================== %s... " % dep, 2) - # Does the env already have the dependency? - deps = env.GetProjectOption('lib_deps') - for dep in deps: - name = PackageSpec(dep).name - if name in deps_to_add: - del deps_to_add[name] + # Does the env already have the dependency? + deps = env.GetProjectOption('lib_deps') + for dep in deps: + name = PackageSpec(dep).name + if name in deps_to_add: + del deps_to_add[name] - # Are there any libraries that should be ignored? - lib_ignore = env.GetProjectOption('lib_ignore') - for dep in deps: - name = PackageSpec(dep).name - if name in deps_to_add: - del deps_to_add[name] + # Are there any libraries that should be ignored? + lib_ignore = env.GetProjectOption('lib_ignore') + for dep in deps: + name = PackageSpec(dep).name + if name in deps_to_add: + del deps_to_add[name] - # Is there anything left? - if len(deps_to_add) > 0: - # Only add the missing dependencies - set_env_field('lib_deps', deps + list(deps_to_add.values())) + # Is there anything left? + if len(deps_to_add) > 0: + # Only add the missing dependencies + set_env_field('lib_deps', deps + list(deps_to_add.values())) - if 'build_flags' in feat: - f = feat['build_flags'] - blab("========== Adding build_flags for %s: %s" % (feature, f), 2) - new_flags = env.GetProjectOption('build_flags') + [ f ] - env.Replace(BUILD_FLAGS=new_flags) + if 'build_flags' in feat: + f = feat['build_flags'] + blab("========== Adding build_flags for %s: %s" % (feature, f), 2) + new_flags = env.GetProjectOption('build_flags') + [ f ] + env.Replace(BUILD_FLAGS=new_flags) - if 'extra_scripts' in feat: - blab("Running extra_scripts for %s... " % feature, 2) - env.SConscript(feat['extra_scripts'], exports="env") + if 'extra_scripts' in feat: + blab("Running extra_scripts for %s... " % feature, 2) + env.SConscript(feat['extra_scripts'], exports="env") - if 'src_filter' in feat: - blab("========== Adding build_src_filter for %s... " % feature, 2) - src_filter = ' '.join(env.GetProjectOption('src_filter')) - # first we need to remove the references to the same folder - my_srcs = re.findall(r'[+-](<.*?>)', feat['src_filter']) - cur_srcs = re.findall(r'[+-](<.*?>)', src_filter) - for d in my_srcs: - if d in cur_srcs: - src_filter = re.sub(r'[+-]' + d, '', src_filter) + if 'src_filter' in feat: + blab("========== Adding build_src_filter for %s... " % feature, 2) + src_filter = ' '.join(env.GetProjectOption('src_filter')) + # first we need to remove the references to the same folder + my_srcs = re.findall(r'[+-](<.*?>)', feat['src_filter']) + cur_srcs = re.findall(r'[+-](<.*?>)', src_filter) + for d in my_srcs: + if d in cur_srcs: + src_filter = re.sub(r'[+-]' + d, '', src_filter) - src_filter = feat['src_filter'] + ' ' + src_filter - set_env_field('build_src_filter', [src_filter]) - env.Replace(SRC_FILTER=src_filter) + src_filter = feat['src_filter'] + ' ' + src_filter + set_env_field('build_src_filter', [src_filter]) + env.Replace(SRC_FILTER=src_filter) - if 'lib_ignore' in feat: - blab("========== Adding lib_ignore for %s... " % feature, 2) - lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']] - set_env_field('lib_ignore', lib_ignore) + if 'lib_ignore' in feat: + blab("========== Adding lib_ignore for %s... " % feature, 2) + lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']] + set_env_field('lib_ignore', lib_ignore) - # - # Use the compiler to get a list of all enabled features - # - def load_marlin_features(): - if 'MARLIN_FEATURES' in env: - return + # + # Use the compiler to get a list of all enabled features + # + def load_marlin_features(): + if 'MARLIN_FEATURES' in env: + return - # Process defines - from preprocessor import run_preprocessor - define_list = run_preprocessor(env) - marlin_features = {} - for define in define_list: - feature = define[8:].strip().decode().split(' ') - feature, definition = feature[0], ' '.join(feature[1:]) - marlin_features[feature] = definition - env['MARLIN_FEATURES'] = marlin_features + # Process defines + from preprocessor import run_preprocessor + define_list = run_preprocessor(env) + marlin_features = {} + for define in define_list: + feature = define[8:].strip().decode().split(' ') + feature, definition = feature[0], ' '.join(feature[1:]) + marlin_features[feature] = definition + env['MARLIN_FEATURES'] = marlin_features - # - # Return True if a matching feature is enabled - # - def MarlinHas(env, feature): - load_marlin_features() - r = re.compile('^' + feature + '$') - found = list(filter(r.match, env['MARLIN_FEATURES'])) + # + # Return True if a matching feature is enabled + # + def MarlinHas(env, feature): + load_marlin_features() + r = re.compile('^' + feature + '$') + found = list(filter(r.match, env['MARLIN_FEATURES'])) - # Defines could still be 'false' or '0', so check - some_on = False - if len(found): - for f in found: - val = env['MARLIN_FEATURES'][f] - if val in [ '', '1', 'true' ]: - some_on = True - elif val in env['MARLIN_FEATURES']: - some_on = env.MarlinHas(val) + # Defines could still be 'false' or '0', so check + some_on = False + if len(found): + for f in found: + val = env['MARLIN_FEATURES'][f] + if val in [ '', '1', 'true' ]: + some_on = True + elif val in env['MARLIN_FEATURES']: + some_on = env.MarlinHas(val) - return some_on + return some_on - validate_pio() + validate_pio() - try: - verbose = int(env.GetProjectOption('custom_verbose')) - except: - pass + try: + verbose = int(env.GetProjectOption('custom_verbose')) + except: + pass - # - # Add a method for other PIO scripts to query enabled features - # - env.AddMethod(MarlinHas) + # + # Add a method for other PIO scripts to query enabled features + # + env.AddMethod(MarlinHas) - # - # Add dependencies for enabled Marlin features - # - apply_features_config() - force_ignore_unused_libs() + # + # Add dependencies for enabled Marlin features + # + apply_features_config() + force_ignore_unused_libs() - #print(env.Dump()) + #print(env.Dump()) - from signature import compute_build_signature - compute_build_signature(env) + from signature import compute_build_signature + compute_build_signature(env) diff --git a/buildroot/share/PlatformIO/scripts/custom_board.py b/buildroot/share/PlatformIO/scripts/custom_board.py index da3bdca0bb..7a8fe91be0 100644 --- a/buildroot/share/PlatformIO/scripts/custom_board.py +++ b/buildroot/share/PlatformIO/scripts/custom_board.py @@ -6,13 +6,13 @@ # import pioutil if pioutil.is_pio_build(): - import marlin - board = marlin.env.BoardConfig() + import marlin + board = marlin.env.BoardConfig() - address = board.get("build.address", "") - if address: - marlin.relocate_firmware(address) + address = board.get("build.address", "") + if address: + marlin.relocate_firmware(address) - ldscript = board.get("build.ldscript", "") - if ldscript: - marlin.custom_ld_script(ldscript) + ldscript = board.get("build.ldscript", "") + if ldscript: + marlin.custom_ld_script(ldscript) diff --git a/buildroot/share/PlatformIO/scripts/download_mks_assets.py b/buildroot/share/PlatformIO/scripts/download_mks_assets.py index 1990400222..3984c0baf6 100644 --- a/buildroot/share/PlatformIO/scripts/download_mks_assets.py +++ b/buildroot/share/PlatformIO/scripts/download_mks_assets.py @@ -4,46 +4,46 @@ # import pioutil if pioutil.is_pio_build(): - Import("env") - import os,requests,zipfile,tempfile,shutil + Import("env") + import os,requests,zipfile,tempfile,shutil - url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/0263cdaccf.zip" - deps_path = env.Dictionary("PROJECT_LIBDEPS_DIR") - zip_path = os.path.join(deps_path, "mks-assets.zip") - assets_path = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env.Dictionary("PIOENV"), "assets") + url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/0263cdaccf.zip" + deps_path = env.Dictionary("PROJECT_LIBDEPS_DIR") + zip_path = os.path.join(deps_path, "mks-assets.zip") + assets_path = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env.Dictionary("PIOENV"), "assets") - def download_mks_assets(): - print("Downloading MKS Assets") - r = requests.get(url, stream=True) - # the user may have a very clean workspace, - # so create the PROJECT_LIBDEPS_DIR directory if not exits - if os.path.exists(deps_path) == False: - os.mkdir(deps_path) - with open(zip_path, 'wb') as fd: - for chunk in r.iter_content(chunk_size=128): - fd.write(chunk) + def download_mks_assets(): + print("Downloading MKS Assets") + r = requests.get(url, stream=True) + # the user may have a very clean workspace, + # so create the PROJECT_LIBDEPS_DIR directory if not exits + if os.path.exists(deps_path) == False: + os.mkdir(deps_path) + with open(zip_path, 'wb') as fd: + for chunk in r.iter_content(chunk_size=128): + fd.write(chunk) - def copy_mks_assets(): - print("Copying MKS Assets") - output_path = tempfile.mkdtemp() - zip_obj = zipfile.ZipFile(zip_path, 'r') - zip_obj.extractall(output_path) - zip_obj.close() - if os.path.exists(assets_path) == True and os.path.isdir(assets_path) == False: - os.unlink(assets_path) - if os.path.exists(assets_path) == False: - os.mkdir(assets_path) - base_path = '' - for filename in os.listdir(output_path): - base_path = filename - for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_font')): - shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_font', filename), assets_path) - for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_pic')): - shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_pic', filename), assets_path) - shutil.rmtree(output_path, ignore_errors=True) + def copy_mks_assets(): + print("Copying MKS Assets") + output_path = tempfile.mkdtemp() + zip_obj = zipfile.ZipFile(zip_path, 'r') + zip_obj.extractall(output_path) + zip_obj.close() + if os.path.exists(assets_path) == True and os.path.isdir(assets_path) == False: + os.unlink(assets_path) + if os.path.exists(assets_path) == False: + os.mkdir(assets_path) + base_path = '' + for filename in os.listdir(output_path): + base_path = filename + for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_font')): + shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_font', filename), assets_path) + for filename in os.listdir(os.path.join(output_path, base_path, 'Firmware', 'mks_pic')): + shutil.copy(os.path.join(output_path, base_path, 'Firmware', 'mks_pic', filename), assets_path) + shutil.rmtree(output_path, ignore_errors=True) - if os.path.exists(zip_path) == False: - download_mks_assets() + if os.path.exists(zip_path) == False: + download_mks_assets() - if os.path.exists(assets_path) == False: - copy_mks_assets() + if os.path.exists(assets_path) == False: + copy_mks_assets() diff --git a/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py b/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py index 83ed17ccca..879a7da3d4 100644 --- a/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py +++ b/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py @@ -4,32 +4,32 @@ import pioutil if pioutil.is_pio_build(): - import shutil - from os.path import join, isfile - from pprint import pprint + import shutil + from os.path import join, isfile + from pprint import pprint - Import("env") + Import("env") - if env.MarlinHas("POSTMORTEM_DEBUGGING"): - FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple") - patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done") + if env.MarlinHas("POSTMORTEM_DEBUGGING"): + FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple") + patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done") - # patch file only if we didn't do it before - if not isfile(patchflag_path): - print("Patching libmaple exception handlers") - original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S") - backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak") - src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S") + # patch file only if we didn't do it before + if not isfile(patchflag_path): + print("Patching libmaple exception handlers") + original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S") + backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak") + src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S") - assert isfile(original_file) and isfile(src_file) - shutil.copyfile(original_file, backup_file) - shutil.copyfile(src_file, original_file); + assert isfile(original_file) and isfile(src_file) + shutil.copyfile(original_file, backup_file) + shutil.copyfile(src_file, original_file); - def _touch(path): - with open(path, "w") as fp: - fp.write("") + def _touch(path): + with open(path, "w") as fp: + fp.write("") - env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) - print("Done patching exception handler") + env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) + print("Done patching exception handler") - print("Libmaple modified and ready for post mortem debugging") + print("Libmaple modified and ready for post mortem debugging") diff --git a/buildroot/share/PlatformIO/scripts/generic_create_variant.py b/buildroot/share/PlatformIO/scripts/generic_create_variant.py index 1bd77812f7..2d231907a4 100644 --- a/buildroot/share/PlatformIO/scripts/generic_create_variant.py +++ b/buildroot/share/PlatformIO/scripts/generic_create_variant.py @@ -7,54 +7,54 @@ # import pioutil if pioutil.is_pio_build(): - import os,shutil,marlin - from SCons.Script import DefaultEnvironment - from platformio import util + import os,shutil,marlin + from SCons.Script import DefaultEnvironment + from platformio import util - env = DefaultEnvironment() + env = DefaultEnvironment() - # - # Get the platform name from the 'platform_packages' option, - # or look it up by the platform.class.name. - # - platform = env.PioPlatform() + # + # Get the platform name from the 'platform_packages' option, + # or look it up by the platform.class.name. + # + platform = env.PioPlatform() - from platformio.package.meta import PackageSpec - platform_packages = env.GetProjectOption('platform_packages') + from platformio.package.meta import PackageSpec + platform_packages = env.GetProjectOption('platform_packages') - # Remove all tool items from platform_packages - platform_packages = [x for x in platform_packages if not x.startswith("platformio/tool-")] + # Remove all tool items from platform_packages + platform_packages = [x for x in platform_packages if not x.startswith("platformio/tool-")] - if len(platform_packages) == 0: - framewords = { - "Ststm32Platform": "framework-arduinoststm32", - "AtmelavrPlatform": "framework-arduino-avr" - } - platform_name = framewords[platform.__class__.__name__] - else: - platform_name = PackageSpec(platform_packages[0]).name + if len(platform_packages) == 0: + framewords = { + "Ststm32Platform": "framework-arduinoststm32", + "AtmelavrPlatform": "framework-arduino-avr" + } + platform_name = framewords[platform.__class__.__name__] + else: + platform_name = PackageSpec(platform_packages[0]).name - if platform_name in [ "usb-host-msc", "usb-host-msc-cdc-msc", "usb-host-msc-cdc-msc-2", "usb-host-msc-cdc-msc-3", "tool-stm32duino", "biqu-bx-workaround", "main" ]: - platform_name = "framework-arduinoststm32" + if platform_name in [ "usb-host-msc", "usb-host-msc-cdc-msc", "usb-host-msc-cdc-msc-2", "usb-host-msc-cdc-msc-3", "tool-stm32duino", "biqu-bx-workaround", "main" ]: + platform_name = "framework-arduinoststm32" - FRAMEWORK_DIR = platform.get_package_dir(platform_name) - assert os.path.isdir(FRAMEWORK_DIR) + FRAMEWORK_DIR = platform.get_package_dir(platform_name) + assert os.path.isdir(FRAMEWORK_DIR) - board = env.BoardConfig() + board = env.BoardConfig() - #mcu_type = board.get("build.mcu")[:-2] - variant = board.get("build.variant") - #series = mcu_type[:7].upper() + "xx" + #mcu_type = board.get("build.mcu")[:-2] + variant = board.get("build.variant") + #series = mcu_type[:7].upper() + "xx" - # Prepare a new empty folder at the destination - variant_dir = os.path.join(FRAMEWORK_DIR, "variants", variant) - if os.path.isdir(variant_dir): - shutil.rmtree(variant_dir) - if not os.path.isdir(variant_dir): - os.mkdir(variant_dir) + # Prepare a new empty folder at the destination + variant_dir = os.path.join(FRAMEWORK_DIR, "variants", variant) + if os.path.isdir(variant_dir): + shutil.rmtree(variant_dir) + if not os.path.isdir(variant_dir): + os.mkdir(variant_dir) - # Source dir is a local variant sub-folder - source_dir = os.path.join("buildroot/share/PlatformIO/variants", variant) - assert os.path.isdir(source_dir) + # Source dir is a local variant sub-folder + source_dir = os.path.join("buildroot/share/PlatformIO/variants", variant) + assert os.path.isdir(source_dir) - marlin.copytree(source_dir, variant_dir) + marlin.copytree(source_dir, variant_dir) diff --git a/buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py b/buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py index 0af9c1046d..04a3f1a492 100644 --- a/buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py +++ b/buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py @@ -4,37 +4,37 @@ # import pioutil if pioutil.is_pio_build(): - import os,marlin - # Append ${PROGNAME}.bin firmware after bootloader and save it as 'jgaurora_firmware.bin' - def addboot(source, target, env): - firmware = open(target[0].path, "rb") - lengthfirmware = os.path.getsize(target[0].path) - bootloader_bin = "buildroot/share/PlatformIO/scripts/" + "jgaurora_bootloader.bin" - bootloader = open(bootloader_bin, "rb") - lengthbootloader = os.path.getsize(bootloader_bin) + import os,marlin + # Append ${PROGNAME}.bin firmware after bootloader and save it as 'jgaurora_firmware.bin' + def addboot(source, target, env): + firmware = open(target[0].path, "rb") + lengthfirmware = os.path.getsize(target[0].path) + bootloader_bin = "buildroot/share/PlatformIO/scripts/" + "jgaurora_bootloader.bin" + bootloader = open(bootloader_bin, "rb") + lengthbootloader = os.path.getsize(bootloader_bin) - firmware_with_boothloader_bin = target[0].dir.path + '/firmware_with_bootloader.bin' - if os.path.exists(firmware_with_boothloader_bin): - os.remove(firmware_with_boothloader_bin) - firmwareimage = open(firmware_with_boothloader_bin, "wb") - position = 0 - while position < lengthbootloader: - byte = bootloader.read(1) - firmwareimage.write(byte) - position += 1 - position = 0 - while position < lengthfirmware: - byte = firmware.read(1) - firmwareimage.write(byte) - position += 1 - bootloader.close() - firmware.close() - firmwareimage.close() + firmware_with_boothloader_bin = target[0].dir.path + '/firmware_with_bootloader.bin' + if os.path.exists(firmware_with_boothloader_bin): + os.remove(firmware_with_boothloader_bin) + firmwareimage = open(firmware_with_boothloader_bin, "wb") + position = 0 + while position < lengthbootloader: + byte = bootloader.read(1) + firmwareimage.write(byte) + position += 1 + position = 0 + while position < lengthfirmware: + byte = firmware.read(1) + firmwareimage.write(byte) + position += 1 + bootloader.close() + firmware.close() + firmwareimage.close() - firmware_without_bootloader_bin = target[0].dir.path + '/firmware_for_sd_upload.bin' - if os.path.exists(firmware_without_bootloader_bin): - os.remove(firmware_without_bootloader_bin) - os.rename(target[0].path, firmware_without_bootloader_bin) - #os.rename(target[0].dir.path+'/firmware_with_bootloader.bin', target[0].dir.path+'/firmware.bin') + firmware_without_bootloader_bin = target[0].dir.path + '/firmware_for_sd_upload.bin' + if os.path.exists(firmware_without_bootloader_bin): + os.remove(firmware_without_bootloader_bin) + os.rename(target[0].path, firmware_without_bootloader_bin) + #os.rename(target[0].dir.path+'/firmware_with_bootloader.bin', target[0].dir.path+'/firmware.bin') - marlin.add_post_action(addboot); + marlin.add_post_action(addboot); diff --git a/buildroot/share/PlatformIO/scripts/lerdge.py b/buildroot/share/PlatformIO/scripts/lerdge.py index 06e4543930..0d7f6c4816 100644 --- a/buildroot/share/PlatformIO/scripts/lerdge.py +++ b/buildroot/share/PlatformIO/scripts/lerdge.py @@ -7,43 +7,43 @@ # import pioutil if pioutil.is_pio_build(): - import os,marlin - Import("env") + import os,marlin + Import("env") - from SCons.Script import DefaultEnvironment - board = DefaultEnvironment().BoardConfig() + from SCons.Script import DefaultEnvironment + board = DefaultEnvironment().BoardConfig() - def encryptByte(byte): - byte = 0xFF & ((byte << 6) | (byte >> 2)) - i = 0x58 + byte - j = 0x05 + byte + (i >> 8) - byte = (0xF8 & i) | (0x07 & j) - return byte + def encryptByte(byte): + byte = 0xFF & ((byte << 6) | (byte >> 2)) + i = 0x58 + byte + j = 0x05 + byte + (i >> 8) + byte = (0xF8 & i) | (0x07 & j) + return byte - def encrypt_file(input, output_file, file_length): - input_file = bytearray(input.read()) - for i in range(len(input_file)): - input_file[i] = encryptByte(input_file[i]) - output_file.write(input_file) + def encrypt_file(input, output_file, file_length): + input_file = bytearray(input.read()) + for i in range(len(input_file)): + input_file[i] = encryptByte(input_file[i]) + output_file.write(input_file) - # 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.crypt_lerdge") - print("Encrypting %s to %s" % (fwpath, enname)) - fwfile = open(fwpath, "rb") - enfile = open(target[0].dir.path + "/" + enname, "wb") - length = os.path.getsize(fwpath) + # 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.crypt_lerdge") + print("Encrypting %s to %s" % (fwpath, enname)) + fwfile = open(fwpath, "rb") + enfile = open(target[0].dir.path + "/" + enname, "wb") + length = os.path.getsize(fwpath) - encrypt_file(fwfile, enfile, length) + encrypt_file(fwfile, enfile, length) - fwfile.close() - enfile.close() - os.remove(fwpath) + fwfile.close() + enfile.close() + os.remove(fwpath) - 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.crypt_lerdge = 'filename' parameter") - exit(1) + 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.crypt_lerdge = 'filename' parameter") + exit(1) diff --git a/buildroot/share/PlatformIO/scripts/marlin.py b/buildroot/share/PlatformIO/scripts/marlin.py index 580268c423..ad73eabdfd 100644 --- a/buildroot/share/PlatformIO/scripts/marlin.py +++ b/buildroot/share/PlatformIO/scripts/marlin.py @@ -10,66 +10,66 @@ env = DefaultEnvironment() from os.path import join def copytree(src, dst, symlinks=False, ignore=None): - for item in os.listdir(src): - s = join(src, item) - d = join(dst, item) - if os.path.isdir(s): - shutil.copytree(s, d, symlinks, ignore) - else: - shutil.copy2(s, d) + for item in os.listdir(src): + s = join(src, item) + d = join(dst, item) + if os.path.isdir(s): + shutil.copytree(s, d, symlinks, ignore) + else: + shutil.copy2(s, d) def replace_define(field, value): - for define in env['CPPDEFINES']: - if define[0] == field: - env['CPPDEFINES'].remove(define) - env['CPPDEFINES'].append((field, value)) + for define in env['CPPDEFINES']: + if define[0] == field: + env['CPPDEFINES'].remove(define) + env['CPPDEFINES'].append((field, value)) # Relocate the firmware to a new address, such as "0x08005000" def relocate_firmware(address): - replace_define("VECT_TAB_ADDR", address) + replace_define("VECT_TAB_ADDR", address) # Relocate the vector table with a new offset def relocate_vtab(address): - replace_define("VECT_TAB_OFFSET", address) + replace_define("VECT_TAB_OFFSET", address) # Replace the existing -Wl,-T with the given ldscript path def custom_ld_script(ldname): - apath = os.path.abspath("buildroot/share/PlatformIO/ldscripts/" + ldname) - for i, flag in enumerate(env["LINKFLAGS"]): - if "-Wl,-T" in flag: - env["LINKFLAGS"][i] = "-Wl,-T" + apath - elif flag == "-T": - env["LINKFLAGS"][i + 1] = apath + apath = os.path.abspath("buildroot/share/PlatformIO/ldscripts/" + ldname) + for i, flag in enumerate(env["LINKFLAGS"]): + if "-Wl,-T" in flag: + env["LINKFLAGS"][i] = "-Wl,-T" + apath + elif flag == "-T": + env["LINKFLAGS"][i + 1] = apath # 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 + import sys - key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E] + key = [0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80, 0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33, 0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF, 0xF7, 0x3E] - # If FIRMWARE_BIN is defined by config, override all - mf = env["MARLIN_FEATURES"] - if "FIRMWARE_BIN" in mf: new_name = mf["FIRMWARE_BIN"] + # If FIRMWARE_BIN is defined by config, override all + mf = env["MARLIN_FEATURES"] + if "FIRMWARE_BIN" in mf: new_name = mf["FIRMWARE_BIN"] - fwpath = target[0].path - fwfile = open(fwpath, "rb") - enfile = open(target[0].dir.path + "/" + new_name, "wb") - length = os.path.getsize(fwpath) - position = 0 - try: - while position < length: - byte = fwfile.read(1) - if position >= 320 and position < 31040: - byte = chr(ord(byte) ^ key[position & 31]) - if sys.version_info[0] > 2: - byte = bytes(byte, 'latin1') - enfile.write(byte) - position += 1 - finally: - fwfile.close() - enfile.close() - os.remove(fwpath) + fwpath = target[0].path + fwfile = open(fwpath, "rb") + enfile = open(target[0].dir.path + "/" + new_name, "wb") + length = os.path.getsize(fwpath) + position = 0 + try: + while position < length: + byte = fwfile.read(1) + if position >= 320 and position < 31040: + byte = chr(ord(byte) ^ key[position & 31]) + if sys.version_info[0] > 2: + byte = bytes(byte, 'latin1') + enfile.write(byte) + position += 1 + finally: + fwfile.close() + enfile.close() + os.remove(fwpath) def add_post_action(action): - env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action); + env.AddPostAction(join("$BUILD_DIR", "${PROGNAME}.bin"), action); diff --git a/buildroot/share/PlatformIO/scripts/mc-apply.py b/buildroot/share/PlatformIO/scripts/mc-apply.py index f71d192679..ed0ed795c6 100755 --- a/buildroot/share/PlatformIO/scripts/mc-apply.py +++ b/buildroot/share/PlatformIO/scripts/mc-apply.py @@ -11,59 +11,59 @@ opt_output = '--opt' in sys.argv output_suffix = '.sh' if opt_output else '' if '--bare-output' in sys.argv else '.gen' try: - with open('marlin_config.json', 'r') as infile: - conf = json.load(infile) - for key in conf: - # We don't care about the hash when restoring here - if key == '__INITIAL_HASH': - continue - if key == 'VERSION': - for k, v in sorted(conf[key].items()): - print(k + ': ' + v) - continue - # The key is the file name, so let's build it now - outfile = open('Marlin/' + key + output_suffix, 'w') - for k, v in sorted(conf[key].items()): - # Make define line now - if opt_output: - if v != '': - if '"' in v: - v = "'%s'" % v - elif ' ' in v: - v = '"%s"' % v - define = 'opt_set ' + k + ' ' + v + '\n' - else: - define = 'opt_enable ' + k + '\n' - else: - define = '#define ' + k + ' ' + v + '\n' - outfile.write(define) - outfile.close() + with open('marlin_config.json', 'r') as infile: + conf = json.load(infile) + for key in conf: + # We don't care about the hash when restoring here + if key == '__INITIAL_HASH': + continue + if key == 'VERSION': + for k, v in sorted(conf[key].items()): + print(k + ': ' + v) + continue + # The key is the file name, so let's build it now + outfile = open('Marlin/' + key + output_suffix, 'w') + for k, v in sorted(conf[key].items()): + # Make define line now + if opt_output: + if v != '': + if '"' in v: + v = "'%s'" % v + elif ' ' in v: + v = '"%s"' % v + define = 'opt_set ' + k + ' ' + v + '\n' + else: + define = 'opt_enable ' + k + '\n' + else: + define = '#define ' + k + ' ' + v + '\n' + outfile.write(define) + outfile.close() - # Try to apply changes to the actual configuration file (in order to keep useful comments) - if output_suffix != '': - # Move the existing configuration so it doesn't interfere - shutil.move('Marlin/' + key, 'Marlin/' + key + '.orig') - infile_lines = open('Marlin/' + key + '.orig', 'r').read().split('\n') - outfile = open('Marlin/' + key, 'w') - for line in infile_lines: - sline = line.strip(" \t\n\r") - if sline[:7] == "#define": - # Extract the key here (we don't care about the value) - kv = sline[8:].strip().split(' ') - if kv[0] in conf[key]: - outfile.write('#define ' + kv[0] + ' ' + conf[key][kv[0]] + '\n') - # Remove the key from the dict, so we can still write all missing keys at the end of the file - del conf[key][kv[0]] - else: - outfile.write(line + '\n') - else: - outfile.write(line + '\n') - # Process any remaining defines here - for k, v in sorted(conf[key].items()): - define = '#define ' + k + ' ' + v + '\n' - outfile.write(define) - outfile.close() + # Try to apply changes to the actual configuration file (in order to keep useful comments) + if output_suffix != '': + # Move the existing configuration so it doesn't interfere + shutil.move('Marlin/' + key, 'Marlin/' + key + '.orig') + infile_lines = open('Marlin/' + key + '.orig', 'r').read().split('\n') + outfile = open('Marlin/' + key, 'w') + for line in infile_lines: + sline = line.strip(" \t\n\r") + if sline[:7] == "#define": + # Extract the key here (we don't care about the value) + kv = sline[8:].strip().split(' ') + if kv[0] in conf[key]: + outfile.write('#define ' + kv[0] + ' ' + conf[key][kv[0]] + '\n') + # Remove the key from the dict, so we can still write all missing keys at the end of the file + del conf[key][kv[0]] + else: + outfile.write(line + '\n') + else: + outfile.write(line + '\n') + # Process any remaining defines here + for k, v in sorted(conf[key].items()): + define = '#define ' + k + ' ' + v + '\n' + outfile.write(define) + outfile.close() - print('Output configuration written to: ' + 'Marlin/' + key + output_suffix) + print('Output configuration written to: ' + 'Marlin/' + key + output_suffix) except: - print('No marlin_config.json found.') + print('No marlin_config.json found.') diff --git a/buildroot/share/PlatformIO/scripts/offset_and_rename.py b/buildroot/share/PlatformIO/scripts/offset_and_rename.py index 6f44524619..7d4b0fb504 100644 --- a/buildroot/share/PlatformIO/scripts/offset_and_rename.py +++ b/buildroot/share/PlatformIO/scripts/offset_and_rename.py @@ -2,61 +2,61 @@ # offset_and_rename.py # # - If 'build.offset' is provided, either by JSON or by the environment... -# - Set linker flag LD_FLASH_OFFSET and relocate the VTAB based on 'build.offset'. -# - Set linker flag LD_MAX_DATA_SIZE based on 'build.maximum_ram_size'. -# - Define STM32_FLASH_SIZE from 'upload.maximum_size' for use by Flash-based EEPROM emulation. +# - Set linker flag LD_FLASH_OFFSET and relocate the VTAB based on 'build.offset'. +# - Set linker flag LD_MAX_DATA_SIZE based on 'build.maximum_ram_size'. +# - Define STM32_FLASH_SIZE from 'upload.maximum_size' for use by Flash-based EEPROM emulation. # # - For 'board_build.rename' add a post-action to rename the firmware file. # import pioutil if pioutil.is_pio_build(): - import os,sys,marlin - Import("env") + import os,sys,marlin + Import("env") - from SCons.Script import DefaultEnvironment - board = DefaultEnvironment().BoardConfig() + from SCons.Script import DefaultEnvironment + board = DefaultEnvironment().BoardConfig() - board_keys = board.get("build").keys() + board_keys = board.get("build").keys() - # - # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld - # - if 'offset' in board_keys: - LD_FLASH_OFFSET = board.get("build.offset") - marlin.relocate_vtab(LD_FLASH_OFFSET) + # + # For build.offset define LD_FLASH_OFFSET, used by ldscript.ld + # + if 'offset' in board_keys: + LD_FLASH_OFFSET = board.get("build.offset") + marlin.relocate_vtab(LD_FLASH_OFFSET) - # Flash size - maximum_flash_size = int(board.get("upload.maximum_size") / 1024) - marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size) + # Flash size + maximum_flash_size = int(board.get("upload.maximum_size") / 1024) + marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size) - # Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json) - maximum_ram_size = board.get("upload.maximum_ram_size") + # Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json) + maximum_ram_size = board.get("upload.maximum_ram_size") - for i, flag in enumerate(env["LINKFLAGS"]): - if "-Wl,--defsym=LD_FLASH_OFFSET" in flag: - env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET - if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag: - env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40) + for i, flag in enumerate(env["LINKFLAGS"]): + if "-Wl,--defsym=LD_FLASH_OFFSET" in flag: + env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET + if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag: + env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40) - # - # For build.encrypt_mks rename and encode the firmware file. - # - if 'encrypt_mks' in board_keys: + # + # For build.encrypt_mks rename and encode the firmware file. + # + if 'encrypt_mks' in board_keys: - # 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_mks")) + # 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_mks")) - if board.get("build.encrypt_mks") != "": - marlin.add_post_action(encrypt) + if board.get("build.encrypt_mks") != "": + marlin.add_post_action(encrypt) - # - # For build.rename simply rename the firmware file. - # - if 'rename' in board_keys: + # + # For build.rename simply rename the firmware file. + # + if 'rename' in board_keys: - def rename_target(source, target, env): - firmware = os.path.join(target[0].dir.path, board.get("build.rename")) - os.replace(target[0].path, firmware) + def rename_target(source, target, env): + firmware = os.path.join(target[0].dir.path, board.get("build.rename")) + os.replace(target[0].path, firmware) - marlin.add_post_action(rename_target) + marlin.add_post_action(rename_target) diff --git a/buildroot/share/PlatformIO/scripts/openblt.py b/buildroot/share/PlatformIO/scripts/openblt.py index 33e82898f7..104bd142ca 100644 --- a/buildroot/share/PlatformIO/scripts/openblt.py +++ b/buildroot/share/PlatformIO/scripts/openblt.py @@ -3,18 +3,18 @@ # import pioutil if pioutil.is_pio_build(): - import os,sys - from os.path import join + import os,sys + from os.path import join - Import("env") + Import("env") - board = env.BoardConfig() - board_keys = board.get("build").keys() - if 'encode' in board_keys: - env.AddPostAction( - join("$BUILD_DIR", "${PROGNAME}.bin"), - env.VerboseAction(" ".join([ - "$OBJCOPY", "-O", "srec", - "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"" + join("$BUILD_DIR", board.get("build.encode")) + "\"" - ]), "Building " + board.get("build.encode")) - ) + board = env.BoardConfig() + board_keys = board.get("build").keys() + if 'encode' in board_keys: + env.AddPostAction( + join("$BUILD_DIR", "${PROGNAME}.bin"), + env.VerboseAction(" ".join([ + "$OBJCOPY", "-O", "srec", + "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"" + join("$BUILD_DIR", board.get("build.encode")) + "\"" + ]), "Building " + board.get("build.encode")) + ) diff --git a/buildroot/share/PlatformIO/scripts/pioutil.py b/buildroot/share/PlatformIO/scripts/pioutil.py index 32096dab3f..5ae28a62f3 100644 --- a/buildroot/share/PlatformIO/scripts/pioutil.py +++ b/buildroot/share/PlatformIO/scripts/pioutil.py @@ -4,10 +4,10 @@ # Make sure 'vscode init' is not the current command def is_pio_build(): - from SCons.Script import DefaultEnvironment - env = DefaultEnvironment() - return not env.IsIntegrationDump() + from SCons.Script import DefaultEnvironment + env = DefaultEnvironment() + return not env.IsIntegrationDump() def get_pio_version(): - from platformio import util - return util.pioversion_to_intstr() + from platformio import util + return util.pioversion_to_intstr() diff --git a/buildroot/share/PlatformIO/scripts/preflight-checks.py b/buildroot/share/PlatformIO/scripts/preflight-checks.py index d0f1c138c9..25eee7e29d 100644 --- a/buildroot/share/PlatformIO/scripts/preflight-checks.py +++ b/buildroot/share/PlatformIO/scripts/preflight-checks.py @@ -5,115 +5,115 @@ import pioutil if pioutil.is_pio_build(): - import os,re,sys - Import("env") + import os,re,sys + Import("env") - def get_envs_for_board(board): - with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file: + def get_envs_for_board(board): + with open(os.path.join("Marlin", "src", "pins", "pins.h"), "r") as file: - if sys.platform == 'win32': - envregex = r"(?:env|win):" - elif sys.platform == 'darwin': - envregex = r"(?:env|mac|uni):" - elif sys.platform == 'linux': - envregex = r"(?:env|lin|uni):" - else: - envregex = r"(?:env):" + if sys.platform == 'win32': + envregex = r"(?:env|win):" + elif sys.platform == 'darwin': + envregex = r"(?:env|mac|uni):" + elif sys.platform == 'linux': + envregex = r"(?:env|lin|uni):" + else: + envregex = r"(?:env):" - r = re.compile(r"if\s+MB\((.+)\)") - if board.startswith("BOARD_"): - board = board[6:] + r = re.compile(r"if\s+MB\((.+)\)") + if board.startswith("BOARD_"): + board = board[6:] - for line in file: - mbs = r.findall(line) - if mbs and board in re.split(r",\s*", mbs[0]): - line = file.readline() - found_envs = re.match(r"\s*#include .+" + envregex, line) - if found_envs: - envlist = re.findall(envregex + r"(\w+)", line) - return [ "env:"+s for s in envlist ] - return [] + for line in file: + mbs = r.findall(line) + if mbs and board in re.split(r",\s*", mbs[0]): + line = file.readline() + found_envs = re.match(r"\s*#include .+" + envregex, line) + if found_envs: + envlist = re.findall(envregex + r"(\w+)", line) + return [ "env:"+s for s in envlist ] + return [] - def check_envs(build_env, board_envs, config): - if build_env in board_envs: - return True - ext = config.get(build_env, 'extends', default=None) - if ext: - if isinstance(ext, str): - return check_envs(ext, board_envs, config) - elif isinstance(ext, list): - for ext_env in ext: - if check_envs(ext_env, board_envs, config): - return True - return False + def check_envs(build_env, board_envs, config): + if build_env in board_envs: + return True + ext = config.get(build_env, 'extends', default=None) + if ext: + if isinstance(ext, str): + return check_envs(ext, board_envs, config) + elif isinstance(ext, list): + for ext_env in ext: + if check_envs(ext_env, board_envs, config): + return True + return False - def sanity_check_target(): - # Sanity checks: - if 'PIOENV' not in env: - raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO") + def sanity_check_target(): + # Sanity checks: + if 'PIOENV' not in env: + raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO") - if 'MARLIN_FEATURES' not in env: - raise SystemExit("Error: this script should be used after common Marlin scripts") + if 'MARLIN_FEATURES' not in env: + raise SystemExit("Error: this script should be used after common Marlin scripts") - if 'MOTHERBOARD' not in env['MARLIN_FEATURES']: - raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h") + if 'MOTHERBOARD' not in env['MARLIN_FEATURES']: + raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h") - build_env = env['PIOENV'] - motherboard = env['MARLIN_FEATURES']['MOTHERBOARD'] - board_envs = get_envs_for_board(motherboard) - config = env.GetProjectConfig() - result = check_envs("env:"+build_env, board_envs, config) + build_env = env['PIOENV'] + motherboard = env['MARLIN_FEATURES']['MOTHERBOARD'] + board_envs = get_envs_for_board(motherboard) + config = env.GetProjectConfig() + result = check_envs("env:"+build_env, board_envs, config) - if not result: - err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \ - ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) ) - raise SystemExit(err) + if not result: + err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \ + ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) ) + raise SystemExit(err) - # - # Check for Config files in two common incorrect places - # - for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: - for f in [ "Configuration.h", "Configuration_adv.h" ]: - if os.path.isfile(os.path.join(p, f)): - err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p - raise SystemExit(err) + # + # Check for Config files in two common incorrect places + # + for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: + for f in [ "Configuration.h", "Configuration_adv.h" ]: + if os.path.isfile(os.path.join(p, f)): + err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p + raise SystemExit(err) - # - # Find the name.cpp.o or name.o and remove it - # - def rm_ofile(subdir, name): - build_dir = os.path.join(env['PROJECT_BUILD_DIR'], build_env); - for outdir in [ build_dir, os.path.join(build_dir, "debug") ]: - for ext in [ ".cpp.o", ".o" ]: - fpath = os.path.join(outdir, "src", "src", subdir, name + ext) - if os.path.exists(fpath): - os.remove(fpath) + # + # Find the name.cpp.o or name.o and remove it + # + def rm_ofile(subdir, name): + build_dir = os.path.join(env['PROJECT_BUILD_DIR'], build_env); + for outdir in [ build_dir, os.path.join(build_dir, "debug") ]: + for ext in [ ".cpp.o", ".o" ]: + fpath = os.path.join(outdir, "src", "src", subdir, name + ext) + if os.path.exists(fpath): + os.remove(fpath) - # - # Give warnings on every build - # - rm_ofile("inc", "Warnings") + # + # Give warnings on every build + # + rm_ofile("inc", "Warnings") - # - # Rebuild 'settings.cpp' for EEPROM_INIT_NOW - # - if 'EEPROM_INIT_NOW' in env['MARLIN_FEATURES']: - rm_ofile("module", "settings") + # + # Rebuild 'settings.cpp' for EEPROM_INIT_NOW + # + if 'EEPROM_INIT_NOW' in env['MARLIN_FEATURES']: + rm_ofile("module", "settings") - # - # Check for old files indicating an entangled Marlin (mixing old and new code) - # - mixedin = [] - p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "lcd", "dogm") - for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]: - if os.path.isfile(os.path.join(p, f)): - mixedin += [ f ] - p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "feature", "bedlevel", "abl") - for f in [ "abl.cpp", "abl.h" ]: - if os.path.isfile(os.path.join(p, f)): - mixedin += [ f ] - if mixedin: - err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin) - raise SystemExit(err) + # + # Check for old files indicating an entangled Marlin (mixing old and new code) + # + mixedin = [] + p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "lcd", "dogm") + for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]: + if os.path.isfile(os.path.join(p, f)): + mixedin += [ f ] + p = os.path.join(env['PROJECT_DIR'], "Marlin", "src", "feature", "bedlevel", "abl") + for f in [ "abl.cpp", "abl.h" ]: + if os.path.isfile(os.path.join(p, f)): + mixedin += [ f ] + if mixedin: + err = "ERROR: Old files fell into your Marlin folder. Remove %s and try again" % ", ".join(mixedin) + raise SystemExit(err) - sanity_check_target() + sanity_check_target() diff --git a/buildroot/share/PlatformIO/scripts/preprocessor.py b/buildroot/share/PlatformIO/scripts/preprocessor.py index d0395cd481..96f63a49eb 100644 --- a/buildroot/share/PlatformIO/scripts/preprocessor.py +++ b/buildroot/share/PlatformIO/scripts/preprocessor.py @@ -7,8 +7,8 @@ nocache = 1 verbose = 0 def blab(str): - if verbose: - print(str) + if verbose: + print(str) ################################################################################ # @@ -16,36 +16,36 @@ def blab(str): # preprocessor_cache = {} def run_preprocessor(env, fn=None): - filename = fn or 'buildroot/share/PlatformIO/scripts/common-dependencies.h' - if filename in preprocessor_cache: - return preprocessor_cache[filename] + filename = fn or 'buildroot/share/PlatformIO/scripts/common-dependencies.h' + if filename in preprocessor_cache: + return preprocessor_cache[filename] - # Process defines - build_flags = env.get('BUILD_FLAGS') - build_flags = env.ParseFlagsExtended(build_flags) + # Process defines + build_flags = env.get('BUILD_FLAGS') + build_flags = env.ParseFlagsExtended(build_flags) - cxx = search_compiler(env) - cmd = ['"' + cxx + '"'] + cxx = search_compiler(env) + cmd = ['"' + cxx + '"'] - # Build flags from board.json - #if 'BOARD' in env: - # cmd += [env.BoardConfig().get("build.extra_flags")] - for s in build_flags['CPPDEFINES']: - if isinstance(s, tuple): - cmd += ['-D' + s[0] + '=' + str(s[1])] - else: - cmd += ['-D' + s] + # Build flags from board.json + #if 'BOARD' in env: + # cmd += [env.BoardConfig().get("build.extra_flags")] + for s in build_flags['CPPDEFINES']: + if isinstance(s, tuple): + cmd += ['-D' + s[0] + '=' + str(s[1])] + else: + cmd += ['-D' + s] - cmd += ['-D__MARLIN_DEPS__ -w -dM -E -x c++'] - depcmd = cmd + [ filename ] - cmd = ' '.join(depcmd) - blab(cmd) - try: - define_list = subprocess.check_output(cmd, shell=True).splitlines() - except: - define_list = {} - preprocessor_cache[filename] = define_list - return define_list + cmd += ['-D__MARLIN_DEPS__ -w -dM -E -x c++'] + depcmd = cmd + [ filename ] + cmd = ' '.join(depcmd) + blab(cmd) + try: + define_list = subprocess.check_output(cmd, shell=True).splitlines() + except: + define_list = {} + preprocessor_cache[filename] = define_list + return define_list ################################################################################ @@ -54,51 +54,51 @@ def run_preprocessor(env, fn=None): # def search_compiler(env): - ENV_BUILD_PATH = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV']) - GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path") + ENV_BUILD_PATH = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV']) + GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path") - try: - filepath = env.GetProjectOption('custom_gcc') - blab("Getting compiler from env") - return filepath - except: - pass + try: + filepath = env.GetProjectOption('custom_gcc') + blab("Getting compiler from env") + return filepath + except: + pass - # Warning: The cached .gcc_path will obscure a newly-installed toolkit - if not nocache and os.path.exists(GCC_PATH_CACHE): - blab("Getting g++ path from cache") - with open(GCC_PATH_CACHE, 'r') as f: - return f.read() + # Warning: The cached .gcc_path will obscure a newly-installed toolkit + if not nocache and os.path.exists(GCC_PATH_CACHE): + blab("Getting g++ path from cache") + with open(GCC_PATH_CACHE, 'r') as f: + return f.read() - # Find the current platform compiler by searching the $PATH - # which will be in a platformio toolchain bin folder - path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) - gcc = "g++" - if env['PLATFORM'] == 'win32': - path_separator = ';' - path_regex += r'.*\\bin' - gcc += ".exe" - else: - path_separator = ':' - path_regex += r'/.+/bin' + # Find the current platform compiler by searching the $PATH + # which will be in a platformio toolchain bin folder + path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + gcc = "g++" + if env['PLATFORM'] == 'win32': + path_separator = ';' + path_regex += r'.*\\bin' + gcc += ".exe" + else: + path_separator = ':' + path_regex += r'/.+/bin' - # Search for the compiler - for pathdir in env['ENV']['PATH'].split(path_separator): - if not re.search(path_regex, pathdir, re.IGNORECASE): - continue - for filepath in os.listdir(pathdir): - if not filepath.endswith(gcc): - continue - # Use entire path to not rely on env PATH - filepath = os.path.sep.join([pathdir, filepath]) - # Cache the g++ path to no search always - if not nocache and os.path.exists(ENV_BUILD_PATH): - blab("Caching g++ for current env") - with open(GCC_PATH_CACHE, 'w+') as f: - f.write(filepath) + # Search for the compiler + for pathdir in env['ENV']['PATH'].split(path_separator): + if not re.search(path_regex, pathdir, re.IGNORECASE): + continue + for filepath in os.listdir(pathdir): + if not filepath.endswith(gcc): + continue + # Use entire path to not rely on env PATH + filepath = os.path.sep.join([pathdir, filepath]) + # Cache the g++ path to no search always + if not nocache and os.path.exists(ENV_BUILD_PATH): + blab("Caching g++ for current env") + with open(GCC_PATH_CACHE, 'w+') as f: + f.write(filepath) - return filepath + return filepath - filepath = env.get('CXX') - blab("Couldn't find a compiler! Fallback to %s" % filepath) - return filepath + filepath = env.get('CXX') + blab("Couldn't find a compiler! Fallback to %s" % filepath) + return filepath diff --git a/buildroot/share/PlatformIO/scripts/random-bin.py b/buildroot/share/PlatformIO/scripts/random-bin.py index 5a88906c30..dc8634ea7d 100644 --- a/buildroot/share/PlatformIO/scripts/random-bin.py +++ b/buildroot/share/PlatformIO/scripts/random-bin.py @@ -4,6 +4,6 @@ # import pioutil if pioutil.is_pio_build(): - from datetime import datetime - Import("env") - env['PROGNAME'] = datetime.now().strftime("firmware-%Y%m%d-%H%M%S") + from datetime import datetime + Import("env") + env['PROGNAME'] = datetime.now().strftime("firmware-%Y%m%d-%H%M%S") diff --git a/buildroot/share/PlatformIO/scripts/signature.py b/buildroot/share/PlatformIO/scripts/signature.py index f1c86bb839..41f17fd3b6 100644 --- a/buildroot/share/PlatformIO/scripts/signature.py +++ b/buildroot/share/PlatformIO/scripts/signature.py @@ -12,32 +12,32 @@ import os,subprocess,re,json,hashlib # resulting config.ini to produce more exact configuration files. # def extract_defines(filepath): - f = open(filepath, encoding="utf8").read().split("\n") - a = [] - for line in f: - sline = line.strip() - if sline[:7] == "#define": - # Extract the key here (we don't care about the value) - kv = sline[8:].strip().split() - a.append(kv[0]) - return a + f = open(filepath, encoding="utf8").read().split("\n") + a = [] + for line in f: + sline = line.strip() + if sline[:7] == "#define": + # Extract the key here (we don't care about the value) + kv = sline[8:].strip().split() + a.append(kv[0]) + return a # Compute the SHA256 hash of a file def get_file_sha256sum(filepath): - sha256_hash = hashlib.sha256() - with open(filepath,"rb") as f: - # Read and update hash string value in blocks of 4K - for byte_block in iter(lambda: f.read(4096),b""): - sha256_hash.update(byte_block) - return sha256_hash.hexdigest() + sha256_hash = hashlib.sha256() + with open(filepath,"rb") as f: + # Read and update hash string value in blocks of 4K + for byte_block in iter(lambda: f.read(4096),b""): + sha256_hash.update(byte_block) + return sha256_hash.hexdigest() # # Compress a JSON file into a zip file # import zipfile def compress_file(filepath, outputbase): - with zipfile.ZipFile(outputbase + '.zip', 'w', compression=zipfile.ZIP_BZIP2, compresslevel=9) as zipf: - zipf.write(filepath, compress_type=zipfile.ZIP_BZIP2, compresslevel=9) + with zipfile.ZipFile(outputbase + '.zip', 'w', compression=zipfile.ZIP_BZIP2, compresslevel=9) as zipf: + zipf.write(filepath, compress_type=zipfile.ZIP_BZIP2, compresslevel=9) # # Compute the build signature. The idea is to extract all defines in the configuration headers @@ -45,139 +45,139 @@ def compress_file(filepath, outputbase): # We can reverse the signature to get a 1:1 equivalent configuration file # def compute_build_signature(env): - if 'BUILD_SIGNATURE' in env: - return + if 'BUILD_SIGNATURE' in env: + return - # Definitions from these files will be kept - files_to_keep = [ 'Marlin/Configuration.h', 'Marlin/Configuration_adv.h' ] + # Definitions from these files will be kept + files_to_keep = [ 'Marlin/Configuration.h', 'Marlin/Configuration_adv.h' ] - build_dir = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV']) + build_dir = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV']) - # Check if we can skip processing - hashes = '' - for header in files_to_keep: - hashes += get_file_sha256sum(header)[0:10] + # Check if we can skip processing + hashes = '' + for header in files_to_keep: + hashes += get_file_sha256sum(header)[0:10] - marlin_json = os.path.join(build_dir, 'marlin_config.json') - marlin_zip = os.path.join(build_dir, 'mc') + marlin_json = os.path.join(build_dir, 'marlin_config.json') + marlin_zip = os.path.join(build_dir, 'mc') - # Read existing config file - try: - with open(marlin_json, 'r') as infile: - conf = json.load(infile) - if conf['__INITIAL_HASH'] == hashes: - # Same configuration, skip recomputing the building signature - compress_file(marlin_json, marlin_zip) - return - except: - pass + # Read existing config file + try: + with open(marlin_json, 'r') as infile: + conf = json.load(infile) + if conf['__INITIAL_HASH'] == hashes: + # Same configuration, skip recomputing the building signature + compress_file(marlin_json, marlin_zip) + return + except: + pass - # Get enabled config options based on preprocessor - from preprocessor import run_preprocessor - complete_cfg = run_preprocessor(env) + # Get enabled config options based on preprocessor + from preprocessor import run_preprocessor + complete_cfg = run_preprocessor(env) - # Dumb #define extraction from the configuration files - conf_defines = {} - all_defines = [] - for header in files_to_keep: - defines = extract_defines(header) - # To filter only the define we want - all_defines += defines - # To remember from which file it cames from - conf_defines[header.split('/')[-1]] = defines + # Dumb #define extraction from the configuration files + conf_defines = {} + all_defines = [] + for header in files_to_keep: + defines = extract_defines(header) + # To filter only the define we want + all_defines += defines + # To remember from which file it cames from + conf_defines[header.split('/')[-1]] = defines - r = re.compile(r"\(+(\s*-*\s*_.*)\)+") + r = re.compile(r"\(+(\s*-*\s*_.*)\)+") - # First step is to collect all valid macros - defines = {} - for line in complete_cfg: + # First step is to collect all valid macros + defines = {} + for line in complete_cfg: - # Split the define from the value - key_val = line[8:].strip().decode().split(' ') - key, value = key_val[0], ' '.join(key_val[1:]) + # Split the define from the value + key_val = line[8:].strip().decode().split(' ') + key, value = key_val[0], ' '.join(key_val[1:]) - # Ignore values starting with two underscore, since it's low level - if len(key) > 2 and key[0:2] == "__" : - continue - # Ignore values containing a parenthesis (likely a function macro) - if '(' in key and ')' in key: - continue + # Ignore values starting with two underscore, since it's low level + if len(key) > 2 and key[0:2] == "__" : + continue + # Ignore values containing a parenthesis (likely a function macro) + if '(' in key and ')' in key: + continue - # Then filter dumb values - if r.match(value): - continue + # Then filter dumb values + if r.match(value): + continue - defines[key] = value if len(value) else "" + defines[key] = value if len(value) else "" - if not 'CONFIGURATION_EMBEDDING' in defines: - return + if not 'CONFIGURATION_EMBEDDING' in defines: + return - # Second step is to filter useless macro - resolved_defines = {} - for key in defines: - # Remove all boards now - if key.startswith("BOARD_") and key != "BOARD_INFO_NAME": - continue - # Remove all keys ending by "_NAME" as it does not make a difference to the configuration - if key.endswith("_NAME") and key != "CUSTOM_MACHINE_NAME": - continue - # Remove all keys ending by "_T_DECLARED" as it's a copy of extraneous system stuff - if key.endswith("_T_DECLARED"): - continue - # Remove keys that are not in the #define list in the Configuration list - if key not in all_defines + [ 'DETAILED_BUILD_VERSION', 'STRING_DISTRIBUTION_DATE' ]: - continue + # Second step is to filter useless macro + resolved_defines = {} + for key in defines: + # Remove all boards now + if key.startswith("BOARD_") and key != "BOARD_INFO_NAME": + continue + # Remove all keys ending by "_NAME" as it does not make a difference to the configuration + if key.endswith("_NAME") and key != "CUSTOM_MACHINE_NAME": + continue + # Remove all keys ending by "_T_DECLARED" as it's a copy of extraneous system stuff + if key.endswith("_T_DECLARED"): + continue + # Remove keys that are not in the #define list in the Configuration list + if key not in all_defines + [ 'DETAILED_BUILD_VERSION', 'STRING_DISTRIBUTION_DATE' ]: + continue - # Don't be that smart guy here - resolved_defines[key] = defines[key] + # Don't be that smart guy here + resolved_defines[key] = defines[key] - # Generate a build signature now - # We are making an object that's a bit more complex than a basic dictionary here - data = {} - data['__INITIAL_HASH'] = hashes - # First create a key for each header here - for header in conf_defines: - data[header] = {} + # Generate a build signature now + # We are making an object that's a bit more complex than a basic dictionary here + data = {} + data['__INITIAL_HASH'] = hashes + # First create a key for each header here + for header in conf_defines: + data[header] = {} - # Then populate the object where each key is going to (that's a O(N^2) algorithm here...) - for key in resolved_defines: - for header in conf_defines: - if key in conf_defines[header]: - data[header][key] = resolved_defines[key] + # Then populate the object where each key is going to (that's a O(N^2) algorithm here...) + for key in resolved_defines: + for header in conf_defines: + if key in conf_defines[header]: + data[header][key] = resolved_defines[key] - # Append the source code version and date - data['VERSION'] = {} - data['VERSION']['DETAILED_BUILD_VERSION'] = resolved_defines['DETAILED_BUILD_VERSION'] - data['VERSION']['STRING_DISTRIBUTION_DATE'] = resolved_defines['STRING_DISTRIBUTION_DATE'] - try: - curver = subprocess.check_output(["git", "describe", "--match=NeVeRmAtCh", "--always"]).strip() - data['VERSION']['GIT_REF'] = curver.decode() - except: - pass + # Append the source code version and date + data['VERSION'] = {} + data['VERSION']['DETAILED_BUILD_VERSION'] = resolved_defines['DETAILED_BUILD_VERSION'] + data['VERSION']['STRING_DISTRIBUTION_DATE'] = resolved_defines['STRING_DISTRIBUTION_DATE'] + try: + curver = subprocess.check_output(["git", "describe", "--match=NeVeRmAtCh", "--always"]).strip() + data['VERSION']['GIT_REF'] = curver.decode() + except: + pass - # - # Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_DUMP > 0 - # - with open(marlin_json, 'w') as outfile: - json.dump(data, outfile, separators=(',', ':')) + # + # Produce a JSON file for CONFIGURATION_EMBEDDING or CONFIG_DUMP > 0 + # + with open(marlin_json, 'w') as outfile: + json.dump(data, outfile, separators=(',', ':')) - # Compress the JSON file as much as we can - compress_file(marlin_json, marlin_zip) + # Compress the JSON file as much as we can + compress_file(marlin_json, marlin_zip) - # Generate a C source file for storing this array - with open('Marlin/src/mczip.h','wb') as result_file: - result_file.write( - b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n' - + b' #warning "Generated file \'mc.zip\' is embedded (Define NO_CONFIGURATION_EMBEDDING_WARNING to suppress this warning.)"\n' - + b'#endif\n' - + b'const unsigned char mc_zip[] PROGMEM = {\n ' - ) - count = 0 - for b in open(os.path.join(build_dir, 'mc.zip'), 'rb').read(): - result_file.write(b' 0x%02X,' % b) - count += 1 - if (count % 16 == 0): - result_file.write(b'\n ') - if (count % 16): - result_file.write(b'\n') - result_file.write(b'};\n') + # Generate a C source file for storing this array + with open('Marlin/src/mczip.h','wb') as result_file: + result_file.write( + b'#ifndef NO_CONFIGURATION_EMBEDDING_WARNING\n' + + b' #warning "Generated file \'mc.zip\' is embedded (Define NO_CONFIGURATION_EMBEDDING_WARNING to suppress this warning.)"\n' + + b'#endif\n' + + b'const unsigned char mc_zip[] PROGMEM = {\n ' + ) + count = 0 + for b in open(os.path.join(build_dir, 'mc.zip'), 'rb').read(): + result_file.write(b' 0x%02X,' % b) + count += 1 + if (count % 16 == 0): + result_file.write(b'\n ') + if (count % 16): + result_file.write(b'\n') + result_file.write(b'};\n') diff --git a/buildroot/share/PlatformIO/scripts/simulator.py b/buildroot/share/PlatformIO/scripts/simulator.py index 2961d2826d..b3a8d67a66 100644 --- a/buildroot/share/PlatformIO/scripts/simulator.py +++ b/buildroot/share/PlatformIO/scripts/simulator.py @@ -4,49 +4,49 @@ # import pioutil if pioutil.is_pio_build(): - # Get the environment thus far for the build - Import("env") + # Get the environment thus far for the build + Import("env") - #print(env.Dump()) + #print(env.Dump()) - # - # Give the binary a distinctive name - # + # + # Give the binary a distinctive name + # - env['PROGNAME'] = "MarlinSimulator" + env['PROGNAME'] = "MarlinSimulator" - # - # If Xcode is installed add the path to its Frameworks folder, - # or if Mesa is installed try to use its GL/gl.h. - # + # + # If Xcode is installed add the path to its Frameworks folder, + # or if Mesa is installed try to use its GL/gl.h. + # - import sys - if sys.platform == 'darwin': + import sys + if sys.platform == 'darwin': - # - # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS') - # - env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ] + # + # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS') + # + env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ] - # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa - xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" - mesa_path = "/opt/local/include/GL/gl.h" + # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa + xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" + mesa_path = "/opt/local/include/GL/gl.h" - import os.path + import os.path - if os.path.exists(xcode_path): + if os.path.exists(xcode_path): - env['BUILD_FLAGS'] += [ "-F" + xcode_path ] - print("Using OpenGL framework headers from Xcode.app") + env['BUILD_FLAGS'] += [ "-F" + xcode_path ] + print("Using OpenGL framework headers from Xcode.app") - elif os.path.exists(mesa_path): + elif os.path.exists(mesa_path): - env['BUILD_FLAGS'] += [ '-D__MESA__' ] - print("Using OpenGL header from", mesa_path) + env['BUILD_FLAGS'] += [ '-D__MESA__' ] + print("Using OpenGL header from", mesa_path) - else: + else: - print("\n\nNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h.\n\n") + print("\n\nNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h.\n\n") - # Break out of the PIO build immediately - sys.exit(1) + # Break out of the PIO build immediately + sys.exit(1) diff --git a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py index 033803009e..1f5f6eec78 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py +++ b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py @@ -3,59 +3,59 @@ # import pioutil if pioutil.is_pio_build(): - Import("env") + Import("env") - # Get a build flag's value or None - def getBuildFlagValue(name): - for flag in build_flags: - if isinstance(flag, list) and flag[0] == name: - return flag[1] + # Get a build flag's value or None + def getBuildFlagValue(name): + for flag in build_flags: + if isinstance(flag, list) and flag[0] == name: + return flag[1] - return None + return None - # Get an overriding buffer size for RX or TX from the build flags - def getInternalSize(side): - return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \ - getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \ - getBuildFlagValue(f"USART_{side}_BUF_SIZE") + # Get an overriding buffer size for RX or TX from the build flags + def getInternalSize(side): + return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"USART_{side}_BUF_SIZE") - # Get the largest defined buffer size for RX or TX - def getBufferSize(side, default): - # Get a build flag value or fall back to the given default - internal = int(getInternalSize(side) or default) - flag = side + "_BUFFER_SIZE" - # Return the largest value - return max(int(mf[flag]), internal) if flag in mf else internal + # Get the largest defined buffer size for RX or TX + def getBufferSize(side, default): + # Get a build flag value or fall back to the given default + internal = int(getInternalSize(side) or default) + flag = side + "_BUFFER_SIZE" + # Return the largest value + return max(int(mf[flag]), internal) if flag in mf else internal - # Add a build flag if it's not already defined - def tryAddFlag(name, value): - if getBuildFlagValue(name) is None: - env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) + # Add a build flag if it's not already defined + def tryAddFlag(name, value): + if getBuildFlagValue(name) is None: + env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) - # Marlin uses the `RX_BUFFER_SIZE` \ `TX_BUFFER_SIZE` options to - # configure buffer sizes for receiving \ transmitting serial data. - # Stm32duino uses another set of defines for the same purpose, so this - # script gets the values from the configuration and uses them to define - # `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE` as global build - # flags so they are available for use by the platform. - # - # The script will set the value as the default one (64 bytes) - # or the user-configured one, whichever is higher. - # - # Marlin's default buffer sizes are 128 for RX and 32 for TX. - # The highest value is taken (128/64). - # - # If MF_*_BUFFER_SIZE, SERIAL_*_BUFFER_SIZE, USART_*_BUF_SIZE, are - # defined, the first of these values will be used as the minimum. - build_flags = env.ParseFlags(env.get('BUILD_FLAGS'))["CPPDEFINES"] - mf = env["MARLIN_FEATURES"] + # Marlin uses the `RX_BUFFER_SIZE` \ `TX_BUFFER_SIZE` options to + # configure buffer sizes for receiving \ transmitting serial data. + # Stm32duino uses another set of defines for the same purpose, so this + # script gets the values from the configuration and uses them to define + # `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE` as global build + # flags so they are available for use by the platform. + # + # The script will set the value as the default one (64 bytes) + # or the user-configured one, whichever is higher. + # + # Marlin's default buffer sizes are 128 for RX and 32 for TX. + # The highest value is taken (128/64). + # + # If MF_*_BUFFER_SIZE, SERIAL_*_BUFFER_SIZE, USART_*_BUF_SIZE, are + # defined, the first of these values will be used as the minimum. + build_flags = env.ParseFlags(env.get('BUILD_FLAGS'))["CPPDEFINES"] + mf = env["MARLIN_FEATURES"] - # Get the largest defined buffer sizes for RX or TX, using defaults for undefined - rxBuf = getBufferSize("RX", 128) - txBuf = getBufferSize("TX", 64) + # Get the largest defined buffer sizes for RX or TX, using defaults for undefined + rxBuf = getBufferSize("RX", 128) + txBuf = getBufferSize("TX", 64) - # Provide serial buffer sizes to the stm32duino platform - tryAddFlag("SERIAL_RX_BUFFER_SIZE", rxBuf) - tryAddFlag("SERIAL_TX_BUFFER_SIZE", txBuf) - tryAddFlag("USART_RX_BUF_SIZE", rxBuf) - tryAddFlag("USART_TX_BUF_SIZE", txBuf) + # Provide serial buffer sizes to the stm32duino platform + tryAddFlag("SERIAL_RX_BUFFER_SIZE", rxBuf) + tryAddFlag("SERIAL_TX_BUFFER_SIZE", txBuf) + tryAddFlag("USART_RX_BUF_SIZE", rxBuf) + tryAddFlag("USART_TX_BUF_SIZE", txBuf) diff --git a/buildroot/share/scripts/config-labels.py b/buildroot/share/scripts/config-labels.py index 700604e452..0fdf540b0d 100755 --- a/buildroot/share/scripts/config-labels.py +++ b/buildroot/share/scripts/config-labels.py @@ -47,152 +47,152 @@ different_out_dir = not (output_examples_dir == input_examples_dir) #---------------------------------------------- def process_file(subdir: str, filename: str): #---------------------------------------------- - global filenum - filenum += 1 + global filenum + filenum += 1 - print(str(filenum) + ' ' + filename + ': ' + subdir) + print(str(filenum) + ' ' + filename + ': ' + subdir) - def_line = (def_macro_name + ' "' + subdir.replace('\\', '/') + '"') + def_line = (def_macro_name + ' "' + subdir.replace('\\', '/') + '"') - #------------------------ - # Read file - #------------------------ - lines = [] - infilepath = os.path.join(input_examples_dir, subdir, filename) - try: - # UTF-8 because some files contain unicode chars - with open(infilepath, 'rt', encoding="utf-8") as infile: - lines = infile.readlines() + #------------------------ + # Read file + #------------------------ + lines = [] + infilepath = os.path.join(input_examples_dir, subdir, filename) + try: + # UTF-8 because some files contain unicode chars + with open(infilepath, 'rt', encoding="utf-8") as infile: + lines = infile.readlines() - except Exception as e: - print('Failed to read file: ' + str(e) ) - raise Exception + except Exception as e: + print('Failed to read file: ' + str(e) ) + raise Exception - lines = [line.rstrip('\r\n') for line in lines] + lines = [line.rstrip('\r\n') for line in lines] - #------------------------ - # Process lines - #------------------------ - file_modified = False + #------------------------ + # Process lines + #------------------------ + file_modified = False - # region state machine - # -1 = before pragma once; - # 0 = region to place define; - # 1 = past region to place define - region = -1 + # region state machine + # -1 = before pragma once; + # 0 = region to place define; + # 1 = past region to place define + region = -1 - outlines = [] - for line in lines: - outline = line + outlines = [] + for line in lines: + outline = line - if (region == -1) and (def_macro_name in line): - outline = None - file_modified = True + if (region == -1) and (def_macro_name in line): + outline = None + file_modified = True - elif (region == -1) and ('pragma once' in line): - region = 0 + elif (region == -1) and ('pragma once' in line): + region = 0 - elif (region == 0): - if (line.strip() == ''): - pass - elif (def_macro_name in line): - region = 1 - if line == def_line: # leave it as is - pass - else: - outline = def_line - file_modified = True - else: # some other string - outlines.append(def_line) - outlines.append('') - region = 1 - file_modified = True + elif (region == 0): + if (line.strip() == ''): + pass + elif (def_macro_name in line): + region = 1 + if line == def_line: # leave it as is + pass + else: + outline = def_line + file_modified = True + else: # some other string + outlines.append(def_line) + outlines.append('') + region = 1 + file_modified = True - elif (region == 1): - if (def_macro_name in line): - outline = None - file_modified = True - else: - pass + elif (region == 1): + if (def_macro_name in line): + outline = None + file_modified = True + else: + pass - # end if - if outline is not None: - outlines.append(outline) - # end for + # end if + if outline is not None: + outlines.append(outline) + # end for - #------------------------- - # Output file - #------------------------- - outdir = os.path.join(output_examples_dir, subdir) - outfilepath = os.path.join(outdir, filename) + #------------------------- + # Output file + #------------------------- + outdir = os.path.join(output_examples_dir, subdir) + outfilepath = os.path.join(outdir, filename) - if file_modified: - # Note: no need to create output dirs, as the initial copy_tree - # will do that. + if file_modified: + # Note: no need to create output dirs, as the initial copy_tree + # will do that. - print(' writing ' + str(outfilepath)) - try: - # Preserve unicode chars; Avoid CR-LF on Windows. - with open(outfilepath, "w", encoding="utf-8", newline='\n') as outfile: - outfile.write("\n".join(outlines)) - outfile.write("\n") + print(' writing ' + str(outfilepath)) + try: + # Preserve unicode chars; Avoid CR-LF on Windows. + with open(outfilepath, "w", encoding="utf-8", newline='\n') as outfile: + outfile.write("\n".join(outlines)) + outfile.write("\n") - except Exception as e: - print('Failed to write file: ' + str(e) ) - raise Exception - else: - print(' no change for ' + str(outfilepath)) + except Exception as e: + print('Failed to write file: ' + str(e) ) + raise Exception + else: + print(' no change for ' + str(outfilepath)) #---------- def main(): #---------- - global filenum - global input_examples_dir - global output_examples_dir - filenum = 0 + global filenum + global input_examples_dir + global output_examples_dir + filenum = 0 - #-------------------------------- - # Check for requirements - #-------------------------------- - input_examples_dir = input_examples_dir.strip() - input_examples_dir = input_examples_dir.rstrip('\\/') - output_examples_dir = output_examples_dir.strip() - output_examples_dir = output_examples_dir.rstrip('\\/') + #-------------------------------- + # Check for requirements + #-------------------------------- + input_examples_dir = input_examples_dir.strip() + input_examples_dir = input_examples_dir.rstrip('\\/') + output_examples_dir = output_examples_dir.strip() + output_examples_dir = output_examples_dir.rstrip('\\/') - for dir in [input_examples_dir, output_examples_dir]: - if not (os.path.exists(dir)): - print('Directory not found: ' + dir) - sys.exit(1) + for dir in [input_examples_dir, output_examples_dir]: + if not (os.path.exists(dir)): + print('Directory not found: ' + dir) + sys.exit(1) - #-------------------------------- - # Copy tree if necessary. - #-------------------------------- - # This includes files that are not otherwise included in the - # insertion of the define statement. - # - if different_out_dir: - print('Copying files to new directory: ' + output_examples_dir) - try: - copy_tree(input_examples_dir, output_examples_dir) - except Exception as e: - print('Failed to copy directory: ' + str(e) ) - raise Exception + #-------------------------------- + # Copy tree if necessary. + #-------------------------------- + # This includes files that are not otherwise included in the + # insertion of the define statement. + # + if different_out_dir: + print('Copying files to new directory: ' + output_examples_dir) + try: + copy_tree(input_examples_dir, output_examples_dir) + except Exception as e: + print('Failed to copy directory: ' + str(e) ) + raise Exception - #----------------------------- - # Find and process files - #----------------------------- - len_input_examples_dir = len(input_examples_dir); - len_input_examples_dir += 1 + #----------------------------- + # Find and process files + #----------------------------- + len_input_examples_dir = len(input_examples_dir); + len_input_examples_dir += 1 - for filename in files_to_mod: - input_path = Path(input_examples_dir) - filepathlist = input_path.rglob(filename) + for filename in files_to_mod: + input_path = Path(input_examples_dir) + filepathlist = input_path.rglob(filename) - for filepath in filepathlist: - fulldirpath = str(filepath.parent) - subdir = fulldirpath[len_input_examples_dir:] + for filepath in filepathlist: + fulldirpath = str(filepath.parent) + subdir = fulldirpath[len_input_examples_dir:] - process_file(subdir, filename) + process_file(subdir, filename) #============== print('--- Starting config-labels ---') diff --git a/buildroot/share/scripts/gen-tft-image.py b/buildroot/share/scripts/gen-tft-image.py index d89245fea4..ddbab236ee 100644 --- a/buildroot/share/scripts/gen-tft-image.py +++ b/buildroot/share/scripts/gen-tft-image.py @@ -26,38 +26,38 @@ import sys,re,struct from PIL import Image,ImageDraw def image2bin(image, output_file): - if output_file.endswith(('.c', '.cpp')): - f = open(output_file, 'wt') - is_cpp = True - f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0])) - else: - f = open(output_file, 'wb') - is_cpp = False - pixs = image.load() - for y in range(image.size[1]): - for x in range(image.size[0]): - R = pixs[x, y][0] >> 3 - G = pixs[x, y][1] >> 2 - B = pixs[x, y][2] >> 3 - rgb = (R << 11) | (G << 5) | B - if is_cpp: - strHex = '0x{0:04X}, '.format(rgb) - f.write(strHex) - else: - f.write(struct.pack("B", (rgb & 0xFF))) - f.write(struct.pack("B", (rgb >> 8) & 0xFF)) - if is_cpp: - f.write("\n") - if is_cpp: - f.write("};\n") - f.close() + if output_file.endswith(('.c', '.cpp')): + f = open(output_file, 'wt') + is_cpp = True + f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0])) + else: + f = open(output_file, 'wb') + is_cpp = False + pixs = image.load() + for y in range(image.size[1]): + for x in range(image.size[0]): + R = pixs[x, y][0] >> 3 + G = pixs[x, y][1] >> 2 + B = pixs[x, y][2] >> 3 + rgb = (R << 11) | (G << 5) | B + if is_cpp: + strHex = '0x{0:04X}, '.format(rgb) + f.write(strHex) + else: + f.write(struct.pack("B", (rgb & 0xFF))) + f.write(struct.pack("B", (rgb >> 8) & 0xFF)) + if is_cpp: + f.write("\n") + if is_cpp: + f.write("};\n") + f.close() if len(sys.argv) <= 2: - print("Utility to export a image in Marlin TFT friendly format.") - print("It will dump a raw bin RGB565 image or create a CPP file with an array of 16 bit image pixels.") - print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin)") - print("Author: rhapsodyv") - exit(1) + print("Utility to export a image in Marlin TFT friendly format.") + print("It will dump a raw bin RGB565 image or create a CPP file with an array of 16 bit image pixels.") + print("Usage: gen-tft-image.py INPUT_IMAGE.(png|bmp|jpg) OUTPUT_FILE.(cpp|bin)") + print("Author: rhapsodyv") + exit(1) output_img = sys.argv[2] img = Image.open(sys.argv[1]) diff --git a/get_test_targets.py b/get_test_targets.py index ce2080eba0..a38e3a594a 100755 --- a/get_test_targets.py +++ b/get_test_targets.py @@ -6,7 +6,7 @@ import yaml with open('.github/workflows/test-builds.yml') as f: - github_configuration = yaml.safe_load(f) + github_configuration = yaml.safe_load(f) test_platforms = github_configuration\ - ['jobs']['test_builds']['strategy']['matrix']['test-platform'] + ['jobs']['test_builds']['strategy']['matrix']['test-platform'] print(' '.join(test_platforms))