2 Main file for bcfg shell Debug1 function.
4 Copyright (c) 2010 - 2011, 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 Function to add a option.
53 @param[in] Position The position to add Target at.
54 @param[in] File The file to make the target.
55 @param[in] Desc The description text.
56 @param[in] CurrentOrder The pointer to the current order of items.
57 @param[in] OrderCount The number if items in CurrentOrder.
58 @param[in] Target The info on the option to add.
59 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
60 @param[in] UsePath TRUE to convert to devicepath.
61 @param[in] HandleNumber The handle number to add.
63 @retval SHELL_SUCCESS The operation was successful.
64 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
70 IN CONST CHAR16
*File
,
71 IN CONST CHAR16
*Desc
,
72 IN CONST UINT16
*CurrentOrder
,
73 IN CONST UINTN OrderCount
,
74 IN CONST BCFG_OPERATION_TARGET Target
,
75 IN CONST BOOLEAN UseHandle
,
76 IN CONST BOOLEAN UsePath
,
77 IN CONST UINTN HandleNumber
81 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
82 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
83 EFI_DEVICE_PATH_PROTOCOL
*FileNode
;
84 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
86 CONST CHAR16
*StringWalker
;
87 UINT8
*TempByteBuffer
;
89 EFI_SHELL_FILE_INFO
*Arg
;
90 EFI_SHELL_FILE_INFO
*FileList
;
92 UINTN DescSize
, FilePathSize
;
98 UINTN DriverBindingHandleCount
;
99 UINTN ParentControllerHandleCount
;
100 UINTN ChildControllerHandleCount
;
101 SHELL_STATUS ShellStatus
;
106 if (File
== NULL
|| Desc
== NULL
) {
107 return (SHELL_INVALID_PARAMETER
);
110 if (HandleNumber
== 0) {
111 return (SHELL_INVALID_PARAMETER
);
115 if (Position
> OrderCount
) {
116 Position
= OrderCount
;
124 ShellStatus
= SHELL_SUCCESS
;
125 TargetLocation
= 0xFFFF;
128 Status
= ShellConvertStringToUint64(File
, &Intermediate
, TRUE
, FALSE
);
129 CurHandle
= ConvertHandleIndexToHandle((UINTN
)Intermediate
);
130 if (CurHandle
== NULL
|| EFI_ERROR(Status
)) {
131 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, File
);
132 ShellStatus
= SHELL_INVALID_PARAMETER
;
135 //Make sure that the handle should point to a real controller
137 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
139 &DriverBindingHandleCount
,
142 Status
= PARSE_HANDLE_DATABASE_PARENTS (
144 &ParentControllerHandleCount
,
147 Status
= ParseHandleDatabaseForChildControllers (
149 &ChildControllerHandleCount
,
152 if (DriverBindingHandleCount
> 0
153 || ParentControllerHandleCount
> 0
154 || ChildControllerHandleCount
> 0) {
156 Status
= gBS
->HandleProtocol (
158 &gEfiDevicePathProtocolGuid
,
161 if (EFI_ERROR (Status
)) {
162 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellDebug1HiiHandle
, Intermediate
);
163 ShellStatus
= SHELL_INVALID_PARAMETER
;
170 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
172 if (FileList
== NULL
) {
174 // If filename matched nothing fail
176 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, File
);
177 ShellStatus
= SHELL_INVALID_PARAMETER
;
178 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
180 // If filename expanded to multiple names, fail
182 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellDebug1HiiHandle
, File
);
183 ShellStatus
= SHELL_INVALID_PARAMETER
;
185 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
186 if (EFI_ERROR(Arg
->Status
)) {
187 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellDebug1HiiHandle
, File
, Arg
->Status
);
188 ShellStatus
= SHELL_INVALID_PARAMETER
;
191 // Build FilePath to the filename
195 // get the device path
197 DevicePath
= mEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
198 if (DevicePath
== NULL
) {
199 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellDebug1HiiHandle
, Arg
->FullName
);
200 ShellStatus
= SHELL_UNSUPPORTED
;
203 DevPath
= DevicePath
;
204 while (!IsDevicePathEnd(DevPath
)) {
205 if ((DevicePathType(DevPath
) == MEDIA_DEVICE_PATH
) &&
206 (DevicePathSubType(DevPath
) == MEDIA_HARDDRIVE_DP
)) {
209 // If we find it use it instead
211 DevicePath
= DevPath
;
214 DevPath
= NextDevicePathNode(DevPath
);
219 for(StringWalker
=Arg
->FullName
; *StringWalker
!= CHAR_NULL
&& *StringWalker
!= ':'; StringWalker
++);
220 FileNode
= FileDevicePath(NULL
, StringWalker
+1);
221 FilePath
= AppendDevicePath(DevicePath
, FileNode
);
224 FilePath
= DuplicateDevicePath(DevicePath
);
227 FreePool(DevicePath
);
234 if (ShellStatus
== SHELL_SUCCESS
) {
236 // Find a free target ,a brute force implementation
239 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
241 for (Index
=0; Index
< OrderCount
; Index
++) {
242 if (CurrentOrder
[Index
] == TargetLocation
) {
253 if (TargetLocation
== 0xFFFF) {
254 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellDebug1HiiHandle
);
256 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellDebug1HiiHandle
, TargetLocation
);
260 if (ShellStatus
== SHELL_SUCCESS
) {
264 DescSize
= StrSize(Desc
);
265 FilePathSize
= GetDevicePathSize (FilePath
);
267 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
268 if (TempByteBuffer
!= NULL
) {
269 TempByteStart
= TempByteBuffer
;
270 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
271 TempByteBuffer
+= sizeof (UINT32
);
273 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
274 TempByteBuffer
+= sizeof (UINT16
);
276 CopyMem (TempByteBuffer
, Desc
, DescSize
);
277 TempByteBuffer
+= DescSize
;
278 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
280 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
281 Status
= gRT
->SetVariable (
283 &gEfiGlobalVariableGuid
,
284 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
285 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
289 FreePool(TempByteStart
);
291 Status
= EFI_OUT_OF_RESOURCES
;
294 if (EFI_ERROR(Status
)) {
295 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellDebug1HiiHandle
, OptionStr
, Status
);
297 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
298 ASSERT(NewOrder
!= NULL
);
299 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
302 // Insert target into order list
304 for (Index
=OrderCount
; Index
> Position
; Index
--) {
305 NewOrder
[Index
] = NewOrder
[Index
-1];
308 NewOrder
[Position
] = (UINT16
) TargetLocation
;
309 Status
= gRT
->SetVariable (
310 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
311 &gEfiGlobalVariableGuid
,
312 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
313 (OrderCount
+1) * sizeof(UINT16
),
319 if (EFI_ERROR(Status
)) {
320 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder", Status
);
321 ShellStatus
= SHELL_INVALID_PARAMETER
;
323 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
329 //If always Free FilePath, will free devicepath in system when use "addh"
331 if (FilePath
!=NULL
&& !UseHandle
) {
339 if (Handles
!= NULL
) {
343 if (FileList
!= NULL
) {
344 ShellCloseFileMetaArg (&FileList
);
347 return (ShellStatus
);
351 Funciton to remove an item.
353 @param[in] Target The target item to move.
354 @param[in] CurrentOrder The pointer to the current order of items.
355 @param[in] OrderCount The number if items in CurrentOrder.
356 @param[in] Location The current location of the Target.
358 @retval SHELL_SUCCESS The operation was successful.
359 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
364 IN CONST BCFG_OPERATION_TARGET Target
,
365 IN CONST UINT16
*CurrentOrder
,
366 IN CONST UINTN OrderCount
,
367 IN CONST UINT16 Location
370 CHAR16 VariableName
[12];
376 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Location
);
377 Status
= gRT
->SetVariable(
379 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
380 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
383 if (EFI_ERROR(Status
)) {
384 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
385 return (SHELL_INVALID_PARAMETER
);
387 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
388 if (NewOrder
!= NULL
) {
389 NewCount
= OrderCount
;
390 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
391 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++){
392 if (NewOrder
[LoopVar
] == Location
) {
393 CopyMem(NewOrder
+LoopVar
, NewOrder
+LoopVar
+1, (OrderCount
- LoopVar
- 1)*sizeof(CurrentOrder
[0]));
397 Status
= gRT
->SetVariable(
398 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
399 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
400 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
401 NewCount
*sizeof(NewOrder
[0]),
405 Status
= EFI_OUT_OF_RESOURCES
;
407 if (EFI_ERROR(Status
)) {
408 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
409 return (SHELL_INVALID_PARAMETER
);
411 return (SHELL_SUCCESS
);
415 Funciton to move a item to another location.
417 @param[in] Target The target item to move.
418 @param[in] CurrentOrder The pointer to the current order of items.
419 @param[in] OrderCount The number if items in CurrentOrder.
420 @param[in] OldLocation The current location of the Target.
421 @param[in] NewLocation The desired location of the Target.
423 @retval SHELL_SUCCESS The operation was successful.
424 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
429 IN CONST BCFG_OPERATION_TARGET Target
,
430 IN CONST UINT16
*CurrentOrder
,
431 IN CONST UINTN OrderCount
,
432 IN CONST UINT16 OldLocation
,
433 IN CONST UINT16 NewLocation
440 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
441 ASSERT(NewOrder
!= NULL
);
443 Temp
= CurrentOrder
[OldLocation
];
444 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
445 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
446 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
447 NewOrder
[NewLocation
] = Temp
;
450 Status
= gRT
->SetVariable(
451 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
452 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
453 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
454 OrderCount
*sizeof(CurrentOrder
[0]),
459 if (EFI_ERROR(Status
)) {
460 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
461 return (SHELL_INVALID_PARAMETER
);
463 return (SHELL_SUCCESS
);
467 Function to add optional data to an option.
469 @param[in] OptData The optional data to add.
470 @param[in] Target The target of the operation.
472 @retval SHELL_SUCCESS The operation was succesful.
477 IN CONST CHAR16
*OptData
,
478 IN CONST BCFG_OPERATION_TARGET Target
481 ASSERT(OptData
!= NULL
);
482 return SHELL_SUCCESS
;
486 Function to dump the Bcfg information.
488 @param[in] Op The operation.
489 @param[in] OrderCount How many to dump.
490 @param[in] CurrentOrder The pointer to the current order of items.
491 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
493 @retval SHELL_SUCCESS The dump was successful.
494 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
498 BcfgDisplayDumpDebug1(
500 IN CONST UINTN OrderCount
,
501 IN CONST UINT16
*CurrentOrder
,
502 IN CONST BOOLEAN VerboseOutput
508 CHAR16 VariableName
[12];
511 CHAR16
*DevPathString
;
514 if (OrderCount
== 0) {
515 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellDebug1HiiHandle
);
516 return (SHELL_SUCCESS
);
519 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
522 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
524 Status
= gRT
->GetVariable(
526 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
530 if (Status
== EFI_BUFFER_TOO_SMALL
) {
531 Buffer
= AllocateZeroPool(BufferSize
);
532 Status
= gRT
->GetVariable(
534 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
540 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
541 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
542 return (SHELL_INVALID_PARAMETER
);
545 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
546 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
547 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
552 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
553 gShellDebug1HiiHandle
,
558 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
560 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
575 if (Buffer
!= NULL
) {
578 if (DevPath
!= NULL
) {
581 if (DevPathString
!= NULL
) {
582 FreePool(DevPathString
);
585 return (SHELL_SUCCESS
);
589 Function to initialize the BCFG operation structure.
591 @param[in] Struct The stuct to initialize.
595 InitBcfgStructDebug1(
596 IN BGFG_OPERATION
*Struct
599 ASSERT(Struct
!= NULL
);
600 Struct
->Target
= BcfgTargetMax
;
601 Struct
->Type
= BcfgTypeMax
;
604 Struct
->HandleIndex
= 0;
605 Struct
->FileName
= NULL
;
606 Struct
->Description
= NULL
;
607 Struct
->Order
= NULL
;
608 Struct
->OptData
= NULL
;
612 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
614 {L
"-opt", TypeMaxValue
},
619 Function for 'bcfg' command.
621 @param[in] ImageHandle Handle to the Image (NULL if Internal).
622 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
626 ShellCommandRunBcfg (
627 IN EFI_HANDLE ImageHandle
,
628 IN EFI_SYSTEM_TABLE
*SystemTable
633 CHAR16
*ProblemParam
;
634 SHELL_STATUS ShellStatus
;
636 CONST CHAR16
*CurrentParam
;
637 BGFG_OPERATION CurrentOperation
;
644 ShellStatus
= SHELL_SUCCESS
;
646 InitBcfgStructDebug1(&CurrentOperation
);
649 // initialize the shell lib (we must be in non-auto-init...)
651 Status
= ShellInitialize();
652 ASSERT_EFI_ERROR(Status
);
654 Status
= CommandInit();
655 ASSERT_EFI_ERROR(Status
);
658 // parse the command line
660 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
661 if (EFI_ERROR(Status
)) {
662 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
663 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
664 FreePool(ProblemParam
);
665 ShellStatus
= SHELL_INVALID_PARAMETER
;
671 // Read in if we are doing -OPT
673 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
674 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
675 if (CurrentOperation
.OptData
== NULL
) {
676 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellDebug1HiiHandle
, L
"-opt");
677 ShellStatus
= SHELL_INVALID_PARAMETER
;
679 CurrentOperation
.Type
= BcfgTypeOpt
;
683 // small block to read the target of the operation
685 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
686 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
688 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
689 ShellStatus
= SHELL_INVALID_PARAMETER
;
690 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
691 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
692 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
693 CurrentOperation
.Target
= BcfgTargetBootOrder
;
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellDebug1HiiHandle
);
696 ShellStatus
= SHELL_INVALID_PARAMETER
;
701 // Read in the boot or driver order environment variable (not needed for opt)
703 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
!= BcfgTypeOpt
) {
705 Status
= gRT
->GetVariable(
706 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
707 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
710 CurrentOperation
.Order
);
711 if (Status
== EFI_BUFFER_TOO_SMALL
) {
712 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
713 Status
= gRT
->GetVariable(
714 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
715 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
718 CurrentOperation
.Order
);
723 // large block to read the type of operation and verify parameter types for the info.
725 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
726 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
727 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
728 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
729 CurrentOperation
.Type
= BcfgTypeDump
;
730 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
731 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"-v (without dump)");
732 ShellStatus
= SHELL_INVALID_PARAMETER
;
733 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
734 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
735 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
736 ShellStatus
= SHELL_INVALID_PARAMETER
;
738 CurrentOperation
.Type
= BcfgTypeAdd
;
739 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
740 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
741 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
742 ShellStatus
= SHELL_INVALID_PARAMETER
;
744 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
745 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
746 ASSERT(CurrentOperation
.FileName
== NULL
);
747 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
748 ASSERT(CurrentOperation
.Description
== NULL
);
749 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
751 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
752 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
753 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
754 ShellStatus
= SHELL_INVALID_PARAMETER
;
756 CurrentOperation
.Type
= BcfgTypeAddp
;
757 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
758 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
759 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
760 ShellStatus
= SHELL_INVALID_PARAMETER
;
762 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
763 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
764 ASSERT(CurrentOperation
.FileName
== NULL
);
765 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
766 ASSERT(CurrentOperation
.Description
== NULL
);
767 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
769 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
770 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
771 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
772 ShellStatus
= SHELL_INVALID_PARAMETER
;
774 CurrentOperation
.Type
= BcfgTypeAddh
;
775 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
776 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
777 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
778 ShellStatus
= SHELL_INVALID_PARAMETER
;
780 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
781 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
782 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
783 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
784 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
785 ShellStatus
= SHELL_INVALID_PARAMETER
;
787 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
788 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
789 ASSERT(CurrentOperation
.Description
== NULL
);
790 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
793 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
794 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
795 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
796 ShellStatus
= SHELL_INVALID_PARAMETER
;
798 CurrentOperation
.Type
= BcfgTypeRm
;
799 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
800 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
801 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
802 ShellStatus
= SHELL_INVALID_PARAMETER
;
804 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
805 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
806 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
807 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
808 ShellStatus
= SHELL_INVALID_PARAMETER
;
811 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
812 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
813 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
814 ShellStatus
= SHELL_INVALID_PARAMETER
;
816 CurrentOperation
.Type
= BcfgTypeMv
;
817 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
818 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
819 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
820 ShellStatus
= SHELL_INVALID_PARAMETER
;
822 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
823 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
824 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
825 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
826 ShellStatus
= SHELL_INVALID_PARAMETER
;
828 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
829 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
830 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
831 ShellStatus
= SHELL_INVALID_PARAMETER
;
833 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
834 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
836 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
837 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
838 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
840 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
841 ShellStatus
= SHELL_INVALID_PARAMETER
;
845 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
846 ShellStatus
= SHELL_INVALID_PARAMETER
;
850 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
852 // we have all the info. Do the work
854 switch (CurrentOperation
.Type
) {
856 ShellStatus
= BcfgDisplayDumpDebug1(
857 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
858 Length
/ sizeof(CurrentOperation
.Order
[0]),
859 CurrentOperation
.Order
,
860 ShellCommandLineGetFlag(Package
, L
"-v"));
863 ShellStatus
= BcfgMoveDebug1(
864 CurrentOperation
.Target
,
865 CurrentOperation
.Order
,
866 Length
/ sizeof(CurrentOperation
.Order
[0]),
867 CurrentOperation
.Number1
,
868 CurrentOperation
.Number2
);
871 ShellStatus
= BcfgRemoveDebug1(
872 CurrentOperation
.Target
,
873 CurrentOperation
.Order
,
874 Length
/ sizeof(CurrentOperation
.Order
[0]),
875 CurrentOperation
.Number1
);
880 ShellStatus
= BcfgAddDebug1(
881 CurrentOperation
.Number1
,
882 CurrentOperation
.FileName
,
883 CurrentOperation
.Description
,
884 CurrentOperation
.Order
,
885 Length
/ sizeof(CurrentOperation
.Order
[0]),
886 CurrentOperation
.Target
,
887 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
888 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
889 CurrentOperation
.HandleIndex
);
892 ShellStatus
= BcfgAddOptDebug1(
893 CurrentOperation
.OptData
,
894 CurrentOperation
.Target
);
902 if (Package
!= NULL
) {
903 ShellCommandLineFreeVarList (Package
);
905 if (CurrentOperation
.FileName
!= NULL
) {
906 FreePool(CurrentOperation
.FileName
);
908 if (CurrentOperation
.Description
!= NULL
) {
909 FreePool(CurrentOperation
.Description
);
911 if (CurrentOperation
.Order
!= NULL
) {
912 FreePool(CurrentOperation
.Order
);
915 return (ShellStatus
);