Skip to content

Commit

Permalink
Merge branch 'release/v1.11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Nov 1, 2019
2 parents 1c9d00d + afa7d2f commit 30f2d55
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 108 deletions.
2 changes: 1 addition & 1 deletion boards/m5stick-c.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"require_upload_port": true,
"speed": 460800
"speed": 1500000
},
"url": "http://www.m5stack.com",
"vendor": "M5Stack"
Expand Down
122 changes: 122 additions & 0 deletions builder/frameworks/_embed_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright 2014-present PlatformIO <[email protected]>
#
# 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.

import shutil
from os import SEEK_CUR, SEEK_END
from os.path import basename, isfile, join

from SCons.Script import Builder

from platformio.util import cd

Import("env")

board = env.BoardConfig()

#
# Embedded files helpers
#

def extract_files(cppdefines, files_type):
files = []
if "build." + files_type in board:
files.extend(
[join("$PROJECT_DIR", f) for f in board.get(
"build." + files_type, "").split() if f])
else:
files_define = "COMPONENT_" + files_type.upper()
for define in cppdefines:
if files_define not in define:
continue

value = define[1]
if not isinstance(define, tuple):
print("Warning! %s macro cannot be empty!" % files_define)
return []

if not isinstance(value, str):
print("Warning! %s macro must contain "
"a list of files separated by ':'" % files_define)
return []

for f in value.split(':'):
if not f:
continue
files.append(join("$PROJECT_DIR", f))

for f in files:
if not isfile(env.subst(f)):
print("Warning! Could not find file \"%s\"" % basename(f))

return files


def remove_config_define(cppdefines, files_type):
for define in cppdefines:
if files_type in define:
env.ProcessUnFlags("-D%s" % "=".join(str(d) for d in define))
return


def prepare_file(source, target, env):
filepath = source[0].get_abspath()
shutil.copy(filepath, filepath + ".piobkp")

with open(filepath, "rb+") as fp:
fp.seek(-1, SEEK_END)
if fp.read(1) != '\0':
fp.seek(0, SEEK_CUR)
fp.write(b'\0')


def revert_original_file(source, target, env):
filepath = source[0].get_abspath()
if isfile(filepath + ".piobkp"):
shutil.move(filepath + ".piobkp", filepath)


def embed_files(files, files_type):
for f in files:
filename = basename(f) + ".txt.o"
file_target = env.TxtToBin(join("$BUILD_DIR", filename), f)
env.Depends("$PIOMAINPROG", file_target)
if files_type == "embed_txtfiles":
env.AddPreAction(file_target, prepare_file)
env.AddPostAction(file_target, revert_original_file)
env.Append(PIOBUILDFILES=[env.File(join("$BUILD_DIR", filename))])


env.Append(
BUILDERS=dict(
TxtToBin=Builder(
action=env.VerboseAction(" ".join([
"xtensa-esp32-elf-objcopy",
"--input-target", "binary",
"--output-target", "elf32-xtensa-le",
"--binary-architecture", "xtensa",
"--rename-section", ".data=.rodata.embedded",
"$SOURCE", "$TARGET"
]), "Converting $TARGET"),
suffix=".txt.o"))
)

flags = env.get("CPPDEFINES")
for files_type in ("embed_txtfiles", "embed_files"):
if "COMPONENT_" + files_type.upper() not in env.Flatten(
flags) and "build." + files_type not in board:
continue

files = extract_files(flags, files_type)
embed_files(files, files_type)
remove_config_define(flags, files_type)
102 changes: 0 additions & 102 deletions builder/frameworks/_embedtxt_files.py

This file was deleted.

2 changes: 1 addition & 1 deletion builder/frameworks/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

env = DefaultEnvironment()

SConscript("_embedtxt_files.py", exports="env")
SConscript("_embed_files.py", exports="env")

if "espidf" not in env.subst("$PIOFRAMEWORK"):
SConscript(
Expand Down
2 changes: 1 addition & 1 deletion builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
platform = env.PioPlatform()

env.SConscript("_bare.py", exports="env")
env.SConscript("_embedtxt_files.py", exports="env")
env.SConscript("_embed_files.py", exports="env")

ulp_lib = None
ulp_dir = join(env.subst("$PROJECT_DIR"), "ulp")
Expand Down
3 changes: 2 additions & 1 deletion builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def __fetch_spiffs_size(target, source, env):
],
ERASECMD='"$PYTHONEXE" "$OBJCOPY" $ERASEFLAGS erase_flash',

MKSPIFFSTOOL="mkspiffs_${PIOPLATFORM}_${PIOFRAMEWORK}",
MKSPIFFSTOOL="mkspiffs_${PIOPLATFORM}_" + ("espidf" if "espidf" in env.subst(
"$PIOFRAMEWORK") else "${PIOFRAMEWORK}"),
PROGSUFFIX=".elf"
)

Expand Down
6 changes: 5 additions & 1 deletion examples/espidf-aws-iot/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ framework = espidf
board = esp32dev
monitor_speed = 115200
build_flags =
-DCOMPONENT_EMBED_TXTFILES=src/private.pem.key:src/certificate.pem.crt:src/aws-root-ca.pem
-DCONFIG_WIFI_SSID=\"ESP_AP\"
-DCONFIG_WIFI_PASSWORD=\"MYPASS\"

board_build.embed_txtfiles =
src/private.pem.key
src/certificate.pem.crt
src/aws-root-ca.pem
2 changes: 1 addition & 1 deletion platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "git",
"url": "https://github.com/platformio/platform-espressif32.git"
},
"version": "1.11.0",
"version": "1.11.1",
"packageRepositories": [
"https://dl.bintray.com/platformio/dl-packages/manifest.json",
"http://dl.platformio.org/packages/manifest.json",
Expand Down

0 comments on commit 30f2d55

Please sign in to comment.