Content-Type: multipart/mixed; boundary="===============2911285213653160223==" MIME-Version: 1.0 From: Sami Mujawar Subject: [Devel] [PATCH v4] Modify hex AML C header file generation Date: Thu, 15 Mar 2018 18:08:25 +0000 Message-ID: <20180315180825.33572-1-sami.mujawar@arm.com> List-ID: To: devel@acpica.org --===============2911285213653160223== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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[] =3D { /* 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[] =3D { /* HEX AML data */ ... }; #endif /* DSDT_HEX_ */ Where Dsdt.asl is the input file name. Note: The header file include guard uses '_HEX_' format instead of '_H_' to avoid possible collision with an existing header guard. Signed-off-by: Sami Mujawar Signed-off-by: Evan Lloyd --- 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(-) diff --git a/source/common/adfile.c b/source/common/adfile.c index d05fe40a29cbe9596b0f1a75358a540bd4dad84b..3aa8219fc520429ca97b4177b0c= 1339a26e47e30 100644 --- a/source/common/adfile.c +++ b/source/common/adfile.c @@ -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) { diff --git a/source/compiler/aslhex.c b/source/compiler/aslhex.c index fe2d58ada468643d54b565a108764ad4262f782b..fb77cc930c92a31470e736a3034= 68862b4a1282f 100644 --- a/source/compiler/aslhex.c +++ b/source/compiler/aslhex.c @@ -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 =3D 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 =3D FlGenerateFilename (FilenamePrefix, ""); + + FilenamePrefix[strlen (FilenamePrefix) - 1] =3D 0; + AcpiUtStrlwr (FilenamePrefix); + + FileGuard =3D 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 byt= es\n *\n */\n", AmlFileSize); - FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =3D\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[] =3D\n{\n= ", FilenamePrefix); = while (Offset < AmlFileSize) { @@ -337,7 +357,8 @@ HxDoHexOutputC ( Offset +=3D LineLength; } = - FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif /* %s_HEX_ */\n", FileGuard); } = = diff --git a/source/include/acapps.h b/source/include/acapps.h index 94a40187cb221cd8c369b4a3b0aa3df83ba6b039..6bc4036bedd157067fec02b535f= 530e36ef78bd7 100644 --- a/source/include/acapps.h +++ b/source/include/acapps.h @@ -318,6 +318,10 @@ FlGenerateFilename ( char *InputFilename, char *Suffix); = +char * +FlStrdup ( + char *String); + ACPI_STATUS FlSplitInputPathname ( char *InputPath, -- = 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' --===============2911285213653160223==--