]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Update SetVar to use existing attributes for updating existing variables.
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 2 Oct 2014 16:41:28 +0000 (16:41 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 2 Oct 2014 16:41:28 +0000 (16:41 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hp.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16194 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c

index 9e57998ff85f797be72b4caed6e7ee3bff24cc2d..0749826b896111edbe67a38474bbf45744e61e06 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for SetVar shell Debug1 function.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, 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
@@ -44,7 +44,6 @@ ShellCommandRunSetVar (
   EFI_GUID            Guid;\r
   CONST CHAR16        *StringGuid;\r
   UINT32              Attributes;\r
-  UINT32              Attributes2;\r
   VOID                *Buffer;\r
   UINTN               Size;\r
   UINTN               LoopVar;\r
@@ -98,7 +97,7 @@ ShellCommandRunSetVar (
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         }\r
       }\r
-      if (Data == NULL) {\r
+      if (Data == NULL || Data[0] !=  L'=') {\r
         //\r
         // Display what's there\r
         //\r
@@ -129,22 +128,43 @@ ShellCommandRunSetVar (
           ASSERT(ShellStatus == SHELL_SUCCESS);\r
         }\r
       } else {\r
-        if (Data[0] == L'=') {\r
-          Data++;\r
-        }\r
         //\r
-        // Change what's there\r
+        // Change what's there or create a new one.\r
         //\r
-        if (ShellCommandLineGetFlag(Package, L"-bs")) {\r
-          Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;\r
-        }\r
-        if (ShellCommandLineGetFlag(Package, L"-rt")) {\r
-          Attributes |= EFI_VARIABLE_RUNTIME_ACCESS |\r
-                        EFI_VARIABLE_BOOTSERVICE_ACCESS;\r
+\r
+        ASSERT(Data[0] == L'=');\r
+        Data++;\r
+\r
+        //\r
+        // Determine if the variable exists and get the attributes\r
+        //\r
+        Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer);\r
+        if (Status == EFI_BUFFER_TOO_SMALL) {\r
+          Buffer = AllocateZeroPool(Size);\r
+          Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer);\r
         }\r
-        if (ShellCommandLineGetFlag(Package, L"-nv")) {\r
-          Attributes |= EFI_VARIABLE_NON_VOLATILE;\r
+\r
+        if (EFI_ERROR(Status) || Buffer == NULL) {\r
+          //\r
+          // Creating a new variable.  determine attributes from command line.\r
+          //\r
+          Attributes = 0;\r
+          if (ShellCommandLineGetFlag(Package, L"-bs")) {\r
+            Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;\r
+          }\r
+          if (ShellCommandLineGetFlag(Package, L"-rt")) {\r
+            Attributes |= EFI_VARIABLE_RUNTIME_ACCESS |\r
+                          EFI_VARIABLE_BOOTSERVICE_ACCESS;\r
+          }\r
+          if (ShellCommandLineGetFlag(Package, L"-nv")) {\r
+            Attributes |= EFI_VARIABLE_NON_VOLATILE;\r
+          }\r
         }\r
+        SHELL_FREE_NON_NULL(Buffer);\r
+\r
+        //\r
+        // What type is the new data.\r
+        //\r
         if (ShellIsHexOrDecimalNumber(Data, TRUE, FALSE)) {\r
           if (StrLen(Data) % 2 != 0) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, Data);\r
@@ -171,17 +191,6 @@ ShellCommandRunSetVar (
             }\r
           }\r
         } else if (StrnCmp(Data, L"\"", 1) == 0) {\r
-          Size = 0;\r
-          Attributes2 = 0;\r
-          Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);\r
-          if (Status == EFI_BUFFER_TOO_SMALL) {\r
-            Buffer = AllocateZeroPool(Size);\r
-            Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);\r
-            if (Buffer != NULL) {\r
-              FreePool(Buffer);\r
-            }\r
-            Attributes = Attributes2;\r
-          }          \r
           //\r
           // ascii text\r
           //\r