From 05ebccecf28f79bf1831d1df55b508936392ecad Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 11 Aug 2018 19:10:58 +0300 Subject: [PATCH] Switch to isolated build flags per framework --- builder/frameworks/_bare.py | 65 ++++++++++++++++++++++++++++++++++++ builder/frameworks/espidf.py | 1 + builder/main.py | 53 ++++++----------------------- platform.json | 2 +- 4 files changed, 78 insertions(+), 43 deletions(-) create mode 100644 builder/frameworks/_bare.py diff --git a/builder/frameworks/_bare.py b/builder/frameworks/_bare.py new file mode 100644 index 0000000..5db4a07 --- /dev/null +++ b/builder/frameworks/_bare.py @@ -0,0 +1,65 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Default flags for bare-metal programming (without any framework layers) +# + +from SCons.Script import Import + +Import("env") + +env.Append( + ASFLAGS=["-x", "assembler-with-cpp"], + + CFLAGS=["-std=gnu99"], + + CCFLAGS=[ + "-Os", + "-Wall", + "-nostdlib", + "-Wpointer-arith", + "-Wno-error=unused-but-set-variable", + "-Wno-error=unused-variable", + "-mlongcalls", + "-ffunction-sections", + "-fdata-sections", + "-fstrict-volatile-bitfields" + ], + + CXXFLAGS=[ + "-fno-rtti", + "-fno-exceptions", + "-std=gnu++11" + ], + + CPPDEFINES=[ + "ESP32", + "ESP_PLATFORM", + ("F_CPU", "$BOARD_F_CPU"), + "HAVE_CONFIG_H", + ("MBEDTLS_CONFIG_FILE", '\\"mbedtls/esp_config.h\\"') + ], + + LINKFLAGS=[ + "-nostdlib", + "-Wl,-static", + "-u", "call_user_start_cpu0", + "-Wl,--undefined=uxTopUsedPriority", + "-Wl,--gc-sections" + ] +) + +# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) +env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 2979b3f..e379f44 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -32,6 +32,7 @@ from SCons.Script import DefaultEnvironment env = DefaultEnvironment() platform = env.PioPlatform() +env.SConscript("_bare.py", exports="env") env.SConscript("_embedtxt_files.py", exports="env") FRAMEWORK_DIR = platform.get_package_dir("framework-espidf") diff --git a/builder/main.py b/builder/main.py index a39ffb8..ab5e7e3 100644 --- a/builder/main.py +++ b/builder/main.py @@ -141,45 +141,6 @@ env.Replace( ARFLAGS=["rc"], - ASFLAGS=["-x", "assembler-with-cpp"], - - CFLAGS=["-std=gnu99"], - - CCFLAGS=[ - "-Os", - "-Wall", - "-nostdlib", - "-Wpointer-arith", - "-Wno-error=unused-but-set-variable", - "-Wno-error=unused-variable", - "-mlongcalls", - "-ffunction-sections", - "-fdata-sections", - "-fstrict-volatile-bitfields" - ], - - CXXFLAGS=[ - "-fno-rtti", - "-fno-exceptions", - "-std=gnu++11" - ], - - CPPDEFINES=[ - "ESP32", - "ESP_PLATFORM", - ("F_CPU", "$BOARD_F_CPU"), - "HAVE_CONFIG_H", - ("MBEDTLS_CONFIG_FILE", '\\"mbedtls/esp_config.h\\"') - ], - - LINKFLAGS=[ - "-nostdlib", - "-Wl,-static", - "-u", "call_user_start_cpu0", - "-Wl,--undefined=uxTopUsedPriority", - "-Wl,--gc-sections" - ], - SIZEPROGREGEXP=r"^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).*", SIZEDATAREGEXP=r"^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).*", SIZECHECKCMD="$SIZETOOL -A -d $SOURCES", @@ -194,8 +155,9 @@ if env.get("PROGNAME", "program") == "program": env.Replace(PROGNAME="firmware") env.Append( - # Clone actual CCFLAGS to ASFLAGS + # copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) ASFLAGS=env.get("CCFLAGS", [])[:], + BUILDERS=dict( ElfToBin=Builder( action=env.VerboseAction(" ".join([ @@ -208,7 +170,8 @@ env.Append( "upload.flash_size", "detect"), "-o", "$TARGET", "$SOURCES" ]), "Building $TARGET"), - suffix=".bin"), + suffix=".bin" + ), DataToBin=Builder( action=env.VerboseAction(" ".join([ '"$MKSPIFFSTOOL"', @@ -220,7 +183,13 @@ env.Append( ]), "Building SPIFFS image from '$SOURCES' directory to $TARGET"), emitter=__fetch_spiffs_size, source_factory=env.Dir, - suffix=".bin"))) + suffix=".bin" + ) + ) +) + +if not env.get("PIOFRAMEWORK"): + env.SConscript("frameworks/_bare.py", exports="env") # # Target: Build executable and linkable firmware or SPIFFS image diff --git a/platform.json b/platform.json index 3b918db..483b034 100644 --- a/platform.json +++ b/platform.json @@ -45,7 +45,7 @@ "framework-arduinoespressif32": { "type": "framework", "optional": true, - "version": "~1.10000.0" + "version": "~2.10000.0" }, "framework-espidf": { "type": "framework",