public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v5 0/5] Compile AML bytecode array into OBJ file
@ 2020-07-01 14:05 PierreGondois
  2020-07-01 14:06 ` [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check PierreGondois
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:05 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

Following the BZ at https://bugzilla.tianocore.org/show_bug.cgi?id=2425
This patch serie is a another way to solve the dependency
of C files over ASL files. With this new method, the
dependency is resolved at the linking stage.

The last method to solve this dependency was to add
the possibility to modify INF files to depict such a
dependency. This method was not accepted. The discussion
is available at https://edk2.groups.io/g/devel/topic/72655342#56658

The last patch modifying the INF specification and INF
parsing are available at:
https://edk2.groups.io/g/devel/topic/72655342#56658
https://edk2.groups.io/g/devel/topic/72656060#56662

Pierre Gondois (5):
  BaseTools: PatchCheck: Exclude bash scripts from CRLF check
  BaseTools: Generate multiple rules when multiple output files
  BaseTools: Rename AmlToHex script to AmlToC
  BaseTools: Compile AML bytecode arrays into .obj file
  BaseTools: Fix string concatenation

 BaseTools/BinWrappers/PosixLike/{AmlToHex => AmlToC}               | 28 +++----
 BaseTools/BinWrappers/WindowsLike/{AmlToHex.bat => AmlToC.bat}     |  0
 BaseTools/Conf/build_rule.template                                 | 15 +++-
 BaseTools/Scripts/PatchCheck.py                                    |  8 +-
 BaseTools/Source/Python/{AmlToHex/AmlToHex.py => AmlToC/AmlToC.py} | 82 ++++++++------------
 BaseTools/Source/Python/AutoGen/BuildEngine.py                     |  2 +-
 BaseTools/Source/Python/AutoGen/GenMake.py                         |  6 ++
 BaseTools/Source/Python/AutoGen/ModuleAutoGen.py                   | 38 +++++----
 8 files changed, 96 insertions(+), 83 deletions(-)
 rename BaseTools/BinWrappers/PosixLike/{AmlToHex => AmlToC} (97%)
 rename BaseTools/BinWrappers/WindowsLike/{AmlToHex.bat => AmlToC.bat} (100%)
 rename BaseTools/Source/Python/{AmlToHex/AmlToHex.py => AmlToC/AmlToC.py} (52%)

-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
@ 2020-07-01 14:06 ` PierreGondois
  2020-07-02  4:21   ` Bob Feng
  2020-07-01 14:06 ` [PATCH 2/5] BaseTools: Generate multiple rules when multiple output files PierreGondois
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:06 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

From: Pierre Gondois <pierre.gondois@arm.com>

Bash scripts require LF line endings to work.
PatchCheck.py checks that the files added in a patch have CRLF
line endings. It excludes files ending with the ".sh" extension
from this check.

Some bash script don't have a ".sh" extension. Most of them are
located in:
 - BaseTools/BinWrappers/PosixLike/
 - BaseTools/Bin/CYGWIN_NT-5.1-i686/

This patch excludes these folder plus BaseTools/BuildEnv from
this CRLF check.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v5:
     - Exclude some directories/files having LF line
       endings from the PatchCheck,py script. [Bob]

 BaseTools/Scripts/PatchCheck.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 106b434c750d71d8aa1658109f146dc066633c2c..e38cf61f93da50f77d4e1e2e37de5f6a08d25408 100755
--- a/BaseTools/Scripts/PatchCheck.py
+++ b/BaseTools/Scripts/PatchCheck.py
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
 #  Copyright (C) 2020, Red Hat, Inc.<BR>
+#  Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -384,9 +385,14 @@ class GitDiffCheck:
                 self.is_newfile = False
                 self.force_crlf = True
                 self.force_notabs = True
-                if self.filename.endswith('.sh'):
+                if self.filename.endswith('.sh') or \
+                    self.filename.startswith('BaseTools/BinWrappers/PosixLike/') or \
+                    self.filename.startswith('BaseTools/Bin/CYGWIN_NT-5.1-i686/') or \
+                    self.filename == 'BaseTools/BuildEnv':
                     #
                     # Do not enforce CR/LF line endings for linux shell scripts.
+                    # Some linux shell scripts don't end with the ".sh" extension,
+                    # they are identified by their path.
                     #
                     self.force_crlf = False
                 if self.filename == '.gitmodules':
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/5] BaseTools: Generate multiple rules when multiple output files
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
  2020-07-01 14:06 ` [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check PierreGondois
@ 2020-07-01 14:06 ` PierreGondois
  2020-07-01 14:06 ` [PATCH v5 3/5] BaseTools: Rename AmlToHex script to AmlToC PierreGondois
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:06 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

From: Pierre Gondois <pierre.gondois@arm.com>

This patch modifies the Makefile generation not to stop
adding Makfile rules when the first final target is found.
E.g.:
If the following rules are described in build_rule.txt:
 -[Rule1]: .X files generate .Y and .Z files;
 -[Rule2]: .Z files generate .Z1 files.
Currently, if a File1.X file was part of the sources of a
module, only [Rule1] would be generated in the Makefile.
Indeed, there are no rules to apply to .Y files: .Y files
are a final target. However, there is still [Rule2] to
apply to .Z files.

This patch also adds a dependency between the first
ouput file of a rule and the other output files.
For instance, with the same example as above, File1.Y
and File1.Z are generated by the following rule:
File1.Y: File1.X
    <Generate File1.Y>
    <Generate File1.Z>

and the new dependency is:
File1.Z: File1.Y

This is necessary to keep a dependency order during the
execution of the Makefile. Indeed, .Y and .Z files are
generated by the execution of a common set of commands,
and without this rule, there is no explicit dependency
relation between them.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Suggested-by: Tomas Pilar <Tomas.Pilar@arm.com>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v1:
     - Generate multiple rules when multiple output files
       are specified in the build_rule.txt file. [Pierre]
    v2:
     - Use the "FileType" variable in the _ApplyBuildRule
       function as it is in the current state. [Pierre]
    v3:
     - Adding Suggested-by [Pierre]
    v4:
    - No modification. Re-sending the patch with base64
      encoding to conserve the right line endings. [Bob]
    v5:
     - No modification. [Pierre]

 BaseTools/Source/Python/AutoGen/GenMake.py       |  6 ++++
 BaseTools/Source/Python/AutoGen/ModuleAutoGen.py | 38 +++++++++++---------
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index bbb3c29446f53fa7f2cb61a216a5b119f72c3fbc..0314d0ea34d99a014379e8d30c46ac0f0a7068ce 100755
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -1054,6 +1054,12 @@ cleanlib:
                     TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}
                     self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
 
+                    # Add a Makefile rule for targets generating multiple files.
+                    # The main output is a prerequisite for the other output files.
+                    for i in T.Outputs[1:]:
+                        AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}
+                        self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))
+
     def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):
         if not CmdSumDict:
             for item in self._AutoGenObject.Targets[Type]:
diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
index aad591de65f086043d55aeea5661f59c53792e7c..dc8b1fe3d160cac2da22227fc233e3aa0d92cb1e 100755
--- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
@@ -860,7 +860,8 @@ class ModuleAutoGen(AutoGen):
         SubDirectory = os.path.join(self.OutputDir, File.SubDir)
         if not os.path.exists(SubDirectory):
             CreateDirectory(SubDirectory)
-        LastTarget = None
+        TargetList = set()
+        FinalTargetName = set()
         RuleChain = set()
         SourceList = [File]
         Index = 0
@@ -870,6 +871,9 @@ class ModuleAutoGen(AutoGen):
         self.BuildOption
 
         while Index < len(SourceList):
+            # Reset the FileType if not the first iteration.
+            if Index > 0:
+                FileType = TAB_UNKNOWN_FILE
             Source = SourceList[Index]
             Index = Index + 1
 
@@ -886,29 +890,25 @@ class ModuleAutoGen(AutoGen):
             elif Source.Ext in self.BuildRules:
                 RuleObject = self.BuildRules[Source.Ext]
             else:
-                # stop at no more rules
-                if LastTarget:
-                    self._FinalBuildTargetList.add(LastTarget)
-                break
+                # No more rule to apply: Source is a final target.
+                FinalTargetName.add(Source)
+                continue
 
             FileType = RuleObject.SourceFileType
             self._FileTypes[FileType].add(Source)
 
             # stop at STATIC_LIBRARY for library
             if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
-                if LastTarget:
-                    self._FinalBuildTargetList.add(LastTarget)
-                break
+                FinalTargetName.add(Source)
+                continue
 
             Target = RuleObject.Apply(Source, self.BuildRuleOrder)
             if not Target:
-                if LastTarget:
-                    self._FinalBuildTargetList.add(LastTarget)
-                break
-            elif not Target.Outputs:
-                # Only do build for target with outputs
-                self._FinalBuildTargetList.add(Target)
+                # No Target: Source is a final target.
+                FinalTargetName.add(Source)
+                continue
 
+            TargetList.add(Target)
             self._BuildTargets[FileType].add(Target)
 
             if not Source.IsBinary and Source == File:
@@ -916,12 +916,16 @@ class ModuleAutoGen(AutoGen):
 
             # to avoid cyclic rule
             if FileType in RuleChain:
-                break
+                EdkLogger.error("build", ERROR_STATEMENT, "Cyclic dependency detected while generating rule for %s" % str(Source))
 
             RuleChain.add(FileType)
             SourceList.extend(Target.Outputs)
-            LastTarget = Target
-            FileType = TAB_UNKNOWN_FILE
+
+        # For each final target name, retrieve the corresponding TargetDescBlock instance.
+        for FTargetName in FinalTargetName:
+            for Target in TargetList:
+                if FTargetName == Target.Target:
+                    self._FinalBuildTargetList.add(Target)
 
     @cached_property
     def Targets(self):
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 3/5] BaseTools: Rename AmlToHex script to AmlToC
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
  2020-07-01 14:06 ` [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check PierreGondois
  2020-07-01 14:06 ` [PATCH 2/5] BaseTools: Generate multiple rules when multiple output files PierreGondois
@ 2020-07-01 14:06 ` PierreGondois
  2020-07-01 14:06 ` [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file PierreGondois
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:06 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

From: Pierre Gondois <pierre.gondois@arm.com>

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>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v1:
     - Rename AmlToHex scripts to AmlToC, and change line
       endings of the PosixLike bin-wrapper. [Pierre]
    v2:
     - No modification. [Pierre]
    v3:
     - Changed "Signed-off-by" to "Suggested-by". [Bob]
    v4:
     - No modification. Re-sending the patch with base64
       encoding to conserve the right line endings. [Bob]
    v5:
     - No modification. [Pierre]

 BaseTools/BinWrappers/PosixLike/{AmlToHex => AmlToC}               | 28 ++++++++++----------
 BaseTools/BinWrappers/WindowsLike/{AmlToHex.bat => AmlToC.bat}     |  0
 BaseTools/Source/Python/{AmlToHex/AmlToHex.py => AmlToC/AmlToC.py} |  0
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex b/BaseTools/BinWrappers/PosixLike/AmlToC
similarity index 97%
rename from BaseTools/BinWrappers/PosixLike/AmlToHex
rename to BaseTools/BinWrappers/PosixLike/AmlToC
index 9fb68299e4c67d1f332cd883fd348a896f1bdc50..1dd28e966288f6ea4fc52d42e2dc7b1f74226c23 100755
--- a/BaseTools/BinWrappers/PosixLike/AmlToHex
+++ b/BaseTools/BinWrappers/PosixLike/AmlToC
@@ -1,14 +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" "$@"
+#!/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/WindowsLike/AmlToHex.bat b/BaseTools/BinWrappers/WindowsLike/AmlToC.bat
similarity index 100%
rename from BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
rename to BaseTools/BinWrappers/WindowsLike/AmlToC.bat
diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py b/BaseTools/Source/Python/AmlToC/AmlToC.py
similarity index 100%
rename from BaseTools/Source/Python/AmlToHex/AmlToHex.py
rename to BaseTools/Source/Python/AmlToC/AmlToC.py
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
                   ` (2 preceding siblings ...)
  2020-07-01 14:06 ` [PATCH v5 3/5] BaseTools: Rename AmlToHex script to AmlToC PierreGondois
@ 2020-07-01 14:06 ` PierreGondois
  2020-07-27 13:58   ` [edk2-devel] " Leif Lindholm
  2020-07-01 14:06 ` [PATCH v5 5/5] BaseTools: Fix string concatenation PierreGondois
  2020-07-02 10:20 ` [PATCH v5 0/5] Compile AML bytecode array into OBJ file Bob Feng
  5 siblings, 1 reply; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:06 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

From: Pierre Gondois <pierre.gondois@arm.com>

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 modifies the AmlToC script to generate a C file
instead of a ".hex" file.
It also adds the generation of an intermediate ".amli" file
when compiling an ASL file, and adds a rule to convert this
".amli" to a C file.

This allows to generate 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>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v1:
     - Add a new rule to the build_rule.template file to
       generate ".obj" files from .asl files, and modify
       the AmlToC script accordingly. [Pierre]
    v2:
     - Restrict the rule to DXE_DRIVER. This allows to build
       the OvmfPkg, which was not the case in v1. [Pierre]
    v3:
     - Changed "Signed-off-by" to "Suggested-by". [Bob]
    v4:
    - No modification. Re-sending the patch with base64
      encoding to conserve the right line endings. [Bob]
    v5:
     - No modification. [Pierre]

 BaseTools/Conf/build_rule.template       | 15 +++-
 BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
 2 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
index 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aadba08e0169da44 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 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809ddbe8175f1493cfb 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
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 5/5] BaseTools: Fix string concatenation
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
                   ` (3 preceding siblings ...)
  2020-07-01 14:06 ` [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file PierreGondois
@ 2020-07-01 14:06 ` PierreGondois
  2020-07-02 10:20 ` [PATCH v5 0/5] Compile AML bytecode array into OBJ file Bob Feng
  5 siblings, 0 replies; 17+ messages in thread
From: PierreGondois @ 2020-07-01 14:06 UTC (permalink / raw)
  To: devel; +Cc: Pierre Gondois, sami.mujawar, tomas.pilar, bob.c.feng, liming.gao,
	nd

From: Pierre Gondois <pierre.gondois@arm.com>

Using Python 3.7.2 on win32, when printing a FileBuildRule
instance, the following error occurs:
File "edk2\BaseTools\Source\Python\AutoGen\BuildEngine.py",
line 177, in __str__
  DestString = ", ".join(self.DestFileList)
  TypeError: sequence item 0: expected str instance, PathClass found

This patch converts each PathClass element of the list to a string
instance before concatenating them.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v2:
     - No v1 for this patch. Fix a __str__ method. [Pierre]
    v3:
     - No modification. [Pierre]
    v4:
     - No modification. Re-sending the patch with base64
       encoding to conserve the right line endings. [Bob]
    v5:
     - No modification. [Pierre]

 BaseTools/Source/Python/AutoGen/BuildEngine.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index d602414ca41f37155c9c6d00eec54ea3918840c3..722fead75af6d60aa82365d999837cd5ac3299af 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -172,7 +172,7 @@ class FileBuildRule:
     def __str__(self):
         SourceString = ""
         SourceString += " %s %s %s" % (self.SourceFileType, " ".join(self.SourceFileExtList), self.ExtraSourceFileList)
-        DestString = ", ".join(self.DestFileList)
+        DestString = ", ".join([str(i) for i in self.DestFileList])
         CommandString = "\n\t".join(self.CommandList)
         return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)
 
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check
  2020-07-01 14:06 ` [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check PierreGondois
@ 2020-07-02  4:21   ` Bob Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Bob Feng @ 2020-07-02  4:21 UTC (permalink / raw)
  To: PierreGondois, devel@edk2.groups.io
  Cc: sami.mujawar@arm.com, tomas.pilar@arm.com, Gao, Liming,
	nd@arm.com

Reviewed-by: Bob Feng<bob.c.feng@intel.com>


-----Original Message-----
From: PierreGondois <pierre.gondois@arm.com> 
Sent: Wednesday, July 1, 2020 10:06 PM
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@arm.com>; sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; nd@arm.com
Subject: [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check

From: Pierre Gondois <pierre.gondois@arm.com>

Bash scripts require LF line endings to work.
PatchCheck.py checks that the files added in a patch have CRLF line endings. It excludes files ending with the ".sh" extension from this check.

Some bash script don't have a ".sh" extension. Most of them are located in:
 - BaseTools/BinWrappers/PosixLike/
 - BaseTools/Bin/CYGWIN_NT-5.1-i686/

This patch excludes these folder plus BaseTools/BuildEnv from this CRLF check.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---

The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5

Notes:
    v5:
     - Exclude some directories/files having LF line
       endings from the PatchCheck,py script. [Bob]

 BaseTools/Scripts/PatchCheck.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py index 106b434c750d71d8aa1658109f146dc066633c2c..e38cf61f93da50f77d4e1e2e37de5f6a08d25408 100755
--- a/BaseTools/Scripts/PatchCheck.py
+++ b/BaseTools/Scripts/PatchCheck.py
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>  #  Copyright (C) 2020, Red Hat, Inc.<BR>
+#  Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent  # @@ -384,9 +385,14 @@ class GitDiffCheck:
                 self.is_newfile = False
                 self.force_crlf = True
                 self.force_notabs = True
-                if self.filename.endswith('.sh'):
+                if self.filename.endswith('.sh') or \
+                    self.filename.startswith('BaseTools/BinWrappers/PosixLike/') or \
+                    self.filename.startswith('BaseTools/Bin/CYGWIN_NT-5.1-i686/') or \
+                    self.filename == 'BaseTools/BuildEnv':
                     #
                     # Do not enforce CR/LF line endings for linux shell scripts.
+                    # Some linux shell scripts don't end with the ".sh" extension,
+                    # they are identified by their path.
                     #
                     self.force_crlf = False
                 if self.filename == '.gitmodules':
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 0/5] Compile AML bytecode array into OBJ file
  2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
                   ` (4 preceding siblings ...)
  2020-07-01 14:06 ` [PATCH v5 5/5] BaseTools: Fix string concatenation PierreGondois
@ 2020-07-02 10:20 ` Bob Feng
  5 siblings, 0 replies; 17+ messages in thread
From: Bob Feng @ 2020-07-02 10:20 UTC (permalink / raw)
  To: PierreGondois, devel@edk2.groups.io
  Cc: sami.mujawar@arm.com, tomas.pilar@arm.com, Gao, Liming,
	nd@arm.com

Merged.

-----Original Message-----
From: PierreGondois <pierre.gondois@arm.com> 
Sent: Wednesday, July 1, 2020 10:06 PM
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@arm.com>; sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; nd@arm.com
Subject: [PATCH v5 0/5] Compile AML bytecode array into OBJ file

Following the BZ at https://bugzilla.tianocore.org/show_bug.cgi?id=2425
This patch serie is a another way to solve the dependency of C files over ASL files. With this new method, the dependency is resolved at the linking stage.

The last method to solve this dependency was to add the possibility to modify INF files to depict such a dependency. This method was not accepted. The discussion is available at https://edk2.groups.io/g/devel/topic/72655342#56658

The last patch modifying the INF specification and INF parsing are available at:
https://edk2.groups.io/g/devel/topic/72655342#56658
https://edk2.groups.io/g/devel/topic/72656060#56662

Pierre Gondois (5):
  BaseTools: PatchCheck: Exclude bash scripts from CRLF check
  BaseTools: Generate multiple rules when multiple output files
  BaseTools: Rename AmlToHex script to AmlToC
  BaseTools: Compile AML bytecode arrays into .obj file
  BaseTools: Fix string concatenation

 BaseTools/BinWrappers/PosixLike/{AmlToHex => AmlToC}               | 28 +++----
 BaseTools/BinWrappers/WindowsLike/{AmlToHex.bat => AmlToC.bat}     |  0
 BaseTools/Conf/build_rule.template                                 | 15 +++-
 BaseTools/Scripts/PatchCheck.py                                    |  8 +-
 BaseTools/Source/Python/{AmlToHex/AmlToHex.py => AmlToC/AmlToC.py} | 82 ++++++++------------
 BaseTools/Source/Python/AutoGen/BuildEngine.py                     |  2 +-
 BaseTools/Source/Python/AutoGen/GenMake.py                         |  6 ++
 BaseTools/Source/Python/AutoGen/ModuleAutoGen.py                   | 38 +++++----
 8 files changed, 96 insertions(+), 83 deletions(-)  rename BaseTools/BinWrappers/PosixLike/{AmlToHex => AmlToC} (97%)  rename BaseTools/BinWrappers/WindowsLike/{AmlToHex.bat => AmlToC.bat} (100%)  rename BaseTools/Source/Python/{AmlToHex/AmlToHex.py => AmlToC/AmlToC.py} (52%)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-01 14:06 ` [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file PierreGondois
@ 2020-07-27 13:58   ` Leif Lindholm
  2020-07-27 14:13     ` Sami Mujawar
  2020-07-27 14:21     ` Liming Gao
  0 siblings, 2 replies; 17+ messages in thread
From: Leif Lindholm @ 2020-07-27 13:58 UTC (permalink / raw)
  To: devel, pierre.gondois, Masahisa Kojima
  Cc: sami.mujawar, tomas.pilar, bob.c.feng, liming.gao, Ard Biesheuvel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=utf-8, Size: 13190 bytes --]

Hi Pierre, (+Masahisa)

This commit (0a4aa20e8d44) made for an exciting start to my week.

Socionext's Developerbox failed to build for me, with the spectacular
error message:

/usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
DWARF error: could not find abbrev number 5912
/tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
<artificial>:(.text.RegisterDevices+0xb0): undefined reference to
`RegisterEmmc'

GCC49 (without lto) and CLANG38 profiles give much the same result,
with slightly less esoteric messages.

The reason for this turned out to be that edk2-platforms
Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl
and an Emmc.c file, which after this patch both generate an Emmc.obj
in the same output directory.

I think the correct course of action is to fix this in the SynQuacer
driver, but I am reporting it here so we get it logged in the list
archives.

It would of course be good if the build system could detect and warn
over cases like this, rather than silently overwriting existing object
files.

Masahisa - since Ard is still on holiday, could you create a patch and
send out for me to review? Either one of the files needs to be
renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
into a subdirectory.

Best Regards,

Leif

On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> From: Pierre Gondois <pierre.gondois@arm.com>
> 
> 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 modifies the AmlToC script to generate a C file
> instead of a ".hex" file.
> It also adds the generation of an intermediate ".amli" file
> when compiling an ASL file, and adds a rule to convert this
> ".amli" to a C file.
> 
> This allows to generate 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>
> ---
> 
> The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5
> 
> Notes:
>     v1:
>      - Add a new rule to the build_rule.template file to
>        generate ".obj" files from .asl files, and modify
>        the AmlToC script accordingly. [Pierre]
>     v2:
>      - Restrict the rule to DXE_DRIVER. This allows to build
>        the OvmfPkg, which was not the case in v1. [Pierre]
>     v3:
>      - Changed "Signed-off-by" to "Suggested-by". [Bob]
>     v4:
>     - No modification. Re-sending the patch with base64
>       encoding to conserve the right line endings. [Bob]
>     v5:
>      - No modification. [Pierre]
> 
>  BaseTools/Conf/build_rule.template       | 15 +++-
>  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
>  2 files changed, 47 insertions(+), 50 deletions(-)
> 
> diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
> index 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aadba08e0169da44 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 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809ddbe8175f1493cfb 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
> -- 
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> 
> ÿ

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-27 13:58   ` [edk2-devel] " Leif Lindholm
@ 2020-07-27 14:13     ` Sami Mujawar
  2020-07-27 14:21     ` Liming Gao
  1 sibling, 0 replies; 17+ messages in thread
From: Sami Mujawar @ 2020-07-27 14:13 UTC (permalink / raw)
  To: Leif Lindholm, devel@edk2.groups.io, Pierre Gondois,
	Masahisa Kojima
  Cc: Tomas Pilar, bob.c.feng@intel.com, liming.gao@intel.com,
	Ard Biesheuvel

Hi Leif,

Would updating build_rule.template so that the AmlToC Script generates a C file with an AutoGen prefix be an option?

Regards,

Sami Mujawar

-----Original Message-----
From: Leif Lindholm <leif@nuviainc.com>
Sent: 27 July 2020 02:58 PM
To: devel@edk2.groups.io; Pierre Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; bob.c.feng@intel.com; liming.gao@intel.com; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file

Hi Pierre, (+Masahisa)

This commit (0a4aa20e8d44) made for an exciting start to my week.

Socionext's Developerbox failed to build for me, with the spectacular error message:

/usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
DWARF error: could not find abbrev number 5912
/tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
<artificial>:(.text.RegisterDevices+0xb0): undefined reference to `RegisterEmmc'

GCC49 (without lto) and CLANG38 profiles give much the same result, with slightly less esoteric messages.

The reason for this turned out to be that edk2-platforms Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl and an Emmc.c file, which after this patch both generate an Emmc.obj in the same output directory.

I think the correct course of action is to fix this in the SynQuacer driver, but I am reporting it here so we get it logged in the list archives.

It would of course be good if the build system could detect and warn over cases like this, rather than silently overwriting existing object files.

Masahisa - since Ard is still on holiday, could you create a patch and send out for me to review? Either one of the files needs to be renamed, or we need to move the .asl files (Emmc.asl and Optee.asl) into a subdirectory.

Best Regards,

Leif

On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> From: Pierre Gondois <pierre.gondois@arm.com>
>
> 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 modifies the AmlToC script to generate a C file instead of
> a ".hex" file.
> It also adds the generation of an intermediate ".amli" file when
> compiling an ASL file, and adds a rule to convert this ".amli" to a C
> file.
>
> This allows to generate 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>
> ---
>
> The changes can be seen at:
> https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_arr
> ay_into_OBJ_file_v5
>
> Notes:
>     v1:
>      - Add a new rule to the build_rule.template file to
>        generate ".obj" files from .asl files, and modify
>        the AmlToC script accordingly. [Pierre]
>     v2:
>      - Restrict the rule to DXE_DRIVER. This allows to build
>        the OvmfPkg, which was not the case in v1. [Pierre]
>     v3:
>      - Changed "Signed-off-by" to "Suggested-by". [Bob]
>     v4:
>     - No modification. Re-sending the patch with base64
>       encoding to conserve the right line endings. [Bob]
>     v5:
>      - No modification. [Pierre]
>
>  BaseTools/Conf/build_rule.template       | 15 +++-
>  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
>  2 files changed, 47 insertions(+), 50 deletions(-)
>
> diff --git a/BaseTools/Conf/build_rule.template
> b/BaseTools/Conf/build_rule.template
> index
> 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aadb
> a08e0169da44 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
> 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809ddbe
> 8175f1493cfb 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
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
>
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-27 13:58   ` [edk2-devel] " Leif Lindholm
  2020-07-27 14:13     ` Sami Mujawar
@ 2020-07-27 14:21     ` Liming Gao
  2020-07-27 17:10       ` PierreGondois
  1 sibling, 1 reply; 17+ messages in thread
From: Liming Gao @ 2020-07-27 14:21 UTC (permalink / raw)
  To: Leif Lindholm, devel@edk2.groups.io, pierre.gondois@arm.com,
	Masahisa Kojima
  Cc: sami.mujawar@arm.com, tomas.pilar@arm.com, Feng, Bob C,
	Ard Biesheuvel

Leif:
  VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file. 

Bob:
  Has BaseTools such detection if VFR and C source file have the same file name?

Thanks
Liming
> -----Original Message-----
> From: Leif Lindholm <leif@nuviainc.com>
> Sent: Monday, July 27, 2020 9:58 PM
> To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima <masahisa.kojima@linaro.org>
> Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> Biesheuvel <ard.biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
> 
> Hi Pierre, (+Masahisa)
> 
> This commit (0a4aa20e8d44) made for an exciting start to my week.
> 
> Socionext's Developerbox failed to build for me, with the spectacular
> error message:
> 
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> DWARF error: could not find abbrev number 5912
> /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> `RegisterEmmc'
> 
> GCC49 (without lto) and CLANG38 profiles give much the same result,
> with slightly less esoteric messages.
> 
> The reason for this turned out to be that edk2-platforms
> Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl
> and an Emmc.c file, which after this patch both generate an Emmc.obj
> in the same output directory.
> 
> I think the correct course of action is to fix this in the SynQuacer
> driver, but I am reporting it here so we get it logged in the list
> archives.
> 
> It would of course be good if the build system could detect and warn
> over cases like this, rather than silently overwriting existing object
> files.
> 
> Masahisa - since Ard is still on holiday, could you create a patch and
> send out for me to review? Either one of the files needs to be
> renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> into a subdirectory.
> 
> Best Regards,
> 
> Leif
> 
> On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > From: Pierre Gondois <pierre.gondois@arm.com>
> >
> > 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 modifies the AmlToC script to generate a C file
> > instead of a ".hex" file.
> > It also adds the generation of an intermediate ".amli" file
> > when compiling an ASL file, and adds a rule to convert this
> > ".amli" to a C file.
> >
> > This allows to generate 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>
> > ---
> >
> > The changes can be seen at: https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_array_into_OBJ_file_v5
> >
> > Notes:
> >     v1:
> >      - Add a new rule to the build_rule.template file to
> >        generate ".obj" files from .asl files, and modify
> >        the AmlToC script accordingly. [Pierre]
> >     v2:
> >      - Restrict the rule to DXE_DRIVER. This allows to build
> >        the OvmfPkg, which was not the case in v1. [Pierre]
> >     v3:
> >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> >     v4:
> >     - No modification. Re-sending the patch with base64
> >       encoding to conserve the right line endings. [Bob]
> >     v5:
> >      - No modification. [Pierre]
> >
> >  BaseTools/Conf/build_rule.template       | 15 +++-
> >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
> >  2 files changed, 47 insertions(+), 50 deletions(-)
> >
> > diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
> > index 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aadba08e0169da44 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 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809ddbe8175f1493cfb 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
> > --
> > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> >
> > �

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-27 14:21     ` Liming Gao
@ 2020-07-27 17:10       ` PierreGondois
  2020-07-28  0:40         ` Liming Gao
  0 siblings, 1 reply; 17+ messages in thread
From: PierreGondois @ 2020-07-27 17:10 UTC (permalink / raw)
  To: devel@edk2.groups.io, liming.gao@intel.com, Leif Lindholm,
	Masahisa Kojima
  Cc: Sami Mujawar, Tomas Pilar, Feng, Bob C, Ard Biesheuvel

Hello,

Liming:
I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.

Everybody:
The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
$(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl)
$(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from Ip4Config2.vfr)
$(OUTPUT_DIR)/CDir/Emmc.obj : $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/CDir/Emmc.c (from Emmc.c)

The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.

Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.

Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.

Regards,
Pierre

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming Gao via groups.io
Sent: Monday, July 27, 2020 3:21 PM
To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file

Leif:
  VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.

Bob:
  Has BaseTools such detection if VFR and C source file have the same file name?

Thanks
Liming
> -----Original Message-----
> From: Leif Lindholm <leif@nuviainc.com>
> Sent: Monday, July 27, 2020 9:58 PM
> To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima
> <masahisa.kojima@linaro.org>
> Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C
> <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> Biesheuvel <ard.biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> bytecode arrays into .obj file
>
> Hi Pierre, (+Masahisa)
>
> This commit (0a4aa20e8d44) made for an exciting start to my week.
>
> Socionext's Developerbox failed to build for me, with the spectacular
> error message:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> DWARF error: could not find abbrev number 5912
> /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> `RegisterEmmc'
>
> GCC49 (without lto) and CLANG38 profiles give much the same result,
> with slightly less esoteric messages.
>
> The reason for this turned out to be that edk2-platforms
> Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl
> and an Emmc.c file, which after this patch both generate an Emmc.obj
> in the same output directory.
>
> I think the correct course of action is to fix this in the SynQuacer
> driver, but I am reporting it here so we get it logged in the list
> archives.
>
> It would of course be good if the build system could detect and warn
> over cases like this, rather than silently overwriting existing object
> files.
>
> Masahisa - since Ard is still on holiday, could you create a patch and
> send out for me to review? Either one of the files needs to be
> renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> into a subdirectory.
>
> Best Regards,
>
> Leif
>
> On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > From: Pierre Gondois <pierre.gondois@arm.com>
> >
> > 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 modifies the AmlToC script to generate a C file instead
> > of a ".hex" file.
> > It also adds the generation of an intermediate ".amli" file when
> > compiling an ASL file, and adds a rule to convert this ".amli" to a
> > C file.
> >
> > This allows to generate 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>
> > ---
> >
> > The changes can be seen at:
> > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_a
> > rray_into_OBJ_file_v5
> >
> > Notes:
> >     v1:
> >      - Add a new rule to the build_rule.template file to
> >        generate ".obj" files from .asl files, and modify
> >        the AmlToC script accordingly. [Pierre]
> >     v2:
> >      - Restrict the rule to DXE_DRIVER. This allows to build
> >        the OvmfPkg, which was not the case in v1. [Pierre]
> >     v3:
> >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> >     v4:
> >     - No modification. Re-sending the patch with base64
> >       encoding to conserve the right line endings. [Bob]
> >     v5:
> >      - No modification. [Pierre]
> >
> >  BaseTools/Conf/build_rule.template       | 15 +++-
> >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
> >  2 files changed, 47 insertions(+), 50 deletions(-)
> >
> > diff --git a/BaseTools/Conf/build_rule.template
> > b/BaseTools/Conf/build_rule.template
> > index
> > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aa
> > dba08e0169da44 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
> > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809dd
> > be8175f1493cfb 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
> > --
> > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> >
> >



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-27 17:10       ` PierreGondois
@ 2020-07-28  0:40         ` Liming Gao
  2020-07-28  1:38           ` Masahisa Kojima
  0 siblings, 1 reply; 17+ messages in thread
From: Liming Gao @ 2020-07-28  0:40 UTC (permalink / raw)
  To: devel@edk2.groups.io, pierre.gondois@arm.com, Leif Lindholm,
	Masahisa Kojima
  Cc: Sami Mujawar, Tomas Pilar, Feng, Bob C, Ard Biesheuvel

Pierre:
  Thanks for your investigation. For now, the module will rename source file to avoid the file conflict. Can you submit one BZ for BaseTools to enhance the logic for the autogen source file? This needs more discussion. 

  Yes. I agree to place the generated source file into $(DEBUG_DIR). You can make another patch for this change. 

Thanks
Liming
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of PierreGondois
Sent: 2020年7月28日 1:10
To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Leif Lindholm <leif@nuviainc.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file

Hello,

Liming:
I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.

Everybody:
The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
$(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl) $(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from Ip4Config2.vfr) $(OUTPUT_DIR)/CDir/Emmc.obj : $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/CDir/Emmc.c (from Emmc.c)

The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.

Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.

Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.

Regards,
Pierre

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming Gao via groups.io
Sent: Monday, July 27, 2020 3:21 PM
To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file

Leif:
  VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.

Bob:
  Has BaseTools such detection if VFR and C source file have the same file name?

Thanks
Liming
> -----Original Message-----
> From: Leif Lindholm <leif@nuviainc.com>
> Sent: Monday, July 27, 2020 9:58 PM
> To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima 
> <masahisa.kojima@linaro.org>
> Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C 
> <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard 
> Biesheuvel <ard.biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML 
> bytecode arrays into .obj file
>
> Hi Pierre, (+Masahisa)
>
> This commit (0a4aa20e8d44) made for an exciting start to my week.
>
> Socionext's Developerbox failed to build for me, with the spectacular 
> error message:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> DWARF error: could not find abbrev number 5912
> /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> <artificial>:(.text.RegisterDevices+0xb0): undefined reference to 
> `RegisterEmmc'
>
> GCC49 (without lto) and CLANG38 profiles give much the same result, 
> with slightly less esoteric messages.
>
> The reason for this turned out to be that edk2-platforms 
> Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl 
> and an Emmc.c file, which after this patch both generate an Emmc.obj 
> in the same output directory.
>
> I think the correct course of action is to fix this in the SynQuacer 
> driver, but I am reporting it here so we get it logged in the list 
> archives.
>
> It would of course be good if the build system could detect and warn 
> over cases like this, rather than silently overwriting existing object 
> files.
>
> Masahisa - since Ard is still on holiday, could you create a patch and 
> send out for me to review? Either one of the files needs to be 
> renamed, or we need to move the .asl files (Emmc.asl and Optee.asl) 
> into a subdirectory.
>
> Best Regards,
>
> Leif
>
> On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > From: Pierre Gondois <pierre.gondois@arm.com>
> >
> > 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 modifies the AmlToC script to generate a C file instead 
> > of a ".hex" file.
> > It also adds the generation of an intermediate ".amli" file when 
> > compiling an ASL file, and adds a rule to convert this ".amli" to a 
> > C file.
> >
> > This allows to generate 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>
> > ---
> >
> > The changes can be seen at:
> > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_a
> > rray_into_OBJ_file_v5
> >
> > Notes:
> >     v1:
> >      - Add a new rule to the build_rule.template file to
> >        generate ".obj" files from .asl files, and modify
> >        the AmlToC script accordingly. [Pierre]
> >     v2:
> >      - Restrict the rule to DXE_DRIVER. This allows to build
> >        the OvmfPkg, which was not the case in v1. [Pierre]
> >     v3:
> >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> >     v4:
> >     - No modification. Re-sending the patch with base64
> >       encoding to conserve the right line endings. [Bob]
> >     v5:
> >      - No modification. [Pierre]
> >
> >  BaseTools/Conf/build_rule.template       | 15 +++-
> >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
> >  2 files changed, 47 insertions(+), 50 deletions(-)
> >
> > diff --git a/BaseTools/Conf/build_rule.template
> > b/BaseTools/Conf/build_rule.template
> > index
> > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aa
> > dba08e0169da44 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
> > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809dd
> > be8175f1493cfb 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
> > --
> > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> >
> >



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-28  0:40         ` Liming Gao
@ 2020-07-28  1:38           ` Masahisa Kojima
  2020-07-28  9:04             ` PierreGondois
  0 siblings, 1 reply; 17+ messages in thread
From: Masahisa Kojima @ 2020-07-28  1:38 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel@edk2.groups.io, Gao, Liming, pierre.gondois@arm.com,
	Sami Mujawar, Tomas Pilar, Feng, Bob C, Ard Biesheuvel

Hi Leif,

> > Masahisa - since Ard is still on holiday, could you create a patch and
> > send out for me to review? Either one of the files needs to be
> > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > into a subdirectory.

Probably I'm missing something, but my build for Developerbox platform is
successful, with the latest edk2/edk2-platforms as of today.

My build option is:
---
export TARGET=Platform/Socionext/DeveloperBox/DeveloperBox.dsc
export PROFILE=DEBUG
export ARCH=AARCH64
export TOOL_CHAIN_TAG=GCC5

build -n $NUM_CPUS -a $ARCH -b $PROFILE -t $TOOL_CHAIN_TAG -p $TARGET
-D SECURE_BOOT_ENABLE=TRUE -D X64EMU_ENABLE=TRUE -D TPM2_ENABLE=TRUE
---

GCC version is "gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-".

Some Output directory information:
~/src/uefi/Build/DeveloperBox$ find .|grep -i emmc
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iii
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj.deps
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iiii
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml.deps
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.i

Regards,
Masahisa

On Tue, 28 Jul 2020 at 09:40, Gao, Liming <liming.gao@intel.com> wrote:
>
> Pierre:
>   Thanks for your investigation. For now, the module will rename source file to avoid the file conflict. Can you submit one BZ for BaseTools to enhance the logic for the autogen source file? This needs more discussion.
>
>   Yes. I agree to place the generated source file into $(DEBUG_DIR). You can make another patch for this change.
>
> Thanks
> Liming
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of PierreGondois
> Sent: 2020年7月28日 1:10
> To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Leif Lindholm <leif@nuviainc.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
> Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
>
> Hello,
>
> Liming:
> I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.
>
> Everybody:
> The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
> $(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl) $(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from Ip4Config2.vfr) $(OUTPUT_DIR)/CDir/Emmc.obj : $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/CDir/Emmc.c (from Emmc.c)
>
> The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
> This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.
>
> Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.
>
> Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.
>
> Regards,
> Pierre
>
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming Gao via groups.io
> Sent: Monday, July 27, 2020 3:21 PM
> To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima <masahisa.kojima@linaro.org>
> Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
>
> Leif:
>   VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.
>
> Bob:
>   Has BaseTools such detection if VFR and C source file have the same file name?
>
> Thanks
> Liming
> > -----Original Message-----
> > From: Leif Lindholm <leif@nuviainc.com>
> > Sent: Monday, July 27, 2020 9:58 PM
> > To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima
> > <masahisa.kojima@linaro.org>
> > Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C
> > <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> > Biesheuvel <ard.biesheuvel@arm.com>
> > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > bytecode arrays into .obj file
> >
> > Hi Pierre, (+Masahisa)
> >
> > This commit (0a4aa20e8d44) made for an exciting start to my week.
> >
> > Socionext's Developerbox failed to build for me, with the spectacular
> > error message:
> >
> > /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> > DWARF error: could not find abbrev number 5912
> > /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> > <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> > `RegisterEmmc'
> >
> > GCC49 (without lto) and CLANG38 profiles give much the same result,
> > with slightly less esoteric messages.
> >
> > The reason for this turned out to be that edk2-platforms
> > Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an Emmc.asl
> > and an Emmc.c file, which after this patch both generate an Emmc.obj
> > in the same output directory.
> >
> > I think the correct course of action is to fix this in the SynQuacer
> > driver, but I am reporting it here so we get it logged in the list
> > archives.
> >
> > It would of course be good if the build system could detect and warn
> > over cases like this, rather than silently overwriting existing object
> > files.
> >
> > Masahisa - since Ard is still on holiday, could you create a patch and
> > send out for me to review? Either one of the files needs to be
> > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > into a subdirectory.
> >
> > Best Regards,
> >
> > Leif
> >
> > On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > > From: Pierre Gondois <pierre.gondois@arm.com>
> > >
> > > 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 modifies the AmlToC script to generate a C file instead
> > > of a ".hex" file.
> > > It also adds the generation of an intermediate ".amli" file when
> > > compiling an ASL file, and adds a rule to convert this ".amli" to a
> > > C file.
> > >
> > > This allows to generate 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>
> > > ---
> > >
> > > The changes can be seen at:
> > > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode_a
> > > rray_into_OBJ_file_v5
> > >
> > > Notes:
> > >     v1:
> > >      - Add a new rule to the build_rule.template file to
> > >        generate ".obj" files from .asl files, and modify
> > >        the AmlToC script accordingly. [Pierre]
> > >     v2:
> > >      - Restrict the rule to DXE_DRIVER. This allows to build
> > >        the OvmfPkg, which was not the case in v1. [Pierre]
> > >     v3:
> > >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> > >     v4:
> > >     - No modification. Re-sending the patch with base64
> > >       encoding to conserve the right line endings. [Bob]
> > >     v5:
> > >      - No modification. [Pierre]
> > >
> > >  BaseTools/Conf/build_rule.template       | 15 +++-
> > >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82 ++++++++------------
> > >  2 files changed, 47 insertions(+), 50 deletions(-)
> > >
> > > diff --git a/BaseTools/Conf/build_rule.template
> > > b/BaseTools/Conf/build_rule.template
> > > index
> > > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6aa
> > > dba08e0169da44 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
> > > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809dd
> > > be8175f1493cfb 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
> > > --
> > > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> > >
> > >
>
>
>
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
>
> 
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-28  1:38           ` Masahisa Kojima
@ 2020-07-28  9:04             ` PierreGondois
  2020-07-28 11:19               ` Leif Lindholm
  0 siblings, 1 reply; 17+ messages in thread
From: PierreGondois @ 2020-07-28  9:04 UTC (permalink / raw)
  To: devel@edk2.groups.io, masahisa.kojima@linaro.org, Leif Lindholm
  Cc: Gao, Liming, Sami Mujawar, Tomas Pilar, Feng, Bob C,
	Ard Biesheuvel

Hello Masahisa,

Maybe you will have to delete/re-generate the build_rule.txt and tools_def.txt files that you have. This patch makes the build system generate a .amli file for each .asl file. If there is no Emmc.amli in your Build directory, this might be the reason.

Regards,
Pierre

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Masahisa Kojima via groups.io
Sent: Tuesday, July 28, 2020 2:38 AM
To: Leif Lindholm <leif@nuviainc.com>
Cc: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Pierre Gondois <Pierre.Gondois@arm.com>; Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file

Hi Leif,

> > Masahisa - since Ard is still on holiday, could you create a patch
> > and send out for me to review? Either one of the files needs to be
> > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > into a subdirectory.

Probably I'm missing something, but my build for Developerbox platform is successful, with the latest edk2/edk2-platforms as of today.

My build option is:
---
export TARGET=Platform/Socionext/DeveloperBox/DeveloperBox.dsc
export PROFILE=DEBUG
export ARCH=AARCH64
export TOOL_CHAIN_TAG=GCC5

build -n $NUM_CPUS -a $ARCH -b $PROFILE -t $TOOL_CHAIN_TAG -p $TARGET -D SECURE_BOOT_ENABLE=TRUE -D X64EMU_ENABLE=TRUE -D TPM2_ENABLE=TRUE
---

GCC version is "gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-".

Some Output directory information:
~/src/uefi/Build/DeveloperBox$ find .|grep -i emmc ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iii
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj.deps
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iiii
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml.deps
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml
./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.i

Regards,
Masahisa

On Tue, 28 Jul 2020 at 09:40, Gao, Liming <liming.gao@intel.com> wrote:
>
> Pierre:
>   Thanks for your investigation. For now, the module will rename source file to avoid the file conflict. Can you submit one BZ for BaseTools to enhance the logic for the autogen source file? This needs more discussion.
>
>   Yes. I agree to place the generated source file into $(DEBUG_DIR). You can make another patch for this change.
>
> Thanks
> Liming
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> PierreGondois
> Sent: 2020年7月28日 1:10
> To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Leif
> Lindholm <leif@nuviainc.com>; Masahisa Kojima
> <masahisa.kojima@linaro.org>
> Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> Biesheuvel <Ard.Biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> bytecode arrays into .obj file
>
> Hello,
>
> Liming:
> I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.
>
> Everybody:
> The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
> $(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl)
> $(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from
> Ip4Config2.vfr) $(OUTPUT_DIR)/CDir/Emmc.obj :
> $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/Platfo
> rmDxe/CDir/Emmc.c (from Emmc.c)
>
> The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
> This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.
>
> Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.
>
> Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.
>
> Regards,
> Pierre
>
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming
> Gao via groups.io
> Sent: Monday, July 27, 2020 3:21 PM
> To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre
> Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima
> <masahisa.kojima@linaro.org>
> Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> Biesheuvel <Ard.Biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> bytecode arrays into .obj file
>
> Leif:
>   VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.
>
> Bob:
>   Has BaseTools such detection if VFR and C source file have the same file name?
>
> Thanks
> Liming
> > -----Original Message-----
> > From: Leif Lindholm <leif@nuviainc.com>
> > Sent: Monday, July 27, 2020 9:58 PM
> > To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima
> > <masahisa.kojima@linaro.org>
> > Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C
> > <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> > Biesheuvel <ard.biesheuvel@arm.com>
> > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > bytecode arrays into .obj file
> >
> > Hi Pierre, (+Masahisa)
> >
> > This commit (0a4aa20e8d44) made for an exciting start to my week.
> >
> > Socionext's Developerbox failed to build for me, with the
> > spectacular error message:
> >
> > /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> > DWARF error: could not find abbrev number 5912
> > /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> > <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> > `RegisterEmmc'
> >
> > GCC49 (without lto) and CLANG38 profiles give much the same result,
> > with slightly less esoteric messages.
> >
> > The reason for this turned out to be that edk2-platforms
> > Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an
> > Emmc.asl and an Emmc.c file, which after this patch both generate an
> > Emmc.obj in the same output directory.
> >
> > I think the correct course of action is to fix this in the SynQuacer
> > driver, but I am reporting it here so we get it logged in the list
> > archives.
> >
> > It would of course be good if the build system could detect and warn
> > over cases like this, rather than silently overwriting existing
> > object files.
> >
> > Masahisa - since Ard is still on holiday, could you create a patch
> > and send out for me to review? Either one of the files needs to be
> > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > into a subdirectory.
> >
> > Best Regards,
> >
> > Leif
> >
> > On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > > From: Pierre Gondois <pierre.gondois@arm.com>
> > >
> > > 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 modifies the AmlToC script to generate a C file instead
> > > of a ".hex" file.
> > > It also adds the generation of an intermediate ".amli" file when
> > > compiling an ASL file, and adds a rule to convert this ".amli" to
> > > a C file.
> > >
> > > This allows to generate 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>
> > > ---
> > >
> > > The changes can be seen at:
> > > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode
> > > _a
> > > rray_into_OBJ_file_v5
> > >
> > > Notes:
> > >     v1:
> > >      - Add a new rule to the build_rule.template file to
> > >        generate ".obj" files from .asl files, and modify
> > >        the AmlToC script accordingly. [Pierre]
> > >     v2:
> > >      - Restrict the rule to DXE_DRIVER. This allows to build
> > >        the OvmfPkg, which was not the case in v1. [Pierre]
> > >     v3:
> > >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> > >     v4:
> > >     - No modification. Re-sending the patch with base64
> > >       encoding to conserve the right line endings. [Bob]
> > >     v5:
> > >      - No modification. [Pierre]
> > >
> > >  BaseTools/Conf/build_rule.template       | 15 +++-
> > >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82
> > > ++++++++------------
> > >  2 files changed, 47 insertions(+), 50 deletions(-)
> > >
> > > diff --git a/BaseTools/Conf/build_rule.template
> > > b/BaseTools/Conf/build_rule.template
> > > index
> > > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6
> > > aa
> > > dba08e0169da44 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
> > > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809
> > > dd
> > > be8175f1493cfb 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
> > > --
> > > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> > >
> > >
>
>
>
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
>
>
>



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-28  9:04             ` PierreGondois
@ 2020-07-28 11:19               ` Leif Lindholm
  2020-07-29  0:17                 ` Masahisa Kojima
  0 siblings, 1 reply; 17+ messages in thread
From: Leif Lindholm @ 2020-07-28 11:19 UTC (permalink / raw)
  To: Pierre Gondois, masahisa.kojima
  Cc: devel@edk2.groups.io, Gao, Liming, Sami Mujawar, Tomas Pilar,
	Feng, Bob C, Ard Biesheuvel

Yes,

Do a git clean -fx in your edk2 directory, and delete your Build
directory completely.

Regards,

Leif

On Tue, Jul 28, 2020 at 09:04:44 +0000, Pierre Gondois wrote:
> Hello Masahisa,
> 
> Maybe you will have to delete/re-generate the build_rule.txt and
> tools_def.txt files that you have. This patch makes the build system
> generate a .amli file for each .asl file. If there is no Emmc.amli
> in your Build directory, this might be the reason.
> 
> Regards,
> Pierre
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Masahisa Kojima via groups.io
> Sent: Tuesday, July 28, 2020 2:38 AM
> To: Leif Lindholm <leif@nuviainc.com>
> Cc: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Pierre Gondois <Pierre.Gondois@arm.com>; Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
> Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
> 
> Hi Leif,
> 
> > > Masahisa - since Ard is still on holiday, could you create a patch
> > > and send out for me to review? Either one of the files needs to be
> > > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > > into a subdirectory.
> 
> Probably I'm missing something, but my build for Developerbox platform is successful, with the latest edk2/edk2-platforms as of today.
> 
> My build option is:
> ---
> export TARGET=Platform/Socionext/DeveloperBox/DeveloperBox.dsc
> export PROFILE=DEBUG
> export ARCH=AARCH64
> export TOOL_CHAIN_TAG=GCC5
> 
> build -n $NUM_CPUS -a $ARCH -b $PROFILE -t $TOOL_CHAIN_TAG -p $TARGET -D SECURE_BOOT_ENABLE=TRUE -D X64EMU_ENABLE=TRUE -D TPM2_ENABLE=TRUE
> ---
> 
> GCC version is "gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-".
> 
> Some Output directory information:
> ~/src/uefi/Build/DeveloperBox$ find .|grep -i emmc ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iii
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj.deps
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iiii
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml.deps
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml
> ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.i
> 
> Regards,
> Masahisa
> 
> On Tue, 28 Jul 2020 at 09:40, Gao, Liming <liming.gao@intel.com> wrote:
> >
> > Pierre:
> >   Thanks for your investigation. For now, the module will rename source file to avoid the file conflict. Can you submit one BZ for BaseTools to enhance the logic for the autogen source file? This needs more discussion.
> >
> >   Yes. I agree to place the generated source file into $(DEBUG_DIR). You can make another patch for this change.
> >
> > Thanks
> > Liming
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > PierreGondois
> > Sent: 2020年7月28日 1:10
> > To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Leif
> > Lindholm <leif@nuviainc.com>; Masahisa Kojima
> > <masahisa.kojima@linaro.org>
> > Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> > <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> > Biesheuvel <Ard.Biesheuvel@arm.com>
> > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > bytecode arrays into .obj file
> >
> > Hello,
> >
> > Liming:
> > I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.
> >
> > Everybody:
> > The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
> > $(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl)
> > $(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from
> > Ip4Config2.vfr) $(OUTPUT_DIR)/CDir/Emmc.obj :
> > $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/Platfo
> > rmDxe/CDir/Emmc.c (from Emmc.c)
> >
> > The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
> > This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.
> >
> > Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.
> >
> > Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.
> >
> > Regards,
> > Pierre
> >
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming
> > Gao via groups.io
> > Sent: Monday, July 27, 2020 3:21 PM
> > To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre
> > Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima
> > <masahisa.kojima@linaro.org>
> > Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> > <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> > Biesheuvel <Ard.Biesheuvel@arm.com>
> > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > bytecode arrays into .obj file
> >
> > Leif:
> >   VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.
> >
> > Bob:
> >   Has BaseTools such detection if VFR and C source file have the same file name?
> >
> > Thanks
> > Liming
> > > -----Original Message-----
> > > From: Leif Lindholm <leif@nuviainc.com>
> > > Sent: Monday, July 27, 2020 9:58 PM
> > > To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima
> > > <masahisa.kojima@linaro.org>
> > > Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C
> > > <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> > > Biesheuvel <ard.biesheuvel@arm.com>
> > > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > > bytecode arrays into .obj file
> > >
> > > Hi Pierre, (+Masahisa)
> > >
> > > This commit (0a4aa20e8d44) made for an exciting start to my week.
> > >
> > > Socionext's Developerbox failed to build for me, with the
> > > spectacular error message:
> > >
> > > /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> > > DWARF error: could not find abbrev number 5912
> > > /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> > > <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> > > `RegisterEmmc'
> > >
> > > GCC49 (without lto) and CLANG38 profiles give much the same result,
> > > with slightly less esoteric messages.
> > >
> > > The reason for this turned out to be that edk2-platforms
> > > Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an
> > > Emmc.asl and an Emmc.c file, which after this patch both generate an
> > > Emmc.obj in the same output directory.
> > >
> > > I think the correct course of action is to fix this in the SynQuacer
> > > driver, but I am reporting it here so we get it logged in the list
> > > archives.
> > >
> > > It would of course be good if the build system could detect and warn
> > > over cases like this, rather than silently overwriting existing
> > > object files.
> > >
> > > Masahisa - since Ard is still on holiday, could you create a patch
> > > and send out for me to review? Either one of the files needs to be
> > > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > > into a subdirectory.
> > >
> > > Best Regards,
> > >
> > > Leif
> > >
> > > On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > > > From: Pierre Gondois <pierre.gondois@arm.com>
> > > >
> > > > 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 modifies the AmlToC script to generate a C file instead
> > > > of a ".hex" file.
> > > > It also adds the generation of an intermediate ".amli" file when
> > > > compiling an ASL file, and adds a rule to convert this ".amli" to
> > > > a C file.
> > > >
> > > > This allows to generate 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>
> > > > ---
> > > >
> > > > The changes can be seen at:
> > > > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode
> > > > _a
> > > > rray_into_OBJ_file_v5
> > > >
> > > > Notes:
> > > >     v1:
> > > >      - Add a new rule to the build_rule.template file to
> > > >        generate ".obj" files from .asl files, and modify
> > > >        the AmlToC script accordingly. [Pierre]
> > > >     v2:
> > > >      - Restrict the rule to DXE_DRIVER. This allows to build
> > > >        the OvmfPkg, which was not the case in v1. [Pierre]
> > > >     v3:
> > > >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> > > >     v4:
> > > >     - No modification. Re-sending the patch with base64
> > > >       encoding to conserve the right line endings. [Bob]
> > > >     v5:
> > > >      - No modification. [Pierre]
> > > >
> > > >  BaseTools/Conf/build_rule.template       | 15 +++-
> > > >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82
> > > > ++++++++------------
> > > >  2 files changed, 47 insertions(+), 50 deletions(-)
> > > >
> > > > diff --git a/BaseTools/Conf/build_rule.template
> > > > b/BaseTools/Conf/build_rule.template
> > > > index
> > > > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6
> > > > aa
> > > > dba08e0169da44 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
> > > > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809
> > > > dd
> > > > be8175f1493cfb 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
> > > > --
> > > > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> > > >
> > > >
> >
> >
> >
> > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
> >
> >
> >
> 
> 
> 
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
  2020-07-28 11:19               ` Leif Lindholm
@ 2020-07-29  0:17                 ` Masahisa Kojima
  0 siblings, 0 replies; 17+ messages in thread
From: Masahisa Kojima @ 2020-07-29  0:17 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: Pierre Gondois, devel@edk2.groups.io, Gao, Liming, Sami Mujawar,
	Tomas Pilar, Feng, Bob C, Ard Biesheuvel

Hi Pierre, Leif,

Thank you for your comment, I could replicate the issue.
I will submit the patch to rename the Emmc.c.

Regards,
Masahisa

On Tue, 28 Jul 2020 at 20:19, Leif Lindholm <leif@nuviainc.com> wrote:
>
> Yes,
>
> Do a git clean -fx in your edk2 directory, and delete your Build
> directory completely.
>
> Regards,
>
> Leif
>
> On Tue, Jul 28, 2020 at 09:04:44 +0000, Pierre Gondois wrote:
> > Hello Masahisa,
> >
> > Maybe you will have to delete/re-generate the build_rule.txt and
> > tools_def.txt files that you have. This patch makes the build system
> > generate a .amli file for each .asl file. If there is no Emmc.amli
> > in your Build directory, this might be the reason.
> >
> > Regards,
> > Pierre
> >
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Masahisa Kojima via groups.io
> > Sent: Tuesday, July 28, 2020 2:38 AM
> > To: Leif Lindholm <leif@nuviainc.com>
> > Cc: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Pierre Gondois <Pierre.Gondois@arm.com>; Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard Biesheuvel <Ard.Biesheuvel@arm.com>
> > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file
> >
> > Hi Leif,
> >
> > > > Masahisa - since Ard is still on holiday, could you create a patch
> > > > and send out for me to review? Either one of the files needs to be
> > > > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > > > into a subdirectory.
> >
> > Probably I'm missing something, but my build for Developerbox platform is successful, with the latest edk2/edk2-platforms as of today.
> >
> > My build option is:
> > ---
> > export TARGET=Platform/Socionext/DeveloperBox/DeveloperBox.dsc
> > export PROFILE=DEBUG
> > export ARCH=AARCH64
> > export TOOL_CHAIN_TAG=GCC5
> >
> > build -n $NUM_CPUS -a $ARCH -b $PROFILE -t $TOOL_CHAIN_TAG -p $TARGET -D SECURE_BOOT_ENABLE=TRUE -D X64EMU_ENABLE=TRUE -D TPM2_ENABLE=TRUE
> > ---
> >
> > GCC version is "gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-".
> >
> > Some Output directory information:
> > ~/src/uefi/Build/DeveloperBox$ find .|grep -i emmc ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iii
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj.deps
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.iiii
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.obj
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml.deps
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.aml
> > ./DEBUG_GCC5/AARCH64/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe/OUTPUT/Emmc.i
> >
> > Regards,
> > Masahisa
> >
> > On Tue, 28 Jul 2020 at 09:40, Gao, Liming <liming.gao@intel.com> wrote:
> > >
> > > Pierre:
> > >   Thanks for your investigation. For now, the module will rename source file to avoid the file conflict. Can you submit one BZ for BaseTools to enhance the logic for the autogen source file? This needs more discussion.
> > >
> > >   Yes. I agree to place the generated source file into $(DEBUG_DIR). You can make another patch for this change.
> > >
> > > Thanks
> > > Liming
> > > -----Original Message-----
> > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > > PierreGondois
> > > Sent: 2020年7月28日 1:10
> > > To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>; Leif
> > > Lindholm <leif@nuviainc.com>; Masahisa Kojima
> > > <masahisa.kojima@linaro.org>
> > > Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> > > <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> > > Biesheuvel <Ard.Biesheuvel@arm.com>
> > > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > > bytecode arrays into .obj file
> > >
> > > Hello,
> > >
> > > Liming:
> > > I didn't find anything preventing from having a .vfr and .c file with the same name in the same scope.
> > >
> > > Everybody:
> > > The .c files generated (from either .vfr or .asl) are generated in the Build/..../OUTPUT/ directory, with their original subdirectory stripped. In the example below, the .c, .vfr and .asl files have been placed in subdirectories in edk2/edk2-platforms. The recipes that have been generated are:
> > > $(OUTPUT_DIR)/Emmc.obj : $(OUTPUT_DIR)/AslDir/Emmc.c (from Emmc.asl)
> > > $(OUTPUT_DIR)/Ip4Config2.obj : $(DEBUG_DIR)/VfrDir/Ip4Config2.c (from
> > > Ip4Config2.vfr) $(OUTPUT_DIR)/CDir/Emmc.obj :
> > > $(WORKSPACE)/edk2-platforms/Silicon/Socionext/SynQuacer/Drivers/Platfo
> > > rmDxe/CDir/Emmc.c (from Emmc.c)
> > >
> > > The only subdirectory that remains is the one from the .c files. Indeed, the build system might detects subdirectories from the .inf file location. As the .c file is generated in the OUTPUT directory where there is no .inf file, it gets stripped.
> > > This means that if a subdirectory is created, it is for the .c file, but I don't think we should modify this.
> > >
> > > Adding a pre/postfix to the generated .c filename seems a better approach to me. It would require modifying build_rule.template, and choose which pre/postfix to add.
> > >
> > > Another point is that the .c file generated from the .c file is placed in the $(DEBUG_DIR), when the one coming from the .asl file is placed in $(OUTPUT_DIR). Maybe it should be modified to $(DEBUG_DIR) aswell.
> > >
> > > Regards,
> > > Pierre
> > >
> > > -----Original Message-----
> > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming
> > > Gao via groups.io
> > > Sent: Monday, July 27, 2020 3:21 PM
> > > To: Leif Lindholm <leif@nuviainc.com>; devel@edk2.groups.io; Pierre
> > > Gondois <Pierre.Gondois@arm.com>; Masahisa Kojima
> > > <masahisa.kojima@linaro.org>
> > > Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Tomas Pilar
> > > <Tomas.Pilar@arm.com>; Feng, Bob C <bob.c.feng@intel.com>; Ard
> > > Biesheuvel <Ard.Biesheuvel@arm.com>
> > > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > > bytecode arrays into .obj file
> > >
> > > Leif:
> > >   VFR file has the similar case. VFR is converted to xxx.c, then compile it to obj file.
> > >
> > > Bob:
> > >   Has BaseTools such detection if VFR and C source file have the same file name?
> > >
> > > Thanks
> > > Liming
> > > > -----Original Message-----
> > > > From: Leif Lindholm <leif@nuviainc.com>
> > > > Sent: Monday, July 27, 2020 9:58 PM
> > > > To: devel@edk2.groups.io; pierre.gondois@arm.com; Masahisa Kojima
> > > > <masahisa.kojima@linaro.org>
> > > > Cc: sami.mujawar@arm.com; tomas.pilar@arm.com; Feng, Bob C
> > > > <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Ard
> > > > Biesheuvel <ard.biesheuvel@arm.com>
> > > > Subject: Re: [edk2-devel] [PATCH v5 4/5] BaseTools: Compile AML
> > > > bytecode arrays into .obj file
> > > >
> > > > Hi Pierre, (+Masahisa)
> > > >
> > > > This commit (0a4aa20e8d44) made for an exciting start to my week.
> > > >
> > > > Socionext's Developerbox failed to build for me, with the
> > > > spectacular error message:
> > > >
> > > > /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> > > > DWARF error: could not find abbrev number 5912
> > > > /tmp/ccKt4gaM.ltrans0.ltrans.o: in function `RegisterDevices':
> > > > <artificial>:(.text.RegisterDevices+0xb0): undefined reference to
> > > > `RegisterEmmc'
> > > >
> > > > GCC49 (without lto) and CLANG38 profiles give much the same result,
> > > > with slightly less esoteric messages.
> > > >
> > > > The reason for this turned out to be that edk2-platforms
> > > > Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/ has both an
> > > > Emmc.asl and an Emmc.c file, which after this patch both generate an
> > > > Emmc.obj in the same output directory.
> > > >
> > > > I think the correct course of action is to fix this in the SynQuacer
> > > > driver, but I am reporting it here so we get it logged in the list
> > > > archives.
> > > >
> > > > It would of course be good if the build system could detect and warn
> > > > over cases like this, rather than silently overwriting existing
> > > > object files.
> > > >
> > > > Masahisa - since Ard is still on holiday, could you create a patch
> > > > and send out for me to review? Either one of the files needs to be
> > > > renamed, or we need to move the .asl files (Emmc.asl and Optee.asl)
> > > > into a subdirectory.
> > > >
> > > > Best Regards,
> > > >
> > > > Leif
> > > >
> > > > On Wed, Jul 01, 2020 at 15:06:03 +0100, PierreGondois wrote:
> > > > > From: Pierre Gondois <pierre.gondois@arm.com>
> > > > >
> > > > > 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 modifies the AmlToC script to generate a C file instead
> > > > > of a ".hex" file.
> > > > > It also adds the generation of an intermediate ".amli" file when
> > > > > compiling an ASL file, and adds a rule to convert this ".amli" to
> > > > > a C file.
> > > > >
> > > > > This allows to generate 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>
> > > > > ---
> > > > >
> > > > > The changes can be seen at:
> > > > > https://github.com/PierreARM/edk2/commits/803_Compile_AML_bytecode
> > > > > _a
> > > > > rray_into_OBJ_file_v5
> > > > >
> > > > > Notes:
> > > > >     v1:
> > > > >      - Add a new rule to the build_rule.template file to
> > > > >        generate ".obj" files from .asl files, and modify
> > > > >        the AmlToC script accordingly. [Pierre]
> > > > >     v2:
> > > > >      - Restrict the rule to DXE_DRIVER. This allows to build
> > > > >        the OvmfPkg, which was not the case in v1. [Pierre]
> > > > >     v3:
> > > > >      - Changed "Signed-off-by" to "Suggested-by". [Bob]
> > > > >     v4:
> > > > >     - No modification. Re-sending the patch with base64
> > > > >       encoding to conserve the right line endings. [Bob]
> > > > >     v5:
> > > > >      - No modification. [Pierre]
> > > > >
> > > > >  BaseTools/Conf/build_rule.template       | 15 +++-
> > > > >  BaseTools/Source/Python/AmlToC/AmlToC.py | 82
> > > > > ++++++++------------
> > > > >  2 files changed, 47 insertions(+), 50 deletions(-)
> > > > >
> > > > > diff --git a/BaseTools/Conf/build_rule.template
> > > > > b/BaseTools/Conf/build_rule.template
> > > > > index
> > > > > 0822b681fcd9f61c6508e6f93ffc31fa70fd7059..c034869915914936e28f64a6
> > > > > aa
> > > > > dba08e0169da44 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
> > > > > 643db2910e37acfdd80ac18d288c921320a79ce1..346de7159de702d860bbd809
> > > > > dd
> > > > > be8175f1493cfb 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
> > > > > --
> > > > > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> > > > >
> > > > >
> > >
> > >
> > >
> > > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
> > >
> > >
> > >
> >
> > 
> >
> > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-07-29  0:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-01 14:05 [PATCH v5 0/5] Compile AML bytecode array into OBJ file PierreGondois
2020-07-01 14:06 ` [PATCH v5 1/5] BaseTools: PatchCheck: Exclude bash scripts from CRLF check PierreGondois
2020-07-02  4:21   ` Bob Feng
2020-07-01 14:06 ` [PATCH 2/5] BaseTools: Generate multiple rules when multiple output files PierreGondois
2020-07-01 14:06 ` [PATCH v5 3/5] BaseTools: Rename AmlToHex script to AmlToC PierreGondois
2020-07-01 14:06 ` [PATCH v5 4/5] BaseTools: Compile AML bytecode arrays into .obj file PierreGondois
2020-07-27 13:58   ` [edk2-devel] " Leif Lindholm
2020-07-27 14:13     ` Sami Mujawar
2020-07-27 14:21     ` Liming Gao
2020-07-27 17:10       ` PierreGondois
2020-07-28  0:40         ` Liming Gao
2020-07-28  1:38           ` Masahisa Kojima
2020-07-28  9:04             ` PierreGondois
2020-07-28 11:19               ` Leif Lindholm
2020-07-29  0:17                 ` Masahisa Kojima
2020-07-01 14:06 ` [PATCH v5 5/5] BaseTools: Fix string concatenation PierreGondois
2020-07-02 10:20 ` [PATCH v5 0/5] Compile AML bytecode array into OBJ file Bob Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox