]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/CreateMtFile/CreateMtFile.c
3 Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
19 Simple utility to create a pad file containing fixed data.
27 #include <Common/UefiBaseTypes.h>
29 #define PROGRAM_NAME "CreateMtFile"
42 IN OUT OPTIONS
*Options
60 Main entry point for this utility.
64 Standard C entry point args Argc and Argv
68 EFI_SUCCESS if good to go
71 // GC_TODO: ] - add argument and description to function comment
72 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
73 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
74 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
80 // Process the command-line arguments.
82 if (ProcessArgs (Argc
, Argv
, &Options
) != EFI_SUCCESS
) {
83 return EFI_INVALID_PARAMETER
;
86 // Open the output file
88 if ((OutFptr
= fopen (Options
.OutFileName
, "wb")) == NULL
) {
91 PROGRAM_NAME
" ERROR: Could not open output file '%s' for writing\n",
94 return EFI_DEVICE_ERROR
;
97 // Write the pad bytes. Do it the slow way (one at a time) for now.
99 while (Options
.FileSize
> 0) {
100 if (fwrite (&Options
.ByteValue
, 1, 1, OutFptr
) != 1) {
102 fprintf (stdout
, PROGRAM_NAME
" ERROR: Failed to write to output file\n");
103 return EFI_DEVICE_ERROR
;
120 IN OUT OPTIONS
*Options
126 Process the command line arguments.
130 Argc - argument count as passed in to the entry point function
131 Argv - array of arguments as passed in to the entry point function
132 Options - stucture of where to put the values of the parsed arguments
136 EFI_SUCCESS if everything looks good
137 EFI_INVALID_PARAMETER otherwise
140 // GC_TODO: ] - add argument and description to function comment
147 memset ((char *) Options
, 0, sizeof (OPTIONS
));
156 return EFI_INVALID_PARAMETER
;
159 // If first arg is dash-option, then print usage.
161 if (Argv
[0][0] == '-') {
163 return EFI_INVALID_PARAMETER
;
166 // First arg is file name
168 Options
->OutFileName
= Argv
[0];
173 // Second arg is file size. Allow 0x1000, 0x100K, 1024, 1K
176 if ((Argv
[0][strlen (Argv
[0]) - 1] == 'k') || (Argv
[0][strlen (Argv
[0]) - 1] == 'K')) {
180 // Look for 0x prefix on file size
182 if ((Argv
[0][0] == '0') && ((Argv
[0][1] == 'x') || (Argv
[0][1] == 'X'))) {
183 if (sscanf (Argv
[0], "%x", &Options
->FileSize
) != 1) {
184 fprintf (stdout
, PROGRAM_NAME
" ERROR: Invalid file size '%s'\n", Argv
[0]);
186 return EFI_INVALID_PARAMETER
;
189 // Otherwise must be a decimal number
192 if (sscanf (Argv
[0], "%d", &Options
->FileSize
) != 1) {
193 fprintf (stdout
, PROGRAM_NAME
" ERROR: Invalid file size '%s'\n", Argv
[0]);
195 return EFI_INVALID_PARAMETER
;
199 Options
->FileSize
*= Multiplier
;
201 // Assume byte value of 0xff
203 Options
->ByteValue
= (INT8
) (UINT8
) 0xFF;
207 // Print utility usage info
218 GC_TODO: Add function description
226 GC_TODO: add return values
231 static const INT8
*Text
[] = {
233 "Usage: "PROGRAM_NAME
" OutFileName FileSize",
235 " OutFileName is the name of the output file to generate",
236 " FileSize is the size of the file to create",
238 " "PROGRAM_NAME
" OutFile.bin 32K",
239 " "PROGRAM_NAME
" OutFile.bin 0x1000",
244 for (Index
= 0; Text
[Index
] != NULL
; Index
++) {
245 fprintf (stdout
, "%s\n", Text
[Index
]);