]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BdsHelper.c
ArmPlatformPkg: Minor code changes (comments, misspellings, coding stylei, line endings)
[mirror_edk2.git] / ArmPlatformPkg / Bds / BdsHelper.c
index 0a6961183aff1e17ec4494117ef51dad9215a5f4..28d02c6620d6ea23521d237c64202f06b791e02f 100644 (file)
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2011, ARM Limited. All rights reserved.
+*  Copyright (c) 2011-2012, 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         
 
 #include "BdsInternal.h"
 
-EFI_STATUS
-GetEnvironmentVariable (
-  IN     CONST CHAR16*   VariableName,
-  IN     VOID*           DefaultValue,
-  IN OUT UINTN*          Size,
-  OUT    VOID**          Value
-  )
-{
-  EFI_STATUS  Status;
-  UINTN       VariableSize;
-
-  // Try to get the variable size.
-  *Value = NULL;
-  VariableSize = 0;
-  Status = gRT->GetVariable ((CHAR16 *) VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
-  if (Status == EFI_NOT_FOUND) {
-    if ((DefaultValue != NULL) && (Size != NULL) && (*Size != 0)) {
-      // If the environment variable does not exist yet then set it with the default value
-      Status = gRT->SetVariable (
-                    (CHAR16*)VariableName,
-                    &gEfiGlobalVariableGuid,
-                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-                    *Size,
-                    DefaultValue
-                    );
-      *Value = DefaultValue;
-    } else {
-      return EFI_NOT_FOUND;
-    }
-  } else if (Status == EFI_BUFFER_TOO_SMALL) {
-    // Get the environment variable value
-    *Value = AllocatePool (VariableSize);
-    if (*Value == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
-    if (EFI_ERROR (Status)) {
-      FreePool(*Value);
-      return EFI_INVALID_PARAMETER;
-    }
-
-    if (Size) {
-      *Size = VariableSize;
-    }
-  } else {
-    *Value = DefaultValue;
-    return Status;
-  }
-
-  return EFI_SUCCESS;
-}
-
 EFI_STATUS
 EditHIInputStr (
   IN OUT CHAR16  *CmdLine,
@@ -146,7 +93,6 @@ EditHIInputAscii (
   AsciiStrToUnicodeStr (CmdLine, Str);
 
   Status = EditHIInputStr (Str, MaxCmdLine);
-
   if (!EFI_ERROR(Status)) {
     UnicodeStrToAsciiStr (Str, CmdLine);
   }
@@ -234,7 +180,7 @@ GetHIInputBoolean (
 
   while(1) {
     Print (L"[y/n] ");
-    Status = GetHIInputStr (CmdBoolean,2);
+    Status = GetHIInputStr (CmdBoolean, 2);
     if (EFI_ERROR(Status)) {
       return Status;
     } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {
@@ -292,7 +238,7 @@ GenerateDeviceDescriptionName (
     //TODO: Fixme. we must find the best langague
     Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);
     if (!EFI_ERROR(Status)) {
-      StrnCpy (Description,DriverName,BOOT_DEVICE_DESCRIPTION_MAX);
+      StrnCpy (Description, DriverName, BOOT_DEVICE_DESCRIPTION_MAX);
     }
   }
 
@@ -307,7 +253,7 @@ GenerateDeviceDescriptionName (
     DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);
     Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
     ASSERT_EFI_ERROR(Status);
-    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathNode,TRUE,TRUE);
+    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathNode, TRUE, TRUE);
     StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);
     FreePool (DevicePathTxt);
   }
@@ -321,17 +267,12 @@ BdsStartBootOption (
   )
 {
   EFI_STATUS          Status;
-  EFI_LOAD_OPTION     EfiLoadOption;
-  UINTN               EfiLoadOptionSize;
   BDS_LOAD_OPTION     *BdsLoadOption;
 
-  Status = GetEnvironmentVariable (BootOption, NULL, &EfiLoadOptionSize, (VOID**)&EfiLoadOption);
+  Status = BootOptionFromLoadOptionVariable (BootOption, &BdsLoadOption);
   if (!EFI_ERROR(Status)) {
-    Status = BootOptionParseLoadOption (EfiLoadOption, EfiLoadOptionSize, &BdsLoadOption);
-    if (!EFI_ERROR(Status)) {
-      Status = BootOptionStart (BdsLoadOption);
-      FreePool (BdsLoadOption);
-    }
+    Status = BootOptionStart (BdsLoadOption);
+    FreePool (BdsLoadOption);
 
     if (!EFI_ERROR(Status)) {
       Status = EFI_SUCCESS;
@@ -343,3 +284,34 @@ BdsStartBootOption (
   }
   return Status;
 }
+
+UINTN
+GetUnalignedDevicePathSize (
+  IN EFI_DEVICE_PATH* DevicePath
+  )
+{
+  UINTN Size;
+  EFI_DEVICE_PATH* AlignedDevicePath;
+
+  if ((UINTN)DevicePath & 0x1) {
+    AlignedDevicePath = DuplicateDevicePath (DevicePath);
+    Size = GetDevicePathSize (AlignedDevicePath);
+    FreePool (AlignedDevicePath);
+  } else {
+    Size = GetDevicePathSize (DevicePath);
+  }
+  return Size;
+}
+
+EFI_DEVICE_PATH*
+GetAlignedDevicePath (
+  IN EFI_DEVICE_PATH* DevicePath
+  )
+{
+  if ((UINTN)DevicePath & 0x1) {
+    return DuplicateDevicePath (DevicePath);
+  } else {
+    return DevicePath;
+  }
+}
+