Modify hex AML C header file generation
Sami Mujawar
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.
---
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
@@ -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
@@ -150,6 +150,7 @@*****************************************************************************/ #include "aslcompiler.h" +#include "acapps.h" #define _COMPONENT ACPI_COMPILERACPI_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
@@ -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)'