Skip to content

Instantly share code, notes, and snippets.

@igrr
Created January 13, 2023 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrr/c17487c1ea4060161529e5a0d4a49eb1 to your computer and use it in GitHub Desktop.
Save igrr/c17487c1ea4060161529e5a0d4a49eb1 to your computer and use it in GitHub Desktop.
create an intel hex file from IDF build directory
#!/usr/bin/env python
import intelhex
import json
from pathlib import Path
def main():
build_dir = Path('build')
if not build_dir.exists() or not build_dir.is_dir():
print('build directory doesn\'t exist')
raise SystemExit(1)
flasher_args_file = build_dir / 'flasher_args.json'
if not flasher_args_file.exists():
print('build/flasher_args.json doesn\'t exist')
raise SystemExit(1)
flasher_args = json.loads(flasher_args_file.read_text(encoding='utf-8'))
flash_files = flasher_args['flash_files']
output_file_name = flasher_args['app']['file'].replace('.bin', '.hex')
hexfile = intelhex.IntelHex()
for offset, filename in flash_files.items():
file = build_dir / filename
hexfile.loadbin(file, offset=int(offset, 0))
hexfile.write_hex_file(build_dir / output_file_name)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment