2 Main file for bcfg shell Install1 function.
4 Copyright (c) 2010 - 2013, 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 Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3.
53 @param KeyOption Pointer to the EFI_KEY_OPTION structure.
55 @return Actual number of entries in EFI_KEY_OPTION.Keys.
57 #define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) \
58 (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK))
61 Update the optional data for a boot or driver option.
63 If optional data exists it will be changed.
65 @param[in] Index The boot or driver option index update.
66 @param[in] DataSize The size in bytes of Data.
67 @param[in] Data The buffer for the optioanl data.
68 @param[in] Target The target of the operation.
70 @retval EFI_SUCCESS The data was sucessfully updated.
71 @retval other A error occured.
79 IN CONST BCFG_OPERATION_TARGET Target
83 CHAR16 VariableName
[12];
88 UINTN OriginalOptionDataSize
;
90 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
97 Status
= gRT
->GetVariable(
99 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
103 if (Status
== EFI_BUFFER_TOO_SMALL
) {
104 OriginalData
= AllocateZeroPool(OriginalSize
);
105 if (OriginalData
== NULL
) {
106 return (EFI_OUT_OF_RESOURCES
);
108 Status
= gRT
->GetVariable(
110 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
116 if (!EFI_ERROR(Status
)) {
118 // Allocate new struct and discard old optional data.
120 ASSERT (OriginalData
!= NULL
);
121 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
122 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
123 OriginalOptionDataSize
-= OriginalSize
;
124 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
125 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
126 if (NewData
== NULL
) {
127 Status
= EFI_OUT_OF_RESOURCES
;
129 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
133 if (!EFI_ERROR(Status
)) {
135 // put the data back under the variable
137 Status
= gRT
->SetVariable(
139 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
140 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
145 SHELL_FREE_NON_NULL(OriginalData
);
146 SHELL_FREE_NON_NULL(NewData
);
151 This function will get a CRC for a boot option.
153 @param[in, out] Crc The CRC value to return.
154 @param[in] BootIndex The boot option index to CRC.
156 @retval EFI_SUCCESS The CRC was sucessfully returned.
157 @retval other A error occured.
166 CHAR16 VariableName
[12];
175 // Get the data Buffer
177 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
178 Status
= gRT
->GetVariable(
180 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
184 if (Status
== EFI_BUFFER_TOO_SMALL
) {
185 Buffer
= AllocateZeroPool(BufferSize
);
186 Status
= gRT
->GetVariable(
188 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
195 // Get the CRC computed
197 if (!EFI_ERROR(Status
)) {
198 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
201 SHELL_FREE_NON_NULL(Buffer
);
206 This function will populate the device path protocol parameter based on TheHandle.
208 @param[in] TheHandle Driver handle.
209 @param[in, out] FilePath On a sucessful return the device path to the handle.
211 @retval EFI_SUCCESS The device path was sucessfully returned.
212 @retval other A error from gBS->HandleProtocol.
218 GetDevicePathForDriverHandleInstall1 (
219 IN EFI_HANDLE TheHandle
,
220 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
224 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
225 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
227 Status
= gBS
->OpenProtocol (
229 &gEfiLoadedImageProtocolGuid
,
230 (VOID
**)&LoadedImage
,
233 EFI_OPEN_PROTOCOL_GET_PROTOCOL
235 if (!EFI_ERROR (Status
)) {
236 Status
= gBS
->OpenProtocol (
237 LoadedImage
->DeviceHandle
,
238 &gEfiDevicePathProtocolGuid
,
239 (VOID
**)&ImageDevicePath
,
242 EFI_OPEN_PROTOCOL_GET_PROTOCOL
244 if (!EFI_ERROR (Status
)) {
245 // *DevPath = DuplicateDevicePath (ImageDevicePath);
246 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
247 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
249 LoadedImage
->DeviceHandle
,
250 &gEfiDevicePathProtocolGuid
,
256 &gEfiLoadedImageProtocolGuid
,
264 Function to add a option.
266 @param[in] Position The position to add Target at.
267 @param[in] File The file to make the target.
268 @param[in] Desc The description text.
269 @param[in] CurrentOrder The pointer to the current order of items.
270 @param[in] OrderCount The number if items in CurrentOrder.
271 @param[in] Target The info on the option to add.
272 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
273 @param[in] UsePath TRUE to convert to devicepath.
274 @param[in] HandleNumber The handle number to add.
276 @retval SHELL_SUCCESS The operation was successful.
277 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
283 IN CONST CHAR16
*File
,
284 IN CONST CHAR16
*Desc
,
285 IN CONST UINT16
*CurrentOrder
,
286 IN CONST UINTN OrderCount
,
287 IN CONST BCFG_OPERATION_TARGET Target
,
288 IN CONST BOOLEAN UseHandle
,
289 IN CONST BOOLEAN UsePath
,
290 IN CONST UINTN HandleNumber
294 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
295 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
297 UINT8
*TempByteBuffer
;
298 UINT8
*TempByteStart
;
299 EFI_SHELL_FILE_INFO
*Arg
;
300 EFI_SHELL_FILE_INFO
*FileList
;
301 CHAR16 OptionStr
[40];
302 UINTN DescSize
, FilePathSize
;
304 UINTN TargetLocation
;
307 EFI_HANDLE CurHandle
;
308 UINTN DriverBindingHandleCount
;
309 UINTN ParentControllerHandleCount
;
310 UINTN ChildControllerHandleCount
;
311 SHELL_STATUS ShellStatus
;
315 if (File
== NULL
|| Desc
== NULL
) {
316 return (SHELL_INVALID_PARAMETER
);
319 if (HandleNumber
== 0) {
320 return (SHELL_INVALID_PARAMETER
);
324 if (Position
> OrderCount
) {
325 Position
= OrderCount
;
332 ShellStatus
= SHELL_SUCCESS
;
333 TargetLocation
= 0xFFFF;
336 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
337 if (CurHandle
== NULL
) {
338 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Handle Number");
339 ShellStatus
= SHELL_INVALID_PARAMETER
;
341 if (Target
== BcfgTargetBootOrder
) {
343 //Make sure that the handle should point to a real controller
345 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
347 &DriverBindingHandleCount
,
350 Status
= PARSE_HANDLE_DATABASE_PARENTS (
352 &ParentControllerHandleCount
,
355 Status
= ParseHandleDatabaseForChildControllers (
357 &ChildControllerHandleCount
,
360 if (DriverBindingHandleCount
> 0
361 || ParentControllerHandleCount
> 0
362 || ChildControllerHandleCount
> 0) {
364 Status
= gBS
->HandleProtocol (
366 &gEfiDevicePathProtocolGuid
,
369 if (EFI_ERROR (Status
)) {
370 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellInstall1HiiHandle
, HandleNumber
);
371 ShellStatus
= SHELL_INVALID_PARAMETER
;
375 //Make sure that the handle should point to driver, not a controller.
377 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
379 &DriverBindingHandleCount
,
382 Status
= PARSE_HANDLE_DATABASE_PARENTS (
384 &ParentControllerHandleCount
,
387 Status
= ParseHandleDatabaseForChildControllers (
389 &ChildControllerHandleCount
,
392 Status
= gBS
->HandleProtocol (
394 &gEfiDevicePathProtocolGuid
,
397 if (DriverBindingHandleCount
> 0
398 || ParentControllerHandleCount
> 0
399 || ChildControllerHandleCount
> 0
400 || !EFI_ERROR(Status
) ) {
401 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Handle Number");
402 ShellStatus
= SHELL_INVALID_PARAMETER
;
405 // Get the DevicePath from the loaded image information.
407 Status
= GetDevicePathForDriverHandleInstall1(CurHandle
, &FilePath
);
415 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
417 if (FileList
== NULL
) {
419 // If filename matched nothing fail
421 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellInstall1HiiHandle
, File
);
422 ShellStatus
= SHELL_INVALID_PARAMETER
;
423 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
425 // If filename expanded to multiple names, fail
427 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellInstall1HiiHandle
, File
);
428 ShellStatus
= SHELL_INVALID_PARAMETER
;
430 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
431 if (EFI_ERROR(Arg
->Status
)) {
432 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellInstall1HiiHandle
, File
, Arg
->Status
);
433 ShellStatus
= SHELL_INVALID_PARAMETER
;
436 // Build FilePath to the filename
440 // get the device path
442 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
443 if (DevicePath
== NULL
) {
444 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellInstall1HiiHandle
, Arg
->FullName
);
445 ShellStatus
= SHELL_UNSUPPORTED
;
449 DevPath = DevicePath;
450 while (!IsDevicePathEnd(DevPath)) {
451 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
452 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
455 // If we find it use it instead
457 DevicePath = DevPath;
460 DevPath = NextDevicePathNode(DevPath);
465 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
466 FileNode = FileDevicePath(NULL, StringWalker+1);
467 FilePath = AppendDevicePath(DevicePath, FileNode);
471 FilePath
= DuplicateDevicePath(DevicePath
);
475 FreePool(DevicePath
);
482 if (ShellStatus
== SHELL_SUCCESS
) {
484 // Find a free target ,a brute force implementation
487 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
489 for (Index
=0; Index
< OrderCount
; Index
++) {
490 if (CurrentOrder
[Index
] == TargetLocation
) {
501 if (TargetLocation
== 0xFFFF) {
502 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellInstall1HiiHandle
);
504 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellInstall1HiiHandle
, TargetLocation
);
508 if (ShellStatus
== SHELL_SUCCESS
) {
512 DescSize
= StrSize(Desc
);
513 FilePathSize
= GetDevicePathSize (FilePath
);
515 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
516 if (TempByteBuffer
!= NULL
) {
517 TempByteStart
= TempByteBuffer
;
518 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
519 TempByteBuffer
+= sizeof (UINT32
);
521 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
522 TempByteBuffer
+= sizeof (UINT16
);
524 CopyMem (TempByteBuffer
, Desc
, DescSize
);
525 TempByteBuffer
+= DescSize
;
526 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
528 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
529 Status
= gRT
->SetVariable (
531 &gEfiGlobalVariableGuid
,
532 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
533 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
537 FreePool(TempByteStart
);
539 Status
= EFI_OUT_OF_RESOURCES
;
542 if (EFI_ERROR(Status
)) {
543 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, OptionStr
, Status
);
545 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
546 ASSERT(NewOrder
!= NULL
);
547 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
550 // Insert target into order list
552 for (Index
=OrderCount
; Index
> Position
; Index
--) {
553 NewOrder
[Index
] = NewOrder
[Index
-1];
556 NewOrder
[Position
] = (UINT16
) TargetLocation
;
557 Status
= gRT
->SetVariable (
558 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
559 &gEfiGlobalVariableGuid
,
560 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
561 (OrderCount
+1) * sizeof(UINT16
),
567 if (EFI_ERROR(Status
)) {
568 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder", Status
);
569 ShellStatus
= SHELL_INVALID_PARAMETER
;
571 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
577 //If always Free FilePath, will free devicepath in system when use "addh"
579 if (FilePath
!=NULL
&& !UseHandle
) {
587 if (Handles
!= NULL
) {
591 if (FileList
!= NULL
) {
592 ShellCloseFileMetaArg (&FileList
);
595 return (ShellStatus
);
599 Funciton to remove an item.
601 @param[in] Target The target item to move.
602 @param[in] CurrentOrder The pointer to the current order of items.
603 @param[in] OrderCount The number if items in CurrentOrder.
604 @param[in] Location The current location of the Target.
606 @retval SHELL_SUCCESS The operation was successful.
607 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
612 IN CONST BCFG_OPERATION_TARGET Target
,
613 IN CONST UINT16
*CurrentOrder
,
614 IN CONST UINTN OrderCount
,
615 IN CONST UINT16 Location
618 CHAR16 VariableName
[12];
623 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
624 Status
= gRT
->SetVariable(
626 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
627 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
630 if (EFI_ERROR(Status
)) {
631 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
632 return (SHELL_INVALID_PARAMETER
);
634 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
635 if (NewOrder
!= NULL
) {
636 NewCount
= OrderCount
;
637 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
638 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
641 Status
= gRT
->SetVariable(
642 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
643 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
644 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
645 NewCount
*sizeof(NewOrder
[0]),
649 Status
= EFI_OUT_OF_RESOURCES
;
651 if (EFI_ERROR(Status
)) {
652 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
653 return (SHELL_INVALID_PARAMETER
);
655 return (SHELL_SUCCESS
);
659 Funciton to move a item to another location.
661 @param[in] Target The target item to move.
662 @param[in] CurrentOrder The pointer to the current order of items.
663 @param[in] OrderCount The number if items in CurrentOrder.
664 @param[in] OldLocation The current location of the Target.
665 @param[in] NewLocation The desired location of the Target.
667 @retval SHELL_SUCCESS The operation was successful.
668 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
673 IN CONST BCFG_OPERATION_TARGET Target
,
674 IN CONST UINT16
*CurrentOrder
,
675 IN CONST UINTN OrderCount
,
676 IN CONST UINT16 OldLocation
,
677 IN CONST UINT16 NewLocation
684 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
685 ASSERT(NewOrder
!= NULL
);
687 Temp
= CurrentOrder
[OldLocation
];
688 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
689 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
690 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
691 NewOrder
[NewLocation
] = Temp
;
694 Status
= gRT
->SetVariable(
695 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
696 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
697 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
698 OrderCount
*sizeof(CurrentOrder
[0]),
703 if (EFI_ERROR(Status
)) {
704 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
705 return (SHELL_INVALID_PARAMETER
);
707 return (SHELL_SUCCESS
);
711 Function to add optional data to an option.
713 @param[in] OptData The optional data to add.
714 @param[in] CurrentOrder The pointer to the current order of items.
715 @param[in] OrderCount The number if items in CurrentOrder.
716 @param[in] Target The target of the operation.
718 @retval SHELL_SUCCESS The operation was succesful.
723 IN CONST CHAR16
*OptData
,
724 IN CONST UINT16
*CurrentOrder
,
725 IN CONST UINTN OrderCount
,
726 IN CONST BCFG_OPERATION_TARGET Target
729 EFI_KEY_OPTION NewKeyOption
;
730 EFI_KEY_OPTION
*KeyOptionBuffer
;
731 SHELL_STATUS ShellStatus
;
737 CONST CHAR16
*Walker
;
742 CHAR16 VariableName
[12];
744 SHELL_FILE_HANDLE FileHandle
;
746 Status
= EFI_SUCCESS
;
747 ShellStatus
= SHELL_SUCCESS
;
751 KeyOptionBuffer
= NULL
;
753 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
755 while(Walker
[0] == L
' ') {
760 // Get the index of the variable we are changing.
762 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
763 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
764 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
765 ShellStatus
= SHELL_INVALID_PARAMETER
;
766 return (ShellStatus
);
768 OptionIndex
= (UINT16
)Intermediate
;
770 Temp
= StrStr(Walker
, L
" ");
774 while(Walker
[0] == L
' ') {
779 // determine whether we have file with data, quote delimited information, or a hot-key
781 if (Walker
[0] == L
'\"') {
783 // quoted filename or quoted information.
785 Temp
= StrStr(Walker
+1, L
"\"");
786 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
787 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
788 ShellStatus
= SHELL_INVALID_PARAMETER
;
790 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
791 if (FileName
== NULL
) {
792 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellInstall1HiiHandle
);
793 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
794 return (ShellStatus
);
796 Temp2
= StrStr(FileName
, L
"\"");
797 ASSERT(Temp2
!= NULL
);
798 Temp2
[0] = CHAR_NULL
;
800 if (StrLen(Temp2
)>0) {
801 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
802 ShellStatus
= SHELL_INVALID_PARAMETER
;
804 if (EFI_ERROR(ShellFileExists(Walker
))) {
806 // Not a file. must be misc information.
811 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
816 // filename or hot key information.
818 if (StrStr(Walker
, L
" ") == NULL
) {
822 if (EFI_ERROR(ShellFileExists(Walker
))) {
823 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellInstall1HiiHandle
, Walker
);
824 ShellStatus
= SHELL_INVALID_PARAMETER
;
826 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
829 if (Target
!= BcfgTargetBootOrder
) {
830 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellInstall1HiiHandle
);
831 ShellStatus
= SHELL_INVALID_PARAMETER
;
834 if (ShellStatus
== SHELL_SUCCESS
) {
836 // Get hot key information
838 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
839 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
840 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
841 ShellStatus
= SHELL_INVALID_PARAMETER
;
843 NewKeyOption
.KeyData
= (UINT32
)Intermediate
;
844 Temp
= StrStr(Walker
, L
" ");
848 while(Walker
[0] == L
' ') {
853 if (ShellStatus
== SHELL_SUCCESS
) {
855 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
856 // Re-allocate with the added information.
858 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
)), &NewKeyOption
);
859 if (KeyOptionBuffer
== NULL
) {
860 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
861 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
864 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
); LoopCounter
++) {
868 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
869 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
870 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
871 ShellStatus
= SHELL_INVALID_PARAMETER
;
873 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
874 Temp
= StrStr(Walker
, L
" ");
878 while(Walker
[0] == L
' ') {
885 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
886 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
887 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
888 ShellStatus
= SHELL_INVALID_PARAMETER
;
890 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
891 Temp
= StrStr(Walker
, L
" ");
895 while(Walker
[0] == L
' ') {
900 if (ShellStatus
== SHELL_SUCCESS
) {
902 // Now do the BootOption / BootOptionCrc
904 ASSERT (OptionIndex
<= OrderCount
);
905 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
906 Status
= GetBootOptionCrc(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
907 if (EFI_ERROR(Status
)) {
908 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
909 ShellStatus
= SHELL_INVALID_PARAMETER
;
913 if (ShellStatus
== SHELL_SUCCESS
) {
914 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
< 0xFFFF ; KeyIndex
++) {
915 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
916 Status
= gRT
->GetVariable(
918 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
920 (UINTN
*)&Intermediate
,
922 if (Status
== EFI_NOT_FOUND
) {
926 Status
= gRT
->SetVariable(
928 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
929 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
930 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption
)),
932 if (EFI_ERROR(Status
)) {
933 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
934 ShellStatus
= SHELL_INVALID_PARAMETER
;
936 ASSERT(FileName
== NULL
&& Data
== NULL
);
942 // Shouldn't be possible to have have both. Neither is ok though.
944 ASSERT(FileName
== NULL
|| Data
== NULL
);
946 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
947 if (FileName
!= NULL
) {
949 // Open the file and populate the data buffer.
951 Status
= ShellOpenFileByName(
956 if (!EFI_ERROR(Status
)) {
957 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
959 Data
= AllocateZeroPool((UINTN
)Intermediate
);
961 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
962 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
964 if (!EFI_ERROR(Status
)) {
965 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
968 Intermediate
= StrSize(Data
);
971 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
972 Status
= UpdateOptionalData(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
973 if (EFI_ERROR(Status
)) {
974 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
975 ShellStatus
= SHELL_INVALID_PARAMETER
;
978 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
979 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
980 ShellStatus
= SHELL_INVALID_PARAMETER
;
984 SHELL_FREE_NON_NULL(Data
);
985 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
986 SHELL_FREE_NON_NULL(FileName
);
991 Function to dump the Bcfg information.
993 @param[in] Op The operation.
994 @param[in] OrderCount How many to dump.
995 @param[in] CurrentOrder The pointer to the current order of items.
996 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
998 @retval SHELL_SUCCESS The dump was successful.
999 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1003 BcfgDisplayDumpInstall1(
1004 IN CONST CHAR16
*Op
,
1005 IN CONST UINTN OrderCount
,
1006 IN CONST UINT16
*CurrentOrder
,
1007 IN CONST BOOLEAN VerboseOutput
1013 CHAR16 VariableName
[12];
1016 CHAR16
*DevPathString
;
1019 if (OrderCount
== 0) {
1020 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellInstall1HiiHandle
);
1021 return (SHELL_SUCCESS
);
1024 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1027 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1029 Status
= gRT
->GetVariable(
1031 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1035 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1036 Buffer
= AllocateZeroPool(BufferSize
);
1037 Status
= gRT
->GetVariable(
1039 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1045 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1046 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
1047 return (SHELL_INVALID_PARAMETER
);
1050 if ((*(UINT16
*)(Buffer
+4)) != 0) {
1051 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
1052 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
1053 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1056 DevPathString
= NULL
;
1062 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1063 gShellInstall1HiiHandle
,
1066 (CHAR16
*)(Buffer
+6),
1068 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
1069 if (VerboseOutput
) {
1070 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
1085 if (Buffer
!= NULL
) {
1088 if (DevPath
!= NULL
) {
1091 if (DevPathString
!= NULL
) {
1092 FreePool(DevPathString
);
1095 return (SHELL_SUCCESS
);
1099 Function to initialize the BCFG operation structure.
1101 @param[in] Struct The stuct to initialize.
1105 InitBcfgStructInstall1(
1106 IN BGFG_OPERATION
*Struct
1109 ASSERT(Struct
!= NULL
);
1110 Struct
->Target
= BcfgTargetMax
;
1111 Struct
->Type
= BcfgTypeMax
;
1112 Struct
->Number1
= 0;
1113 Struct
->Number2
= 0;
1114 Struct
->HandleIndex
= 0;
1115 Struct
->FileName
= NULL
;
1116 Struct
->Description
= NULL
;
1117 Struct
->Order
= NULL
;
1118 Struct
->OptData
= NULL
;
1122 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1124 {L
"-opt", TypeMaxValue
},
1129 Function for 'bcfg' command.
1131 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1132 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1136 ShellCommandRunBcfgInstall (
1137 IN EFI_HANDLE ImageHandle
,
1138 IN EFI_SYSTEM_TABLE
*SystemTable
1142 LIST_ENTRY
*Package
;
1143 CHAR16
*ProblemParam
;
1144 SHELL_STATUS ShellStatus
;
1146 CONST CHAR16
*CurrentParam
;
1147 BGFG_OPERATION CurrentOperation
;
1149 UINT64 Intermediate
;
1152 ProblemParam
= NULL
;
1154 ShellStatus
= SHELL_SUCCESS
;
1156 InitBcfgStructInstall1(&CurrentOperation
);
1159 // initialize the shell lib (we must be in non-auto-init...)
1161 Status
= ShellInitialize();
1162 ASSERT_EFI_ERROR(Status
);
1164 Status
= CommandInit();
1165 ASSERT_EFI_ERROR(Status
);
1168 // parse the command line
1170 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1171 if (EFI_ERROR(Status
)) {
1172 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1173 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, ProblemParam
);
1174 FreePool(ProblemParam
);
1175 ShellStatus
= SHELL_INVALID_PARAMETER
;
1181 // Read in if we are doing -OPT
1183 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1184 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1185 if (CurrentOperation
.OptData
== NULL
) {
1186 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellInstall1HiiHandle
, L
"-opt");
1187 ShellStatus
= SHELL_INVALID_PARAMETER
;
1189 CurrentOperation
.Type
= BcfgTypeOpt
;
1193 // small block to read the target of the operation
1195 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1196 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1199 ShellStatus
= SHELL_INVALID_PARAMETER
;
1200 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1201 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1202 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1203 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1205 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellInstall1HiiHandle
);
1206 ShellStatus
= SHELL_INVALID_PARAMETER
;
1211 // Read in the boot or driver order environment variable (not needed for opt)
1213 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1215 Status
= gRT
->GetVariable(
1216 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1217 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1220 CurrentOperation
.Order
);
1221 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1222 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1223 Status
= gRT
->GetVariable(
1224 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1225 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1228 CurrentOperation
.Order
);
1233 // large block to read the type of operation and verify parameter types for the info.
1235 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1236 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1237 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1238 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1239 CurrentOperation
.Type
= BcfgTypeDump
;
1240 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1241 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"-v (without dump)");
1242 ShellStatus
= SHELL_INVALID_PARAMETER
;
1243 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1244 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1245 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1246 ShellStatus
= SHELL_INVALID_PARAMETER
;
1248 CurrentOperation
.Type
= BcfgTypeAdd
;
1249 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1250 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1251 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1252 ShellStatus
= SHELL_INVALID_PARAMETER
;
1254 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1255 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1256 ASSERT(CurrentOperation
.FileName
== NULL
);
1257 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1258 ASSERT(CurrentOperation
.Description
== NULL
);
1259 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1261 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1262 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1263 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1264 ShellStatus
= SHELL_INVALID_PARAMETER
;
1266 CurrentOperation
.Type
= BcfgTypeAddp
;
1267 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1268 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1269 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1270 ShellStatus
= SHELL_INVALID_PARAMETER
;
1272 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1273 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1274 ASSERT(CurrentOperation
.FileName
== NULL
);
1275 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1276 ASSERT(CurrentOperation
.Description
== NULL
);
1277 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1279 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1280 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1281 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1282 ShellStatus
= SHELL_INVALID_PARAMETER
;
1284 CurrentOperation
.Type
= BcfgTypeAddh
;
1285 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1286 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1287 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1288 ShellStatus
= SHELL_INVALID_PARAMETER
;
1290 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1291 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1292 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1293 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1294 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1295 ShellStatus
= SHELL_INVALID_PARAMETER
;
1297 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1298 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1299 ASSERT(CurrentOperation
.Description
== NULL
);
1300 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1303 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1304 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1305 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1306 ShellStatus
= SHELL_INVALID_PARAMETER
;
1308 CurrentOperation
.Type
= BcfgTypeRm
;
1309 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1310 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1311 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1312 ShellStatus
= SHELL_INVALID_PARAMETER
;
1314 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1315 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1316 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1317 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1318 ShellStatus
= SHELL_INVALID_PARAMETER
;
1321 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1322 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1323 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1324 ShellStatus
= SHELL_INVALID_PARAMETER
;
1326 CurrentOperation
.Type
= BcfgTypeMv
;
1327 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1328 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1329 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1330 ShellStatus
= SHELL_INVALID_PARAMETER
;
1332 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1333 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1334 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
1335 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1336 ShellStatus
= SHELL_INVALID_PARAMETER
;
1338 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1339 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1340 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1341 ShellStatus
= SHELL_INVALID_PARAMETER
;
1343 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1344 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1346 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1347 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1348 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
1350 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
1351 ShellStatus
= SHELL_INVALID_PARAMETER
;
1355 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1356 ShellStatus
= SHELL_INVALID_PARAMETER
;
1360 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1362 // we have all the info. Do the work
1364 switch (CurrentOperation
.Type
) {
1366 ShellStatus
= BcfgDisplayDumpInstall1(
1367 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1368 Length
/ sizeof(CurrentOperation
.Order
[0]),
1369 CurrentOperation
.Order
,
1370 ShellCommandLineGetFlag(Package
, L
"-v"));
1373 ShellStatus
= BcfgMoveInstall1(
1374 CurrentOperation
.Target
,
1375 CurrentOperation
.Order
,
1376 Length
/ sizeof(CurrentOperation
.Order
[0]),
1377 CurrentOperation
.Number1
,
1378 CurrentOperation
.Number2
);
1381 ShellStatus
= BcfgRemoveInstall1(
1382 CurrentOperation
.Target
,
1383 CurrentOperation
.Order
,
1384 Length
/ sizeof(CurrentOperation
.Order
[0]),
1385 CurrentOperation
.Number1
);
1390 ShellStatus
= BcfgAddInstall1(
1391 CurrentOperation
.Number1
,
1392 CurrentOperation
.FileName
,
1393 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1394 CurrentOperation
.Order
,
1395 Length
/ sizeof(CurrentOperation
.Order
[0]),
1396 CurrentOperation
.Target
,
1397 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1398 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1399 CurrentOperation
.HandleIndex
);
1402 ShellStatus
= BcfgAddOptInstall1(
1403 CurrentOperation
.OptData
,
1404 CurrentOperation
.Order
,
1405 Length
/ sizeof(CurrentOperation
.Order
[0]),
1406 CurrentOperation
.Target
);
1414 if (Package
!= NULL
) {
1415 ShellCommandLineFreeVarList (Package
);
1417 if (CurrentOperation
.FileName
!= NULL
) {
1418 FreePool(CurrentOperation
.FileName
);
1420 if (CurrentOperation
.Description
!= NULL
) {
1421 FreePool(CurrentOperation
.Description
);
1423 if (CurrentOperation
.Order
!= NULL
) {
1424 FreePool(CurrentOperation
.Order
);
1427 return (ShellStatus
);