diff options
Diffstat (limited to 'tools/acpiexec/aemain.c')
-rw-r--r-- | tools/acpiexec/aemain.c | 280 |
1 files changed, 271 insertions, 9 deletions
diff --git a/tools/acpiexec/aemain.c b/tools/acpiexec/aemain.c index 3aec0740fecf4..1a2dd7cdb3678 100644 --- a/tools/acpiexec/aemain.c +++ b/tools/acpiexec/aemain.c @@ -127,6 +127,15 @@ BOOLEAN AcpiGbl_IgnoreErrors = FALSE; BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE; BOOLEAN AcpiGbl_DebugTimeout = FALSE; char BatchBuffer[128]; +AE_TABLE_DESC *AeTableListHead = NULL; + +#define ASL_MAX_FILES 256 +char *FileList[ASL_MAX_FILES]; +int FileCount; + + + +#define AE_SUPPORTED_OPTIONS "?ab:de^ghimo:rstvx:z" /****************************************************************************** @@ -144,7 +153,7 @@ char BatchBuffer[128]; static void usage (void) { - printf ("Usage: acpiexec [Options] [InputFile]\n\n"); + printf ("Usage: acpiexec [options] AMLfile1 AMLfile2 ...\n\n"); printf ("Where:\n"); printf (" -? Display this message\n"); @@ -218,6 +227,184 @@ AcpiDbRunBatchMode ( } +/******************************************************************************* + * + * FUNCTION: FlStrdup + * + * DESCRIPTION: Local strdup function + * + ******************************************************************************/ + +static char * +FlStrdup ( + char *String) +{ + char *NewString; + + + NewString = AcpiOsAllocate (strlen (String) + 1); + if (!NewString) + { + return (NULL); + } + + strcpy (NewString, String); + return (NewString); +} + + +/******************************************************************************* + * + * FUNCTION: FlSplitInputPathname + * + * PARAMETERS: InputFilename - The user-specified ASL source file to be + * compiled + * OutDirectoryPath - Where the directory path prefix is + * returned + * OutFilename - Where the filename part is returned + * + * RETURN: Status + * + * DESCRIPTION: Split the input path into a directory and filename part + * 1) Directory part used to open include files + * 2) Filename part used to generate output filenames + * + ******************************************************************************/ + +ACPI_STATUS +FlSplitInputPathname ( + char *InputPath, + char **OutDirectoryPath, + char **OutFilename) +{ + char *Substring; + char *DirectoryPath; + char *Filename; + + + *OutDirectoryPath = NULL; + *OutFilename = NULL; + + if (!InputPath) + { + return (AE_OK); + } + + /* Get the path to the input filename's directory */ + + DirectoryPath = FlStrdup (InputPath); + if (!DirectoryPath) + { + return (AE_NO_MEMORY); + } + + Substring = strrchr (DirectoryPath, '\\'); + if (!Substring) + { + Substring = strrchr (DirectoryPath, '/'); + if (!Substring) + { + Substring = strrchr (DirectoryPath, ':'); + } + } + + if (!Substring) + { + DirectoryPath[0] = 0; + Filename = FlStrdup (InputPath); + } + else + { + Filename = FlStrdup (Substring + 1); + *(Substring+1) = 0; + } + + if (!Filename) + { + return (AE_NO_MEMORY); + } + + *OutDirectoryPath = DirectoryPath; + *OutFilename = Filename; + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AsDoWildcard + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Process files via wildcards. This function is for the Windows + * case only. + * + ******************************************************************************/ + +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier) +{ +#ifdef WIN32 + void *DirInfo; + char *Filename; + + + FileCount = 0; + + /* Open parent directory */ + + DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); + if (!DirInfo) + { + /* Either the directory or file does not exist */ + + printf ("File or directory %s%s does not exist\n", DirectoryPathname, FileSpecifier); + return (NULL); + } + + /* Process each file that matches the wildcard specification */ + + while ((Filename = AcpiOsGetNextFilename (DirInfo))) + { + /* Add the filename to the file list */ + + FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); + strcpy (FileList[FileCount], Filename); + FileCount++; + + if (FileCount >= ASL_MAX_FILES) + { + printf ("Max files reached\n"); + FileList[0] = NULL; + return (FileList); + } + } + + /* Cleanup */ + + AcpiOsCloseDirectory (DirInfo); + FileList[FileCount] = NULL; + return (FileList); + +#else + /* + * Linux/Unix cases - Wildcards are expanded by the shell automatically. + * Just return the filename in a null terminated list + */ + FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); + strcpy (FileList[0], FileSpecifier); + FileList[1] = NULL; + + return (FileList); +#endif +} + + /****************************************************************************** * * FUNCTION: main @@ -238,7 +425,13 @@ main ( int j; ACPI_STATUS Status; UINT32 InitFlags; - ACPI_TABLE_HEADER *Table; + ACPI_TABLE_HEADER *Table = NULL; + UINT32 TableCount; + AE_TABLE_DESC *TableDesc; + char **FileList; + char *Filename; + char *Directory; + char *FullPathname; #ifdef _DEBUG @@ -269,7 +462,7 @@ main ( /* Get the command line options */ - while ((j = AcpiGetopt (argc, argv, "?ab:de^gimo:rstvx:z")) != EOF) switch(j) + while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j) { case 'a': AcpiGbl_IgnoreErrors = TRUE; @@ -352,6 +545,7 @@ main ( break; case '?': + case 'h': default: usage(); return -1; @@ -364,21 +558,89 @@ main ( InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); } - /* Standalone filename is the only argument */ + /* The remaining arguments are filenames for ACPI tables */ if (argv[AcpiGbl_Optind]) { AcpiGbl_DbOpt_tables = TRUE; - AcpiGbl_DbFilename = argv[AcpiGbl_Optind]; + TableCount = 0; + + /* Get each of the ACPI table files on the command line */ - Status = AcpiDbReadTableFromFile (AcpiGbl_DbFilename, &Table); + while (argv[AcpiGbl_Optind]) + { + /* Split incoming path into a directory/filename combo */ + + Status = FlSplitInputPathname (argv[AcpiGbl_Optind], &Directory, &Filename); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Expand wildcards (Windows only) */ + + FileList = AsDoWildcard (Directory, Filename); + if (!FileList) + { + return -1; + } + + while (*FileList) + { + FullPathname = AcpiOsAllocate ( + strlen (Directory) + strlen (*FileList) + 1); + + /* Construct a full path to the file */ + + strcpy (FullPathname, Directory); + strcat (FullPathname, *FileList); + + /* Get one table */ + + Status = AcpiDbReadTableFromFile (FullPathname, &Table); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not get input table %s, %s\n", FullPathname, + AcpiFormatException (Status)); + goto enterloop; + } + + AcpiOsFree (FullPathname); + AcpiOsFree (*FileList); + *FileList = NULL; + FileList++; + + /* + * Ignore an FACS or RSDT, we can't use them. + */ + if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FACS) || + ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_RSDT)) + { + AcpiOsFree (Table); + continue; + } + + /* Allocate and link a table descriptor */ + + TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); + TableDesc->Table = Table; + TableDesc->Next = AeTableListHead; + AeTableListHead = TableDesc; + + TableCount++; + } + + AcpiGbl_Optind++; + } + + /* Build a local RSDT with all tables and let ACPICA process the RSDT */ + + Status = AeBuildLocalTables (TableCount, AeTableListHead); if (ACPI_FAILURE (Status)) { - printf ("**** Could not get input table, %s\n", AcpiFormatException (Status)); - goto enterloop; + return -1; } - AeBuildLocalTables (Table); Status = AeInstallTables (); if (ACPI_FAILURE (Status)) { |