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
);
327 if (FileNode
!= NULL
) {
332 //If always Free FilePath, will free devicepath in system when use "addh"
335 if (FilePath
!=NULL
&& !UseHandle
) {
343 if (Handles
!= NULL
) {
347 if (FileList
!= NULL
) {
348 ShellCloseFileMetaArg (&FileList
);
351 return (ShellStatus
);
355 Funciton to remove an item.
357 @param[in] Target The target item to move.
358 @param[in] CurrentOrder The pointer to the current order of items.
359 @param[in] OrderCount The number if items in CurrentOrder.
360 @param[in] Location The current location of the Target.
362 @retval SHELL_SUCCESS The operation was successful.
363 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
368 IN CONST BCFG_OPERATION_TARGET Target
,
369 IN CONST UINT16
*CurrentOrder
,
370 IN CONST UINTN OrderCount
,
371 IN CONST UINT16 Location
374 CHAR16 VariableName
[12];
380 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Location
);
381 Status
= gRT
->SetVariable(
383 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
384 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
387 if (EFI_ERROR(Status
)) {
388 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
389 return (SHELL_INVALID_PARAMETER
);
391 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
392 if (NewOrder
!= NULL
) {
393 NewCount
= OrderCount
;
394 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
395 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++){
396 if (NewOrder
[LoopVar
] == Location
) {
397 CopyMem(NewOrder
+LoopVar
, NewOrder
+LoopVar
+1, (OrderCount
- LoopVar
- 1)*sizeof(CurrentOrder
[0]));
401 Status
= gRT
->SetVariable(
402 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
403 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
404 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
405 NewCount
*sizeof(NewOrder
[0]),
409 Status
= EFI_OUT_OF_RESOURCES
;
411 if (EFI_ERROR(Status
)) {
412 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
413 return (SHELL_INVALID_PARAMETER
);
415 return (SHELL_SUCCESS
);
419 Funciton to move a item to another location.
421 @param[in] Target The target item to move.
422 @param[in] CurrentOrder The pointer to the current order of items.
423 @param[in] OrderCount The number if items in CurrentOrder.
424 @param[in] OldLocation The current location of the Target.
425 @param[in] NewLocation The desired location of the Target.
427 @retval SHELL_SUCCESS The operation was successful.
428 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
433 IN CONST BCFG_OPERATION_TARGET Target
,
434 IN CONST UINT16
*CurrentOrder
,
435 IN CONST UINTN OrderCount
,
436 IN CONST UINT16 OldLocation
,
437 IN CONST UINT16 NewLocation
444 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
445 ASSERT(NewOrder
!= NULL
);
447 Temp
= CurrentOrder
[OldLocation
];
448 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
449 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
450 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
451 NewOrder
[NewLocation
] = Temp
;
454 Status
= gRT
->SetVariable(
455 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
456 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
457 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
458 OrderCount
*sizeof(CurrentOrder
[0]),
463 if (EFI_ERROR(Status
)) {
464 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellDebug1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
465 return (SHELL_INVALID_PARAMETER
);
467 return (SHELL_SUCCESS
);
473 IN CONST CHAR16
*OptData
,
474 IN CONST BCFG_OPERATION_TARGET Target
477 ASSERT(OptData
!= NULL
);
478 return SHELL_SUCCESS
;
482 Function to dump the Bcfg information.
484 @param[in] Op The operation.
485 @param[in] OrderCount How many to dump.
486 @param[in] CurrentOrder The pointer to the current order of items.
487 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
489 @retval SHELL_SUCCESS The dump was successful.
490 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
494 BcfgDisplayDumpDebug1(
496 IN CONST UINTN OrderCount
,
497 IN CONST UINT16
*CurrentOrder
,
498 IN CONST BOOLEAN VerboseOutput
504 CHAR16 VariableName
[12];
507 CHAR16
*DevPathString
;
510 if (OrderCount
== 0) {
511 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellDebug1HiiHandle
);
512 return (SHELL_SUCCESS
);
515 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
518 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
520 Status
= gRT
->GetVariable(
522 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
526 if (Status
== EFI_BUFFER_TOO_SMALL
) {
527 Buffer
= AllocateZeroPool(BufferSize
);
528 Status
= gRT
->GetVariable(
530 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
536 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
537 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellDebug1HiiHandle
, VariableName
, Status
);
538 return (SHELL_INVALID_PARAMETER
);
541 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
542 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
543 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
548 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
549 gShellDebug1HiiHandle
,
554 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
556 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
571 if (Buffer
!= NULL
) {
574 if (DevPath
!= NULL
) {
577 if (DevPathString
!= NULL
) {
578 FreePool(DevPathString
);
581 return (SHELL_SUCCESS
);
585 Function to initialize the BCFG operation structure.
587 @param[in] Struct The stuct to initialize.
591 InitBcfgStructDebug1(
592 IN BGFG_OPERATION
*Struct
595 ASSERT(Struct
!= NULL
);
596 Struct
->Target
= BcfgTargetMax
;
597 Struct
->Type
= BcfgTypeMax
;
600 Struct
->HandleIndex
= 0;
601 Struct
->FileName
= NULL
;
602 Struct
->Description
= NULL
;
603 Struct
->Order
= NULL
;
604 Struct
->OptData
= NULL
;
608 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
610 {L
"-opt", TypeMaxValue
},
615 Function for 'bcfg' command.
617 @param[in] ImageHandle Handle to the Image (NULL if Internal).
618 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
622 ShellCommandRunBcfg (
623 IN EFI_HANDLE ImageHandle
,
624 IN EFI_SYSTEM_TABLE
*SystemTable
629 CHAR16
*ProblemParam
;
630 SHELL_STATUS ShellStatus
;
632 CONST CHAR16
*CurrentParam
;
633 BGFG_OPERATION CurrentOperation
;
640 ShellStatus
= SHELL_SUCCESS
;
642 InitBcfgStructDebug1(&CurrentOperation
);
645 // initialize the shell lib (we must be in non-auto-init...)
647 Status
= ShellInitialize();
648 ASSERT_EFI_ERROR(Status
);
650 Status
= CommandInit();
651 ASSERT_EFI_ERROR(Status
);
654 // parse the command line
656 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
657 if (EFI_ERROR(Status
)) {
658 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
659 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
660 FreePool(ProblemParam
);
661 ShellStatus
= SHELL_INVALID_PARAMETER
;
667 // Read in if we are doing -OPT
669 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
670 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
671 if (CurrentOperation
.OptData
== NULL
) {
672 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellDebug1HiiHandle
, L
"-opt");
673 ShellStatus
= SHELL_INVALID_PARAMETER
;
675 CurrentOperation
.Type
= BcfgTypeOpt
;
679 // small block to read the target of the operation
681 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
682 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
684 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
685 ShellStatus
= SHELL_INVALID_PARAMETER
;
686 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
687 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
688 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
689 CurrentOperation
.Target
= BcfgTargetBootOrder
;
691 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellDebug1HiiHandle
);
692 ShellStatus
= SHELL_INVALID_PARAMETER
;
697 // Read in the boot or driver order environment variable (not needed for opt)
699 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
!= BcfgTypeOpt
) {
701 Status
= gRT
->GetVariable(
702 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
703 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
706 CurrentOperation
.Order
);
707 if (Status
== EFI_BUFFER_TOO_SMALL
) {
708 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
709 Status
= gRT
->GetVariable(
710 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
711 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
714 CurrentOperation
.Order
);
719 // large block to read the type of operation and verify parameter types for the info.
721 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
722 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
723 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
724 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
725 CurrentOperation
.Type
= BcfgTypeDump
;
726 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
727 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"-v (without dump)");
728 ShellStatus
= SHELL_INVALID_PARAMETER
;
729 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
730 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
731 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
732 ShellStatus
= SHELL_INVALID_PARAMETER
;
734 CurrentOperation
.Type
= BcfgTypeAdd
;
735 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
736 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
737 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
738 ShellStatus
= SHELL_INVALID_PARAMETER
;
740 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
741 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
742 ASSERT(CurrentOperation
.FileName
== NULL
);
743 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
744 ASSERT(CurrentOperation
.Description
== NULL
);
745 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
747 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
748 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
749 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
750 ShellStatus
= SHELL_INVALID_PARAMETER
;
752 CurrentOperation
.Type
= BcfgTypeAddp
;
753 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
754 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
755 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
756 ShellStatus
= SHELL_INVALID_PARAMETER
;
758 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
759 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
760 ASSERT(CurrentOperation
.FileName
== NULL
);
761 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
762 ASSERT(CurrentOperation
.Description
== NULL
);
763 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
765 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
766 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
767 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
768 ShellStatus
= SHELL_INVALID_PARAMETER
;
770 CurrentOperation
.Type
= BcfgTypeAddh
;
771 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
772 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
773 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
774 ShellStatus
= SHELL_INVALID_PARAMETER
;
776 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
777 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
778 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
779 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
780 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
781 ShellStatus
= SHELL_INVALID_PARAMETER
;
783 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
784 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
785 ASSERT(CurrentOperation
.Description
== NULL
);
786 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
789 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
790 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
791 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
792 ShellStatus
= SHELL_INVALID_PARAMETER
;
794 CurrentOperation
.Type
= BcfgTypeRm
;
795 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
796 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
797 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
798 ShellStatus
= SHELL_INVALID_PARAMETER
;
800 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
801 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
802 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
803 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
804 ShellStatus
= SHELL_INVALID_PARAMETER
;
807 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
808 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
809 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
810 ShellStatus
= SHELL_INVALID_PARAMETER
;
812 CurrentOperation
.Type
= BcfgTypeMv
;
813 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
814 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
815 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
816 ShellStatus
= SHELL_INVALID_PARAMETER
;
818 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
819 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
820 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
821 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
822 ShellStatus
= SHELL_INVALID_PARAMETER
;
824 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
825 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
826 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
827 ShellStatus
= SHELL_INVALID_PARAMETER
;
829 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
830 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
832 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
833 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
834 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
836 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellDebug1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
837 ShellStatus
= SHELL_INVALID_PARAMETER
;
841 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, CurrentParam
);
842 ShellStatus
= SHELL_INVALID_PARAMETER
;
846 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
848 // we have all the info. Do the work
850 switch (CurrentOperation
.Type
) {
852 ShellStatus
= BcfgDisplayDumpDebug1(
853 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
854 Length
/ sizeof(CurrentOperation
.Order
[0]),
855 CurrentOperation
.Order
,
856 ShellCommandLineGetFlag(Package
, L
"-v"));
859 ShellStatus
= BcfgMoveDebug1(
860 CurrentOperation
.Target
,
861 CurrentOperation
.Order
,
862 Length
/ sizeof(CurrentOperation
.Order
[0]),
863 CurrentOperation
.Number1
,
864 CurrentOperation
.Number2
);
867 ShellStatus
= BcfgRemoveDebug1(
868 CurrentOperation
.Target
,
869 CurrentOperation
.Order
,
870 Length
/ sizeof(CurrentOperation
.Order
[0]),
871 CurrentOperation
.Number1
);
876 ShellStatus
= BcfgAddDebug1(
877 CurrentOperation
.Number1
,
878 CurrentOperation
.FileName
,
879 CurrentOperation
.Description
,
880 CurrentOperation
.Order
,
881 Length
/ sizeof(CurrentOperation
.Order
[0]),
882 CurrentOperation
.Target
,
883 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
884 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
885 CurrentOperation
.HandleIndex
);
888 ShellStatus
= BcfgAddOptDebug1(
889 CurrentOperation
.OptData
,
890 CurrentOperation
.Target
);
898 if (Package
!= NULL
) {
899 ShellCommandLineFreeVarList (Package
);
901 if (CurrentOperation
.FileName
!= NULL
) {
902 FreePool(CurrentOperation
.FileName
);
904 if (CurrentOperation
.Description
!= NULL
) {
905 FreePool(CurrentOperation
.Description
);
907 if (CurrentOperation
.Order
!= NULL
) {
908 FreePool(CurrentOperation
.Order
);
911 return (ShellStatus
);