Update the ELF file sections with binary data (platform-specific). Args: objcopy_path (Path): Path to the objcopy executable. bin_file (Path): Path to the binary file. elf_file (Path): Path to the ELF file. platform (str): Target platform.
(
objcopy_path: Path, bin_file: Path, elf_file: Path, platform: str
)
| 325 | |
| 326 | |
| 327 | def _update_elf_sections( |
| 328 | objcopy_path: Path, bin_file: Path, elf_file: Path, platform: str |
| 329 | ): |
| 330 | """ |
| 331 | Update the ELF file sections with binary data (platform-specific). |
| 332 | |
| 333 | Args: |
| 334 | objcopy_path (Path): Path to the objcopy executable. |
| 335 | bin_file (Path): Path to the binary file. |
| 336 | elf_file (Path): Path to the ELF file. |
| 337 | platform (str): Target platform. |
| 338 | """ |
| 339 | print(f"Updating {platform} ELF sections...") |
| 340 | |
| 341 | # Platform-specific section names |
| 342 | section_mapping = {"esp32": ".flash.text", "avr": ".text", "arm": ".text"} |
| 343 | |
| 344 | section_name = section_mapping.get(platform, ".text") |
| 345 | |
| 346 | try: |
| 347 | command = [ |
| 348 | str(objcopy_path), |
| 349 | "--update-section", |
| 350 | f"{section_name}={bin_file}", |
| 351 | str(elf_file), |
| 352 | ] |
| 353 | print( |
| 354 | f"Updating {platform} ELF file '{elf_file}' section '{section_name}' with binary file '{bin_file}'" |
| 355 | ) |
| 356 | _run_command(command, show_output=True) |
| 357 | print(f"Successfully updated {section_name} section") |
| 358 | except RuntimeError as e: |
| 359 | print(f"Warning: Could not update {section_name} section: {e}") |
| 360 | # Try alternative section names |
| 361 | alternative_sections = [".text", ".data", ".rodata"] |
| 362 | for alt_section in alternative_sections: |
| 363 | if alt_section != section_name: |
| 364 | try: |
| 365 | command = [ |
| 366 | str(objcopy_path), |
| 367 | "--update-section", |
| 368 | f"{alt_section}={bin_file}", |
| 369 | str(elf_file), |
| 370 | ] |
| 371 | print(f"Trying alternative section: {alt_section}") |
| 372 | _run_command(command, show_output=True) |
| 373 | print(f"Successfully updated {alt_section} section") |
| 374 | break |
| 375 | except RuntimeError: |
| 376 | continue |
| 377 | |
| 378 | |
| 379 | def bin_to_elf( |
no test coverage detected