build_board.py 7.7 KB

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