2 Main file for bcfg shell install1 function.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellInstall1CommandsLib.h"
16 #include <Guid/GlobalVariable.h>
17 #include <Library/PrintLib.h>
18 #include <Library/HandleParsingLib.h>
19 #include <Library/DevicePathLib.h>
22 BCFG_TARGET_BOOT_ORDER
= 0,
23 BCFG_TARGET_DRIVER_ORDER
= 1,
25 } BCFG_OPERATION_TARGET
;
36 } BCFG_OPERATION_TYPE
;
39 BCFG_OPERATION_TARGET Target
;
40 BCFG_OPERATION_TYPE Type
;
47 CONST CHAR16
*OptData
;
51 Function to update the optional data associated with an option.
53 @param[in] Target The type being modified. BOOT or DRIVER
54 @param[in] OptData The pointer to the data to modify with.
56 @retval SHELL_SUCCESS The optional data was updated sucessfully.
61 IN CONST BCFG_OPERATION_TARGET Target
,
62 IN CONST CHAR16
*OptData
65 ShellPrintEx(-1, -1, L
"use of -opt is not currently supported.");
66 return (SHELL_UNSUPPORTED
);
70 Function to add an option.
72 @param[in] Position The position to add this in at.
73 @param[in] File The file to add as the option.
74 @param[in] Desc The description.
75 @param[in] CurrentOrder The current order of that type.
76 @param[in] OrderCount The number of items in the current order.
77 @param[in] Target The type being modified. BOOT or DRIVER
78 @param[in] UseHandle Add something by a handle. Uses HandleNumber if TRUE and File if FALSE.
79 @param[in] UsePath Add something by local path. Only used of UseHandle is FALSE.
80 @param[in] HandleNumber The HandleIndex to use.
82 @retval SHELL_SUCCESS The option was added sucessfully.
88 IN CONST CHAR16
*File
,
89 IN CONST CHAR16
*Desc
,
90 IN CONST UINT16
*CurrentOrder
,
91 IN CONST UINTN OrderCount
,
92 IN CONST BCFG_OPERATION_TARGET Target
,
93 IN CONST BOOLEAN UseHandle
,
94 IN CONST BOOLEAN UseFullPath
,
95 IN CONST UINTN HandleNumber
99 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, *FilePath
, *FileNode
;
104 EFI_SHELL_FILE_INFO
*Arg
;
105 EFI_SHELL_FILE_INFO
*FileList
;
106 CHAR16 OptionStr
[40];
107 UINTN DescSize
, FilePathSize
;
109 UINTN TargetLocation
;
112 EFI_HANDLE CurHandle
;
113 SHELL_STATUS ShellStatus
;
115 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
118 ASSERT(File
!= NULL
);
119 ASSERT(Desc
!= NULL
);
121 ASSERT(HandleNumber
!= 0);
129 ShellStatus
= SHELL_SUCCESS
;
130 TargetLocation
= 0xFFFF;
133 CurHandle
= ConvertHandleIndexToHandle(HandleNumber
);
134 if (CurHandle
== NULL
) {
135 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"<HandleNumber>");
136 ShellStatus
= SHELL_INVALID_PARAMETER
;
139 Status
= gBS
->HandleProtocol (CurHandle
, &gEfiLoadedImageDevicePathProtocolGuid
, (VOID
**)&FilePath
);
140 if (EFI_ERROR (Status
)) {
141 Status
= EFI_SUCCESS
;
143 // Try to construct the DevicePath
145 Status
= gBS
->OpenProtocol(CurHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&Image
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
146 if (EFI_ERROR(Status
)) {
147 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellInstall1HiiHandle
, HandleNumber
);
148 ShellStatus
= SHELL_INVALID_PARAMETER
;
150 Status
= gBS
->HandleProtocol (Image
->DeviceHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePath
);
151 if (EFI_ERROR(Status
)) {
152 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_HANDLE
), gShellInstall1HiiHandle
, HandleNumber
);
153 ShellStatus
= SHELL_INVALID_PARAMETER
;
155 FilePath
= AppendDevicePath(DevicePath
, Image
->FilePath
);
164 Status
= ShellOpenFileMetaArg ((CHAR16
*)File
, EFI_FILE_MODE_READ
, &FileList
);
165 if (EFI_ERROR(Status
)) {
166 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellInstall1HiiHandle
, File
);
167 ShellStatus
= SHELL_NOT_FOUND
;
168 } else if (FileList
== NULL
|| FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
170 // If filename expanded to multiple names, fail
172 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE
), gShellInstall1HiiHandle
, File
);
173 ShellStatus
= SHELL_INVALID_PARAMETER
;
175 Arg
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
);
176 if (EFI_ERROR(Arg
->Status
)) {
177 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_OPEN
), gShellInstall1HiiHandle
, File
, Arg
->Status
);
178 ShellStatus
= SHELL_INVALID_PARAMETER
;
181 // Build FilePath to the filename
185 // get the device path
187 DevicePath
= mEfiShellProtocol
->GetDevicePathFromFilePath(Arg
->FullName
);
188 if (DevicePath
== NULL
) {
189 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_FILE_DP
), gShellInstall1HiiHandle
, Arg
->FullName
);
190 ShellStatus
= SHELL_UNSUPPORTED
;
193 FilePath
= DuplicateDevicePath(DevicePath
);
195 for(p
=Arg
->FullName
; *p
!= CHAR_NULL
&& *p
!= ':'; p
++);
196 FilePath
= FileDevicePath(NULL
, p
+1);
199 FreePool(DevicePath
);
206 if (ShellStatus
== SHELL_SUCCESS
) {
208 // Find a free target ,a brute force implementation
211 for (TargetLocation
=0; TargetLocation
< 0xFFFF; TargetLocation
++) {
213 for (Index
=0; Index
< OrderCount
; Index
++) {
214 if (CurrentOrder
[Index
] == TargetLocation
) {
225 if (TargetLocation
== 0xFFFF) {
226 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET_NF
), gShellInstall1HiiHandle
);
228 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_TARGET
), gShellInstall1HiiHandle
, TargetLocation
);
232 if (ShellStatus
== SHELL_SUCCESS
) {
236 DescSize
= StrSize(Desc
);
237 FilePathSize
= GetDevicePathSize (FilePath
);
239 p8
= AllocateZeroPool(sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
);
242 *((UINT32
*) p8
) = LOAD_OPTION_ACTIVE
; // Attributes
243 p8
+= sizeof (UINT32
);
245 *((UINT16
*) p8
) = (UINT16
)FilePathSize
; // FilePathListLength
246 p8
+= sizeof (UINT16
);
248 CopyMem (p8
, Desc
, DescSize
);
250 CopyMem (p8
, FilePath
, FilePathSize
);
252 UnicodeSPrint (OptionStr
, sizeof(OptionStr
), L
"%s%04x", Target
== BCFG_TARGET_BOOT_ORDER
?L
"Boot":L
"Driver", TargetLocation
);
253 Status
= gRT
->SetVariable (
255 &gEfiGlobalVariableGuid
,
256 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
257 sizeof(UINT32
) + sizeof(UINT16
) + DescSize
+ FilePathSize
,
263 if (EFI_ERROR(Status
)) {
264 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL
), gShellInstall1HiiHandle
, OptionStr
, Status
);
266 NewOrder
= AllocateZeroPool((OrderCount
+1)*sizeof(UINT16
));
267 ASSERT(NewOrder
!= NULL
);
268 CopyMem(NewOrder
, CurrentOrder
, (OrderCount
)*sizeof(UINT16
));
271 // Insert target into order list
273 for (Index
=OrderCount
; Index
> Position
; Index
--) {
274 NewOrder
[Index
] = NewOrder
[Index
-1];
277 NewOrder
[Index
] = (UINT16
)TargetLocation
;
278 Status
= gRT
->SetVariable (
279 Target
== BCFG_TARGET_BOOT_ORDER
?L
"BootOrder":L
"DriverOrder",
280 &gEfiGlobalVariableGuid
,
281 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
282 (OrderCount
+1) * sizeof(UINT16
),
288 if (EFI_ERROR(Status
)) {
289 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BCFG_TARGET_BOOT_ORDER
?L
"BootOrder":L
"DriverOrder", Status
);
290 ShellStatus
= SHELL_INVALID_PARAMETER
;
292 ShellPrintEx (-1, -1, L
"bcfg: Add %s as %x\n", OptionStr
, Index
);
296 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellInstall1HiiHandle
);
297 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
302 //If always Free FilePath, will free devicepath in system when use "addh"
305 if (FilePath
!=NULL
&& !UseHandle
) {
313 if (Handles
!= NULL
) {
317 if (FileList
!= NULL
) {
318 ShellCloseFileMetaArg (&FileList
);
321 return (ShellStatus
);
327 IN CONST BCFG_OPERATION_TARGET Target
,
328 IN CONST UINT16
*CurrentOrder
,
329 IN CONST UINTN OrderCount
,
330 IN CONST UINT16 Location
333 CHAR16 VariableName
[12];
337 NewOrder
= AllocatePool(OrderCount
*sizeof(CurrentOrder
[0]));
338 if (NewOrder
== NULL
) {
339 return (SHELL_OUT_OF_RESOURCES
);
342 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
343 CopyMem(NewOrder
+Location
, NewOrder
+Location
+1, (OrderCount
- Location
- 1)*sizeof(CurrentOrder
[0]));
345 Status
= gRT
->SetVariable(
346 Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
347 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
348 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
349 (OrderCount
-1)*sizeof(CurrentOrder
[0]), // drop 1 off since the list is 1 shorter
354 if (EFI_ERROR(Status
)) {
355 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
356 return (SHELL_INVALID_PARAMETER
);
359 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Target
== BCFG_TARGET_BOOT_ORDER
?L
"Boot":L
"Driver", CurrentOrder
[Location
]);
360 Status
= gRT
->SetVariable(
362 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
363 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
366 if (EFI_ERROR(Status
)) {
367 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
368 return (SHELL_INVALID_PARAMETER
);
371 return (SHELL_SUCCESS
);
377 IN CONST BCFG_OPERATION_TARGET Target
,
378 IN CONST UINT16
*CurrentOrder
,
379 IN CONST UINTN OrderCount
,
380 IN CONST UINT16 OldLocation
,
381 IN CONST UINT16 NewLocation
388 NewOrder
= AllocatePool(OrderCount
*sizeof(CurrentOrder
[0]));
389 ASSERT(NewOrder
!= NULL
);
391 Temp
= CurrentOrder
[OldLocation
];
392 CopyMem(NewOrder
, CurrentOrder
, OrderCount
*sizeof(CurrentOrder
[0]));
393 CopyMem(NewOrder
+OldLocation
, NewOrder
+OldLocation
+1, (OrderCount
- OldLocation
- 1)*sizeof(CurrentOrder
[0]));
394 if (NewLocation
== OrderCount
) {
395 NewOrder
[OrderCount
-1] = Temp
;
397 CopyMem(NewOrder
+NewLocation
+1, NewOrder
+NewLocation
, (OrderCount
- NewLocation
- 1)*sizeof(CurrentOrder
[0]));
398 NewOrder
[NewLocation
] = Temp
;
402 Status
= gRT
->SetVariable(
403 Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
404 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
405 EFI_VARIABLE_NON_VOLATILE
|EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
,
406 OrderCount
*sizeof(CurrentOrder
[0]),
411 if (EFI_ERROR(Status
)) {
412 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_WRITE_FAIL
), gShellInstall1HiiHandle
, Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder", Status
);
413 return (SHELL_INVALID_PARAMETER
);
415 return (SHELL_SUCCESS
);
420 BcfgDisplayDumpInstall(
422 IN CONST UINT16
*CurrentOrder
,
423 IN CONST UINTN OrderCount
,
424 IN CONST BOOLEAN VerboseOutput
430 CHAR16 VariableName
[12];
433 CHAR16
*DevPathString
;
436 for (LoopVar
= 0 ; LoopVar
< OrderCount
; LoopVar
++) {
439 UnicodeSPrint(VariableName
, sizeof(VariableName
), L
"%s%04x", Op
, CurrentOrder
[LoopVar
]);
441 Status
= gRT
->GetVariable(
443 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
447 if (Status
== EFI_BUFFER_TOO_SMALL
) {
448 Buffer
= AllocatePool(BufferSize
);
449 Status
= gRT
->GetVariable(
451 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
457 if (EFI_ERROR(Status
) || Buffer
== NULL
) {
458 SHELL_FREE_NON_NULL(Buffer
);
459 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_READ_FAIL
), gShellInstall1HiiHandle
, VariableName
, Status
);
460 return (SHELL_INVALID_PARAMETER
);
463 DevPath
= AllocatePool(*(UINT16
*)(Buffer
+4));
464 CopyMem(DevPath
, Buffer
+6+StrSize((CHAR16
*)(Buffer
+6)), *(UINT16
*)(Buffer
+4));
465 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
470 STRING_TOKEN(STR_BCFG_LOAD_OPTIONS
),
471 gShellInstall1HiiHandle
,
476 (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6) <= BufferSize
?L
'N':L
'Y');
478 for (LoopVar2
= (StrSize((CHAR16
*)(Buffer
+6)) + *(UINT16
*)(Buffer
+4) + 6);LoopVar2
<BufferSize
;LoopVar2
++){
479 ShellPrintEx(-1, -1, L
"%02x", Buffer
[LoopVar2
]);
481 ShellPrintEx(-1, -1, L
"\r\n");
484 if (Buffer
!= NULL
) {
487 if (DevPath
!= NULL
) {
490 if (DevPathString
!= NULL
) {
491 FreePool(DevPathString
);
494 return (SHELL_SUCCESS
);
499 InitBcfgStructInstall(
500 IN BGFG_OPERATION
*Struct
503 ASSERT(Struct
!= NULL
);
504 Struct
->Target
= BCFG_TARGET_MAX
;
505 Struct
->Type
= BCFG_TYPE_MAX
;
508 Struct
->HandleIndex
= 0;
509 Struct
->FileName
= NULL
;
510 Struct
->Description
= NULL
;
511 Struct
->Order
= NULL
;
512 Struct
->OptData
= NULL
;
516 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
518 {L
"-opt", TypeMaxValue
},
523 Function for 'bcfg' command.
525 @param[in] ImageHandle Handle to the Image (NULL if Internal).
526 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
530 ShellCommandRunBcfgInstall (
531 IN EFI_HANDLE ImageHandle
,
532 IN EFI_SYSTEM_TABLE
*SystemTable
537 CHAR16
*ProblemParam
;
538 SHELL_STATUS ShellStatus
;
540 CONST CHAR16
*CurrentParam
;
541 BGFG_OPERATION CurrentOperation
;
547 ShellStatus
= SHELL_SUCCESS
;
549 InitBcfgStructInstall(&CurrentOperation
);
552 // initialize the shell lib (we must be in non-auto-init...)
554 Status
= ShellInitialize();
555 ASSERT_EFI_ERROR(Status
);
557 Status
= CommandInit();
558 ASSERT_EFI_ERROR(Status
);
561 // parse the command line
563 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
564 if (EFI_ERROR(Status
)) {
565 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
566 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, ProblemParam
);
567 FreePool(ProblemParam
);
568 ShellStatus
= SHELL_INVALID_PARAMETER
;
574 // small block to read the target of the operation
576 if (ShellCommandLineGetFlag(Package
, L
"-opt") && ShellCommandLineGetCount(Package
) < 2) {
577 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
578 ShellStatus
= SHELL_INVALID_PARAMETER
;
579 } else if (!ShellCommandLineGetFlag(Package
, L
"-opt") && ShellCommandLineGetCount(Package
) < 3) {
580 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
581 ShellStatus
= SHELL_INVALID_PARAMETER
;
582 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"driver") == 0) {
583 CurrentOperation
.Target
= BCFG_TARGET_DRIVER_ORDER
;
584 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), L
"boot") == 0) {
585 CurrentOperation
.Target
= BCFG_TARGET_BOOT_ORDER
;
587 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT
), gShellInstall1HiiHandle
);
588 ShellStatus
= SHELL_INVALID_PARAMETER
;
592 // Read in if we are doing -OPT
594 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BCFG_TARGET_MAX
&& ShellCommandLineGetFlag(Package
, L
"-opt")) {
595 CurrentOperation
.OptData
= ShellCommandLineGetValue(Package
, L
"-opt");
596 CurrentOperation
.Type
= BCFG_TYPE_OPT
;
600 // Read in the boot or driver order environment variable (not needed for opt)
602 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BCFG_TARGET_MAX
&& CurrentOperation
.Type
!= BCFG_TYPE_OPT
) {
604 Status
= gRT
->GetVariable(
605 CurrentOperation
.Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
606 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
609 CurrentOperation
.Order
);
610 if (Status
== EFI_BUFFER_TOO_SMALL
) {
611 CurrentOperation
.Order
= AllocatePool(Length
+(4*sizeof(CurrentOperation
.Order
[0])));
612 Status
= gRT
->GetVariable(
613 CurrentOperation
.Target
== BCFG_TARGET_BOOT_ORDER
?(CHAR16
*)L
"BootOrder":(CHAR16
*)L
"DriverOrder",
614 (EFI_GUID
*)&gEfiGlobalVariableGuid
,
617 CurrentOperation
.Order
);
622 // large block to read the type of operation and verify parameter types for the info.
624 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BCFG_TARGET_MAX
) {
625 for (ParamNumber
= 2 ; ParamNumber
< ShellCommandLineGetCount(Package
) && ShellStatus
== SHELL_SUCCESS
; ParamNumber
++) {
626 CurrentParam
= ShellCommandLineGetRawValue(Package
, ParamNumber
);
627 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"dump") == 0) {
628 if (ShellCommandLineGetCount(Package
) > 3) {
629 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellInstall1HiiHandle
);
630 ShellStatus
= SHELL_INVALID_PARAMETER
;
632 CurrentOperation
.Type
= BCFG_TYPE_DUMP
;
633 } else if (ShellCommandLineGetFlag(Package
, L
"-v")) {
634 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, L
"-v (without dump)");
635 ShellStatus
= SHELL_INVALID_PARAMETER
;
636 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"add") == 0) {
637 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
638 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
639 ShellStatus
= SHELL_INVALID_PARAMETER
;
641 CurrentOperation
.Type
= BCFG_TYPE_ADD
;
642 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
643 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
644 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
645 ShellStatus
= SHELL_INVALID_PARAMETER
;
647 CurrentOperation
.Number1
= (UINT16
)StrHexToUintn(CurrentParam
);
648 ASSERT(CurrentOperation
.FileName
== NULL
);
649 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
650 ASSERT(CurrentOperation
.Description
== NULL
);
651 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
653 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addp") == 0) {
654 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
655 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
656 ShellStatus
= SHELL_INVALID_PARAMETER
;
658 CurrentOperation
.Type
= BCFG_TYPE_ADDP
;
659 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
660 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
661 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
662 ShellStatus
= SHELL_INVALID_PARAMETER
;
664 CurrentOperation
.Number1
= (UINT16
)StrHexToUintn(CurrentParam
);
665 ASSERT(CurrentOperation
.FileName
== NULL
);
666 CurrentOperation
.FileName
= StrnCatGrow(&CurrentOperation
.FileName
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
667 ASSERT(CurrentOperation
.Description
== NULL
);
668 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
671 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"addh") == 0) {
672 if ((ParamNumber
+ 3) >= ShellCommandLineGetCount(Package
)) {
673 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
674 ShellStatus
= SHELL_INVALID_PARAMETER
;
676 CurrentOperation
.Type
= BCFG_TYPE_ADDH
;
677 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
678 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
679 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
680 ShellStatus
= SHELL_INVALID_PARAMETER
;
682 CurrentOperation
.Number1
= (UINT16
)StrHexToUintn(CurrentParam
);
683 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
684 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
685 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
686 ShellStatus
= SHELL_INVALID_PARAMETER
;
688 CurrentOperation
.HandleIndex
= (UINT16
)StrHexToUintn(CurrentParam
);
689 ASSERT(CurrentOperation
.Description
== NULL
);
690 CurrentOperation
.Description
= StrnCatGrow(&CurrentOperation
.Description
, NULL
, ShellCommandLineGetRawValue(Package
, ++ParamNumber
), 0);
693 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"rm") == 0) {
694 if ((ParamNumber
+ 1) >= ShellCommandLineGetCount(Package
)) {
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
696 ShellStatus
= SHELL_INVALID_PARAMETER
;
698 CurrentOperation
.Type
= BCFG_TYPE_RM
;
699 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
700 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
701 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
702 ShellStatus
= SHELL_INVALID_PARAMETER
;
704 CurrentOperation
.Number1
= (UINT16
)StrHexToUintn(CurrentParam
);
705 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
706 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_LOCATION_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
707 ShellStatus
= SHELL_INVALID_PARAMETER
;
710 } else if (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)CurrentParam
, L
"mv") == 0) {
711 if ((ParamNumber
+ 2) >= ShellCommandLineGetCount(Package
)) {
712 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellInstall1HiiHandle
);
713 ShellStatus
= SHELL_INVALID_PARAMETER
;
715 CurrentOperation
.Type
= BCFG_TYPE_MV
;
716 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
717 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
718 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
719 ShellStatus
= SHELL_INVALID_PARAMETER
;
721 CurrentOperation
.Number1
= (UINT16
)StrHexToUintn(CurrentParam
);
722 if (CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))){
723 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_LOCATION_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
724 ShellStatus
= SHELL_INVALID_PARAMETER
;
726 CurrentParam
= ShellCommandLineGetRawValue(Package
, ++ParamNumber
);
727 if (CurrentParam
== NULL
|| !ShellIsHexOrDecimalNumber(CurrentParam
, TRUE
, FALSE
)) {
728 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
729 ShellStatus
= SHELL_INVALID_PARAMETER
;
731 CurrentOperation
.Number2
= (UINT16
)StrHexToUintn(CurrentParam
);
733 if (CurrentOperation
.Number2
== CurrentOperation
.Number1
734 ||CurrentOperation
.Number1
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
735 ||CurrentOperation
.Number2
> (Length
/ sizeof(CurrentOperation
.Order
[0]))
737 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_BCFG_LOCATION_RANGE
), gShellInstall1HiiHandle
, Length
/ sizeof(CurrentOperation
.Order
[0]));
738 ShellStatus
= SHELL_INVALID_PARAMETER
;
742 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellInstall1HiiHandle
, CurrentParam
);
743 ShellStatus
= SHELL_INVALID_PARAMETER
;
747 if (ShellStatus
== SHELL_SUCCESS
&& CurrentOperation
.Target
< BCFG_TARGET_MAX
&& CurrentOperation
.Type
< BCFG_TYPE_MAX
) {
749 // we have all the info. Do the work
751 switch (CurrentOperation
.Type
) {
753 ShellStatus
= BcfgDisplayDumpInstall(
754 CurrentOperation
.Target
== BCFG_TARGET_BOOT_ORDER
?L
"Boot":L
"Driver",
755 CurrentOperation
.Order
,
756 Length
/ sizeof(CurrentOperation
.Order
[0]),
757 ShellCommandLineGetFlag(Package
, L
"-v"));
760 ShellStatus
= BcfgMoveInstall(
761 CurrentOperation
.Target
,
762 CurrentOperation
.Order
,
763 Length
/ sizeof(CurrentOperation
.Order
[0]),
764 CurrentOperation
.Number1
,
765 CurrentOperation
.Number2
);
768 ShellStatus
= BcfgRemoveInstall(
769 CurrentOperation
.Target
,
770 CurrentOperation
.Order
,
771 (Length
/ sizeof(CurrentOperation
.Order
[0])),
772 CurrentOperation
.Number1
);
777 ShellStatus
= BcfgAddInstall(
778 CurrentOperation
.Number1
,
779 CurrentOperation
.FileName
,
780 CurrentOperation
.Description
,
781 CurrentOperation
.Order
,
782 Length
/ sizeof(CurrentOperation
.Order
[0]),
783 CurrentOperation
.Target
,
784 (BOOLEAN
)(CurrentOperation
.Type
== BCFG_TYPE_ADDH
),
785 (BOOLEAN
)(CurrentOperation
.Type
== BCFG_TYPE_ADD
),
786 CurrentOperation
.HandleIndex
);
789 ShellStatus
= BcfgAddOptInstall(
790 CurrentOperation
.Target
,
791 CurrentOperation
.OptData
);
799 if (Package
!= NULL
) {
800 ShellCommandLineFreeVarList (Package
);
802 if (CurrentOperation
.FileName
!= NULL
) {
803 FreePool(CurrentOperation
.FileName
);
805 if (CurrentOperation
.Description
!= NULL
) {
806 FreePool(CurrentOperation
.Description
);
808 if (CurrentOperation
.Order
!= NULL
) {
809 FreePool(CurrentOperation
.Order
);
812 return (ShellStatus
);