Randomize firmware.bin, fix unflag

This commit is contained in:
Scott Lahteine 2020-07-25 22:57:00 -05:00
parent e02817b077
commit d0222e5c76
4 changed files with 28 additions and 21 deletions

View file

@ -47,22 +47,25 @@ def get_all_known_libs():
def get_all_env_libs(): def get_all_env_libs():
env_libs = [] env_libs = []
lib_deps = env.GetProjectOption("lib_deps") lib_deps = env.GetProjectOption('lib_deps')
for dep in lib_deps: for dep in lib_deps:
name, _, _ = PackageManager.parse_pkg_uri(dep) name, _, _ = PackageManager.parse_pkg_uri(dep)
env_libs.append(name) env_libs.append(name)
return env_libs return env_libs
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 # All unused libs should be ignored so that if a library
# exists in .pio/lib_deps it will not break compilation. # exists in .pio/lib_deps it will not break compilation.
def force_ignore_unused_libs(): def force_ignore_unused_libs():
env_libs = get_all_env_libs() env_libs = get_all_env_libs()
known_libs = get_all_known_libs() known_libs = get_all_known_libs()
diff = (list(set(known_libs) - set(env_libs))) diff = (list(set(known_libs) - set(env_libs)))
lib_ignore = env.GetProjectOption("lib_ignore") + diff lib_ignore = env.GetProjectOption('lib_ignore') + diff
print("Ignoring libs:", lib_ignore) print("Ignoring libs:", lib_ignore)
proj = env.GetProjectConfig() set_env_field('lib_ignore', lib_ignore)
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
def install_features_dependencies(): def install_features_dependencies():
load_config() load_config()
@ -80,14 +83,14 @@ def install_features_dependencies():
deps_to_add[name] = dep deps_to_add[name] = dep
# Does the env already have the dependency? # Does the env already have the dependency?
deps = env.GetProjectOption("lib_deps") deps = env.GetProjectOption('lib_deps')
for dep in deps: for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep) name, _, _ = PackageManager.parse_pkg_uri(dep)
if name in deps_to_add: if name in deps_to_add:
del deps_to_add[name] del deps_to_add[name]
# Are there any libraries that should be ignored? # Are there any libraries that should be ignored?
lib_ignore = env.GetProjectOption("lib_ignore") lib_ignore = env.GetProjectOption('lib_ignore')
for dep in deps: for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep) name, _, _ = PackageManager.parse_pkg_uri(dep)
if name in deps_to_add: if name in deps_to_add:
@ -96,8 +99,7 @@ def install_features_dependencies():
# Is there anything left? # Is there anything left?
if len(deps_to_add) > 0: if len(deps_to_add) > 0:
# Only add the missing dependencies # Only add the missing dependencies
proj = env.GetProjectConfig() set_env_field('lib_deps', deps + list(deps_to_add.values()))
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
if 'extra_scripts' in FEATURE_DEPENDENCIES[feature]: if 'extra_scripts' in FEATURE_DEPENDENCIES[feature]:
print("Executing extra_scripts for %s... " % feature) print("Executing extra_scripts for %s... " % feature)
@ -105,8 +107,7 @@ def install_features_dependencies():
if 'src_filter' in FEATURE_DEPENDENCIES[feature]: if 'src_filter' in FEATURE_DEPENDENCIES[feature]:
print("Adding src_filter for %s... " % feature) print("Adding src_filter for %s... " % feature)
proj = env.GetProjectConfig() src_filter = ' '.join(env.GetProjectOption('src_filter'))
src_filter = ' '.join(env.GetProjectOption("src_filter"))
# first we need to remove the references to the same folder # first we need to remove the references to the same folder
my_srcs = re.findall( r'[+-](<.*?>)', FEATURE_DEPENDENCIES[feature]['src_filter']) my_srcs = re.findall( r'[+-](<.*?>)', FEATURE_DEPENDENCIES[feature]['src_filter'])
cur_srcs = re.findall( r'[+-](<.*?>)', src_filter) cur_srcs = re.findall( r'[+-](<.*?>)', src_filter)
@ -115,19 +116,18 @@ def install_features_dependencies():
src_filter = re.sub(r'[+-]' + d, '', src_filter) src_filter = re.sub(r'[+-]' + d, '', src_filter)
src_filter = FEATURE_DEPENDENCIES[feature]['src_filter'] + ' ' + src_filter src_filter = FEATURE_DEPENDENCIES[feature]['src_filter'] + ' ' + src_filter
proj.set("env:" + env["PIOENV"], "src_filter", [src_filter]) set_env_field('src_filter', [src_filter])
env.Replace(SRC_FILTER=src_filter) env.Replace(SRC_FILTER=src_filter)
if 'lib_ignore' in FEATURE_DEPENDENCIES[feature]: if 'lib_ignore' in FEATURE_DEPENDENCIES[feature]:
print("Ignoring libs for %s... " % feature) print("Ignoring libs for %s... " % feature)
lib_ignore = env.GetProjectOption("lib_ignore") + [FEATURE_DEPENDENCIES[feature]['lib_ignore']] lib_ignore = env.GetProjectOption('lib_ignore') + [FEATURE_DEPENDENCIES[feature]['lib_ignore']]
proj = env.GetProjectConfig() set_env_field('lib_ignore', lib_ignore)
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
# #
# Find a compiler, considering the OS # Find a compiler, considering the OS
# #
ENV_BUILD_PATH = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env["PIOENV"]) ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV'])
GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path") GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
def search_compiler(): def search_compiler():
if os.path.exists(GCC_PATH_CACHE): if os.path.exists(GCC_PATH_CACHE):

View file

@ -5,12 +5,13 @@ Import("env")
for define in env['CPPDEFINES']: for define in env['CPPDEFINES']:
if define[0] == "VECT_TAB_ADDR": if define[0] == "VECT_TAB_ADDR":
env['CPPDEFINES'].remove(define) env['CPPDEFINES'].remove(define)
env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000")) env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000"))
custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/creality.ld") custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/creality.ld")
for i, flag in enumerate(env["LINKFLAGS"]):
if "-Wl,-T" in flag:
env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
elif flag == "-T":
env["LINKFLAGS"][i + 1] = custom_ld_script
for i, flag in enumerate(env['LINKFLAGS']):
if "-Wl,-T" in flag:
env['LINKFLAGS'][i] = "-Wl,-T" + custom_ld_script
elif flag == "-T":
env['LINKFLAGS'][i + 1] = custom_ld_script

View file

@ -0,0 +1,5 @@
Import("env")
from datetime import datetime
env['PROGNAME'] = datetime.now().strftime("firmware-%Y%m%d-%H%M%S")

View file

@ -380,7 +380,7 @@ src_filter = ${common.default_src_filter} +<src/HAL/STM32>
platform = ${common_stm32.platform} platform = ${common_stm32.platform}
build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py
${common.build_flags} -std=gnu++14 -DHAVE_SW_SERIAL ${common.build_flags} -std=gnu++14 -DHAVE_SW_SERIAL
build_unflags = -std=gnu++11 build_unflags = -std=gnu11
src_filter = ${common.default_src_filter} +<src/HAL/STM32F1> src_filter = ${common.default_src_filter} +<src/HAL/STM32F1>
lib_ignore = SPI lib_ignore = SPI
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
@ -744,6 +744,7 @@ board = genericSTM32F103RC
build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py
${common.build_flags} -std=gnu++14 -DSTM32_XL_DENSITY -DTEMP_TIMER_CHAN=4 ${common.build_flags} -std=gnu++14 -DSTM32_XL_DENSITY -DTEMP_TIMER_CHAN=4
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
pre:buildroot/share/PlatformIO/scripts/random-bin.py
buildroot/share/PlatformIO/scripts/creality.py buildroot/share/PlatformIO/scripts/creality.py
lib_ignore = ${common_stm32f1.lib_ignore} lib_ignore = ${common_stm32f1.lib_ignore}
debug_tool = jlink debug_tool = jlink