process-linker-script.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
  2. #
  3. # ZuluSCSI™ file is licensed under the GPL version 3 or any later version. 
  4. #
  5. # https://www.gnu.org/licenses/gpl-3.0.html
  6. # ----
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version. 
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details. 
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  19. from string import Template
  20. Import ("env")
  21. template_file = 'lib/ZuluSCSI_platform_RP2040/rp2040-template.ld'
  22. linker_file = env.subst('$BUILD_DIR') + '/rp2040.ld'
  23. def process_template(source, target, env):
  24. values = {
  25. 'program_size': env.GetProjectOption('program_flash_allocation'),
  26. 'project_name': env.subst('$PIOENV')
  27. }
  28. with open(template_file, 'r') as t:
  29. src = Template(t.read())
  30. result = src.substitute(values)
  31. with open(linker_file, 'w') as linker_script:
  32. linker_script.write(result)
  33. env.AddPreAction("${BUILD_DIR}/${PROGNAME}.elf",
  34. env.VerboseAction(process_template,
  35. 'Generating linker script: "' + linker_file + '" from : "' + template_file + '"'
  36. )
  37. )