X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmbeddedPkg%2FEbl%2FVariable.c;fp=EmbeddedPkg%2FEbl%2FVariable.c;h=5c00122cdb16e6c5b1611eeea69073c1827bee46;hp=3fd688bee11943eff00bdb34e85d47368ddcb772;hb=a6caee65ac3bba2ac649f20bf1c63f0a87050f17;hpb=70aa21d5d6a91877d26d71ec5c6b7956825d7245 diff --git a/EmbeddedPkg/Ebl/Variable.c b/EmbeddedPkg/Ebl/Variable.c index 3fd688bee1..5c00122cdb 100644 --- a/EmbeddedPkg/Ebl/Variable.c +++ b/EmbeddedPkg/Ebl/Variable.c @@ -1,20 +1,20 @@ -/** @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. -* -**/ +/** @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 + +#include EFI_STATUS EblGetCmd ( @@ -23,55 +23,55 @@ EblGetCmd ( ) { 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 '%s' 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); + 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 '%s' 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); @@ -85,60 +85,60 @@ EblSetCmd ( ) { EFI_STATUS Status = EFI_INVALID_PARAMETER; - CHAR8* AsciiVariableSetting = NULL; - CHAR8* AsciiVariableName; - CHAR8* AsciiValue; - UINT32 AsciiValueLength; - CHAR16* VariableName; + 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 + 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) { - // - // There is no value. It means this variable will be deleted - // - - // Convert VariableName into Unicode - VariableName = AllocatePool((AsciiStrLen (AsciiVariableSetting) + 1) * sizeof (CHAR16)); - AsciiStrToUnicodeStr (AsciiVariableSetting,VariableName); - - Status = gRT->SetVariable ( - VariableName, - &gEfiGlobalVariableGuid, - ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) | - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - 0, - NULL - ); - if (!EFI_ERROR(Status)) { - AsciiPrint("Variable '%s' deleted\n",VariableName); - } else { - AsciiPrint("Variable setting is incorrect. It should be VariableName=Value\n"); - } - return Status; + if (AsciiValue == NULL) { + // + // There is no value. It means this variable will be deleted + // + + // Convert VariableName into Unicode + VariableName = AllocatePool((AsciiStrLen (AsciiVariableSetting) + 1) * sizeof (CHAR16)); + AsciiStrToUnicodeStr (AsciiVariableSetting,VariableName); + + Status = gRT->SetVariable ( + VariableName, + &gEfiGlobalVariableGuid, + ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) | + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + 0, + NULL + ); + if (!EFI_ERROR(Status)) { + AsciiPrint("Variable '%s' deleted\n",VariableName); + } else { + AsciiPrint("Variable setting is incorrect. It should be VariableName=Value\n"); + } + return Status; } AsciiValue[0] = '\0'; @@ -167,20 +167,20 @@ EblSetCmd ( } // Convert VariableName into Unicode - VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16)); + 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 + Status = gRT->SetVariable ( + VariableName, + &gEfiGlobalVariableGuid, + ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) | + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + AsciiStrLen (AsciiValue)+1, + AsciiValue ); if (!EFI_ERROR(Status)) { AsciiPrint("'%a'='%a'\n",AsciiVariableName,AsciiValue); - } + } return Status; }