2 Main file for BCFG command.
4 (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <ShellBase.h>
20 #include <Guid/GlobalVariable.h>
21 #include <Guid/ShellLibHiiGuid.h>
23 #include <Protocol/EfiShell.h>
24 #include <Protocol/EfiShellParameters.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/LoadedImage.h>
27 #include <Protocol/UnicodeCollation.h>
29 #include <Library/BaseLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PcdLib.h>
34 #include <Library/ShellCommandLib.h>
35 #include <Library/ShellLib.h>
36 #include <Library/SortLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/UefiRuntimeServicesTableLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/HiiLib.h>
41 #include <Library/FileHandleLib.h>
42 #include <Library/PrintLib.h>
43 #include <Library/HandleParsingLib.h>
44 #include <Library/DevicePathLib.h>
46 STATIC CONST CHAR16 mFileName
[] = L
"ShellCommands";
47 STATIC EFI_HANDLE gShellBcfgHiiHandle
= NULL
;
50 BcfgTargetBootOrder
= 0,
51 BcfgTargetDriverOrder
= 1,
53 } BCFG_OPERATION_TARGET
;
64 } BCFG_OPERATION_TYPE
;
67 BCFG_OPERATION_TARGET Target
;
68 BCFG_OPERATION_TYPE Type
;
75 CONST CHAR16
*OptData
;
79 Update the optional data for a boot or driver option.
81 If optional data exists it will be changed.
83 @param[in] Index The boot or driver option index update.
84 @param[in] DataSize The size in bytes of Data.
85 @param[in] Data The buffer for the optioanl data.
86 @param[in] Target The target of the operation.
88 @retval EFI_SUCCESS The data was sucessfully updated.
89 @retval other A error occured.
97 IN CONST BCFG_OPERATION_TARGET Target
101 CHAR16 VariableName
[12];
106 UINTN OriginalOptionDataSize
;
108 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
115 Status
= gRT
->GetVariable(
117 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
121 if (Status
== EFI_BUFFER_TOO_SMALL
) {
122 OriginalData
= AllocateZeroPool(OriginalSize
);
123 if (OriginalData
== NULL
) {
124 return (EFI_OUT_OF_RESOURCES
);
126 Status
= gRT
->GetVariable(
128 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
134 if (!EFI_ERROR(Status
)) {
136 // Allocate new struct and discard old optional data.
138 ASSERT (OriginalData
!= NULL
);
139 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
140 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
141 OriginalOptionDataSize
-= OriginalSize
;
142 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
143 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
144 if (NewData
== NULL
) {
145 Status
= EFI_OUT_OF_RESOURCES
;
147 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
151 if (!EFI_ERROR(Status
)) {
153 // put the data back under the variable
155 Status
= gRT
->SetVariable(
157 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
158 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
163 SHELL_FREE_NON_NULL(OriginalData
);
164 SHELL_FREE_NON_NULL(NewData
);
169 This function will get a CRC for a boot option.
171 @param[in, out] Crc The CRC value to return.
172 @param[in] BootIndex The boot option index to CRC.
174 @retval EFI_SUCCESS The CRC was sucessfully returned.
175 @retval other A error occured.
184 CHAR16 VariableName
[12];
193 // Get the data Buffer
195 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
196 Status
= gRT
->GetVariable(
198 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
202 if (Status
== EFI_BUFFER_TOO_SMALL
) {
203 Buffer
= AllocateZeroPool(BufferSize
);
204 Status
= gRT
->GetVariable(
206 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
213 // Get the CRC computed
215 if (!EFI_ERROR(Status
)) {
216 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
219 SHELL_FREE_NON_NULL(Buffer
);
224 This function will populate the device path protocol parameter based on TheHandle.
226 @param[in] TheHandle Driver handle.
227 @param[in, out] FilePath On a sucessful return the device path to the handle.
229 @retval EFI_SUCCESS The device path was sucessfully returned.
230 @retval other A error from gBS->HandleProtocol.
236 GetDevicePathForDriverHandle (
237 IN EFI_HANDLE TheHandle
,
238 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
242 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
243 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
245 Status
= gBS
->OpenProtocol (
247 &gEfiLoadedImageProtocolGuid
,
248 (VOID
**)&LoadedImage
,
251 EFI_OPEN_PROTOCOL_GET_PROTOCOL
253 if (!EFI_ERROR (Status
)) {
254 Status
= gBS
->OpenProtocol (
255 LoadedImage
->DeviceHandle
,
256 &gEfiDevicePathProtocolGuid
,
257 (VOID
**)&ImageDevicePath
,
260 EFI_OPEN_PROTOCOL_GET_PROTOCOL
262 if (!EFI_ERROR (Status
)) {
263 // *DevPath = DuplicateDevicePath (ImageDevicePath);
264 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
265 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
267 LoadedImage
->DeviceHandle
,
268 &gEfiDevicePathProtocolGuid
,
274 &gEfiLoadedImageProtocolGuid
,
282 Function to add a option.
284 @param[in] Position The position to add Target at.
285 @param[in] File The file to make the target.
286 @param[in] Desc The description text.
287 @param[in] CurrentOrder The pointer to the current order of items.
288 @param[in] OrderCount The number if items in CurrentOrder.
289 @param[in] Target The info on the option to add.
290 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
291 @param[in] UsePath TRUE to convert to devicepath.
292 @param[in] HandleNumber The handle number to add.
294 @retval SHELL_SUCCESS The operation was successful.
295 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
301 IN CONST CHAR16
*File
,
302 IN CONST CHAR16
*Desc
,
303 IN CONST UINT16
*CurrentOrder
,
304 IN CONST UINTN OrderCount
,
305 IN CONST BCFG_OPERATION_TARGET Target
,
306 IN CONST BOOLEAN UseHandle
,
307 IN CONST BOOLEAN UsePath
,
308 IN CONST UINTN HandleNumber
312 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
313 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
315 UINT8
*TempByteBuffer
;
316 UINT8
*TempByteStart
;
317 EFI_SHELL_FILE_INFO
*Arg
;
318 EFI_SHELL_FILE_INFO
*FileList
;
319 CHAR16 OptionStr
[40];
320 UINTN DescSize
, FilePathSize
;
322 UINTN TargetLocation
;
325 EFI_HANDLE CurHandle
;
326 UINTN DriverBindingHandleCount
;
327 UINTN ParentControllerHandleCount
;
328 UINTN ChildControllerHandleCount
;
329 SHELL_STATUS ShellStatus
;
333 if (File
== NULL
|| Desc
== NULL
) {
334 return (SHELL_INVALID_PARAMETER
);
337 if (HandleNumber
== 0) {
338 return (SHELL_INVALID_PARAMETER
);
342 if (Position
> OrderCount
) {
343 Position
= OrderCount
;
350 ShellStatus
= SHELL_SUCCESS
;
351 TargetLocation
= 0xFFFF;
354 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
355 if (CurHandle
== NULL
) {
356 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Handle Number");
357 ShellStatus
= SHELL_INVALID_PARAMETER
;
359 if (Target
== BcfgTargetBootOrder
) {
361 //Make sure that the handle should point to a real controller
363 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
365 &DriverBindingHandleCount
,
368 Status
= PARSE_HANDLE_DATABASE_PARENTS (
370 &ParentControllerHandleCount
,
373 Status
= ParseHandleDatabaseForChildControllers (
375 &ChildControllerHandleCount
,
378 if (DriverBindingHandleCount
> 0
379 || ParentControllerHandleCount
> 0
380 || ChildControllerHandleCount
> 0) {
382 Status
= gBS
->HandleProtocol (
384 &gEfiDevicePathProtocolGuid
,
387 if (EFI_ERROR (Status
)) {
388 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellBcfgHiiHandle
, L
"bcfg", HandleNumber
);
389 ShellStatus
= SHELL_INVALID_PARAMETER
;
393 //Make sure that the handle should point to driver, not a controller.
395 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
397 &DriverBindingHandleCount
,
400 Status
= PARSE_HANDLE_DATABASE_PARENTS (
402 &ParentControllerHandleCount
,
405 Status
= ParseHandleDatabaseForChildControllers (
407 &ChildControllerHandleCount
,
410 Status
= gBS
->HandleProtocol (
412 &gEfiDevicePathProtocolGuid
,
415 if (DriverBindingHandleCount
> 0
416 || ParentControllerHandleCount
> 0
417 || ChildControllerHandleCount
> 0
418 || !EFI_ERROR(Status
) ) {
419 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Handle Number");
420 ShellStatus
= SHELL_INVALID_PARAMETER
;
423 // Get the DevicePath from the loaded image information.
425 Status
= GetDevicePathForDriverHandle(CurHandle
, &FilePath
);
433 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
435 if (FileList
== NULL
) {
437 // If filename matched nothing fail
439 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", File
);
440 ShellStatus
= SHELL_INVALID_PARAMETER
;
441 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
443 // If filename expanded to multiple names, fail
445 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellBcfgHiiHandle
, L
"bcfg", File
);
446 ShellStatus
= SHELL_INVALID_PARAMETER
;
448 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
449 if (EFI_ERROR(Arg
->Status
)) {
450 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellBcfgHiiHandle
, L
"bcfg", File
);
451 ShellStatus
= SHELL_INVALID_PARAMETER
;
454 // Build FilePath to the filename
458 // get the device path
460 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
461 if (DevicePath
== NULL
) {
462 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellBcfgHiiHandle
, L
"bcfg", Arg
->FullName
);
463 ShellStatus
= SHELL_UNSUPPORTED
;
467 DevPath = DevicePath;
468 while (!IsDevicePathEnd(DevPath)) {
469 if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
470 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
473 // If we find it use it instead
475 DevicePath = DevPath;
478 DevPath = NextDevicePathNode(DevPath);
483 for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
484 FileNode = FileDevicePath(NULL, StringWalker+1);
485 FilePath = AppendDevicePath(DevicePath, FileNode);
489 FilePath
= DuplicateDevicePath(DevicePath
);
493 FreePool(DevicePath
);
500 if (ShellStatus
== SHELL_SUCCESS
) {
502 // Find a free target ,a brute force implementation
505 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
507 for (Index
=0; Index
< OrderCount
; Index
++) {
508 if (CurrentOrder
[Index
] == TargetLocation
) {
519 if (TargetLocation
== 0xFFFF) {
520 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellBcfgHiiHandle
, L
"bcfg");
522 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellBcfgHiiHandle
, TargetLocation
);
526 if (ShellStatus
== SHELL_SUCCESS
) {
530 DescSize
= StrSize(Desc
);
531 FilePathSize
= GetDevicePathSize (FilePath
);
533 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
534 if (TempByteBuffer
!= NULL
) {
535 TempByteStart
= TempByteBuffer
;
536 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
537 TempByteBuffer
+= sizeof (UINT32
);
539 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
540 TempByteBuffer
+= sizeof (UINT16
);
542 CopyMem (TempByteBuffer
, Desc
, DescSize
);
543 TempByteBuffer
+= DescSize
;
544 ASSERT (FilePath
!= NULL
);
545 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
547 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
548 Status
= gRT
->SetVariable (
550 &gEfiGlobalVariableGuid
,
551 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
552 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
556 FreePool(TempByteStart
);
558 Status
= EFI_OUT_OF_RESOURCES
;
561 if (EFI_ERROR(Status
)) {
562 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", OptionStr
);
564 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(NewOrder
[0]));
565 ASSERT(NewOrder
!= NULL
);
566 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(NewOrder
[0]));
569 // Insert target into order list
571 for (Index
=OrderCount
; Index
> Position
; Index
--) {
572 NewOrder
[Index
] = NewOrder
[Index
-1];
575 NewOrder
[Position
] = (UINT16
) TargetLocation
;
576 Status
= gRT
->SetVariable (
577 Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder",
578 &gEfiGlobalVariableGuid
,
579 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
580 (OrderCount
+1) * sizeof(UINT16
),
586 if (EFI_ERROR(Status
)) {
587 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
?L
"BootOrder":L
"DriverOrder");
588 ShellStatus
= SHELL_INVALID_PARAMETER
;
590 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
596 //If always Free FilePath, will free devicepath in system when use "addh"
598 if (FilePath
!=NULL
&& !UseHandle
) {
606 if (Handles
!= NULL
) {
610 if (FileList
!= NULL
) {
611 ShellCloseFileMetaArg (&FileList
);
614 return (ShellStatus
);
618 Funciton to remove an item.
620 @param[in] Target The target item to move.
621 @param[in] CurrentOrder The pointer to the current order of items.
622 @param[in] OrderCount The number if items in CurrentOrder.
623 @param[in] Location The current location of the Target.
625 @retval SHELL_SUCCESS The operation was successful.
626 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
631 IN CONST BCFG_OPERATION_TARGET Target
,
632 IN CONST UINT16
*CurrentOrder
,
633 IN CONST UINTN OrderCount
,
634 IN CONST UINT16 Location
637 CHAR16 VariableName
[12];
642 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
643 Status
= gRT
->SetVariable(
645 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
646 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
649 if (EFI_ERROR(Status
)) {
650 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
651 return (SHELL_INVALID_PARAMETER
);
653 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
654 if (NewOrder
!= NULL
) {
655 NewCount
= OrderCount
;
656 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
657 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
660 Status
= gRT
->SetVariable(
661 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
662 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
663 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
664 NewCount
*sizeof(NewOrder
[0]),
668 Status
= EFI_OUT_OF_RESOURCES
;
670 if (EFI_ERROR(Status
)) {
671 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder");
672 return (SHELL_INVALID_PARAMETER
);
674 return (SHELL_SUCCESS
);
678 Funciton to move a item to another location.
680 @param[in] Target The target item to move.
681 @param[in] CurrentOrder The pointer to the current order of items.
682 @param[in] OrderCount The number if items in CurrentOrder.
683 @param[in] OldLocation The current location of the Target.
684 @param[in] NewLocation The desired location of the Target.
686 @retval SHELL_SUCCESS The operation was successful.
687 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
692 IN CONST BCFG_OPERATION_TARGET Target
,
693 IN CONST UINT16
*CurrentOrder
,
694 IN CONST UINTN OrderCount
,
695 IN CONST UINT16 OldLocation
,
696 IN UINT16 NewLocation
703 NewOrder
= AllocateCopyPool(OrderCount
*sizeof(CurrentOrder
[0]), CurrentOrder
);
704 if (NewOrder
== NULL
) {
705 return (SHELL_OUT_OF_RESOURCES
);
709 // correct the new location
711 if (NewLocation
>= OrderCount
) {
712 if (OrderCount
> 0) {
713 NewLocation
= (UINT16
)OrderCount
- 1;
719 Temp
= CurrentOrder
[OldLocation
];
720 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
721 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
722 NewOrder
[NewLocation
] = Temp
;
724 Status
= gRT
->SetVariable(
725 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
726 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
727 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
728 OrderCount
*sizeof(CurrentOrder
[0]),
733 if (EFI_ERROR(Status
)) {
734 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder");
735 return (SHELL_INVALID_PARAMETER
);
737 return (SHELL_SUCCESS
);
741 Function to add optional data to an option.
743 @param[in] OptData The optional data to add.
744 @param[in] CurrentOrder The pointer to the current order of items.
745 @param[in] OrderCount The number if items in CurrentOrder.
746 @param[in] Target The target of the operation.
748 @retval SHELL_SUCCESS The operation was succesful.
753 IN CONST CHAR16
*OptData
,
754 IN CONST UINT16
*CurrentOrder
,
755 IN CONST UINTN OrderCount
,
756 IN CONST BCFG_OPERATION_TARGET Target
759 EFI_KEY_OPTION NewKeyOption
;
760 EFI_KEY_OPTION
*KeyOptionBuffer
;
761 SHELL_STATUS ShellStatus
;
767 CONST CHAR16
*Walker
;
772 CHAR16 VariableName
[12];
775 SHELL_FILE_HANDLE FileHandle
;
777 Status
= EFI_SUCCESS
;
778 ShellStatus
= SHELL_SUCCESS
;
782 KeyOptionBuffer
= NULL
;
785 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
786 ZeroMem(VariableName
, sizeof(VariableName
));
788 while(Walker
[0] == L
' ') {
793 // Get the index of the variable we are changing.
795 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
796 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
797 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Option Index");
798 ShellStatus
= SHELL_INVALID_PARAMETER
;
799 return (ShellStatus
);
801 OptionIndex
= (UINT16
)Intermediate
;
803 Temp
= StrStr(Walker
, L
" ");
807 while(Walker
[0] == L
' ') {
812 // determine whether we have file with data, quote delimited information, or a hot-key
814 if (Walker
[0] == L
'\"') {
816 // quoted filename or quoted information.
818 Temp
= StrStr(Walker
+1, L
"\"");
819 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
820 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
821 ShellStatus
= SHELL_INVALID_PARAMETER
;
823 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
824 if (FileName
== NULL
) {
825 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
826 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
827 return (ShellStatus
);
829 Temp2
= StrStr(FileName
, L
"\"");
830 ASSERT(Temp2
!= NULL
);
831 Temp2
[0] = CHAR_NULL
;
833 if (StrLen(Temp2
)>0) {
834 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
835 ShellStatus
= SHELL_INVALID_PARAMETER
;
837 if (EFI_ERROR(ShellFileExists(Walker
))) {
839 // Not a file. must be misc information.
844 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
849 // filename or hot key information.
851 if (StrStr(Walker
, L
" ") == NULL
) {
855 if (EFI_ERROR(ShellFileExists(Walker
))) {
856 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
857 ShellStatus
= SHELL_INVALID_PARAMETER
;
859 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
862 if (Target
!= BcfgTargetBootOrder
) {
863 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellBcfgHiiHandle
, L
"bcfg");
864 ShellStatus
= SHELL_INVALID_PARAMETER
;
867 if (ShellStatus
== SHELL_SUCCESS
) {
869 // Get hot key information
871 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
872 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
873 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
874 ShellStatus
= SHELL_INVALID_PARAMETER
;
876 NewKeyOption
.KeyData
.PackedValue
= (UINT32
)Intermediate
;
877 Temp
= StrStr(Walker
, L
" ");
881 while(Walker
[0] == L
' ') {
886 if (ShellStatus
== SHELL_SUCCESS
) {
888 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
889 // Re-allocate with the added information.
891 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
), &NewKeyOption
);
892 if (KeyOptionBuffer
== NULL
) {
893 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
894 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
897 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< NewKeyOption
.KeyData
.Options
.InputKeyCount
; LoopCounter
++) {
901 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
902 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
903 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
904 ShellStatus
= SHELL_INVALID_PARAMETER
;
906 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
907 Temp
= StrStr(Walker
, L
" ");
911 while(Walker
[0] == L
' ') {
918 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
919 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
920 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
921 ShellStatus
= SHELL_INVALID_PARAMETER
;
923 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
924 Temp
= StrStr(Walker
, L
" ");
928 while(Walker
[0] == L
' ') {
933 if (ShellStatus
== SHELL_SUCCESS
) {
935 // Now do the BootOption / BootOptionCrc
937 ASSERT (OptionIndex
<= OrderCount
);
938 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
939 Status
= GetBootOptionCrc(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
940 if (EFI_ERROR(Status
)) {
941 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Option Index");
942 ShellStatus
= SHELL_INVALID_PARAMETER
;
946 if (ShellStatus
== SHELL_SUCCESS
) {
947 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
<= 0xFFFF ; KeyIndex
++) {
948 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
949 Status
= GetEfiGlobalVariable2 (VariableName
, &VariableData
, NULL
);
950 if (Status
== EFI_NOT_FOUND
) {
953 if (!EFI_ERROR(Status
)) {
954 SHELL_FREE_NON_NULL(VariableData
);
957 if (KeyIndex
<= 0xFFFF) {
958 Status
= gRT
->SetVariable(
960 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
961 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
962 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
),
964 if (EFI_ERROR(Status
)) {
965 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
966 ShellStatus
= SHELL_INVALID_PARAMETER
;
969 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_VAR_NO_NUM
), gShellBcfgHiiHandle
, L
"bcfg");
970 ShellStatus
= SHELL_INVALID_PARAMETER
;
972 ASSERT(FileName
== NULL
&& Data
== NULL
);
978 // Shouldn't be possible to have have both. Neither is ok though.
980 ASSERT(FileName
== NULL
|| Data
== NULL
);
982 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
983 if (FileName
!= NULL
) {
985 // Open the file and populate the data buffer.
987 Status
= ShellOpenFileByName(
992 if (!EFI_ERROR(Status
)) {
993 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
995 Data
= AllocateZeroPool((UINTN
)Intermediate
);
997 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
998 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1000 if (!EFI_ERROR(Status
)) {
1001 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
1004 Intermediate
= StrSize(Data
);
1007 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
1008 Status
= UpdateOptionalData(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
1009 if (EFI_ERROR(Status
)) {
1010 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1011 ShellStatus
= SHELL_INVALID_PARAMETER
;
1014 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
1015 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1016 ShellStatus
= SHELL_INVALID_PARAMETER
;
1020 SHELL_FREE_NON_NULL(Data
);
1021 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
1022 SHELL_FREE_NON_NULL(FileName
);
1027 Function to dump the Bcfg information.
1029 @param[in] Op The operation.
1030 @param[in] OrderCount How many to dump.
1031 @param[in] CurrentOrder The pointer to the current order of items.
1032 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
1034 @retval SHELL_SUCCESS The dump was successful.
1035 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1040 IN CONST CHAR16
*Op
,
1041 IN CONST UINTN OrderCount
,
1042 IN CONST UINT16
*CurrentOrder
,
1043 IN CONST BOOLEAN VerboseOutput
1049 CHAR16 VariableName
[12];
1052 CHAR16
*DevPathString
;
1055 EFI_LOAD_OPTION
*LoadOption
;
1056 CHAR16
*Description
;
1057 UINTN DescriptionSize
;
1059 if (OrderCount
== 0) {
1060 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellBcfgHiiHandle
, L
"bcfg");
1061 return (SHELL_SUCCESS
);
1066 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1070 DevPathString
= NULL
;
1072 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1074 Status
= gRT
->GetVariable(
1076 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1080 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1081 Buffer
= AllocateZeroPool(BufferSize
);
1082 Status
= gRT
->GetVariable(
1084 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1090 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1091 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1097 // We expect the Attributes, FilePathListLength, and L'\0'-terminated
1098 // Description fields to be present.
1100 if (BufferSize
< sizeof *LoadOption
+ sizeof (CHAR16
)) {
1105 STRING_TOKEN (STR_BCFG_VAR_CORRUPT
),
1106 gShellBcfgHiiHandle
,
1114 LoadOption
= (EFI_LOAD_OPTION
*)Buffer
;
1115 Description
= (CHAR16
*)(&LoadOption
->FilePathListLength
+ 1);
1116 DescriptionSize
= StrSize (Description
);
1118 if (LoadOption
->FilePathListLength
!= 0) {
1119 DevPath
= AllocateZeroPool(LoadOption
->FilePathListLength
);
1120 if (DevPath
!= NULL
) {
1121 CopyMem(DevPath
, Buffer
+6+DescriptionSize
, LoadOption
->FilePathListLength
);
1122 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
1129 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1130 gShellBcfgHiiHandle
,
1135 (DescriptionSize
+ LoadOption
->FilePathListLength
+ 6) <= BufferSize
?L
'N':L
'Y');
1136 if (VerboseOutput
) {
1137 for (LoopVar2
= (DescriptionSize
+ LoadOption
->FilePathListLength
+ 6);LoopVar2
<BufferSize
;LoopVar2
++){
1153 if (Buffer
!= NULL
) {
1156 if (DevPath
!= NULL
) {
1159 if (DevPathString
!= NULL
) {
1160 FreePool(DevPathString
);
1163 return (Errors
> 0) ? SHELL_INVALID_PARAMETER
: SHELL_SUCCESS
;
1167 Function to initialize the BCFG operation structure.
1169 @param[in] Struct The stuct to initialize.
1174 IN BGFG_OPERATION
*Struct
1177 ASSERT(Struct
!= NULL
);
1178 Struct
->Target
= BcfgTargetMax
;
1179 Struct
->Type
= BcfgTypeMax
;
1180 Struct
->Number1
= 0;
1181 Struct
->Number2
= 0;
1182 Struct
->HandleIndex
= 0;
1183 Struct
->FileName
= NULL
;
1184 Struct
->Description
= NULL
;
1185 Struct
->Order
= NULL
;
1186 Struct
->OptData
= NULL
;
1190 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1192 {L
"-opt", TypeMaxValue
},
1197 Function for 'bcfg' command.
1199 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1200 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1204 ShellCommandRunBcfg (
1205 IN EFI_HANDLE ImageHandle
,
1206 IN EFI_SYSTEM_TABLE
*SystemTable
1210 LIST_ENTRY
*Package
;
1211 CHAR16
*ProblemParam
;
1212 SHELL_STATUS ShellStatus
;
1214 CONST CHAR16
*CurrentParam
;
1215 BGFG_OPERATION CurrentOperation
;
1217 UINT64 Intermediate
;
1221 ProblemParam
= NULL
;
1223 ShellStatus
= SHELL_SUCCESS
;
1225 InitBcfgStruct(&CurrentOperation
);
1228 // initialize the shell lib (we must be in non-auto-init...)
1230 Status
= ShellInitialize();
1231 ASSERT_EFI_ERROR(Status
);
1233 Status
= CommandInit();
1234 ASSERT_EFI_ERROR(Status
);
1237 // parse the command line
1239 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1240 if (EFI_ERROR(Status
)) {
1241 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1242 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellBcfgHiiHandle
, L
"bcfg", ProblemParam
);
1243 FreePool(ProblemParam
);
1244 ShellStatus
= SHELL_INVALID_PARAMETER
;
1250 // Read in if we are doing -OPT
1252 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1253 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1254 if (CurrentOperation
.OptData
== NULL
) {
1255 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellBcfgHiiHandle
, L
"bcfg", L
"-opt");
1256 ShellStatus
= SHELL_INVALID_PARAMETER
;
1258 CurrentOperation
.Type
= BcfgTypeOpt
;
1262 // small block to read the target of the operation
1264 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1265 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1267 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1268 ShellStatus
= SHELL_INVALID_PARAMETER
;
1269 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1270 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1271 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1272 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1274 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellBcfgHiiHandle
, L
"bcfg");
1275 ShellStatus
= SHELL_INVALID_PARAMETER
;
1280 // Read in the boot or driver order environment variable (not needed for opt)
1282 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1284 Status
= gRT
->GetVariable(
1285 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1286 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1289 CurrentOperation
.Order
);
1290 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1291 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1292 if (CurrentOperation
.Order
== NULL
) {
1293 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1295 Status
= gRT
->GetVariable(
1296 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1297 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1300 CurrentOperation
.Order
);
1305 Count
= (UINT16
) (Length
/ sizeof(CurrentOperation
.Order
[0]));
1308 // large block to read the type of operation and verify parameter types for the info.
1310 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1311 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1312 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1313 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1314 CurrentOperation
.Type
= BcfgTypeDump
;
1315 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1316 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"-v (without dump)");
1317 ShellStatus
= SHELL_INVALID_PARAMETER
;
1318 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1319 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1320 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1321 ShellStatus
= SHELL_INVALID_PARAMETER
;
1323 CurrentOperation
.Type
= BcfgTypeAdd
;
1324 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1325 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1326 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1327 ShellStatus
= SHELL_INVALID_PARAMETER
;
1329 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1330 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1331 ASSERT(CurrentOperation
.FileName
== NULL
);
1332 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1333 ASSERT(CurrentOperation
.Description
== NULL
);
1334 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1336 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1337 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1338 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1339 ShellStatus
= SHELL_INVALID_PARAMETER
;
1341 CurrentOperation
.Type
= BcfgTypeAddp
;
1342 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1343 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1344 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1345 ShellStatus
= SHELL_INVALID_PARAMETER
;
1347 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1348 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1349 ASSERT(CurrentOperation
.FileName
== NULL
);
1350 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1351 ASSERT(CurrentOperation
.Description
== NULL
);
1352 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1354 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1355 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1356 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1357 ShellStatus
= SHELL_INVALID_PARAMETER
;
1359 CurrentOperation
.Type
= BcfgTypeAddh
;
1360 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1361 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1362 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1363 ShellStatus
= SHELL_INVALID_PARAMETER
;
1365 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1366 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1367 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1368 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1369 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1370 ShellStatus
= SHELL_INVALID_PARAMETER
;
1372 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1373 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1374 ASSERT(CurrentOperation
.Description
== NULL
);
1375 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1378 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1379 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1380 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1381 ShellStatus
= SHELL_INVALID_PARAMETER
;
1383 CurrentOperation
.Type
= BcfgTypeRm
;
1384 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1385 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1386 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1387 ShellStatus
= SHELL_INVALID_PARAMETER
;
1389 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1390 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1391 if (CurrentOperation
.Number1
>= Count
){
1392 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1393 ShellStatus
= SHELL_INVALID_PARAMETER
;
1396 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1397 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1398 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1399 ShellStatus
= SHELL_INVALID_PARAMETER
;
1401 CurrentOperation
.Type
= BcfgTypeMv
;
1402 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1403 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1404 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1405 ShellStatus
= SHELL_INVALID_PARAMETER
;
1407 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1408 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1409 if (CurrentOperation
.Number1
>= Count
){
1410 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1411 ShellStatus
= SHELL_INVALID_PARAMETER
;
1413 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1414 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1415 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1416 ShellStatus
= SHELL_INVALID_PARAMETER
;
1418 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1419 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1421 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1422 ||CurrentOperation
.Number2
>= Count
1424 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1425 ShellStatus
= SHELL_INVALID_PARAMETER
;
1430 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1431 ShellStatus
= SHELL_INVALID_PARAMETER
;
1435 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1437 // we have all the info. Do the work
1439 switch (CurrentOperation
.Type
) {
1441 ShellStatus
= BcfgDisplayDump(
1442 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1444 CurrentOperation
.Order
,
1445 ShellCommandLineGetFlag(Package
, L
"-v"));
1448 ShellStatus
= BcfgMove(
1449 CurrentOperation
.Target
,
1450 CurrentOperation
.Order
,
1452 CurrentOperation
.Number1
,
1453 CurrentOperation
.Number2
);
1456 ShellStatus
= BcfgRemove(
1457 CurrentOperation
.Target
,
1458 CurrentOperation
.Order
,
1460 CurrentOperation
.Number1
);
1465 ShellStatus
= BcfgAdd(
1466 CurrentOperation
.Number1
,
1467 CurrentOperation
.FileName
,
1468 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1469 CurrentOperation
.Order
,
1471 CurrentOperation
.Target
,
1472 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1473 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1474 CurrentOperation
.HandleIndex
);
1477 ShellStatus
= BcfgAddOpt(
1478 CurrentOperation
.OptData
,
1479 CurrentOperation
.Order
,
1481 CurrentOperation
.Target
);
1489 if (Package
!= NULL
) {
1490 ShellCommandLineFreeVarList (Package
);
1492 if (CurrentOperation
.FileName
!= NULL
) {
1493 FreePool(CurrentOperation
.FileName
);
1495 if (CurrentOperation
.Description
!= NULL
) {
1496 FreePool(CurrentOperation
.Description
);
1498 if (CurrentOperation
.Order
!= NULL
) {
1499 FreePool(CurrentOperation
.Order
);
1502 return (ShellStatus
);
1507 Function to get the filename with help context if HII will not be used.
1509 @return The filename with help text in it.
1513 ShellCommandGetManFileNameBcfg (
1521 "Constructor" for the library.
1523 This will register the handler for the bcfg command.
1525 @param[in] ImageHandle the image handle of the process
1526 @param[in] SystemTable the EFI System Table pointer
1527 @param[in] Name the profile name to use
1529 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
1530 @retval EFI_UNSUPPORTED the shell level required was not found.
1534 BcfgLibraryRegisterBcfgCommand (
1535 IN EFI_HANDLE ImageHandle
,
1536 IN EFI_SYSTEM_TABLE
*SystemTable
,
1537 IN CONST CHAR16
*Name
1540 if (gShellBcfgHiiHandle
!= NULL
) {
1541 return (EFI_SUCCESS
);
1544 gShellBcfgHiiHandle
= HiiAddPackages (&gShellBcfgHiiGuid
, gImageHandle
, UefiShellBcfgCommandLibStrings
, NULL
);
1545 if (gShellBcfgHiiHandle
== NULL
) {
1546 return (EFI_DEVICE_ERROR
);
1550 // install our shell command handler
1552 ShellCommandRegisterCommandName(L
"bcfg", ShellCommandRunBcfg
, ShellCommandGetManFileNameBcfg
, 0, Name
, FALSE
, gShellBcfgHiiHandle
, STRING_TOKEN(STR_GET_HELP_BCFG
));
1554 return (EFI_SUCCESS
);
1558 Destructor for the library. free any resources.
1560 @param ImageHandle The image handle of the process.
1561 @param SystemTable The EFI System Table pointer.
1565 BcfgLibraryUnregisterBcfgCommand (
1566 IN EFI_HANDLE ImageHandle
,
1567 IN EFI_SYSTEM_TABLE
*SystemTable
1570 if (gShellBcfgHiiHandle
!= NULL
) {
1571 HiiRemovePackages(gShellBcfgHiiHandle
);
1573 gShellBcfgHiiHandle
= NULL
;
1574 return (EFI_SUCCESS
);