2 Main file for bcfg shell Install1 function.
4 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellInstall1CommandsLib.h"
16 #include <Guid/GlobalVariable.h>
17 #include <Library/PrintLib.h>
18 #include <Library/HandleParsingLib.h>
19 #include <Library/DevicePathLib.h>
22 BcfgTargetBootOrder
= 0,
23 BcfgTargetDriverOrder
= 1,
25 } BCFG_OPERATION_TARGET
;
36 } BCFG_OPERATION_TYPE
;
39 BCFG_OPERATION_TARGET Target
;
40 BCFG_OPERATION_TYPE Type
;
47 CONST CHAR16
*OptData
;
51 Update the optional data for a boot or driver option.
53 If optional data exists it will be changed.
55 @param[in] Index The boot or driver option index update.
56 @param[in] DataSize The size in bytes of Data.
57 @param[in] Data The buffer for the optioanl data.
58 @param[in] Target The target of the operation.
60 @retval EFI_SUCCESS The data was sucessfully updated.
61 @retval other A error occured.
69 IN CONST BCFG_OPERATION_TARGET Target
73 CHAR16 VariableName
[12];
78 UINTN OriginalOptionDataSize
;
80 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
87 Status
= gRT
->GetVariable(
89 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
93 if (Status
== EFI_BUFFER_TOO_SMALL
) {
94 OriginalData
= AllocateZeroPool(OriginalSize
);
95 if (OriginalData
== NULL
) {
96 return (EFI_OUT_OF_RESOURCES
);
98 Status
= gRT
->GetVariable(
100 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
106 if (!EFI_ERROR(Status
)) {
108 // Allocate new struct and discard old optional data.
110 ASSERT (OriginalData
!= NULL
);
111 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
112 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
113 OriginalOptionDataSize
-= OriginalSize
;
114 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
115 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
116 if (NewData
== NULL
) {
117 Status
= EFI_OUT_OF_RESOURCES
;
119 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
123 if (!EFI_ERROR(Status
)) {
125 // put the data back under the variable
127 Status
= gRT
->SetVariable(
129 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
130 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
135 SHELL_FREE_NON_NULL(OriginalData
);
136 SHELL_FREE_NON_NULL(NewData
);
141 This function will get a CRC for a boot option.
143 @param[in, out] Crc The CRC value to return.
144 @param[in] BootIndex The boot option index to CRC.
146 @retval EFI_SUCCESS The CRC was sucessfully returned.
147 @retval other A error occured.
156 CHAR16 VariableName
[12];
165 // Get the data Buffer
167 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
168 Status
= gRT
->GetVariable(
170 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
174 if (Status
== EFI_BUFFER_TOO_SMALL
) {
175 Buffer
= AllocateZeroPool(BufferSize
);
176 Status
= gRT
->GetVariable(
178 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
185 // Get the CRC computed
187 if (!EFI_ERROR(Status
)) {
188 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
191 SHELL_FREE_NON_NULL(Buffer
);
196 This function will populate the device path protocol parameter based on TheHandle.
198 @param[in] TheHandle Driver handle.
199 @param[in, out] FilePath On a sucessful return the device path to the handle.
201 @retval EFI_SUCCESS The device path was sucessfully returned.
202 @retval other A error from gBS->HandleProtocol.
208 GetDevicePathForDriverHandleInstall1 (
209 IN EFI_HANDLE TheHandle
,
210 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
214 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
215 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
217 Status
= gBS
->OpenProtocol (
219 &gEfiLoadedImageProtocolGuid
,
220 (VOID
**)&LoadedImage
,
223 EFI_OPEN_PROTOCOL_GET_PROTOCOL
225 if (!EFI_ERROR (Status
)) {
226 Status
= gBS
->OpenProtocol (
227 LoadedImage
->DeviceHandle
,
228 &gEfiDevicePathProtocolGuid
,
229 (VOID
**)&ImageDevicePath
,
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL
234 if (!EFI_ERROR (Status
)) {
235 // *DevPath = DuplicateDevicePath (ImageDevicePath);
236 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
237 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
239 LoadedImage
->DeviceHandle
,
240 &gEfiDevicePathProtocolGuid
,
246 &gEfiLoadedImageProtocolGuid
,
254 Function to add a option.
256 @param[in] Position The position to add Target at.
257 @param[in] File The file to make the target.
258 @param[in] Desc The description text.
259 @param[in] CurrentOrder The pointer to the current order of items.
260 @param[in] OrderCount The number if items in CurrentOrder.
261 @param[in] Target The info on the option to add.
262 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
263 @param[in] UsePath TRUE to convert to devicepath.
264 @param[in] HandleNumber The handle number to add.
266 @retval SHELL_SUCCESS The operation was successful.
267 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
273 IN CONST CHAR16
*File
,
274 IN CONST CHAR16
*Desc
,
275 IN CONST UINT16
*CurrentOrder
,
276 IN CONST UINTN OrderCount
,
277 IN CONST BCFG_OPERATION_TARGET Target
,
278 IN CONST BOOLEAN UseHandle
,
279 IN CONST BOOLEAN UsePath
,
280 IN CONST UINTN HandleNumber
284 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
285 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
287 UINT8
*TempByteBuffer
;
288 UINT8
*TempByteStart
;
289 EFI_SHELL_FILE_INFO
*Arg
;
290 EFI_SHELL_FILE_INFO
*FileList
;
291 CHAR16 OptionStr
[40];
292 UINTN DescSize
, FilePathSize
;
294 UINTN TargetLocation
;
297 EFI_HANDLE CurHandle
;
298 UINTN DriverBindingHandleCount
;
299 UINTN ParentControllerHandleCount
;
300 UINTN ChildControllerHandleCount
;
301 SHELL_STATUS ShellStatus
;
305 if (File
== NULL
|| Desc
== NULL
) {
306 return (SHELL_INVALID_PARAMETER
);
309 if (HandleNumber
== 0) {
310 return (SHELL_INVALID_PARAMETER
);
314 if (Position
> OrderCount
) {
315 Position
= OrderCount
;
322 ShellStatus
= SHELL_SUCCESS
;
323 TargetLocation
= 0xFFFF;
326 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
327 if (CurHandle
== NULL
) {
328 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Handle Number");
329 ShellStatus
= SHELL_INVALID_PARAMETER
;
331 if (Target
== BcfgTargetBootOrder
) {
333 //Make sure that the handle should point to a real controller
335 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
337 &DriverBindingHandleCount
,
340 Status
= PARSE_HANDLE_DATABASE_PARENTS (
342 &ParentControllerHandleCount
,
345 Status
= ParseHandleDatabaseForChildControllers (
347 &ChildControllerHandleCount
,
350 if (DriverBindingHandleCount
> 0
351 || ParentControllerHandleCount
> 0
352 || ChildControllerHandleCount
> 0) {
354 Status
= gBS
->HandleProtocol (
356 &gEfiDevicePathProtocolGuid
,
359 if (EFI_ERROR (Status
)) {
360 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellInstall1HiiHandle
, HandleNumber
);
361 ShellStatus
= SHELL_INVALID_PARAMETER
;
365 //Make sure that the handle should point to driver, not a controller.
367 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
369 &DriverBindingHandleCount
,
372 Status
= PARSE_HANDLE_DATABASE_PARENTS (
374 &ParentControllerHandleCount
,
377 Status
= ParseHandleDatabaseForChildControllers (
379 &ChildControllerHandleCount
,
382 Status
= gBS
->HandleProtocol (
384 &gEfiDevicePathProtocolGuid
,
387 if (DriverBindingHandleCount
> 0
388 || ParentControllerHandleCount
> 0
389 || ChildControllerHandleCount
> 0
390 || !EFI_ERROR(Status
) ) {
391 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Handle Number");
392 ShellStatus
= SHELL_INVALID_PARAMETER
;
395 // Get the DevicePath from the loaded image information.
397 Status
= GetDevicePathForDriverHandleInstall1(CurHandle
, &FilePath
);
405 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
407 if (FileList
== NULL
) {
409 // If filename matched nothing fail
411 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellInstall1HiiHandle
, File
);
412 ShellStatus
= SHELL_INVALID_PARAMETER
;
413 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
415 // If filename expanded to multiple names, fail
417 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellInstall1HiiHandle
, File
);
418 ShellStatus
= SHELL_INVALID_PARAMETER
;
420 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
421 if (EFI_ERROR(Arg
->Status
)) {
422 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellInstall1HiiHandle
, File
, Arg
->Status
);
423 ShellStatus
= SHELL_INVALID_PARAMETER
;
426 // Build FilePath to the filename
430 // get the device path
432 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
433 if (DevicePath
== NULL
) {
434 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellInstall1HiiHandle
, Arg
->FullName
);
435 ShellStatus
= SHELL_UNSUPPORTED
;
439 DevPath = DevicePath;
440 while (!IsDevicePathEnd(DevPath)) {
441 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
442 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
445 // If we find it use it instead
447 DevicePath = DevPath;
450 DevPath = NextDevicePathNode(DevPath);
455 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
456 FileNode = FileDevicePath(NULL, StringWalker+1);
457 FilePath = AppendDevicePath(DevicePath, FileNode);
461 FilePath
= DuplicateDevicePath(DevicePath
);
465 FreePool(DevicePath
);
472 if (ShellStatus
== SHELL_SUCCESS
) {
474 // Find a free target ,a brute force implementation
477 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
479 for (Index
=0; Index
< OrderCount
; Index
++) {
480 if (CurrentOrder
[Index
] == TargetLocation
) {
491 if (TargetLocation
== 0xFFFF) {
492 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellInstall1HiiHandle
);
494 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellInstall1HiiHandle
, TargetLocation
);
498 if (ShellStatus
== SHELL_SUCCESS
) {
502 DescSize
= StrSize(Desc
);
503 FilePathSize
= GetDevicePathSize (FilePath
);
505 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
506 if (TempByteBuffer
!= NULL
) {
507 TempByteStart
= TempByteBuffer
;
508 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
509 TempByteBuffer
+= sizeof (UINT32
);
511 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
512 TempByteBuffer
+= sizeof (UINT16
);
514 CopyMem (TempByteBuffer
, Desc
, DescSize
);
515 TempByteBuffer
+= DescSize
;
516 ASSERT (FilePath
!= NULL
);
517 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
519 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
520 Status
= gRT
->SetVariable (
522 &gEfiGlobalVariableGuid
,
523 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
524 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
528 FreePool(TempByteStart
);
530 Status
= EFI_OUT_OF_RESOURCES
;
533 if (EFI_ERROR(Status
)) {
534 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, OptionStr
, Status
);
536 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
537 ASSERT(NewOrder
!= NULL
);
538 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
541 // Insert target into order list
543 for (Index
=OrderCount
; Index
> Position
; Index
--) {
544 NewOrder
[Index
] = NewOrder
[Index
-1];
547 NewOrder
[Position
] = (UINT16
) TargetLocation
;
548 Status
= gRT
->SetVariable (
549 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
550 &gEfiGlobalVariableGuid
,
551 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
552 (OrderCount
+1) * sizeof(UINT16
),
558 if (EFI_ERROR(Status
)) {
559 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder", Status
);
560 ShellStatus
= SHELL_INVALID_PARAMETER
;
562 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
568 //If always Free FilePath, will free devicepath in system when use "addh"
570 if (FilePath
!=NULL
&& !UseHandle
) {
578 if (Handles
!= NULL
) {
582 if (FileList
!= NULL
) {
583 ShellCloseFileMetaArg (&FileList
);
586 return (ShellStatus
);
590 Funciton to remove an item.
592 @param[in] Target The target item to move.
593 @param[in] CurrentOrder The pointer to the current order of items.
594 @param[in] OrderCount The number if items in CurrentOrder.
595 @param[in] Location The current location of the Target.
597 @retval SHELL_SUCCESS The operation was successful.
598 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
603 IN CONST BCFG_OPERATION_TARGET Target
,
604 IN CONST UINT16
*CurrentOrder
,
605 IN CONST UINTN OrderCount
,
606 IN CONST UINT16 Location
609 CHAR16 VariableName
[12];
614 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
615 Status
= gRT
->SetVariable(
617 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
618 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
621 if (EFI_ERROR(Status
)) {
622 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
623 return (SHELL_INVALID_PARAMETER
);
625 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
626 if (NewOrder
!= NULL
) {
627 NewCount
= OrderCount
;
628 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
629 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
632 Status
= gRT
->SetVariable(
633 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
634 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
635 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
636 NewCount
*sizeof(NewOrder
[0]),
640 Status
= EFI_OUT_OF_RESOURCES
;
642 if (EFI_ERROR(Status
)) {
643 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
644 return (SHELL_INVALID_PARAMETER
);
646 return (SHELL_SUCCESS
);
650 Funciton to move a item to another location.
652 @param[in] Target The target item to move.
653 @param[in] CurrentOrder The pointer to the current order of items.
654 @param[in] OrderCount The number if items in CurrentOrder.
655 @param[in] OldLocation The current location of the Target.
656 @param[in] NewLocation The desired location of the Target.
658 @retval SHELL_SUCCESS The operation was successful.
659 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
664 IN CONST BCFG_OPERATION_TARGET Target
,
665 IN CONST UINT16
*CurrentOrder
,
666 IN CONST UINTN OrderCount
,
667 IN CONST UINT16 OldLocation
,
668 IN CONST UINT16 NewLocation
675 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
676 ASSERT(NewOrder
!= NULL
);
678 Temp
= CurrentOrder
[OldLocation
];
679 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
680 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
681 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
682 NewOrder
[NewLocation
] = Temp
;
685 Status
= gRT
->SetVariable(
686 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
687 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
688 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
689 OrderCount
*sizeof(CurrentOrder
[0]),
694 if (EFI_ERROR(Status
)) {
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
696 return (SHELL_INVALID_PARAMETER
);
698 return (SHELL_SUCCESS
);
702 Function to add optional data to an option.
704 @param[in] OptData The optional data to add.
705 @param[in] CurrentOrder The pointer to the current order of items.
706 @param[in] OrderCount The number if items in CurrentOrder.
707 @param[in] Target The target of the operation.
709 @retval SHELL_SUCCESS The operation was succesful.
714 IN CONST CHAR16
*OptData
,
715 IN CONST UINT16
*CurrentOrder
,
716 IN CONST UINTN OrderCount
,
717 IN CONST BCFG_OPERATION_TARGET Target
720 EFI_KEY_OPTION NewKeyOption
;
721 EFI_KEY_OPTION
*KeyOptionBuffer
;
722 SHELL_STATUS ShellStatus
;
728 CONST CHAR16
*Walker
;
733 CHAR16 VariableName
[12];
735 SHELL_FILE_HANDLE FileHandle
;
737 Status
= EFI_SUCCESS
;
738 ShellStatus
= SHELL_SUCCESS
;
742 KeyOptionBuffer
= NULL
;
744 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
746 while(Walker
[0] == L
' ') {
751 // Get the index of the variable we are changing.
753 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
754 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
755 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
756 ShellStatus
= SHELL_INVALID_PARAMETER
;
757 return (ShellStatus
);
759 OptionIndex
= (UINT16
)Intermediate
;
761 Temp
= StrStr(Walker
, L
" ");
765 while(Walker
[0] == L
' ') {
770 // determine whether we have file with data, quote delimited information, or a hot-key
772 if (Walker
[0] == L
'\"') {
774 // quoted filename or quoted information.
776 Temp
= StrStr(Walker
+1, L
"\"");
777 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
778 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
779 ShellStatus
= SHELL_INVALID_PARAMETER
;
781 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
782 if (FileName
== NULL
) {
783 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellInstall1HiiHandle
);
784 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
785 return (ShellStatus
);
787 Temp2
= StrStr(FileName
, L
"\"");
788 ASSERT(Temp2
!= NULL
);
789 Temp2
[0] = CHAR_NULL
;
791 if (StrLen(Temp2
)>0) {
792 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
793 ShellStatus
= SHELL_INVALID_PARAMETER
;
795 if (EFI_ERROR(ShellFileExists(Walker
))) {
797 // Not a file. must be misc information.
802 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
807 // filename or hot key information.
809 if (StrStr(Walker
, L
" ") == NULL
) {
813 if (EFI_ERROR(ShellFileExists(Walker
))) {
814 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellInstall1HiiHandle
, Walker
);
815 ShellStatus
= SHELL_INVALID_PARAMETER
;
817 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
820 if (Target
!= BcfgTargetBootOrder
) {
821 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellInstall1HiiHandle
);
822 ShellStatus
= SHELL_INVALID_PARAMETER
;
825 if (ShellStatus
== SHELL_SUCCESS
) {
827 // Get hot key information
829 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
830 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
831 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
832 ShellStatus
= SHELL_INVALID_PARAMETER
;
834 NewKeyOption
.KeyData
.PackedValue
= (UINT32
)Intermediate
;
835 Temp
= StrStr(Walker
, L
" ");
839 while(Walker
[0] == L
' ') {
844 if (ShellStatus
== SHELL_SUCCESS
) {
846 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
847 // Re-allocate with the added information.
849 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
), &NewKeyOption
);
850 if (KeyOptionBuffer
== NULL
) {
851 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
852 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
855 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< NewKeyOption
.KeyData
.Options
.InputKeyCount
; LoopCounter
++) {
859 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
860 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
861 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
862 ShellStatus
= SHELL_INVALID_PARAMETER
;
864 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
865 Temp
= StrStr(Walker
, L
" ");
869 while(Walker
[0] == L
' ') {
876 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
877 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
878 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
879 ShellStatus
= SHELL_INVALID_PARAMETER
;
881 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
882 Temp
= StrStr(Walker
, L
" ");
886 while(Walker
[0] == L
' ') {
891 if (ShellStatus
== SHELL_SUCCESS
) {
893 // Now do the BootOption / BootOptionCrc
895 ASSERT (OptionIndex
<= OrderCount
);
896 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
897 Status
= GetBootOptionCrc(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
898 if (EFI_ERROR(Status
)) {
899 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
900 ShellStatus
= SHELL_INVALID_PARAMETER
;
904 if (ShellStatus
== SHELL_SUCCESS
) {
905 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
< 0xFFFF ; KeyIndex
++) {
906 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
907 Status
= gRT
->GetVariable(
909 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
911 (UINTN
*)&Intermediate
,
913 if (Status
== EFI_NOT_FOUND
) {
917 Status
= gRT
->SetVariable(
919 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
920 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
921 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
),
923 if (EFI_ERROR(Status
)) {
924 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
925 ShellStatus
= SHELL_INVALID_PARAMETER
;
927 ASSERT(FileName
== NULL
&& Data
== NULL
);
933 // Shouldn't be possible to have have both. Neither is ok though.
935 ASSERT(FileName
== NULL
|| Data
== NULL
);
937 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
938 if (FileName
!= NULL
) {
940 // Open the file and populate the data buffer.
942 Status
= ShellOpenFileByName(
947 if (!EFI_ERROR(Status
)) {
948 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
950 Data
= AllocateZeroPool((UINTN
)Intermediate
);
952 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
953 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
955 if (!EFI_ERROR(Status
)) {
956 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
959 Intermediate
= StrSize(Data
);
962 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
963 Status
= UpdateOptionalData(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
964 if (EFI_ERROR(Status
)) {
965 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
966 ShellStatus
= SHELL_INVALID_PARAMETER
;
969 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
970 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
971 ShellStatus
= SHELL_INVALID_PARAMETER
;
975 SHELL_FREE_NON_NULL(Data
);
976 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
977 SHELL_FREE_NON_NULL(FileName
);
982 Function to dump the Bcfg information.
984 @param[in] Op The operation.
985 @param[in] OrderCount How many to dump.
986 @param[in] CurrentOrder The pointer to the current order of items.
987 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
989 @retval SHELL_SUCCESS The dump was successful.
990 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
994 BcfgDisplayDumpInstall1(
996 IN CONST UINTN OrderCount
,
997 IN CONST UINT16
*CurrentOrder
,
998 IN CONST BOOLEAN VerboseOutput
1004 CHAR16 VariableName
[12];
1007 CHAR16
*DevPathString
;
1010 if (OrderCount
== 0) {
1011 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellInstall1HiiHandle
);
1012 return (SHELL_SUCCESS
);
1015 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1018 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1020 Status
= gRT
->GetVariable(
1022 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1026 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1027 Buffer
= AllocateZeroPool(BufferSize
);
1028 Status
= gRT
->GetVariable(
1030 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1036 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1037 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
1038 return (SHELL_INVALID_PARAMETER
);
1041 if ((*(UINT16
*)(Buffer
+4)) != 0) {
1042 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
1043 if (DevPath
== NULL
) {
1044 DevPathString
= NULL
;
1046 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
1047 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1051 DevPathString
= NULL
;
1057 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1058 gShellInstall1HiiHandle
,
1061 (CHAR16
*)(Buffer
+6),
1063 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
1064 if (VerboseOutput
) {
1065 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
1080 if (Buffer
!= NULL
) {
1083 if (DevPath
!= NULL
) {
1086 if (DevPathString
!= NULL
) {
1087 FreePool(DevPathString
);
1090 return (SHELL_SUCCESS
);
1094 Function to initialize the BCFG operation structure.
1096 @param[in] Struct The stuct to initialize.
1100 InitBcfgStructInstall1(
1101 IN BGFG_OPERATION
*Struct
1104 ASSERT(Struct
!= NULL
);
1105 Struct
->Target
= BcfgTargetMax
;
1106 Struct
->Type
= BcfgTypeMax
;
1107 Struct
->Number1
= 0;
1108 Struct
->Number2
= 0;
1109 Struct
->HandleIndex
= 0;
1110 Struct
->FileName
= NULL
;
1111 Struct
->Description
= NULL
;
1112 Struct
->Order
= NULL
;
1113 Struct
->OptData
= NULL
;
1117 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1119 {L
"-opt", TypeMaxValue
},
1124 Function for 'bcfg' command.
1126 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1127 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1131 ShellCommandRunBcfgInstall (
1132 IN EFI_HANDLE ImageHandle
,
1133 IN EFI_SYSTEM_TABLE
*SystemTable
1137 LIST_ENTRY
*Package
;
1138 CHAR16
*ProblemParam
;
1139 SHELL_STATUS ShellStatus
;
1141 CONST CHAR16
*CurrentParam
;
1142 BGFG_OPERATION CurrentOperation
;
1144 UINT64 Intermediate
;
1147 ProblemParam
= NULL
;
1149 ShellStatus
= SHELL_SUCCESS
;
1151 InitBcfgStructInstall1(&CurrentOperation
);
1154 // initialize the shell lib (we must be in non-auto-init...)
1156 Status
= ShellInitialize();
1157 ASSERT_EFI_ERROR(Status
);
1159 Status
= CommandInit();
1160 ASSERT_EFI_ERROR(Status
);
1163 // parse the command line
1165 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1166 if (EFI_ERROR(Status
)) {
1167 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1168 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, ProblemParam
);
1169 FreePool(ProblemParam
);
1170 ShellStatus
= SHELL_INVALID_PARAMETER
;
1176 // Read in if we are doing -OPT
1178 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1179 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1180 if (CurrentOperation
.OptData
== NULL
) {
1181 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellInstall1HiiHandle
, L
"-opt");
1182 ShellStatus
= SHELL_INVALID_PARAMETER
;
1184 CurrentOperation
.Type
= BcfgTypeOpt
;
1188 // small block to read the target of the operation
1190 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1191 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1193 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1194 ShellStatus
= SHELL_INVALID_PARAMETER
;
1195 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1196 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1197 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1198 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1200 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellInstall1HiiHandle
);
1201 ShellStatus
= SHELL_INVALID_PARAMETER
;
1206 // Read in the boot or driver order environment variable (not needed for opt)
1208 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1210 Status
= gRT
->GetVariable(
1211 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1212 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1215 CurrentOperation
.Order
);
1216 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1217 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1218 if (CurrentOperation
.Order
== NULL
) {
1219 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1221 Status
= gRT
->GetVariable(
1222 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1223 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1226 CurrentOperation
.Order
);
1232 // large block to read the type of operation and verify parameter types for the info.
1234 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1235 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1236 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1237 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1238 CurrentOperation
.Type
= BcfgTypeDump
;
1239 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1240 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"-v (without dump)");
1241 ShellStatus
= SHELL_INVALID_PARAMETER
;
1242 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1243 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1244 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1245 ShellStatus
= SHELL_INVALID_PARAMETER
;
1247 CurrentOperation
.Type
= BcfgTypeAdd
;
1248 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1249 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1250 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1251 ShellStatus
= SHELL_INVALID_PARAMETER
;
1253 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1254 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1255 ASSERT(CurrentOperation
.FileName
== NULL
);
1256 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1257 ASSERT(CurrentOperation
.Description
== NULL
);
1258 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1260 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1261 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1262 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1263 ShellStatus
= SHELL_INVALID_PARAMETER
;
1265 CurrentOperation
.Type
= BcfgTypeAddp
;
1266 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1267 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1268 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1269 ShellStatus
= SHELL_INVALID_PARAMETER
;
1271 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1272 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1273 ASSERT(CurrentOperation
.FileName
== NULL
);
1274 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1275 ASSERT(CurrentOperation
.Description
== NULL
);
1276 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1278 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1279 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1280 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1281 ShellStatus
= SHELL_INVALID_PARAMETER
;
1283 CurrentOperation
.Type
= BcfgTypeAddh
;
1284 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1285 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1286 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1287 ShellStatus
= SHELL_INVALID_PARAMETER
;
1289 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1290 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1291 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1292 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1293 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1294 ShellStatus
= SHELL_INVALID_PARAMETER
;
1296 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1297 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1298 ASSERT(CurrentOperation
.Description
== NULL
);
1299 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1302 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1303 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1304 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1305 ShellStatus
= SHELL_INVALID_PARAMETER
;
1307 CurrentOperation
.Type
= BcfgTypeRm
;
1308 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1309 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1310 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1311 ShellStatus
= SHELL_INVALID_PARAMETER
;
1313 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1314 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1315 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1316 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1317 ShellStatus
= SHELL_INVALID_PARAMETER
;
1320 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1321 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1322 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1323 ShellStatus
= SHELL_INVALID_PARAMETER
;
1325 CurrentOperation
.Type
= BcfgTypeMv
;
1326 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1327 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1328 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1329 ShellStatus
= SHELL_INVALID_PARAMETER
;
1331 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1332 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1333 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1334 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1335 ShellStatus
= SHELL_INVALID_PARAMETER
;
1337 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1338 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1339 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1340 ShellStatus
= SHELL_INVALID_PARAMETER
;
1342 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1343 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1345 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1346 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1347 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1349 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1350 ShellStatus
= SHELL_INVALID_PARAMETER
;
1354 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1355 ShellStatus
= SHELL_INVALID_PARAMETER
;
1359 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1361 // we have all the info. Do the work
1363 switch (CurrentOperation
.Type
) {
1365 ShellStatus
= BcfgDisplayDumpInstall1(
1366 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1367 Length
/ sizeof(CurrentOperation
.Order
[0]),
1368 CurrentOperation
.Order
,
1369 ShellCommandLineGetFlag(Package
, L
"-v"));
1372 ShellStatus
= BcfgMoveInstall1(
1373 CurrentOperation
.Target
,
1374 CurrentOperation
.Order
,
1375 Length
/ sizeof(CurrentOperation
.Order
[0]),
1376 CurrentOperation
.Number1
,
1377 CurrentOperation
.Number2
);
1380 ShellStatus
= BcfgRemoveInstall1(
1381 CurrentOperation
.Target
,
1382 CurrentOperation
.Order
,
1383 Length
/ sizeof(CurrentOperation
.Order
[0]),
1384 CurrentOperation
.Number1
);
1389 ShellStatus
= BcfgAddInstall1(
1390 CurrentOperation
.Number1
,
1391 CurrentOperation
.FileName
,
1392 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1393 CurrentOperation
.Order
,
1394 Length
/ sizeof(CurrentOperation
.Order
[0]),
1395 CurrentOperation
.Target
,
1396 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1397 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1398 CurrentOperation
.HandleIndex
);
1401 ShellStatus
= BcfgAddOptInstall1(
1402 CurrentOperation
.OptData
,
1403 CurrentOperation
.Order
,
1404 Length
/ sizeof(CurrentOperation
.Order
[0]),
1405 CurrentOperation
.Target
);
1413 if (Package
!= NULL
) {
1414 ShellCommandLineFreeVarList (Package
);
1416 if (CurrentOperation
.FileName
!= NULL
) {
1417 FreePool(CurrentOperation
.FileName
);
1419 if (CurrentOperation
.Description
!= NULL
) {
1420 FreePool(CurrentOperation
.Description
);
1422 if (CurrentOperation
.Order
!= NULL
) {
1423 FreePool(CurrentOperation
.Order
);
1426 return (ShellStatus
);