From 6ea557e35ed3258232019128dcd4eb1d18116b02 Mon Sep 17 00:00:00 2001 From: htao Date: Thu, 27 Sep 2007 09:29:57 +0000 Subject: [PATCH] enable -q/-v/-d interface for EfiRom, GenVtf and TianoCompress tool and use the common message interface. git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@775 7335b38e-4728-0410-8992-fb3ffe349368 --- Source/C/EfiRom/EfiRom.c | 49 +++++++++++++------------- Source/C/EfiRom/EfiRom.h | 2 -- Source/C/GenVtf/GenVtf.c | 22 +++++++++--- Source/C/TianoCompress/TianoCompress.c | 45 +++++++++++++++-------- Source/C/TianoCompress/TianoCompress.h | 8 +++++ 5 files changed, 80 insertions(+), 46 deletions(-) diff --git a/Source/C/EfiRom/EfiRom.c b/Source/C/EfiRom/EfiRom.c index 1fe65b7..5044f67 100644 --- a/Source/C/EfiRom/EfiRom.c +++ b/Source/C/EfiRom/EfiRom.c @@ -88,7 +88,7 @@ Returns: } if (mOptions.Verbose) { - fprintf (stdout, "%s tool start.\n", UTILITY_NAME); + VerboseMsg("%s tool start.\n", UTILITY_NAME); } // // If dumping an image, then do that and quit @@ -153,13 +153,13 @@ Returns: Size = 0; if (FList->FileFlags & FILE_FLAG_EFI) { if (mOptions.Verbose) { - fprintf (stdout, "Processing EFI file %s\n", FList->FileName); + VerboseMsg("Processing EFI file %s\n", FList->FileName); } Status = ProcessEfiFile (FptrOut, FList, mOptions.VendId, mOptions.DevId, &Size); } else if (FList->FileFlags & FILE_FLAG_BINARY) { if (mOptions.Verbose) { - fprintf (stdout, "Processing binary file %s\n", FList->FileName); + VerboseMsg("Processing binary file %s\n", FList->FileName); } Status = ProcessBinFile (FptrOut, FList, &Size); @@ -169,7 +169,7 @@ Returns: } if (mOptions.Verbose) { - fprintf (stdout, " Output size = 0x%X\n", Size); + VerboseMsg(" Output size = 0x%X\n", Size); } if (Status != STATUS_SUCCESS) { @@ -206,7 +206,7 @@ BailOut: } } if (mOptions.Verbose) { - fprintf (stdout, "%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); + VerboseMsg("%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); } return GetUtilityStatus (); @@ -265,7 +265,7 @@ Returns: fseek (InFptr, 0, SEEK_END); FileSize = ftell (InFptr); if (mOptions.Verbose) { - fprintf (stdout, " File size = 0x%X\n", FileSize); + VerboseMsg(" File size = 0x%X\n", FileSize); } fseek (InFptr, 0, SEEK_SET); @@ -366,7 +366,9 @@ Returns: } Buffer[FileSize - 1] = (UINT8) ((~ByteCheckSum) + 1); - fprintf (stdout, "Checksum = %02x\n", (UINT32) Buffer[FileSize - 1]); + if (mOptions.Verbose) { + VerboseMsg(" Checksum = %02x\n\n", (UINT32) Buffer[FileSize - 1]); + } // // Now copy the input file contents out to the output file @@ -487,7 +489,7 @@ Returns: HeaderSize = sizeof (PCI_DATA_STRUCTURE) + HeaderPadBytes + sizeof (EFI_PCI_EXPANSION_ROM_HEADER); if (mOptions.Verbose) { - fprintf (stdout, " File size = 0x%X\n", FileSize); + VerboseMsg(" File size = 0x%X\n", FileSize); } // // Allocate memory for the entire file (in case we have to compress), then @@ -532,7 +534,7 @@ Returns: // Now compute the size, then swap buffer pointers. // if (mOptions.Verbose) { - fprintf (stdout, " Comp size = 0x%X\n", CompressedFileSize); + VerboseMsg(" Comp size = 0x%X\n", CompressedFileSize); } TotalSize = CompressedFileSize + HeaderSize; @@ -816,7 +818,7 @@ Returns: *SubSystem = OptionalHdr.Subsystem; if (mOptions.Verbose) { - fprintf (stdout, " Got subsystem = 0x%X from image\n", (int) *SubSystem); + VerboseMsg(" Got subsystem = 0x%X from image\n", (int) *SubSystem); } // // Good to go @@ -902,7 +904,6 @@ Returns: // // Process until no more arguments // - //__asm int 3; while (Argc > 0) { if ((Argv[0][0] == '-') || (Argv[0][0] == '/')) { // @@ -917,7 +918,6 @@ Returns: // // Make sure there's another parameter // - //printf("\nvendor id specified!\n"); if (Argc > 1) { Options->VendId = (UINT16) strtol (Argv[1], NULL, 16); Options->VendIdValid = 1; @@ -998,16 +998,14 @@ Returns: return 1; } if (DebugLevel>=5 && DebugLevel<=9) { - DebugMode = TRUE; + Options->Debug = TRUE; } else { - DebugMode = FALSE; + Options->Debug = FALSE; } - Argv++; - } else if ((stricmp (Argv[0], "-quiet") == 0) || (stricmp (Argv[0], "-q") == 0)) { - QuietMode = TRUE; - //Argv++; - //Argc--; - } else if ((stricmp (Argv[0], "-dump") == 0) || (stricmp (Argv[0], "-d") == 0)) { + Argc--; + } else if ((stricmp (Argv[0], "--quiet") == 0) || (stricmp (Argv[0], "-q") == 0)) { + Options->Quiet = TRUE; + } else if ((stricmp (Argv[0], "--dump") == 0) || (stricmp (Argv[0], "-d") == 0)) { // // -dump for dumping a ROM image. In this case, say that the device id // and vendor id are valid so we don't have to specify bogus ones on the @@ -1239,7 +1237,7 @@ Returns: Show this help message and exit.\n"); fprintf (stdout, " -q, --quiet\n\ Disable all messages except FATAL ERRORS.\n"); - fprintf (stdout, " --debug [#]\n\ + fprintf (stdout, " --debug [#,0-9]\n\ Enable debug messages at level #.\n"); } @@ -1322,17 +1320,20 @@ Returns: // if (mOptions.Pci23 == 1) { if (fread (&PciDs23, sizeof (PciDs23), 1, InFptr) != 1) { - Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file"); + Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file %s", InFile->FileName); goto BailOut; } } else { if (fread (&PciDs30, sizeof (PciDs30), 1, InFptr) != 1) { - Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file"); + Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file %s", InFile->FileName); goto BailOut; } } + if (mOptions.Verbose) { + VerboseMsg("Read PCI data structure from file %s", InFile->FileName); + } - fprintf (stdout, " PCI Data Structure\n"); + //fprintf (stdout, " PCI Data Structure\n"); if (mOptions.Pci23 == 1) { fprintf ( stdout, diff --git a/Source/C/EfiRom/EfiRom.h b/Source/C/EfiRom/EfiRom.h index 42acd7d..cdcf357 100644 --- a/Source/C/EfiRom/EfiRom.h +++ b/Source/C/EfiRom/EfiRom.h @@ -82,8 +82,6 @@ Abstract: // global variables // UINTN DebugLevel = 0; -BOOLEAN DebugMode = FALSE; -BOOLEAN QuietMode = FALSE; // // Use this linked list structure to keep track of all the filenames diff --git a/Source/C/GenVtf/GenVtf.c b/Source/C/GenVtf/GenVtf.c index 1178657..547249f 100644 --- a/Source/C/GenVtf/GenVtf.c +++ b/Source/C/GenVtf/GenVtf.c @@ -363,7 +363,7 @@ Returns: VtfInfo->LocationType = SECOND_VTF; } else { VtfInfo->LocationType = NONE; - printf ("\nWARN: Unknown location for component %s\n", VtfInfo->CompName); + Warning(UTILITY_NAME, 0, 0001, "Unknown location for component", VtfInfo->CompName); } } else if (strnicmp (*TokenStr, "COMP_TYPE", 9) == 0) { TokenStr++; @@ -2636,8 +2636,19 @@ Returns: } } +// +// All Parameters has been parsed, now set the message print level +// + if (QuietMode) { + SetPrintLevel(40); + } else if (VerboseMode) { + SetPrintLevel(15); + } else if (DebugMode) { + SetPrintLevel(DebugLevel); + } + if (VerboseMode) { - fprintf (stdout, "%s tool start.\n", UTILITY_NAME); + VerboseMsg("%s tool start.\n", UTILITY_NAME); } if (VTF_OUTPUT == FALSE) { @@ -2653,7 +2664,7 @@ Returns: // Call the GenVtfImage // if (DebugMode) { - fprintf(stdout, "Start to generate the VTF image\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Start to generate the VTF image\n"); } Status = GenerateVtfImage (StartAddress1, FwVolSize1, StartAddress2, FwVolSize2, VtfFP); @@ -2682,13 +2693,14 @@ Returns: } ERROR: if (VerboseMode) { - fprintf (stdout, "%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); + VerboseMsg("%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); } return GetUtilityStatus (); } if (DebugMode) { - fprintf(stdout, "VTF image generated successful\n"); + //fprintf(stdout, "VTF image generated successful\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "VTF image generated successful\n"); } return 0; } diff --git a/Source/C/TianoCompress/TianoCompress.c b/Source/C/TianoCompress/TianoCompress.c index 02dce90..2f6e56b 100644 --- a/Source/C/TianoCompress/TianoCompress.c +++ b/Source/C/TianoCompress/TianoCompress.c @@ -1710,7 +1710,7 @@ Returns: Show this help message and exit.\n"); fprintf (stdout, " -q, --quiet\n\ Disable all messages except FATAL ERRORS.\n"); - fprintf (stdout, " -d, --debug [#]\n\ + fprintf (stdout, " -d, --debug [#,0-9]\n\ Enable debug messages at level #.\n"); } @@ -1862,22 +1862,28 @@ Returns: } // -// All Parameters has been parsed -// +// All Parameters has been parsed, now set the message print level +// + if (QuietMode) { + SetPrintLevel(40); + } else if (VerboseMode) { + SetPrintLevel(15); + } else if (DebugMode) { + SetPrintLevel(DebugLevel); + } + if (VerboseMode) { - fprintf (stdout, "%s tool start.\n", UTILITY_NAME); + VerboseMsg("%s tool start.\n", UTILITY_NAME); } Scratch = (SCRATCH_DATA *)malloc(sizeof(SCRATCH_DATA)); if (Scratch == NULL) { Error(NULL, 0, 4001, "Resource:", "Memory cannot be allocated!"); - //return 1; goto ERROR; } InputFile = fopen (InputFileName, "rb"); if (InputFile == NULL) { Error(NULL, 0, 0001, "Error opening input file", InputFileName); - //return 1; goto ERROR; } @@ -1912,9 +1918,11 @@ Returns: if (InputFile != NULL) { fclose (InputFile); } - //return EFI_ABORTED; goto ERROR; } + } else { + OutputFileName = DEFAULT_OUTPUT_FILE; + OutputFile = fopen (OutputFileName, "wb"); } if (ENCODE) { @@ -1922,7 +1930,7 @@ Returns: // First call TianoCompress to get DstSize // if (DebugMode) { - fprintf(stdout, "Encoding\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding"); } Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize); @@ -1940,17 +1948,21 @@ Returns: } fwrite(OutBuffer,(size_t)DstSize, 1, OutputFile); + free(Scratch); free(FileBuffer); free(OutBuffer); if (DebugMode) { - fprintf(stdout, "Encoding successful\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding Successful!\n"); + } + if (VerboseMode) { + VerboseMsg("Encoding successful\n"); } return 0; } else if (DECODE) { if (DebugMode) { - fprintf(stdout, "Decoding\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Decoding\n"); } // // Get Compressed file original size @@ -1969,7 +1981,6 @@ Returns: Status = Decompress((VOID *)FileBuffer, (VOID *)OutBuffer, (VOID *)Scratch, 2); if (Status != EFI_SUCCESS) { - //Error(NULL, 0, 0008, "Error decompressing file: %s", InputFileName); goto ERROR; } @@ -1979,7 +1990,11 @@ Returns: free(OutBuffer); if (DebugMode) { - fprintf(stdout, "Decoding successful\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding successful!\n"); + } + + if (VerboseMode) { + VerboseMsg("Decoding successful\n"); } return 0; } @@ -1987,16 +2002,16 @@ Returns: ERROR: if (DebugMode) { if (ENCODE) { - fprintf(stdout, "Encoding Error\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Encoding Error\n"); } else if (DECODE) { - fprintf(stdout, "Decoding Error\n"); + DebugMsg(UTILITY_NAME, 0, DebugLevel, "Decoding Error\n"); } } free(Scratch); free(FileBuffer); free(OutBuffer); if (VerboseMode) { - fprintf (stdout, "%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); + VerboseMsg("%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); } return GetUtilityStatus (); } diff --git a/Source/C/TianoCompress/TianoCompress.h b/Source/C/TianoCompress/TianoCompress.h index 6b2b167..4fc48c3 100644 --- a/Source/C/TianoCompress/TianoCompress.h +++ b/Source/C/TianoCompress/TianoCompress.h @@ -20,12 +20,20 @@ #include #include #include + + // // Decompression algorithm begins here // #define UTILITY_NAME "TianoCompress" #define UTILITY_MAJOR_VERSION 0 #define UTILITY_MINOR_VERSION 1 + +// +// Default output file name +// +#define DEFAULT_OUTPUT_FILE "file.tmp" + #define BITBUFSIZ 32 #define MAXMATCH 256 #define THRESHOLD 3 -- 2.17.1