Robby Candra
3 years ago
committed by
Scott Lahteine
37 changed files with 1116 additions and 1082 deletions
@ -1,123 +1,127 @@ |
|||
# |
|||
# sets output_port |
|||
# upload_extra_script.py |
|||
# set the output_port |
|||
# if target_filename is found then that drive is used |
|||
# else if target_drive is found then that drive is used |
|||
# |
|||
from __future__ import print_function |
|||
|
|||
target_filename = "FIRMWARE.CUR" |
|||
target_drive = "REARM" |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
|
|||
import os,getpass,platform |
|||
target_filename = "FIRMWARE.CUR" |
|||
target_drive = "REARM" |
|||
|
|||
current_OS = platform.system() |
|||
Import("env") |
|||
import os,getpass,platform |
|||
|
|||
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'))) |
|||
current_OS = platform.system() |
|||
Import("env") |
|||
|
|||
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': |
|||
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 |
|||
# |
|||
# 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 |
|||
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: |
|||
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 |
|||
target_file_found = True |
|||
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: |
|||
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" |
|||
) |
|||
|
|||
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: |
|||
files = os.listdir(os.path.join(os.sep, 'media', getpass.getuser(), drive)) |
|||
filenames = os.listdir('/Volumes/' + drive + '/') # will get an error if the drive is protected |
|||
except: |
|||
continue |
|||
else: |
|||
if target_filename in files: |
|||
upload_disk = os.path.join(os.sep, 'media', getpass.getuser(), drive) + os.sep |
|||
if target_filename in filenames: |
|||
if not target_file_found: |
|||
upload_disk = '/Volumes/' + drive + '/' |
|||
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" |
|||
) |
|||
|
|||
elif current_OS == 'Darwin': # MAC |
|||
# |
|||
# platformio.ini will accept this for a OSX upload port designation: 'upload_port = /media/media_name/drive' |
|||
# Set upload_port to drive if found |
|||
# |
|||
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') |
|||
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) |
|||
|
@ -1,40 +1,43 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py |
|||
# STM32F103RC_MEEB_3DP.py |
|||
# |
|||
try: |
|||
import configparser |
|||
except ImportError: |
|||
import ConfigParser as configparser |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
|
|||
import os |
|||
Import("env", "projenv") |
|||
try: |
|||
import configparser |
|||
except ImportError: |
|||
import ConfigParser as configparser |
|||
|
|||
config = configparser.ConfigParser() |
|||
config.read("platformio.ini") |
|||
import os |
|||
Import("env", "projenv") |
|||
|
|||
# |
|||
# Upload actions |
|||
# |
|||
def before_upload(source, target, env): |
|||
env.Execute("pwd") |
|||
config = configparser.ConfigParser() |
|||
config.read("platformio.ini") |
|||
|
|||
# |
|||
# Upload actions |
|||
# |
|||
def before_upload(source, target, env): |
|||
env.Execute("pwd") |
|||
|
|||
def after_upload(source, target, env): |
|||
env.Execute("pwd") |
|||
def after_upload(source, target, env): |
|||
env.Execute("pwd") |
|||
|
|||
env.AddPreAction("upload", before_upload) |
|||
env.AddPostAction("upload", after_upload) |
|||
env.AddPreAction("upload", before_upload) |
|||
env.AddPostAction("upload", after_upload) |
|||
|
|||
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)) |
|||
|
|||
import marlin |
|||
marlin.custom_ld_script("STM32F103RC_MEEB_3DP.ld") |
|||
import marlin |
|||
marlin.custom_ld_script("STM32F103RC_MEEB_3DP.ld") |
|||
|
@ -1,25 +1,28 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py |
|||
# STM32F103RC_fysetc.py |
|||
# |
|||
from os.path import join |
|||
from os.path import expandvars |
|||
Import("env") |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
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") |
|||
) |
|||
|
@ -1,30 +1,32 @@ |
|||
# |
|||
# STM32F1_create_variant.py |
|||
# |
|||
import os,shutil,marlin |
|||
from SCons.Script import DefaultEnvironment |
|||
from platformio import util |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
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) |
|||
|
@ -1,116 +1,117 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/chitu_crypt.py |
|||
# chitu_crypt.py |
|||
# Customizations for Chitu boards |
|||
# |
|||
import os,random,struct,uuid,marlin |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
import os,random,struct,uuid,marlin |
|||
# Relocate firmware from 0x08000000 to 0x08008800 |
|||
marlin.relocate_firmware("0x08008800") |
|||
|
|||
# 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('<I', contents[ i : i + 4])[0] |
|||
accumulating_xor_value = accumulating_xor_value ^ value |
|||
return accumulating_xor_value |
|||
|
|||
for i in range(0, len(contents), 4): |
|||
value = struct.unpack('<I', contents[ i : i + 4])[0] |
|||
accumulating_xor_value = accumulating_xor_value ^ value |
|||
return accumulating_xor_value |
|||
def xor_block(r0, r1, block_number, block_size, file_key): |
|||
# This is the loop counter |
|||
loop_counter = 0x0 |
|||
|
|||
def xor_block(r0, r1, block_number, block_size, file_key): |
|||
# This is the loop counter |
|||
loop_counter = 0x0 |
|||
# This is the key length |
|||
key_length = 0x18 |
|||
|
|||
# This is the key length |
|||
key_length = 0x18 |
|||
# This is an initial seed |
|||
xor_seed = 0x4BAD |
|||
|
|||
# This is an initial seed |
|||
xor_seed = 0x4BAD |
|||
# This is the block counter |
|||
block_number = xor_seed * block_number |
|||
|
|||
# This is the block counter |
|||
block_number = xor_seed * block_number |
|||
#load the xor key from the file |
|||
r7 = file_key |
|||
|
|||
#load the xor key from the file |
|||
r7 = file_key |
|||
for loop_counter in range(0, block_size): |
|||
# meant to make sure different bits of the key are used. |
|||
xor_seed = int(loop_counter / key_length) |
|||
|
|||
for loop_counter in range(0, block_size): |
|||
# meant to make sure different bits of the key are used. |
|||
xor_seed = int(loop_counter / key_length) |
|||
# IP is a scratch register / R12 |
|||
ip = loop_counter - (key_length * xor_seed) |
|||
|
|||
# IP is a scratch register / R12 |
|||
ip = loop_counter - (key_length * xor_seed) |
|||
# xor_seed = (loop_counter * loop_counter) + block_number |
|||
xor_seed = (loop_counter * loop_counter) + block_number |
|||
|
|||
# xor_seed = (loop_counter * loop_counter) + block_number |
|||
xor_seed = (loop_counter * loop_counter) + block_number |
|||
# shift the xor_seed left by the bits in IP. |
|||
xor_seed = xor_seed >> 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("<I", file_key)) |
|||
|
|||
# write the file_key |
|||
output_file.write(struct.pack("<I", file_key)) |
|||
#TODO - how to enforce that the firmware aligns to block boundaries? |
|||
block_count = int(len(input_file) / block_size) |
|||
print ("Block Count is ", block_count) |
|||
for block_number in range(0, block_count): |
|||
block_offset = (block_number * block_size) |
|||
block_end = block_offset + block_size |
|||
block_array = bytearray(input_file[block_offset: block_end]) |
|||
xor_block(block_array, block_array, block_number, block_size, file_key) |
|||
for n in range (0, block_size): |
|||
input_file[block_offset + n] = block_array[n] |
|||
|
|||
#TODO - how to enforce that the firmware aligns to block boundaries? |
|||
block_count = int(len(input_file) / block_size) |
|||
print ("Block Count is ", block_count) |
|||
for block_number in range(0, block_count): |
|||
block_offset = (block_number * block_size) |
|||
block_end = block_offset + block_size |
|||
block_array = bytearray(input_file[block_offset: block_end]) |
|||
xor_block(block_array, block_array, block_number, block_size, file_key) |
|||
for n in range (0, block_size): |
|||
input_file[block_offset + n] = block_array[n] |
|||
# update the expected CRC value. |
|||
xor_crc = calculate_crc(block_array, xor_crc) |
|||
|
|||
# update the expected CRC value. |
|||
xor_crc = calculate_crc(block_array, xor_crc) |
|||
# write CRC |
|||
output_file.write(struct.pack("<I", xor_crc)) |
|||
|
|||
# write CRC |
|||
output_file.write(struct.pack("<I", xor_crc)) |
|||
# finally, append the encrypted results. |
|||
output_file.write(input_file) |
|||
return |
|||
|
|||
# finally, append the encrypted results. |
|||
output_file.write(input_file) |
|||
return |
|||
# Encrypt ${PROGNAME}.bin and save it as 'update.cbd' |
|||
def encrypt(source, target, env): |
|||
firmware = open(target[0].path, "rb") |
|||
update = open(target[0].dir.path + '/update.cbd', "wb") |
|||
length = os.path.getsize(target[0].path) |
|||
|
|||
# Encrypt ${PROGNAME}.bin and save it as 'update.cbd' |
|||
def encrypt(source, target, env): |
|||
firmware = open(target[0].path, "rb") |
|||
update = open(target[0].dir.path + '/update.cbd', "wb") |
|||
length = os.path.getsize(target[0].path) |
|||
encrypt_file(firmware, update, length) |
|||
|
|||
encrypt_file(firmware, update, length) |
|||
firmware.close() |
|||
update.close() |
|||
|
|||
firmware.close() |
|||
update.close() |
|||
|
|||
marlin.add_post_action(encrypt); |
|||
marlin.add_post_action(encrypt); |
|||
|
@ -1,16 +1,16 @@ |
|||
# |
|||
# common-dependencies-post.py |
|||
# post:common-dependencies-post.py |
|||
# Convenience script to add build flags for Marlin Enabled Features |
|||
# |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
Import("env", "projenv") |
|||
|
|||
Import("env") |
|||
Import("projenv") |
|||
def apply_board_build_flags(): |
|||
if not 'BOARD_CUSTOM_BUILD_FLAGS' in env['MARLIN_FEATURES']: |
|||
return |
|||
projenv.Append(CCFLAGS=env['MARLIN_FEATURES']['BOARD_CUSTOM_BUILD_FLAGS'].split()) |
|||
|
|||
def apply_board_build_flags(): |
|||
if not 'BOARD_CUSTOM_BUILD_FLAGS' in env['MARLIN_FEATURES']: |
|||
return |
|||
projenv.Append(CCFLAGS=env['MARLIN_FEATURES']['BOARD_CUSTOM_BUILD_FLAGS'].split()) |
|||
|
|||
# We need to add the board build flags in a post script |
|||
# so the platform build script doesn't overwrite the custom CCFLAGS |
|||
apply_board_build_flags() |
|||
# We need to add the board build flags in a post script |
|||
# so the platform build script doesn't overwrite the custom CCFLAGS |
|||
apply_board_build_flags() |
|||
|
@ -1,16 +1,18 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/custom_board.py |
|||
# custom_board.py |
|||
# |
|||
# - For build.address replace VECT_TAB_ADDR to relocate the firmware |
|||
# - For build.ldscript use one of the linker scripts in buildroot/share/PlatformIO/ldscripts |
|||
# |
|||
import marlin |
|||
board = marlin.env.BoardConfig() |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
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) |
|||
|
@ -1,51 +1,49 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/download_mks_assets.py |
|||
# download_mks_assets.py |
|||
# Added by HAS_TFT_LVGL_UI to download assets from Makerbase repo |
|||
# |
|||
Import("env") |
|||
import os,requests,zipfile,tempfile,shutil,pioutil |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
Import("env") |
|||
import os,requests,zipfile,tempfile,shutil |
|||
|
|||
# Detect that 'vscode init' is running |
|||
if pioutil.is_vscode_init(): |
|||
env.Exit(0) |
|||
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() |
|||
|
@ -1,32 +1,35 @@ |
|||
# |
|||
# fix_framework_weakness.py |
|||
# |
|||
from os.path import join, isfile |
|||
import shutil |
|||
from pprint import pprint |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
|
|||
Import("env") |
|||
import shutil |
|||
from os.path import join, isfile |
|||
from pprint import pprint |
|||
|
|||
if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"): |
|||
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple") |
|||
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done") |
|||
Import("env") |
|||
|
|||
# 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") |
|||
if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"): |
|||
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple") |
|||
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done") |
|||
|
|||
assert isfile(original_file) and isfile(src_file) |
|||
shutil.copyfile(original_file, backup_file) |
|||
shutil.copyfile(src_file, original_file); |
|||
# 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") |
|||
|
|||
def _touch(path): |
|||
with open(path, "w") as fp: |
|||
fp.write("") |
|||
assert isfile(original_file) and isfile(src_file) |
|||
shutil.copyfile(original_file, backup_file) |
|||
shutil.copyfile(src_file, original_file); |
|||
|
|||
env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) |
|||
print("Done patching exception handler") |
|||
def _touch(path): |
|||
with open(path, "w") as fp: |
|||
fp.write("") |
|||
|
|||
print("Libmaple modified and ready for post mortem debugging") |
|||
env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) |
|||
print("Done patching exception handler") |
|||
|
|||
print("Libmaple modified and ready for post mortem debugging") |
|||
|
@ -1,39 +1,40 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/jgaurora_a5s_a1_with_bootloader.py |
|||
# jgaurora_a5s_a1_with_bootloader.py |
|||
# Customizations for env:jgaurora_a5s_a1 |
|||
# |
|||
import os,marlin |
|||
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) |
|||
|
|||
# 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); |
|||
|
@ -1,47 +1,49 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/lerdge.py |
|||
# lerdge.py |
|||
# Customizations for Lerdge build environments: |
|||
# env:LERDGEX env:LERDGEX_usb_flash_drive |
|||
# env:LERDGES env:LERDGES_usb_flash_drive |
|||
# env:LERDGEK env:LERDGEK_usb_flash_drive |
|||
# |
|||
import os,marlin |
|||
Import("env") |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
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.encrypt |
|||
def encrypt(source, target, env): |
|||
fwpath = target[0].path |
|||
enname = board.get("build.encrypt") |
|||
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.encrypt |
|||
def encrypt(source, target, env): |
|||
fwpath = target[0].path |
|||
enname = board.get("build.encrypt") |
|||
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 'encrypt' in board.get("build").keys(): |
|||
if board.get("build.encrypt") != "": |
|||
marlin.add_post_action(encrypt) |
|||
else: |
|||
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter") |
|||
exit(1) |
|||
if 'encrypt' in board.get("build").keys(): |
|||
if board.get("build.encrypt") != "": |
|||
marlin.add_post_action(encrypt) |
|||
else: |
|||
print("LERDGE builds require output file via board_build.encrypt = 'filename' parameter") |
|||
exit(1) |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin.py |
|||
# mks_robin.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin.ld", "Robin.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_e3.py |
|||
# mks_robin_e3.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08005000", "mks_robin_e3.ld", "Robin_e3.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_e3p.py |
|||
# mks_robin_e3p.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin_e3p.ld", "Robin_e3p.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_lite.py |
|||
# mks_robin_lite.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08005000", "mks_robin_lite.ld", "mksLite.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_lite3.py |
|||
# mks_robin_lite3.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08005000", "mks_robin_lite.ld", "mksLite3.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_mini.py |
|||
# mks_robin_mini.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin_mini.ld", "Robin_mini.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_nano.py |
|||
# mks_robin_nano.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin_nano.ld", "Robin_nano.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_nano35.py |
|||
# mks_robin_nano35.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin_nano.ld", "Robin_nano35.bin") |
|||
|
@ -1,5 +1,5 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/mks_robin_pro.py |
|||
# mks_robin_pro.py |
|||
# |
|||
import robin |
|||
robin.prepare("0x08007000", "mks_robin_pro.ld", "Robin_pro.bin") |
|||
|
@ -1,18 +1,20 @@ |
|||
# |
|||
# Convert the ELF to an SREC file suitable for some bootloaders |
|||
# |
|||
import os,sys |
|||
from os.path import join |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
import os,sys |
|||
from os.path import join |
|||
|
|||
Import("env") |
|||
Import("env") |
|||
|
|||
board = env.BoardConfig() |
|||
board_keys = board.get("build").keys() |
|||
if 'encrypt' 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.encrypt")) + "\"" |
|||
]), "Building $TARGET") |
|||
) |
|||
board = env.BoardConfig() |
|||
board_keys = board.get("build").keys() |
|||
if 'encrypt' 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.encrypt")) + "\"" |
|||
]), "Building $TARGET") |
|||
) |
|||
|
@ -1,8 +1,8 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/pioutil.py |
|||
# pioutil.py |
|||
# |
|||
|
|||
# Detect that 'vscode init' is running |
|||
def is_vscode_init(): |
|||
# Make sure 'vscode init' is not the current command |
|||
def is_pio_build(): |
|||
from SCons.Script import COMMAND_LINE_TARGETS |
|||
return "idedata" in COMMAND_LINE_TARGETS or "_idedata" in COMMAND_LINE_TARGETS |
|||
return "idedata" not in COMMAND_LINE_TARGETS and "_idedata" not in COMMAND_LINE_TARGETS |
|||
|
@ -1,12 +1,14 @@ |
|||
# |
|||
# buildroot/share/PlatformIO/scripts/robin.py |
|||
# robin.py |
|||
# |
|||
import marlin |
|||
|
|||
# Apply customizations for a MKS Robin |
|||
def prepare(address, ldname, fwname): |
|||
def encrypt(source, target, env): |
|||
marlin.encrypt_mks(source, target, env, fwname) |
|||
marlin.relocate_firmware(address) |
|||
marlin.custom_ld_script(ldname) |
|||
marlin.add_post_action(encrypt); |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
import marlin |
|||
def encrypt(source, target, env): |
|||
marlin.encrypt_mks(source, target, env, fwname) |
|||
marlin.relocate_firmware(address) |
|||
marlin.custom_ld_script(ldname) |
|||
marlin.add_post_action(encrypt); |
|||
|
@ -1,52 +1,54 @@ |
|||
# |
|||
# simulator.py |
|||
# PlatformIO pre: script for simulator builds |
|||
# |
|||
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) |
|||
|
|||
env.AddCustomTarget("upload", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}") |
|||
env.AddCustomTarget("upload", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}") |
|||
|
@ -1,59 +1,61 @@ |
|||
# |
|||
# stm32_serialbuffer.py |
|||
# |
|||
Import("env") |
|||
|
|||
# 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 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 |
|||
|
|||
# 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 |
|||
|
|||
# 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}"]) |
|||
|
|||
# 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) |
|||
import pioutil |
|||
if pioutil.is_pio_build(): |
|||
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] |
|||
|
|||
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 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}"]) |
|||
|
|||
# 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) |
|||
|
|||
# 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) |
|||
|
Loading…
Reference in new issue