copy_files.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #/*
  2. # * FreeRTOS Kernel V10.4.6
  3. # * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. # *
  5. # * SPDX-License-Identifier: MIT
  6. # *
  7. # * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. # * this software and associated documentation files (the "Software"), to deal in
  9. # * the Software without restriction, including without limitation the rights to
  10. # * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. # * the Software, and to permit persons to whom the Software is furnished to do so,
  12. # * subject to the following conditions:
  13. # *
  14. # * The above copyright notice and this permission notice shall be included in all
  15. # * copies or substantial portions of the Software.
  16. # *
  17. # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. # * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. # * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. # * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. # * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. # *
  24. # * https://www.FreeRTOS.org
  25. # * https://github.com/FreeRTOS
  26. # *
  27. # */
  28. import os
  29. import shutil
  30. _THIS_FILE_DIRECTORY_ = os.path.dirname(os.path.realpath(__file__))
  31. _FREERTOS_PORTABLE_DIRECTORY_ = os.path.dirname(_THIS_FILE_DIRECTORY_)
  32. _COMPILERS_ = ['GCC', 'IAR']
  33. _ARCH_NS_ = ['ARM_CM33', 'ARM_CM33_NTZ', 'ARM_CM23', 'ARM_CM23_NTZ']
  34. _ARCH_S_ = ['ARM_CM33', 'ARM_CM23']
  35. _SUPPORTED_CONFIGS_ = {
  36. 'GCC' : ['ARM_CM33', 'ARM_CM33_NTZ', 'ARM_CM23', 'ARM_CM23_NTZ'],
  37. 'IAR' : ['ARM_CM33', 'ARM_CM33_NTZ', 'ARM_CM23', 'ARM_CM23_NTZ']
  38. }
  39. # Files to be complied in the Secure Project
  40. _SECURE_FILE_PATHS_ = [
  41. os.path.join('secure', 'context'),
  42. os.path.join('secure', 'context', 'portable', '_COMPILER_ARCH_'),
  43. os.path.join('secure', 'heap'),
  44. os.path.join('secure', 'init'),
  45. os.path.join('secure', 'macros')
  46. ]
  47. # Files to be complied in the Non-Secure Project
  48. _NONSECURE_FILE_PATHS_ = [
  49. 'non_secure',
  50. os.path.join('non_secure', 'portable', '_COMPILER_ARCH_')
  51. ]
  52. def is_supported_config(compiler, arch):
  53. return arch in _SUPPORTED_CONFIGS_[compiler]
  54. def copy_files_in_dir(src_abs_path, dst_abs_path):
  55. for src_file in os.listdir(src_abs_path):
  56. src_file_abs_path = os.path.join(src_abs_path, src_file)
  57. if os.path.isfile(src_file_abs_path) and src_file != 'ReadMe.txt':
  58. if not os.path.exists(dst_abs_path):
  59. os.makedirs(dst_abs_path)
  60. print('Copying {}...'.format(os.path.basename(src_file_abs_path)))
  61. shutil.copy2(src_file_abs_path, dst_abs_path)
  62. def copy_files_for_compiler_and_arch(compiler, arch, src_paths, dst_path):
  63. _COMPILER_ARCH_ = os.path.join(compiler, arch)
  64. for src_path in src_paths:
  65. src_path_sanitized = src_path.replace('_COMPILER_ARCH_', _COMPILER_ARCH_ )
  66. src_abs_path = os.path.join(_THIS_FILE_DIRECTORY_, src_path_sanitized)
  67. dst_abs_path = os.path.join(_FREERTOS_PORTABLE_DIRECTORY_, _COMPILER_ARCH_, dst_path)
  68. copy_files_in_dir(src_abs_path, dst_abs_path)
  69. def copy_files():
  70. # Copy Secure Files
  71. for compiler in _COMPILERS_:
  72. for arch in _ARCH_S_:
  73. if is_supported_config(compiler, arch):
  74. copy_files_for_compiler_and_arch(compiler, arch, _SECURE_FILE_PATHS_, 'secure')
  75. # Copy Non-Secure Files
  76. for compiler in _COMPILERS_:
  77. for arch in _ARCH_NS_:
  78. if is_supported_config(compiler, arch):
  79. copy_files_for_compiler_and_arch(compiler, arch, _NONSECURE_FILE_PATHS_, 'non_secure')
  80. def main():
  81. copy_files()
  82. if __name__ == '__main__':
  83. main()