Skip to contentSkip to conversation

Modify hex AML C header file generation

PATCH New Sami Mujawar 1 participant 1 message Mar 15, 2018 ACPI component architecture (acpica)

lore
Share & tools
lore

Sami Mujawar

author
#0 lore raw

PATCH v4 1/1 Modify hex AML C header file generation

The iAsl compiler provides a list of options to support 'Firmware Support - C Text Output'.

The '-tc' option supports generation of AML hex tables in C. Previously the output resembled:

           unsigned char AmlCode[] = {
               /* HEX AML data */
               ...
               };

However, this output did not change the name of the generated character array (AmlCode) in the output hex file. This limits the ability to reference more than one table from the firmware code.

Also, the generated output does not have header file include guards. This is desirable if the hex file is to be included from a C source file.

A solution to this is to modify the Hex C output such that the name of the array is derived from the input file name, and to add header file include guards.

To address the above, the output generated by the '-tc' option is modified as below:

1. Use the input file name as a prefix for the generated C array name.
e.g. 'unsigned char dsdt_AmlCode[]'

2. Add a header file include guard.
e.g.

        #ifndef DSDT_HEX_
        #define DSDT_HEX_
        ...

        unsigned char dsdt_AmlCode[] = {
            /* HEX AML data */
            ...
        };

        #endif /* DSDT_HEX_ */

Where Dsdt.asl is the input file name.

Note: The header file include guard uses '<InputFileName>_HEX_'
format instead of '<InputFileName>_H_' to avoid possible collision with an existing header guard.

Signed-off-by Sami Mujawar <sami.mujawar(a)arm.com>
Signed-off-by Evan Lloyd <evan.lloyd(a)arm.com>

---

The changes can be seen at

    https://github.com/samimujawar/acpica/tree/139_aml_c_header_v4

Notes:
v4:
- We agree that this is a useful change to the iASL compiler. However, we don't necessarily see a need to create a new
option ... [ROBERT]
- Submitting updated patch that modified existing '-tc'
option. [SAMI]

v3:
- Please change the style for if statements so that braces
are on separate lines. [ERIK]
- Resubmitting patch after fixing the issue. [SAMI]

v2:
- The line below causes a segmentation fault for file paths without '/'. A command like "iasl -th hpet.dsl"
should compile without segfaults. [ERIK]
- Resubmitting patch after fixing the issue. [SAMI]

 source/common/adfile.c   |  9 +++++--
 source/compiler/aslhex.c | 25 ++++++++++++++++++--
 source/include/acapps.h  |  4 ++++
 3 files changed, 34 insertions(+), 4 deletions(-)
source/common/adfile.c +7 -2
index d05fe40a29cbe9596b0f1a75358a540bd4dad84b..3aa8219fc520429ca97b4177b0c1339a26e47e30 100644
@@ -347,11 +347,16 @@ FlGenerateFilename (
  *
  * FUNCTION:    FlStrdup
  *
- * DESCRIPTION: Local strdup function
+ * PARAMETERS:  String              - Source string to duplicate.
+ *
+ * RETURN:      New string cloned from the source string.
+ *
+ * DESCRIPTION: Generate a new string which is a clone of the
+ *              source string. Similar to strdup function.
  *
  ******************************************************************************/
 
-static char *
+char *
 FlStrdup (
     char                *String)
 {
source/compiler/aslhex.c +23 -2
index fe2d58ada468643d54b565a108764ad4262f782b..fb77cc930c92a31470e736a303468862b4a1282f 100644
@@ -150,6 +150,7 @@
  *****************************************************************************/
 
 #include "aslcompiler.h"
+#include "acapps.h"
 
 #define _COMPONENT          ACPI_COMPILER
         ACPI_MODULE_NAME    ("ashex")
@@ -276,7 +277,23 @@ HxDoHexOutputC (
     UINT32                  Offset = 0;
     UINT32                  AmlFileSize;
     UINT32                  i;
+    char                    *FilenamePrefix;
+    char                    *FileGuard;
 
+    /*
+     * Get the filename and use it as a prefix for
+     * the AML code array and the header file guard
+     */
+    FlSplitInputPathname (Gbl_Files [ASL_FILE_HEX_OUTPUT].Filename, NULL,
+        &FilenamePrefix);
+
+    FilenamePrefix = FlGenerateFilename (FilenamePrefix, "");
+
+    FilenamePrefix[strlen (FilenamePrefix) - 1] = 0;
+    AcpiUtStrlwr (FilenamePrefix);
+
+    FileGuard = FlStrdup (FilenamePrefix);
+    AcpiUtStrupr (FileGuard);
 
     /* Get AML size, seek back to start */
 
@@ -286,7 +303,10 @@ HxDoHexOutputC (
     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
         AmlFileSize);
-    FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
+
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "#ifndef %s_HEX_\n", FileGuard);
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "#define %s_HEX_\n\n", FileGuard);
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char %s_AmlCode[] =\n{\n", FilenamePrefix);
 
     while (Offset < AmlFileSize)
     {
@@ -337,7 +357,8 @@ HxDoHexOutputC (
         Offset += LineLength;
     }
 
-    FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n");
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif /* %s_HEX_ */\n", FileGuard);
 }
 
 
source/include/acapps.h +4 -0
index 94a40187cb221cd8c369b4a3b0aa3df83ba6b039..6bc4036bedd157067fec02b535f530e36ef78bd7 100644
@@ -318,6 +318,10 @@ FlGenerateFilename (
     char                    *InputFilename,
     char                    *Suffix);
 
+char *
+FlStrdup (
+    char                *String);
+
 ACPI_STATUS
 FlSplitInputPathname (
     char                    *InputPath,
Signature · 1 line
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'