2 Main file for BCFG command.
4 (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2017, 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.
19 #include <Guid/GlobalVariable.h>
20 #include <Guid/ShellLibHiiGuid.h>
22 #include <Protocol/Shell.h>
23 #include <Protocol/ShellParameters.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/LoadedImage.h>
26 #include <Protocol/UnicodeCollation.h>
28 #include <Library/BaseLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/PcdLib.h>
33 #include <Library/ShellCommandLib.h>
34 #include <Library/ShellLib.h>
35 #include <Library/SortLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/HiiLib.h>
40 #include <Library/FileHandleLib.h>
41 #include <Library/PrintLib.h>
42 #include <Library/HandleParsingLib.h>
43 #include <Library/DevicePathLib.h>
44 #include <Library/UefiBootManagerLib.h>
46 STATIC CONST CHAR16 mFileName
[] = L
"ShellCommands";
47 STATIC EFI_HANDLE gShellBcfgHiiHandle
= NULL
;
50 BcfgTargetBootOrder
= 0,
51 BcfgTargetDriverOrder
= 1,
53 } BCFG_OPERATION_TARGET
;
68 } BCFG_OPERATION_TYPE
;
71 BCFG_OPERATION_TARGET Target
;
72 BCFG_OPERATION_TYPE Type
;
79 CONST CHAR16
*OptData
;
83 Update the optional data for a boot or driver option.
85 If optional data exists it will be changed.
87 @param[in] Index The boot or driver option index update.
88 @param[in] DataSize The size in bytes of Data.
89 @param[in] Data The buffer for the optioanl data.
90 @param[in] Target The target of the operation.
92 @retval EFI_SUCCESS The data was sucessfully updated.
93 @retval other A error occured.
100 IN CONST BCFG_OPERATION_TARGET Target
104 CHAR16 VariableName
[12];
109 UINTN OriginalOptionDataSize
;
111 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", Index
);
118 Status
= gRT
->GetVariable(
120 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
124 if (Status
== EFI_BUFFER_TOO_SMALL
) {
125 OriginalData
= AllocateZeroPool(OriginalSize
);
126 if (OriginalData
== NULL
) {
127 return (EFI_OUT_OF_RESOURCES
);
129 Status
= gRT
->GetVariable(
131 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
137 if (!EFI_ERROR(Status
)) {
139 // Allocate new struct and discard old optional data.
141 ASSERT (OriginalData
!= NULL
);
142 OriginalOptionDataSize
= sizeof(UINT32
) + sizeof(UINT16
) + StrSize(((CHAR16
*)(OriginalData
+ sizeof(UINT32
) + sizeof(UINT16
))));
143 OriginalOptionDataSize
+= (*(UINT16
*)(OriginalData
+ sizeof(UINT32
)));
144 OriginalOptionDataSize
-= OriginalSize
;
145 NewSize
= OriginalSize
- OriginalOptionDataSize
+ DataSize
;
146 NewData
= AllocateCopyPool(NewSize
, OriginalData
);
147 if (NewData
== NULL
) {
148 Status
= EFI_OUT_OF_RESOURCES
;
150 CopyMem(NewData
+ OriginalSize
- OriginalOptionDataSize
, Data
, DataSize
);
154 if (!EFI_ERROR(Status
)) {
156 // put the data back under the variable
158 Status
= gRT
->SetVariable(
160 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
161 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
166 SHELL_FREE_NON_NULL(OriginalData
);
167 SHELL_FREE_NON_NULL(NewData
);
172 This function will get a CRC for a boot option.
174 @param[in, out] Crc The CRC value to return.
175 @param[in] BootIndex The boot option index to CRC.
177 @retval EFI_SUCCESS The CRC was sucessfully returned.
178 @retval other A error occured.
186 CHAR16 VariableName
[12];
195 // Get the data Buffer
197 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%Boot%04x", BootIndex
);
198 Status
= gRT
->GetVariable(
200 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
204 if (Status
== EFI_BUFFER_TOO_SMALL
) {
205 Buffer
= AllocateZeroPool(BufferSize
);
206 Status
= gRT
->GetVariable(
208 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
215 // Get the CRC computed
217 if (!EFI_ERROR(Status
)) {
218 Status
= gBS
->CalculateCrc32 (Buffer
, BufferSize
, Crc
);
221 SHELL_FREE_NON_NULL(Buffer
);
226 This function will populate the device path protocol parameter based on TheHandle.
228 @param[in] TheHandle Driver handle.
229 @param[in, out] FilePath On a sucessful return the device path to the handle.
231 @retval EFI_SUCCESS The device path was sucessfully returned.
232 @retval other A error from gBS->HandleProtocol.
237 GetDevicePathForDriverHandle (
238 IN EFI_HANDLE TheHandle
,
239 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
243 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
244 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
246 Status
= gBS
->OpenProtocol (
248 &gEfiLoadedImageProtocolGuid
,
249 (VOID
**)&LoadedImage
,
252 EFI_OPEN_PROTOCOL_GET_PROTOCOL
254 if (!EFI_ERROR (Status
)) {
255 Status
= gBS
->OpenProtocol (
256 LoadedImage
->DeviceHandle
,
257 &gEfiDevicePathProtocolGuid
,
258 (VOID
**)&ImageDevicePath
,
261 EFI_OPEN_PROTOCOL_GET_PROTOCOL
263 if (!EFI_ERROR (Status
)) {
264 // *DevPath = DuplicateDevicePath (ImageDevicePath);
265 // *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
266 *FilePath
= AppendDevicePath(ImageDevicePath
,LoadedImage
->FilePath
);
268 LoadedImage
->DeviceHandle
,
269 &gEfiDevicePathProtocolGuid
,
275 &gEfiLoadedImageProtocolGuid
,
283 Functino to get Device Path by a handle.
285 @param[in] TheHandle Use it to get DevicePath.
286 @param[in] Target Boot option target.
287 @param[in, out] DevicePath On a sucessful return the device path to the handle.
289 @retval SHELL_INVALID_PARAMETER The handle was NULL.
290 @retval SHELL_NOT_FOUND Not found device path by handle.
291 @retval SHELL_SUCCESS Get device path successfully.
294 GetDevicePathByHandle(
295 IN EFI_HANDLE TheHandle
,
296 IN BCFG_OPERATION_TARGET Target
,
297 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
301 SHELL_STATUS ShellStatus
;
303 UINTN DriverBindingHandleCount
;
304 UINTN ParentControllerHandleCount
;
305 UINTN ChildControllerHandleCount
;
307 ShellStatus
= SHELL_SUCCESS
;
309 if (TheHandle
== NULL
) {
310 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Handle Number");
311 return SHELL_INVALID_PARAMETER
;
314 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle
, &DriverBindingHandleCount
, NULL
);
315 if (EFI_ERROR(Status
)) {
316 DriverBindingHandleCount
= 0;
319 Status
= PARSE_HANDLE_DATABASE_PARENTS (TheHandle
, &ParentControllerHandleCount
, NULL
);
320 if (EFI_ERROR (Status
)) {
321 ParentControllerHandleCount
= 0;
324 Status
= ParseHandleDatabaseForChildControllers (TheHandle
, &ChildControllerHandleCount
, NULL
);
325 if (EFI_ERROR (Status
)) {
326 ChildControllerHandleCount
= 0;
329 Status
= gBS
->HandleProtocol (TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)DevicePath
);
331 if ( DriverBindingHandleCount
> 0 ||
332 ParentControllerHandleCount
> 0 ||
333 ChildControllerHandleCount
> 0 ||
337 // The handle points to a real controller which has a device path.
339 if (Target
== BcfgTargetDriverOrder
) {
343 NULL
,STRING_TOKEN (STR_GEN_PARAM_INV
),
346 L
"Handle should point to driver image."
348 ShellStatus
= SHELL_NOT_FOUND
;
352 // The handle points to a driver image.
354 if (Target
== BcfgTargetBootOrder
) {
359 STRING_TOKEN (STR_GEN_PARAM_INV
),
362 L
"Handle should point to controller."
364 ShellStatus
= SHELL_NOT_FOUND
;
366 if (EFI_ERROR (GetDevicePathForDriverHandle (TheHandle
, DevicePath
))) {
367 ShellStatus
= SHELL_NOT_FOUND
;
372 return (ShellStatus
);
376 Function to modify an option.
378 @param[in] BcfgOperation Pointer to BCFG operation.
379 @param[in] OrderCount The number if items in CurrentOrder.
381 @retval SHELL_SUCCESS The operation was successful.
382 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
383 @retval SHELL_OUT_OF_RESOUCES A memory allocation failed.
387 IN CONST BGFG_OPERATION
*BcfgOperation
,
388 IN CONST UINTN OrderCount
392 EFI_HANDLE CurHandle
;
393 SHELL_STATUS ShellStatus
;
394 CHAR16 OptionStr
[40];
395 EFI_SHELL_FILE_INFO
*FileList
;
396 EFI_SHELL_FILE_INFO
*Arg
;
397 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
398 EFI_DEVICE_PATH_PROTOCOL
*DevicePathBuffer
;
399 EFI_DEVICE_PATH_PROTOCOL
*DevicePathWalker
;
400 EFI_BOOT_MANAGER_LOAD_OPTION LoadOption
;
402 ShellStatus
= SHELL_SUCCESS
;
406 ZeroMem (&LoadOption
, sizeof(EFI_BOOT_MANAGER_LOAD_OPTION
));
408 if ( (BcfgOperation
->Type
== BcfgTypeMod
&& BcfgOperation
->Description
== NULL
) ||
409 (BcfgOperation
->Type
== BcfgTypeModf
&& BcfgOperation
->FileName
== NULL
) ||
410 (BcfgOperation
->Type
== BcfgTypeModp
&& BcfgOperation
->FileName
== NULL
) ||
411 (BcfgOperation
->Type
== BcfgTypeModh
&& BcfgOperation
->HandleIndex
== 0) ||
412 (BcfgOperation
->Number1
> OrderCount
)
414 return (SHELL_INVALID_PARAMETER
);
417 if (BcfgOperation
->Type
== BcfgTypeModh
) {
418 CurHandle
= ConvertHandleIndexToHandle (BcfgOperation
->HandleIndex
);
419 ShellStatus
= GetDevicePathByHandle (CurHandle
, BcfgOperation
->Target
, &DevicePathBuffer
);
420 if (ShellStatus
== SHELL_SUCCESS
) {
421 DevicePath
= DuplicateDevicePath (DevicePathBuffer
);
423 } else if (BcfgOperation
->Type
== BcfgTypeModf
|| BcfgOperation
->Type
== BcfgTypeModp
) {
425 // Get Device Path by FileName.
427 ShellOpenFileMetaArg ((CHAR16
*)BcfgOperation
->FileName
, EFI_FILE_MODE_READ
, &FileList
);
428 if (FileList
== NULL
) {
430 // The name of file matched nothing.
432 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", BcfgOperation
->FileName
);
433 ShellStatus
= SHELL_INVALID_PARAMETER
;
435 else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
437 // If the name of file expanded to multiple names, it's fail.
439 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellBcfgHiiHandle
, L
"bcfg", BcfgOperation
->FileName
);
440 ShellStatus
= SHELL_INVALID_PARAMETER
;
442 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode (&FileList
->Link
);
443 if (EFI_ERROR (Arg
->Status
)) {
444 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellBcfgHiiHandle
, L
"bcfg", BcfgOperation
->FileName
);
445 ShellStatus
= SHELL_INVALID_PARAMETER
;
447 DevicePathBuffer
= gEfiShellProtocol
->GetDevicePathFromFilePath (Arg
->FullName
);
448 if (DevicePathBuffer
== NULL
) {
449 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellBcfgHiiHandle
, L
"bcfg", Arg
->FullName
);
450 ShellStatus
= SHELL_UNSUPPORTED
;
455 if (ShellStatus
== SHELL_SUCCESS
) {
456 if (BcfgOperation
->Type
== BcfgTypeModp
) {
457 ShellStatus
= SHELL_INVALID_PARAMETER
;
458 DevicePathWalker
= DevicePathBuffer
;
459 while (!IsDevicePathEnd (DevicePathWalker
)) {
460 if ( DevicePathType (DevicePathWalker
) == MEDIA_DEVICE_PATH
&&
461 DevicePathSubType (DevicePathWalker
) == MEDIA_HARDDRIVE_DP
464 // We found the portion of device path starting with the hard driver partition.
466 ShellStatus
= SHELL_SUCCESS
;
467 DevicePath
= DuplicateDevicePath (DevicePathWalker
);
470 DevicePathWalker
= NextDevicePathNode (DevicePathWalker
);
474 DevicePath
= DuplicateDevicePath (DevicePathBuffer
);
477 FreePool (DevicePathBuffer
);
481 if (ShellStatus
== SHELL_SUCCESS
) {
482 if (BcfgOperation
->Target
== BcfgTargetBootOrder
) {
483 UnicodeSPrint (OptionStr
, sizeof (OptionStr
), L
"Boot%04x", BcfgOperation
->Order
[BcfgOperation
->Number1
]);
485 UnicodeSPrint (OptionStr
, sizeof (OptionStr
), L
"Driver%04x", BcfgOperation
->Order
[BcfgOperation
->Number1
]);
487 Status
= EfiBootManagerVariableToLoadOption (OptionStr
, &LoadOption
);
488 if (EFI_ERROR(Status
)) {
489 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NONE
), gShellBcfgHiiHandle
);
490 ShellStatus
= SHELL_NOT_FOUND
;
494 if (ShellStatus
== SHELL_SUCCESS
) {
495 if (BcfgOperation
->Type
== BcfgTypeMod
) {
496 SHELL_FREE_NON_NULL (LoadOption
.Description
);
497 LoadOption
.Description
= AllocateCopyPool (StrSize (BcfgOperation
->Description
), BcfgOperation
->Description
);
499 SHELL_FREE_NON_NULL (LoadOption
.FilePath
);
500 LoadOption
.FilePath
= DuplicateDevicePath (DevicePath
);
503 Status
= EfiBootManagerLoadOptionToVariable (&LoadOption
);
504 if (EFI_ERROR(Status
)) {
505 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", OptionStr
);
506 ShellStatus
= SHELL_INVALID_PARAMETER
;
510 EfiBootManagerFreeLoadOption (&LoadOption
);
512 if (DevicePath
!= NULL
) {
513 FreePool (DevicePath
);
516 if (FileList
!= NULL
) {
517 ShellCloseFileMetaArg (&FileList
);
520 return (ShellStatus
);
524 Function to add a option.
526 @param[in] Position The position to add Target at.
527 @param[in] File The file to make the target.
528 @param[in] Desc The description text.
529 @param[in] CurrentOrder The pointer to the current order of items.
530 @param[in] OrderCount The number if items in CurrentOrder.
531 @param[in] Target The info on the option to add.
532 @param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
533 @param[in] UsePath TRUE to convert to devicepath.
534 @param[in] HandleNumber The handle number to add.
536 @retval SHELL_SUCCESS The operation was successful.
537 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
542 IN CONST CHAR16
*File
,
543 IN CONST CHAR16
*Desc
,
544 IN CONST UINT16
*CurrentOrder
,
545 IN CONST UINTN OrderCount
,
546 IN CONST BCFG_OPERATION_TARGET Target
,
547 IN CONST BOOLEAN UseHandle
,
548 IN CONST BOOLEAN UsePath
,
549 IN CONST UINTN HandleNumber
553 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
554 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
555 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
557 UINT8
*TempByteBuffer
;
558 UINT8
*TempByteStart
;
559 EFI_SHELL_FILE_INFO
*Arg
;
560 EFI_SHELL_FILE_INFO
*FileList
;
561 CHAR16 OptionStr
[40];
562 UINTN DescSize
, FilePathSize
;
564 UINTN TargetLocation
;
567 EFI_HANDLE CurHandle
;
568 UINTN DriverBindingHandleCount
;
569 UINTN ParentControllerHandleCount
;
570 UINTN ChildControllerHandleCount
;
571 SHELL_STATUS ShellStatus
;
575 if (File
== NULL
|| Desc
== NULL
) {
576 return (SHELL_INVALID_PARAMETER
);
579 if (HandleNumber
== 0) {
580 return (SHELL_INVALID_PARAMETER
);
584 if (Position
> OrderCount
) {
585 Position
= OrderCount
;
592 ShellStatus
= SHELL_SUCCESS
;
593 TargetLocation
= 0xFFFF;
596 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
597 if (CurHandle
== NULL
) {
598 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Handle Number");
599 ShellStatus
= SHELL_INVALID_PARAMETER
;
601 if (Target
== BcfgTargetBootOrder
) {
603 //Make sure that the handle should point to a real controller
605 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
607 &DriverBindingHandleCount
,
610 Status
= PARSE_HANDLE_DATABASE_PARENTS (
612 &ParentControllerHandleCount
,
615 Status
= ParseHandleDatabaseForChildControllers (
617 &ChildControllerHandleCount
,
620 if (DriverBindingHandleCount
> 0
621 || ParentControllerHandleCount
> 0
622 || ChildControllerHandleCount
> 0) {
624 Status
= gBS
->HandleProtocol (
626 &gEfiDevicePathProtocolGuid
,
629 if (EFI_ERROR (Status
)) {
630 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellBcfgHiiHandle
, L
"bcfg", HandleNumber
);
631 ShellStatus
= SHELL_INVALID_PARAMETER
;
635 //Make sure that the handle should point to driver, not a controller.
637 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
639 &DriverBindingHandleCount
,
642 Status
= PARSE_HANDLE_DATABASE_PARENTS (
644 &ParentControllerHandleCount
,
647 Status
= ParseHandleDatabaseForChildControllers (
649 &ChildControllerHandleCount
,
652 Status
= gBS
->HandleProtocol (
654 &gEfiDevicePathProtocolGuid
,
657 if (DriverBindingHandleCount
> 0
658 || ParentControllerHandleCount
> 0
659 || ChildControllerHandleCount
> 0
660 || !EFI_ERROR(Status
) ) {
661 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Handle Number");
662 ShellStatus
= SHELL_INVALID_PARAMETER
;
665 // Get the DevicePath from the loaded image information.
667 Status
= GetDevicePathForDriverHandle(CurHandle
, &FilePath
);
675 ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
677 if (FileList
== NULL
) {
679 // If filename matched nothing fail
681 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", File
);
682 ShellStatus
= SHELL_INVALID_PARAMETER
;
683 } else if (FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
685 // If filename expanded to multiple names, fail
687 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellBcfgHiiHandle
, L
"bcfg", File
);
688 ShellStatus
= SHELL_INVALID_PARAMETER
;
690 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
691 if (EFI_ERROR(Arg
->Status
)) {
692 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellBcfgHiiHandle
, L
"bcfg", File
);
693 ShellStatus
= SHELL_INVALID_PARAMETER
;
696 // Build FilePath to the filename
700 // get the device path
702 DevicePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
703 if (DevicePath
== NULL
) {
704 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellBcfgHiiHandle
, L
"bcfg", Arg
->FullName
);
705 ShellStatus
= SHELL_UNSUPPORTED
;
708 DevPath
= DevicePath
;
709 ShellStatus
= SHELL_INVALID_PARAMETER
;
710 while (!IsDevicePathEnd(DevPath
)) {
711 if ((DevicePathType(DevPath
) == MEDIA_DEVICE_PATH
) &&
712 (DevicePathSubType(DevPath
) == MEDIA_HARDDRIVE_DP
)) {
715 // If we find it use it instead
717 ShellStatus
= SHELL_SUCCESS
;
718 FilePath
= DuplicateDevicePath (DevPath
);
721 DevPath
= NextDevicePathNode(DevPath
);
724 FilePath
= DuplicateDevicePath(DevicePath
);
726 FreePool(DevicePath
);
733 if (ShellStatus
== SHELL_SUCCESS
) {
735 // Find a free target ,a brute force implementation
738 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
740 for (Index
=0; Index
< OrderCount
; Index
++) {
741 if (CurrentOrder
[Index
] == TargetLocation
) {
752 if (TargetLocation
== 0xFFFF) {
753 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellBcfgHiiHandle
, L
"bcfg");
755 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellBcfgHiiHandle
, TargetLocation
);
759 if (ShellStatus
== SHELL_SUCCESS
) {
763 DescSize
= StrSize(Desc
);
764 FilePathSize
= GetDevicePathSize (FilePath
);
766 TempByteBuffer
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
767 if (TempByteBuffer
!= NULL
) {
768 TempByteStart
= TempByteBuffer
;
769 *((UINT32
*) TempByteBuffer
) = LOAD_OPTION_ACTIVE
; // Attributes
770 TempByteBuffer
+= sizeof (UINT32
);
772 *((UINT16
*) TempByteBuffer
) = (UINT16
)FilePathSize
; // FilePathListLength
773 TempByteBuffer
+= sizeof (UINT16
);
775 CopyMem (TempByteBuffer
, Desc
, DescSize
);
776 TempByteBuffer
+= DescSize
;
777 ASSERT (FilePath
!= NULL
);
778 CopyMem (TempByteBuffer
, FilePath
, FilePathSize
);
780 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", TargetLocation
);
781 Status
= gRT
->SetVariable (
783 &gEfiGlobalVariableGuid
,
784 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
785 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
789 FreePool(TempByteStart
);
791 Status
= EFI_OUT_OF_RESOURCES
;
794 if (EFI_ERROR(Status
)) {
795 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", OptionStr
);
797 NewOrder
= AllocateZeroPool ((OrderCount
+ 1) * sizeof (NewOrder
[0]));
798 if (NewOrder
!= NULL
) {
799 CopyMem (NewOrder
, CurrentOrder
, (OrderCount
) * sizeof (NewOrder
[0]));
802 // Insert target into order list
804 for (Index
= OrderCount
; Index
> Position
; Index
--) {
805 NewOrder
[Index
] = NewOrder
[Index
- 1];
808 NewOrder
[Position
] = (UINT16
) TargetLocation
;
809 Status
= gRT
->SetVariable (
810 Target
== BcfgTargetBootOrder
? L
"BootOrder" : L
"DriverOrder",
811 &gEfiGlobalVariableGuid
,
812 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
813 (OrderCount
+ 1) * sizeof (UINT16
),
819 if (EFI_ERROR (Status
)) {
820 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
? L
"BootOrder" : L
"DriverOrder");
821 ShellStatus
= SHELL_INVALID_PARAMETER
;
823 Print (L
"bcfg: Add %s as %x\n", OptionStr
, Position
);
830 //If always Free FilePath, will free devicepath in system when use "addh"
832 if (FilePath
!=NULL
&& !UseHandle
) {
840 if (Handles
!= NULL
) {
844 if (FileList
!= NULL
) {
845 ShellCloseFileMetaArg (&FileList
);
848 return (ShellStatus
);
852 Funciton to remove an item.
854 @param[in] Target The target item to move.
855 @param[in] CurrentOrder The pointer to the current order of items.
856 @param[in] OrderCount The number if items in CurrentOrder.
857 @param[in] Location The current location of the Target.
859 @retval SHELL_SUCCESS The operation was successful.
860 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
864 IN CONST BCFG_OPERATION_TARGET Target
,
865 IN CONST UINT16
*CurrentOrder
,
866 IN CONST UINTN OrderCount
,
867 IN CONST UINT16 Location
870 CHAR16 VariableName
[12];
875 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
876 Status
= gRT
->SetVariable(
878 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
879 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
882 if (EFI_ERROR(Status
)) {
883 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
884 return (SHELL_INVALID_PARAMETER
);
886 NewOrder
= AllocateZeroPool(OrderCount
*sizeof(CurrentOrder
[0]));
887 if (NewOrder
!= NULL
) {
888 NewCount
= OrderCount
;
889 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
890 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
893 Status
= gRT
->SetVariable(
894 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
895 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
896 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
897 NewCount
*sizeof(NewOrder
[0]),
901 Status
= EFI_OUT_OF_RESOURCES
;
903 if (EFI_ERROR(Status
)) {
904 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder");
905 return (SHELL_INVALID_PARAMETER
);
907 return (SHELL_SUCCESS
);
911 Funciton to move a item to another location.
913 @param[in] Target The target item to move.
914 @param[in] CurrentOrder The pointer to the current order of items.
915 @param[in] OrderCount The number if items in CurrentOrder.
916 @param[in] OldLocation The current location of the Target.
917 @param[in] NewLocation The desired location of the Target.
919 @retval SHELL_SUCCESS The operation was successful.
920 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
924 IN CONST BCFG_OPERATION_TARGET Target
,
925 IN CONST UINT16
*CurrentOrder
,
926 IN CONST UINTN OrderCount
,
927 IN CONST UINT16 OldLocation
,
928 IN UINT16 NewLocation
935 NewOrder
= AllocateCopyPool(OrderCount
*sizeof(CurrentOrder
[0]), CurrentOrder
);
936 if (NewOrder
== NULL
) {
937 return (SHELL_OUT_OF_RESOURCES
);
941 // correct the new location
943 if (NewLocation
>= OrderCount
) {
944 if (OrderCount
> 0) {
945 NewLocation
= (UINT16
)OrderCount
- 1;
951 Temp
= CurrentOrder
[OldLocation
];
952 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
953 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
954 NewOrder
[NewLocation
] = Temp
;
956 Status
= gRT
->SetVariable(
957 Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
958 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
959 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
960 OrderCount
*sizeof(CurrentOrder
[0]),
965 if (EFI_ERROR(Status
)) {
966 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder");
967 return (SHELL_INVALID_PARAMETER
);
969 return (SHELL_SUCCESS
);
973 Function to add optional data to an option.
975 @param[in] OptData The optional data to add.
976 @param[in] CurrentOrder The pointer to the current order of items.
977 @param[in] OrderCount The number if items in CurrentOrder.
978 @param[in] Target The target of the operation.
980 @retval SHELL_SUCCESS The operation was succesful.
984 IN CONST CHAR16
*OptData
,
985 IN CONST UINT16
*CurrentOrder
,
986 IN CONST UINTN OrderCount
,
987 IN CONST BCFG_OPERATION_TARGET Target
990 EFI_KEY_OPTION NewKeyOption
;
991 EFI_KEY_OPTION
*KeyOptionBuffer
;
992 SHELL_STATUS ShellStatus
;
998 CONST CHAR16
*Walker
;
1003 CHAR16 VariableName
[12];
1006 SHELL_FILE_HANDLE FileHandle
;
1008 Status
= EFI_SUCCESS
;
1009 ShellStatus
= SHELL_SUCCESS
;
1013 KeyOptionBuffer
= NULL
;
1014 VariableData
= NULL
;
1016 ZeroMem(&NewKeyOption
, sizeof(EFI_KEY_OPTION
));
1017 ZeroMem(VariableName
, sizeof(VariableName
));
1019 while(Walker
[0] == L
' ') {
1024 // Get the index of the variable we are changing.
1026 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
1027 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
|| ((UINT16
)Intermediate
) > ((UINT16
)OrderCount
)) {
1028 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Option Index");
1029 ShellStatus
= SHELL_INVALID_PARAMETER
;
1030 return (ShellStatus
);
1032 OptionIndex
= (UINT16
)Intermediate
;
1034 Temp
= StrStr(Walker
, L
" ");
1038 while(Walker
[0] == L
' ') {
1043 // determine whether we have file with data, quote delimited information, or a hot-key
1045 if (Walker
[0] == L
'\"') {
1047 // quoted filename or quoted information.
1049 Temp
= StrStr(Walker
+1, L
"\"");
1050 if (Temp
== NULL
|| StrLen(Temp
) != 1) {
1051 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1052 ShellStatus
= SHELL_INVALID_PARAMETER
;
1054 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
+1, 0);
1055 if (FileName
== NULL
) {
1056 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
1057 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1058 return (ShellStatus
);
1060 Temp2
= StrStr(FileName
, L
"\"");
1061 ASSERT(Temp2
!= NULL
);
1062 Temp2
[0] = CHAR_NULL
;
1064 if (StrLen(Temp2
)>0) {
1065 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1066 ShellStatus
= SHELL_INVALID_PARAMETER
;
1068 if (EFI_ERROR(ShellFileExists(Walker
))) {
1070 // Not a file. must be misc information.
1075 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
1080 // filename or hot key information.
1082 if (StrStr(Walker
, L
" ") == NULL
) {
1086 if (EFI_ERROR(ShellFileExists(Walker
))) {
1087 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FIND_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1088 ShellStatus
= SHELL_INVALID_PARAMETER
;
1090 FileName
= StrnCatGrow(&FileName
, NULL
, Walker
, 0);
1093 if (Target
!= BcfgTargetBootOrder
) {
1094 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_BOOT_ONLY
), gShellBcfgHiiHandle
, L
"bcfg");
1095 ShellStatus
= SHELL_INVALID_PARAMETER
;
1098 if (ShellStatus
== SHELL_SUCCESS
) {
1100 // Get hot key information
1102 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
1103 if (EFI_ERROR(Status
) || (((UINT32
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
1104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1105 ShellStatus
= SHELL_INVALID_PARAMETER
;
1107 NewKeyOption
.KeyData
.PackedValue
= (UINT32
)Intermediate
;
1108 Temp
= StrStr(Walker
, L
" ");
1112 while(Walker
[0] == L
' ') {
1117 if (ShellStatus
== SHELL_SUCCESS
) {
1119 // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.
1120 // Re-allocate with the added information.
1122 KeyOptionBuffer
= AllocateCopyPool(sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
), &NewKeyOption
);
1123 if (KeyOptionBuffer
== NULL
) {
1124 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
1125 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1128 for (LoopCounter
= 0 ; ShellStatus
== SHELL_SUCCESS
&& LoopCounter
< NewKeyOption
.KeyData
.Options
.InputKeyCount
; LoopCounter
++) {
1132 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
1133 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
) || StrStr(Walker
, L
" ") == NULL
) {
1134 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1135 ShellStatus
= SHELL_INVALID_PARAMETER
;
1137 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].ScanCode
= (UINT16
)Intermediate
;
1138 Temp
= StrStr(Walker
, L
" ");
1142 while(Walker
[0] == L
' ') {
1149 Status
= ShellConvertStringToUint64(Walker
, &Intermediate
, FALSE
, TRUE
);
1150 if (EFI_ERROR(Status
) || (((UINT16
)Intermediate
) != Intermediate
)) {
1151 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", Walker
);
1152 ShellStatus
= SHELL_INVALID_PARAMETER
;
1154 ((EFI_INPUT_KEY
*)(((UINT8
*)KeyOptionBuffer
) + sizeof(EFI_KEY_OPTION
)))[LoopCounter
].UnicodeChar
= (UINT16
)Intermediate
;
1155 Temp
= StrStr(Walker
, L
" ");
1159 while(Walker
[0] == L
' ') {
1164 if (ShellStatus
== SHELL_SUCCESS
) {
1166 // Now do the BootOption / BootOptionCrc
1168 ASSERT (OptionIndex
<= OrderCount
);
1169 KeyOptionBuffer
->BootOption
= CurrentOrder
[OptionIndex
];
1170 Status
= GetBootOptionCrc(&(KeyOptionBuffer
->BootOptionCrc
), KeyOptionBuffer
->BootOption
);
1171 if (EFI_ERROR(Status
)) {
1172 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"Option Index");
1173 ShellStatus
= SHELL_INVALID_PARAMETER
;
1177 if (ShellStatus
== SHELL_SUCCESS
) {
1178 for (Temp2
= NULL
, KeyIndex
= 0 ; KeyIndex
<= 0xFFFF ; KeyIndex
++) {
1179 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"Key%04x", KeyIndex
);
1180 Status
= GetEfiGlobalVariable2 (VariableName
, &VariableData
, NULL
);
1181 if (Status
== EFI_NOT_FOUND
) {
1184 if (!EFI_ERROR(Status
)) {
1185 SHELL_FREE_NON_NULL(VariableData
);
1188 if (KeyIndex
<= 0xFFFF) {
1189 Status
= gRT
->SetVariable(
1191 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1192 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
1193 sizeof(EFI_KEY_OPTION
) + (sizeof(EFI_INPUT_KEY
) * NewKeyOption
.KeyData
.Options
.InputKeyCount
),
1195 if (EFI_ERROR(Status
)) {
1196 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1197 ShellStatus
= SHELL_INVALID_PARAMETER
;
1200 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_VAR_NO_NUM
), gShellBcfgHiiHandle
, L
"bcfg");
1201 ShellStatus
= SHELL_INVALID_PARAMETER
;
1203 ASSERT(FileName
== NULL
&& Data
== NULL
);
1209 // Shouldn't be possible to have have both. Neither is ok though.
1211 ASSERT(FileName
== NULL
|| Data
== NULL
);
1213 if (ShellStatus
== SHELL_SUCCESS
&& (FileName
!= NULL
|| Data
!= NULL
)) {
1214 if (FileName
!= NULL
) {
1216 // Open the file and populate the data buffer.
1218 Status
= ShellOpenFileByName(
1223 if (!EFI_ERROR(Status
)) {
1224 Status
= ShellGetFileSize(FileHandle
, &Intermediate
);
1226 Data
= AllocateZeroPool((UINTN
)Intermediate
);
1228 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellBcfgHiiHandle
, L
"bcfg");
1229 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1231 if (!EFI_ERROR(Status
)) {
1232 Status
= ShellReadFile(FileHandle
, (UINTN
*)&Intermediate
, Data
);
1235 Intermediate
= StrSize(Data
);
1238 if (!EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
&& Data
!= NULL
) {
1239 Status
= UpdateOptionalData(CurrentOrder
[OptionIndex
], (UINTN
)Intermediate
, (UINT8
*)Data
, Target
);
1240 if (EFI_ERROR(Status
)) {
1241 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1242 ShellStatus
= SHELL_INVALID_PARAMETER
;
1245 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
1246 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1247 ShellStatus
= SHELL_INVALID_PARAMETER
;
1251 SHELL_FREE_NON_NULL(Data
);
1252 SHELL_FREE_NON_NULL(KeyOptionBuffer
);
1253 SHELL_FREE_NON_NULL(FileName
);
1258 Function to dump the Bcfg information.
1260 @param[in] Op The operation.
1261 @param[in] OrderCount How many to dump.
1262 @param[in] CurrentOrder The pointer to the current order of items.
1263 @param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
1265 @retval SHELL_SUCCESS The dump was successful.
1266 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
1270 IN CONST CHAR16
*Op
,
1271 IN CONST UINTN OrderCount
,
1272 IN CONST UINT16
*CurrentOrder
,
1273 IN CONST BOOLEAN VerboseOutput
1279 CHAR16 VariableName
[12];
1281 CHAR16
*DevPathString
;
1284 EFI_LOAD_OPTION
*LoadOption
;
1285 CHAR16
*Description
;
1286 UINTN DescriptionSize
;
1287 UINTN OptionalDataOffset
;
1289 if (OrderCount
== 0) {
1290 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_BCFG_NONE
), gShellBcfgHiiHandle
, L
"bcfg");
1291 return (SHELL_SUCCESS
);
1296 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
1299 DevPathString
= NULL
;
1301 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
1303 Status
= gRT
->GetVariable(
1305 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1309 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1310 Buffer
= AllocateZeroPool(BufferSize
);
1311 Status
= gRT
->GetVariable(
1313 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1319 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
1320 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellBcfgHiiHandle
, L
"bcfg", VariableName
);
1326 // We expect the Attributes, FilePathListLength, and L'\0'-terminated
1327 // Description fields to be present.
1329 if (BufferSize
< sizeof *LoadOption
+ sizeof (CHAR16
)) {
1334 STRING_TOKEN (STR_BCFG_VAR_CORRUPT
),
1335 gShellBcfgHiiHandle
,
1343 LoadOption
= (EFI_LOAD_OPTION
*)Buffer
;
1344 Description
= (CHAR16
*)(Buffer
+ sizeof (EFI_LOAD_OPTION
));
1345 DescriptionSize
= StrSize (Description
);
1347 if (LoadOption
->FilePathListLength
!= 0) {
1348 FilePathList
= (UINT8
*)Description
+ DescriptionSize
;
1349 DevPathString
= ConvertDevicePathToText(FilePathList
, TRUE
, FALSE
);
1352 OptionalDataOffset
= sizeof *LoadOption
+ DescriptionSize
+
1353 LoadOption
->FilePathListLength
;
1359 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
1360 gShellBcfgHiiHandle
,
1365 OptionalDataOffset
>= BufferSize
? L
'N' : L
'Y'
1367 if (VerboseOutput
&& (OptionalDataOffset
< BufferSize
)) {
1370 0, // Offset (displayed)
1371 BufferSize
- OptionalDataOffset
, // DataSize
1372 Buffer
+ OptionalDataOffset
// UserData
1377 if (Buffer
!= NULL
) {
1380 if (DevPathString
!= NULL
) {
1381 FreePool(DevPathString
);
1384 return (Errors
> 0) ? SHELL_INVALID_PARAMETER
: SHELL_SUCCESS
;
1388 Function to initialize the BCFG operation structure.
1390 @param[in] Struct The stuct to initialize.
1394 IN BGFG_OPERATION
*Struct
1397 ASSERT(Struct
!= NULL
);
1398 Struct
->Target
= BcfgTargetMax
;
1399 Struct
->Type
= BcfgTypeMax
;
1400 Struct
->Number1
= 0;
1401 Struct
->Number2
= 0;
1402 Struct
->HandleIndex
= 0;
1403 Struct
->FileName
= NULL
;
1404 Struct
->Description
= NULL
;
1405 Struct
->Order
= NULL
;
1406 Struct
->OptData
= NULL
;
1410 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
1412 {L
"-opt", TypeMaxValue
},
1417 Function for 'bcfg' command.
1419 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1420 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1424 ShellCommandRunBcfg (
1425 IN EFI_HANDLE ImageHandle
,
1426 IN EFI_SYSTEM_TABLE
*SystemTable
1430 LIST_ENTRY
*Package
;
1431 CHAR16
*ProblemParam
;
1432 SHELL_STATUS ShellStatus
;
1434 CONST CHAR16
*CurrentParam
;
1435 BGFG_OPERATION CurrentOperation
;
1437 UINT64 Intermediate
;
1441 ProblemParam
= NULL
;
1443 ShellStatus
= SHELL_SUCCESS
;
1445 InitBcfgStruct(&CurrentOperation
);
1448 // initialize the shell lib (we must be in non-auto-init...)
1450 Status
= ShellInitialize();
1451 ASSERT_EFI_ERROR(Status
);
1453 Status
= CommandInit();
1454 ASSERT_EFI_ERROR(Status
);
1457 // parse the command line
1459 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1460 if (EFI_ERROR(Status
)) {
1461 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1462 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellBcfgHiiHandle
, L
"bcfg", ProblemParam
);
1463 FreePool(ProblemParam
);
1464 ShellStatus
= SHELL_INVALID_PARAMETER
;
1470 // Read in if we are doing -OPT
1472 if (ShellCommandLineGetFlag(Package
, L
"-opt")) {
1473 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
1474 if (CurrentOperation
.OptData
== NULL
) {
1475 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellBcfgHiiHandle
, L
"bcfg", L
"-opt");
1476 ShellStatus
= SHELL_INVALID_PARAMETER
;
1478 CurrentOperation
.Type
= BcfgTypeOpt
;
1482 // small block to read the target of the operation
1484 if ((ShellCommandLineGetCount(Package
) < 3 && CurrentOperation
.Type
!= BcfgTypeOpt
) ||
1485 (ShellCommandLineGetCount(Package
) < 2 && CurrentOperation
.Type
== BcfgTypeOpt
)
1487 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1488 ShellStatus
= SHELL_INVALID_PARAMETER
;
1489 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
1490 CurrentOperation
.Target
= BcfgTargetDriverOrder
;
1491 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
1492 CurrentOperation
.Target
= BcfgTargetBootOrder
;
1494 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellBcfgHiiHandle
, L
"bcfg");
1495 ShellStatus
= SHELL_INVALID_PARAMETER
;
1500 // Read in the boot or driver order environment variable (not needed for opt)
1502 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1504 Status
= gRT
->GetVariable(
1505 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1506 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1509 CurrentOperation
.Order
);
1510 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1511 CurrentOperation
.Order
= AllocateZeroPool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
1512 if (CurrentOperation
.Order
== NULL
) {
1513 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1515 Status
= gRT
->GetVariable(
1516 CurrentOperation
.Target
== BcfgTargetBootOrder
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
1517 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
1520 CurrentOperation
.Order
);
1525 Count
= (UINT16
) (Length
/ sizeof(CurrentOperation
.Order
[0]));
1528 // large block to read the type of operation and verify parameter types for the info.
1530 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
) {
1531 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
1532 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
1533 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
1534 CurrentOperation
.Type
= BcfgTypeDump
;
1535 if (ShellCommandLineGetCount(Package
) > 3) {
1536 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellBcfgHiiHandle
, L
"bcfg");
1537 ShellStatus
= SHELL_INVALID_PARAMETER
;
1539 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
1540 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", L
"-v (without dump)");
1541 ShellStatus
= SHELL_INVALID_PARAMETER
;
1542 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
1543 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1544 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1545 ShellStatus
= SHELL_INVALID_PARAMETER
;
1547 CurrentOperation
.Type
= BcfgTypeAdd
;
1548 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1549 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1550 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1551 ShellStatus
= SHELL_INVALID_PARAMETER
;
1553 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1554 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1555 ASSERT(CurrentOperation
.FileName
== NULL
);
1556 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1557 ASSERT(CurrentOperation
.Description
== NULL
);
1558 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1560 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
1561 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1562 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1563 ShellStatus
= SHELL_INVALID_PARAMETER
;
1565 CurrentOperation
.Type
= BcfgTypeAddp
;
1566 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1567 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1568 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1569 ShellStatus
= SHELL_INVALID_PARAMETER
;
1571 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1572 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1573 ASSERT(CurrentOperation
.FileName
== NULL
);
1574 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1575 ASSERT(CurrentOperation
.Description
== NULL
);
1576 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1578 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
1579 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
1580 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1581 ShellStatus
= SHELL_INVALID_PARAMETER
;
1583 CurrentOperation
.Type
= BcfgTypeAddh
;
1584 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1585 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1586 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1587 ShellStatus
= SHELL_INVALID_PARAMETER
;
1589 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1590 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1591 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1592 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1593 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1594 ShellStatus
= SHELL_INVALID_PARAMETER
;
1596 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1597 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1598 ASSERT(CurrentOperation
.Description
== NULL
);
1599 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
1602 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
1603 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
1604 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1605 ShellStatus
= SHELL_INVALID_PARAMETER
;
1607 CurrentOperation
.Type
= BcfgTypeRm
;
1608 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1609 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1610 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1611 ShellStatus
= SHELL_INVALID_PARAMETER
;
1613 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1614 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1615 if (CurrentOperation
.Number1
>= Count
){
1616 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1617 ShellStatus
= SHELL_INVALID_PARAMETER
;
1620 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
1621 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
1622 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1623 ShellStatus
= SHELL_INVALID_PARAMETER
;
1625 CurrentOperation
.Type
= BcfgTypeMv
;
1626 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1627 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1628 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1629 ShellStatus
= SHELL_INVALID_PARAMETER
;
1631 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1632 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1633 if (CurrentOperation
.Number1
>= Count
){
1634 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1635 ShellStatus
= SHELL_INVALID_PARAMETER
;
1637 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
1638 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
1639 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1640 ShellStatus
= SHELL_INVALID_PARAMETER
;
1642 Status
= ShellConvertStringToUint64(CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1643 CurrentOperation
.Number2
= (UINT16
)Intermediate
;
1645 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
1646 ||CurrentOperation
.Number2
>= Count
1648 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1649 ShellStatus
= SHELL_INVALID_PARAMETER
;
1654 else if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mod") == 0) {
1655 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount (Package
)) {
1656 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1657 ShellStatus
= SHELL_INVALID_PARAMETER
;
1659 CurrentOperation
.Type
= BcfgTypeMod
;
1660 CurrentParam
= ShellCommandLineGetRawValue (Package
, ++ParamNumber
);
1661 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber (CurrentParam
, TRUE
, FALSE
)) {
1662 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1663 ShellStatus
= SHELL_INVALID_PARAMETER
;
1665 Status
= ShellConvertStringToUint64 (CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1666 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1667 if (CurrentOperation
.Number1
>= Count
) {
1668 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1669 ShellStatus
= SHELL_INVALID_PARAMETER
;
1671 ASSERT (CurrentOperation
.Description
== NULL
);
1672 CurrentOperation
.Description
= StrnCatGrow (&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue (Package
, ++ParamNumber
), 0);
1676 } else if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"modf") == 0) {
1677 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount (Package
)) {
1678 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1679 ShellStatus
= SHELL_INVALID_PARAMETER
;
1681 CurrentOperation
.Type
= BcfgTypeModf
;
1682 CurrentParam
= ShellCommandLineGetRawValue (Package
, ++ParamNumber
);
1683 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber (CurrentParam
, TRUE
, FALSE
)) {
1684 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1685 ShellStatus
= SHELL_INVALID_PARAMETER
;
1687 Status
= ShellConvertStringToUint64 (CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1688 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1689 if (CurrentOperation
.Number1
>= Count
) {
1690 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1691 ShellStatus
= SHELL_INVALID_PARAMETER
;
1693 ASSERT (CurrentOperation
.FileName
== NULL
);
1694 CurrentOperation
.FileName
= StrnCatGrow (&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue (Package
, ++ParamNumber
), 0);
1698 } else if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"modp") == 0) {
1699 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount (Package
)) {
1700 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1701 ShellStatus
= SHELL_INVALID_PARAMETER
;
1703 CurrentOperation
.Type
= BcfgTypeModp
;
1704 CurrentParam
= ShellCommandLineGetRawValue (Package
, ++ParamNumber
);
1705 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber (CurrentParam
, TRUE
, FALSE
)) {
1706 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1707 ShellStatus
= SHELL_INVALID_PARAMETER
;
1709 Status
= ShellConvertStringToUint64 (CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1710 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1711 if (CurrentOperation
.Number1
>= Count
) {
1712 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1713 ShellStatus
= SHELL_INVALID_PARAMETER
;
1715 ASSERT (CurrentOperation
.FileName
== NULL
);
1716 CurrentOperation
.FileName
= StrnCatGrow (&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue (Package
, ++ParamNumber
), 0);
1720 } else if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"modh") == 0) {
1721 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount (Package
)) {
1722 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellBcfgHiiHandle
, L
"bcfg");
1723 ShellStatus
= SHELL_INVALID_PARAMETER
;
1725 CurrentOperation
.Type
= BcfgTypeModh
;
1726 CurrentParam
= ShellCommandLineGetRawValue (Package
, ++ParamNumber
);
1727 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber (CurrentParam
, TRUE
, FALSE
)) {
1728 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1729 ShellStatus
= SHELL_INVALID_PARAMETER
;
1732 Status
= ShellConvertStringToUint64 (CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1733 CurrentOperation
.Number1
= (UINT16
)Intermediate
;
1734 if (CurrentOperation
.Number1
>= Count
) {
1735 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_BCFG_NUMB_RANGE
), gShellBcfgHiiHandle
, L
"bcfg", Count
);
1736 ShellStatus
= SHELL_INVALID_PARAMETER
;
1738 CurrentParam
= ShellCommandLineGetRawValue (Package
, ++ParamNumber
);
1739 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber (CurrentParam
, TRUE
, FALSE
)) {
1740 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1741 ShellStatus
= SHELL_INVALID_PARAMETER
;
1743 Status
= ShellConvertStringToUint64 (CurrentParam
, &Intermediate
, TRUE
, FALSE
);
1744 CurrentOperation
.HandleIndex
= (UINT16
)Intermediate
;
1750 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellBcfgHiiHandle
, L
"bcfg", CurrentParam
);
1751 ShellStatus
= SHELL_INVALID_PARAMETER
;
1755 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BcfgTargetMax
&& CurrentOperation
.Type
< BcfgTypeMax
) {
1757 // we have all the info. Do the work
1759 switch (CurrentOperation
.Type
) {
1761 ShellStatus
= BcfgDisplayDump(
1762 CurrentOperation
.Target
== BcfgTargetBootOrder
?L
"Boot":L
"Driver",
1764 CurrentOperation
.Order
,
1765 ShellCommandLineGetFlag(Package
, L
"-v"));
1768 ShellStatus
= BcfgMove(
1769 CurrentOperation
.Target
,
1770 CurrentOperation
.Order
,
1772 CurrentOperation
.Number1
,
1773 CurrentOperation
.Number2
);
1776 ShellStatus
= BcfgRemove(
1777 CurrentOperation
.Target
,
1778 CurrentOperation
.Order
,
1780 CurrentOperation
.Number1
);
1785 ShellStatus
= BcfgAdd(
1786 CurrentOperation
.Number1
,
1787 CurrentOperation
.FileName
,
1788 CurrentOperation
.Description
==NULL
?L
"":CurrentOperation
.Description
,
1789 CurrentOperation
.Order
,
1791 CurrentOperation
.Target
,
1792 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddh
),
1793 (BOOLEAN
)(CurrentOperation
.Type
== BcfgTypeAddp
),
1794 CurrentOperation
.HandleIndex
);
1800 ShellStatus
= BcfgMod (&CurrentOperation
, Count
);
1803 ShellStatus
= BcfgAddOpt(
1804 CurrentOperation
.OptData
,
1805 CurrentOperation
.Order
,
1807 CurrentOperation
.Target
);
1815 if (Package
!= NULL
) {
1816 ShellCommandLineFreeVarList (Package
);
1818 if (CurrentOperation
.FileName
!= NULL
) {
1819 FreePool(CurrentOperation
.FileName
);
1821 if (CurrentOperation
.Description
!= NULL
) {
1822 FreePool(CurrentOperation
.Description
);
1824 if (CurrentOperation
.Order
!= NULL
) {
1825 FreePool(CurrentOperation
.Order
);
1828 return (ShellStatus
);
1833 Function to get the filename with help context if HII will not be used.
1835 @return The filename with help text in it.
1839 ShellCommandGetManFileNameBcfg (
1847 "Constructor" for the library.
1849 This will register the handler for the bcfg command.
1851 @param[in] ImageHandle the image handle of the process
1852 @param[in] SystemTable the EFI System Table pointer
1853 @param[in] Name the profile name to use
1855 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
1856 @retval EFI_UNSUPPORTED the shell level required was not found.
1860 BcfgLibraryRegisterBcfgCommand (
1861 IN EFI_HANDLE ImageHandle
,
1862 IN EFI_SYSTEM_TABLE
*SystemTable
,
1863 IN CONST CHAR16
*Name
1866 if (gShellBcfgHiiHandle
!= NULL
) {
1867 return (EFI_SUCCESS
);
1870 gShellBcfgHiiHandle
= HiiAddPackages (&gShellBcfgHiiGuid
, gImageHandle
, UefiShellBcfgCommandLibStrings
, NULL
);
1871 if (gShellBcfgHiiHandle
== NULL
) {
1872 return (EFI_DEVICE_ERROR
);
1876 // install our shell command handler
1878 ShellCommandRegisterCommandName(L
"bcfg", ShellCommandRunBcfg
, ShellCommandGetManFileNameBcfg
, 0, Name
, FALSE
, gShellBcfgHiiHandle
, STRING_TOKEN(STR_GET_HELP_BCFG
));
1880 return (EFI_SUCCESS
);
1884 Destructor for the library. free any resources.
1886 @param ImageHandle The image handle of the process.
1887 @param SystemTable The EFI System Table pointer.
1891 BcfgLibraryUnregisterBcfgCommand (
1892 IN EFI_HANDLE ImageHandle
,
1893 IN EFI_SYSTEM_TABLE
*SystemTable
1896 if (gShellBcfgHiiHandle
!= NULL
) {
1897 HiiRemovePackages(gShellBcfgHiiHandle
);
1899 gShellBcfgHiiHandle
= NULL
;
1900 return (EFI_SUCCESS
);