[edk2] [PATCH v3] MdeModulePkg: Skip registering BootManagerMenu if its FFS is not found

2016-06-30 Thread Sunny Wang
This is a enhancement to support the case when platform firmware doesn’t 
support Boot Manager Menu.
For now, if BootManagerMenu FFS can not be retrieved from FV, BDS core code 
will still register a boot option for it. Then, this non-functional boot option 
will still be booted by user's request (like HotKey or Exit from shell) to 
cause additional boot time and error status code reported. Therefore, it would 
be good to skip BootManagerMenu boot option registration and then return error 
status and Invalid BootOption data for this case so that the BootManagerBoot() 
or other consumers can directly return without doing anything.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h | 10 +++--
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c  | 39 +++
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c  | 46 +++
 3 files changed, 70 insertions(+), 25 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index 0fdb23d..e333ffd 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -418,12 +418,16 @@ EfiBootManagerBoot (
   );
 
 /**
-  Return the Boot Manager Menu.
- 
+  Return the boot option corresponding to the Boot Manager Menu.
+  It may automatically create one if the boot option hasn't been created yet.
+
   @param BootOptionReturn the Boot Manager Menu.
 
   @retval EFI_SUCCESS   The Boot Manager Menu is successfully returned.
-  @retval EFI_NOT_FOUND The Boot Manager Menu is not found.
+  @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.
+  @retval othersReturn status of gRT->SetVariable (). BootOption still 
points
+to the Boot Manager Menu even the Status is not 
EFI_SUCCESS
+and EFI_NOT_FOUND.
 **/
 EFI_STATUS
 EFIAPI
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index d016517..4da401d 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2,7 +2,7 @@
   Library functions which relates with booting.
 
 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 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
@@ -2159,7 +2159,7 @@ EfiBootManagerRefreshAllBootOption (
 }
 
 /**
-  This function is called to create the boot option for the Boot Manager Menu.
+  This function is called to get or create the boot option for the Boot 
Manager Menu.
 
   The Boot Manager Menu is shown after successfully booting a boot option.
   Assume the BootManagerMenuFile is in the same FV as the module links to this 
library.
@@ -2167,8 +2167,10 @@ EfiBootManagerRefreshAllBootOption (
   @param  BootOptionReturn the boot option of the Boot Manager Menu
 
   @retval EFI_SUCCESS   Successfully register the Boot Manager Menu.
-  @retval StatusReturn status of gRT->SetVariable (). BootOption still 
points
-to the Boot Manager Menu even the Status is not 
EFI_SUCCESS.
+  @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.
+  @retval othersReturn status of gRT->SetVariable (). BootOption still 
points
+to the Boot Manager Menu even the Status is not 
EFI_SUCCESS
+and EFI_NOT_FOUND.
 **/
 EFI_STATUS
 BmRegisterBootManagerMenu (
@@ -2181,7 +2183,28 @@ BmRegisterBootManagerMenu (
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
   EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;
   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;
+  VOID   *Data;
+  UINTN  DataSize;
 
+  Data = NULL;
+  Status = GetSectionFromFv (
+ PcdGetPtr (PcdBootManagerMenuFile),
+ EFI_SECTION_PE32,
+ 0,
+ (VOID **) ,
+ 
+ );
+  if (Data != NULL) {
+FreePool (Data);
+  }
+  if (EFI_ERROR (Status)) {
+DEBUG ((EFI_D_WARN, "[Bds]BootManagerMenu FFS section can not be found, 
skip its boot option registration\n"));
+return EFI_NOT_FOUND;
+  }
+
+  //
+  // Get BootManagerMenu application's description from EFI User Interface 
Section.
+  //
   Status = GetSectionFromFv (
  PcdGetPtr (PcdBootManagerMenuFile),
  EFI_SECTION_USER_INTERFACE,
@@ -2237,12 +2260,14 @@ BmRegisterBootManagerMenu (
 /**
   Return the boot option corresponding to the Boot Manager Menu.
   It may automatically create one if th

[edk2] [PATCH v2] MdeModulePkg: Skip registering BootManagerMenu if its FFS is not found

2016-06-27 Thread Sunny Wang
This is a enhancement to support the case when platform firmware doesn’t 
support Boot Manager Menu.
For now, if BootManagerMenu FFS can not be retrieved from FV, BDS core code 
will still register a boot option for it. Then, this non-functional boot option 
will still be booted by user's request (like HotKey or Exit from shell) to 
cause additional boot time and error status code reported. Therefore, it would 
be good to skip BootManagerMenu boot option registration and then return error 
status and Invalid BootOption data for this case so that the BootManagerBoot() 
or other consumers can directly return without doing anything.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  7 ++--
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   | 39 ++
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c |  9 +++--
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c   | 29 +++-
 4 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index 0fdb23d..649af9a 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -418,12 +418,13 @@ EfiBootManagerBoot (
   );
 
 /**
-  Return the Boot Manager Menu.
- 
+  Return the boot option corresponding to the Boot Manager Menu.
+  It may automatically create one if the boot option hasn't been created yet.
+
   @param BootOptionReturn the Boot Manager Menu.
 
   @retval EFI_SUCCESS   The Boot Manager Menu is successfully returned.
-  @retval EFI_NOT_FOUND The Boot Manager Menu is not found.
+  @retval StatusReturn status of either gRT->SetVariable () or 
GetSectionFromFv().
 **/
 EFI_STATUS
 EFIAPI
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index d016517..17e416a 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2,7 +2,7 @@
   Library functions which relates with booting.
 
 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 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
@@ -2159,16 +2159,19 @@ EfiBootManagerRefreshAllBootOption (
 }
 
 /**
-  This function is called to create the boot option for the Boot Manager Menu.
+  This function is called to get or create the boot option for the Boot 
Manager Menu.
 
   The Boot Manager Menu is shown after successfully booting a boot option.
   Assume the BootManagerMenuFile is in the same FV as the module links to this 
library.
 
-  @param  BootOptionReturn the boot option of the Boot Manager Menu
+  @param  BootOptionReturn the boot option of the Boot Manager Menu.
+If BootManagerMenu fails to be set as a Boot 
variables, BootOption
+still points to the Boot Manager Menu.
+If BootManagerMenu FFS section can not be retrieved, 
BootOption will 
+be contain invalid data to prevent other function from 
using it.
 
   @retval EFI_SUCCESS   Successfully register the Boot Manager Menu.
-  @retval StatusReturn status of gRT->SetVariable (). BootOption still 
points
-to the Boot Manager Menu even the Status is not 
EFI_SUCCESS.
+  @retval StatusReturn status of either gRT->SetVariable() or 
GetSectionFromFv().
 **/
 EFI_STATUS
 BmRegisterBootManagerMenu (
@@ -2181,9 +2184,32 @@ BmRegisterBootManagerMenu (
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
   EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;
   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;
+  VOID   *Data;
+  UINTN  DataSize;
 
   Status = GetSectionFromFv (
  PcdGetPtr (PcdBootManagerMenuFile),
+ EFI_SECTION_PE32,
+ 0,
+ (VOID **) ,
+ 
+ );
+  if (Data != NULL) {
+FreePool (Data);
+  }
+  if (EFI_ERROR (Status)) {
+DEBUG ((EFI_D_ERROR, "[Bds]BootManagerMenu FFS section can not be found, 
skip its boot option registeration\n"));
+ZeroMem (BootOption, sizeof (EFI_BOOT_MANAGER_LOAD_OPTION));
+BootOption->OptionNumber = LoadOptionNumberUnassigned;
+BootOption->OptionType   = LoadOptionTypeMax;
+return Status;
+  }
+
+  //
+  // Get BootManagerMenu application's description from EFI User Interface 
Section.
+  //
+  Status = GetSectionFromFv (
+ Pc

[edk2] [PATCH v2] MdeModulePkg/UefiBootManagerLib: Fix for wrong data built into MemoryTypeInformation variable

2016-06-23 Thread Sunny Wang
After booting a large-size ISO RAM disk (HTTP boot option pointing to a ISO 
file) and reboot system, system will possibly run into the following ASSERT 
because the BDS core code doesn't consider the case that Memory page management 
(Page.c) would possibly NOT update current memory usage 
statistics(CurrentMemoryTypeInformation) if system allocates a memory buffer 
with a large number of pages.
ASSERT [DxeCore] u:\MdeModulePkg\Core\Dxe\Gcd\Gcd.c(2273): Length >= 
MinimalMemorySizeNeeded

The BDS code block for skipping counting reserved memory occupied by RAM Disk 
didn't consider the Memory page management's behavior mentioned above, which 
caused that the CurrentMemoryTypeInformation[Index1].NumberOfPages will be 
updated to a "very big value" because RamDiskSizeInPages is bigger than 
CurrentMemoryTypeInformation[Index1].NumberOfPages. For example, NumberOfPages 
is 0x9000 (current use) and RamDiskSizeInPages is 0xC (ISO image size). The 
result will become a very big value 0xFFF49000.

Therefore, we need to add a check to prevent BDS core code updating wrong data 
(very big value) to MemoryTypeInformation variable. This code change is a 
improvement for fixing this issue for most cases. There is still a corner case 
even when the memory bins don't include the RAM disk memory, the memory used by 
all other modules exceeds RamDiskSizeInPages. Ray will send the other patch to 
fix this corner case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
Reviewed-by: Samer El-Haj-Mahmoud <el...@hpe.com>
Reviewed-by: Ruiyu Ni <ruiyu...@intel.com>
Reviewed-by: Star Zeng <star.z...@intel.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index 29c1bfa..93502fe 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -2,6 +2,7 @@
   Misc library functions.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
 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
@@ -231,7 +232,8 @@ BmSetMemoryTypeInformationVariable (
 //
 // Do not count the reserved memory occupied by RAM Disk.
 //
-if (CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) {
+if ((CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) &&
+(CurrentMemoryTypeInformation[Index1].NumberOfPages > ((UINT32) 
RamDiskSizeInPages))) {
   CurrentMemoryTypeInformation[Index1].NumberOfPages -= (UINT32) 
RamDiskSizeInPages;
 }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Skip registering BootManagerMenu if its FFS is not found

2016-06-20 Thread Sunny Wang
This is a enhancement.
For now, if BootManagerMenu FFS can not be found from FV, BDS core code will 
still register a boot option for it. Then, this non-functional boot option will 
still be booted by user's request (like HotKey or Exit from shell) to cause 
additional boot time and error status code reported. Therefore, it would be 
good to return EFI_NOT_FOUND status and NULL BootOption pointer to skip 
registering and booting BootManagerMenu boot option for this case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index d016517..74b2acc 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2,7 +2,7 @@
   Library functions which relates with booting.
 
 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 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
@@ -2164,9 +2164,11 @@ EfiBootManagerRefreshAllBootOption (
   The Boot Manager Menu is shown after successfully booting a boot option.
   Assume the BootManagerMenuFile is in the same FV as the module links to this 
library.
 
-  @param  BootOptionReturn the boot option of the Boot Manager Menu
+  @param  BootOptionReturn the boot option of the Boot Manager Menu. 
Return NULL if
+BootManagerMenu FFS section can not be found.
 
   @retval EFI_SUCCESS   Successfully register the Boot Manager Menu.
+  @retval EFI_NOT_FOUND BootManagerMenu FFS section can not be found.
   @retval StatusReturn status of gRT->SetVariable (). BootOption still 
points
 to the Boot Manager Menu even the Status is not 
EFI_SUCCESS.
 **/
@@ -2190,7 +2192,9 @@ BmRegisterBootManagerMenu (
  
  );
   if (EFI_ERROR (Status)) {
-Description = NULL;
+BootOption = NULL;
+DEBUG ((EFI_D_ERROR, "[Bds]BootManagerMenu FFS section can not be found, 
skip to register BootManagerMenu\n"));
+return EFI_NOT_FOUND;
   }
 
   EfiInitializeFwVolDevicepathNode (, PcdGetPtr 
(PcdBootManagerMenuFile));
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Keep HTTP boot mounted RAM disk

2016-06-20 Thread Sunny Wang
There may be some use cases which need to keep HTTP boot mounted RAM disk 
(downloaded image) after image returns back to save the time for downloading 
the same image again.
Therefore, this code change is to remove BmDestroyRamDisk() function call to 
keep the mounted RAM disk for these cases.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index d016517..2fb612be 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2,7 +2,7 @@
   Library functions which relates with booting.
 
 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 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
@@ -1797,11 +1797,7 @@ EfiBootManagerBoot (
   }
   PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32) OptionNumber);
 
-  //
-  // Destroy the RAM disk
-  //
   if (RamDiskDevicePath != NULL) {
-BmDestroyRamDisk (RamDiskDevicePath);
 FreePool (RamDiskDevicePath);
   }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Fix for wrong data updated into MemoryTypeInformation variable

2016-06-20 Thread Sunny Wang
After booting a large-size ISO RAM disk (HTTP boot option pointing to a ISO 
file) and rebooting the system, system will possibly run into the following 
ASSERT because the BDS core code doesn't consider the case that Memory page 
management (Page.c) would possibly skip updating current memory usage 
statistics (CurrentMemoryTypeInformation) if system allocates a memory buffer 
with a large number of pages. For this case, the problematic BDS code block in 
BmSetMemoryTypeInformationVariable() function will get a 
CurrentMemoryTypeInformation[Index1].NumberOfPages value which is not updated 
with large-size ISO RAM disk usage by Memory page management (it keeps original 
value without RAM disk size. For example, 0x9000) and gets RamDiskSizeInPages 
(ISO RAM disk size) in a big value (For example, 0xC). Then, the result 
will become a very big value (0xFFF49000) to be updated into 
MemoryTypeInformation variable to cause the ASSERT in next boot.

ASSERT [DxeCore] u:\MdeModulePkg\Core\Dxe\Gcd\Gcd.c(2273): Length >= 
MinimalMemorySizeNeeded

For fixing this issue, we need to add a check to the problematic BDS code block 
for checking that NumberOfPages is bigger than RamDiskSizeInPages to prevent 
BDS core code updating wrong data (very big value) to MemoryTypeInformation 
variable in this case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index 29c1bfa..93502fe 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -2,6 +2,7 @@
   Misc library functions.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
 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
@@ -231,7 +232,8 @@ BmSetMemoryTypeInformationVariable (
 //
 // Do not count the reserved memory occupied by RAM Disk.
 //
-if (CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) {
+if ((CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) &&
+(CurrentMemoryTypeInformation[Index1].NumberOfPages > ((UINT32) 
RamDiskSizeInPages))) {
   CurrentMemoryTypeInformation[Index1].NumberOfPages -= (UINT32) 
RamDiskSizeInPages;
 }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] NetworkPkg/HttpBootDxe: Fix for the issue that the HTTP boot option can't be booted more than once

2016-05-04 Thread Sunny Wang
This issue can be reproduced by the following steps:
1. Boot to HTTP boot option and the boot file is a ISO file like Ubuntu PE 
image.
2. Exit from boot option (GRUB) and then back to boot manager menu.
3. Boot to the same HTTP boot option again or a HTTP boot option pointing to 
the same HTTP ISO file. It will fail to boot.
Root cause:
When booting a HTTP boot option, the HTTP boot driver will save the Boot File's 
information in its private data as cache data for skipping the Boot file 
discovery from next time boot. However, the cache data doesn't include 
ImageType data, which would cause HTTP boot driver using the invalid ImageType 
(ImageTypeMax) and then fail to boot the cached boot file. In other words, for 
the second time boot, the HttpBootLoadFile() doesn't update ImageType (it 
returns a valid ImageType), which causes that the HttpBootDxeLoadFile() skips 
to Register a RAM Disk for downloaded HTTP ISO file and then BDS code can't 
find the RAM disk to boot.
Solution:
Save ImageType to private data for next time HTTP boot.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 NetworkPkg/HttpBootDxe/HttpBootDxe.h  | 1 +
 NetworkPkg/HttpBootDxe/HttpBootImpl.c | 6 --
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h 
b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 76b7943..806429c 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
@@ -189,6 +189,7 @@ struct _HTTP_BOOT_PRIVATE_DATA {
   VOID  *BootFileUriParser;
   UINTN BootFileSize;
   BOOLEAN   NoGateway;
+  HTTP_BOOT_IMAGE_TYPE  ImageType;
 
   //
   // URI string extracted from the input FilePath parameter.
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c 
b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index cf643d8..4b850b6 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -2,6 +2,7 @@
   The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.
 
 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials are licensed and made available 
under 
 the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -271,7 +272,7 @@ HttpBootLoadFile (
TRUE,
>BootFileSize,
NULL,
-   ImageType
+   >ImageType
);
 if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
   //
@@ -283,7 +284,7 @@ HttpBootLoadFile (
  FALSE,
  >BootFileSize,
  NULL,
- ImageType
+ >ImageType
  );
   if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
 return Status;
@@ -293,6 +294,7 @@ HttpBootLoadFile (
 
   if (*BufferSize < Private->BootFileSize) {
 *BufferSize = Private->BootFileSize;
+*ImageType = Private->ImageType;
 return EFI_BUFFER_TOO_SMALL;
   }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2] MdeModulePkg: Fix memory leak issues

2015-11-02 Thread Sunny Wang
Fix memory leak issues

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
index 86b4fac..a13917b 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
@@ -2,6 +2,7 @@
   Library functions which contain all the code to connect console device.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -301,6 +302,7 @@ BmUpdateSystemTableConsole (
   EFI_DEVICE_PATH_PROTOCOL*FullDevicePath;
   EFI_DEVICE_PATH_PROTOCOL*VarConsole;
   EFI_DEVICE_PATH_PROTOCOL*Instance;
+  EFI_DEVICE_PATH_PROTOCOL*FullInstance;
   VOID*Interface;
   EFI_HANDLE  NewHandle;
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
@@ -354,11 +356,13 @@ BmUpdateSystemTableConsole (
 //
 // Find console device handle by device path instance
 //
+FullInstance = Instance;
 Status = gBS->LocateDevicePath (
 ConsoleGuid,
 ,
 
 );
+FreePool (FullInstance);
 if (!EFI_ERROR (Status)) {
   //
   // Get the console protocol on this console device handle
@@ -383,6 +387,7 @@ BmUpdateSystemTableConsole (
 TextOut->SetMode (TextOut, 0);
   }
 }
+FreePool (FullDevicePath);
 return TRUE;
   }
 }
@@ -392,6 +397,7 @@ BmUpdateSystemTableConsole (
   //
   // No any available console devcie found.
   //
+  FreePool (FullDevicePath);
   return FALSE;
 }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg: Fix memory leak issues

2015-10-27 Thread Sunny Wang
Fix memory leak issues

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
index 86b4fac..0830166 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c
@@ -2,6 +2,7 @@
   Library functions which contain all the code to connect console device.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -301,6 +302,7 @@ BmUpdateSystemTableConsole (
   EFI_DEVICE_PATH_PROTOCOL*FullDevicePath;
   EFI_DEVICE_PATH_PROTOCOL*VarConsole;
   EFI_DEVICE_PATH_PROTOCOL*Instance;
+  EFI_DEVICE_PATH_PROTOCOL*FullInstance;
   VOID*Interface;
   EFI_HANDLE  NewHandle;
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
@@ -354,6 +356,7 @@ BmUpdateSystemTableConsole (
 //
 // Find console device handle by device path instance
 //
+FullInstance = Instance;
 Status = gBS->LocateDevicePath (
 ConsoleGuid,
 ,
@@ -383,15 +386,18 @@ BmUpdateSystemTableConsole (
 TextOut->SetMode (TextOut, 0);
   }
 }
+FreePool (FullDevicePath);
+FreePool (FullInstance);
 return TRUE;
   }
 }
-
+FreePool (FullInstance);
   } while (Instance != NULL);
 
   //
   // No any available console devcie found.
   //
+  FreePool (FullDevicePath);
   return FALSE;
 }
 
-- 
2.5.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg: Add a BDS platform hook function PlatformBootManagerDefaultBootFail to PlatformBootManagerLib

2015-10-27 Thread Sunny Wang
Add a BDS platform hook function PlatformBootManagerDefaultBootFail to 
PlatformBootManagerLib

Why we need this hook function :
 1) According to UEFI 2.5 Section 3.4.3, the 3rd paragraph, It seems we need to 
have a hook function (PlatformBootManagerDefaultBootFail) for platform firmware 
to do platform action like recovering or setting to a known set of boot options.
 2) This hook function is similar to IntelFrameworkModulePkg's PlatformBdsLib's 
PlatformBdsBootFail function which was used in several platforms in EDK2, so it 
would be helpful for other platforms to change their BDS platform library from 
IntelFrameworkModulePkg's PlatformBdsLib to MdeModulePkg's 
PlatformBootManagerLib in the future.

Where we call/run this hook function:
 1) According to UEFI 2.5 Section 3.1.1, the 5th paragraph, we need to present 
a boot manager menu to the user for the successful boot attempt, so we only 
call PlatformBootManagerDefaultBootFail when booting enumerated boot options 
fails.

Reference:
 1) UEFI 2.5 Section 3.4.3, the 3rd paragraph:
- It is expected that this default boot will load an operating system or a 
maintenance utility. If this is an operating system setup program it is then 
responsible for setting the requisite environment variables for subsequent 
boots. The platform firmware may also decide to recover or set to a known set 
of boot
options.
 2) UEFI 2.5 Section 3.1.1, the 5th paragraph:
- If the boot via Boot returns with a status of EFI_SUCCESS, platform 
firmware supports boot manager menu, and if firmware is configured to boot in 
an interactive mode, the boot manager will stop processing the BootOrder 
variable and present a boot manager menu to the user.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
---
 MdeModulePkg/Include/Library/PlatformBootManagerLib.h  | 15 +++
 .../PlatformBootManagerLibNull/PlatformBootManager.c   | 18 ++
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c   | 18 --
 .../PlatformBootManagerLib/PlatformBootManager.c   | 18 ++
 4 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Include/Library/PlatformBootManagerLib.h 
b/MdeModulePkg/Include/Library/PlatformBootManagerLib.h
index 5274503..974dcc5 100644
--- a/MdeModulePkg/Include/Library/PlatformBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/PlatformBootManagerLib.h
@@ -3,6 +3,7 @@
   instances to support platform-specific behavior.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -59,4 +60,18 @@ PlatformBootManagerWaitCallback (
   UINT16  TimeoutRemain
   );
 
+/**
+  Do the platform specific action after all the boot attempts are failed to 
boot.
+
+  Such as:
+Print specific string
+Show the Boot Manager Menu
+
+**/
+VOID
+EFIAPI
+PlatformBootManagerDefaultBootFail (
+  VOID
+  );
+
 #endif
diff --git 
a/MdeModulePkg/Library/PlatformBootManagerLibNull/PlatformBootManager.c 
b/MdeModulePkg/Library/PlatformBootManagerLibNull/PlatformBootManager.c
index 1390e19..b9e5a71 100644
--- a/MdeModulePkg/Library/PlatformBootManagerLibNull/PlatformBootManager.c
+++ b/MdeModulePkg/Library/PlatformBootManagerLibNull/PlatformBootManager.c
@@ -3,6 +3,7 @@
   by IBV/OEM.
 
 Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -65,3 +66,20 @@ PlatformBootManagerWaitCallback (
 {
   return;
 }
+
+/**
+  Do the platform specific action after all the boot attempts are failed to 
boot.
+
+  Such as:
+Print specific string
+Show the Boot Manager Menu
+
+**/
+VOID
+EFIAPI
+PlatformBootManagerDefaultBootFail (
+  VOID
+  )
+{
+  return;
+}
diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c 
b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
index c889892..729a220 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -5,8 +5,8 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be 
invoked
   to enter BDS phase.
 
-(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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 th

[edk2] [PATCH v2] MdeModulePkg: Make the BmFindLoadOption function public

2015-10-13 Thread Sunny Wang
Make the BmFindLoadOption function public

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Sunny Wang <sunnyw...@hpe.com>
Reviewed-by: Samer El-Haj-Mahmoud <el...@hpe.com>
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  | 22 ++
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   | 10 +-
 .../Library/UefiBootManagerLib/BmLoadOption.c  |  4 +++-
 .../Library/UefiBootManagerLib/InternalBm.h| 22 +-
 4 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index 5538d90..54a6713 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -2,6 +2,7 @@
   Provide Boot Manager related library APIs.
 
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -222,6 +223,27 @@ EfiBootManagerSortLoadOptionVariable (
   IN SORT_COMPARE  CompareFunction
   );
 
+/**
+  Return the index of the load option in the load option array.
+
+  The function consider two load options are equal when the 
+  OptionType, Attributes, Description, FilePath and OptionalData are equal.
+
+  @param KeyPointer to the load option to be found.
+  @param Array  Pointer to the array of load options to be found.
+  @param Count  Number of entries in the Array.
+
+  @retval -1  Key wasn't found in the Array.
+  @retval 0 ~ Count-1 The index of the Key in the Array.
+**/
+INTN
+EFIAPI
+EfiBootManagerFindLoadOption (
+  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,
+  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,
+  IN UINTN  Count
+  );
+
 //
 // Boot Manager hot key library functions.
 //
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 8f14cf6..aef2e7b 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1,8 +1,8 @@
 /** @file
   Library functions which relates with booting.
 
-(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
 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
@@ -206,7 +206,7 @@ BmFindBootOptionInVariable (
   if (OptionNumber == LoadOptionNumberUnassigned) {
 BootOptions = EfiBootManagerGetLoadOptions (, 
LoadOptionTypeBoot);
 
-Index = BmFindLoadOption (OptionToFind, BootOptions, BootOptionCount);
+Index = EfiBootManagerFindLoadOption (OptionToFind, BootOptions, 
BootOptionCount);
 if (Index != -1) {
   OptionNumber = BootOptions[Index].OptionNumber;
 }
@@ -2165,7 +2165,7 @@ EfiBootManagerRefreshAllBootOption (
   // Only check those added by BDS
   // so that the boot options added by end-user or OS installer won't be 
deleted
   //
-  if (BmFindLoadOption ([Index], BootOptions, 
BootOptionCount) == (UINTN) -1) {
+  if (EfiBootManagerFindLoadOption ([Index], BootOptions, 
BootOptionCount) == (UINTN) -1) {
 Status = EfiBootManagerDeleteLoadOptionVariable 
(NvBootOptions[Index].OptionNumber, LoadOptionTypeBoot);
 //
 // Deleting variable with current variable implementation shouldn't 
fail.
@@ -2179,7 +2179,7 @@ EfiBootManagerRefreshAllBootOption (
   // Add new EFI boot options to NV
   //
   for (Index = 0; Index < BootOptionCount; Index++) {
-if (BmFindLoadOption ([Index], NvBootOptions, 
NvBootOptionCount) == (UINTN) -1) {
+if (EfiBootManagerFindLoadOption ([Index], NvBootOptions, 
NvBootOptionCount) == (UINTN) -1) {
   EfiBootManagerAddLoadOptionVariable ([Index], (UINTN) -1);
   //
   // Try best to add the boot options so continue upon failure.
@@ -2260,7 +2260,7 @@ BmRegisterBootManagerMenu (
 UINTN   BootOptionCount;
 
 BootOptions = EfiBootManagerGetLoadOptions (, 
LoadOptionTypeBoot);
-ASSERT (BmFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1);
+ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, 
BootOptionCount) == -1);
 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
 );
 
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
index 6b9690a..07c3376 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoa