Sync patches r15544 and r15545 from main trunk.
1. Remove the assertion which may cause IsDevicePathValid() hang in DEBUG build.
2. Remove the RT attribute for HDDP variable and validate the variable content before using it.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/branches/UDK2014@15688 6f19259b-4bc3-4df7-8a09-765794883524
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
index 1348332..db7a750 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
@@ -2526,11 +2526,28 @@
   // If exist, search the front path which point to partition node in the variable instants.

   // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system

   //

-  CachedDevicePath = BdsLibGetVariableAndSize (

-                      HD_BOOT_DEVICE_PATH_VARIABLE_NAME,

-                      &gHdBootDevicePathVariablGuid,

-                      &CachedDevicePathSize

-                      );

+  GetVariable2 (

+    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,

+    &gHdBootDevicePathVariablGuid,

+    (VOID **) &CachedDevicePath,

+    &CachedDevicePathSize

+    );

+

+  //

+  // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.

+  //

+  if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {

+    FreePool (CachedDevicePath);

+    CachedDevicePath = NULL;

+    Status = gRT->SetVariable (

+                    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,

+                    &gHdBootDevicePathVariablGuid,

+                    0,

+                    0,

+                    NULL

+                    );

+    ASSERT_EFI_ERROR (Status);

+  }

 

   if (CachedDevicePath != NULL) {

     TempNewDevicePath = CachedDevicePath;

@@ -2593,7 +2610,7 @@
         Status = gRT->SetVariable (

                         HD_BOOT_DEVICE_PATH_VARIABLE_NAME,

                         &gHdBootDevicePathVariablGuid,

-                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,

+                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,

                         GetDevicePathSize (CachedDevicePath),

                         CachedDevicePath

                         );

@@ -2692,7 +2709,7 @@
       Status = gRT->SetVariable (

                       HD_BOOT_DEVICE_PATH_VARIABLE_NAME,

                       &gHdBootDevicePathVariablGuid,

-                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,

+                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,

                       GetDevicePathSize (CachedDevicePath),

                       CachedDevicePath

                       );

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
index b48bf02..7f21a60 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
@@ -8,7 +8,7 @@
   environment varibles. Multi-instance device paths should never be placed

   on a Handle.

 

-  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>

+  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>

   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        

@@ -153,12 +153,8 @@
   IN CONST VOID  *Node

   )

 {

-  UINTN Length;

-

   ASSERT (Node != NULL);

-  Length = ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);

-  ASSERT (Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL));

-  return Length;

+  return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);

 }

 

 /**