]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
ShellPkg: Use the new library for "bcfg" command
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SetVar.c
index afccf7bd5821aa0a7740ae73225e5fb87387a1c5..9e57998ff85f797be72b4caed6e7ee3bff24cc2d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for SetVar shell Debug1 function.\r
 \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2013, 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
@@ -49,7 +49,6 @@ ShellCommandRunSetVar (
   UINTN               Size;\r
   UINTN               LoopVar;\r
   EFI_DEVICE_PATH_PROTOCOL           *DevPath;\r
-  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *DevPathFromText;\r
 \r
   ShellStatus         = SHELL_SUCCESS;\r
   Status              = EFI_SUCCESS;\r
@@ -140,7 +139,8 @@ ShellCommandRunSetVar (
           Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;\r
         }\r
         if (ShellCommandLineGetFlag(Package, L"-rt")) {\r
-          Attributes |= EFI_VARIABLE_RUNTIME_ACCESS;\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
@@ -177,7 +177,9 @@ ShellCommandRunSetVar (
           if (Status == EFI_BUFFER_TOO_SMALL) {\r
             Buffer = AllocateZeroPool(Size);\r
             Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);\r
-            FreePool(Buffer);\r
+            if (Buffer != NULL) {\r
+              FreePool(Buffer);\r
+            }\r
             Attributes = Attributes2;\r
           }          \r
           //\r
@@ -205,15 +207,20 @@ ShellCommandRunSetVar (
           Data++;\r
           Data++;\r
           Buffer = AllocateZeroPool(StrSize(Data));\r
-          UnicodeSPrint(Buffer, StrSize(Data), L"%s", Data);\r
-          ((CHAR16*)Buffer)[StrLen(Buffer)-1] = CHAR_NULL;\r
-\r
-          Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrSize(Buffer)-sizeof(CHAR16), Buffer);\r
-          if (EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
-            ShellStatus = SHELL_ACCESS_DENIED;\r
+          if (Buffer == NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
+            ShellStatus = SHELL_OUT_OF_RESOURCES;\r
           } else {\r
-            ASSERT(ShellStatus == SHELL_SUCCESS);\r
+            UnicodeSPrint(Buffer, StrSize(Data), L"%s", Data);\r
+            ((CHAR16*)Buffer)[StrLen(Buffer)-1] = CHAR_NULL;\r
+\r
+            Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrSize(Buffer)-sizeof(CHAR16), Buffer);\r
+            if (EFI_ERROR(Status)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
+              ShellStatus = SHELL_ACCESS_DENIED;\r
+            } else {\r
+              ASSERT(ShellStatus == SHELL_SUCCESS);\r
+            }\r
           }\r
         } else if (StrnCmp(Data, L"--", 2) == 0) {\r
           //\r
@@ -221,9 +228,7 @@ ShellCommandRunSetVar (
           //\r
           Data++;\r
           Data++;\r
-          Status = gBS->LocateProtocol(&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID**)&DevPathFromText);\r
-          ASSERT_EFI_ERROR(Status);\r
-          DevPath = DevPathFromText->ConvertTextToDevicePath(Data);\r
+          DevPath = ConvertTextToDevicePath(Data);\r
           if (DevPath == NULL) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_DPFT), gShellDebug1HiiHandle, Status);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r