2 Main file for bcfg shell Debug1 function.
4 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellDebug1CommandsLib.h"
16 #include <Guid/GlobalVariable.h>
17 #include <Library/PrintLib.h>
18 #include <Library/HandleParsingLib.h>
19 #include <Library/DevicePathLib.h>
22 BcfgTargetBootOrder
= 0,
23 BcfgTargetDriverOrder
= 1,
25 } BCFG_OPERATION_TARGET
;
36 } BCFG_OPERATION_TYPE
;
39 BCFG_OPERATION_TARGET Target
;
40 BCFG_OPERATION_TYPE Type
;
47 CONST CHAR16
*OptData
;
51 Update the optional data for a boot or driver option.
53 If optional data exists it will be changed.
55 @param[in] Index The boot or driver option index update.
56 @param[in] DataSize The size in bytes of Data.
57 @param[in] Data The buffer for the optioanl data.
58 @param[in] Target The target of the operation.
60 @retval EFI_SUCCESS The data was sucessfully updated.
61 @retval other A error occured.
65 UpdateOptionalDataDebug1(
69 IN CONST BCFG_OPERATION_TARGET Target
73 CHAR16 VariableName
[12];
78 UINTN OriginalOptionDataSize
;
80 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
87 Status
= gRT
->GetVariable(
89 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
93 if (Status
== EFI_BUFFER_TOO_SMALL
) {
94 OriginalData
= AllocateZeroPool(OriginalSize
);
95 if (OriginalData
== NULL
) {
96 return (EFI_OUT_OF_RESOURCES
);
98 Status
= gRT
->GetVariable(
100 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
106 if (!EFI_ERROR(Status
)) {
108 // Allocate new struct and discard old optional data.
110 ASSERT (OriginalData
!= NULL
);
111 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
112 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
113 OriginalOptionDataSize
-= OriginalSize
;
114 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
115 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
116 if (NewData
== NULL
) {
117 Status
= EFI_OUT_OF_RESOURCES
;
119 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
123 if (!EFI_ERROR(Status
)) {
125 // put the data back under the variable
127 Status
= gRT
->SetVariable(
129 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
130 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
135 SHELL_FREE_NON_NULL(OriginalData
);
136 SHELL_FREE_NON_NULL(NewData
);
141 This function will get a CRC for a boot option.
143 @param[in, out] Crc The CRC value to return.
144 @param[in] BootIndex The boot option index to CRC.
146 @retval EFI_SUCCESS The CRC was sucessfully returned.
147 @retval other A error occured.
151 GetBootOptionCrcDebug1(
156 CHAR16 VariableName
[12];
165 // Get the data Buffer
167 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
168 Status
= gRT
->GetVariable(
170 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
174 if (Status
== EFI_BUFFER_TOO_SMALL
) {
175 Buffer
= AllocateZeroPool(BufferSize
);
176 Status
= gRT
->GetVariable(
178 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
185 // Get the CRC computed
187 if (!EFI_ERROR(Status
)) {
188 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
191 SHELL_FREE_NON_NULL(Buffer
);
196 This function will populate the device path protocol parameter based on TheHandle.
198 @param[in] TheHandle Driver handle.
199 @param[in, out] FilePath On a sucessful return the device path to the handle.
201 @retval EFI_SUCCESS The device path was sucessfully returned.
202 @retval other A error from gBS->HandleProtocol.
208 GetDevicePathForDriverHandleDebug1 (
209 IN EFI_HANDLE TheHandle
,
210 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
214 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
215 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
217 Status
= gBS
->OpenProtocol (
219 &gEfiLoadedImageProtocolGuid
,
220 (VOID
**)&LoadedImage
,
223 EFI_OPEN_PROTOCOL_GET_PROTOCOL
225 if (!EFI_ERROR (Status
)) {
226 Status
= gBS
->OpenProtocol (
227 LoadedImage
->DeviceHandle
,
228 &gEfiDevicePathProtocolGuid
,
229 (VOID
**)&ImageDevicePath
,
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL
234 if (!EFI_ERROR (Status
)) {
235 // *DevPath = DuplicateDevicePath (ImageDevicePath);
236 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
237 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
239 LoadedImage
->DeviceHandle
,
240 &gEfiDevicePathProtocolGuid
,
246 &gEfiLoadedImageProtocolGuid
,
254 Function to add a option.
256 @param[in] Position The position to add Target at.
257 @param[in] File The file to make the target.
258 @param[in] Desc The description text.
259 @param[in] CurrentOrder The pointer to the current order of items.
260 @param[in] OrderCount The number if items in CurrentOrder.
261 @param[in] Target The info on the option to add.
262 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
263 @param[in] UsePath TRUE to convert to devicepath.
264 @param[in] HandleNumber The handle number to add.
266 @retval SHELL_SUCCESS The operation was successful.
267 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
273 IN CONST CHAR16
*File
,
274 IN CONST CHAR16
*Desc
,
275 IN CONST UINT16
*CurrentOrder
,
276 IN CONST UINTN OrderCount
,
277 IN CONST BCFG_OPERATION_TARGET Target
,
278 IN CONST BOOLEAN UseHandle
,
279 IN CONST BOOLEAN UsePath
,
280 IN CONST UINTN HandleNumber
284 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
285 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
286 /* EFI_DEVICE_PATH_PROTOCOL *FileNode; */
288 UINT8
*TempByteBuffer
;
289 UINT8
*TempByteStart
;
290 EFI_SHELL_FILE_INFO
*Arg
;
291 EFI_SHELL_FILE_INFO
*FileList
;
292 CHAR16 OptionStr
[40];
293 UINTN DescSize
, FilePathSize
;
295 UINTN TargetLocation
;
298 EFI_HANDLE CurHandle
;
299 UINTN DriverBindingHandleCount
;
300 UINTN ParentControllerHandleCount
;
301 UINTN ChildControllerHandleCount
;
302 SHELL_STATUS ShellStatus
;
306 if (File
== NULL
|| Desc
== NULL
) {
307 return (SHELL_INVALID_PARAMETER
);
310 if (HandleNumber
== 0) {
311 return (SHELL_INVALID_PARAMETER
);
315 if (Position
> OrderCount
) {
316 Position
= OrderCount
;
321 /* FileNode = NULL; */
324 ShellStatus
= SHELL_SUCCESS
;
325 TargetLocation
= 0xFFFF;
328 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
329 if (CurHandle
== NULL
) {
330 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Handle Number");
331 ShellStatus
= SHELL_INVALID_PARAMETER
;
333 if (Target
== BcfgTargetBootOrder
) {
335 //Make sure that the handle should point to a real controller
337 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
339 &DriverBindingHandleCount
,
342 Status
= PARSE_HANDLE_DATABASE_PARENTS (
344 &ParentControllerHandleCount
,
347 Status
= ParseHandleDatabaseForChildControllers (
349 &ChildControllerHandleCount
,
352 if (DriverBindingHandleCount
> 0
353 || ParentControllerHandleCount
> 0
354 || ChildControllerHandleCount
> 0) {
356 Status
= gBS
->HandleProtocol (
358 &gEfiDevicePathProtocolGuid
,
361 if (EFI_ERROR (Status
)) {
362 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellDebug1HiiHandle
, HandleNumber
);
363 ShellStatus
= SHELL_INVALID_PARAMETER
;
367 //Make sure that the handle should point to driver, not a controller.
369 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
371 &DriverBindingHandleCount
,
374 Status
= PARSE_HANDLE_DATABASE_PARENTS (
376 &ParentControllerHandleCount
,
379 Status
= ParseHandleDatabaseForChildControllers (
381 &ChildControllerHandleCount
,
384 Status
= gBS
->HandleProtocol (
386 &gEfiDevicePathProtocolGuid
,
389 if (DriverBindingHandleCount
> 0
390 || ParentControllerHandleCount
> 0
391 || ChildControllerHandleCount
> 0
392 || !EFI_ERROR(Status
) ) {
393 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Handle Number");
394 ShellStatus
= SHELL_INVALID_PARAMETER
;
397 // Get the DevicePath from the loaded image information.
399 Status
= GetDevicePathForDriverHandleDebug1(CurHandle
, &FilePath
);
407 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
409 if (FileList
== NULL
) {
411 // If filename matched nothing fail
413 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, File
);
414 ShellStatus
= SHELL_INVALID_PARAMETER
;
415 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
417 // If filename expanded to multiple names, fail
419 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellDebug1HiiHandle
, File
);
420 ShellStatus
= SHELL_INVALID_PARAMETER
;
422 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
423 if (EFI_ERROR(Arg
->Status
)) {
424 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellDebug1HiiHandle
, File
, Arg
->Status
);
425 ShellStatus
= SHELL_INVALID_PARAMETER
;
428 // Build FilePath to the filename
432 // get the device path
434 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
435 if (DevicePath
== NULL
) {
436 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellDebug1HiiHandle
, Arg
->FullName
);
437 ShellStatus
= SHELL_UNSUPPORTED
;
441 DevPath = DevicePath;
442 while (!IsDevicePathEnd(DevPath)) {
443 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
444 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
447 // If we find it use it instead
449 DevicePath = DevPath;
452 DevPath = NextDevicePathNode(DevPath);
457 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
458 FileNode = FileDevicePath(NULL, StringWalker+1);
459 FilePath = AppendDevicePath(DevicePath, FileNode);
463 FilePath
= DuplicateDevicePath(DevicePath
);
467 FreePool(DevicePath
);
474 if (ShellStatus
== SHELL_SUCCESS
) {
476 // Find a free target ,a brute force implementation
479 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
481 for (Index
=0; Index
< OrderCount
; Index
++) {
482 if (CurrentOrder
[Index
] == TargetLocation
) {
493 if (TargetLocation
== 0xFFFF) {
494 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellDebug1HiiHandle
);
496 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellDebug1HiiHandle
, TargetLocation
);
500 if (ShellStatus
== SHELL_SUCCESS
) {
504 DescSize
= StrSize(Desc
);
505 FilePathSize
= GetDevicePathSize (FilePath
);
507 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
508 if (TempByteBuffer
!= NULL
) {
509 TempByteStart
= TempByteBuffer
;
510 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
511 TempByteBuffer
+= sizeof (UINT32
);
513 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
514 TempByteBuffer
+= sizeof (UINT16
);
516 CopyMem (TempByteBuffer
, Desc
, DescSize
);
517 TempByteBuffer
+= DescSize
;
518 ASSERT (FilePath
!= NULL
);
519 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
521 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
522 Status
= gRT
->SetVariable (
524 &gEfiGlobalVariableGuid
,
525 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
526 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
530 FreePool(TempByteStart
);
532 Status
= EFI_OUT_OF_RESOURCES
;
535 if (EFI_ERROR(Status
)) {
536 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, OptionStr
, Status
);
538 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
539 ASSERT(NewOrder
!= NULL
);
540 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
543 // Insert target into order list
545 for (Index
=OrderCount
; Index
> Position
; Index
--) {
546 NewOrder
[Index
] = NewOrder
[Index
-1];
549 NewOrder
[Position
] = (UINT16
) TargetLocation
;
550 Status
= gRT
->SetVariable (
551 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
552 &gEfiGlobalVariableGuid
,
553 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
554 (OrderCount
+1) * sizeof(UINT16
),
560 if (EFI_ERROR(Status
)) {
561 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder", Status
);
562 ShellStatus
= SHELL_INVALID_PARAMETER
;
564 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
570 //If always Free FilePath, will free devicepath in system when use "addh"
572 if (FilePath
!=NULL
&& !UseHandle
) {
580 if (Handles
!= NULL
) {
584 if (FileList
!= NULL
) {
585 ShellCloseFileMetaArg (&FileList
);
588 return (ShellStatus
);
592 Funciton to remove an item.
594 @param[in] Target The target item to move.
595 @param[in] CurrentOrder The pointer to the current order of items.
596 @param[in] OrderCount The number if items in CurrentOrder.
597 @param[in] Location The current location of the Target.
599 @retval SHELL_SUCCESS The operation was successful.
600 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
605 IN CONST BCFG_OPERATION_TARGET Target
,
606 IN CONST UINT16
*CurrentOrder
,
607 IN CONST UINTN OrderCount
,
608 IN CONST UINT16 Location
611 CHAR16 VariableName
[12];
616 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
617 Status
= gRT
->SetVariable(
619 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
620 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
623 if (EFI_ERROR(Status
)) {
624 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
625 return (SHELL_INVALID_PARAMETER
);
627 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
628 if (NewOrder
!= NULL
) {
629 NewCount
= OrderCount
;
630 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
631 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
634 Status
= gRT
->SetVariable(
635 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
636 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
637 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
638 NewCount
*sizeof(NewOrder
[0]),
642 Status
= EFI_OUT_OF_RESOURCES
;
644 if (EFI_ERROR(Status
)) {
645 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
646 return (SHELL_INVALID_PARAMETER
);
648 return (SHELL_SUCCESS
);
652 Funciton to move a item to another location.
654 @param[in] Target The target item to move.
655 @param[in] CurrentOrder The pointer to the current order of items.
656 @param[in] OrderCount The number if items in CurrentOrder.
657 @param[in] OldLocation The current location of the Target.
658 @param[in] NewLocation The desired location of the Target.
660 @retval SHELL_SUCCESS The operation was successful.
661 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
666 IN CONST BCFG_OPERATION_TARGET Target
,
667 IN CONST UINT16
*CurrentOrder
,
668 IN CONST UINTN OrderCount
,
669 IN CONST UINT16 OldLocation
,
670 IN UINT16 NewLocation
677 NewOrder
= AllocateCopyPool(OrderCount
*sizeof(CurrentOrder
[0]), CurrentOrder
);
678 if (NewOrder
== NULL
) {
679 return (SHELL_OUT_OF_RESOURCES
);
683 // correct the new location
685 if (NewLocation
>= OrderCount
) {
686 if (OrderCount
> 0) {
687 NewLocation
= (UINT16
)OrderCount
- 1;
693 Temp
= CurrentOrder
[OldLocation
];
694 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
695 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
696 NewOrder
[NewLocation
] = Temp
;
698 Status
= gRT
->SetVariable(
699 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
700 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
701 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
702 OrderCount
*sizeof(CurrentOrder
[0]),
707 if (EFI_ERROR(Status
)) {
708 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
709 return (SHELL_INVALID_PARAMETER
);
711 return (SHELL_SUCCESS
);
715 Function to add optional data to an option.
717 @param[in] OptData The optional data to add.
718 @param[in] CurrentOrder The pointer to the current order of items.
719 @param[in] OrderCount The number if items in CurrentOrder.
720 @param[in] Target The target of the operation.
722 @retval SHELL_SUCCESS The operation was succesful.
727 IN CONST CHAR16
*OptData
,
728 IN CONST UINT16
*CurrentOrder
,
729 IN CONST UINTN OrderCount
,
730 IN CONST BCFG_OPERATION_TARGET Target
733 EFI_KEY_OPTION NewKeyOption
;
734 EFI_KEY_OPTION
*KeyOptionBuffer
;
735 SHELL_STATUS ShellStatus
;
741 CONST CHAR16
*Walker
;
746 CHAR16 VariableName
[12];
748 SHELL_FILE_HANDLE FileHandle
;
750 Status
= EFI_SUCCESS
;
751 ShellStatus
= SHELL_SUCCESS
;
755 KeyOptionBuffer
= NULL
;
757 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
759 while(Walker
[0] == L
' ') {
764 // Get the index of the variable we are changing.
766 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
767 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
768 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Option Index");
769 ShellStatus
= SHELL_INVALID_PARAMETER
;
770 return (ShellStatus
);
772 OptionIndex
= (UINT16
)Intermediate
;
774 Temp
= StrStr(Walker
, L
" ");
778 while(Walker
[0] == L
' ') {
783 // determine whether we have file with data, quote delimited information, or a hot-key
785 if (Walker
[0] == L
'\"') {
787 // quoted filename or quoted information.
789 Temp
= StrStr(Walker
+1, L
"\"");
790 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
791 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
792 ShellStatus
= SHELL_INVALID_PARAMETER
;
794 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
795 if (FileName
== NULL
) {
796 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
797 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
798 return (ShellStatus
);
800 Temp2
= StrStr(FileName
, L
"\"");
801 ASSERT(Temp2
!= NULL
);
802 Temp2
[0] = CHAR_NULL
;
804 if (StrLen(Temp2
)>0) {
805 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
806 ShellStatus
= SHELL_INVALID_PARAMETER
;
808 if (EFI_ERROR(ShellFileExists(Walker
))) {
810 // Not a file. must be misc information.
815 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
820 // filename or hot key information.
822 if (StrStr(Walker
, L
" ") == NULL
) {
826 if (EFI_ERROR(ShellFileExists(Walker
))) {
827 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellDebug1HiiHandle
, Walker
);
828 ShellStatus
= SHELL_INVALID_PARAMETER
;
830 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
833 if (Target
!= BcfgTargetBootOrder
) {
834 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellDebug1HiiHandle
);
835 ShellStatus
= SHELL_INVALID_PARAMETER
;
838 if (ShellStatus
== SHELL_SUCCESS
) {
840 // Get hot key information
842 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
843 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
844 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
845 ShellStatus
= SHELL_INVALID_PARAMETER
;
847 NewKeyOption
.KeyData
.PackedValue
= (UINT32
)Intermediate
;
848 Temp
= StrStr(Walker
, L
" ");
852 while(Walker
[0] == L
' ') {
857 if (ShellStatus
== SHELL_SUCCESS
) {
859 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
860 // Re-allocate with the added information.
862 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_KEY_DATA
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
), &NewKeyOption
);
863 if (KeyOptionBuffer
== NULL
) {
864 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellDebug1HiiHandle
);
865 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
868 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< NewKeyOption
.KeyData
.Options
.InputKeyCount
; LoopCounter
++) {
872 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
873 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
874 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
875 ShellStatus
= SHELL_INVALID_PARAMETER
;
877 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
878 Temp
= StrStr(Walker
, L
" ");
882 while(Walker
[0] == L
' ') {
889 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
890 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
891 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
892 ShellStatus
= SHELL_INVALID_PARAMETER
;
894 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
895 Temp
= StrStr(Walker
, L
" ");
899 while(Walker
[0] == L
' ') {
904 if (ShellStatus
== SHELL_SUCCESS
) {
906 // Now do the BootOption / BootOptionCrc
908 ASSERT (OptionIndex
<= OrderCount
);
909 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
910 Status
= GetBootOptionCrcDebug1(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
911 if (EFI_ERROR(Status
)) {
912 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Option Index");
913 ShellStatus
= SHELL_INVALID_PARAMETER
;
917 if (ShellStatus
== SHELL_SUCCESS
) {
918 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
< 0xFFFF ; KeyIndex
++) {
919 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
920 Status
= gRT
->GetVariable(
922 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
924 (UINTN
*)&Intermediate
,
926 if (Status
== EFI_NOT_FOUND
) {
930 Status
= gRT
->SetVariable(
932 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
933 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
934 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_KEY_DATA
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
),
936 if (EFI_ERROR(Status
)) {
937 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
938 ShellStatus
= SHELL_INVALID_PARAMETER
;
940 ASSERT(FileName
== NULL
&& Data
== NULL
);
946 // Shouldn't be possible to have have both. Neither is ok though.
948 ASSERT(FileName
== NULL
|| Data
== NULL
);
950 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
951 if (FileName
!= NULL
) {
953 // Open the file and populate the data buffer.
955 Status
= ShellOpenFileByName(
960 if (!EFI_ERROR(Status
)) {
961 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
963 Data
= AllocateZeroPool((UINTN
)Intermediate
);
965 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellDebug1HiiHandle
);
966 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
968 if (!EFI_ERROR(Status
)) {
969 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
972 Intermediate
= StrSize(Data
);
975 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
976 Status
= UpdateOptionalDataDebug1(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
977 if (EFI_ERROR(Status
)) {
978 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
979 ShellStatus
= SHELL_INVALID_PARAMETER
;
982 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
983 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
984 ShellStatus
= SHELL_INVALID_PARAMETER
;
988 SHELL_FREE_NON_NULL(Data
);
989 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
990 SHELL_FREE_NON_NULL(FileName
);
995 Function to dump the Bcfg information.
997 @param[in] Op The operation.
998 @param[in] OrderCount How many to dump.
999 @param[in] CurrentOrder The pointer to the current order of items.
1000 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
1002 @retval SHELL_SUCCESS The dump was successful.
1003 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1007 BcfgDisplayDumpDebug1(
1008 IN CONST CHAR16
*Op
,
1009 IN CONST UINTN OrderCount
,
1010 IN CONST UINT16
*CurrentOrder
,
1011 IN CONST BOOLEAN VerboseOutput
1017 CHAR16 VariableName
[12];
1020 CHAR16
*DevPathString
;
1023 if (OrderCount
== 0) {
1024 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellDebug1HiiHandle
);
1025 return (SHELL_SUCCESS
);
1028 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1031 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1033 Status
= gRT
->GetVariable(
1035 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1039 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1040 Buffer
= AllocateZeroPool(BufferSize
);
1041 if (Buffer
!= NULL
) {
1042 Status
= gRT
->GetVariable(
1044 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1051 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1052 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
1053 return (SHELL_INVALID_PARAMETER
);
1056 if ((*(UINT16
*)(Buffer
+4)) != 0) {
1057 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
1058 if (DevPath
!= NULL
) {
1059 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
1060 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1062 DevPathString
= NULL
;
1066 DevPathString
= NULL
;
1072 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1073 gShellDebug1HiiHandle
,
1076 (CHAR16
*)(Buffer
+6),
1078 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
1079 if (VerboseOutput
) {
1080 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
1095 if (Buffer
!= NULL
) {
1098 if (DevPath
!= NULL
) {
1101 if (DevPathString
!= NULL
) {
1102 FreePool(DevPathString
);
1105 return (SHELL_SUCCESS
);
1109 Function to initialize the BCFG operation structure.
1111 @param[in] Struct The stuct to initialize.
1115 InitBcfgStructDebug1(
1116 IN BGFG_OPERATION
*Struct
1119 ASSERT(Struct
!= NULL
);
1120 Struct
->Target
= BcfgTargetMax
;
1121 Struct
->Type
= BcfgTypeMax
;
1122 Struct
->Number1
= 0;
1123 Struct
->Number2
= 0;
1124 Struct
->HandleIndex
= 0;
1125 Struct
->FileName
= NULL
;
1126 Struct
->Description
= NULL
;
1127 Struct
->Order
= NULL
;
1128 Struct
->OptData
= NULL
;
1132 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1134 {L
"-opt", TypeMaxValue
},
1139 Function for 'bcfg' command.
1141 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1142 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1146 ShellCommandRunBcfg (
1147 IN EFI_HANDLE ImageHandle
,
1148 IN EFI_SYSTEM_TABLE
*SystemTable
1152 LIST_ENTRY
*Package
;
1153 CHAR16
*ProblemParam
;
1154 SHELL_STATUS ShellStatus
;
1156 CONST CHAR16
*CurrentParam
;
1157 BGFG_OPERATION CurrentOperation
;
1159 UINT64 Intermediate
;
1163 ProblemParam
= NULL
;
1165 ShellStatus
= SHELL_SUCCESS
;
1167 InitBcfgStructDebug1(&CurrentOperation
);
1170 // initialize the shell lib (we must be in non-auto-init...)
1172 Status
= ShellInitialize();
1173 ASSERT_EFI_ERROR(Status
);
1175 Status
= CommandInit();
1176 ASSERT_EFI_ERROR(Status
);
1179 // parse the command line
1181 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1182 if (EFI_ERROR(Status
)) {
1183 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1184 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
1185 FreePool(ProblemParam
);
1186 ShellStatus
= SHELL_INVALID_PARAMETER
;
1192 // Read in if we are doing -OPT
1194 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1195 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1196 if (CurrentOperation
.OptData
== NULL
) {
1197 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellDebug1HiiHandle
, L
"-opt");
1198 ShellStatus
= SHELL_INVALID_PARAMETER
;
1200 CurrentOperation
.Type
= BcfgTypeOpt
;
1204 // small block to read the target of the operation
1206 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1207 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1209 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1210 ShellStatus
= SHELL_INVALID_PARAMETER
;
1211 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1212 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1213 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1214 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1216 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellDebug1HiiHandle
);
1217 ShellStatus
= SHELL_INVALID_PARAMETER
;
1222 // Read in the boot or driver order environment variable (not needed for opt)
1224 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1226 Status
= gRT
->GetVariable(
1227 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1228 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1231 CurrentOperation
.Order
);
1232 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1233 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1234 if (CurrentOperation
.Order
!= NULL
) {
1235 Status
= gRT
->GetVariable(
1236 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1237 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1240 CurrentOperation
.Order
);
1242 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1247 Count
= (UINT16
) (Length
/ sizeof(CurrentOperation
.Order
[0]));
1250 // large block to read the type of operation and verify parameter types for the info.
1252 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1253 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1254 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1255 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1256 CurrentOperation
.Type
= BcfgTypeDump
;
1257 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1258 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"-v (without dump)");
1259 ShellStatus
= SHELL_INVALID_PARAMETER
;
1260 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1261 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1262 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1263 ShellStatus
= SHELL_INVALID_PARAMETER
;
1265 CurrentOperation
.Type
= BcfgTypeAdd
;
1266 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1267 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1268 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1269 ShellStatus
= SHELL_INVALID_PARAMETER
;
1271 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1272 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1273 ASSERT(CurrentOperation
.FileName
== NULL
);
1274 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1275 ASSERT(CurrentOperation
.Description
== NULL
);
1276 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1278 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1279 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1280 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1281 ShellStatus
= SHELL_INVALID_PARAMETER
;
1283 CurrentOperation
.Type
= BcfgTypeAddp
;
1284 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1285 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1286 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1287 ShellStatus
= SHELL_INVALID_PARAMETER
;
1289 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1290 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1291 ASSERT(CurrentOperation
.FileName
== NULL
);
1292 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1293 ASSERT(CurrentOperation
.Description
== NULL
);
1294 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1296 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1297 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1298 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1299 ShellStatus
= SHELL_INVALID_PARAMETER
;
1301 CurrentOperation
.Type
= BcfgTypeAddh
;
1302 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1303 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1304 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1305 ShellStatus
= SHELL_INVALID_PARAMETER
;
1307 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1308 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1309 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1310 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1311 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1312 ShellStatus
= SHELL_INVALID_PARAMETER
;
1314 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1315 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1316 ASSERT(CurrentOperation
.Description
== NULL
);
1317 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1320 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1321 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1322 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1323 ShellStatus
= SHELL_INVALID_PARAMETER
;
1325 CurrentOperation
.Type
= BcfgTypeRm
;
1326 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1327 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1328 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1329 ShellStatus
= SHELL_INVALID_PARAMETER
;
1331 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1332 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1333 if (CurrentOperation
.Number1
> Count
){
1334 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Count
);
1335 ShellStatus
= SHELL_INVALID_PARAMETER
;
1338 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1339 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1340 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1341 ShellStatus
= SHELL_INVALID_PARAMETER
;
1343 CurrentOperation
.Type
= BcfgTypeMv
;
1344 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1345 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1346 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1347 ShellStatus
= SHELL_INVALID_PARAMETER
;
1349 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1350 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1351 if (CurrentOperation
.Number1
> Count
){
1352 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Count
);
1353 ShellStatus
= SHELL_INVALID_PARAMETER
;
1355 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1356 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1357 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1358 ShellStatus
= SHELL_INVALID_PARAMETER
;
1360 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1361 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1363 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1364 ||CurrentOperation
.Number2
>= Count
1366 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Count
);
1367 ShellStatus
= SHELL_INVALID_PARAMETER
;
1372 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1373 ShellStatus
= SHELL_INVALID_PARAMETER
;
1377 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1379 // we have all the info. Do the work
1381 switch (CurrentOperation
.Type
) {
1383 ShellStatus
= BcfgDisplayDumpDebug1(
1384 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1386 CurrentOperation
.Order
,
1387 ShellCommandLineGetFlag(Package
, L
"-v"));
1390 ShellStatus
= BcfgMoveDebug1(
1391 CurrentOperation
.Target
,
1392 CurrentOperation
.Order
,
1394 CurrentOperation
.Number1
,
1395 CurrentOperation
.Number2
);
1398 ShellStatus
= BcfgRemoveDebug1(
1399 CurrentOperation
.Target
,
1400 CurrentOperation
.Order
,
1402 CurrentOperation
.Number1
);
1407 ShellStatus
= BcfgAddDebug1(
1408 CurrentOperation
.Number1
,
1409 CurrentOperation
.FileName
,
1410 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1411 CurrentOperation
.Order
,
1413 CurrentOperation
.Target
,
1414 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1415 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1416 CurrentOperation
.HandleIndex
);
1419 ShellStatus
= BcfgAddOptDebug1(
1420 CurrentOperation
.OptData
,
1421 CurrentOperation
.Order
,
1423 CurrentOperation
.Target
);
1431 if (Package
!= NULL
) {
1432 ShellCommandLineFreeVarList (Package
);
1434 if (CurrentOperation
.FileName
!= NULL
) {
1435 FreePool(CurrentOperation
.FileName
);
1437 if (CurrentOperation
.Description
!= NULL
) {
1438 FreePool(CurrentOperation
.Description
);
1440 if (CurrentOperation
.Order
!= NULL
) {
1441 FreePool(CurrentOperation
.Order
);
1444 return (ShellStatus
);