]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
ShellPkg/Bcfg: Add support for 'addp' command.
[mirror_edk2.git] / ShellPkg / Library / UefiShellBcfgCommandLib / UefiShellBcfgCommandLib.c
index 7e118eb771e6ff4a8f79ce982fa55be738240646..bf35a35b985d00e32af4e4aa5d1cb285c7e9a014 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Main file for BCFG command.\r
 \r
-  Copyright (c) 2014 - 2015, Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -310,6 +310,7 @@ BcfgAdd(
 {\r
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   EFI_DEVICE_PATH_PROTOCOL  *FilePath;\r
   CHAR16                    *Str;\r
   UINT8                     *TempByteBuffer;\r
@@ -353,7 +354,7 @@ BcfgAdd(
   if (UseHandle) {\r
     CurHandle = ConvertHandleIndexToHandle(HandleNumber);\r
     if (CurHandle == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellBcfgHiiHandle, L"Handle Number");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number");\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       if (Target == BcfgTargetBootOrder) {\r
@@ -462,9 +463,9 @@ BcfgAdd(
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellBcfgHiiHandle, L"bcfg", Arg->FullName);  \r
           ShellStatus = SHELL_UNSUPPORTED;\r
         } else {\r
-/*\r
           if (UsePath) {\r
-            DevPath = DevicePath;\r
+            DevPath     = DevicePath;\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
             while (!IsDevicePathEnd(DevPath)) {\r
               if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&\r
                 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {\r
@@ -472,24 +473,15 @@ BcfgAdd(
                 //\r
                 // If we find it use it instead\r
                 //\r
-                DevicePath = DevPath;\r
+                ShellStatus = SHELL_SUCCESS;\r
+                FilePath    = DuplicateDevicePath (DevPath);\r
                 break;\r
               }\r
               DevPath = NextDevicePathNode(DevPath);\r
             }\r
-            //\r
-            // append the file\r
-            //\r
-            for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);\r
-            FileNode = FileDevicePath(NULL, StringWalker+1);\r
-            FilePath = AppendDevicePath(DevicePath, FileNode);\r
-            FreePool(FileNode);\r
           } else {\r
-*/\r
             FilePath = DuplicateDevicePath(DevicePath);\r
-/*\r
           }\r
-*/\r
           FreePool(DevicePath);\r
         }\r
       }\r
@@ -1043,23 +1035,31 @@ BcfgDisplayDump(
   IN CONST BOOLEAN  VerboseOutput\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT8       *Buffer;\r
-  UINTN       BufferSize;\r
-  CHAR16      VariableName[12];\r
-  UINTN       LoopVar;\r
-  UINTN       LoopVar2;\r
-  CHAR16      *DevPathString;\r
-  VOID        *DevPath;\r
+  EFI_STATUS      Status;\r
+  UINT8           *Buffer;\r
+  UINTN           BufferSize;\r
+  CHAR16          VariableName[12];\r
+  UINTN           LoopVar;\r
+  CHAR16          *DevPathString;\r
+  VOID            *FilePathList;\r
+  UINTN           Errors;\r
+  EFI_LOAD_OPTION *LoadOption;\r
+  CHAR16          *Description;\r
+  UINTN           DescriptionSize;\r
+  UINTN           OptionalDataOffset;\r
 \r
   if (OrderCount == 0) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellBcfgHiiHandle, L"bcfg");  \r
     return (SHELL_SUCCESS);\r
   }\r
 \r
+  Errors = 0;\r
+\r
   for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) {\r
-    Buffer      = NULL;\r
-    BufferSize  = 0;\r
+    Buffer        = NULL;\r
+    BufferSize    = 0;\r
+    DevPathString = NULL;\r
+\r
     UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, CurrentOrder[LoopVar]);\r
 \r
     Status = gRT->GetVariable(\r
@@ -1080,21 +1080,40 @@ BcfgDisplayDump(
 \r
     if (EFI_ERROR(Status) || Buffer == NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_READ_FAIL), gShellBcfgHiiHandle, L"bcfg", VariableName);  \r
-      return (SHELL_INVALID_PARAMETER);\r
+      ++Errors;\r
+      goto Cleanup;\r
     }\r
 \r
-    if ((*(UINT16*)(Buffer+4)) != 0) {\r
-      DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
-      if (DevPath == NULL) {\r
-        DevPathString = NULL;\r
-      } else {\r
-        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
-        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
-      }\r
-    } else {\r
-      DevPath       = NULL;\r
-      DevPathString = NULL;\r
+    //\r
+    // We expect the Attributes, FilePathListLength, and L'\0'-terminated\r
+    // Description fields to be present.\r
+    //\r
+    if (BufferSize < sizeof *LoadOption + sizeof (CHAR16)) {\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
+        STRING_TOKEN (STR_BCFG_VAR_CORRUPT),\r
+        gShellBcfgHiiHandle,\r
+        L"bcfg",\r
+        VariableName\r
+        );\r
+      ++Errors;\r
+      goto Cleanup;\r
+    }\r
+\r
+    LoadOption      = (EFI_LOAD_OPTION *)Buffer;\r
+    Description     = (CHAR16*)(Buffer + sizeof (EFI_LOAD_OPTION));\r
+    DescriptionSize = StrSize (Description);\r
+\r
+    if (LoadOption->FilePathListLength != 0) {\r
+      FilePathList = (UINT8 *)Description + DescriptionSize;\r
+      DevPathString = ConvertDevicePathToText(FilePathList, TRUE, FALSE);\r
     }\r
+\r
+    OptionalDataOffset = sizeof *LoadOption + DescriptionSize +\r
+                         LoadOption->FilePathListLength;\r
+\r
     ShellPrintHiiEx(\r
       -1,\r
       -1,\r
@@ -1103,36 +1122,28 @@ BcfgDisplayDump(
       gShellBcfgHiiHandle,\r
       LoopVar,\r
       VariableName,\r
-      (CHAR16*)(Buffer+6),\r
+      Description,\r
       DevPathString,\r
-      (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6) <= BufferSize?L'N':L'Y');\r
-    if (VerboseOutput) {\r
-      for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6);LoopVar2<BufferSize;LoopVar2++){\r
-        ShellPrintEx(\r
-          -1,\r
-          -1,\r
-          NULL,\r
-          L"%02x",\r
-          Buffer[LoopVar2]);\r
-      }\r
-      ShellPrintEx(\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        L"\r\n");\r
+      OptionalDataOffset >= BufferSize ? L'N' : L'Y'\r
+      );\r
+    if (VerboseOutput && (OptionalDataOffset < BufferSize)) {\r
+      DumpHex (\r
+        2,                               // Indent\r
+        0,                               // Offset (displayed)\r
+        BufferSize - OptionalDataOffset, // DataSize\r
+        Buffer + OptionalDataOffset      // UserData\r
+        );\r
     }\r
 \r
+Cleanup:\r
     if (Buffer != NULL) {\r
       FreePool(Buffer);\r
     }\r
-    if (DevPath != NULL) {\r
-      FreePool(DevPath);\r
-    }\r
     if (DevPathString != NULL) {\r
       FreePool(DevPathString);\r
     }\r
   }\r
-  return (SHELL_SUCCESS);\r
+  return (Errors > 0) ? SHELL_INVALID_PARAMETER : SHELL_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -1379,7 +1390,7 @@ ShellCommandRunBcfg (
             Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
             CurrentOperation.Number1     = (UINT16)Intermediate;\r
             if (CurrentOperation.Number1 >= Count){\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), L"bcfg", gShellBcfgHiiHandle, Count);  \r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count);  \r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r