summaryrefslogtreecommitdiff
path: root/EmbeddedPkg/Ebl/Variable.c
diff options
context:
space:
mode:
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-02-01 05:37:22 +0000
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-02-01 05:37:22 +0000
commitfb334ef6c543b1babc9d8a613ad5d1ce6fe536e1 (patch)
tree50dd2943c02eba26b158b1734d3d0d6d4bf85f36 /EmbeddedPkg/Ebl/Variable.c
parent4c8a6e069c908c65b60ee5b89db6cc3c5981f9a1 (diff)
downloadedk2-platforms-fb334ef6c543b1babc9d8a613ad5d1ce6fe536e1.tar.xz
Fix EBL GetCurrentIpAddress & GetCurrentMacAddress commands. Add variable services commands. Fix arugment parsing in EBL. All fixes from ARM Ltd.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11290 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'EmbeddedPkg/Ebl/Variable.c')
-rw-r--r--EmbeddedPkg/Ebl/Variable.c192
1 files changed, 192 insertions, 0 deletions
diff --git a/EmbeddedPkg/Ebl/Variable.c b/EmbeddedPkg/Ebl/Variable.c
new file mode 100644
index 0000000000..330a143375
--- /dev/null
+++ b/EmbeddedPkg/Ebl/Variable.c
@@ -0,0 +1,192 @@
+/** @file
+*
+* Copyright (c) 2011, ARM Limited. All rights reserved.
+*
+* 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
+* http://opensource.org/licenses/bsd-license.php
+*
+* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include "Ebl.h"
+
+#include <Guid/GlobalVariable.h>
+
+EFI_STATUS
+EblGetCmd (
+ IN UINTN Argc,
+ IN CHAR8 **Argv
+ )
+{
+ EFI_STATUS Status = EFI_INVALID_PARAMETER;
+ UINTN Size;
+ VOID* Value;
+ CHAR8* AsciiVariableName = NULL;
+ CHAR16* VariableName;
+ UINT32 Index;
+
+ if (Argc == 1) {
+ AsciiPrint("Variable name is missing.\n");
+ return Status;
+ }
+
+ for (Index = 1; Index < Argc; Index++) {
+ if (Argv[Index][0] == '-') {
+ AsciiPrint("Warning: '%a' not recognized.\n",Argv[Index]);
+ } else {
+ AsciiVariableName = Argv[Index];
+ }
+ }
+
+ if (AsciiVariableName == NULL) {
+ AsciiPrint("Variable name is missing.\n");
+ return Status;
+ } else {
+ VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16));
+ AsciiStrToUnicodeStr (AsciiVariableName,VariableName);
+ }
+
+ // Try to get the variable size.
+ Value = NULL;
+ Size = 0;
+ Status = gRT->GetVariable (VariableName, &gEfiGlobalVariableGuid, NULL, &Size, Value);
+ if (Status == EFI_NOT_FOUND) {
+ AsciiPrint("Variable name '%a' not found.\n",VariableName);
+ } else if (Status == EFI_BUFFER_TOO_SMALL) {
+ // Get the environment variable value
+ Value = AllocatePool (Size);
+ if (Value == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &Size, Value);
+ if (EFI_ERROR (Status)) {
+ AsciiPrint("Error: '%r'\n",Status);
+ } else {
+ AsciiPrint("%a=%a\n",AsciiVariableName,Value);
+ }
+ FreePool(Value);
+ } else {
+ AsciiPrint("Error: '%r'\n",Status);
+ }
+
+ FreePool(VariableName);
+ return Status;
+}
+
+EFI_STATUS
+EblSetCmd (
+ IN UINTN Argc,
+ IN CHAR8 **Argv
+ )
+{
+ EFI_STATUS Status = EFI_INVALID_PARAMETER;
+ CHAR8* AsciiVariableSetting = NULL;
+ CHAR8* AsciiVariableName;
+ CHAR8* AsciiValue;
+ UINT32 AsciiValueLength;
+ CHAR16* VariableName;
+ UINT32 Index;
+ UINT32 EscapedQuotes = 0;
+ BOOLEAN Volatile = FALSE;
+
+ if (Argc == 1) {
+ AsciiPrint("Variable name is missing.\n");
+ return Status;
+ }
+
+ for (Index = 1; Index < Argc; Index++) {
+ if (AsciiStrCmp(Argv[Index],"-v") == 0) {
+ Volatile = 0;
+ } else if (Argv[Index][0] == '-') {
+ AsciiPrint("Warning: '%a' not recognized.\n",Argv[Index]);
+ } else {
+ AsciiVariableSetting = Argv[Index];
+ }
+ }
+
+ if (AsciiVariableSetting == NULL) {
+ AsciiPrint("Variable name is missing.\n");
+ return Status;
+ }
+
+ // Check if it is a valid variable setting
+ AsciiValue = AsciiStrStr (AsciiVariableSetting,"=");
+ if (AsciiValue == NULL) {
+ AsciiPrint("Variable setting is incorrect. It should be VariableName=Value\n");
+ return Status;
+ }
+
+ AsciiValue[0] = '\0';
+ AsciiVariableName = AsciiVariableSetting;
+ AsciiValue++;
+
+ // Clean AsciiValue from quote
+ if (AsciiValue[0] == '"') {
+ AsciiValue++;
+ }
+ AsciiValueLength = AsciiStrLen (AsciiValue);
+ if ((AsciiValue[AsciiValueLength-2] != '\\') && (AsciiValue[AsciiValueLength-1] == '"')) {
+ AsciiValue[AsciiValueLength-1] = '\0';
+ }
+
+ // Clean AsciiValue from escaped quotes
+ for (Index = 0; Index < AsciiValueLength; Index++) {
+ if ((Index > 0) && (AsciiValue[Index-1] == '\\') && (AsciiValue[Index] == '"')) {
+ EscapedQuotes++;
+ }
+ AsciiValue[Index-EscapedQuotes] = AsciiValue[Index];
+ }
+ // Fill the end of the value with '\0'
+ for (Index = 0; Index < EscapedQuotes; Index++) {
+ AsciiValue[AsciiValueLength-1-Index] = '\0';
+ }
+
+ // Convert VariableName into Unicode
+ VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16));
+ AsciiStrToUnicodeStr (AsciiVariableName,VariableName);
+
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ AsciiStrLen (AsciiValue)+1,
+ AsciiValue
+ );
+
+ AsciiPrint("'%a'='%a'\n",AsciiVariableName,AsciiValue);
+
+ return Status;
+}
+
+GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdVariableTemplate[] =
+{
+ {
+ "get",
+ " ; get UEFI variable\n\r [v]; verbose",
+ NULL,
+ EblGetCmd
+ },
+ {
+ "set",
+ " ; set UEFI variable\n\r [v]; create volatile variable",
+ NULL,
+ EblSetCmd
+ }
+};
+
+/**
+ Initialize the commands in this in this file
+**/
+VOID
+EblInitializeVariableCmds (
+ VOID
+ )
+{
+ EblAddCommands (mCmdVariableTemplate, sizeof (mCmdVariableTemplate)/sizeof (EBL_COMMAND_TABLE));
+}