Fix GCC build failure.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Bcfg.c
CommitLineData
5d73d92f 1/** @file\r
3737ac2b 2 Main file for bcfg shell Debug1 function.\r
5d73d92f 3\r
863986b3 4 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
5d73d92f 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellDebug1CommandsLib.h"\r
16#include <Guid/GlobalVariable.h>\r
17#include <Library/PrintLib.h>\r
18#include <Library/HandleParsingLib.h>\r
19#include <Library/DevicePathLib.h>\r
20\r
21typedef enum {\r
3737ac2b 22 BcfgTargetBootOrder = 0,\r
23 BcfgTargetDriverOrder = 1,\r
24 BcfgTargetMax = 2\r
5d73d92f 25} BCFG_OPERATION_TARGET;\r
26\r
27typedef enum {\r
3737ac2b 28 BcfgTypeDump = 0,\r
29 BcfgTypeAdd = 1,\r
30 BcfgTypeAddp = 2,\r
31 BcfgTypeAddh = 3,\r
32 BcfgTypeRm = 4,\r
33 BcfgTypeMv = 5,\r
34 BcfgTypeOpt = 6,\r
35 BcfgTypeMax = 7\r
5d73d92f 36} BCFG_OPERATION_TYPE;\r
37\r
38typedef struct {\r
39 BCFG_OPERATION_TARGET Target;\r
40 BCFG_OPERATION_TYPE Type;\r
41 UINT16 Number1;\r
42 UINT16 Number2;\r
43 UINTN HandleIndex;\r
44 CHAR16 *FileName;\r
45 CHAR16 *Description;\r
46 UINT16 *Order;\r
47 CONST CHAR16 *OptData;\r
48} BGFG_OPERATION;\r
49\r
3206b5e7
RN
50/**\r
51 Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3.\r
52\r
53 @param KeyOption Pointer to the EFI_KEY_OPTION structure. \r
54\r
55 @return Actual number of entries in EFI_KEY_OPTION.Keys.\r
56**/\r
57#define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) \\r
58 (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK))\r
59\r
cff7bffb 60/**\r
61 Update the optional data for a boot or driver option.\r
62\r
63 If optional data exists it will be changed.\r
64\r
65 @param[in] Index The boot or driver option index update.\r
66 @param[in] DataSize The size in bytes of Data.\r
67 @param[in] Data The buffer for the optioanl data.\r
68 @param[in] Target The target of the operation.\r
69\r
70 @retval EFI_SUCCESS The data was sucessfully updated.\r
71 @retval other A error occured.\r
72**/\r
73EFI_STATUS\r
74EFIAPI\r
75UpdateOptionalDataDebug1(\r
76 UINT16 Index, \r
77 UINTN DataSize, \r
78 UINT8 *Data,\r
79 IN CONST BCFG_OPERATION_TARGET Target\r
80 )\r
81{\r
82 EFI_STATUS Status;\r
83 CHAR16 VariableName[12];\r
84 UINTN OriginalSize;\r
85 UINT8 *OriginalData;\r
86 UINTN NewSize;\r
87 UINT8 *NewData;\r
88 UINTN OriginalOptionDataSize;\r
89\r
90 UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", Index);\r
91 \r
92 OriginalSize = 0;\r
93 OriginalData = NULL;\r
94 NewData = NULL;\r
95 NewSize = 0;\r
96\r
97 Status = gRT->GetVariable(\r
98 VariableName,\r
99 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
100 NULL,\r
101 &OriginalSize,\r
102 OriginalData);\r
103 if (Status == EFI_BUFFER_TOO_SMALL) {\r
104 OriginalData = AllocateZeroPool(OriginalSize);\r
105 if (OriginalData == NULL) {\r
106 return (EFI_OUT_OF_RESOURCES);\r
107 }\r
108 Status = gRT->GetVariable(\r
109 VariableName,\r
110 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
111 NULL,\r
112 &OriginalSize,\r
113 OriginalData);\r
114 }\r
115\r
116 if (!EFI_ERROR(Status)) {\r
117 //\r
118 // Allocate new struct and discard old optional data.\r
119 //\r
8d300003 120 ASSERT (OriginalData != NULL);\r
cff7bffb 121 OriginalOptionDataSize = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16))));\r
122 OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32)));\r
123 OriginalOptionDataSize -= OriginalSize;\r
124 NewSize = OriginalSize - OriginalOptionDataSize + DataSize;\r
125 NewData = AllocateCopyPool(NewSize, OriginalData);\r
126 if (NewData == NULL) {\r
127 Status = EFI_OUT_OF_RESOURCES;\r
128 } else {\r
129 CopyMem(NewData + OriginalSize - OriginalOptionDataSize, Data, DataSize);\r
130 }\r
131 }\r
132\r
133 if (!EFI_ERROR(Status)) {\r
134 //\r
135 // put the data back under the variable\r
136 //\r
137 Status = gRT->SetVariable(\r
138 VariableName, \r
139 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
140 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
141 NewSize,\r
142 NewData);\r
143 }\r
144\r
145 SHELL_FREE_NON_NULL(OriginalData);\r
146 SHELL_FREE_NON_NULL(NewData);\r
147 return (Status);\r
148}\r
149\r
150/**\r
151 This function will get a CRC for a boot option.\r
152\r
8d300003
ED
153 @param[in, out] Crc The CRC value to return.\r
154 @param[in] BootIndex The boot option index to CRC.\r
cff7bffb 155\r
156 @retval EFI_SUCCESS The CRC was sucessfully returned.\r
157 @retval other A error occured.\r
158**/\r
159EFI_STATUS\r
160EFIAPI\r
161GetBootOptionCrcDebug1(\r
162 UINT32 *Crc, \r
163 UINT16 BootIndex\r
164 )\r
165{\r
166 CHAR16 VariableName[12];\r
167 EFI_STATUS Status;\r
168 UINT8 *Buffer;\r
169 UINTN BufferSize;\r
170\r
171 Buffer = NULL;\r
172 BufferSize = 0;\r
173\r
174 //\r
175 // Get the data Buffer\r
176 //\r
177 UnicodeSPrint(VariableName, sizeof(VariableName), L"%Boot%04x", BootIndex);\r
178 Status = gRT->GetVariable(\r
179 VariableName,\r
180 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
181 NULL,\r
182 &BufferSize,\r
183 NULL);\r
184 if (Status == EFI_BUFFER_TOO_SMALL) {\r
185 Buffer = AllocateZeroPool(BufferSize);\r
186 Status = gRT->GetVariable(\r
187 VariableName,\r
188 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
189 NULL,\r
190 &BufferSize,\r
191 Buffer);\r
192 }\r
193\r
194 //\r
195 // Get the CRC computed\r
196 //\r
197 if (!EFI_ERROR(Status)) {\r
198 Status = gBS->CalculateCrc32 (Buffer, BufferSize, Crc);\r
199 }\r
200\r
201 SHELL_FREE_NON_NULL(Buffer);\r
202 return EFI_SUCCESS;\r
203}\r
204\r
6878e7a7 205/**\r
206 This function will populate the device path protocol parameter based on TheHandle.\r
4ff7e37b
ED
207\r
208 @param[in] TheHandle Driver handle.\r
209 @param[in, out] FilePath On a sucessful return the device path to the handle.\r
6878e7a7 210\r
211 @retval EFI_SUCCESS The device path was sucessfully returned.\r
212 @retval other A error from gBS->HandleProtocol.\r
213\r
214 @sa HandleProtocol\r
215**/\r
216EFI_STATUS\r
217EFIAPI\r
218GetDevicePathForDriverHandleDebug1 (\r
219 IN EFI_HANDLE TheHandle,\r
220 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
221 )\r
222{\r
223 EFI_STATUS Status;\r
224 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
225 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r
226\r
227 Status = gBS->OpenProtocol (\r
228 TheHandle,\r
229 &gEfiLoadedImageProtocolGuid,\r
230 (VOID**)&LoadedImage,\r
231 gImageHandle,\r
232 NULL,\r
233 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
234 );\r
235 if (!EFI_ERROR (Status)) {\r
236 Status = gBS->OpenProtocol (\r
237 LoadedImage->DeviceHandle,\r
238 &gEfiDevicePathProtocolGuid,\r
239 (VOID**)&ImageDevicePath,\r
240 gImageHandle,\r
241 NULL,\r
242 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
243 );\r
244 if (!EFI_ERROR (Status)) {\r
245// *DevPath = DuplicateDevicePath (ImageDevicePath);\r
246// *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r
247 *FilePath = AppendDevicePath(ImageDevicePath,LoadedImage->FilePath);\r
248 gBS->CloseProtocol(\r
249 LoadedImage->DeviceHandle,\r
250 &gEfiDevicePathProtocolGuid,\r
251 gImageHandle,\r
252 NULL);\r
253 }\r
254 gBS->CloseProtocol(\r
255 TheHandle,\r
256 &gEfiLoadedImageProtocolGuid,\r
257 gImageHandle,\r
258 NULL);\r
259 }\r
260 return (Status);\r
261}\r
262\r
3737ac2b 263/**\r
264 Function to add a option.\r
265\r
266 @param[in] Position The position to add Target at.\r
267 @param[in] File The file to make the target.\r
268 @param[in] Desc The description text.\r
269 @param[in] CurrentOrder The pointer to the current order of items.\r
270 @param[in] OrderCount The number if items in CurrentOrder.\r
271 @param[in] Target The info on the option to add.\r
272 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.\r
273 @param[in] UsePath TRUE to convert to devicepath.\r
274 @param[in] HandleNumber The handle number to add.\r
275\r
276 @retval SHELL_SUCCESS The operation was successful.\r
277 @retval SHELL_INVALID_PARAMETER A parameter was invalid.\r
278**/\r
5d73d92f 279SHELL_STATUS\r
280EFIAPI\r
3737ac2b 281BcfgAddDebug1(\r
5d73d92f 282 IN UINTN Position,\r
283 IN CONST CHAR16 *File,\r
284 IN CONST CHAR16 *Desc,\r
285 IN CONST UINT16 *CurrentOrder,\r
286 IN CONST UINTN OrderCount,\r
287 IN CONST BCFG_OPERATION_TARGET Target,\r
288 IN CONST BOOLEAN UseHandle,\r
289 IN CONST BOOLEAN UsePath,\r
290 IN CONST UINTN HandleNumber\r
291 )\r
292{\r
293 EFI_STATUS Status;\r
3737ac2b 294 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
295 EFI_DEVICE_PATH_PROTOCOL *FilePath;\r
e755a4ca 296 /* EFI_DEVICE_PATH_PROTOCOL *FileNode; */\r
5d73d92f 297 CHAR16 *Str;\r
3737ac2b 298 UINT8 *TempByteBuffer;\r
299 UINT8 *TempByteStart;\r
5d73d92f 300 EFI_SHELL_FILE_INFO *Arg;\r
301 EFI_SHELL_FILE_INFO *FileList;\r
302 CHAR16 OptionStr[40];\r
303 UINTN DescSize, FilePathSize;\r
304 BOOLEAN Found;\r
305 UINTN TargetLocation;\r
306 UINTN Index;\r
307 EFI_HANDLE *Handles;\r
308 EFI_HANDLE CurHandle;\r
309 UINTN DriverBindingHandleCount;\r
310 UINTN ParentControllerHandleCount;\r
311 UINTN ChildControllerHandleCount;\r
312 SHELL_STATUS ShellStatus;\r
313 UINT16 *NewOrder;\r
314\r
315 if (!UseHandle) {\r
3737ac2b 316 if (File == NULL || Desc == NULL) {\r
317 return (SHELL_INVALID_PARAMETER);\r
318 }\r
5d73d92f 319 } else {\r
3737ac2b 320 if (HandleNumber == 0) {\r
321 return (SHELL_INVALID_PARAMETER);\r
322 }\r
5d73d92f 323 }\r
324\r
3737ac2b 325 if (Position > OrderCount) {\r
326 Position = OrderCount;\r
327 }\r
5d73d92f 328\r
329 Str = NULL;\r
330 FilePath = NULL;\r
e755a4ca 331 /* FileNode = NULL; */\r
5d73d92f 332 FileList = NULL;\r
333 Handles = NULL;\r
334 ShellStatus = SHELL_SUCCESS;\r
335 TargetLocation = 0xFFFF;\r
336\r
5d73d92f 337 if (UseHandle) {\r
6878e7a7 338 CurHandle = ConvertHandleIndexToHandle(HandleNumber);\r
339 if (CurHandle == NULL) {\r
340 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Handle Number");\r
5d73d92f 341 ShellStatus = SHELL_INVALID_PARAMETER;\r
342 } else {\r
6878e7a7 343 if (Target == BcfgTargetBootOrder) {\r
344 //\r
345 //Make sure that the handle should point to a real controller\r
346 //\r
347 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (\r
348 CurHandle,\r
349 &DriverBindingHandleCount,\r
350 NULL);\r
351\r
352 Status = PARSE_HANDLE_DATABASE_PARENTS (\r
353 CurHandle,\r
354 &ParentControllerHandleCount,\r
355 NULL);\r
356\r
357 Status = ParseHandleDatabaseForChildControllers (\r
358 CurHandle,\r
359 &ChildControllerHandleCount,\r
360 NULL);\r
361\r
362 if (DriverBindingHandleCount > 0\r
363 || ParentControllerHandleCount > 0\r
364 || ChildControllerHandleCount > 0) {\r
365 FilePath = NULL;\r
366 Status = gBS->HandleProtocol (\r
367 CurHandle,\r
368 &gEfiDevicePathProtocolGuid,\r
369 (VOID**)&FilePath);\r
370 }\r
371 if (EFI_ERROR (Status)) {\r
372 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellDebug1HiiHandle, HandleNumber);\r
373 ShellStatus = SHELL_INVALID_PARAMETER;\r
374 }\r
375 } else {\r
376 //\r
377 //Make sure that the handle should point to driver, not a controller.\r
378 //\r
379 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (\r
380 CurHandle,\r
381 &DriverBindingHandleCount,\r
382 NULL);\r
383\r
384 Status = PARSE_HANDLE_DATABASE_PARENTS (\r
385 CurHandle,\r
386 &ParentControllerHandleCount,\r
387 NULL);\r
388\r
389 Status = ParseHandleDatabaseForChildControllers (\r
390 CurHandle,\r
391 &ChildControllerHandleCount,\r
392 NULL);\r
393\r
5d73d92f 394 Status = gBS->HandleProtocol (\r
395 CurHandle,\r
396 &gEfiDevicePathProtocolGuid,\r
397 (VOID**)&FilePath);\r
6878e7a7 398\r
399 if (DriverBindingHandleCount > 0\r
400 || ParentControllerHandleCount > 0\r
401 || ChildControllerHandleCount > 0\r
402 || !EFI_ERROR(Status) ) {\r
403 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Handle Number");\r
404 ShellStatus = SHELL_INVALID_PARAMETER;\r
405 } else {\r
406 //\r
407 // Get the DevicePath from the loaded image information.\r
408 //\r
409 Status = GetDevicePathForDriverHandleDebug1(CurHandle, &FilePath);\r
410 }\r
5d73d92f 411 }\r
412 }\r
413 } else {\r
414 //\r
415 // Get file info\r
416 //\r
417 ShellOpenFileMetaArg ((CHAR16*)File, EFI_FILE_MODE_READ, &FileList);\r
418\r
3737ac2b 419 if (FileList == NULL) {\r
420 //\r
421 // If filename matched nothing fail\r
422 //\r
423 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);\r
424 ShellStatus = SHELL_INVALID_PARAMETER;\r
425 } else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {\r
426 //\r
427 // If filename expanded to multiple names, fail\r
428 //\r
5d73d92f 429 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE), gShellDebug1HiiHandle, File);\r
430 ShellStatus = SHELL_INVALID_PARAMETER;\r
431 } else {\r
432 Arg = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link);\r
433 if (EFI_ERROR(Arg->Status)) {\r
434 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN), gShellDebug1HiiHandle, File, Arg->Status);\r
435 ShellStatus = SHELL_INVALID_PARAMETER;\r
436 } else {\r
437 //\r
438 // Build FilePath to the filename\r
439 //\r
440\r
441 //\r
442 // get the device path\r
443 //\r
366f81a0 444 DevicePath = gEfiShellProtocol->GetDevicePathFromFilePath(Arg->FullName);\r
3737ac2b 445 if (DevicePath == NULL) {\r
5d73d92f 446 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellDebug1HiiHandle, Arg->FullName);\r
447 ShellStatus = SHELL_UNSUPPORTED;\r
448 } else {\r
6878e7a7 449/*\r
5d73d92f 450 if (UsePath) {\r
451 DevPath = DevicePath;\r
452 while (!IsDevicePathEnd(DevPath)) {\r
453 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&\r
454 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {\r
455\r
456 //\r
457 // If we find it use it instead\r
458 //\r
459 DevicePath = DevPath;\r
460 break;\r
461 }\r
462 DevPath = NextDevicePathNode(DevPath);\r
463 }\r
464 //\r
465 // append the file\r
466 //\r
3737ac2b 467 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);\r
468 FileNode = FileDevicePath(NULL, StringWalker+1);\r
5d73d92f 469 FilePath = AppendDevicePath(DevicePath, FileNode);\r
470 FreePool(FileNode);\r
471 } else {\r
6878e7a7 472*/\r
5d73d92f 473 FilePath = DuplicateDevicePath(DevicePath);\r
6878e7a7 474/*\r
5d73d92f 475 }\r
6878e7a7 476*/\r
5d73d92f 477 FreePool(DevicePath);\r
478 }\r
479 }\r
480 }\r
481 }\r
482\r
483\r
484 if (ShellStatus == SHELL_SUCCESS) {\r
485 //\r
486 // Find a free target ,a brute force implementation\r
487 //\r
488 Found = FALSE;\r
3737ac2b 489 for (TargetLocation=0; TargetLocation < 0xFFFF; TargetLocation++) {\r
5d73d92f 490 Found = TRUE;\r
491 for (Index=0; Index < OrderCount; Index++) {\r
492 if (CurrentOrder[Index] == TargetLocation) {\r
493 Found = FALSE;\r
494 break;\r
495 }\r
496 }\r
497\r
498 if (Found) {\r
499 break;\r
500 }\r
501 }\r
502\r
503 if (TargetLocation == 0xFFFF) {\r
504 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_TARGET_NF), gShellDebug1HiiHandle);\r
505 } else {\r
506 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_TARGET), gShellDebug1HiiHandle, TargetLocation);\r
507 }\r
508 }\r
509\r
510 if (ShellStatus == SHELL_SUCCESS) {\r
511 //\r
512 // Add the option\r
513 //\r
514 DescSize = StrSize(Desc);\r
515 FilePathSize = GetDevicePathSize (FilePath);\r
516\r
3737ac2b 517 TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);\r
33c031ee 518 if (TempByteBuffer != NULL) {\r
519 TempByteStart = TempByteBuffer;\r
520 *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE; // Attributes\r
521 TempByteBuffer += sizeof (UINT32);\r
5d73d92f 522\r
33c031ee 523 *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize; // FilePathListLength\r
524 TempByteBuffer += sizeof (UINT16);\r
5d73d92f 525\r
33c031ee 526 CopyMem (TempByteBuffer, Desc, DescSize);\r
527 TempByteBuffer += DescSize;\r
e3df6949 528 ASSERT (FilePath != NULL);\r
33c031ee 529 CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
5d73d92f 530\r
33c031ee 531 UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
532 Status = gRT->SetVariable (\r
533 OptionStr,\r
534 &gEfiGlobalVariableGuid,\r
535 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
536 sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
537 TempByteStart\r
538 );\r
539\r
540 FreePool(TempByteStart);\r
541 } else {\r
542 Status = EFI_OUT_OF_RESOURCES;\r
543 }\r
5d73d92f 544\r
545 if (EFI_ERROR(Status)) {\r
546 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, OptionStr, Status);\r
547 } else {\r
3737ac2b 548 NewOrder = AllocateZeroPool((OrderCount+1)*sizeof(NewOrder[0]));\r
5d73d92f 549 ASSERT(NewOrder != NULL);\r
550 CopyMem(NewOrder, CurrentOrder, (OrderCount)*sizeof(NewOrder[0]));\r
551\r
552 //\r
553 // Insert target into order list\r
554 //\r
555 for (Index=OrderCount; Index > Position; Index--) {\r
556 NewOrder[Index] = NewOrder[Index-1];\r
557 }\r
558\r
559 NewOrder[Position] = (UINT16) TargetLocation;\r
560 Status = gRT->SetVariable (\r
3737ac2b 561 Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder",\r
5d73d92f 562 &gEfiGlobalVariableGuid,\r
563 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
564 (OrderCount+1) * sizeof(UINT16),\r
565 NewOrder\r
566 );\r
567\r
568 FreePool(NewOrder);\r
569\r
570 if (EFI_ERROR(Status)) {\r
3737ac2b 571 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder", Status);\r
5d73d92f 572 ShellStatus = SHELL_INVALID_PARAMETER;\r
573 } else {\r
574 Print (L"bcfg: Add %s as %x\n", OptionStr, Position);\r
575 }\r
576 }\r
577 }\r
5d73d92f 578\r
579//\r
580//If always Free FilePath, will free devicepath in system when use "addh"\r
581//\r
5d73d92f 582 if (FilePath!=NULL && !UseHandle) {\r
583 FreePool (FilePath);\r
584 }\r
585\r
586 if (Str != NULL) {\r
587 FreePool(Str);\r
588 }\r
589\r
590 if (Handles != NULL) {\r
591 FreePool (Handles);\r
592 }\r
593\r
594 if (FileList != NULL) {\r
595 ShellCloseFileMetaArg (&FileList);\r
596 }\r
597\r
598 return (ShellStatus);\r
599}\r
600\r
3737ac2b 601/**\r
602 Funciton to remove an item.\r
603\r
604 @param[in] Target The target item to move.\r
605 @param[in] CurrentOrder The pointer to the current order of items.\r
606 @param[in] OrderCount The number if items in CurrentOrder.\r
607 @param[in] Location The current location of the Target.\r
608\r
609 @retval SHELL_SUCCESS The operation was successful.\r
610 @retval SHELL_INVALID_PARAMETER A parameter was invalid.\r
611**/\r
5d73d92f 612SHELL_STATUS\r
613EFIAPI\r
3737ac2b 614BcfgRemoveDebug1(\r
5d73d92f 615 IN CONST BCFG_OPERATION_TARGET Target,\r
616 IN CONST UINT16 *CurrentOrder,\r
617 IN CONST UINTN OrderCount,\r
6878e7a7 618 IN CONST UINT16 Location\r
5d73d92f 619 )\r
620{\r
621 CHAR16 VariableName[12];\r
622 UINT16 *NewOrder;\r
623 EFI_STATUS Status;\r
5d73d92f 624 UINTN NewCount;\r
625\r
6878e7a7 626 UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", CurrentOrder[Location]);\r
5d73d92f 627 Status = gRT->SetVariable(\r
628 VariableName,\r
629 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
630 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
631 0,\r
632 NULL);\r
633 if (EFI_ERROR(Status)) {\r
634 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, VariableName, Status);\r
635 return (SHELL_INVALID_PARAMETER);\r
636 }\r
3737ac2b 637 NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
33c031ee 638 if (NewOrder != NULL) {\r
639 NewCount = OrderCount;\r
640 CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
6878e7a7 641 CopyMem(NewOrder+Location, NewOrder+Location+1, (OrderCount - Location - 1)*sizeof(CurrentOrder[0]));\r
642 NewCount--;\r
643\r
33c031ee 644 Status = gRT->SetVariable(\r
645 Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
646 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
647 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
648 NewCount*sizeof(NewOrder[0]),\r
649 NewOrder);\r
650 FreePool(NewOrder);\r
651 } else {\r
652 Status = EFI_OUT_OF_RESOURCES;\r
5d73d92f 653 }\r
5d73d92f 654 if (EFI_ERROR(Status)) {\r
3737ac2b 655 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
5d73d92f 656 return (SHELL_INVALID_PARAMETER);\r
657 }\r
658 return (SHELL_SUCCESS);\r
659}\r
660\r
3737ac2b 661/**\r
662 Funciton to move a item to another location.\r
663\r
664 @param[in] Target The target item to move.\r
665 @param[in] CurrentOrder The pointer to the current order of items.\r
666 @param[in] OrderCount The number if items in CurrentOrder.\r
667 @param[in] OldLocation The current location of the Target.\r
668 @param[in] NewLocation The desired location of the Target.\r
669\r
670 @retval SHELL_SUCCESS The operation was successful.\r
671 @retval SHELL_INVALID_PARAMETER A parameter was invalid.\r
672**/\r
5d73d92f 673SHELL_STATUS\r
674EFIAPI\r
3737ac2b 675BcfgMoveDebug1(\r
5d73d92f 676 IN CONST BCFG_OPERATION_TARGET Target,\r
677 IN CONST UINT16 *CurrentOrder,\r
678 IN CONST UINTN OrderCount,\r
679 IN CONST UINT16 OldLocation,\r
680 IN CONST UINT16 NewLocation\r
681 )\r
682{\r
683 UINT16 *NewOrder;\r
684 EFI_STATUS Status;\r
685 UINT16 Temp;\r
686\r
3737ac2b 687 NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
5d73d92f 688 ASSERT(NewOrder != NULL);\r
689\r
690 Temp = CurrentOrder[OldLocation];\r
691 CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
692 CopyMem(NewOrder+OldLocation, NewOrder+OldLocation+1, (OrderCount - OldLocation - 1)*sizeof(CurrentOrder[0]));\r
693 CopyMem(NewOrder+NewLocation+1, NewOrder+NewLocation, (OrderCount - NewLocation - 1)*sizeof(CurrentOrder[0]));\r
694 NewOrder[NewLocation] = Temp;\r
695\r
696\r
697 Status = gRT->SetVariable(\r
3737ac2b 698 Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
5d73d92f 699 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
700 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
701 OrderCount*sizeof(CurrentOrder[0]),\r
702 NewOrder);\r
703\r
704 FreePool(NewOrder);\r
705\r
706 if (EFI_ERROR(Status)) {\r
3737ac2b 707 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
5d73d92f 708 return (SHELL_INVALID_PARAMETER);\r
709 }\r
710 return (SHELL_SUCCESS);\r
711}\r
712\r
f2ad804f 713/**\r
714 Function to add optional data to an option.\r
715\r
716 @param[in] OptData The optional data to add.\r
cff7bffb 717 @param[in] CurrentOrder The pointer to the current order of items.\r
718 @param[in] OrderCount The number if items in CurrentOrder.\r
f2ad804f 719 @param[in] Target The target of the operation.\r
720\r
721 @retval SHELL_SUCCESS The operation was succesful.\r
722**/\r
5d73d92f 723SHELL_STATUS\r
724EFIAPI\r
3737ac2b 725BcfgAddOptDebug1(\r
726 IN CONST CHAR16 *OptData,\r
cff7bffb 727 IN CONST UINT16 *CurrentOrder,\r
728 IN CONST UINTN OrderCount,\r
3737ac2b 729 IN CONST BCFG_OPERATION_TARGET Target\r
730 )\r
731{\r
cff7bffb 732 EFI_KEY_OPTION NewKeyOption;\r
733 EFI_KEY_OPTION *KeyOptionBuffer;\r
734 SHELL_STATUS ShellStatus;\r
735 EFI_STATUS Status;\r
736 UINT16 OptionIndex;\r
737 UINT16 LoopCounter;\r
738 UINT64 Intermediate;\r
739 CONST CHAR16 *Temp;\r
740 CONST CHAR16 *Walker;\r
741 CHAR16 *FileName;\r
742 CHAR16 *Temp2;\r
743 CHAR16 *Data;\r
744 UINT16 KeyIndex;\r
745 CHAR16 VariableName[12];\r
746\r
747 SHELL_FILE_HANDLE FileHandle;\r
748\r
749 Status = EFI_SUCCESS;\r
750 ShellStatus = SHELL_SUCCESS;\r
751 Walker = OptData;\r
752 FileName = NULL;\r
753 Data = NULL;\r
754 KeyOptionBuffer = NULL;\r
755\r
756 ZeroMem(&NewKeyOption, sizeof(EFI_KEY_OPTION));\r
757\r
758 while(Walker[0] == L' ') {\r
759 Walker++;\r
760 }\r
761\r
762 //\r
763 // Get the index of the variable we are changing.\r
764 //\r
765 Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE);\r
766 if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL || ((UINT16)Intermediate) > ((UINT16)OrderCount)) {\r
767 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Option Index");\r
768 ShellStatus = SHELL_INVALID_PARAMETER;\r
769 return (ShellStatus);\r
770 }\r
771 OptionIndex = (UINT16)Intermediate;\r
772\r
773 Temp = StrStr(Walker, L" ");\r
774 if (Temp != NULL) {\r
775 Walker = Temp;\r
776 }\r
777 while(Walker[0] == L' ') {\r
778 Walker++;\r
779 }\r
780\r
781 //\r
782 // determine whether we have file with data, quote delimited information, or a hot-key \r
783 //\r
784 if (Walker[0] == L'\"') {\r
785 //\r
786 // quoted filename or quoted information.\r
787 //\r
788 Temp = StrStr(Walker+1, L"\"");\r
789 if (Temp == NULL || StrLen(Temp) != 1) {\r
790 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker);\r
791 ShellStatus = SHELL_INVALID_PARAMETER;\r
792 } else {\r
793 FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0);\r
8d300003
ED
794 if (FileName == NULL) {\r
795 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
796 ShellStatus = SHELL_OUT_OF_RESOURCES;\r
797 return (ShellStatus);\r
798 }\r
cff7bffb 799 Temp2 = StrStr(FileName, L"\"");\r
800 ASSERT(Temp2 != NULL);\r
801 Temp2[0] = CHAR_NULL;\r
802 Temp2++;\r
803 if (StrLen(Temp2)>0) {\r
804 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker);\r
805 ShellStatus = SHELL_INVALID_PARAMETER;\r
806 }\r
807 if (EFI_ERROR(ShellFileExists(Walker))) {\r
808 //\r
809 // Not a file. must be misc information.\r
810 //\r
811 Data = FileName;\r
812 FileName = NULL;\r
813 } else {\r
814 FileName = StrnCatGrow(&FileName, NULL, Walker, 0);\r
815 }\r
816 }\r
817 } else {\r
818 //\r
819 // filename or hot key information.\r
820 //\r
821 if (StrStr(Walker, L" ") == NULL) {\r
822 //\r
823 // filename\r
824 //\r
825 if (EFI_ERROR(ShellFileExists(Walker))) {\r
826 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDebug1HiiHandle, Walker);\r
827 ShellStatus = SHELL_INVALID_PARAMETER;\r
828 } else {\r
829 FileName = StrnCatGrow(&FileName, NULL, Walker, 0);\r
830 }\r
831 } else {\r
832 if (Target != BcfgTargetBootOrder) {\r
833 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_BOOT_ONLY), gShellDebug1HiiHandle);\r
834 ShellStatus = SHELL_INVALID_PARAMETER;\r
835 }\r
836\r
837 if (ShellStatus == SHELL_SUCCESS) {\r
838 //\r
839 // Get hot key information\r
840 //\r
841 Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE);\r
842 if (EFI_ERROR(Status) || (((UINT32)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL) {\r
843 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker);\r
844 ShellStatus = SHELL_INVALID_PARAMETER;\r
845 }\r
3206b5e7 846 NewKeyOption.KeyData = (UINT32)Intermediate;\r
cff7bffb 847 Temp = StrStr(Walker, L" ");\r
848 if (Temp != NULL) {\r
849 Walker = Temp;\r
850 }\r
851 while(Walker[0] == L' ') {\r
852 Walker++;\r
853 }\r
854 }\r
855\r
856 if (ShellStatus == SHELL_SUCCESS) {\r
857 //\r
858 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct. \r
859 // Re-allocate with the added information.\r
860 //\r
3206b5e7 861 KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)), &NewKeyOption);\r
cff7bffb 862 if (KeyOptionBuffer == NULL) {\r
863 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle);\r
864 ShellStatus = SHELL_OUT_OF_RESOURCES;\r
865 }\r
866 }\r
3206b5e7 867 for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption); LoopCounter++) {\r
cff7bffb 868 //\r
869 // ScanCode\r
870 //\r
871 Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE);\r
872 if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate) || StrStr(Walker, L" ") == NULL) {\r
873 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker);\r
874 ShellStatus = SHELL_INVALID_PARAMETER;\r
875 }\r
876 ((EFI_INPUT_KEY*)(((UINT8*)KeyOptionBuffer) + sizeof(EFI_KEY_OPTION)))[LoopCounter].ScanCode = (UINT16)Intermediate;\r
877 Temp = StrStr(Walker, L" ");\r
878 if (Temp != NULL) {\r
879 Walker = Temp;\r
880 }\r
881 while(Walker[0] == L' ') {\r
882 Walker++;\r
883 }\r
884\r
885 //\r
886 // UnicodeChar\r
887 //\r
888 Status = ShellConvertStringToUint64(Walker, &Intermediate, FALSE, TRUE);\r
889 if (EFI_ERROR(Status) || (((UINT16)Intermediate) != Intermediate)) {\r
890 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker);\r
891 ShellStatus = SHELL_INVALID_PARAMETER;\r
892 }\r
893 ((EFI_INPUT_KEY*)(((UINT8*)KeyOptionBuffer) + sizeof(EFI_KEY_OPTION)))[LoopCounter].UnicodeChar = (UINT16)Intermediate;\r
894 Temp = StrStr(Walker, L" ");\r
895 if (Temp != NULL) {\r
896 Walker = Temp;\r
897 }\r
898 while(Walker[0] == L' ') {\r
899 Walker++;\r
900 }\r
901 }\r
902\r
903 if (ShellStatus == SHELL_SUCCESS) {\r
904 //\r
905 // Now do the BootOption / BootOptionCrc\r
906 //\r
907 ASSERT (OptionIndex <= OrderCount);\r
908 KeyOptionBuffer->BootOption = CurrentOrder[OptionIndex];\r
909 Status = GetBootOptionCrcDebug1(&(KeyOptionBuffer->BootOptionCrc), KeyOptionBuffer->BootOption);\r
910 if (EFI_ERROR(Status)) {\r
911 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"Option Index");\r
912 ShellStatus = SHELL_INVALID_PARAMETER;\r
913 } \r
914 }\r
915\r
916 if (ShellStatus == SHELL_SUCCESS) {\r
917 for (Temp2 = NULL, KeyIndex = 0 ; KeyIndex < 0xFFFF ; KeyIndex++) {\r
918 UnicodeSPrint(VariableName, sizeof(VariableName), L"Key%04x", KeyIndex);\r
919 Status = gRT->GetVariable(\r
920 VariableName,\r
921 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
922 NULL,\r
923 (UINTN*)&Intermediate,\r
924 NULL);\r
925 if (Status == EFI_NOT_FOUND) {\r
926 break;\r
927 }\r
928 }\r
929 Status = gRT->SetVariable(\r
930 VariableName,\r
931 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
932 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
3206b5e7 933 sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)),\r
cff7bffb 934 KeyOptionBuffer);\r
935 if (EFI_ERROR(Status)) {\r
936 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status);\r
937 ShellStatus = SHELL_INVALID_PARAMETER;\r
938 } \r
939 ASSERT(FileName == NULL && Data == NULL);\r
940 }\r
941 }\r
942 }\r
943\r
944 //\r
945 // Shouldn't be possible to have have both. Neither is ok though.\r
946 //\r
947 ASSERT(FileName == NULL || Data == NULL);\r
948\r
479f85bb 949 if (ShellStatus == SHELL_SUCCESS && (FileName != NULL || Data != NULL)) {\r
cff7bffb 950 if (FileName != NULL) {\r
951 //\r
952 // Open the file and populate the data buffer.\r
953 //\r
50b43b15 954 Status = ShellOpenFileByName(\r
cff7bffb 955 FileName,\r
956 &FileHandle,\r
957 EFI_FILE_MODE_READ,\r
958 0);\r
50b43b15 959 if (!EFI_ERROR(Status)) {\r
960 Status = ShellGetFileSize(FileHandle, &Intermediate);\r
cff7bffb 961 }\r
962 Data = AllocateZeroPool((UINTN)Intermediate);\r
963 if (Data == NULL) {\r
964 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle);\r
965 ShellStatus = SHELL_OUT_OF_RESOURCES;\r
966 }\r
50b43b15 967 if (!EFI_ERROR(Status)) {\r
968 Status = ShellReadFile(FileHandle, (UINTN *)&Intermediate, Data);\r
cff7bffb 969 }\r
970 } else {\r
971 Intermediate = StrSize(Data);\r
972 }\r
973\r
50b43b15 974 if (!EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS && Data != NULL) {\r
cff7bffb 975 Status = UpdateOptionalDataDebug1(CurrentOrder[OptionIndex], (UINTN)Intermediate, (UINT8*)Data, Target);\r
976 if (EFI_ERROR(Status)) {\r
977 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status);\r
978 ShellStatus = SHELL_INVALID_PARAMETER;\r
979 } \r
980 }\r
50b43b15 981 if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {\r
982 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status);\r
983 ShellStatus = SHELL_INVALID_PARAMETER;\r
984 } \r
cff7bffb 985 }\r
986\r
987 SHELL_FREE_NON_NULL(Data);\r
988 SHELL_FREE_NON_NULL(KeyOptionBuffer);\r
989 SHELL_FREE_NON_NULL(FileName);\r
990 return ShellStatus;\r
3737ac2b 991}\r
992\r
993/**\r
994 Function to dump the Bcfg information.\r
995\r
996 @param[in] Op The operation.\r
997 @param[in] OrderCount How many to dump.\r
998 @param[in] CurrentOrder The pointer to the current order of items.\r
999 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.\r
1000\r
1001 @retval SHELL_SUCCESS The dump was successful.\r
1002 @retval SHELL_INVALID_PARAMETER A parameter was invalid.\r
1003**/\r
1004SHELL_STATUS\r
1005EFIAPI\r
1006BcfgDisplayDumpDebug1(\r
5d73d92f 1007 IN CONST CHAR16 *Op,\r
3737ac2b 1008 IN CONST UINTN OrderCount,\r
1009 IN CONST UINT16 *CurrentOrder,\r
5d73d92f 1010 IN CONST BOOLEAN VerboseOutput\r
1011 )\r
1012{\r
1013 EFI_STATUS Status;\r
1014 UINT8 *Buffer;\r
1015 UINTN BufferSize;\r
1016 CHAR16 VariableName[12];\r
1017 UINTN LoopVar;\r
1018 UINTN LoopVar2;\r
1019 CHAR16 *DevPathString;\r
1020 VOID *DevPath;\r
1021\r
3737ac2b 1022 if (OrderCount == 0) {\r
1023 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellDebug1HiiHandle);\r
1024 return (SHELL_SUCCESS);\r
1025 }\r
1026\r
5d73d92f 1027 for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) {\r
1028 Buffer = NULL;\r
1029 BufferSize = 0;\r
3737ac2b 1030 UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, CurrentOrder[LoopVar]);\r
5d73d92f 1031\r
1032 Status = gRT->GetVariable(\r
1033 VariableName,\r
1034 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
1035 NULL,\r
1036 &BufferSize,\r
1037 Buffer);\r
1038 if (Status == EFI_BUFFER_TOO_SMALL) {\r
3737ac2b 1039 Buffer = AllocateZeroPool(BufferSize);\r
5d73d92f 1040 Status = gRT->GetVariable(\r
1041 VariableName,\r
1042 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
1043 NULL,\r
1044 &BufferSize,\r
1045 Buffer);\r
1046 }\r
1047\r
1048 if (EFI_ERROR(Status) || Buffer == NULL) {\r
1049 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_READ_FAIL), gShellDebug1HiiHandle, VariableName, Status);\r
1050 return (SHELL_INVALID_PARAMETER);\r
1051 }\r
1052\r
6878e7a7 1053 if ((*(UINT16*)(Buffer+4)) != 0) {\r
1054 DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
1055 CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
863986b3 1056 DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
6878e7a7 1057 } else {\r
1058 DevPath = NULL;\r
1059 DevPathString = NULL;\r
1060 }\r
5d73d92f 1061 ShellPrintHiiEx(\r
1062 -1,\r
1063 -1,\r
1064 NULL,\r
1065 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS),\r
1066 gShellDebug1HiiHandle,\r
3737ac2b 1067 LoopVar,\r
5d73d92f 1068 VariableName,\r
1069 (CHAR16*)(Buffer+6),\r
1070 DevPathString,\r
1071 (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6) <= BufferSize?L'N':L'Y');\r
1072 if (VerboseOutput) {\r
1073 for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6);LoopVar2<BufferSize;LoopVar2++){\r
1074 ShellPrintEx(\r
1075 -1,\r
1076 -1,\r
1077 NULL,\r
1078 L"%02x",\r
1079 Buffer[LoopVar2]);\r
1080 }\r
1081 ShellPrintEx(\r
1082 -1,\r
1083 -1,\r
1084 NULL,\r
1085 L"\r\n");\r
1086 }\r
1087\r
1088 if (Buffer != NULL) {\r
1089 FreePool(Buffer);\r
1090 }\r
1091 if (DevPath != NULL) {\r
1092 FreePool(DevPath);\r
1093 }\r
1094 if (DevPathString != NULL) {\r
1095 FreePool(DevPathString);\r
1096 }\r
1097 }\r
1098 return (SHELL_SUCCESS);\r
1099}\r
1100\r
3737ac2b 1101/**\r
1102 Function to initialize the BCFG operation structure.\r
1103\r
1104 @param[in] Struct The stuct to initialize.\r
1105**/\r
5d73d92f 1106VOID\r
1107EFIAPI\r
3737ac2b 1108InitBcfgStructDebug1(\r
5d73d92f 1109 IN BGFG_OPERATION *Struct\r
1110 )\r
1111{\r
1112 ASSERT(Struct != NULL);\r
3737ac2b 1113 Struct->Target = BcfgTargetMax;\r
1114 Struct->Type = BcfgTypeMax;\r
5d73d92f 1115 Struct->Number1 = 0;\r
1116 Struct->Number2 = 0;\r
1117 Struct->HandleIndex = 0;\r
1118 Struct->FileName = NULL;\r
1119 Struct->Description = NULL;\r
1120 Struct->Order = NULL;\r
1121 Struct->OptData = NULL;\r
1122}\r
1123\r
1124\r
1125STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
1126 {L"-v", TypeFlag},\r
1127 {L"-opt", TypeMaxValue},\r
1128 {NULL, TypeMax}\r
1129 };\r
1130\r
1131/**\r
1132 Function for 'bcfg' command.\r
1133\r
1134 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
1135 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
1136**/\r
1137SHELL_STATUS\r
1138EFIAPI\r
1139ShellCommandRunBcfg (\r
1140 IN EFI_HANDLE ImageHandle,\r
1141 IN EFI_SYSTEM_TABLE *SystemTable\r
1142 )\r
1143{\r
1144 EFI_STATUS Status;\r
1145 LIST_ENTRY *Package;\r
1146 CHAR16 *ProblemParam;\r
1147 SHELL_STATUS ShellStatus;\r
1148 UINTN ParamNumber;\r
1149 CONST CHAR16 *CurrentParam;\r
1150 BGFG_OPERATION CurrentOperation;\r
1151 UINTN Length;\r
3737ac2b 1152 UINT64 Intermediate;\r
5d73d92f 1153\r
1154 Length = 0;\r
1155 ProblemParam = NULL;\r
1156 Package = NULL;\r
1157 ShellStatus = SHELL_SUCCESS;\r
1158\r
3737ac2b 1159 InitBcfgStructDebug1(&CurrentOperation);\r
5d73d92f 1160\r
1161 //\r
1162 // initialize the shell lib (we must be in non-auto-init...)\r
1163 //\r
1164 Status = ShellInitialize();\r
1165 ASSERT_EFI_ERROR(Status);\r
1166\r
1167 Status = CommandInit();\r
1168 ASSERT_EFI_ERROR(Status);\r
1169\r
1170 //\r
1171 // parse the command line\r
1172 //\r
1173 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
1174 if (EFI_ERROR(Status)) {\r
1175 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
1176 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
1177 FreePool(ProblemParam);\r
1178 ShellStatus = SHELL_INVALID_PARAMETER;\r
1179 } else {\r
1180 ASSERT(FALSE);\r
1181 }\r
1182 } else {\r
3737ac2b 1183 //\r
1184 // Read in if we are doing -OPT\r
1185 //\r
1186 if (ShellCommandLineGetFlag(Package, L"-opt")) {\r
1187 CurrentOperation.OptData = ShellCommandLineGetValue(Package, L"-opt");\r
1188 if (CurrentOperation.OptData == NULL) {\r
1189 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-opt");\r
1190 ShellStatus = SHELL_INVALID_PARAMETER;\r
1191 }\r
1192 CurrentOperation.Type = BcfgTypeOpt;\r
1193 }\r
1194\r
5d73d92f 1195 //\r
1196 // small block to read the target of the operation\r
1197 //\r
3737ac2b 1198 if ((ShellCommandLineGetCount(Package) < 3 && CurrentOperation.Type != BcfgTypeOpt) ||\r
1199 (ShellCommandLineGetCount(Package) < 2 && CurrentOperation.Type == BcfgTypeOpt)\r
1200 ){\r
5d73d92f 1201 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1202 ShellStatus = SHELL_INVALID_PARAMETER;\r
1203 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"driver") == 0) {\r
3737ac2b 1204 CurrentOperation.Target = BcfgTargetDriverOrder;\r
5d73d92f 1205 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"boot") == 0) {\r
3737ac2b 1206 CurrentOperation.Target = BcfgTargetBootOrder;\r
5d73d92f 1207 } else {\r
1208 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT), gShellDebug1HiiHandle);\r
1209 ShellStatus = SHELL_INVALID_PARAMETER;\r
1210 }\r
1211\r
5d73d92f 1212\r
1213 //\r
1214 // Read in the boot or driver order environment variable (not needed for opt)\r
1215 //\r
cff7bffb 1216 if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax) {\r
5d73d92f 1217 Length = 0;\r
1218 Status = gRT->GetVariable(\r
3737ac2b 1219 CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
5d73d92f 1220 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
1221 NULL,\r
1222 &Length,\r
1223 CurrentOperation.Order);\r
1224 if (Status == EFI_BUFFER_TOO_SMALL) {\r
3737ac2b 1225 CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));\r
5d73d92f 1226 Status = gRT->GetVariable(\r
3737ac2b 1227 CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
5d73d92f 1228 (EFI_GUID*)&gEfiGlobalVariableGuid,\r
1229 NULL,\r
1230 &Length,\r
1231 CurrentOperation.Order);\r
1232 }\r
1233 }\r
1234\r
1235 //\r
1236 // large block to read the type of operation and verify parameter types for the info.\r
1237 //\r
3737ac2b 1238 if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax) {\r
5d73d92f 1239 for (ParamNumber = 2 ; ParamNumber < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS; ParamNumber++) {\r
1240 CurrentParam = ShellCommandLineGetRawValue(Package, ParamNumber);\r
1241 if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"dump") == 0) {\r
3737ac2b 1242 CurrentOperation.Type = BcfgTypeDump;\r
5d73d92f 1243 } else if (ShellCommandLineGetFlag(Package, L"-v")) {\r
1244 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"-v (without dump)");\r
1245 ShellStatus = SHELL_INVALID_PARAMETER;\r
1246 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"add") == 0) {\r
1247 if ((ParamNumber + 3) >= ShellCommandLineGetCount(Package)) {\r
1248 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1249 ShellStatus = SHELL_INVALID_PARAMETER;\r
1250 }\r
3737ac2b 1251 CurrentOperation.Type = BcfgTypeAdd;\r
5d73d92f 1252 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1253 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1254 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1255 ShellStatus = SHELL_INVALID_PARAMETER;\r
1256 } else {\r
3737ac2b 1257 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1258 CurrentOperation.Number1 = (UINT16)Intermediate;\r
5d73d92f 1259 ASSERT(CurrentOperation.FileName == NULL);\r
1260 CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);\r
1261 ASSERT(CurrentOperation.Description == NULL);\r
1262 CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);\r
1263 }\r
1264 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"addp") == 0) {\r
1265 if ((ParamNumber + 3) >= ShellCommandLineGetCount(Package)) {\r
1266 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1267 ShellStatus = SHELL_INVALID_PARAMETER;\r
1268 }\r
3737ac2b 1269 CurrentOperation.Type = BcfgTypeAddp;\r
5d73d92f 1270 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1271 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1272 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1273 ShellStatus = SHELL_INVALID_PARAMETER;\r
1274 } else {\r
3737ac2b 1275 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1276 CurrentOperation.Number1 = (UINT16)Intermediate;\r
5d73d92f 1277 ASSERT(CurrentOperation.FileName == NULL);\r
1278 CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);\r
1279 ASSERT(CurrentOperation.Description == NULL);\r
1280 CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);\r
1281 }\r
1282 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"addh") == 0) {\r
1283 if ((ParamNumber + 3) >= ShellCommandLineGetCount(Package)) {\r
1284 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1285 ShellStatus = SHELL_INVALID_PARAMETER;\r
1286 }\r
3737ac2b 1287 CurrentOperation.Type = BcfgTypeAddh;\r
5d73d92f 1288 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1289 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1290 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1291 ShellStatus = SHELL_INVALID_PARAMETER;\r
1292 } else {\r
3737ac2b 1293 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1294 CurrentOperation.Number1 = (UINT16)Intermediate;\r
5d73d92f 1295 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1296 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1297 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1298 ShellStatus = SHELL_INVALID_PARAMETER;\r
1299 } else {\r
3737ac2b 1300 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1301 CurrentOperation.HandleIndex = (UINT16)Intermediate;\r
5d73d92f 1302 ASSERT(CurrentOperation.Description == NULL);\r
1303 CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);\r
1304 }\r
1305 }\r
1306 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"rm") == 0) {\r
1307 if ((ParamNumber + 1) >= ShellCommandLineGetCount(Package)) {\r
1308 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1309 ShellStatus = SHELL_INVALID_PARAMETER;\r
1310 }\r
3737ac2b 1311 CurrentOperation.Type = BcfgTypeRm;\r
5d73d92f 1312 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1313 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1314 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1315 ShellStatus = SHELL_INVALID_PARAMETER;\r
1316 } else {\r
3737ac2b 1317 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1318 CurrentOperation.Number1 = (UINT16)Intermediate;\r
5d73d92f 1319 if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){\r
1320 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));\r
1321 ShellStatus = SHELL_INVALID_PARAMETER;\r
1322 }\r
1323 }\r
1324 } else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"mv") == 0) {\r
1325 if ((ParamNumber + 2) >= ShellCommandLineGetCount(Package)) {\r
1326 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
1327 ShellStatus = SHELL_INVALID_PARAMETER;\r
1328 }\r
3737ac2b 1329 CurrentOperation.Type = BcfgTypeMv;\r
5d73d92f 1330 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1331 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1332 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1333 ShellStatus = SHELL_INVALID_PARAMETER;\r
1334 } else {\r
3737ac2b 1335 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1336 CurrentOperation.Number1 = (UINT16)Intermediate;\r
5d73d92f 1337 if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){\r
1338 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));\r
1339 ShellStatus = SHELL_INVALID_PARAMETER;\r
1340 }\r
1341 CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r
1342 if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {\r
1343 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1344 ShellStatus = SHELL_INVALID_PARAMETER;\r
1345 } else {\r
3737ac2b 1346 Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
1347 CurrentOperation.Number2 = (UINT16)Intermediate;\r
5d73d92f 1348 }\r
1349 if (CurrentOperation.Number2 == CurrentOperation.Number1\r
1350 ||CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))\r
1351 ||CurrentOperation.Number2 > (Length / sizeof(CurrentOperation.Order[0]))\r
1352 ){\r
1353 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));\r
1354 ShellStatus = SHELL_INVALID_PARAMETER;\r
1355 }\r
1356 }\r
1357 } else {\r
1358 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);\r
1359 ShellStatus = SHELL_INVALID_PARAMETER;\r
1360 }\r
1361 }\r
1362 }\r
3737ac2b 1363 if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type < BcfgTypeMax) {\r
5d73d92f 1364 //\r
1365 // we have all the info. Do the work\r
1366 //\r
1367 switch (CurrentOperation.Type) {\r
3737ac2b 1368 case BcfgTypeDump:\r
1369 ShellStatus = BcfgDisplayDumpDebug1(\r
1370 CurrentOperation.Target == BcfgTargetBootOrder?L"Boot":L"Driver",\r
5d73d92f 1371 Length / sizeof(CurrentOperation.Order[0]),\r
3737ac2b 1372 CurrentOperation.Order,\r
5d73d92f 1373 ShellCommandLineGetFlag(Package, L"-v"));\r
1374 break;\r
3737ac2b 1375 case BcfgTypeMv:\r
1376 ShellStatus = BcfgMoveDebug1(\r
5d73d92f 1377 CurrentOperation.Target,\r
1378 CurrentOperation.Order,\r
1379 Length / sizeof(CurrentOperation.Order[0]),\r
1380 CurrentOperation.Number1,\r
1381 CurrentOperation.Number2);\r
1382 break;\r
3737ac2b 1383 case BcfgTypeRm:\r
1384 ShellStatus = BcfgRemoveDebug1(\r
5d73d92f 1385 CurrentOperation.Target,\r
1386 CurrentOperation.Order,\r
1387 Length / sizeof(CurrentOperation.Order[0]),\r
1388 CurrentOperation.Number1);\r
1389 break;\r
3737ac2b 1390 case BcfgTypeAdd:\r
1391 case BcfgTypeAddp:\r
1392 case BcfgTypeAddh:\r
1393 ShellStatus = BcfgAddDebug1(\r
5d73d92f 1394 CurrentOperation.Number1,\r
1395 CurrentOperation.FileName,\r
532691c8 1396 CurrentOperation.Description==NULL?L"":CurrentOperation.Description,\r
5d73d92f 1397 CurrentOperation.Order,\r
3737ac2b 1398 Length / sizeof(CurrentOperation.Order[0]),\r
5d73d92f 1399 CurrentOperation.Target,\r
3737ac2b 1400 (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddh),\r
1401 (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),\r
5d73d92f 1402 CurrentOperation.HandleIndex);\r
1403 break;\r
3737ac2b 1404 case BcfgTypeOpt:\r
1405 ShellStatus = BcfgAddOptDebug1(\r
1406 CurrentOperation.OptData,\r
cff7bffb 1407 CurrentOperation.Order,\r
1408 Length / sizeof(CurrentOperation.Order[0]),\r
3737ac2b 1409 CurrentOperation.Target);\r
1410 break;\r
5d73d92f 1411 default:\r
1412 ASSERT(FALSE);\r
1413 }\r
1414 }\r
1415 }\r
1416\r
1417 if (Package != NULL) {\r
1418 ShellCommandLineFreeVarList (Package);\r
1419 }\r
1420 if (CurrentOperation.FileName != NULL) {\r
1421 FreePool(CurrentOperation.FileName);\r
1422 }\r
1423 if (CurrentOperation.Description != NULL) {\r
1424 FreePool(CurrentOperation.Description);\r
1425 }\r
1426 if (CurrentOperation.Order != NULL) {\r
1427 FreePool(CurrentOperation.Order);\r
1428 }\r
1429\r
1430 return (ShellStatus);\r
1431}\r