+++ /dev/null
-/*++\r
-\r
-Copyright (c) 1999-2006 Intel Corporation. All rights reserved\r
-This program and the accompanying materials are licensed and made available \r
-under the terms and conditions of the BSD License which accompanies this \r
-distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-\r
-Module Name:\r
-\r
- CreateMtFile.c\r
-\r
-Abstract:\r
-\r
- Simple utility to create a pad file containing fixed data.\r
- \r
---*/\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-\r
-#include <Common/UefiBaseTypes.h>\r
-\r
-#define UTILITY_NAME "CreateMtFile"\r
-#define UTILITY_MAJOR_VERSION 1\r
-#define UTILITY_MINOR_VERSION 1\r
-\r
-typedef struct {\r
- INT8 *OutFileName;\r
- INT8 ByteValue;\r
- UINT32 FileSize;\r
-} OPTIONS;\r
-\r
-static\r
-EFI_STATUS\r
-ProcessArgs (\r
- IN INT32 Argc,\r
- IN INT8 *Argv[],\r
- IN OUT OPTIONS *Options\r
- );\r
-\r
-static\r
-void\r
-Usage (\r
- VOID\r
- );\r
-\r
-static\r
-void\r
-Version (\r
- VOID\r
- );\r
-\r
-int\r
-main (\r
- IN INT32 Argc,\r
- IN INT8 *Argv[]\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Main entry point for this utility.\r
-\r
-Arguments:\r
-\r
- Standard C entry point args Argc and Argv\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS if good to go\r
-\r
---*/\r
-// GC_TODO: ] - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-{\r
- FILE *OutFptr;\r
- OPTIONS Options;\r
-\r
- //\r
- // Process the command-line arguments.\r
- //\r
- if (ProcessArgs (Argc, Argv, &Options) != EFI_SUCCESS) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Open the output file\r
- //\r
- if ((OutFptr = fopen (Options.OutFileName, "wb")) == NULL) {\r
- printf (" ERROR: Could not open output file '%s' for writing\n", Options.OutFileName);\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Write the pad bytes. Do it the slow way (one at a time) for now.\r
- //\r
- while (Options.FileSize > 0) {\r
- if (fwrite (&Options.ByteValue, 1, 1, OutFptr) != 1) {\r
- fclose (OutFptr);\r
- printf (" ERROR: Failed to write to output file\n");\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- Options.FileSize--;\r
- }\r
- //\r
- // Close the file\r
- //\r
- fclose (OutFptr);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-ProcessArgs (\r
- IN INT32 Argc,\r
- IN INT8 *Argv[],\r
- IN OUT OPTIONS *Options\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Process the command line arguments.\r
-\r
-Arguments:\r
-\r
- Argc - argument count as passed in to the entry point function\r
- Argv - array of arguments as passed in to the entry point function\r
- Options - stucture of where to put the values of the parsed arguments\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS if everything looks good\r
- EFI_INVALID_PARAMETER otherwise\r
-\r
---*/\r
-// GC_TODO: ] - add argument and description to function comment\r
-{\r
- UINT32 Multiplier;\r
-\r
- //\r
- // Clear the options\r
- //\r
- memset ((char *) Options, 0, sizeof (OPTIONS));\r
-\r
- //\r
- // Skip program name\r
- //\r
- Argv++;\r
- Argc--;\r
- \r
- if (Argc < 1) {\r
- Usage();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if ((strcmp(Argv[0], "-h") == 0) || (strcmp(Argv[0], "--help") == 0) ||\r
- (strcmp(Argv[0], "-?") == 0) || (strcmp(Argv[0], "/?") == 0)) {\r
- Usage();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if ((strcmp(Argv[0], "-V") == 0) || (strcmp(Argv[0], "--version") == 0)) {\r
- Version();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if (Argc < 2) {\r
- Usage ();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // If first arg is dash-option, then print usage.\r
- //\r
- if (Argv[0][0] == '-') {\r
- Usage ();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // First arg is file name\r
- //\r
- Options->OutFileName = Argv[0];\r
- Argc--;\r
- Argv++;\r
-\r
- //\r
- // Second arg is file size. Allow 0x1000, 0x100K, 1024, 1K\r
- //\r
- Multiplier = 1;\r
- if ((Argv[0][strlen (Argv[0]) - 1] == 'k') || (Argv[0][strlen (Argv[0]) - 1] == 'K')) {\r
- Multiplier = 1024;\r
- }\r
- \r
- //\r
- // Check for negtive size\r
- //\r
- if (Argv[0][0] == '-') {\r
- printf("ERROR: File size should be non-negtive.\n");\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- //\r
- // Look for 0x prefix on file size\r
- //\r
- if ((Argv[0][0] == '0') && ((Argv[0][1] == 'x') || (Argv[0][1] == 'X'))) {\r
- if (sscanf (Argv[0], "%x", &Options->FileSize) != 1) {\r
- printf ("ERROR: Invalid file size '%s'\n", Argv[0]);\r
- Usage ();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Otherwise must be a decimal number\r
- //\r
- } else {\r
- if (sscanf (Argv[0], "%d", &Options->FileSize) != 1) {\r
- printf ("ERROR: Invalid file size '%s'\n", Argv[0]);\r
- Usage ();\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
- \r
- Options->FileSize *= Multiplier;\r
- //\r
- // Assume byte value of 0xff\r
- //\r
- Options->ByteValue = (INT8) (UINT8) 0xFF;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-static\r
-void \r
-Version(\r
- void\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Print out version information for this utility.\r
-\r
-Arguments:\r
-\r
- None\r
- \r
-Returns:\r
-\r
- None\r
- \r
---*/ \r
-{\r
- printf ("%s v%d.%d -EDK utility to create a pad file containing fixed data\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
- printf ("Copyright (c) 1999-2006 Intel Corporation. All rights reserved.\n");\r
-}\r
-\r
-//\r
-// Print utility usage info\r
-//\r
-static\r
-void\r
-Usage (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{ \r
- Version();\r
- \r
- printf ("\nUsage: %s OutFileName FileSize \n\\r
- where: \n\\r
- OutFileName is the name of the output file to generate \n\\r
- FileSize is the size of the file to create \n\\r
- Examples: \n\\r
- %s OutFile.bin 32K \n\\r
- %s OutFile.bin 0x1000 \n",UTILITY_NAME, UTILITY_NAME, UTILITY_NAME);\r
-} \r
-\r