]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/CreateMtFile/CreateMtFile.c
3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Simple utility to create a pad file containing fixed data.
27 #include <Common/UefiBaseTypes.h>
29 #define UTILITY_NAME "CreateMtFile"
30 #define UTILITY_MAJOR_VERSION 1
31 #define UTILITY_MINOR_VERSION 1
44 IN OUT OPTIONS
*Options
68 Main entry point for this utility.
72 Standard C entry point args Argc and Argv
76 EFI_SUCCESS if good to go
79 // GC_TODO: ] - add argument and description to function comment
80 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
81 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
82 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
88 // Process the command-line arguments.
90 if (ProcessArgs (Argc
, Argv
, &Options
) != EFI_SUCCESS
) {
91 return EFI_INVALID_PARAMETER
;
94 // Open the output file
96 if ((OutFptr
= fopen (Options
.OutFileName
, "wb")) == NULL
) {
97 printf (" ERROR: Could not open output file '%s' for writing\n", Options
.OutFileName
);
98 return EFI_DEVICE_ERROR
;
101 // Write the pad bytes. Do it the slow way (one at a time) for now.
103 while (Options
.FileSize
> 0) {
104 if (fwrite (&Options
.ByteValue
, 1, 1, OutFptr
) != 1) {
106 printf (" ERROR: Failed to write to output file\n");
107 return EFI_DEVICE_ERROR
;
124 IN OUT OPTIONS
*Options
130 Process the command line arguments.
134 Argc - argument count as passed in to the entry point function
135 Argv - array of arguments as passed in to the entry point function
136 Options - stucture of where to put the values of the parsed arguments
140 EFI_SUCCESS if everything looks good
141 EFI_INVALID_PARAMETER otherwise
144 // GC_TODO: ] - add argument and description to function comment
151 memset ((char *) Options
, 0, sizeof (OPTIONS
));
161 return EFI_INVALID_PARAMETER
;
164 if ((strcmp(Argv
[0], "-h") == 0) || (strcmp(Argv
[0], "--help") == 0) ||
165 (strcmp(Argv
[0], "-?") == 0) || (strcmp(Argv
[0], "/?") == 0)) {
167 return EFI_INVALID_PARAMETER
;
170 if ((strcmp(Argv
[0], "-V") == 0) || (strcmp(Argv
[0], "--version") == 0)) {
172 return EFI_INVALID_PARAMETER
;
177 return EFI_INVALID_PARAMETER
;
180 // If first arg is dash-option, then print usage.
182 if (Argv
[0][0] == '-') {
184 return EFI_INVALID_PARAMETER
;
187 // First arg is file name
189 Options
->OutFileName
= Argv
[0];
194 // Second arg is file size. Allow 0x1000, 0x100K, 1024, 1K
197 if ((Argv
[0][strlen (Argv
[0]) - 1] == 'k') || (Argv
[0][strlen (Argv
[0]) - 1] == 'K')) {
202 // Check for negtive size
204 if (Argv
[0][0] == '-') {
205 printf("ERROR: File size should be non-negtive.\n");
206 return EFI_INVALID_PARAMETER
;
210 // Look for 0x prefix on file size
212 if ((Argv
[0][0] == '0') && ((Argv
[0][1] == 'x') || (Argv
[0][1] == 'X'))) {
213 if (sscanf (Argv
[0], "%x", &Options
->FileSize
) != 1) {
214 printf ("ERROR: Invalid file size '%s'\n", Argv
[0]);
216 return EFI_INVALID_PARAMETER
;
219 // Otherwise must be a decimal number
222 if (sscanf (Argv
[0], "%d", &Options
->FileSize
) != 1) {
223 printf ("ERROR: Invalid file size '%s'\n", Argv
[0]);
225 return EFI_INVALID_PARAMETER
;
229 Options
->FileSize
*= Multiplier
;
231 // Assume byte value of 0xff
233 Options
->ByteValue
= (INT8
) (UINT8
) 0xFF;
247 Print out version information for Strip.
259 printf ("%s v%d.%d -EDK utility to create a pad file containing fixed data\n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
);
260 printf ("Copyright (c) 1999-2006 Intel Corporation. All rights reserved.\n");
264 // Print utility usage info
275 GC_TODO: Add function description
283 GC_TODO: add return values
289 printf ("\n Usage: %s OutFileName FileSize \n\
291 OutFileName is the name of the output file to generate \n\
292 FileSize is the size of the file to create \n\
294 %s OutFile.bin 32K \n\
295 %s OutFile.bin 0x1000 \n",UTILITY_NAME
, UTILITY_NAME
, UTILITY_NAME
);