@@ -82,52 +82,41 @@ def get_bootloader_image(variants_dir):
8282 return (
8383 variant_bootloader
8484 if isfile (variant_bootloader )
85- else join (
86- FRAMEWORK_DIR ,
87- "tools" ,
88- "sdk" ,
89- build_mcu ,
90- "bin" ,
91- "bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.bin" ,
85+ else generate_bootloader_image (
86+ join (
87+ FRAMEWORK_DIR ,
88+ "tools" ,
89+ "sdk" ,
90+ build_mcu ,
91+ "bin" ,
92+ "bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.elf" ,
93+ )
9294 )
9395 )
9496
9597
96- def get_patched_bootloader_image (original_bootloader_image , bootloader_offset ):
97- patched_bootloader_image = join (env .subst ("$BUILD_DIR" ), "patched_bootloader.bin" )
98+ def generate_bootloader_image (bootloader_elf ):
9899 bootloader_cmd = env .Command (
99- patched_bootloader_image ,
100- original_bootloader_image ,
101- env .VerboseAction (
102- " " .join (
103- [
104- '"$PYTHONEXE"' ,
105- join (
106- platform .get_package_dir ("tool-esptoolpy" ) or "" , "esptool.py"
107- ),
108- "--chip" ,
109- build_mcu ,
110- "merge_bin" ,
111- "-o" ,
112- "$TARGET" ,
113- "--flash_mode" ,
114- "${__get_board_flash_mode(__env__)}" ,
115- "--flash_freq" ,
116- "${__get_board_f_flash(__env__)}" ,
117- "--flash_size" ,
118- board_config .get ("upload.flash_size" , "4MB" ),
119- "--target-offset" ,
120- bootloader_offset ,
121- bootloader_offset ,
122- "$SOURCE" ,
123- ]
124- ),
125- "Updating bootloader headers" ,
126- ),
100+ join ("$BUILD_DIR" , "bootloader.bin" ),
101+ bootloader_elf ,
102+ env .VerboseAction (" " .join ([
103+ '"$PYTHONEXE" "$OBJCOPY"' ,
104+ "--chip" , build_mcu , "elf2image" ,
105+ "--flash_mode" , "${__get_board_flash_mode(__env__)}" ,
106+ "--flash_freq" , "${__get_board_f_flash(__env__)}" ,
107+ "--flash_size" , board_config .get ("upload.flash_size" , "4MB" ),
108+ "-o" , "$TARGET" , "$SOURCES"
109+ ]), "Building $TARGET" ),
127110 )
111+
128112 env .Depends ("$BUILD_DIR/$PROGNAME$PROGSUFFIX" , bootloader_cmd )
129113
130- return patched_bootloader_image
114+ # Because the Command always returns a NodeList, we have to
115+ # access the first element in the list to get the Node object
116+ # that actually represents the bootloader image.
117+ # Also, this file is later used in generic Python code, so the
118+ # Node object in converted to a generic string
119+ return str (bootloader_cmd [0 ])
131120
132121
133122def add_tinyuf2_extra_image ():
@@ -210,34 +199,13 @@ def add_tinyuf2_extra_image():
210199# Process framework extra images
211200#
212201
213- # Starting with v2.0.4 the Arduino core contains updated bootloader images that have
214- # innacurate default headers. This results in bootloops if firmware is flashed via
215- # OpenOCD (e.g. debugging or uploading via debug tools). For this reason, before
216- # uploading or debugging we need to adjust the bootloader binary according to
217- # the values of the --flash-size and --flash-mode arguments.
218- # Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy
219- # overrides the binary image headers before flashing.
220-
221- bootloader_patch_required = bool (
222- env .get ("PIOFRAMEWORK" , []) == ["arduino" ]
223- and (
224- "debug" in env .GetBuildType ()
225- or env .subst ("$UPLOAD_PROTOCOL" ) in board_config .get ("debug.tools" , {})
226- or env .IsIntegrationDump ()
227- )
228- )
229-
230- bootloader_image_path = get_bootloader_image (variants_dir )
231- bootloader_offset = "0x1000" if build_mcu in ("esp32" , "esp32s2" ) else "0x0000"
232- if bootloader_patch_required :
233- bootloader_image_path = get_patched_bootloader_image (
234- bootloader_image_path , bootloader_offset
235- )
236-
237202env .Append (
238203 LIBSOURCE_DIRS = [join (FRAMEWORK_DIR , "libraries" )],
239204 FLASH_EXTRA_IMAGES = [
240- (bootloader_offset , bootloader_image_path ),
205+ (
206+ "0x1000" if build_mcu in ("esp32" , "esp32s2" ) else "0x0000" ,
207+ get_bootloader_image (variants_dir ),
208+ ),
241209 ("0x8000" , join (env .subst ("$BUILD_DIR" ), "partitions.bin" )),
242210 ("0xe000" , join (FRAMEWORK_DIR , "tools" , "partitions" , "boot_app0.bin" )),
243211 ]
0 commit comments