Skip to content

Commit

Permalink
iASL: Enhance the -tc option (create AML hex file in C)
Browse files Browse the repository at this point in the history
This change improves the -tc option by:
1) Creates a unique symbol for the hex table, to simplify
creation of multiple tables (DSDT/SSDT).
2) Adds a protection #ifdef, similar to a .h file.

With assistance from:
Sami Mujawar, sami.mujawar@arm.com
Evan Lloyd, evan.lloyd@arm.com
  • Loading branch information
acpibob committed Mar 16, 2018
1 parent a4f6620 commit f9a88a4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
56 changes: 56 additions & 0 deletions source/common/adfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,59 @@ FlSplitInputPathname (

return (AE_OK);
}


/*******************************************************************************
*
* FUNCTION: FlGetFileBasename
*
* PARAMETERS: FilePathname - File path to be split
*
* RETURN: The extracted base name of the file, in upper case
*
* DESCRIPTION: Extract the file base name (the file name with no extension)
* from the input pathname.
*
* Note: Any backslashes in the pathname should be previously
* converted to forward slashes before calling this function.
*
******************************************************************************/

char *
FlGetFileBasename (
char *FilePathname)
{
char *FileBasename;
char *Substring;


/* Backup to last slash or colon */

Substring = strrchr (FilePathname, '/');
if (!Substring)
{
Substring = strrchr (FilePathname, ':');
}

/* Extract the full filename (base + extension) */

if (Substring)
{
FileBasename = FlStrdup (Substring + 1);
}
else
{
FileBasename = FlStrdup (FilePathname);
}

/* Remove the filename extension if present */

Substring = strchr (FileBasename, '.');
if (Substring)
{
*Substring = 0;
}

AcpiUtStrupr (FileBasename);
return (FileBasename);
}
23 changes: 20 additions & 3 deletions source/compiler/aslhex.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
*****************************************************************************/

#include "aslcompiler.h"
#include "acapps.h"

#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("ashex")
Expand Down Expand Up @@ -265,6 +266,9 @@ HxReadAmlOutputFile (
* output file, but formatted into hex/ascii bytes suitable for
* inclusion into a C source file.
*
* Note: the base name of the hex output file is prepended to
* all symbols as they are output to the file.
*
******************************************************************************/

static void
Expand All @@ -276,17 +280,29 @@ HxDoHexOutputC (
UINT32 Offset = 0;
UINT32 AmlFileSize;
UINT32 i;
char *FileBasename;


/* Obtain the file basename (filename with no extension) */

FileBasename = FlGetFileBasename (Gbl_Files [ASL_FILE_HEX_OUTPUT].Filename);

/* Get AML size, seek back to start */

AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
FlSeekFile (ASL_FILE_AML_OUTPUT, 0);

/* Finish the file header and emit the non-data symbols */

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", FileBasename);
FlPrintFile (ASL_FILE_HEX_OUTPUT, "#define __%s_HEX__\n\n", FileBasename);

AcpiUtStrlwr (FileBasename);
FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char %s_aml_code[] =\n{\n", FileBasename);

while (Offset < AmlFileSize)
{
Expand All @@ -303,7 +319,7 @@ HxDoHexOutputC (
for (i = 0; i < LineLength; i++)
{
/*
* Print each hex byte.
* Output each hex byte in the form: "0xnn,"
* Add a comma until the very last byte of the AML file
* (Some C compilers complain about a trailing comma)
*/
Expand Down Expand Up @@ -337,7 +353,8 @@ HxDoHexOutputC (
Offset += LineLength;
}

FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n");
FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif\n");
}


Expand Down
4 changes: 4 additions & 0 deletions source/include/acapps.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ FlSplitInputPathname (
char **OutDirectoryPath,
char **OutFilename);

char *
FlGetFileBasename (
char *FilePathname);

char *
AdGenerateFilename (
char *Prefix,
Expand Down

8 comments on commit f9a88a4

@juikim
Copy link
Contributor

@juikim juikim commented on f9a88a4 May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be more careful not to include illegal characters. For example,

iasl -tc -p test-file test-file.dsl

generates a file containing this:

#ifndef __TEST-FILE_HEX__
#define __TEST-FILE_HEX__

unsigned char test-file_aml_code[] =

Obviously, this is illegal C because it contains - in a macro and a variable. In other words, we cannot use - in file names any more. In fact, this breaks VirtualBox build:

https://lists.freebsd.org/pipermail/freebsd-pkg-fallout/Week-of-Mon-20180430/762589.html

Can you please add an option to set a unique symbol and restore the previous behavior?

@acpibob
Copy link
Contributor Author

@acpibob acpibob commented on f9a88a4 May 4, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SchmErik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can create a command line option to change the aml_code array and go back to the original behavior. If users would like to use this option, they need to be aware that they need to have the proper filenames

@juikim
Copy link
Contributor

@juikim juikim commented on f9a88a4 May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can create a command line option to change the aml_code array and go back to the original behavior. If users would like to use this option, they need to be aware that they need to have the proper filenames

Yes, that's probably the best course of action.

@malattia
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, the VirtualBox build failure popped up in Debian too: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=899318

@juikim
Copy link
Contributor

@juikim juikim commented on f9a88a4 May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malattia
Copy link

@malattia malattia commented on f9a88a4 May 24, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LocutusOfBorg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! lets apply FreeBSD patch :)

Please sign in to comment.