MCPcopy Create free account
hub / github.com/FastLED/FastLED / bin_to_elf

Function bin_to_elf

ci/util/bin_2_elf.py:379–442  ·  view source on GitHub ↗

Convert a binary file to ELF format with platform detection and analysis. Args: bin_file (Path): Path to the input binary file. map_file (Path): Path to the map file. as_path (Path): Path to the assembler executable. ld_path (Path): Path to the linker execut

(
    bin_file: Path,
    map_file: Path,
    as_path: Path,
    ld_path: Path,
    objcopy_path: Path,
    output_elf: Path,
)

Source from the content-addressed store, hash-verified

377
378
379def bin_to_elf(
380 bin_file: Path,
381 map_file: Path,
382 as_path: Path,
383 ld_path: Path,
384 objcopy_path: Path,
385 output_elf: Path,
386):
387 """
388 Convert a binary file to ELF format with platform detection and analysis.
389
390 Args:
391 bin_file (Path): Path to the input binary file.
392 map_file (Path): Path to the map file.
393 as_path (Path): Path to the assembler executable.
394 ld_path (Path): Path to the linker executable.
395 objcopy_path (Path): Path to the objcopy executable.
396 output_elf (Path): Path to the output ELF file.
397
398 Returns:
399 Path: Path to the generated ELF file.
400 """
401 print("=" * 80)
402 print("IMPROVED BINARY TO ELF CONVERTER")
403 print("=" * 80)
404
405 # Detect platform from toolchain
406 platform = _detect_platform_from_paths(as_path, ld_path)
407 print(f"Detected platform: {platform}")
408
409 # Analyze binary structure
410 binary_analysis = _analyze_binary_structure(bin_file, platform)
411
412 # Generate platform-specific linker script
413 linker_script = _generate_platform_linker_script(map_file, platform)
414
415 # Create platform-specific dummy object file
416 dummy_obj_path = bin_file.with_name(f"dummy_{platform}.o")
417 _create_platform_object_file(as_path, dummy_obj_path, platform)
418
419 # Create a dummy ELF file using the generated linker script
420 _create_dummy_elf(ld_path, linker_script, dummy_obj_path, output_elf, platform)
421
422 # Update the ELF sections with binary data
423 _update_elf_sections(objcopy_path, bin_file, output_elf, platform)
424
425 # Clean up temporary files
426 if dummy_obj_path.exists():
427 dummy_obj_path.unlink()
428 print(f"Cleaned up dummy object file: {dummy_obj_path}")
429
430 if linker_script.exists():
431 linker_script.unlink()
432 print(f"Cleaned up linker script: {linker_script}")
433
434 print(f"\n✅ Successfully created {platform} ELF file: {output_elf}")
435
436 # Save analysis results

Callers 2

mainFunction · 0.90

Calls 9

_create_dummy_elfFunction · 0.85
_update_elf_sectionsFunction · 0.85
unlinkMethod · 0.80
printFunction · 0.50
dumpMethod · 0.45

Tested by 1