Skip to content

Commit

Permalink
Randomize firmware.bin, fix unflag
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 26, 2020
1 parent e02817b commit bdfa3df
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
30 changes: 15 additions & 15 deletions buildroot/share/PlatformIO/scripts/common-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ def get_all_known_libs():

def get_all_env_libs():
env_libs = []
lib_deps = env.GetProjectOption("lib_deps")
lib_deps = env.GetProjectOption('lib_deps')
for dep in lib_deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
env_libs.append(name)
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
# 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
lib_ignore = env.GetProjectOption('lib_ignore') + diff
print("Ignoring libs:", lib_ignore)
proj = env.GetProjectConfig()
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
set_env_field('lib_ignore', lib_ignore)

def install_features_dependencies():
load_config()
Expand All @@ -80,14 +83,14 @@ def install_features_dependencies():
deps_to_add[name] = dep

# Does the env already have the dependency?
deps = env.GetProjectOption("lib_deps")
deps = env.GetProjectOption('lib_deps')
for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
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")
lib_ignore = env.GetProjectOption('lib_ignore')
for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
if name in deps_to_add:
Expand All @@ -96,17 +99,15 @@ def install_features_dependencies():
# Is there anything left?
if len(deps_to_add) > 0:
# Only add the missing dependencies
proj = env.GetProjectConfig()
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
set_env_field('lib_deps', deps + list(deps_to_add.values()))

if 'extra_scripts' in FEATURE_DEPENDENCIES[feature]:
print("Executing extra_scripts for %s... " % feature)
env.SConscript(FEATURE_DEPENDENCIES[feature]['extra_scripts'], exports="env")

if 'src_filter' in FEATURE_DEPENDENCIES[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
my_srcs = re.findall( r'[+-](<.*?>)', FEATURE_DEPENDENCIES[feature]['src_filter'])
cur_srcs = re.findall( r'[+-](<.*?>)', src_filter)
Expand All @@ -115,19 +116,18 @@ def install_features_dependencies():
src_filter = re.sub(r'[+-]' + d, '', 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)

if 'lib_ignore' in FEATURE_DEPENDENCIES[feature]:
print("Ignoring libs for %s... " % feature)
lib_ignore = env.GetProjectOption("lib_ignore") + [FEATURE_DEPENDENCIES[feature]['lib_ignore']]
proj = env.GetProjectConfig()
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
lib_ignore = env.GetProjectOption('lib_ignore') + [FEATURE_DEPENDENCIES[feature]['lib_ignore']]
set_env_field('lib_ignore', lib_ignore)

#
# 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")
def search_compiler():
if os.path.exists(GCC_PATH_CACHE):
Expand Down
9 changes: 5 additions & 4 deletions buildroot/share/PlatformIO/scripts/creality.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
for define in env['CPPDEFINES']:
if define[0] == "VECT_TAB_ADDR":
env['CPPDEFINES'].remove(define)

env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000"))

custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/creality.ld")
for i, flag in enumerate(env["LINKFLAGS"]):

for i, flag in enumerate(env['LINKFLAGS']):
if "-Wl,-T" in flag:
env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
env['LINKFLAGS'][i] = "-Wl,-T" + custom_ld_script
elif flag == "-T":
env["LINKFLAGS"][i + 1] = custom_ld_script

env['LINKFLAGS'][i + 1] = custom_ld_script
5 changes: 5 additions & 0 deletions buildroot/share/PlatformIO/scripts/random-bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
Import("env")

from datetime import datetime
env['PROGNAME'] = datetime.now().strftime("firmware-%Y%m%d-%H%M%S")
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ src_filter = ${common.default_src_filter} +<src/HAL/STM32>
platform = ${common_stm32.platform}
build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py
${common.build_flags} -std=gnu++14 -DHAVE_SW_SERIAL
build_unflags = -std=gnu++11
build_unflags = -std=gnu11

This comment has been minimized.

Copy link
@tpruvot

tpruvot Jul 26, 2020

Contributor

could you explain that ? f1 build system show the command lines, at least with pio build -v and that was the only way to wipe the multiple -std=gnu++11 set by the framework and the platform.... gnu11 is only visible on the few .c files (not .cpp) imo you need to keep both

This comment has been minimized.

Copy link
@tpruvot

tpruvot Jul 26, 2020

Contributor

i mean, build_unflags = -std=gnu11 -std=gnu++11

This comment has been minimized.

Copy link
@thinkyhead

thinkyhead Jul 28, 2020

Author Member

Makes sense. I've now changed it to both.

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

0 comments on commit bdfa3df

Please sign in to comment.