Skip to content

Commit 353f0d0

Browse files
committed
Add extra script to copy *.bin and *.elf file to generic bin folder in order to start wokwi simulation easily.
1 parent 651c669 commit 353f0d0

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@
5151
*.exe
5252
*.out
5353
*.app
54+
55+
# Folder
56+
bin/

.wokwi/wokwi.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[wokwi]
22
version = 1
3-
firmware = '../.pio/build/Example7_SPIFFS/firmware.bin'
4-
elf = '../.pio/build/Example7_SPIFFS/firmware.elf'
3+
firmware = '../bin/firmware.bin'
4+
elf = '../bin/firmware.elf'
55
gdbServerPort=3333
66
rfc2217ServerPort = 4000

extra_script.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Import("env")
2+
3+
import shutil
4+
import os
5+
6+
def after_build(source, target, env):
7+
print(" > Start of build project extra script")
8+
9+
# Obtenir le chemin du fichier .bin compilé
10+
firmware_path = str(target[0])
11+
if not os.path.exists(firmware_path):
12+
print(f"Error: Firmware not found at {firmware_path}")
13+
return
14+
15+
# Créer le dossier de sortie s'il n'existe pas
16+
current_dir = os.getcwd()
17+
output_dir = os.path.join(current_dir, "bin")
18+
if not os.path.exists(output_dir):
19+
os.makedirs(output_dir)
20+
print(f"Created output directory: {output_dir}")
21+
22+
# Nettoyer et copier le firmware.bin
23+
bin_input = firmware_path
24+
bin_output = os.path.join(output_dir, "firmware.bin")
25+
if os.path.exists(bin_output):
26+
try:
27+
os.remove(bin_output)
28+
print("Cleaned up existing firmware.bin")
29+
except Exception as e:
30+
print(f"Warning: Could not remove existing firmware.bin: {e}")
31+
32+
# Nettoyer et copier le firmware.elf
33+
elf_input = os.path.splitext(firmware_path)[0] + ".elf"
34+
elf_output = os.path.join(output_dir, "firmware.elf")
35+
if os.path.exists(elf_output):
36+
try:
37+
os.remove(elf_output)
38+
print("Cleaned up existing firmware.elf")
39+
except Exception as e:
40+
print(f"Warning: Could not remove existing firmware.elf: {e}")
41+
42+
# Copier les nouveaux fichiers firmware
43+
try:
44+
shutil.copy2(bin_input, bin_output)
45+
print(f"Successfully copied new firmware.bin to: {bin_output}")
46+
47+
shutil.copy2(elf_input, elf_output)
48+
print(f"Successfully copied new firmware.elf to: {elf_output}")
49+
except Exception as e:
50+
print(f"Error copying firmware files: {e}")
51+
52+
print(" > End of build project extra script")
53+
54+
# Ajouter le script après la création du binaire
55+
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", after_build)
56+
print("Extra script loaded")

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ monitor_filters = esp32_exception_decoder
2525
build_src_filter = +<*>
2626
+<../examples/${PIOENV}/${PIOENV}.cpp>
2727
monitor_speed = 921600
28+
extra_scripts = post:extra_script.py
2829

2930
[env:Example1_FastStartup]
3031
build_flags =

0 commit comments

Comments
 (0)