build_board.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. command = ["build", "-D", "MAX_SOCKET=" + config["MAX_SOCKET"]]
  55. if config["EXT_BUILD_FLAGS"] and config["EXT_BUILD_FLAGS"] != "":
  56. ext_build_flags = config["EXT_BUILD_FLAGS"].split(" ")
  57. ext_build_flags = [x.strip() for x in ext_build_flags]
  58. ext_build_flags = [x for x in ext_build_flags if x != ""]
  59. command.extend(ext_build_flags)
  60. aml_offsets_split = os.path.split(os.path.normpath(config["AML_OFFSETS_PATH"]))
  61. command.append("-p")
  62. command.append(os.path.normpath(config["AML_OFFSETS_PATH"]) + '.dsc')
  63. command.append("-m")
  64. command.append(os.path.join(aml_offsets_split[0], aml_offsets_split[1], aml_offsets_split[1] + '.inf'))
  65. command.append("-y")
  66. command.append(os.path.join(config["WORKSPACE"], "PreBuildReport.txt"))
  67. command.append("--log=" + os.path.join(config["WORKSPACE"], "PreBuild.log"))
  68. _, _, _, code = execute_script(command, config)
  69. if code != 0:
  70. print(" ".join(command))
  71. print("Error re-generating PlatformOffset header files")
  72. sys.exit(1)
  73. # Build AmlGenOffset command to consume the *.offset.h and produce AmlOffsetTable.c for StaticSkuDataDxe use.
  74. # Get destination path and filename from config
  75. relative_file_path = os.path.normpath(config["STRIPPED_AML_OFFSETS_FILE_PATH"]) # get path relative to Platform/Intel
  76. out_file_path = os.path.join(config["WORKSPACE_PLATFORM"], relative_file_path) # full path to output file
  77. out_file_dir = os.path.dirname(out_file_path) # remove filename
  78. out_file_root_ext = os.path.splitext(os.path.basename(out_file_path)) # root and extension of output file
  79. # Get relative path for the generated offset.h file
  80. relative_dsdt_file_path = os.path.normpath(config["DSDT_TABLE_FILE_PATH"]) # path relative to Platform/Intel
  81. dsdt_file_root_ext = os.path.splitext(os.path.basename(relative_dsdt_file_path)) # root and extension of generated offset.h file
  82. # Generate output directory if it doesn't exist
  83. if not os.path.exists(out_file_dir):
  84. os.mkdir(out_file_dir)
  85. command = ["python",
  86. os.path.join(config["MIN_PACKAGE_TOOLS"], "AmlGenOffset", "AmlGenOffset.py"),
  87. "-d", "--aml_filter", config["AML_FILTER"],
  88. "-o", out_file_path,
  89. 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")]
  90. # execute the command
  91. _, _, _, code = execute_script(command, config)
  92. if code != 0:
  93. print(" ".join(command))
  94. print("Error re-generating PlatformOffset header files")
  95. sys.exit(1)
  96. print("GenOffset done")
  97. return None
  98. def _merge_files(files, ofile):
  99. with open(ofile, 'wb') as of:
  100. for x in files:
  101. if not os.path.exists(x):
  102. return
  103. with open(x, 'rb') as f:
  104. of.write(f.read())
  105. def build_ex(config, functions):
  106. """Additional BIOS build function
  107. :param config: The environment variables to be used in the build process
  108. :type config: Dictionary
  109. :param functions: A dictionary of function pointers
  110. :type functions: Dictionary
  111. :returns: config dictionary
  112. :rtype: Dictionary
  113. """
  114. print("build_ex")
  115. fv_path = os.path.join(config["BUILD_DIR_PATH"], "FV")
  116. binary_fd = os.path.join(fv_path, "BINARY.fd")
  117. main_fd = os.path.join(fv_path, "MAIN.fd")
  118. secpei_fd = os.path.join(fv_path, "SECPEI.fd")
  119. board_fd = config["BOARD"].upper()
  120. final_fd = os.path.join(fv_path, "{}.fd".format(board_fd))
  121. _merge_files((binary_fd, main_fd, secpei_fd), final_fd)
  122. return None
  123. def post_build_ex(config, functions):
  124. """Additional Post BIOS build function
  125. :param config: The environment variables to be used in the post
  126. build process
  127. :type config: Dictionary
  128. :param functions: A dictionary of function pointers
  129. :type functions: Dictionary
  130. :returns: config dictionary
  131. :rtype: Dictionary
  132. """
  133. print("post_build_ex")
  134. fv_path = os.path.join(config["BUILD_DIR_PATH"], "FV")
  135. board_fd = config["BOARD"].upper()
  136. final_fd = os.path.join(fv_path, "{}.fd".format(board_fd))
  137. final_ifwi = os.path.join(fv_path, "{}.bin".format(board_fd))
  138. ifwi_ingredients_path = os.path.join(config["WORKSPACE_PLATFORM_BIN"], "Ifwi", config["BOARD"])
  139. flash_descriptor = os.path.join(ifwi_ingredients_path, "FlashDescriptor.bin")
  140. intel_me = os.path.join(ifwi_ingredients_path, "Me.bin")
  141. _merge_files((flash_descriptor, intel_me, final_fd), final_ifwi)
  142. if os.path.isfile(final_fd):
  143. print("IFWI image can be found at {}".format(final_ifwi))
  144. return None
  145. def clean_ex(config, functions):
  146. """Additional clean function
  147. :param config: The environment variables to be used in the build process
  148. :type config: Dictionary
  149. :param functions: A dictionary of function pointers
  150. :type functions: Dictionary
  151. :returns: config dictionary
  152. :rtype: Dictionary
  153. """
  154. print("clean_ex")
  155. return None