build_board.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # @ build_board.py
  2. # Extensions for building JunctionCity using build_bios.py
  3. #
  4. #
  5. # Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
  6. # Copyright (c) 2021, American Megatrends International LLC. <BR>
  7. # SPDX-License-Identifier: BSD-2-Clause-Patent
  8. #
  9. """
  10. This module serves as a sample implementation of the build extension
  11. scripts
  12. """
  13. import os
  14. import sys
  15. def pre_build_ex(config, functions):
  16. """Additional Pre BIOS build function
  17. :param config: The environment variables to be used in the build process
  18. :type config: Dictionary
  19. :param functions: A dictionary of function pointers
  20. :type functions: Dictionary
  21. :returns: nothing
  22. """
  23. print("pre_build_ex")
  24. config["BUILD_DIR_PATH"] = os.path.join(config["WORKSPACE"],
  25. 'Build',
  26. config["PLATFORM_BOARD_PACKAGE"],
  27. "{}_{}".format(
  28. config["TARGET"],
  29. config["TOOL_CHAIN_TAG"]))
  30. # set BUILD_DIR path
  31. config["BUILD_DIR"] = os.path.join('Build',
  32. config["PLATFORM_BOARD_PACKAGE"],
  33. "{}_{}".format(
  34. config["TARGET"],
  35. config["TOOL_CHAIN_TAG"]))
  36. config["BUILD_X64"] = os.path.join(config["BUILD_DIR_PATH"], 'X64')
  37. config["BUILD_IA32"] = os.path.join(config["BUILD_DIR_PATH"], 'IA32')
  38. if not os.path.isdir(config["BUILD_DIR_PATH"]):
  39. try:
  40. os.makedirs(config["BUILD_DIR_PATH"])
  41. except OSError:
  42. print("Error while creating Build folder")
  43. sys.exit(1)
  44. #@todo: Replace this with PcdFspModeSelection
  45. if config.get("API_MODE_FSP_WRAPPER_BUILD", "FALSE") == "TRUE":
  46. config["EXT_BUILD_FLAGS"] += " -D FSP_MODE=0"
  47. else:
  48. config["EXT_BUILD_FLAGS"] += " -D FSP_MODE=1"
  49. if config.get("API_MODE_FSP_WRAPPER_BUILD", "FALSE") == "TRUE":
  50. raise ValueError("FSP API Mode is currently unsupported on Ice Lake Xeon Scalable")
  51. # Build the ACPI AML offset table *.offset.h
  52. print("Info: re-generating PlatformOffset header files")
  53. execute_script = functions.get("execute_script")
  54. # AML offset arch is X64, not sure if it matters.
  55. command = ["build", "-a", "X64", "-t", config["TOOL_CHAIN_TAG"], "-D", "MAX_SOCKET=" + config["MAX_SOCKET"]]
  56. if config["EXT_BUILD_FLAGS"] and config["EXT_BUILD_FLAGS"] != "":
  57. ext_build_flags = config["EXT_BUILD_FLAGS"].split(" ")
  58. ext_build_flags = [x.strip() for x in ext_build_flags]
  59. ext_build_flags = [x for x in ext_build_flags if x != ""]
  60. command.extend(ext_build_flags)
  61. aml_offsets_split = os.path.split(os.path.normpath(config["AML_OFFSETS_PATH"]))
  62. command.append("-p")
  63. command.append(os.path.normpath(config["AML_OFFSETS_PATH"]) + '.dsc')
  64. command.append("-m")
  65. command.append(os.path.join(aml_offsets_split[0], aml_offsets_split[1], aml_offsets_split[1] + '.inf'))
  66. command.append("-y")
  67. command.append(os.path.join(config["WORKSPACE"], "PreBuildReport.txt"))
  68. command.append("--log=" + os.path.join(config["WORKSPACE"], "PreBuild.log"))
  69. shell = True
  70. if os.name == "posix": # linux
  71. shell = False
  72. _, _, _, code = execute_script(command, config, shell=shell)
  73. if code != 0:
  74. print(" ".join(command))
  75. print("Error re-generating PlatformOffset header files")
  76. sys.exit(1)
  77. # Build AmlGenOffset command to consume the *.offset.h and produce AmlOffsetTable.c for StaticSkuDataDxe use.
  78. # Get destination path and filename from config
  79. relative_file_path = os.path.normpath(config["STRIPPED_AML_OFFSETS_FILE_PATH"]) # get path relative to Platform/Intel
  80. out_file_path = os.path.join(config["WORKSPACE_PLATFORM"], relative_file_path) # full path to output file
  81. out_file_dir = os.path.dirname(out_file_path) # remove filename
  82. out_file_root_ext = os.path.splitext(os.path.basename(out_file_path)) # root and extension of output file
  83. # Get relative path for the generated offset.h file
  84. relative_dsdt_file_path = os.path.normpath(config["DSDT_TABLE_FILE_PATH"]) # path relative to Platform/Intel
  85. dsdt_file_root_ext = os.path.splitext(os.path.basename(relative_dsdt_file_path)) # root and extension of generated offset.h file
  86. # Generate output directory if it doesn't exist
  87. if not os.path.exists(out_file_dir):
  88. os.mkdir(out_file_dir)
  89. command = ["python",
  90. os.path.join(config["MIN_PACKAGE_TOOLS"], "AmlGenOffset", "AmlGenOffset.py"),
  91. "-d", "--aml_filter", config["AML_FILTER"],
  92. "-o", out_file_path,
  93. os.path.join(config["BUILD_X64"], aml_offsets_split[0], aml_offsets_split[1], aml_offsets_split[1], "OUTPUT", os.path.dirname(relative_dsdt_file_path), dsdt_file_root_ext[0] + ".offset.h")]
  94. # execute the command
  95. _, _, _, code = execute_script(command, config, shell=shell)
  96. if code != 0:
  97. print(" ".join(command))
  98. print("Error re-generating PlatformOffset header files")
  99. sys.exit(1)
  100. print("GenOffset done")
  101. return None
  102. def _merge_files(files, ofile):
  103. with open(ofile, 'wb') as of:
  104. for x in files:
  105. if not os.path.exists(x):
  106. return
  107. with open(x, 'rb') as f:
  108. of.write(f.read())
  109. def build_ex(config, functions):
  110. """Additional BIOS build function
  111. :param config: The environment variables to be used in the build process
  112. :type config: Dictionary
  113. :param functions: A dictionary of function pointers
  114. :type functions: Dictionary
  115. :returns: config dictionary
  116. :rtype: Dictionary
  117. """
  118. print("build_ex")
  119. fv_path = os.path.join(config["BUILD_DIR_PATH"], "FV")
  120. binary_fd = os.path.join(fv_path, "BINARY.fd")
  121. main_fd = os.path.join(fv_path, "MAIN.fd")
  122. secpei_fd = os.path.join(fv_path, "SECPEI.fd")
  123. board_fd = config["BOARD"].upper()
  124. final_fd = os.path.join(fv_path, "{}.fd".format(board_fd))
  125. _merge_files((binary_fd, main_fd, secpei_fd), final_fd)
  126. return None
  127. def post_build_ex(config, functions):
  128. """Additional Post BIOS build function
  129. :param config: The environment variables to be used in the post
  130. build process
  131. :type config: Dictionary
  132. :param functions: A dictionary of function pointers
  133. :type functions: Dictionary
  134. :returns: config dictionary
  135. :rtype: Dictionary
  136. """
  137. print("post_build_ex")
  138. fv_path = os.path.join(config["BUILD_DIR_PATH"], "FV")
  139. board_fd = config["BOARD"].upper()
  140. final_fd = os.path.join(fv_path, "{}.fd".format(board_fd))
  141. final_ifwi = os.path.join(fv_path, "{}.bin".format(board_fd))
  142. ifwi_ingredients_path = os.path.join(config["WORKSPACE_PLATFORM_BIN"], "Ifwi", config["BOARD"])
  143. flash_descriptor = os.path.join(ifwi_ingredients_path, "FlashDescriptor.bin")
  144. intel_me = os.path.join(ifwi_ingredients_path, "Me.bin")
  145. _merge_files((flash_descriptor, intel_me, final_fd), final_ifwi)
  146. if os.path.isfile(final_fd):
  147. print("IFWI image can be found at {}".format(final_ifwi))
  148. return None
  149. def clean_ex(config, functions):
  150. """Additional clean function
  151. :param config: The environment variables to be used in the build process
  152. :type config: Dictionary
  153. :param functions: A dictionary of function pointers
  154. :type functions: Dictionary
  155. :returns: config dictionary
  156. :rtype: Dictionary
  157. """
  158. print("clean_ex")
  159. return None