[edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification functionality

Ruiyu Ni posted 1 patch 7 years, 1 month ago
Failed in applying to current master (apply log)
.../UefiShellBcfgCommandLib.c                      | 352 ++++++++++++++++++++-
.../UefiShellBcfgCommandLib.inf                    |   3 +-
ShellPkg/ShellPkg.dsc                              |   8 +
3 files changed, 360 insertions(+), 3 deletions(-)
[edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification functionality
Posted by Ruiyu Ni 7 years, 1 month ago
From: chen881220 <ai_terran@foxmail.com>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
 .../UefiShellBcfgCommandLib.c                      | 352 ++++++++++++++++++++-
 .../UefiShellBcfgCommandLib.inf                    |   3 +-
 ShellPkg/ShellPkg.dsc                              |   8 +
 3 files changed, 360 insertions(+), 3 deletions(-)

diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
index 62a52ad..1538bc6 100644
--- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
+++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
@@ -2,7 +2,7 @@
   Main file for BCFG command.
 
   (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -41,6 +41,7 @@
 #include <Library/PrintLib.h>
 #include <Library/HandleParsingLib.h>
 #include <Library/DevicePathLib.h>
+#include <Library/UefiBootManagerLib.h>
 
 STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
 STATIC EFI_HANDLE gShellBcfgHiiHandle  = NULL;
@@ -59,7 +60,11 @@ typedef enum {
   BcfgTypeRm         = 4,
   BcfgTypeMv         = 5,
   BcfgTypeOpt        = 6,
-  BcfgTypeMax        = 7
+  BcfgTypeMod        = 7,
+  BcfgTypeModf       = 8,
+  BcfgTypeModp       = 9,
+  BcfgTypeModh       = 10,
+  BcfgTypeMax        = 11
 } BCFG_OPERATION_TYPE;
 
 typedef struct {
@@ -275,6 +280,247 @@ GetDevicePathForDriverHandle (
 }
 
 /**
+  Functino to get Device Path by a handle.
+
+  @param[in]        TheHandle   Use it to get DevicePath.
+  @param[in]        Target      Boot option target.
+  @param[in, out]   DevicePath  On a sucessful return the device path to the handle.
+
+  @retval   SHELL_INVALID_PARAMETER The handle was NULL.
+  @retval   SHELL_NOT_FOUND         Not found device path by handle.
+  @retval   SHELL_SUCCESS           Get device path successfully.
+**/
+SHELL_STATUS
+GetDevicePathByHandle(
+  IN     EFI_HANDLE               TheHandle,
+  IN     BCFG_OPERATION_TARGET    Target,
+  IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+  )
+{
+  EFI_STATUS   Status;
+  SHELL_STATUS ShellStatus;
+
+  UINTN DriverBindingHandleCount;
+  UINTN ParentControllerHandleCount;
+  UINTN ChildControllerHandleCount;
+
+  ShellStatus = SHELL_SUCCESS;
+
+  if (TheHandle == NULL) {
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number");
+    return SHELL_INVALID_PARAMETER;
+  }
+
+  Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle, &DriverBindingHandleCount, NULL);
+  if (EFI_ERROR(Status)) {
+    DriverBindingHandleCount = 0;
+  }
+
+  Status = PARSE_HANDLE_DATABASE_PARENTS (TheHandle, &ParentControllerHandleCount, NULL);
+  if (EFI_ERROR (Status)) {
+    ParentControllerHandleCount = 0;
+  }
+
+  Status = ParseHandleDatabaseForChildControllers (TheHandle, &ChildControllerHandleCount, NULL);
+  if (EFI_ERROR (Status)) {
+    ChildControllerHandleCount = 0;
+  }
+
+  Status = gBS->HandleProtocol (TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)DevicePath);
+
+  if ( DriverBindingHandleCount    > 0 ||
+       ParentControllerHandleCount > 0 ||
+       ChildControllerHandleCount  > 0 ||
+       !EFI_ERROR(Status)
+     ) {
+    //
+    // The handle points to a real controller which has a device path.
+    //
+    if (Target == BcfgTargetDriverOrder) {
+      ShellPrintHiiEx (
+        -1,
+        -1,
+        NULL,STRING_TOKEN (STR_GEN_PARAM_INV),
+        gShellBcfgHiiHandle,
+        L"bcfg",
+        L"Handle should point to driver image."
+      );
+      ShellStatus = SHELL_NOT_FOUND;
+    }
+  } else {
+    //
+    // The handle points to a driver image.
+    //
+    if (Target == BcfgTargetBootOrder) {
+      ShellPrintHiiEx (
+        -1,
+        -1,
+        NULL,
+        STRING_TOKEN (STR_GEN_PARAM_INV),
+        gShellBcfgHiiHandle,
+        L"bcfg",
+        L"Handle should point to controller."
+      );
+      ShellStatus = SHELL_NOT_FOUND;
+    } else {
+      if (EFI_ERROR (GetDevicePathForDriverHandle (TheHandle, DevicePath))) {
+        ShellStatus = SHELL_NOT_FOUND;
+      }
+    }
+  }
+
+  return (ShellStatus);
+}
+
+/**
+  Function to modify an option.
+
+  @param[in] BcfgOperation  Pointer to BCFG operation.
+  @param[in] OrderCount     The number if items in CurrentOrder.
+
+  @retval SHELL_SUCCESS             The operation was successful.
+  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.
+  @retval SHELL_OUT_OF_RESOUCES     A memory allocation failed.
+**/
+SHELL_STATUS
+BcfgMod (
+  IN CONST BGFG_OPERATION   *BcfgOperation,
+  IN CONST UINTN            OrderCount
+  )
+{
+  EFI_STATUS                    Status;
+  EFI_HANDLE                    CurHandle;
+  SHELL_STATUS                  ShellStatus;
+  CHAR16                        OptionStr[40];
+  EFI_SHELL_FILE_INFO           *FileList;
+  EFI_SHELL_FILE_INFO           *Arg;
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePathBuffer;
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePathWalker;
+  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;
+
+  ShellStatus       = SHELL_SUCCESS;
+  FileList          = NULL;
+  DevicePath        = NULL;
+
+  ZeroMem (&LoadOption, sizeof(EFI_BOOT_MANAGER_LOAD_OPTION));
+
+  if ( (BcfgOperation->Type == BcfgTypeMod  && BcfgOperation->Description == NULL)  ||
+       (BcfgOperation->Type == BcfgTypeModf && BcfgOperation->FileName == NULL)     ||
+       (BcfgOperation->Type == BcfgTypeModp && BcfgOperation->FileName == NULL)     ||
+       (BcfgOperation->Type == BcfgTypeModh && BcfgOperation->HandleIndex == 0)     ||
+       (BcfgOperation->Number1 > OrderCount)
+     ) {
+    return (SHELL_INVALID_PARAMETER);
+  }
+
+  if (BcfgOperation->Type == BcfgTypeModh) {
+    CurHandle = ConvertHandleIndexToHandle (BcfgOperation->HandleIndex);
+    ShellStatus = GetDevicePathByHandle (CurHandle, BcfgOperation->Target, &DevicePathBuffer);
+    if (ShellStatus == SHELL_SUCCESS) {
+      DevicePath = DuplicateDevicePath (DevicePathBuffer);
+    }
+  } else if (BcfgOperation->Type == BcfgTypeModf || BcfgOperation->Type == BcfgTypeModp) {
+    //
+    // Get Device Path by FileName.
+    //
+    ShellOpenFileMetaArg ((CHAR16 *)BcfgOperation->FileName, EFI_FILE_MODE_READ, &FileList);
+    if (FileList == NULL) {
+      //
+      // The name of file matched nothing.
+      //
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
+      ShellStatus = SHELL_INVALID_PARAMETER;
+    }
+    else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {
+      //
+      // If the name of file expanded to multiple names, it's fail.
+      //
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
+      ShellStatus = SHELL_INVALID_PARAMETER;
+    } else {
+      Arg = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link);
+      if (EFI_ERROR (Arg->Status)) {
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
+        ShellStatus = SHELL_INVALID_PARAMETER;
+      } else {
+        DevicePathBuffer = gEfiShellProtocol->GetDevicePathFromFilePath (Arg->FullName);
+        if (DevicePathBuffer == NULL) {
+          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellBcfgHiiHandle, L"bcfg", Arg->FullName);
+          ShellStatus = SHELL_UNSUPPORTED;
+        }
+      }
+    }
+
+    if (ShellStatus == SHELL_SUCCESS) {
+      if (BcfgOperation->Type == BcfgTypeModp) {
+        ShellStatus = SHELL_INVALID_PARAMETER;
+        DevicePathWalker = DevicePathBuffer;
+        while (!IsDevicePathEnd (DevicePathWalker)) {
+          if ( DevicePathType (DevicePathWalker) == MEDIA_DEVICE_PATH &&
+               DevicePathSubType (DevicePathWalker) == MEDIA_HARDDRIVE_DP
+             ) {
+            //
+            // We found the portion of device path starting with the hard driver partition.
+            //
+            ShellStatus = SHELL_SUCCESS;
+            DevicePath = DuplicateDevicePath (DevicePathWalker);
+            break;
+          } else {
+            DevicePathWalker = NextDevicePathNode (DevicePathWalker);
+          }
+        }
+      } else {
+        DevicePath = DuplicateDevicePath (DevicePathBuffer);
+      }
+
+      FreePool (DevicePathBuffer);
+    }
+  }
+
+  if (ShellStatus == SHELL_SUCCESS) {
+    if (BcfgOperation->Target == BcfgTargetBootOrder) {
+      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Boot%04x", BcfgOperation->Order[BcfgOperation->Number1]);
+    } else {
+      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Driver%04x", BcfgOperation->Order[BcfgOperation->Number1]);
+    }
+    Status = EfiBootManagerVariableToLoadOption (OptionStr, &LoadOption);
+    if (EFI_ERROR(Status)) {
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NONE), gShellBcfgHiiHandle);
+      ShellStatus = SHELL_NOT_FOUND;
+    }
+  }
+
+  if (ShellStatus == SHELL_SUCCESS) {
+    if (BcfgOperation->Type == BcfgTypeMod) {
+      SHELL_FREE_NON_NULL (LoadOption.Description);
+      LoadOption.Description = AllocateCopyPool (StrSize (BcfgOperation->Description), BcfgOperation->Description);
+    } else {
+      SHELL_FREE_NON_NULL (LoadOption.FilePath);
+      LoadOption.FilePath = DuplicateDevicePath (DevicePath);
+    }
+
+    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
+    if (EFI_ERROR(Status)) {
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
+      ShellStatus = SHELL_INVALID_PARAMETER;
+    }
+  }
+
+  EfiBootManagerFreeLoadOption (&LoadOption);
+
+  if (DevicePath != NULL) {
+    FreePool (DevicePath);
+  }
+
+  if (FileList != NULL) {
+    ShellCloseFileMetaArg (&FileList);
+  }
+
+  return (ShellStatus);
+}
+
+/**
   Function to add a option.
 
   @param[in] Position       The position to add Target at.
@@ -1404,6 +1650,102 @@ ShellCommandRunBcfg (
               }
             }
           }
+        }
+        else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"mod") == 0) {
+          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
+            ShellStatus = SHELL_INVALID_PARAMETER;
+          } else {
+            CurrentOperation.Type = BcfgTypeMod;
+            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
+            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
+              ShellStatus = SHELL_INVALID_PARAMETER;
+            } else {
+              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
+              CurrentOperation.Number1 = (UINT16)Intermediate;
+              if (CurrentOperation.Number1 >= Count) {
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
+                ShellStatus = SHELL_INVALID_PARAMETER;
+              } else {
+                ASSERT (CurrentOperation.Description == NULL);
+                CurrentOperation.Description = StrnCatGrow (&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
+              }
+            }
+          }
+        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modf") == 0) {
+          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
+            ShellStatus = SHELL_INVALID_PARAMETER;
+          } else {
+            CurrentOperation.Type = BcfgTypeModf;
+            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
+            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
+              ShellStatus = SHELL_INVALID_PARAMETER;
+            } else {
+              Status = ShellConvertStringToUint64  (CurrentParam, &Intermediate, TRUE, FALSE);
+              CurrentOperation.Number1 = (UINT16)Intermediate;
+              if (CurrentOperation.Number1 >= Count) {
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
+                ShellStatus = SHELL_INVALID_PARAMETER;
+              } else {
+                ASSERT (CurrentOperation.FileName == NULL);
+                CurrentOperation.FileName = StrnCatGrow (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
+              }
+            }
+          }
+        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modp") == 0) {
+          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
+            ShellStatus = SHELL_INVALID_PARAMETER;
+          } else {
+            CurrentOperation.Type = BcfgTypeModp;
+            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
+            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
+              ShellStatus = SHELL_INVALID_PARAMETER;
+            } else {
+              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
+              CurrentOperation.Number1 = (UINT16)Intermediate;
+              if (CurrentOperation.Number1 >= Count) {
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
+                ShellStatus = SHELL_INVALID_PARAMETER;
+              } else {
+                ASSERT (CurrentOperation.FileName == NULL);
+                CurrentOperation.FileName = StrnCatGrow (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
+              }
+            }
+          }
+        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modh") == 0) {
+          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
+            ShellStatus = SHELL_INVALID_PARAMETER;
+          } else {
+            CurrentOperation.Type = BcfgTypeModh;
+            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
+            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
+              ShellStatus = SHELL_INVALID_PARAMETER;
+            }
+            else {
+              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
+              CurrentOperation.Number1 = (UINT16)Intermediate;
+              if (CurrentOperation.Number1 >= Count) {
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
+                ShellStatus = SHELL_INVALID_PARAMETER;
+              } else {
+                CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
+                if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
+                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
+                  ShellStatus = SHELL_INVALID_PARAMETER;
+                } else {
+                  Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
+                  CurrentOperation.HandleIndex = (UINT16)Intermediate;
+                }
+              }
+            }
+          }
         } else {
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);  
           ShellStatus = SHELL_INVALID_PARAMETER;
@@ -1451,6 +1793,12 @@ ShellCommandRunBcfg (
             (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
             CurrentOperation.HandleIndex);
           break;
+        case   BcfgTypeMod:
+        case   BcfgTypeModf:
+        case   BcfgTypeModp:
+        case   BcfgTypeModh:
+          ShellStatus = BcfgMod (&CurrentOperation, Count);
+          break;
         case   BcfgTypeOpt:
           ShellStatus = BcfgAddOpt(
             CurrentOperation.OptData,
diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
index 44c8b7e..88b96ea 100644
--- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
+++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
@@ -1,7 +1,7 @@
 ##  @file
 #  Provides shell install1 functions
 #
-#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
+#  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -41,6 +41,7 @@ [LibraryClasses]
   UefiBootServicesTableLib
   SortLib
   PrintLib
+  UefiBootManagerLib
 
 [Guids]
   gShellBcfgHiiGuid             ## SOMETIMES_CONSUMES ## HII
diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
index 5c01933..a87428a 100644
--- a/ShellPkg/ShellPkg.dsc
+++ b/ShellPkg/ShellPkg.dsc
@@ -55,6 +55,14 @@ [LibraryClasses.common]
   BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
   IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
 
+  UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+  ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
+
 [LibraryClasses.ARM]
   #
   # It is not possible to prevent the ARM compiler for generic intrinsic functions.
-- 
2.9.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification functionality
Posted by Ni, Ruiyu 7 years, 1 month ago
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ruiyu Ni
> Sent: Monday, February 27, 2017 3:50 PM
> To: edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; Chen, Chen A
> <chen.a.chen@intel.com>; chen881220 <ai_terran@foxmail.com>
> Subject: [edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification
> functionality
> 
> From: chen881220 <ai_terran@foxmail.com>
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> ---
>  .../UefiShellBcfgCommandLib.c                      | 352 ++++++++++++++++++++-
>  .../UefiShellBcfgCommandLib.inf                    |   3 +-
>  ShellPkg/ShellPkg.dsc                              |   8 +
>  3 files changed, 360 insertions(+), 3 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> index 62a52ad..1538bc6 100644
> ---
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> +++
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> @@ -2,7 +2,7 @@
>    Main file for BCFG command.
> 
>    (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
> -  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2010 - 2017, Intel Corporation. All rights
> + reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -41,6 +41,7 @@  #include <Library/PrintLib.h>  #include
> <Library/HandleParsingLib.h>  #include <Library/DevicePathLib.h>
> +#include <Library/UefiBootManagerLib.h>
> 
>  STATIC CONST CHAR16 mFileName[] = L"ShellCommands";  STATIC
> EFI_HANDLE gShellBcfgHiiHandle  = NULL; @@ -59,7 +60,11 @@ typedef
> enum {
>    BcfgTypeRm         = 4,
>    BcfgTypeMv         = 5,
>    BcfgTypeOpt        = 6,
> -  BcfgTypeMax        = 7
> +  BcfgTypeMod        = 7,
> +  BcfgTypeModf       = 8,
> +  BcfgTypeModp       = 9,
> +  BcfgTypeModh       = 10,
> +  BcfgTypeMax        = 11
>  } BCFG_OPERATION_TYPE;
> 
>  typedef struct {
> @@ -275,6 +280,247 @@ GetDevicePathForDriverHandle (  }
> 
>  /**
> +  Functino to get Device Path by a handle.
> +
> +  @param[in]        TheHandle   Use it to get DevicePath.
> +  @param[in]        Target      Boot option target.
> +  @param[in, out]   DevicePath  On a sucessful return the device path to the
> handle.
> +
> +  @retval   SHELL_INVALID_PARAMETER The handle was NULL.
> +  @retval   SHELL_NOT_FOUND         Not found device path by handle.
> +  @retval   SHELL_SUCCESS           Get device path successfully.
> +**/
> +SHELL_STATUS
> +GetDevicePathByHandle(
> +  IN     EFI_HANDLE               TheHandle,
> +  IN     BCFG_OPERATION_TARGET    Target,
> +  IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
> +  )
> +{
> +  EFI_STATUS   Status;
> +  SHELL_STATUS ShellStatus;
> +
> +  UINTN DriverBindingHandleCount;
> +  UINTN ParentControllerHandleCount;
> +  UINTN ChildControllerHandleCount;
> +
> +  ShellStatus = SHELL_SUCCESS;
> +
> +  if (TheHandle == NULL) {
> +    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellBcfgHiiHandle, L"bcfg", L"Handle Number");
> +    return SHELL_INVALID_PARAMETER;
> +  }
> +
> +  Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle,
> + &DriverBindingHandleCount, NULL);  if (EFI_ERROR(Status)) {
> +    DriverBindingHandleCount = 0;
> +  }
> +
> +  Status = PARSE_HANDLE_DATABASE_PARENTS (TheHandle,
> + &ParentControllerHandleCount, NULL);  if (EFI_ERROR (Status)) {
> +    ParentControllerHandleCount = 0;
> +  }
> +
> +  Status = ParseHandleDatabaseForChildControllers (TheHandle,
> + &ChildControllerHandleCount, NULL);  if (EFI_ERROR (Status)) {
> +    ChildControllerHandleCount = 0;
> +  }
> +
> +  Status = gBS->HandleProtocol (TheHandle, &gEfiDevicePathProtocolGuid,
> + (VOID**)DevicePath);
> +
> +  if ( DriverBindingHandleCount    > 0 ||
> +       ParentControllerHandleCount > 0 ||
> +       ChildControllerHandleCount  > 0 ||
> +       !EFI_ERROR(Status)
> +     ) {
> +    //
> +    // The handle points to a real controller which has a device path.
> +    //
> +    if (Target == BcfgTargetDriverOrder) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,STRING_TOKEN (STR_GEN_PARAM_INV),
> +        gShellBcfgHiiHandle,
> +        L"bcfg",
> +        L"Handle should point to driver image."
> +      );
> +      ShellStatus = SHELL_NOT_FOUND;
> +    }
> +  } else {
> +    //
> +    // The handle points to a driver image.
> +    //
> +    if (Target == BcfgTargetBootOrder) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_PARAM_INV),
> +        gShellBcfgHiiHandle,
> +        L"bcfg",
> +        L"Handle should point to controller."
> +      );
> +      ShellStatus = SHELL_NOT_FOUND;
> +    } else {
> +      if (EFI_ERROR (GetDevicePathForDriverHandle (TheHandle, DevicePath)))
> {
> +        ShellStatus = SHELL_NOT_FOUND;
> +      }
> +    }
> +  }
> +
> +  return (ShellStatus);
> +}
> +
> +/**
> +  Function to modify an option.
> +
> +  @param[in] BcfgOperation  Pointer to BCFG operation.
> +  @param[in] OrderCount     The number if items in CurrentOrder.
> +
> +  @retval SHELL_SUCCESS             The operation was successful.
> +  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.
> +  @retval SHELL_OUT_OF_RESOUCES     A memory allocation failed.
> +**/
> +SHELL_STATUS
> +BcfgMod (
> +  IN CONST BGFG_OPERATION   *BcfgOperation,
> +  IN CONST UINTN            OrderCount
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  EFI_HANDLE                    CurHandle;
> +  SHELL_STATUS                  ShellStatus;
> +  CHAR16                        OptionStr[40];
> +  EFI_SHELL_FILE_INFO           *FileList;
> +  EFI_SHELL_FILE_INFO           *Arg;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathBuffer;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathWalker;
> +  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;
> +
> +  ShellStatus       = SHELL_SUCCESS;
> +  FileList          = NULL;
> +  DevicePath        = NULL;
> +
> +  ZeroMem (&LoadOption, sizeof(EFI_BOOT_MANAGER_LOAD_OPTION));
> +
> +  if ( (BcfgOperation->Type == BcfgTypeMod  && BcfgOperation-
> >Description == NULL)  ||
> +       (BcfgOperation->Type == BcfgTypeModf && BcfgOperation->FileName
> == NULL)     ||
> +       (BcfgOperation->Type == BcfgTypeModp && BcfgOperation->FileName
> == NULL)     ||
> +       (BcfgOperation->Type == BcfgTypeModh && BcfgOperation-
> >HandleIndex == 0)     ||
> +       (BcfgOperation->Number1 > OrderCount)
> +     ) {
> +    return (SHELL_INVALID_PARAMETER);
> +  }
> +
> +  if (BcfgOperation->Type == BcfgTypeModh) {
> +    CurHandle = ConvertHandleIndexToHandle (BcfgOperation-
> >HandleIndex);
> +    ShellStatus = GetDevicePathByHandle (CurHandle, BcfgOperation->Target,
> &DevicePathBuffer);
> +    if (ShellStatus == SHELL_SUCCESS) {
> +      DevicePath = DuplicateDevicePath (DevicePathBuffer);
> +    }
> +  } else if (BcfgOperation->Type == BcfgTypeModf || BcfgOperation->Type
> == BcfgTypeModp) {
> +    //
> +    // Get Device Path by FileName.
> +    //
> +    ShellOpenFileMetaArg ((CHAR16 *)BcfgOperation->FileName,
> EFI_FILE_MODE_READ, &FileList);
> +    if (FileList == NULL) {
> +      //
> +      // The name of file matched nothing.
> +      //
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_FILE_OPEN_FAIL), gShellBcfgHiiHandle, L"bcfg", BcfgOperation-
> >FileName);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    }
> +    else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {
> +      //
> +      // If the name of file expanded to multiple names, it's fail.
> +      //
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE),
> gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else {
> +      Arg = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link);
> +      if (EFI_ERROR (Arg->Status)) {
> +        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN),
> gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +      } else {
> +        DevicePathBuffer = gEfiShellProtocol->GetDevicePathFromFilePath
> (Arg->FullName);
> +        if (DevicePathBuffer == NULL) {
> +          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP),
> gShellBcfgHiiHandle, L"bcfg", Arg->FullName);
> +          ShellStatus = SHELL_UNSUPPORTED;
> +        }
> +      }
> +    }
> +
> +    if (ShellStatus == SHELL_SUCCESS) {
> +      if (BcfgOperation->Type == BcfgTypeModp) {
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +        DevicePathWalker = DevicePathBuffer;
> +        while (!IsDevicePathEnd (DevicePathWalker)) {
> +          if ( DevicePathType (DevicePathWalker) == MEDIA_DEVICE_PATH &&
> +               DevicePathSubType (DevicePathWalker) == MEDIA_HARDDRIVE_DP
> +             ) {
> +            //
> +            // We found the portion of device path starting with the hard driver
> partition.
> +            //
> +            ShellStatus = SHELL_SUCCESS;
> +            DevicePath = DuplicateDevicePath (DevicePathWalker);
> +            break;
> +          } else {
> +            DevicePathWalker = NextDevicePathNode (DevicePathWalker);
> +          }
> +        }
> +      } else {
> +        DevicePath = DuplicateDevicePath (DevicePathBuffer);
> +      }
> +
> +      FreePool (DevicePathBuffer);
> +    }
> +  }
> +
> +  if (ShellStatus == SHELL_SUCCESS) {
> +    if (BcfgOperation->Target == BcfgTargetBootOrder) {
> +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Boot%04x",
> BcfgOperation->Order[BcfgOperation->Number1]);
> +    } else {
> +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Driver%04x",
> BcfgOperation->Order[BcfgOperation->Number1]);
> +    }
> +    Status = EfiBootManagerVariableToLoadOption (OptionStr, &LoadOption);
> +    if (EFI_ERROR(Status)) {
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NONE),
> gShellBcfgHiiHandle);
> +      ShellStatus = SHELL_NOT_FOUND;
> +    }
> +  }
> +
> +  if (ShellStatus == SHELL_SUCCESS) {
> +    if (BcfgOperation->Type == BcfgTypeMod) {
> +      SHELL_FREE_NON_NULL (LoadOption.Description);
> +      LoadOption.Description = AllocateCopyPool (StrSize (BcfgOperation-
> >Description), BcfgOperation->Description);
> +    } else {
> +      SHELL_FREE_NON_NULL (LoadOption.FilePath);
> +      LoadOption.FilePath = DuplicateDevicePath (DevicePath);
> +    }
> +
> +    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> +    if (EFI_ERROR(Status)) {
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL),
> gShellBcfgHiiHandle, L"bcfg", OptionStr);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    }
> +  }
> +
> +  EfiBootManagerFreeLoadOption (&LoadOption);
> +
> +  if (DevicePath != NULL) {
> +    FreePool (DevicePath);
> +  }
> +
> +  if (FileList != NULL) {
> +    ShellCloseFileMetaArg (&FileList);
> +  }
> +
> +  return (ShellStatus);
> +}
> +
> +/**
>    Function to add a option.
> 
>    @param[in] Position       The position to add Target at.
> @@ -1404,6 +1650,102 @@ ShellCommandRunBcfg (
>                }
>              }
>            }
> +        }
> +        else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"mod") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeMod;
> +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate,
> TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.Description == NULL);
> +                CurrentOperation.Description = StrnCatGrow
> (&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modf") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModf;
> +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64  (CurrentParam, &Intermediate,
> TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.FileName == NULL);
> +                CurrentOperation.FileName = StrnCatGrow
> (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modp") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModp;
> +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate,
> TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.FileName == NULL);
> +                CurrentOperation.FileName = StrnCatGrow
> (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modh") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModh;
> +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            }
> +            else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate,
> TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> +                if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> +                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +                  ShellStatus = SHELL_INVALID_PARAMETER;
> +                } else {
> +                  Status = ShellConvertStringToUint64 (CurrentParam,
> &Intermediate, TRUE, FALSE);
> +                  CurrentOperation.HandleIndex = (UINT16)Intermediate;
> +                }
> +              }
> +            }
> +          }
>          } else {
>            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellBcfgHiiHandle, L"bcfg", CurrentParam);
>            ShellStatus = SHELL_INVALID_PARAMETER; @@ -1451,6 +1793,12 @@
> ShellCommandRunBcfg (
>              (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
>              CurrentOperation.HandleIndex);
>            break;
> +        case   BcfgTypeMod:
> +        case   BcfgTypeModf:
> +        case   BcfgTypeModp:
> +        case   BcfgTypeModh:
> +          ShellStatus = BcfgMod (&CurrentOperation, Count);
> +          break;
>          case   BcfgTypeOpt:
>            ShellStatus = BcfgAddOpt(
>              CurrentOperation.OptData,
> diff --git
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> index 44c8b7e..88b96ea 100644
> ---
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> +++
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.i
> +++ nf
> @@ -1,7 +1,7 @@
>  ##  @file
>  #  Provides shell install1 functions
>  #
> -#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
> +#  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
> +<BR>
>  #
>  #  This program and the accompanying materials  #  are licensed and made
> available under the terms and conditions of the BSD License @@ -41,6 +41,7
> @@ [LibraryClasses]
>    UefiBootServicesTableLib
>    SortLib
>    PrintLib
> +  UefiBootManagerLib
> 
>  [Guids]
>    gShellBcfgHiiGuid             ## SOMETIMES_CONSUMES ## HII
> diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index
> 5c01933..a87428a 100644
> --- a/ShellPkg/ShellPkg.dsc
> +++ b/ShellPkg/ShellPkg.dsc
> @@ -55,6 +55,14 @@ [LibraryClasses.common]
> 
> BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfg
> CommandLib.inf
>    IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> 
> +
> +
> UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBoo
> tMan
> + agerLib.inf  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> +
> +
> TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTem
> pl
> + ate.inf
> +
> PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanc
> eLi
> + bNull.inf
> +
> DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTabl
> + eLib.inf
> + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
> +
> +
> ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseR
> ep
> + ortStatusCodeLibNull.inf
> +
>  [LibraryClasses.ARM]
>    #
>    # It is not possible to prevent the ARM compiler for generic intrinsic
> functions.
> --
> 2.9.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification functionality
Posted by Ard Biesheuvel 7 years, 1 month ago
On 27 February 2017 at 07:50, Ruiyu Ni <ruiyu.ni@intel.com> wrote:
> From: chen881220 <ai_terran@foxmail.com>
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
> Cc: Jaben Carsey <jaben.carsey@intel.com>

This patch has broken the ArmVirtXen.dsc build

Processing meta-data .

build.py...
<https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-upstream/ws/edk2/ArmVirtPkg/ArmVirtXen.dsc(...)>:
error 4000: Instance of library class [UefiBootManagerLib] is not
found
        in [<https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-upstream/ws/edk2/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf]>
[ARM]
        consumed by module
[<https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-upstream/ws/edk2/ShellPkg/Application/Shell/Shell.inf]>

I take it that it is simply a matter of adding

UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf

to the broken platforms?


> ---
>  .../UefiShellBcfgCommandLib.c                      | 352 ++++++++++++++++++++-
>  .../UefiShellBcfgCommandLib.inf                    |   3 +-
>  ShellPkg/ShellPkg.dsc                              |   8 +
>  3 files changed, 360 insertions(+), 3 deletions(-)
>
> diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> index 62a52ad..1538bc6 100644
> --- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> +++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> @@ -2,7 +2,7 @@
>    Main file for BCFG command.
>
>    (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
> -  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD License
>    which accompanies this distribution.  The full text of the license may be found at
> @@ -41,6 +41,7 @@
>  #include <Library/PrintLib.h>
>  #include <Library/HandleParsingLib.h>
>  #include <Library/DevicePathLib.h>
> +#include <Library/UefiBootManagerLib.h>
>
>  STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
>  STATIC EFI_HANDLE gShellBcfgHiiHandle  = NULL;
> @@ -59,7 +60,11 @@ typedef enum {
>    BcfgTypeRm         = 4,
>    BcfgTypeMv         = 5,
>    BcfgTypeOpt        = 6,
> -  BcfgTypeMax        = 7
> +  BcfgTypeMod        = 7,
> +  BcfgTypeModf       = 8,
> +  BcfgTypeModp       = 9,
> +  BcfgTypeModh       = 10,
> +  BcfgTypeMax        = 11
>  } BCFG_OPERATION_TYPE;
>
>  typedef struct {
> @@ -275,6 +280,247 @@ GetDevicePathForDriverHandle (
>  }
>
>  /**
> +  Functino to get Device Path by a handle.
> +
> +  @param[in]        TheHandle   Use it to get DevicePath.
> +  @param[in]        Target      Boot option target.
> +  @param[in, out]   DevicePath  On a sucessful return the device path to the handle.
> +
> +  @retval   SHELL_INVALID_PARAMETER The handle was NULL.
> +  @retval   SHELL_NOT_FOUND         Not found device path by handle.
> +  @retval   SHELL_SUCCESS           Get device path successfully.
> +**/
> +SHELL_STATUS
> +GetDevicePathByHandle(
> +  IN     EFI_HANDLE               TheHandle,
> +  IN     BCFG_OPERATION_TARGET    Target,
> +  IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
> +  )
> +{
> +  EFI_STATUS   Status;
> +  SHELL_STATUS ShellStatus;
> +
> +  UINTN DriverBindingHandleCount;
> +  UINTN ParentControllerHandleCount;
> +  UINTN ChildControllerHandleCount;
> +
> +  ShellStatus = SHELL_SUCCESS;
> +
> +  if (TheHandle == NULL) {
> +    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number");
> +    return SHELL_INVALID_PARAMETER;
> +  }
> +
> +  Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle, &DriverBindingHandleCount, NULL);
> +  if (EFI_ERROR(Status)) {
> +    DriverBindingHandleCount = 0;
> +  }
> +
> +  Status = PARSE_HANDLE_DATABASE_PARENTS (TheHandle, &ParentControllerHandleCount, NULL);
> +  if (EFI_ERROR (Status)) {
> +    ParentControllerHandleCount = 0;
> +  }
> +
> +  Status = ParseHandleDatabaseForChildControllers (TheHandle, &ChildControllerHandleCount, NULL);
> +  if (EFI_ERROR (Status)) {
> +    ChildControllerHandleCount = 0;
> +  }
> +
> +  Status = gBS->HandleProtocol (TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)DevicePath);
> +
> +  if ( DriverBindingHandleCount    > 0 ||
> +       ParentControllerHandleCount > 0 ||
> +       ChildControllerHandleCount  > 0 ||
> +       !EFI_ERROR(Status)
> +     ) {
> +    //
> +    // The handle points to a real controller which has a device path.
> +    //
> +    if (Target == BcfgTargetDriverOrder) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,STRING_TOKEN (STR_GEN_PARAM_INV),
> +        gShellBcfgHiiHandle,
> +        L"bcfg",
> +        L"Handle should point to driver image."
> +      );
> +      ShellStatus = SHELL_NOT_FOUND;
> +    }
> +  } else {
> +    //
> +    // The handle points to a driver image.
> +    //
> +    if (Target == BcfgTargetBootOrder) {
> +      ShellPrintHiiEx (
> +        -1,
> +        -1,
> +        NULL,
> +        STRING_TOKEN (STR_GEN_PARAM_INV),
> +        gShellBcfgHiiHandle,
> +        L"bcfg",
> +        L"Handle should point to controller."
> +      );
> +      ShellStatus = SHELL_NOT_FOUND;
> +    } else {
> +      if (EFI_ERROR (GetDevicePathForDriverHandle (TheHandle, DevicePath))) {
> +        ShellStatus = SHELL_NOT_FOUND;
> +      }
> +    }
> +  }
> +
> +  return (ShellStatus);
> +}
> +
> +/**
> +  Function to modify an option.
> +
> +  @param[in] BcfgOperation  Pointer to BCFG operation.
> +  @param[in] OrderCount     The number if items in CurrentOrder.
> +
> +  @retval SHELL_SUCCESS             The operation was successful.
> +  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.
> +  @retval SHELL_OUT_OF_RESOUCES     A memory allocation failed.
> +**/
> +SHELL_STATUS
> +BcfgMod (
> +  IN CONST BGFG_OPERATION   *BcfgOperation,
> +  IN CONST UINTN            OrderCount
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  EFI_HANDLE                    CurHandle;
> +  SHELL_STATUS                  ShellStatus;
> +  CHAR16                        OptionStr[40];
> +  EFI_SHELL_FILE_INFO           *FileList;
> +  EFI_SHELL_FILE_INFO           *Arg;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathBuffer;
> +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathWalker;
> +  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;
> +
> +  ShellStatus       = SHELL_SUCCESS;
> +  FileList          = NULL;
> +  DevicePath        = NULL;
> +
> +  ZeroMem (&LoadOption, sizeof(EFI_BOOT_MANAGER_LOAD_OPTION));
> +
> +  if ( (BcfgOperation->Type == BcfgTypeMod  && BcfgOperation->Description == NULL)  ||
> +       (BcfgOperation->Type == BcfgTypeModf && BcfgOperation->FileName == NULL)     ||
> +       (BcfgOperation->Type == BcfgTypeModp && BcfgOperation->FileName == NULL)     ||
> +       (BcfgOperation->Type == BcfgTypeModh && BcfgOperation->HandleIndex == 0)     ||
> +       (BcfgOperation->Number1 > OrderCount)
> +     ) {
> +    return (SHELL_INVALID_PARAMETER);
> +  }
> +
> +  if (BcfgOperation->Type == BcfgTypeModh) {
> +    CurHandle = ConvertHandleIndexToHandle (BcfgOperation->HandleIndex);
> +    ShellStatus = GetDevicePathByHandle (CurHandle, BcfgOperation->Target, &DevicePathBuffer);
> +    if (ShellStatus == SHELL_SUCCESS) {
> +      DevicePath = DuplicateDevicePath (DevicePathBuffer);
> +    }
> +  } else if (BcfgOperation->Type == BcfgTypeModf || BcfgOperation->Type == BcfgTypeModp) {
> +    //
> +    // Get Device Path by FileName.
> +    //
> +    ShellOpenFileMetaArg ((CHAR16 *)BcfgOperation->FileName, EFI_FILE_MODE_READ, &FileList);
> +    if (FileList == NULL) {
> +      //
> +      // The name of file matched nothing.
> +      //
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    }
> +    else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {
> +      //
> +      // If the name of file expanded to multiple names, it's fail.
> +      //
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    } else {
> +      Arg = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link);
> +      if (EFI_ERROR (Arg->Status)) {
> +        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN), gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +      } else {
> +        DevicePathBuffer = gEfiShellProtocol->GetDevicePathFromFilePath (Arg->FullName);
> +        if (DevicePathBuffer == NULL) {
> +          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellBcfgHiiHandle, L"bcfg", Arg->FullName);
> +          ShellStatus = SHELL_UNSUPPORTED;
> +        }
> +      }
> +    }
> +
> +    if (ShellStatus == SHELL_SUCCESS) {
> +      if (BcfgOperation->Type == BcfgTypeModp) {
> +        ShellStatus = SHELL_INVALID_PARAMETER;
> +        DevicePathWalker = DevicePathBuffer;
> +        while (!IsDevicePathEnd (DevicePathWalker)) {
> +          if ( DevicePathType (DevicePathWalker) == MEDIA_DEVICE_PATH &&
> +               DevicePathSubType (DevicePathWalker) == MEDIA_HARDDRIVE_DP
> +             ) {
> +            //
> +            // We found the portion of device path starting with the hard driver partition.
> +            //
> +            ShellStatus = SHELL_SUCCESS;
> +            DevicePath = DuplicateDevicePath (DevicePathWalker);
> +            break;
> +          } else {
> +            DevicePathWalker = NextDevicePathNode (DevicePathWalker);
> +          }
> +        }
> +      } else {
> +        DevicePath = DuplicateDevicePath (DevicePathBuffer);
> +      }
> +
> +      FreePool (DevicePathBuffer);
> +    }
> +  }
> +
> +  if (ShellStatus == SHELL_SUCCESS) {
> +    if (BcfgOperation->Target == BcfgTargetBootOrder) {
> +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Boot%04x", BcfgOperation->Order[BcfgOperation->Number1]);
> +    } else {
> +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Driver%04x", BcfgOperation->Order[BcfgOperation->Number1]);
> +    }
> +    Status = EfiBootManagerVariableToLoadOption (OptionStr, &LoadOption);
> +    if (EFI_ERROR(Status)) {
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NONE), gShellBcfgHiiHandle);
> +      ShellStatus = SHELL_NOT_FOUND;
> +    }
> +  }
> +
> +  if (ShellStatus == SHELL_SUCCESS) {
> +    if (BcfgOperation->Type == BcfgTypeMod) {
> +      SHELL_FREE_NON_NULL (LoadOption.Description);
> +      LoadOption.Description = AllocateCopyPool (StrSize (BcfgOperation->Description), BcfgOperation->Description);
> +    } else {
> +      SHELL_FREE_NON_NULL (LoadOption.FilePath);
> +      LoadOption.FilePath = DuplicateDevicePath (DevicePath);
> +    }
> +
> +    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> +    if (EFI_ERROR(Status)) {
> +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
> +      ShellStatus = SHELL_INVALID_PARAMETER;
> +    }
> +  }
> +
> +  EfiBootManagerFreeLoadOption (&LoadOption);
> +
> +  if (DevicePath != NULL) {
> +    FreePool (DevicePath);
> +  }
> +
> +  if (FileList != NULL) {
> +    ShellCloseFileMetaArg (&FileList);
> +  }
> +
> +  return (ShellStatus);
> +}
> +
> +/**
>    Function to add a option.
>
>    @param[in] Position       The position to add Target at.
> @@ -1404,6 +1650,102 @@ ShellCommandRunBcfg (
>                }
>              }
>            }
> +        }
> +        else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"mod") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeMod;
> +            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.Description == NULL);
> +                CurrentOperation.Description = StrnCatGrow (&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modf") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModf;
> +            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64  (CurrentParam, &Intermediate, TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.FileName == NULL);
> +                CurrentOperation.FileName = StrnCatGrow (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modp") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModp;
> +            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            } else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                ASSERT (CurrentOperation.FileName == NULL);
> +                CurrentOperation.FileName = StrnCatGrow (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue (Package, ++ParamNumber), 0);
> +              }
> +            }
> +          }
> +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16*)CurrentParam, L"modh") == 0) {
> +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellBcfgHiiHandle, L"bcfg");
> +            ShellStatus = SHELL_INVALID_PARAMETER;
> +          } else {
> +            CurrentOperation.Type = BcfgTypeModh;
> +            CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
> +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
> +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +              ShellStatus = SHELL_INVALID_PARAMETER;
> +            }
> +            else {
> +              Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
> +              CurrentOperation.Number1 = (UINT16)Intermediate;
> +              if (CurrentOperation.Number1 >= Count) {
> +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> +                ShellStatus = SHELL_INVALID_PARAMETER;
> +              } else {
> +                CurrentParam = ShellCommandLineGetRawValue (Package, ++ParamNumber);
> +                if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber (CurrentParam, TRUE, FALSE)) {
> +                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> +                  ShellStatus = SHELL_INVALID_PARAMETER;
> +                } else {
> +                  Status = ShellConvertStringToUint64 (CurrentParam, &Intermediate, TRUE, FALSE);
> +                  CurrentOperation.HandleIndex = (UINT16)Intermediate;
> +                }
> +              }
> +            }
> +          }
>          } else {
>            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
>            ShellStatus = SHELL_INVALID_PARAMETER;
> @@ -1451,6 +1793,12 @@ ShellCommandRunBcfg (
>              (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
>              CurrentOperation.HandleIndex);
>            break;
> +        case   BcfgTypeMod:
> +        case   BcfgTypeModf:
> +        case   BcfgTypeModp:
> +        case   BcfgTypeModh:
> +          ShellStatus = BcfgMod (&CurrentOperation, Count);
> +          break;
>          case   BcfgTypeOpt:
>            ShellStatus = BcfgAddOpt(
>              CurrentOperation.OptData,
> diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> index 44c8b7e..88b96ea 100644
> --- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> +++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> @@ -1,7 +1,7 @@
>  ##  @file
>  #  Provides shell install1 functions
>  #
> -#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
> +#  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
>  #
>  #  This program and the accompanying materials
>  #  are licensed and made available under the terms and conditions of the BSD License
> @@ -41,6 +41,7 @@ [LibraryClasses]
>    UefiBootServicesTableLib
>    SortLib
>    PrintLib
> +  UefiBootManagerLib
>
>  [Guids]
>    gShellBcfgHiiGuid             ## SOMETIMES_CONSUMES ## HII
> diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
> index 5c01933..a87428a 100644
> --- a/ShellPkg/ShellPkg.dsc
> +++ b/ShellPkg/ShellPkg.dsc
> @@ -55,6 +55,14 @@ [LibraryClasses.common]
>    BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
>    IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
>
> +  UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
> +  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> +  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
> +  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
> +  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
> +  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
> +  ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
> +
>  [LibraryClasses.ARM]
>    #
>    # It is not possible to prevent the ARM compiler for generic intrinsic functions.
> --
> 2.9.0.windows.1
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification functionality
Posted by Ni, Ruiyu 7 years, 1 month ago
Yes.
sorry about that!
Can you commit this change?

Thanks/Ray

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Wednesday, March 1, 2017 3:33 PM
> To: Ni, Ruiyu <ruiyu.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>
> Cc: edk2-devel@lists.01.org; Carsey, Jaben <jaben.carsey@intel.com>; Chen,
> Chen A <chen.a.chen@intel.com>; chen881220 <ai_terran@foxmail.com>
> Subject: Re: [edk2] [PATCH] ShellPkg/bcfg: Add Shell Spec 2.2 modification
> functionality
> 
> On 27 February 2017 at 07:50, Ruiyu Ni <ruiyu.ni@intel.com> wrote:
> > From: chen881220 <ai_terran@foxmail.com>
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
> > Cc: Jaben Carsey <jaben.carsey@intel.com>
> 
> This patch has broken the ArmVirtXen.dsc build
> 
> Processing meta-data .
> 
> build.py...
> <https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-
> upstream/ws/edk2/ArmVirtPkg/ArmVirtXen.dsc(...)>:
> error 4000: Instance of library class [UefiBootManagerLib] is not
> found
>         in [<https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-
> upstream/ws/edk2/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcf
> gCommandLib.inf]>
> [ARM]
>         consumed by module
> [<https://ci.linaro.org/jenkins/job/leg-virt-tianocore-edk2-
> upstream/ws/edk2/ShellPkg/Application/Shell/Shell.inf]>
> 
> I take it that it is simply a matter of adding
> 
> UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBoo
> tManagerLib.inf
> 
> to the broken platforms?
> 
> 
> > ---
> >  .../UefiShellBcfgCommandLib.c                      | 352 ++++++++++++++++++++-
> >  .../UefiShellBcfgCommandLib.inf                    |   3 +-
> >  ShellPkg/ShellPkg.dsc                              |   8 +
> >  3 files changed, 360 insertions(+), 3 deletions(-)
> >
> > diff --git
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> > index 62a52ad..1538bc6 100644
> > ---
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> > +++
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
> > @@ -2,7 +2,7 @@
> >    Main file for BCFG command.
> >
> >    (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
> > -  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> > +  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> >    This program and the accompanying materials
> >    are licensed and made available under the terms and conditions of the
> BSD License
> >    which accompanies this distribution.  The full text of the license may be
> found at
> > @@ -41,6 +41,7 @@
> >  #include <Library/PrintLib.h>
> >  #include <Library/HandleParsingLib.h>
> >  #include <Library/DevicePathLib.h>
> > +#include <Library/UefiBootManagerLib.h>
> >
> >  STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
> >  STATIC EFI_HANDLE gShellBcfgHiiHandle  = NULL;
> > @@ -59,7 +60,11 @@ typedef enum {
> >    BcfgTypeRm         = 4,
> >    BcfgTypeMv         = 5,
> >    BcfgTypeOpt        = 6,
> > -  BcfgTypeMax        = 7
> > +  BcfgTypeMod        = 7,
> > +  BcfgTypeModf       = 8,
> > +  BcfgTypeModp       = 9,
> > +  BcfgTypeModh       = 10,
> > +  BcfgTypeMax        = 11
> >  } BCFG_OPERATION_TYPE;
> >
> >  typedef struct {
> > @@ -275,6 +280,247 @@ GetDevicePathForDriverHandle (
> >  }
> >
> >  /**
> > +  Functino to get Device Path by a handle.
> > +
> > +  @param[in]        TheHandle   Use it to get DevicePath.
> > +  @param[in]        Target      Boot option target.
> > +  @param[in, out]   DevicePath  On a sucessful return the device path to
> the handle.
> > +
> > +  @retval   SHELL_INVALID_PARAMETER The handle was NULL.
> > +  @retval   SHELL_NOT_FOUND         Not found device path by handle.
> > +  @retval   SHELL_SUCCESS           Get device path successfully.
> > +**/
> > +SHELL_STATUS
> > +GetDevicePathByHandle(
> > +  IN     EFI_HANDLE               TheHandle,
> > +  IN     BCFG_OPERATION_TARGET    Target,
> > +  IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
> > +  )
> > +{
> > +  EFI_STATUS   Status;
> > +  SHELL_STATUS ShellStatus;
> > +
> > +  UINTN DriverBindingHandleCount;
> > +  UINTN ParentControllerHandleCount;
> > +  UINTN ChildControllerHandleCount;
> > +
> > +  ShellStatus = SHELL_SUCCESS;
> > +
> > +  if (TheHandle == NULL) {
> > +    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellBcfgHiiHandle, L"bcfg", L"Handle Number");
> > +    return SHELL_INVALID_PARAMETER;
> > +  }
> > +
> > +  Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle,
> &DriverBindingHandleCount, NULL);
> > +  if (EFI_ERROR(Status)) {
> > +    DriverBindingHandleCount = 0;
> > +  }
> > +
> > +  Status = PARSE_HANDLE_DATABASE_PARENTS (TheHandle,
> &ParentControllerHandleCount, NULL);
> > +  if (EFI_ERROR (Status)) {
> > +    ParentControllerHandleCount = 0;
> > +  }
> > +
> > +  Status = ParseHandleDatabaseForChildControllers (TheHandle,
> &ChildControllerHandleCount, NULL);
> > +  if (EFI_ERROR (Status)) {
> > +    ChildControllerHandleCount = 0;
> > +  }
> > +
> > +  Status = gBS->HandleProtocol (TheHandle, &gEfiDevicePathProtocolGuid,
> (VOID**)DevicePath);
> > +
> > +  if ( DriverBindingHandleCount    > 0 ||
> > +       ParentControllerHandleCount > 0 ||
> > +       ChildControllerHandleCount  > 0 ||
> > +       !EFI_ERROR(Status)
> > +     ) {
> > +    //
> > +    // The handle points to a real controller which has a device path.
> > +    //
> > +    if (Target == BcfgTargetDriverOrder) {
> > +      ShellPrintHiiEx (
> > +        -1,
> > +        -1,
> > +        NULL,STRING_TOKEN (STR_GEN_PARAM_INV),
> > +        gShellBcfgHiiHandle,
> > +        L"bcfg",
> > +        L"Handle should point to driver image."
> > +      );
> > +      ShellStatus = SHELL_NOT_FOUND;
> > +    }
> > +  } else {
> > +    //
> > +    // The handle points to a driver image.
> > +    //
> > +    if (Target == BcfgTargetBootOrder) {
> > +      ShellPrintHiiEx (
> > +        -1,
> > +        -1,
> > +        NULL,
> > +        STRING_TOKEN (STR_GEN_PARAM_INV),
> > +        gShellBcfgHiiHandle,
> > +        L"bcfg",
> > +        L"Handle should point to controller."
> > +      );
> > +      ShellStatus = SHELL_NOT_FOUND;
> > +    } else {
> > +      if (EFI_ERROR (GetDevicePathForDriverHandle (TheHandle,
> DevicePath))) {
> > +        ShellStatus = SHELL_NOT_FOUND;
> > +      }
> > +    }
> > +  }
> > +
> > +  return (ShellStatus);
> > +}
> > +
> > +/**
> > +  Function to modify an option.
> > +
> > +  @param[in] BcfgOperation  Pointer to BCFG operation.
> > +  @param[in] OrderCount     The number if items in CurrentOrder.
> > +
> > +  @retval SHELL_SUCCESS             The operation was successful.
> > +  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.
> > +  @retval SHELL_OUT_OF_RESOUCES     A memory allocation failed.
> > +**/
> > +SHELL_STATUS
> > +BcfgMod (
> > +  IN CONST BGFG_OPERATION   *BcfgOperation,
> > +  IN CONST UINTN            OrderCount
> > +  )
> > +{
> > +  EFI_STATUS                    Status;
> > +  EFI_HANDLE                    CurHandle;
> > +  SHELL_STATUS                  ShellStatus;
> > +  CHAR16                        OptionStr[40];
> > +  EFI_SHELL_FILE_INFO           *FileList;
> > +  EFI_SHELL_FILE_INFO           *Arg;
> > +  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
> > +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathBuffer;
> > +  EFI_DEVICE_PATH_PROTOCOL      *DevicePathWalker;
> > +  EFI_BOOT_MANAGER_LOAD_OPTION  LoadOption;
> > +
> > +  ShellStatus       = SHELL_SUCCESS;
> > +  FileList          = NULL;
> > +  DevicePath        = NULL;
> > +
> > +  ZeroMem (&LoadOption, sizeof(EFI_BOOT_MANAGER_LOAD_OPTION));
> > +
> > +  if ( (BcfgOperation->Type == BcfgTypeMod  && BcfgOperation-
> >Description == NULL)  ||
> > +       (BcfgOperation->Type == BcfgTypeModf && BcfgOperation-
> >FileName == NULL)     ||
> > +       (BcfgOperation->Type == BcfgTypeModp && BcfgOperation-
> >FileName == NULL)     ||
> > +       (BcfgOperation->Type == BcfgTypeModh && BcfgOperation-
> >HandleIndex == 0)     ||
> > +       (BcfgOperation->Number1 > OrderCount)
> > +     ) {
> > +    return (SHELL_INVALID_PARAMETER);
> > +  }
> > +
> > +  if (BcfgOperation->Type == BcfgTypeModh) {
> > +    CurHandle = ConvertHandleIndexToHandle (BcfgOperation-
> >HandleIndex);
> > +    ShellStatus = GetDevicePathByHandle (CurHandle, BcfgOperation-
> >Target, &DevicePathBuffer);
> > +    if (ShellStatus == SHELL_SUCCESS) {
> > +      DevicePath = DuplicateDevicePath (DevicePathBuffer);
> > +    }
> > +  } else if (BcfgOperation->Type == BcfgTypeModf || BcfgOperation-
> >Type == BcfgTypeModp) {
> > +    //
> > +    // Get Device Path by FileName.
> > +    //
> > +    ShellOpenFileMetaArg ((CHAR16 *)BcfgOperation->FileName,
> EFI_FILE_MODE_READ, &FileList);
> > +    if (FileList == NULL) {
> > +      //
> > +      // The name of file matched nothing.
> > +      //
> > +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_FILE_OPEN_FAIL), gShellBcfgHiiHandle, L"bcfg", BcfgOperation-
> >FileName);
> > +      ShellStatus = SHELL_INVALID_PARAMETER;
> > +    }
> > +    else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {
> > +      //
> > +      // If the name of file expanded to multiple names, it's fail.
> > +      //
> > +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE),
> gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> > +      ShellStatus = SHELL_INVALID_PARAMETER;
> > +    } else {
> > +      Arg = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link);
> > +      if (EFI_ERROR (Arg->Status)) {
> > +        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN),
> gShellBcfgHiiHandle, L"bcfg", BcfgOperation->FileName);
> > +        ShellStatus = SHELL_INVALID_PARAMETER;
> > +      } else {
> > +        DevicePathBuffer = gEfiShellProtocol->GetDevicePathFromFilePath
> (Arg->FullName);
> > +        if (DevicePathBuffer == NULL) {
> > +          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP),
> gShellBcfgHiiHandle, L"bcfg", Arg->FullName);
> > +          ShellStatus = SHELL_UNSUPPORTED;
> > +        }
> > +      }
> > +    }
> > +
> > +    if (ShellStatus == SHELL_SUCCESS) {
> > +      if (BcfgOperation->Type == BcfgTypeModp) {
> > +        ShellStatus = SHELL_INVALID_PARAMETER;
> > +        DevicePathWalker = DevicePathBuffer;
> > +        while (!IsDevicePathEnd (DevicePathWalker)) {
> > +          if ( DevicePathType (DevicePathWalker) == MEDIA_DEVICE_PATH
> &&
> > +               DevicePathSubType (DevicePathWalker) ==
> MEDIA_HARDDRIVE_DP
> > +             ) {
> > +            //
> > +            // We found the portion of device path starting with the hard driver
> partition.
> > +            //
> > +            ShellStatus = SHELL_SUCCESS;
> > +            DevicePath = DuplicateDevicePath (DevicePathWalker);
> > +            break;
> > +          } else {
> > +            DevicePathWalker = NextDevicePathNode (DevicePathWalker);
> > +          }
> > +        }
> > +      } else {
> > +        DevicePath = DuplicateDevicePath (DevicePathBuffer);
> > +      }
> > +
> > +      FreePool (DevicePathBuffer);
> > +    }
> > +  }
> > +
> > +  if (ShellStatus == SHELL_SUCCESS) {
> > +    if (BcfgOperation->Target == BcfgTargetBootOrder) {
> > +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Boot%04x",
> BcfgOperation->Order[BcfgOperation->Number1]);
> > +    } else {
> > +      UnicodeSPrint (OptionStr, sizeof (OptionStr), L"Driver%04x",
> BcfgOperation->Order[BcfgOperation->Number1]);
> > +    }
> > +    Status = EfiBootManagerVariableToLoadOption (OptionStr,
> &LoadOption);
> > +    if (EFI_ERROR(Status)) {
> > +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_NONE),
> gShellBcfgHiiHandle);
> > +      ShellStatus = SHELL_NOT_FOUND;
> > +    }
> > +  }
> > +
> > +  if (ShellStatus == SHELL_SUCCESS) {
> > +    if (BcfgOperation->Type == BcfgTypeMod) {
> > +      SHELL_FREE_NON_NULL (LoadOption.Description);
> > +      LoadOption.Description = AllocateCopyPool (StrSize (BcfgOperation-
> >Description), BcfgOperation->Description);
> > +    } else {
> > +      SHELL_FREE_NON_NULL (LoadOption.FilePath);
> > +      LoadOption.FilePath = DuplicateDevicePath (DevicePath);
> > +    }
> > +
> > +    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> > +    if (EFI_ERROR(Status)) {
> > +      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
> > +      ShellStatus = SHELL_INVALID_PARAMETER;
> > +    }
> > +  }
> > +
> > +  EfiBootManagerFreeLoadOption (&LoadOption);
> > +
> > +  if (DevicePath != NULL) {
> > +    FreePool (DevicePath);
> > +  }
> > +
> > +  if (FileList != NULL) {
> > +    ShellCloseFileMetaArg (&FileList);
> > +  }
> > +
> > +  return (ShellStatus);
> > +}
> > +
> > +/**
> >    Function to add a option.
> >
> >    @param[in] Position       The position to add Target at.
> > @@ -1404,6 +1650,102 @@ ShellCommandRunBcfg (
> >                }
> >              }
> >            }
> > +        }
> > +        else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"mod") == 0) {
> > +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> > +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> > +            ShellStatus = SHELL_INVALID_PARAMETER;
> > +          } else {
> > +            CurrentOperation.Type = BcfgTypeMod;
> > +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> > +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> > +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> > +              ShellStatus = SHELL_INVALID_PARAMETER;
> > +            } else {
> > +              Status = ShellConvertStringToUint64 (CurrentParam,
> &Intermediate, TRUE, FALSE);
> > +              CurrentOperation.Number1 = (UINT16)Intermediate;
> > +              if (CurrentOperation.Number1 >= Count) {
> > +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> > +                ShellStatus = SHELL_INVALID_PARAMETER;
> > +              } else {
> > +                ASSERT (CurrentOperation.Description == NULL);
> > +                CurrentOperation.Description = StrnCatGrow
> (&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> > +              }
> > +            }
> > +          }
> > +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modf") == 0) {
> > +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> > +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> > +            ShellStatus = SHELL_INVALID_PARAMETER;
> > +          } else {
> > +            CurrentOperation.Type = BcfgTypeModf;
> > +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> > +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> > +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> > +              ShellStatus = SHELL_INVALID_PARAMETER;
> > +            } else {
> > +              Status = ShellConvertStringToUint64  (CurrentParam,
> &Intermediate, TRUE, FALSE);
> > +              CurrentOperation.Number1 = (UINT16)Intermediate;
> > +              if (CurrentOperation.Number1 >= Count) {
> > +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> > +                ShellStatus = SHELL_INVALID_PARAMETER;
> > +              } else {
> > +                ASSERT (CurrentOperation.FileName == NULL);
> > +                CurrentOperation.FileName = StrnCatGrow
> (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> > +              }
> > +            }
> > +          }
> > +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modp") == 0) {
> > +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> > +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> > +            ShellStatus = SHELL_INVALID_PARAMETER;
> > +          } else {
> > +            CurrentOperation.Type = BcfgTypeModp;
> > +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> > +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> > +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> > +              ShellStatus = SHELL_INVALID_PARAMETER;
> > +            } else {
> > +              Status = ShellConvertStringToUint64 (CurrentParam,
> &Intermediate, TRUE, FALSE);
> > +              CurrentOperation.Number1 = (UINT16)Intermediate;
> > +              if (CurrentOperation.Number1 >= Count) {
> > +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> > +                ShellStatus = SHELL_INVALID_PARAMETER;
> > +              } else {
> > +                ASSERT (CurrentOperation.FileName == NULL);
> > +                CurrentOperation.FileName = StrnCatGrow
> (&CurrentOperation.FileName, NULL, ShellCommandLineGetRawValue
> (Package, ++ParamNumber), 0);
> > +              }
> > +            }
> > +          }
> > +        } else if (gUnicodeCollation->StriColl (gUnicodeCollation,
> (CHAR16*)CurrentParam, L"modh") == 0) {
> > +          if ((ParamNumber + 2) >= ShellCommandLineGetCount (Package)) {
> > +            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),
> gShellBcfgHiiHandle, L"bcfg");
> > +            ShellStatus = SHELL_INVALID_PARAMETER;
> > +          } else {
> > +            CurrentOperation.Type = BcfgTypeModh;
> > +            CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> > +            if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> > +              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> > +              ShellStatus = SHELL_INVALID_PARAMETER;
> > +            }
> > +            else {
> > +              Status = ShellConvertStringToUint64 (CurrentParam,
> &Intermediate, TRUE, FALSE);
> > +              CurrentOperation.Number1 = (UINT16)Intermediate;
> > +              if (CurrentOperation.Number1 >= Count) {
> > +                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);
> > +                ShellStatus = SHELL_INVALID_PARAMETER;
> > +              } else {
> > +                CurrentParam = ShellCommandLineGetRawValue (Package,
> ++ParamNumber);
> > +                if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber
> (CurrentParam, TRUE, FALSE)) {
> > +                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> > +                  ShellStatus = SHELL_INVALID_PARAMETER;
> > +                } else {
> > +                  Status = ShellConvertStringToUint64 (CurrentParam,
> &Intermediate, TRUE, FALSE);
> > +                  CurrentOperation.HandleIndex = (UINT16)Intermediate;
> > +                }
> > +              }
> > +            }
> > +          }
> >          } else {
> >            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellBcfgHiiHandle, L"bcfg", CurrentParam);
> >            ShellStatus = SHELL_INVALID_PARAMETER;
> > @@ -1451,6 +1793,12 @@ ShellCommandRunBcfg (
> >              (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
> >              CurrentOperation.HandleIndex);
> >            break;
> > +        case   BcfgTypeMod:
> > +        case   BcfgTypeModf:
> > +        case   BcfgTypeModp:
> > +        case   BcfgTypeModh:
> > +          ShellStatus = BcfgMod (&CurrentOperation, Count);
> > +          break;
> >          case   BcfgTypeOpt:
> >            ShellStatus = BcfgAddOpt(
> >              CurrentOperation.OptData,
> > diff --git
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> > index 44c8b7e..88b96ea 100644
> > ---
> a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> > +++
> b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
> > @@ -1,7 +1,7 @@
> >  ##  @file
> >  #  Provides shell install1 functions
> >  #
> > -#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
> > +#  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
> >  #
> >  #  This program and the accompanying materials
> >  #  are licensed and made available under the terms and conditions of the
> BSD License
> > @@ -41,6 +41,7 @@ [LibraryClasses]
> >    UefiBootServicesTableLib
> >    SortLib
> >    PrintLib
> > +  UefiBootManagerLib
> >
> >  [Guids]
> >    gShellBcfgHiiGuid             ## SOMETIMES_CONSUMES ## HII
> > diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
> > index 5c01933..a87428a 100644
> > --- a/ShellPkg/ShellPkg.dsc
> > +++ b/ShellPkg/ShellPkg.dsc
> > @@ -55,6 +55,14 @@ [LibraryClasses.common]
> >
> BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfg
> CommandLib.inf
> >    IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> >
> > +
> UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBoo
> tManagerLib.inf
> > +  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> > +
> TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTem
> plate.inf
> > +
> PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanc
> eLibNull.inf
> > +
> DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTabl
> eLib.inf
> > +  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
> > +
> ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseR
> eportStatusCodeLibNull.inf
> > +
> >  [LibraryClasses.ARM]
> >    #
> >    # It is not possible to prevent the ARM compiler for generic intrinsic
> functions.
> > --
> > 2.9.0.windows.1
> >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel