generate_files.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #! /usr/bin/env python3
  2. import os
  3. import sys
  4. import shutil
  5. # get the path of current file
  6. cmd = os.path.split(os.path.realpath(__file__))[0]
  7. if not os.path.exists(os.path.join(cmd, '../packages/raspberrypi-pico-sdk-latest')):
  8. print('Error: raspberrypi-pico-sdk not found, please run "pkgs --update" first')
  9. exit(1)
  10. if os.path.exists(os.path.join(cmd, 'build')):
  11. shutil.rmtree(os.path.join(cmd, 'build'))
  12. os.mkdir(os.path.join(cmd, 'build'))
  13. os.chdir(os.path.join(cmd, 'build'))
  14. # run cmake
  15. os.system('cmake ' + os.path.join(cmd, '../packages/raspberrypi-pico-sdk-latest'))
  16. os.system('make ELF2UF2Build bs2_default_padded_checksummed_asm')
  17. # copy header files
  18. shutil.copytree(os.path.join(cmd, 'build', 'generated'), os.path.join(cmd, 'generated'), dirs_exist_ok = True)
  19. # copy the generated files to the destination
  20. if "linux" in sys.platform:
  21. shutil.copyfile(os.path.join(cmd, 'build', 'elf2uf2', 'elf2uf2'), os.path.join(cmd, 'elf2uf2'))
  22. if "win32" in sys.platform:
  23. shutil.copyfile(os.path.join(cmd, 'build', 'elf2uf2', 'elf2uf2.exe'), os.path.join(cmd, 'elf2uf2.exe'))
  24. # copy bs2_default_padded_checksummed_asm
  25. shutil.copyfile(os.path.join(cmd, 'build', 'src', 'rp2_common', 'boot_stage2', 'bs2_default_padded_checksummed.S'), \
  26. os.path.join(cmd, 'generated', 'bs2_default_padded_checksummed.S'))
  27. # clean up
  28. shutil.rmtree(os.path.join(cmd, 'build'))