summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xBaseTools/Conf/build_rule.template15
-rw-r--r--BaseTools/Source/Python/AmlToC/AmlToC.py82
2 files changed, 47 insertions, 50 deletions
diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
index 0822b681fc..c034869915 100755
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -419,6 +419,7 @@
<OutputFile>
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml
+ $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.amli
<ExtraDependency>
$(MAKE_FILE)
@@ -428,14 +429,24 @@
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
- -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml
+ $(CP) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.amli
<Command.GCC>
Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
- -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml
+ $(CP) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.amli
+
+[Acpi-Machine-Language-File-to-C.DXE_DRIVER]
+ <InputFile>
+ ?.amli
+
+ <OutputFile>
+ ${s_path}(+)${s_base}.c
+
+ <Command>
+ -AmlToC ${src}
[C-Code-File.AcpiTable]
<InputFile>
diff --git a/BaseTools/Source/Python/AmlToC/AmlToC.py b/BaseTools/Source/Python/AmlToC/AmlToC.py
index 643db2910e..346de7159d 100644
--- a/BaseTools/Source/Python/AmlToC/AmlToC.py
+++ b/BaseTools/Source/Python/AmlToC/AmlToC.py
@@ -1,9 +1,9 @@
## @file
#
-# Convert an AML file to a .hex file containing the AML bytecode stored in a
+# Convert an AML file to a .c file containing the AML bytecode stored in a
# C array.
-# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".
-# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that contains
+# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.c".
+# "Tables\Dsdt.c" will contain a C array named "dsdt_aml_code" that contains
# the AML bytecode.
#
# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
@@ -17,31 +17,26 @@ from Common.BuildToolError import *
import sys
import os
+__description__ = """
+Convert an AML file to a .c file containing the AML bytecode stored in a C
+array. By default, Tables\Dsdt.aml will generate Tables\Dsdt.c.
+Tables\Dsdt.c will contain a C array named "dsdt_aml_code" that contains
+the AML bytecode.
+"""
+
## Parse the command line arguments.
#
# @retval A argparse.NameSpace instance, containing parsed values.
#
def ParseArgs():
# Initialize the parser.
- Parser = argparse.ArgumentParser(
- description="Convert an AML file to a .hex file containing the AML " + \
- "bytecode stored in a C array. By default, " + \
- "\"Tables\\Dsdt.aml\" will generate" + \
- "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \
- "contain a C array named \"dsdt_aml_code\" that " + \
- "contains the AML bytecode."
- )
+ Parser = argparse.ArgumentParser(description=__description__)
# Define the possible arguments.
- Parser.add_argument(
- dest="InputFile",
- help="Path to an input AML file to generate a .hex file from."
- )
- Parser.add_argument(
- "-o", "--out-dir", dest="OutDir",
- help="Output directory where the .hex file will be generated. " + \
- "Default is the input file's directory."
- )
+ Parser.add_argument(dest="InputFile",
+ help="Path to an input AML file to generate a .c file from.")
+ Parser.add_argument("-o", "--out-dir", dest="OutDir",
+ help="Output directory where the .c file will be generated. Default is the input file's directory.")
# Parse the input arguments.
Args = Parser.parse_args()
@@ -55,9 +50,7 @@ def ParseArgs():
with open(Args.InputFile, "rb") as fIn:
Signature = str(fIn.read(4))
if ("DSDT" not in Signature) and ("SSDT" not in Signature):
- EdkLogger.info("Invalid file type. " + \
- "File does not have a valid " + \
- "DSDT or SSDT signature: %s" % Args.InputFile)
+ EdkLogger.info("Invalid file type. File does not have a valid DSDT or SSDT signature: {}".format(Args.InputFile))
return None
# Get the basename of the input file.
@@ -66,42 +59,39 @@ def ParseArgs():
# If no output directory is specified, output to the input directory.
if not Args.OutDir:
- Args.OutputFile = os.path.join(
- os.path.dirname(Args.InputFile),
- BaseName + ".hex"
- )
+ Args.OutputFile = os.path.join(os.path.dirname(Args.InputFile),
+ BaseName + ".c")
else:
if not os.path.exists(Args.OutDir):
os.mkdir(Args.OutDir)
- Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".hex")
+ Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".c")
Args.BaseName = BaseName
return Args
-## Convert an AML file to a .hex file containing the AML bytecode stored
+## Convert an AML file to a .c file containing the AML bytecode stored
# in a C array.
#
# @param InputFile Path to the input AML file.
-# @param OutputFile Path to the output .hex file to generate.
+# @param OutputFile Path to the output .c file to generate.
# @param BaseName Base name of the input file.
-# This is also the name of the generated .hex file.
+# This is also the name of the generated .c file.
#
-def AmlToHex(InputFile, OutputFile, BaseName):
+def AmlToC(InputFile, OutputFile, BaseName):
- MacroName = "__{}_HEX__".format(BaseName.upper())
ArrayName = BaseName.lower() + "_aml_code"
+ FileHeader =\
+"""
+// This file has been generated from:
+// -Python script: {}
+// -Input AML file: {}
+
+"""
with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:
# Write header.
- fOut.write("// This file has been generated from:\n" + \
- "// \tPython script: " + \
- os.path.abspath(__file__) + "\n" + \
- "// \tInput AML file: " + \
- os.path.abspath(InputFile) + "\n\n" + \
- "#ifndef {}\n".format(MacroName) + \
- "#define {}\n\n".format(MacroName)
- )
+ fOut.write(FileHeader.format(os.path.abspath(InputFile), os.path.abspath(__file__)))
# Write the array and its content.
fOut.write("unsigned char {}[] = {{\n ".format(ArrayName))
@@ -115,15 +105,12 @@ def AmlToHex(InputFile, OutputFile, BaseName):
byte = fIn.read(1)
fOut.write("\n};\n")
- # Write footer.
- fOut.write("#endif // {}\n".format(MacroName))
-
## Main method
#
# This method:
# 1- Initialize an EdkLogger instance.
# 2- Parses the input arguments.
-# 3- Converts an AML file to a .hex file containing the AML bytecode stored
+# 3- Converts an AML file to a .c file containing the AML bytecode stored
# in a C array.
#
# @retval 0 Success.
@@ -139,10 +126,9 @@ def Main():
if not CommandArguments:
return 1
- # Convert an AML file to a .hex file containing the AML bytecode stored
+ # Convert an AML file to a .c file containing the AML bytecode stored
# in a C array.
- AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,
- CommandArguments.BaseName)
+ AmlToC(CommandArguments.InputFile, CommandArguments.OutputFile, CommandArguments.BaseName)
except Exception as e:
print(e)
return 1