Skip to content

Commit c266d51

Browse files
committed
Merge branch 'release/v2.1.0'
2 parents 86db0c0 + f32e3ec commit c266d51

File tree

4 files changed

+172
-19
lines changed

4 files changed

+172
-19
lines changed

builder/frameworks/espidf.py

Lines changed: 128 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
499499
"env_file": os.path.join("$BUILD_DIR", "config.env"),
500500
"libraries_list": libraries_list,
501501
"objdump": os.path.join(
502-
TOOLCHAIN_DIR, "bin", env.subst("$CC").replace("-gcc", "-objdump"),
502+
TOOLCHAIN_DIR,
503+
"bin",
504+
env.subst("$CC").replace("-gcc", "-objdump"),
503505
),
504506
}
505507

@@ -803,19 +805,90 @@ def find_default_component(target_configs):
803805
return ""
804806

805807

806-
def create_verion_file():
808+
def create_version_file():
807809
version_file = os.path.join(FRAMEWORK_DIR, "version.txt")
808810
if not os.path.isfile(version_file):
809811
with open(version_file, "w") as fp:
810812
fp.write(platform.get_package_version("framework-espidf"))
811813

812814

813-
#
815+
def generate_empty_partition_image(binary_path, image_size):
816+
empty_partition = env.Command(
817+
binary_path,
818+
None,
819+
env.VerboseAction(
820+
'"$PYTHONEXE" "%s" %s $TARGET'
821+
% (
822+
os.path.join(
823+
FRAMEWORK_DIR,
824+
"components",
825+
"partition_table",
826+
"gen_empty_partition.py",
827+
),
828+
image_size,
829+
),
830+
"Generating an empty partition $TARGET",
831+
),
832+
)
833+
834+
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", empty_partition)
835+
836+
837+
def get_partition_info(pt_path, pt_offset, pt_params):
838+
assert os.path.isfile(pt_path)
839+
cmd = [
840+
env.subst("$PYTHONEXE"),
841+
os.path.join(FRAMEWORK_DIR, "components", "partition_table", "parttool.py"),
842+
"-q",
843+
"--partition-table-offset",
844+
hex(pt_offset),
845+
"--partition-table-file",
846+
pt_path,
847+
"get_partition_info",
848+
"--info",
849+
"size",
850+
"offset",
851+
]
852+
853+
if pt_params["name"] == "boot":
854+
cmd.append("--partition-boot-default")
855+
else:
856+
cmd.extend(
857+
[
858+
"--partition-type",
859+
pt_params["type"],
860+
"--partition-subtype",
861+
pt_params["subtype"],
862+
]
863+
)
864+
865+
result = exec_command(cmd)
866+
if result["returncode"] != 0:
867+
sys.stderr.write(
868+
"Couldn't extract information for %s/%s from the partition table\n"
869+
% (pt_params["type"], pt_params["subtype"])
870+
)
871+
sys.stderr.write(result["out"] + "\n")
872+
sys.stderr.write(result["err"] + "\n")
873+
env.Exit(1)
874+
875+
size = offset = 0
876+
if result["out"].strip():
877+
size, offset = result["out"].strip().split(" ", 1)
878+
879+
return {"size": size, "offset": offset}
880+
881+
882+
def get_app_partition_offset(pt_table, pt_offset):
883+
# Get the default boot partition offset
884+
app_params = get_partition_info(pt_table, pt_offset, {"name": "boot"})
885+
return app_params.get("offset", "0x10000")
886+
887+
814888
# ESP-IDF package doesn't contain .git folder, instead package version is specified
815889
# in a special file "version.h" in the root folder of the package
816-
#
817890

818-
create_verion_file()
891+
create_version_file()
819892

820893
#
821894
# Generate final linker script
@@ -845,6 +918,7 @@ def create_verion_file():
845918

846919
fwpartitions_dir = os.path.join(FRAMEWORK_DIR, "components", "partition_table")
847920
partitions_csv = board.get("build.partitions", "partitions_singleapp.csv")
921+
848922
env.Replace(
849923
PARTITIONS_TABLE_CSV=os.path.abspath(
850924
os.path.join(fwpartitions_dir, partitions_csv)
@@ -913,6 +987,7 @@ def create_verion_file():
913987
[
914988
"-DIDF_TARGET=" + idf_variant,
915989
"-DEXTRA_COMPONENT_DIRS:PATH=" + ";".join(extra_components),
990+
"-DPYTHON=" + env.subst("$PYTHONEXE"),
916991
]
917992
+ click.parser.split_arg_string(board.get("build.cmake_extra_args", "")),
918993
)
@@ -1057,6 +1132,7 @@ def _skip_prj_source_files(node):
10571132
)
10581133
)
10591134

1135+
partition_table_offset = sdk_config.get("PARTITION_TABLE_OFFSET", 0x8000)
10601136
project_flags.update(link_args)
10611137
env.MergeFlags(project_flags)
10621138
env.Prepend(
@@ -1065,8 +1141,14 @@ def _skip_prj_source_files(node):
10651141
LINKFLAGS=extra_flags,
10661142
LIBS=libs,
10671143
FLASH_EXTRA_IMAGES=[
1068-
("0x1000", os.path.join("$BUILD_DIR", "bootloader.bin")),
1069-
("0x8000", os.path.join("$BUILD_DIR", "partitions.bin")),
1144+
(
1145+
board.get("upload.bootloader_offset", "0x1000"),
1146+
os.path.join("$BUILD_DIR", "bootloader.bin"),
1147+
),
1148+
(
1149+
board.get("upload.partition_table_offset", hex(partition_table_offset)),
1150+
os.path.join("$BUILD_DIR", "partitions.bin"),
1151+
),
10701152
],
10711153
)
10721154

@@ -1087,3 +1169,42 @@ def _skip_prj_source_files(node):
10871169
ulp_dir = os.path.join(env.subst("$PROJECT_DIR"), "ulp")
10881170
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir):
10891171
env.SConscript("ulp.py", exports="env project_config idf_variant")
1172+
1173+
#
1174+
# Process OTA partition and image
1175+
#
1176+
1177+
ota_partition_params = get_partition_info(
1178+
env.subst("$PARTITIONS_TABLE_CSV"),
1179+
partition_table_offset,
1180+
{"name": "ota", "type": "data", "subtype": "ota"},
1181+
)
1182+
1183+
if ota_partition_params["size"] and ota_partition_params["offset"]:
1184+
# Generate an empty image if OTA is enabled in partition table
1185+
ota_partition_image = os.path.join("$BUILD_DIR", "ota_data_initial.bin")
1186+
generate_empty_partition_image(ota_partition_image, ota_partition_params["size"])
1187+
1188+
env.Append(
1189+
FLASH_EXTRA_IMAGES=[
1190+
(
1191+
board.get(
1192+
"upload.ota_partition_offset", ota_partition_params["offset"]
1193+
),
1194+
ota_partition_image,
1195+
)
1196+
]
1197+
)
1198+
1199+
#
1200+
# Configure application partition offset
1201+
#
1202+
1203+
env.Replace(
1204+
ESP32_APP_OFFSET=get_app_partition_offset(
1205+
env.subst("$PARTITIONS_TABLE_CSV"), partition_table_offset
1206+
)
1207+
)
1208+
1209+
# Propagate application offset to debug configurations
1210+
env["IDE_EXTRA_DATA"].update({"application_offset": env.subst("$ESP32_APP_OFFSET")})

builder/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def __fetch_spiffs_size(target, source, env):
163163
MKSPIFFSTOOL="mkspiffs_${PIOPLATFORM}_" + ("espidf" if "espidf" in env.subst(
164164
"$PIOFRAMEWORK") else "${PIOFRAMEWORK}"),
165165
ESP32_SPIFFS_IMAGE_NAME=env.get("ESP32_SPIFFS_IMAGE_NAME", "spiffs"),
166+
ESP32_APP_OFFSET="0x10000",
166167

167168
PROGSUFFIX=".elf"
168169
)
@@ -310,7 +311,7 @@ def __fetch_spiffs_size(target, source, env):
310311
"--flash_freq", "${__get_board_f_flash(__env__)}",
311312
"--flash_size", "detect"
312313
],
313-
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS 0x10000 $SOURCE'
314+
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $ESP32_APP_OFFSET $SOURCE'
314315
)
315316
for image in env.get("FLASH_EXTRA_IMAGES", []):
316317
env.Append(UPLOADERFLAGS=[image[0], env.subst(image[1])])
@@ -371,13 +372,13 @@ def __fetch_spiffs_size(target, source, env):
371372
debug_tools.get(upload_protocol).get("server").get("arguments", []))
372373
openocd_args.extend([
373374
"-c",
374-
"program_esp32 {{$SOURCE}} %s verify" %
375-
board.get("upload.offset_address", "0x10000")
375+
"program_esp {{$SOURCE}} %s verify" %
376+
board.get("upload.offset_address", "$ESP32_APP_OFFSET")
376377
])
377378
for image in env.get("FLASH_EXTRA_IMAGES", []):
378379
openocd_args.extend([
379380
"-c",
380-
'program_esp32 {{%s}} %s verify' %
381+
'program_esp {{%s}} %s verify' %
381382
(_to_unix_slashes(image[1]), image[0])
382383
])
383384
openocd_args.extend(["-c", "reset run; shutdown"])

platform.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"type": "git",
1919
"url": "https://github.com/platformio/platform-espressif32.git"
2020
},
21-
"version": "2.0.0",
21+
"version": "2.1.0",
2222
"frameworks": {
2323
"arduino": {
2424
"package": "framework-arduinoespressif32",
@@ -79,7 +79,7 @@
7979
"framework-arduino-mbcwb": {
8080
"type": "framework",
8181
"optional": true,
82-
"owner": "platformio",
82+
"owner": "meteca",
8383
"version": ">=2.1.1"
8484
},
8585
"framework-espidf": {
@@ -103,18 +103,18 @@
103103
"tool-esptoolpy": {
104104
"type": "uploader",
105105
"owner": "platformio",
106-
"version": "~1.20600.0"
106+
"version": "~1.30000.0"
107107
},
108108
"tool-mbctool": {
109109
"optional": true,
110-
"owner": "platformio",
110+
"owner": "meteca",
111111
"version": ">=2.0.0"
112112
},
113113
"tool-openocd-esp32": {
114114
"type": "debugger",
115115
"optional": true,
116116
"owner": "platformio",
117-
"version": "~1.1000.20181026"
117+
"version": "~2.1000.0"
118118
},
119119
"tool-mkspiffs": {
120120
"type": "uploader",

platform.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from os.path import isdir
15+
import copy
16+
import os
1617

18+
from platformio import fs
1719
from platformio.managers.platform import PlatformBase
1820
from platformio.util import get_systype
1921

@@ -32,7 +34,7 @@ def configure_default_packages(self, variables, targets):
3234
self.packages['tool-mkspiffs']['optional'] = False
3335
if variables.get("upload_protocol"):
3436
self.packages['tool-openocd-esp32']['optional'] = False
35-
if isdir("ulp"):
37+
if os.path.isdir("ulp"):
3638
self.packages['toolchain-esp32ulp']['optional'] = False
3739
if "espidf" in frameworks:
3840
for p in self.packages:
@@ -122,7 +124,8 @@ def _add_dynamic_options(self, board):
122124
server_args = [
123125
"-s", "$PACKAGE_DIR/share/openocd/scripts",
124126
"-f", "interface/%s.cfg" % openocd_interface,
125-
"-f", "board/%s" % debug.get("openocd_board")
127+
"-f", "board/%s" % debug.get("openocd_board"),
128+
"-c", "adapter_khz %d" % debug.get("adapter_speed", 20000)
126129
]
127130

128131
debug['tools'][link] = {
@@ -152,3 +155,31 @@ def _add_dynamic_options(self, board):
152155

153156
board.manifest['debug'] = debug
154157
return board
158+
159+
def configure_debug_options(self, initial_debug_options, ide_data):
160+
ide_extra_data = ide_data.get("extra", {})
161+
flash_images = ide_extra_data.get("flash_images", [])
162+
ignore_conds = [
163+
initial_debug_options["load_cmds"] != ["load"],
164+
not flash_images,
165+
not all([os.path.isfile(item["path"]) for item in flash_images]),
166+
]
167+
if any(ignore_conds):
168+
return initial_debug_options
169+
170+
debug_options = copy.deepcopy(initial_debug_options)
171+
load_cmds = [
172+
'monitor program_esp "{{{path}}}" {offset} verify'.format(
173+
path=fs.to_unix_path(item["path"]), offset=item["offset"]
174+
)
175+
for item in flash_images
176+
]
177+
load_cmds.append(
178+
'monitor program_esp "{%s.bin}" %s verify'
179+
% (
180+
fs.to_unix_path(ide_data["prog_path"][:-4]),
181+
ide_extra_data.get("application_offset", "0x10000"),
182+
)
183+
)
184+
debug_options["load_cmds"] = load_cmds
185+
return debug_options

0 commit comments

Comments
 (0)