]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Rename AmlToHex script to AmlToC
authorPierre Gondois <pierre.gondois@arm.com>
Wed, 1 Jul 2020 14:06:02 +0000 (22:06 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 2 Jul 2020 10:09:17 +0000 (10:09 +0000)
The AmlToHex script and Posix/WindowsLike wrappers convert
an AML file to a .hex file, containing a C array storing
AML bytecode. This ".hex" file can then be included in a
C file, allowing to access the AML bytecode from this C
file.

The EDK2 build system doesn't allow to a depict dependency
orders between files of different languages. For instance,
in a module containing a ".c" file and a ".asl", the ".c"
file may or may not be built prior to the ".asl" file.
This prevents any inclusion of a generated ".hex" in a
".c" file since this later ".hex" file may or may not
have been created yet.

This patch renames the script as AmlToC. It is posted as
a separate patch to prevent git from seeing the renaming
as a deletion plus addition of a new file.
The ending line of the posix-like bin-wrapper script has
also been corrected.

This is a first step toward generating a C file containing
the AML bytecode from an ASL file. This C file will then
be handled by the EDK2 build system to generate an object
file.
Thus, no file inclusion will be required anymore. The C file
requiring the AML bytecode as a C array, and the ASL file,
will be compiled independently. The C array must be defined
as an external symbol. The linker is resolving the
reference to the C array symbol.

To summarize, the flow goes as:
 -1. ASL file is compiled to AML;
 -2. AML file is copied to a ".amli" intermediate file;
 -3. EDK2 build system applies the rule relevant to ".amli"
     files. This is, calling the "AmlToC" script, generating
     a C file from the ".amli" file;
 -4. EDK2 build system applies the rule relevant to C files.
     This is creating an object file.
 -5. EDK2 build system links the object file containing the
     AML bytecode with the object file requiring it.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Suggested-by: Tomas Pilar <Tomas.Pilar@arm.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/BinWrappers/PosixLike/AmlToC [new file with mode: 0755]
BaseTools/BinWrappers/PosixLike/AmlToHex [deleted file]
BaseTools/BinWrappers/WindowsLike/AmlToC.bat [new file with mode: 0644]
BaseTools/BinWrappers/WindowsLike/AmlToHex.bat [deleted file]
BaseTools/Source/Python/AmlToC/AmlToC.py [new file with mode: 0644]
BaseTools/Source/Python/AmlToHex/AmlToHex.py [deleted file]

diff --git a/BaseTools/BinWrappers/PosixLike/AmlToC b/BaseTools/BinWrappers/PosixLike/AmlToC
new file mode 100755 (executable)
index 0000000..1dd28e9
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#python `dirname $0`/RunToolFromSource.py `basename $0` $*
+
+# If a ${PYTHON_COMMAND} command is available, use it in preference to python
+if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+    python_exe=${PYTHON_COMMAND}
+fi
+
+full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
+dir=$(dirname "$full_cmd")
+exe=$(basename "$full_cmd")
+
+export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"
+exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@"
diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex b/BaseTools/BinWrappers/PosixLike/AmlToHex
deleted file mode 100755 (executable)
index 9fb6829..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash\r
-#python `dirname $0`/RunToolFromSource.py `basename $0` $*\r
-\r
-# If a ${PYTHON_COMMAND} command is available, use it in preference to python\r
-if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then\r
-    python_exe=${PYTHON_COMMAND}\r
-fi\r
-\r
-full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here\r
-dir=$(dirname "$full_cmd")\r
-exe=$(basename "$full_cmd")\r
-\r
-export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"\r
-exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@"\r
diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToC.bat b/BaseTools/BinWrappers/WindowsLike/AmlToC.bat
new file mode 100644 (file)
index 0000000..9616cd8
--- /dev/null
@@ -0,0 +1,3 @@
+@setlocal\r
+@set ToolName=%~n0%\r
+@%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*\r
diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
deleted file mode 100644 (file)
index 9616cd8..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-@setlocal\r
-@set ToolName=%~n0%\r
-@%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*\r
diff --git a/BaseTools/Source/Python/AmlToC/AmlToC.py b/BaseTools/Source/Python/AmlToC/AmlToC.py
new file mode 100644 (file)
index 0000000..643db29
--- /dev/null
@@ -0,0 +1,156 @@
+## @file\r
+#\r
+# Convert an AML file to a .hex file containing the AML bytecode stored in a\r
+# C array.\r
+# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".\r
+# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that contains\r
+# the AML bytecode.\r
+#\r
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+\r
+import argparse\r
+import Common.EdkLogger as EdkLogger\r
+from Common.BuildToolError import *\r
+import sys\r
+import os\r
+\r
+## Parse the command line arguments.\r
+#\r
+# @retval A argparse.NameSpace instance, containing parsed values.\r
+#\r
+def ParseArgs():\r
+    # Initialize the parser.\r
+    Parser = argparse.ArgumentParser(\r
+      description="Convert an AML file to a .hex file containing the AML " + \\r
+                  "bytecode stored in a C array. By default, " + \\r
+                  "\"Tables\\Dsdt.aml\" will generate" + \\r
+                  "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \\r
+                  "contain a C array named \"dsdt_aml_code\" that " + \\r
+                  "contains the AML bytecode."\r
+      )\r
+\r
+    # Define the possible arguments.\r
+    Parser.add_argument(\r
+      dest="InputFile",\r
+      help="Path to an input AML file to generate a .hex file from."\r
+      )\r
+    Parser.add_argument(\r
+      "-o", "--out-dir", dest="OutDir",\r
+      help="Output directory where the .hex file will be generated. " + \\r
+           "Default is the input file's directory."\r
+      )\r
+\r
+    # Parse the input arguments.\r
+    Args = Parser.parse_args()\r
+    SplitInputName = ""\r
+\r
+    if not os.path.exists(Args.InputFile):\r
+        EdkLogger.error(__file__, FILE_OPEN_FAILURE,\r
+                        ExtraData=Args.InputFile)\r
+        return None\r
+    else:\r
+        with open(Args.InputFile, "rb") as fIn:\r
+            Signature = str(fIn.read(4))\r
+            if ("DSDT" not in Signature) and ("SSDT" not in Signature):\r
+                EdkLogger.info("Invalid file type. " + \\r
+                                "File does not have a valid " + \\r
+                                "DSDT or SSDT signature: %s" % Args.InputFile)\r
+                return None\r
+\r
+    # Get the basename of the input file.\r
+    SplitInputName = os.path.splitext(Args.InputFile)\r
+    BaseName = os.path.basename(SplitInputName[0])\r
+\r
+    # If no output directory is specified, output to the input directory.\r
+    if not Args.OutDir:\r
+        Args.OutputFile = os.path.join(\r
+          os.path.dirname(Args.InputFile),\r
+          BaseName + ".hex"\r
+          )\r
+    else:\r
+        if not os.path.exists(Args.OutDir):\r
+            os.mkdir(Args.OutDir)\r
+        Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".hex")\r
+\r
+    Args.BaseName = BaseName\r
+\r
+    return Args\r
+\r
+## Convert an AML file to a .hex file containing the AML bytecode stored\r
+#  in a C array.\r
+#\r
+# @param  InputFile     Path to the input AML file.\r
+# @param  OutputFile    Path to the output .hex file to generate.\r
+# @param  BaseName      Base name of the input file.\r
+#                       This is also the name of the generated .hex file.\r
+#\r
+def AmlToHex(InputFile, OutputFile, BaseName):\r
+\r
+    MacroName = "__{}_HEX__".format(BaseName.upper())\r
+    ArrayName = BaseName.lower() + "_aml_code"\r
+\r
+    with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:\r
+        # Write header.\r
+        fOut.write("// This file has been generated from:\n" + \\r
+                   "// \tPython script: " + \\r
+                   os.path.abspath(__file__) + "\n" + \\r
+                   "// \tInput AML file: " + \\r
+                   os.path.abspath(InputFile) + "\n\n" + \\r
+                   "#ifndef {}\n".format(MacroName) + \\r
+                   "#define {}\n\n".format(MacroName)\r
+                   )\r
+\r
+        # Write the array and its content.\r
+        fOut.write("unsigned char {}[] = {{\n  ".format(ArrayName))\r
+        cnt = 0\r
+        byte = fIn.read(1)\r
+        while len(byte) != 0:\r
+            fOut.write("0x{0:02X}, ".format(ord(byte)))\r
+            cnt += 1\r
+            if (cnt % 8) == 0:\r
+                fOut.write("\n  ")\r
+            byte = fIn.read(1)\r
+        fOut.write("\n};\n")\r
+\r
+        # Write footer.\r
+        fOut.write("#endif // {}\n".format(MacroName))\r
+\r
+## Main method\r
+#\r
+# This method:\r
+#   1-  Initialize an EdkLogger instance.\r
+#   2-  Parses the input arguments.\r
+#   3-  Converts an AML file to a .hex file containing the AML bytecode stored\r
+#       in a C array.\r
+#\r
+# @retval 0     Success.\r
+# @retval 1     Error.\r
+#\r
+def Main():\r
+    # Initialize an EdkLogger instance.\r
+    EdkLogger.Initialize()\r
+\r
+    try:\r
+        # Parse the input arguments.\r
+        CommandArguments = ParseArgs()\r
+        if not CommandArguments:\r
+            return 1\r
+\r
+        # Convert an AML file to a .hex file containing the AML bytecode stored\r
+        # in a C array.\r
+        AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,\r
+                          CommandArguments.BaseName)\r
+    except Exception as e:\r
+        print(e)\r
+        return 1\r
+\r
+    return 0\r
+\r
+if __name__ == '__main__':\r
+    r = Main()\r
+    # 0-127 is a safe return range, and 1 is a standard default error\r
+    if r < 0 or r > 127: r = 1\r
+    sys.exit(r)\r
diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
deleted file mode 100644 (file)
index 643db29..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-## @file\r
-#\r
-# Convert an AML file to a .hex file containing the AML bytecode stored in a\r
-# C array.\r
-# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".\r
-# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that contains\r
-# the AML bytecode.\r
-#\r
-# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>\r
-#\r
-# SPDX-License-Identifier: BSD-2-Clause-Patent\r
-#\r
-\r
-import argparse\r
-import Common.EdkLogger as EdkLogger\r
-from Common.BuildToolError import *\r
-import sys\r
-import os\r
-\r
-## Parse the command line arguments.\r
-#\r
-# @retval A argparse.NameSpace instance, containing parsed values.\r
-#\r
-def ParseArgs():\r
-    # Initialize the parser.\r
-    Parser = argparse.ArgumentParser(\r
-      description="Convert an AML file to a .hex file containing the AML " + \\r
-                  "bytecode stored in a C array. By default, " + \\r
-                  "\"Tables\\Dsdt.aml\" will generate" + \\r
-                  "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \\r
-                  "contain a C array named \"dsdt_aml_code\" that " + \\r
-                  "contains the AML bytecode."\r
-      )\r
-\r
-    # Define the possible arguments.\r
-    Parser.add_argument(\r
-      dest="InputFile",\r
-      help="Path to an input AML file to generate a .hex file from."\r
-      )\r
-    Parser.add_argument(\r
-      "-o", "--out-dir", dest="OutDir",\r
-      help="Output directory where the .hex file will be generated. " + \\r
-           "Default is the input file's directory."\r
-      )\r
-\r
-    # Parse the input arguments.\r
-    Args = Parser.parse_args()\r
-    SplitInputName = ""\r
-\r
-    if not os.path.exists(Args.InputFile):\r
-        EdkLogger.error(__file__, FILE_OPEN_FAILURE,\r
-                        ExtraData=Args.InputFile)\r
-        return None\r
-    else:\r
-        with open(Args.InputFile, "rb") as fIn:\r
-            Signature = str(fIn.read(4))\r
-            if ("DSDT" not in Signature) and ("SSDT" not in Signature):\r
-                EdkLogger.info("Invalid file type. " + \\r
-                                "File does not have a valid " + \\r
-                                "DSDT or SSDT signature: %s" % Args.InputFile)\r
-                return None\r
-\r
-    # Get the basename of the input file.\r
-    SplitInputName = os.path.splitext(Args.InputFile)\r
-    BaseName = os.path.basename(SplitInputName[0])\r
-\r
-    # If no output directory is specified, output to the input directory.\r
-    if not Args.OutDir:\r
-        Args.OutputFile = os.path.join(\r
-          os.path.dirname(Args.InputFile),\r
-          BaseName + ".hex"\r
-          )\r
-    else:\r
-        if not os.path.exists(Args.OutDir):\r
-            os.mkdir(Args.OutDir)\r
-        Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".hex")\r
-\r
-    Args.BaseName = BaseName\r
-\r
-    return Args\r
-\r
-## Convert an AML file to a .hex file containing the AML bytecode stored\r
-#  in a C array.\r
-#\r
-# @param  InputFile     Path to the input AML file.\r
-# @param  OutputFile    Path to the output .hex file to generate.\r
-# @param  BaseName      Base name of the input file.\r
-#                       This is also the name of the generated .hex file.\r
-#\r
-def AmlToHex(InputFile, OutputFile, BaseName):\r
-\r
-    MacroName = "__{}_HEX__".format(BaseName.upper())\r
-    ArrayName = BaseName.lower() + "_aml_code"\r
-\r
-    with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:\r
-        # Write header.\r
-        fOut.write("// This file has been generated from:\n" + \\r
-                   "// \tPython script: " + \\r
-                   os.path.abspath(__file__) + "\n" + \\r
-                   "// \tInput AML file: " + \\r
-                   os.path.abspath(InputFile) + "\n\n" + \\r
-                   "#ifndef {}\n".format(MacroName) + \\r
-                   "#define {}\n\n".format(MacroName)\r
-                   )\r
-\r
-        # Write the array and its content.\r
-        fOut.write("unsigned char {}[] = {{\n  ".format(ArrayName))\r
-        cnt = 0\r
-        byte = fIn.read(1)\r
-        while len(byte) != 0:\r
-            fOut.write("0x{0:02X}, ".format(ord(byte)))\r
-            cnt += 1\r
-            if (cnt % 8) == 0:\r
-                fOut.write("\n  ")\r
-            byte = fIn.read(1)\r
-        fOut.write("\n};\n")\r
-\r
-        # Write footer.\r
-        fOut.write("#endif // {}\n".format(MacroName))\r
-\r
-## Main method\r
-#\r
-# This method:\r
-#   1-  Initialize an EdkLogger instance.\r
-#   2-  Parses the input arguments.\r
-#   3-  Converts an AML file to a .hex file containing the AML bytecode stored\r
-#       in a C array.\r
-#\r
-# @retval 0     Success.\r
-# @retval 1     Error.\r
-#\r
-def Main():\r
-    # Initialize an EdkLogger instance.\r
-    EdkLogger.Initialize()\r
-\r
-    try:\r
-        # Parse the input arguments.\r
-        CommandArguments = ParseArgs()\r
-        if not CommandArguments:\r
-            return 1\r
-\r
-        # Convert an AML file to a .hex file containing the AML bytecode stored\r
-        # in a C array.\r
-        AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,\r
-                          CommandArguments.BaseName)\r
-    except Exception as e:\r
-        print(e)\r
-        return 1\r
-\r
-    return 0\r
-\r
-if __name__ == '__main__':\r
-    r = Main()\r
-    # 0-127 is a safe return range, and 1 is a standard default error\r
-    if r < 0 or r > 127: r = 1\r
-    sys.exit(r)\r