copy_partitions.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #This script is based on the Tasmota rename-firmware.py script. https://github.com/arendst/Tasmota
  2. Import('env')
  3. import os
  4. import shutil
  5. buildFlags = env.ParseFlags(env['BUILD_FLAGS'])
  6. OUTPUT_DIR = "build_output{}".format(os.path.sep)
  7. platform = env.PioPlatform()
  8. FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
  9. FRAMEWORK_DIR = "{}{}".format(FRAMEWORK_DIR, os.path.sep)
  10. def copy_boot_partitions(source, target, env):
  11. # check if output directories exist and create if necessary
  12. if not os.path.isdir(OUTPUT_DIR):
  13. os.mkdir(OUTPUT_DIR)
  14. for d in ['firmware', 'map']:
  15. if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
  16. os.mkdir("{}{}".format(OUTPUT_DIR, d))
  17. # create string with location and file names based on variant
  18. src = str(target[0])
  19. dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "partitions.bin")
  20. print(src)
  21. print(dst)
  22. # check if new target files exist and remove if necessary
  23. for f in [dst]:
  24. if os.path.isfile(f):
  25. os.remove(f)
  26. # copy firmware.bin to firmware/<variant>.bin
  27. shutil.copy(src,dst)
  28. # create string with location and file names based on variant
  29. src = "{}tools{}partitions{}boot_app0.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep)
  30. dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "boot_app0.bin")
  31. print(src)
  32. print(dst)
  33. # check if new target files exist and remove if necessary
  34. for f in [dst]:
  35. if os.path.isfile(f):
  36. os.remove(f)
  37. # copy firmware.bin to firmware/<variant>.bin
  38. shutil.copy(src,dst)
  39. # create string with location and file names based on variant
  40. src = "{}tools{}sdk{}bin{}bootloader_dio_40m.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep, os.path.sep)
  41. dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "bootloader_dio_40m.bin")
  42. print(src)
  43. print(dst)
  44. # check if new target files exist and remove if necessary
  45. for f in [dst]:
  46. if os.path.isfile(f):
  47. os.remove(f)
  48. # copy firmware.bin to firmware/<variant>.bin
  49. shutil.copy(src,dst)
  50. env.AddPostAction("$BUILD_DIR/partitions.bin", [copy_boot_partitions])