Skip to contentSkip to conversation

Add support for hex AML C header file generation

PATCH Superseded Sami Mujawar 2 participants 2 messages Mar 14, 2018 ACPI component architecture (acpica)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sami Mujawar

author
#0 lore raw

PATCH v3 1/1 Add support for hex AML C header file generation

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

One of the options, '-tc' supports generation of AML hex tables in C. This command generates a character array that represents the AML hex table data.

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

However, there is no option to 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 ideally desired 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, without breaking existing implementations, a new option '-th' is introduced in the list of supported 'Firmware Support - C Text Output' commands. This option generates an AML hex table output in a C header file suitable for including from a C source file.

The '-th' option:
1. Uses the input file name as a prefix for the generated C array name.
e.g. 'unsigned char DadtAmlCode[]'

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

        #ifndef DSDT_HEX_
        #define DSDT_HEX_
        ...

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

        #endif // DSDT_HEX_

Where Dadt.aml 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>

---

Notes:
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/compiler/aslcompile.c |  15 +-
 source/compiler/aslglobal.h  |   1 +
 source/compiler/aslhelp.c    |   1 +
 source/compiler/aslhex.c     | 167 ++++++++++++++++++++
 source/compiler/asloptions.c |   5 +
 source/include/acapps.h      |   6 +
 6 files changed, 192 insertions(+), 3 deletions(-)
source/compiler/aslcompile.c +12 -3
index b0a06e6beb73e05a10a4d85c1cfda4e0668bbcbb..ffe5afdfebfd6729f14f4b9e2cbab626d64bbdd0 100644
@@ -544,7 +544,8 @@ AslCompilerSignon (
             Prefix = "; ";
         }
         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
-                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
+                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL) ||
+                 (Gbl_HexOutputFlag == HEX_OUTPUT_H))
         {
             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
             Prefix = " * ";
@@ -579,7 +580,14 @@ AslCompilerSignon (
     /* Compiler signon with copyright */
 
     FlPrintFile (FileId, "%s\n", Prefix);
-    FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
+    if (Gbl_HexOutputFlag == HEX_OUTPUT_H)
+    {
+        FlPrintFile (FileId, ACPI_COMMON_HEADER_NO_COPYRIGHT (UtilityName, Prefix));
+    }
+    else
+    {
+        FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
+    }
 }
 
 
@@ -621,7 +629,8 @@ AslCompilerFileHeader (
             Prefix = "; ";
         }
         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
-                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
+                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL) ||
+                 (Gbl_HexOutputFlag == HEX_OUTPUT_H))
         {
             Prefix = " * ";
         }
source/compiler/aslglobal.h +1 -0
index af65a45388127abf84006dafb7ce1431f0027cf6..904cc01e3cd6c5b18ef7d047c7a85d8615a23db9 100644
@@ -328,6 +328,7 @@ ASL_EXTERN BOOLEAN                  ASL_INIT_GLOBAL (Gbl_OptimizeTrivialParseNod
 #define HEX_OUTPUT_C                1
 #define HEX_OUTPUT_ASM              2
 #define HEX_OUTPUT_ASL              3
+#define HEX_OUTPUT_H                4
 
 ASL_EXTERN BOOLEAN                  ASL_INIT_GLOBAL (Gbl_HexOutputFlag, HEX_OUTPUT_NONE);
 
source/compiler/aslhelp.c +1 -0
index 608f18532b54ba59c17057a4d5c08bef38d7b14c..e29d8fc85f0da30fde17334d4d2fc9653e852436 100644
@@ -229,6 +229,7 @@ Usage (
 
     printf ("\nFirmware Support - C Text Output:\n");
     ACPI_OPTION ("-tc",             "Create hex AML table in C (*.hex)");
+    ACPI_OPTION ("-th",             "Create hex AML table in C header (*.hex)");
     ACPI_OPTION ("-sc",             "Create named hex AML arrays in C (*.c)");
     ACPI_OPTION ("-ic",             "Create include file in C for -sc symbols (*.h)");
     ACPI_OPTION ("-so",             "Create namespace AML offset table in C (*.offset.h)");
source/compiler/aslhex.c +167 -0

191 lines not on this page · raw message

source/compiler/asloptions.c +5 -0
index 2b1e6027fdb81e70900148cfd39ce6c453df57d1..a1aa56723349c0c8d91cff276d87217149a18634 100644
@@ -842,6 +842,11 @@ AslDoOptions (
             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
             break;
 
+        case 'h':
+
+            Gbl_HexOutputFlag = HEX_OUTPUT_H;
+            break;
+
         default:
 
             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
source/include/acapps.h +6 -0
index 94a40187cb221cd8c369b4a3b0aa3df83ba6b039..c6063257be92fb80d186a24db9713ec6f45621b4 100644
@@ -188,6 +188,12 @@
     Prefix, ACPICA_COPYRIGHT, \
     Prefix
 
+#define ACPI_COMMON_HEADER_NO_COPYRIGHT(UtilityName, Prefix) \
+    "%s%s\n%s%s version %8.8X%s\n%s\n", \
+    Prefix, ACPICA_NAME, \
+    Prefix, UtilityName, ((UINT32) ACPI_CA_VERSION), ACPI_WIDTH, \
+    Prefix
+
 #define ACPI_COMMON_BUILD_TIME \
     "Build date/time: %s %s\n", __DATE__, __TIME__
 
Signature · 1 line
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
#1 lore raw

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, and we would like to implement this in a manner similar to below:

#ifndef __dsdt_hex__
#define __dsdt_hex__

unsigned char dsdt_AmlCode[] =

{
    0x44,0x53,0x44,0x54,0x2B,0x00,0x00,0x00,  /* 00000000    "DSDT+..." */
    0x02,0xC2,0x49,0x6E,0x74,0x65,0x6C,0x00,  /* 00000008    "..Intel." */
    0x5F,0x44,0x53,0x44,0x54,0x5F,0x30,0x31,  /* 00000010    "_DSDT_01" */
    0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
    0x13,0x03,0x18,0x20,0x14,0x06,0x44,0x53,  /* 00000020    "... ..DS" */
    0x30,0x31,0x00                            /* 00000028    "01."      */
};

#endif

source/compiler/aslhex.c +11 -2
index fe2d58ada..c42087dbb 100644
@@ -150,6 +150,7 @@
  *****************************************************************************/
 
 #include "aslcompiler.h"
+#include "acapps.h"
 
 #define _COMPONENT          ACPI_COMPILER
         ACPI_MODULE_NAME    ("ashex")
@@ -276,8 +277,13 @@ HxDoHexOutputC (
     UINT32                  Offset = 0;
     UINT32                  AmlFileSize;
     UINT32                  i;
+    char                    *FilenamePrefix;
 
 
+    FilenamePrefix = FlGenerateFilename (Gbl_Files [ASL_FILE_HEX_OUTPUT].Filename, "");
+    FilenamePrefix[strlen (FilenamePrefix) - 1] = 0;
+    AcpiUtStrlwr (FilenamePrefix);
+
     /* Get AML size, seek back to start */
 
     AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
@@ -286,7 +292,9 @@ 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", FilenamePrefix);
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "#define __%s_hex__\n\n", FilenamePrefix);
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char %s_AmlCode[] =\n{\n", FilenamePrefix);
 
     while (Offset < AmlFileSize)
     {
@@ -337,7 +345,8 @@ HxDoHexOutputC (
         Offset += LineLength;
     }
 
-    FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n");
+    FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif\n");
 }