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 UINT16 NewLocation
675 NewOrder
= AllocateCopyPool(OrderCount
*sizeof(CurrentOrder
[0]), CurrentOrder
);
676 if (NewOrder
== NULL
) {
677 return (SHELL_OUT_OF_RESOURCES
);
681 // correct the new location
683 if (NewLocation
>= OrderCount
) {
684 if (OrderCount
> 0) {
685 NewLocation
= (UINT16
)OrderCount
- 1;
691 Temp
= CurrentOrder
[OldLocation
];
692 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
693 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
694 NewOrder
[NewLocation
] = Temp
;
696 Status
= gRT
->SetVariable(
697 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
698 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
699 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
700 OrderCount
*sizeof(CurrentOrder
[0]),
705 if (EFI_ERROR(Status
)) {
706 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
707 return (SHELL_INVALID_PARAMETER
);
709 return (SHELL_SUCCESS
);
713 Function to add optional data to an option.
715 @param[in] OptData The optional data to add.
716 @param[in] CurrentOrder The pointer to the current order of items.
717 @param[in] OrderCount The number if items in CurrentOrder.
718 @param[in] Target The target of the operation.
720 @retval SHELL_SUCCESS The operation was succesful.
725 IN CONST CHAR16
*OptData
,
726 IN CONST UINT16
*CurrentOrder
,
727 IN CONST UINTN OrderCount
,
728 IN CONST BCFG_OPERATION_TARGET Target
731 EFI_KEY_OPTION NewKeyOption
;
732 EFI_KEY_OPTION
*KeyOptionBuffer
;
733 SHELL_STATUS ShellStatus
;
739 CONST CHAR16
*Walker
;
744 CHAR16 VariableName
[12];
746 SHELL_FILE_HANDLE FileHandle
;
748 Status
= EFI_SUCCESS
;
749 ShellStatus
= SHELL_SUCCESS
;
753 KeyOptionBuffer
= NULL
;
755 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
757 while(Walker
[0] == L
' ') {
762 // Get the index of the variable we are changing.
764 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
765 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
766 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
767 ShellStatus
= SHELL_INVALID_PARAMETER
;
768 return (ShellStatus
);
770 OptionIndex
= (UINT16
)Intermediate
;
772 Temp
= StrStr(Walker
, L
" ");
776 while(Walker
[0] == L
' ') {
781 // determine whether we have file with data, quote delimited information, or a hot-key
783 if (Walker
[0] == L
'\"') {
785 // quoted filename or quoted information.
787 Temp
= StrStr(Walker
+1, L
"\"");
788 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
789 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
790 ShellStatus
= SHELL_INVALID_PARAMETER
;
792 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
793 if (FileName
== NULL
) {
794 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellInstall1HiiHandle
);
795 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
796 return (ShellStatus
);
798 Temp2
= StrStr(FileName
, L
"\"");
799 ASSERT(Temp2
!= NULL
);
800 Temp2
[0] = CHAR_NULL
;
802 if (StrLen(Temp2
)>0) {
803 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
804 ShellStatus
= SHELL_INVALID_PARAMETER
;
806 if (EFI_ERROR(ShellFileExists(Walker
))) {
808 // Not a file. must be misc information.
813 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
818 // filename or hot key information.
820 if (StrStr(Walker
, L
" ") == NULL
) {
824 if (EFI_ERROR(ShellFileExists(Walker
))) {
825 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellInstall1HiiHandle
, Walker
);
826 ShellStatus
= SHELL_INVALID_PARAMETER
;
828 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
831 if (Target
!= BcfgTargetBootOrder
) {
832 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellInstall1HiiHandle
);
833 ShellStatus
= SHELL_INVALID_PARAMETER
;
836 if (ShellStatus
== SHELL_SUCCESS
) {
838 // Get hot key information
840 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
841 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
842 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
843 ShellStatus
= SHELL_INVALID_PARAMETER
;
845 NewKeyOption
.KeyData
.PackedValue
= (UINT32
)Intermediate
;
846 Temp
= StrStr(Walker
, L
" ");
850 while(Walker
[0] == L
' ') {
855 if (ShellStatus
== SHELL_SUCCESS
) {
857 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
858 // Re-allocate with the added information.
860 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
), &NewKeyOption
);
861 if (KeyOptionBuffer
== NULL
) {
862 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
863 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
866 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< NewKeyOption
.KeyData
.Options
.InputKeyCount
; LoopCounter
++) {
870 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
871 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
872 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
873 ShellStatus
= SHELL_INVALID_PARAMETER
;
875 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
876 Temp
= StrStr(Walker
, L
" ");
880 while(Walker
[0] == L
' ') {
887 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
888 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
889 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, Walker
);
890 ShellStatus
= SHELL_INVALID_PARAMETER
;
892 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
893 Temp
= StrStr(Walker
, L
" ");
897 while(Walker
[0] == L
' ') {
902 if (ShellStatus
== SHELL_SUCCESS
) {
904 // Now do the BootOption / BootOptionCrc
906 ASSERT (OptionIndex
<= OrderCount
);
907 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
908 Status
= GetBootOptionCrc(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
909 if (EFI_ERROR(Status
)) {
910 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"Option Index");
911 ShellStatus
= SHELL_INVALID_PARAMETER
;
915 if (ShellStatus
== SHELL_SUCCESS
) {
916 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
< 0xFFFF ; KeyIndex
++) {
917 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
918 Status
= gRT
->GetVariable(
920 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
922 (UINTN
*)&Intermediate
,
924 if (Status
== EFI_NOT_FOUND
) {
928 Status
= gRT
->SetVariable(
930 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
931 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
932 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
),
934 if (EFI_ERROR(Status
)) {
935 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
936 ShellStatus
= SHELL_INVALID_PARAMETER
;
938 ASSERT(FileName
== NULL
&& Data
== NULL
);
944 // Shouldn't be possible to have have both. Neither is ok though.
946 ASSERT(FileName
== NULL
|| Data
== NULL
);
948 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
949 if (FileName
!= NULL
) {
951 // Open the file and populate the data buffer.
953 Status
= ShellOpenFileByName(
958 if (!EFI_ERROR(Status
)) {
959 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
961 Data
= AllocateZeroPool((UINTN
)Intermediate
);
963 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
964 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
966 if (!EFI_ERROR(Status
)) {
967 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
970 Intermediate
= StrSize(Data
);
973 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
974 Status
= UpdateOptionalData(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
975 if (EFI_ERROR(Status
)) {
976 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
977 ShellStatus
= SHELL_INVALID_PARAMETER
;
980 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
981 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
982 ShellStatus
= SHELL_INVALID_PARAMETER
;
986 SHELL_FREE_NON_NULL(Data
);
987 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
988 SHELL_FREE_NON_NULL(FileName
);
993 Function to dump the Bcfg information.
995 @param[in] Op The operation.
996 @param[in] OrderCount How many to dump.
997 @param[in] CurrentOrder The pointer to the current order of items.
998 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
1000 @retval SHELL_SUCCESS The dump was successful.
1001 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1005 BcfgDisplayDumpInstall1(
1006 IN CONST CHAR16
*Op
,
1007 IN CONST UINTN OrderCount
,
1008 IN CONST UINT16
*CurrentOrder
,
1009 IN CONST BOOLEAN VerboseOutput
1015 CHAR16 VariableName
[12];
1018 CHAR16
*DevPathString
;
1021 if (OrderCount
== 0) {
1022 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellInstall1HiiHandle
);
1023 return (SHELL_SUCCESS
);
1026 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1029 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1031 Status
= gRT
->GetVariable(
1033 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1037 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1038 Buffer
= AllocateZeroPool(BufferSize
);
1039 Status
= gRT
->GetVariable(
1041 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1047 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1048 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
1049 return (SHELL_INVALID_PARAMETER
);
1052 if ((*(UINT16
*)(Buffer
+4)) != 0) {
1053 DevPath
= AllocateZeroPool(*(UINT16
*)(Buffer
+4));
1054 if (DevPath
== NULL
) {
1055 DevPathString
= NULL
;
1057 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
1058 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1062 DevPathString
= NULL
;
1068 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1069 gShellInstall1HiiHandle
,
1072 (CHAR16
*)(Buffer
+6),
1074 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
1075 if (VerboseOutput
) {
1076 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
1091 if (Buffer
!= NULL
) {
1094 if (DevPath
!= NULL
) {
1097 if (DevPathString
!= NULL
) {
1098 FreePool(DevPathString
);
1101 return (SHELL_SUCCESS
);
1105 Function to initialize the BCFG operation structure.
1107 @param[in] Struct The stuct to initialize.
1111 InitBcfgStructInstall1(
1112 IN BGFG_OPERATION
*Struct
1115 ASSERT(Struct
!= NULL
);
1116 Struct
->Target
= BcfgTargetMax
;
1117 Struct
->Type
= BcfgTypeMax
;
1118 Struct
->Number1
= 0;
1119 Struct
->Number2
= 0;
1120 Struct
->HandleIndex
= 0;
1121 Struct
->FileName
= NULL
;
1122 Struct
->Description
= NULL
;
1123 Struct
->Order
= NULL
;
1124 Struct
->OptData
= NULL
;
1128 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1130 {L
"-opt", TypeMaxValue
},
1135 Function for 'bcfg' command.
1137 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1138 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1142 ShellCommandRunBcfgInstall (
1143 IN EFI_HANDLE ImageHandle
,
1144 IN EFI_SYSTEM_TABLE
*SystemTable
1148 LIST_ENTRY
*Package
;
1149 CHAR16
*ProblemParam
;
1150 SHELL_STATUS ShellStatus
;
1152 CONST CHAR16
*CurrentParam
;
1153 BGFG_OPERATION CurrentOperation
;
1155 UINT64 Intermediate
;
1159 ProblemParam
= NULL
;
1161 ShellStatus
= SHELL_SUCCESS
;
1163 InitBcfgStructInstall1(&CurrentOperation
);
1166 // initialize the shell lib (we must be in non-auto-init...)
1168 Status
= ShellInitialize();
1169 ASSERT_EFI_ERROR(Status
);
1171 Status
= CommandInit();
1172 ASSERT_EFI_ERROR(Status
);
1175 // parse the command line
1177 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1178 if (EFI_ERROR(Status
)) {
1179 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1180 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, ProblemParam
);
1181 FreePool(ProblemParam
);
1182 ShellStatus
= SHELL_INVALID_PARAMETER
;
1188 // Read in if we are doing -OPT
1190 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1191 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1192 if (CurrentOperation
.OptData
== NULL
) {
1193 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellInstall1HiiHandle
, L
"-opt");
1194 ShellStatus
= SHELL_INVALID_PARAMETER
;
1196 CurrentOperation
.Type
= BcfgTypeOpt
;
1200 // small block to read the target of the operation
1202 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1203 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1205 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1206 ShellStatus
= SHELL_INVALID_PARAMETER
;
1207 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1208 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1209 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1210 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1212 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellInstall1HiiHandle
);
1213 ShellStatus
= SHELL_INVALID_PARAMETER
;
1218 // Read in the boot or driver order environment variable (not needed for opt)
1220 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1222 Status
= gRT
->GetVariable(
1223 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1224 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1227 CurrentOperation
.Order
);
1228 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1229 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1230 if (CurrentOperation
.Order
== NULL
) {
1231 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1233 Status
= gRT
->GetVariable(
1234 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1235 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1238 CurrentOperation
.Order
);
1243 Count
= (UINT16
) (Length
/ sizeof(CurrentOperation
.Order
[0]));
1246 // large block to read the type of operation and verify parameter types for the info.
1248 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1249 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1250 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1251 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1252 CurrentOperation
.Type
= BcfgTypeDump
;
1253 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1254 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"-v (without dump)");
1255 ShellStatus
= SHELL_INVALID_PARAMETER
;
1256 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1257 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1258 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1259 ShellStatus
= SHELL_INVALID_PARAMETER
;
1261 CurrentOperation
.Type
= BcfgTypeAdd
;
1262 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1263 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1264 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1265 ShellStatus
= SHELL_INVALID_PARAMETER
;
1267 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1268 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1269 ASSERT(CurrentOperation
.FileName
== NULL
);
1270 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1271 ASSERT(CurrentOperation
.Description
== NULL
);
1272 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1274 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1275 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1276 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1277 ShellStatus
= SHELL_INVALID_PARAMETER
;
1279 CurrentOperation
.Type
= BcfgTypeAddp
;
1280 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1281 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1282 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1283 ShellStatus
= SHELL_INVALID_PARAMETER
;
1285 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1286 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1287 ASSERT(CurrentOperation
.FileName
== NULL
);
1288 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1289 ASSERT(CurrentOperation
.Description
== NULL
);
1290 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1292 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1293 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1294 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1295 ShellStatus
= SHELL_INVALID_PARAMETER
;
1297 CurrentOperation
.Type
= BcfgTypeAddh
;
1298 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1299 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1300 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1301 ShellStatus
= SHELL_INVALID_PARAMETER
;
1303 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1304 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1305 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1306 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1307 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1308 ShellStatus
= SHELL_INVALID_PARAMETER
;
1310 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1311 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1312 ASSERT(CurrentOperation
.Description
== NULL
);
1313 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1316 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1317 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1318 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1319 ShellStatus
= SHELL_INVALID_PARAMETER
;
1321 CurrentOperation
.Type
= BcfgTypeRm
;
1322 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1323 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1324 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1325 ShellStatus
= SHELL_INVALID_PARAMETER
;
1327 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1328 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1329 if (CurrentOperation
.Number1
> Count
){
1330 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Count
);
1331 ShellStatus
= SHELL_INVALID_PARAMETER
;
1334 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1335 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1336 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
1337 ShellStatus
= SHELL_INVALID_PARAMETER
;
1339 CurrentOperation
.Type
= BcfgTypeMv
;
1340 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1341 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1342 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1343 ShellStatus
= SHELL_INVALID_PARAMETER
;
1345 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1346 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1347 if (CurrentOperation
.Number1
> Count
){
1348 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Count
);
1349 ShellStatus
= SHELL_INVALID_PARAMETER
;
1351 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1352 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1353 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1354 ShellStatus
= SHELL_INVALID_PARAMETER
;
1356 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1357 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1359 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1360 ||CurrentOperation
.Number2
>= Count
1362 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellInstall1HiiHandle
, Count
);
1363 ShellStatus
= SHELL_INVALID_PARAMETER
;
1368 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
1369 ShellStatus
= SHELL_INVALID_PARAMETER
;
1373 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1375 // we have all the info. Do the work
1377 switch (CurrentOperation
.Type
) {
1379 ShellStatus
= BcfgDisplayDumpInstall1(
1380 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1382 CurrentOperation
.Order
,
1383 ShellCommandLineGetFlag(Package
, L
"-v"));
1386 ShellStatus
= BcfgMoveInstall1(
1387 CurrentOperation
.Target
,
1388 CurrentOperation
.Order
,
1390 CurrentOperation
.Number1
,
1391 CurrentOperation
.Number2
);
1394 ShellStatus
= BcfgRemoveInstall1(
1395 CurrentOperation
.Target
,
1396 CurrentOperation
.Order
,
1398 CurrentOperation
.Number1
);
1403 ShellStatus
= BcfgAddInstall1(
1404 CurrentOperation
.Number1
,
1405 CurrentOperation
.FileName
,
1406 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1407 CurrentOperation
.Order
,
1409 CurrentOperation
.Target
,
1410 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1411 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1412 CurrentOperation
.HandleIndex
);
1415 ShellStatus
= BcfgAddOptInstall1(
1416 CurrentOperation
.OptData
,
1417 CurrentOperation
.Order
,
1419 CurrentOperation
.Target
);
1427 if (Package
!= NULL
) {
1428 ShellCommandLineFreeVarList (Package
);
1430 if (CurrentOperation
.FileName
!= NULL
) {
1431 FreePool(CurrentOperation
.FileName
);
1433 if (CurrentOperation
.Description
!= NULL
) {
1434 FreePool(CurrentOperation
.Description
);
1436 if (CurrentOperation
.Order
!= NULL
) {
1437 FreePool(CurrentOperation
.Order
);
1440 return (ShellStatus
);