2 Main file for bcfg shell Debug1 function.
4 Copyright (c) 2010 - 2012, 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 Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3.
53 @param KeyOption Pointer to the EFI_KEY_OPTION structure.
55 @return Actual number of entries in EFI_KEY_OPTION.Keys.
57 #define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) \
58 (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK))
61 Update the optional data for a boot or driver option.
63 If optional data exists it will be changed.
65 @param[in] Index The boot or driver option index update.
66 @param[in] DataSize The size in bytes of Data.
67 @param[in] Data The buffer for the optioanl data.
68 @param[in] Target The target of the operation.
70 @retval EFI_SUCCESS The data was sucessfully updated.
71 @retval other A error occured.
75 UpdateOptionalDataDebug1(
79 IN CONST BCFG_OPERATION_TARGET Target
83 CHAR16 VariableName
[12];
88 UINTN OriginalOptionDataSize
;
90 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
97 Status
= gRT
->GetVariable(
99 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
103 if (Status
== EFI_BUFFER_TOO_SMALL
) {
104 OriginalData
= AllocateZeroPool(OriginalSize
);
105 if (OriginalData
== NULL
) {
106 return (EFI_OUT_OF_RESOURCES
);
108 Status
= gRT
->GetVariable(
110 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
116 if (!EFI_ERROR(Status
)) {
118 // Allocate new struct and discard old optional data.
120 ASSERT (OriginalData
!= NULL
);
121 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
122 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
123 OriginalOptionDataSize
-= OriginalSize
;
124 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
125 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
126 if (NewData
== NULL
) {
127 Status
= EFI_OUT_OF_RESOURCES
;
129 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
133 if (!EFI_ERROR(Status
)) {
135 // put the data back under the variable
137 Status
= gRT
->SetVariable(
139 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
140 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
145 SHELL_FREE_NON_NULL(OriginalData
);
146 SHELL_FREE_NON_NULL(NewData
);
151 This function will get a CRC for a boot option.
153 @param[in, out] Crc The CRC value to return.
154 @param[in] BootIndex The boot option index to CRC.
156 @retval EFI_SUCCESS The CRC was sucessfully returned.
157 @retval other A error occured.
161 GetBootOptionCrcDebug1(
166 CHAR16 VariableName
[12];
175 // Get the data Buffer
177 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
178 Status
= gRT
->GetVariable(
180 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
184 if (Status
== EFI_BUFFER_TOO_SMALL
) {
185 Buffer
= AllocateZeroPool(BufferSize
);
186 Status
= gRT
->GetVariable(
188 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
195 // Get the CRC computed
197 if (!EFI_ERROR(Status
)) {
198 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
201 SHELL_FREE_NON_NULL(Buffer
);
206 This function will populate the device path protocol parameter based on TheHandle.
208 @param[in] TheHandle Driver handle.
209 @param[in, out] FilePath On a sucessful return the device path to the handle.
211 @retval EFI_SUCCESS The device path was sucessfully returned.
212 @retval other A error from gBS->HandleProtocol.
218 GetDevicePathForDriverHandleDebug1 (
219 IN EFI_HANDLE TheHandle
,
220 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
224 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
225 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
227 Status
= gBS
->OpenProtocol (
229 &gEfiLoadedImageProtocolGuid
,
230 (VOID
**)&LoadedImage
,
233 EFI_OPEN_PROTOCOL_GET_PROTOCOL
235 if (!EFI_ERROR (Status
)) {
236 Status
= gBS
->OpenProtocol (
237 LoadedImage
->DeviceHandle
,
238 &gEfiDevicePathProtocolGuid
,
239 (VOID
**)&ImageDevicePath
,
242 EFI_OPEN_PROTOCOL_GET_PROTOCOL
244 if (!EFI_ERROR (Status
)) {
245 // *DevPath = DuplicateDevicePath (ImageDevicePath);
246 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
247 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
249 LoadedImage
->DeviceHandle
,
250 &gEfiDevicePathProtocolGuid
,
256 &gEfiLoadedImageProtocolGuid
,
264 Function to add a option.
266 @param[in] Position The position to add Target at.
267 @param[in] File The file to make the target.
268 @param[in] Desc The description text.
269 @param[in] CurrentOrder The pointer to the current order of items.
270 @param[in] OrderCount The number if items in CurrentOrder.
271 @param[in] Target The info on the option to add.
272 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
273 @param[in] UsePath TRUE to convert to devicepath.
274 @param[in] HandleNumber The handle number to add.
276 @retval SHELL_SUCCESS The operation was successful.
277 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
283 IN CONST CHAR16
*File
,
284 IN CONST CHAR16
*Desc
,
285 IN CONST UINT16
*CurrentOrder
,
286 IN CONST UINTN OrderCount
,
287 IN CONST BCFG_OPERATION_TARGET Target
,
288 IN CONST BOOLEAN UseHandle
,
289 IN CONST BOOLEAN UsePath
,
290 IN CONST UINTN HandleNumber
294 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
295 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
296 EFI_DEVICE_PATH_PROTOCOL
*FileNode
;
298 UINT8
*TempByteBuffer
;
299 UINT8
*TempByteStart
;
300 EFI_SHELL_FILE_INFO
*Arg
;
301 EFI_SHELL_FILE_INFO
*FileList
;
302 CHAR16 OptionStr
[40];
303 UINTN DescSize
, FilePathSize
;
305 UINTN TargetLocation
;
308 EFI_HANDLE CurHandle
;
309 UINTN DriverBindingHandleCount
;
310 UINTN ParentControllerHandleCount
;
311 UINTN ChildControllerHandleCount
;
312 SHELL_STATUS ShellStatus
;
316 if (File
== NULL
|| Desc
== NULL
) {
317 return (SHELL_INVALID_PARAMETER
);
320 if (HandleNumber
== 0) {
321 return (SHELL_INVALID_PARAMETER
);
325 if (Position
> OrderCount
) {
326 Position
= OrderCount
;
334 ShellStatus
= SHELL_SUCCESS
;
335 TargetLocation
= 0xFFFF;
338 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
339 if (CurHandle
== NULL
) {
340 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Handle Number");
341 ShellStatus
= SHELL_INVALID_PARAMETER
;
343 if (Target
== BcfgTargetBootOrder
) {
345 //Make sure that the handle should point to a real controller
347 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
349 &DriverBindingHandleCount
,
352 Status
= PARSE_HANDLE_DATABASE_PARENTS (
354 &ParentControllerHandleCount
,
357 Status
= ParseHandleDatabaseForChildControllers (
359 &ChildControllerHandleCount
,
362 if (DriverBindingHandleCount
> 0
363 || ParentControllerHandleCount
> 0
364 || ChildControllerHandleCount
> 0) {
366 Status
= gBS
->HandleProtocol (
368 &gEfiDevicePathProtocolGuid
,
371 if (EFI_ERROR (Status
)) {
372 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellDebug1HiiHandle
, HandleNumber
);
373 ShellStatus
= SHELL_INVALID_PARAMETER
;
377 //Make sure that the handle should point to driver, not a controller.
379 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
381 &DriverBindingHandleCount
,
384 Status
= PARSE_HANDLE_DATABASE_PARENTS (
386 &ParentControllerHandleCount
,
389 Status
= ParseHandleDatabaseForChildControllers (
391 &ChildControllerHandleCount
,
394 Status
= gBS
->HandleProtocol (
396 &gEfiDevicePathProtocolGuid
,
399 if (DriverBindingHandleCount
> 0
400 || ParentControllerHandleCount
> 0
401 || ChildControllerHandleCount
> 0
402 || !EFI_ERROR(Status
) ) {
403 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Handle Number");
404 ShellStatus
= SHELL_INVALID_PARAMETER
;
407 // Get the DevicePath from the loaded image information.
409 Status
= GetDevicePathForDriverHandleDebug1(CurHandle
, &FilePath
);
417 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
419 if (FileList
== NULL
) {
421 // If filename matched nothing fail
423 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, File
);
424 ShellStatus
= SHELL_INVALID_PARAMETER
;
425 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
427 // If filename expanded to multiple names, fail
429 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellDebug1HiiHandle
, File
);
430 ShellStatus
= SHELL_INVALID_PARAMETER
;
432 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
433 if (EFI_ERROR(Arg
->Status
)) {
434 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellDebug1HiiHandle
, File
, Arg
->Status
);
435 ShellStatus
= SHELL_INVALID_PARAMETER
;
438 // Build FilePath to the filename
442 // get the device path
444 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
445 if (DevicePath
== NULL
) {
446 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellDebug1HiiHandle
, Arg
->FullName
);
447 ShellStatus
= SHELL_UNSUPPORTED
;
451 DevPath = DevicePath;
452 while (!IsDevicePathEnd(DevPath)) {
453 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
454 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
457 // If we find it use it instead
459 DevicePath = DevPath;
462 DevPath = NextDevicePathNode(DevPath);
467 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
468 FileNode = FileDevicePath(NULL, StringWalker+1);
469 FilePath = AppendDevicePath(DevicePath, FileNode);
473 FilePath
= DuplicateDevicePath(DevicePath
);
477 FreePool(DevicePath
);
484 if (ShellStatus
== SHELL_SUCCESS
) {
486 // Find a free target ,a brute force implementation
489 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
491 for (Index
=0; Index
< OrderCount
; Index
++) {
492 if (CurrentOrder
[Index
] == TargetLocation
) {
503 if (TargetLocation
== 0xFFFF) {
504 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellDebug1HiiHandle
);
506 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellDebug1HiiHandle
, TargetLocation
);
510 if (ShellStatus
== SHELL_SUCCESS
) {
514 DescSize
= StrSize(Desc
);
515 FilePathSize
= GetDevicePathSize (FilePath
);
517 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
518 if (TempByteBuffer
!= NULL
) {
519 TempByteStart
= TempByteBuffer
;
520 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
521 TempByteBuffer
+= sizeof (UINT32
);
523 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
524 TempByteBuffer
+= sizeof (UINT16
);
526 CopyMem (TempByteBuffer
, Desc
, DescSize
);
527 TempByteBuffer
+= DescSize
;
528 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
530 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
531 Status
= gRT
->SetVariable (
533 &gEfiGlobalVariableGuid
,
534 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
535 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
539 FreePool(TempByteStart
);
541 Status
= EFI_OUT_OF_RESOURCES
;
544 if (EFI_ERROR(Status
)) {
545 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, OptionStr
, Status
);
547 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
548 ASSERT(NewOrder
!= NULL
);
549 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
552 // Insert target into order list
554 for (Index
=OrderCount
; Index
> Position
; Index
--) {
555 NewOrder
[Index
] = NewOrder
[Index
-1];
558 NewOrder
[Position
] = (UINT16
) TargetLocation
;
559 Status
= gRT
->SetVariable (
560 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
561 &gEfiGlobalVariableGuid
,
562 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
563 (OrderCount
+1) * sizeof(UINT16
),
569 if (EFI_ERROR(Status
)) {
570 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder", Status
);
571 ShellStatus
= SHELL_INVALID_PARAMETER
;
573 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
579 //If always Free FilePath, will free devicepath in system when use "addh"
581 if (FilePath
!=NULL
&& !UseHandle
) {
589 if (Handles
!= NULL
) {
593 if (FileList
!= NULL
) {
594 ShellCloseFileMetaArg (&FileList
);
597 return (ShellStatus
);
601 Funciton to remove an item.
603 @param[in] Target The target item to move.
604 @param[in] CurrentOrder The pointer to the current order of items.
605 @param[in] OrderCount The number if items in CurrentOrder.
606 @param[in] Location The current location of the Target.
608 @retval SHELL_SUCCESS The operation was successful.
609 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
614 IN CONST BCFG_OPERATION_TARGET Target
,
615 IN CONST UINT16
*CurrentOrder
,
616 IN CONST UINTN OrderCount
,
617 IN CONST UINT16 Location
620 CHAR16 VariableName
[12];
625 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
626 Status
= gRT
->SetVariable(
628 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
629 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
632 if (EFI_ERROR(Status
)) {
633 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
634 return (SHELL_INVALID_PARAMETER
);
636 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
637 if (NewOrder
!= NULL
) {
638 NewCount
= OrderCount
;
639 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
640 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
643 Status
= gRT
->SetVariable(
644 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
645 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
646 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
647 NewCount
*sizeof(NewOrder
[0]),
651 Status
= EFI_OUT_OF_RESOURCES
;
653 if (EFI_ERROR(Status
)) {
654 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
655 return (SHELL_INVALID_PARAMETER
);
657 return (SHELL_SUCCESS
);
661 Funciton to move a item to another location.
663 @param[in] Target The target item to move.
664 @param[in] CurrentOrder The pointer to the current order of items.
665 @param[in] OrderCount The number if items in CurrentOrder.
666 @param[in] OldLocation The current location of the Target.
667 @param[in] NewLocation The desired location of the Target.
669 @retval SHELL_SUCCESS The operation was successful.
670 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
675 IN CONST BCFG_OPERATION_TARGET Target
,
676 IN CONST UINT16
*CurrentOrder
,
677 IN CONST UINTN OrderCount
,
678 IN CONST UINT16 OldLocation
,
679 IN CONST UINT16 NewLocation
686 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
687 ASSERT(NewOrder
!= NULL
);
689 Temp
= CurrentOrder
[OldLocation
];
690 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
691 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
692 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
693 NewOrder
[NewLocation
] = Temp
;
696 Status
= gRT
->SetVariable(
697 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
698 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
699 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
700 OrderCount
*sizeof(CurrentOrder
[0]),
705 if (EFI_ERROR(Status
)) {
706 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
707 return (SHELL_INVALID_PARAMETER
);
709 return (SHELL_SUCCESS
);
713 Function to add optional data to an option.
715 @param[in] OptData The optional data to add.
716 @param[in] CurrentOrder The pointer to the current order of items.
717 @param[in] OrderCount The number if items in CurrentOrder.
718 @param[in] Target The target of the operation.
720 @retval SHELL_SUCCESS The operation was succesful.
725 IN CONST CHAR16
*OptData
,
726 IN CONST UINT16
*CurrentOrder
,
727 IN CONST UINTN OrderCount
,
728 IN CONST BCFG_OPERATION_TARGET Target
731 EFI_KEY_OPTION NewKeyOption
;
732 EFI_KEY_OPTION
*KeyOptionBuffer
;
733 SHELL_STATUS ShellStatus
;
739 CONST CHAR16
*Walker
;
744 CHAR16 VariableName
[12];
746 SHELL_FILE_HANDLE FileHandle
;
748 Status
= EFI_SUCCESS
;
749 ShellStatus
= SHELL_SUCCESS
;
753 KeyOptionBuffer
= NULL
;
755 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
757 while(Walker
[0] == L
' ') {
762 // Get the index of the variable we are changing.
764 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
765 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
766 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Option Index");
767 ShellStatus
= SHELL_INVALID_PARAMETER
;
768 return (ShellStatus
);
770 OptionIndex
= (UINT16
)Intermediate
;
772 Temp
= StrStr(Walker
, L
" ");
776 while(Walker
[0] == L
' ') {
781 // determine whether we have file with data, quote delimited information, or a hot-key
783 if (Walker
[0] == L
'\"') {
785 // quoted filename or quoted information.
787 Temp
= StrStr(Walker
+1, L
"\"");
788 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
789 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
790 ShellStatus
= SHELL_INVALID_PARAMETER
;
792 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
793 if (FileName
== NULL
) {
794 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
795 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
796 return (ShellStatus
);
798 Temp2
= StrStr(FileName
, L
"\"");
799 ASSERT(Temp2
!= NULL
);
800 Temp2
[0] = CHAR_NULL
;
802 if (StrLen(Temp2
)>0) {
803 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
804 ShellStatus
= SHELL_INVALID_PARAMETER
;
806 if (EFI_ERROR(ShellFileExists(Walker
))) {
808 // Not a file. must be misc information.
813 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
818 // filename or hot key information.
820 if (StrStr(Walker
, L
" ") == NULL
) {
824 if (EFI_ERROR(ShellFileExists(Walker
))) {
825 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellDebug1HiiHandle
, Walker
);
826 ShellStatus
= SHELL_INVALID_PARAMETER
;
828 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
831 if (Target
!= BcfgTargetBootOrder
) {
832 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellDebug1HiiHandle
);
833 ShellStatus
= SHELL_INVALID_PARAMETER
;
836 if (ShellStatus
== SHELL_SUCCESS
) {
838 // Get hot key information
840 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
841 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
842 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
843 ShellStatus
= SHELL_INVALID_PARAMETER
;
845 NewKeyOption
.KeyData
= (UINT32
)Intermediate
;
846 Temp
= StrStr(Walker
, L
" ");
850 while(Walker
[0] == L
' ') {
855 if (ShellStatus
== SHELL_SUCCESS
) {
857 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
858 // Re-allocate with the added information.
860 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_KEY_DATA
) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
)), &NewKeyOption
);
861 if (KeyOptionBuffer
== NULL
) {
862 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellDebug1HiiHandle
);
863 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
866 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
); LoopCounter
++) {
870 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
871 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
872 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
873 ShellStatus
= SHELL_INVALID_PARAMETER
;
875 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
876 Temp
= StrStr(Walker
, L
" ");
880 while(Walker
[0] == L
' ') {
887 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
888 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
889 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Walker
);
890 ShellStatus
= SHELL_INVALID_PARAMETER
;
892 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
893 Temp
= StrStr(Walker
, L
" ");
897 while(Walker
[0] == L
' ') {
902 if (ShellStatus
== SHELL_SUCCESS
) {
904 // Now do the BootOption / BootOptionCrc
906 ASSERT (OptionIndex
<= OrderCount
);
907 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
908 Status
= GetBootOptionCrcDebug1(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
909 if (EFI_ERROR(Status
)) {
910 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"Option Index");
911 ShellStatus
= SHELL_INVALID_PARAMETER
;
915 if (ShellStatus
== SHELL_SUCCESS
) {
916 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
< 0xFFFF ; KeyIndex
++) {
917 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
918 Status
= gRT
->GetVariable(
920 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
922 (UINTN
*)&Intermediate
,
924 if (Status
== EFI_NOT_FOUND
) {
928 Status
= gRT
->SetVariable(
930 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
931 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
932 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_KEY_DATA
) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
)),
934 if (EFI_ERROR(Status
)) {
935 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
936 ShellStatus
= SHELL_INVALID_PARAMETER
;
938 ASSERT(FileName
== NULL
&& Data
== NULL
);
944 // Shouldn't be possible to have have both. Neither is ok though.
946 ASSERT(FileName
== NULL
|| Data
== NULL
);
948 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
949 if (FileName
!= NULL
) {
951 // Open the file and populate the data buffer.
953 Status
= ShellOpenFileByName(
958 if (!EFI_ERROR(Status
)) {
959 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
961 Data
= AllocateZeroPool((UINTN
)Intermediate
);
963 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellDebug1HiiHandle
);
964 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
966 if (!EFI_ERROR(Status
)) {
967 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
970 Intermediate
= StrSize(Data
);
973 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
974 Status
= UpdateOptionalDataDebug1(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
975 if (EFI_ERROR(Status
)) {
976 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
977 ShellStatus
= SHELL_INVALID_PARAMETER
;
980 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
981 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
982 ShellStatus
= SHELL_INVALID_PARAMETER
;
986 SHELL_FREE_NON_NULL(Data
);
987 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
988 SHELL_FREE_NON_NULL(FileName
);
993 Function to dump the Bcfg information.
995 @param[in] Op The operation.
996 @param[in] OrderCount How many to dump.
997 @param[in] CurrentOrder The pointer to the current order of items.
998 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
1000 @retval SHELL_SUCCESS The dump was successful.
1001 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1005 BcfgDisplayDumpDebug1(
1006 IN CONST CHAR16
*Op
,
1007 IN CONST UINTN OrderCount
,
1008 IN CONST UINT16
*CurrentOrder
,
1009 IN CONST BOOLEAN VerboseOutput
1015 CHAR16 VariableName
[12];
1018 CHAR16
*DevPathString
;
1021 if (OrderCount
== 0) {
1022 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellDebug1HiiHandle
);
1023 return (SHELL_SUCCESS
);
1026 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1029 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1031 Status
= gRT
->GetVariable(
1033 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1037 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1038 Buffer
= AllocateZeroPool(BufferSize
);
1039 Status
= gRT
->GetVariable(
1041 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1047 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1048 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
1049 return (SHELL_INVALID_PARAMETER
);
1052 if ((*(UINT16
*)(Buffer
+4)) != 0) {
1053 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
1054 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
1055 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1058 DevPathString
= NULL
;
1064 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1065 gShellDebug1HiiHandle
,
1068 (CHAR16
*)(Buffer
+6),
1070 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
1071 if (VerboseOutput
) {
1072 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
1087 if (Buffer
!= NULL
) {
1090 if (DevPath
!= NULL
) {
1093 if (DevPathString
!= NULL
) {
1094 FreePool(DevPathString
);
1097 return (SHELL_SUCCESS
);
1101 Function to initialize the BCFG operation structure.
1103 @param[in] Struct The stuct to initialize.
1107 InitBcfgStructDebug1(
1108 IN BGFG_OPERATION
*Struct
1111 ASSERT(Struct
!= NULL
);
1112 Struct
->Target
= BcfgTargetMax
;
1113 Struct
->Type
= BcfgTypeMax
;
1114 Struct
->Number1
= 0;
1115 Struct
->Number2
= 0;
1116 Struct
->HandleIndex
= 0;
1117 Struct
->FileName
= NULL
;
1118 Struct
->Description
= NULL
;
1119 Struct
->Order
= NULL
;
1120 Struct
->OptData
= NULL
;
1124 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1126 {L
"-opt", TypeMaxValue
},
1131 Function for 'bcfg' command.
1133 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1134 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1138 ShellCommandRunBcfg (
1139 IN EFI_HANDLE ImageHandle
,
1140 IN EFI_SYSTEM_TABLE
*SystemTable
1144 LIST_ENTRY
*Package
;
1145 CHAR16
*ProblemParam
;
1146 SHELL_STATUS ShellStatus
;
1148 CONST CHAR16
*CurrentParam
;
1149 BGFG_OPERATION CurrentOperation
;
1151 UINT64 Intermediate
;
1154 ProblemParam
= NULL
;
1156 ShellStatus
= SHELL_SUCCESS
;
1158 InitBcfgStructDebug1(&CurrentOperation
);
1161 // initialize the shell lib (we must be in non-auto-init...)
1163 Status
= ShellInitialize();
1164 ASSERT_EFI_ERROR(Status
);
1166 Status
= CommandInit();
1167 ASSERT_EFI_ERROR(Status
);
1170 // parse the command line
1172 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1173 if (EFI_ERROR(Status
)) {
1174 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1175 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
1176 FreePool(ProblemParam
);
1177 ShellStatus
= SHELL_INVALID_PARAMETER
;
1183 // Read in if we are doing -OPT
1185 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1186 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1187 if (CurrentOperation
.OptData
== NULL
) {
1188 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellDebug1HiiHandle
, L
"-opt");
1189 ShellStatus
= SHELL_INVALID_PARAMETER
;
1191 CurrentOperation
.Type
= BcfgTypeOpt
;
1195 // small block to read the target of the operation
1197 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1198 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1200 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1201 ShellStatus
= SHELL_INVALID_PARAMETER
;
1202 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1203 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1204 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1205 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1207 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellDebug1HiiHandle
);
1208 ShellStatus
= SHELL_INVALID_PARAMETER
;
1213 // Read in the boot or driver order environment variable (not needed for opt)
1215 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1217 Status
= gRT
->GetVariable(
1218 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1219 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1222 CurrentOperation
.Order
);
1223 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1224 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1225 Status
= gRT
->GetVariable(
1226 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1227 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1230 CurrentOperation
.Order
);
1235 // large block to read the type of operation and verify parameter types for the info.
1237 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1238 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1239 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1240 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1241 CurrentOperation
.Type
= BcfgTypeDump
;
1242 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1243 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"-v (without dump)");
1244 ShellStatus
= SHELL_INVALID_PARAMETER
;
1245 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1246 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1247 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1248 ShellStatus
= SHELL_INVALID_PARAMETER
;
1250 CurrentOperation
.Type
= BcfgTypeAdd
;
1251 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1252 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1253 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1254 ShellStatus
= SHELL_INVALID_PARAMETER
;
1256 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1257 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1258 ASSERT(CurrentOperation
.FileName
== NULL
);
1259 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1260 ASSERT(CurrentOperation
.Description
== NULL
);
1261 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1263 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1264 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1265 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1266 ShellStatus
= SHELL_INVALID_PARAMETER
;
1268 CurrentOperation
.Type
= BcfgTypeAddp
;
1269 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1270 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1271 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1272 ShellStatus
= SHELL_INVALID_PARAMETER
;
1274 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1275 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1276 ASSERT(CurrentOperation
.FileName
== NULL
);
1277 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1278 ASSERT(CurrentOperation
.Description
== NULL
);
1279 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1281 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1282 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1283 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1284 ShellStatus
= SHELL_INVALID_PARAMETER
;
1286 CurrentOperation
.Type
= BcfgTypeAddh
;
1287 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1288 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1289 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1290 ShellStatus
= SHELL_INVALID_PARAMETER
;
1292 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1293 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1294 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1295 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1296 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1297 ShellStatus
= SHELL_INVALID_PARAMETER
;
1299 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1300 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1301 ASSERT(CurrentOperation
.Description
== NULL
);
1302 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1305 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1306 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1307 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1308 ShellStatus
= SHELL_INVALID_PARAMETER
;
1310 CurrentOperation
.Type
= BcfgTypeRm
;
1311 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1312 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1313 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1314 ShellStatus
= SHELL_INVALID_PARAMETER
;
1316 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1317 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1318 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1319 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1320 ShellStatus
= SHELL_INVALID_PARAMETER
;
1323 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1324 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1325 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
1326 ShellStatus
= SHELL_INVALID_PARAMETER
;
1328 CurrentOperation
.Type
= BcfgTypeMv
;
1329 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1330 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1331 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1332 ShellStatus
= SHELL_INVALID_PARAMETER
;
1334 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1335 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1336 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1337 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1338 ShellStatus
= SHELL_INVALID_PARAMETER
;
1340 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1341 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1342 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1343 ShellStatus
= SHELL_INVALID_PARAMETER
;
1345 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1346 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1348 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1349 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1350 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1352 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1353 ShellStatus
= SHELL_INVALID_PARAMETER
;
1357 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
1358 ShellStatus
= SHELL_INVALID_PARAMETER
;
1362 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1364 // we have all the info. Do the work
1366 switch (CurrentOperation
.Type
) {
1368 ShellStatus
= BcfgDisplayDumpDebug1(
1369 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1370 Length
/ sizeof(CurrentOperation
.Order
[0]),
1371 CurrentOperation
.Order
,
1372 ShellCommandLineGetFlag(Package
, L
"-v"));
1375 ShellStatus
= BcfgMoveDebug1(
1376 CurrentOperation
.Target
,
1377 CurrentOperation
.Order
,
1378 Length
/ sizeof(CurrentOperation
.Order
[0]),
1379 CurrentOperation
.Number1
,
1380 CurrentOperation
.Number2
);
1383 ShellStatus
= BcfgRemoveDebug1(
1384 CurrentOperation
.Target
,
1385 CurrentOperation
.Order
,
1386 Length
/ sizeof(CurrentOperation
.Order
[0]),
1387 CurrentOperation
.Number1
);
1392 ShellStatus
= BcfgAddDebug1(
1393 CurrentOperation
.Number1
,
1394 CurrentOperation
.FileName
,
1395 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1396 CurrentOperation
.Order
,
1397 Length
/ sizeof(CurrentOperation
.Order
[0]),
1398 CurrentOperation
.Target
,
1399 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1400 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1401 CurrentOperation
.HandleIndex
);
1404 ShellStatus
= BcfgAddOptDebug1(
1405 CurrentOperation
.OptData
,
1406 CurrentOperation
.Order
,
1407 Length
/ sizeof(CurrentOperation
.Order
[0]),
1408 CurrentOperation
.Target
);
1416 if (Package
!= NULL
) {
1417 ShellCommandLineFreeVarList (Package
);
1419 if (CurrentOperation
.FileName
!= NULL
) {
1420 FreePool(CurrentOperation
.FileName
);
1422 if (CurrentOperation
.Description
!= NULL
) {
1423 FreePool(CurrentOperation
.Description
);
1425 if (CurrentOperation
.Order
!= NULL
) {
1426 FreePool(CurrentOperation
.Order
);
1429 return (ShellStatus
);