LinuxGcc5ToolChain.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # @file LinuxGcc5ToolChain.py
  2. # Plugin to configures paths for GCC5 ARM/AARCH64 Toolchain
  3. ##
  4. # This plugin works in conjuncture with the tools_def
  5. #
  6. # Copyright (c) Microsoft Corporation
  7. # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
  8. # Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>
  9. # SPDX-License-Identifier: BSD-2-Clause-Patent
  10. ##
  11. import os
  12. import logging
  13. from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin
  14. from edk2toolext.environment import shell_environment
  15. class LinuxGcc5ToolChain(IUefiBuildPlugin):
  16. def do_post_build(self, thebuilder):
  17. return 0
  18. def do_pre_build(self, thebuilder):
  19. self.Logger = logging.getLogger("LinuxGcc5ToolChain")
  20. #
  21. # GCC5 - The ARM and AARCH64 compilers need their paths set if available
  22. if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "GCC5":
  23. # Start with AARACH64 compiler
  24. ret = self._check_aarch64()
  25. if ret != 0:
  26. self.Logger.critical("Failed in check aarch64")
  27. return ret
  28. # Check arm compiler
  29. ret = self._check_arm()
  30. if ret != 0:
  31. self.Logger.critical("Failed in check arm")
  32. return ret
  33. # Check RISCV64 compiler
  34. ret = self._check_riscv64()
  35. if ret != 0:
  36. self.Logger.critical("Failed in check riscv64")
  37. return ret
  38. # Check LoongArch64 compiler
  39. ret = self._check_loongarch64()
  40. if ret != 0:
  41. self.Logger.critical("Failed in check loongarch64")
  42. return ret
  43. return 0
  44. def _check_arm(self):
  45. # check to see if full path already configured
  46. if shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") is not None:
  47. self.Logger.info("GCC5_ARM_PREFIX is already set.")
  48. else:
  49. # now check for install dir. If set then set the Prefix
  50. install_path = shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_INSTALL")
  51. if install_path is None:
  52. return 0
  53. # make GCC5_ARM_PREFIX to align with tools_def.txt
  54. prefix = os.path.join(install_path, "bin", "arm-none-linux-gnueabihf-")
  55. shell_environment.GetEnvironment().set_shell_var("GCC5_ARM_PREFIX", prefix)
  56. # now confirm it exists
  57. if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") + "gcc"):
  58. self.Logger.error("Path for GCC5_ARM_PREFIX toolchain is invalid")
  59. return -2
  60. return 0
  61. def _check_aarch64(self):
  62. # check to see if full path already configured
  63. if shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") is not None:
  64. self.Logger.info("GCC5_AARCH64_PREFIX is already set.")
  65. else:
  66. # now check for install dir. If set then set the Prefix
  67. install_path = shell_environment.GetEnvironment(
  68. ).get_shell_var("GCC5_AARCH64_INSTALL")
  69. if install_path is None:
  70. return 0
  71. # make GCC5_AARCH64_PREFIX to align with tools_def.txt
  72. prefix = os.path.join(install_path, "bin", "aarch64-none-linux-gnu-")
  73. shell_environment.GetEnvironment().set_shell_var("GCC5_AARCH64_PREFIX", prefix)
  74. # now confirm it exists
  75. if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") + "gcc"):
  76. self.Logger.error(
  77. "Path for GCC5_AARCH64_PREFIX toolchain is invalid")
  78. return -2
  79. return 0
  80. def _check_riscv64(self):
  81. # now check for install dir.  If set then set the Prefix
  82. install_path = shell_environment.GetEnvironment(
  83. ).get_shell_var("GCC5_RISCV64_INSTALL")
  84. if install_path is None:
  85. return 0
  86. # check to see if full path already configured
  87. if shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") is not None:
  88. self.Logger.info("GCC5_RISCV64_PREFIX is already set.")
  89. else:
  90. # make GCC5_RISCV64_PREFIX to align with tools_def.txt
  91. prefix = os.path.join(install_path, "bin", "riscv64-unknown-elf-")
  92. shell_environment.GetEnvironment().set_shell_var("GCC5_RISCV64_PREFIX", prefix)
  93. # now confirm it exists
  94. if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") + "gcc"):
  95. self.Logger.error(
  96. "Path for GCC5_RISCV64_PREFIX toolchain is invalid")
  97. return -2
  98. # Check if LD_LIBRARY_PATH is set for the libraries of RISC-V GCC toolchain
  99. if shell_environment.GetEnvironment().get_shell_var("LD_LIBRARY_PATH") is not None:
  100. self.Logger.info("LD_LIBRARY_PATH is already set.")
  101. prefix = os.path.join(install_path, "lib")
  102. shell_environment.GetEnvironment().set_shell_var("LD_LIBRARY_PATH", prefix)
  103. return 0
  104. def _check_loongarch64(self):
  105. # check to see if full path already configured
  106. if shell_environment.GetEnvironment().get_shell_var("GCC5_LOONGARCH64_PREFIX") is not None:
  107. self.Logger.info("GCC5_LOONGARCH64_PREFIX is already set.")
  108. else:
  109. # now check for install dir. If set then set the Prefix
  110. install_path = shell_environment.GetEnvironment(
  111. ).get_shell_var("GCC5_LOONGARCH64_INSTALL")
  112. if install_path is None:
  113. return 0
  114. # make GCC5_LOONGARCH64_PREFIX to align with tools_def.txt
  115. prefix = os.path.join(install_path, "bin", "loongarch64-unknown-linux-gnu-")
  116. shell_environment.GetEnvironment().set_shell_var("GCC5_LOONGARCH64_PREFIX", prefix)
  117. # now confirm it exists
  118. if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_LOONGARCH64_PREFIX") + "gcc"):
  119. self.Logger.error(
  120. "Path for GCC5_LOONGARCH64_PREFIX toolchain is invalid")
  121. return -2
  122. return 0