ArmPkg/BdsLib: Fix DHCP4 configuration
Fix DHCP4 configuration as part of TFTP boot process to get the IP address of the gateway and the subnet mask from the DHCP server. Fix a memory leak when the download from the TFTP server fails as well. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron <Ronald.Cron@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16582 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
901b45162a
commit
f88a751a07
|
@ -24,8 +24,20 @@
|
||||||
#include <Protocol/Dhcp4.h>
|
#include <Protocol/Dhcp4.h>
|
||||||
#include <Protocol/Mtftp4.h>
|
#include <Protocol/Mtftp4.h>
|
||||||
|
|
||||||
|
|
||||||
#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))
|
#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))
|
||||||
|
|
||||||
|
/* Type and defines to set up the DHCP4 options */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
EFI_DHCP4_PACKET_OPTION Head;
|
||||||
|
UINT8 Route;
|
||||||
|
} DHCP4_OPTION;
|
||||||
|
|
||||||
|
#define DHCP_TAG_PARA_LIST 55
|
||||||
|
#define DHCP_TAG_NETMASK 1
|
||||||
|
#define DHCP_TAG_ROUTER 3
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Constant strings and define related to the message indicating the amount of
|
Constant strings and define related to the message indicating the amount of
|
||||||
progress in the dowloading of a TFTP file.
|
progress in the dowloading of a TFTP file.
|
||||||
|
@ -998,22 +1010,24 @@ BdsTftpLoadImage (
|
||||||
OUT UINTN *ImageSize
|
OUT UINTN *ImageSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_HANDLE Dhcp4ChildHandle;
|
EFI_HANDLE Dhcp4ChildHandle;
|
||||||
EFI_DHCP4_PROTOCOL *Dhcp4;
|
EFI_DHCP4_PROTOCOL *Dhcp4;
|
||||||
BOOLEAN Dhcp4ToStop;
|
BOOLEAN Dhcp4ToStop;
|
||||||
EFI_HANDLE Mtftp4ChildHandle;
|
EFI_HANDLE Mtftp4ChildHandle;
|
||||||
EFI_MTFTP4_PROTOCOL *Mtftp4;
|
EFI_MTFTP4_PROTOCOL *Mtftp4;
|
||||||
EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;
|
DHCP4_OPTION ParaList;
|
||||||
EFI_DHCP4_MODE_DATA Dhcp4Mode;
|
EFI_DHCP4_PACKET_OPTION *OptionList[2];
|
||||||
EFI_MTFTP4_CONFIG_DATA Mtftp4CfgData;
|
EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;
|
||||||
IPv4_DEVICE_PATH *IPv4DevicePathNode;
|
EFI_DHCP4_MODE_DATA Dhcp4Mode;
|
||||||
FILEPATH_DEVICE_PATH *FilePathDevicePathNode;
|
EFI_MTFTP4_CONFIG_DATA Mtftp4CfgData;
|
||||||
CHAR8 *AsciiFilePath;
|
IPv4_DEVICE_PATH *IPv4DevicePathNode;
|
||||||
EFI_MTFTP4_TOKEN Mtftp4Token;
|
FILEPATH_DEVICE_PATH *FilePathDevicePathNode;
|
||||||
UINT64 FileSize;
|
CHAR8 *AsciiFilePath;
|
||||||
UINT64 TftpBufferSize;
|
EFI_MTFTP4_TOKEN Mtftp4Token;
|
||||||
BDS_TFTP_CONTEXT *TftpContext;
|
UINT64 FileSize;
|
||||||
|
UINT64 TftpBufferSize;
|
||||||
|
BDS_TFTP_CONTEXT *TftpContext;
|
||||||
|
|
||||||
ASSERT(IS_DEVICE_PATH_NODE (RemainingDevicePath, MESSAGING_DEVICE_PATH, MSG_IPv4_DP));
|
ASSERT(IS_DEVICE_PATH_NODE (RemainingDevicePath, MESSAGING_DEVICE_PATH, MSG_IPv4_DP));
|
||||||
IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;
|
IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;
|
||||||
|
@ -1086,6 +1100,14 @@ BdsTftpLoadImage (
|
||||||
// process has been started but is not completed yet.
|
// process has been started but is not completed yet.
|
||||||
//
|
//
|
||||||
ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
|
ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
|
||||||
|
ParaList.Head.OpCode = DHCP_TAG_PARA_LIST;
|
||||||
|
ParaList.Head.Length = 2;
|
||||||
|
ParaList.Head.Data[0] = DHCP_TAG_NETMASK;
|
||||||
|
ParaList.Route = DHCP_TAG_ROUTER;
|
||||||
|
OptionList[0] = &ParaList.Head;
|
||||||
|
Dhcp4CfgData.OptionCount = 1;
|
||||||
|
Dhcp4CfgData.OptionList = OptionList;
|
||||||
|
|
||||||
Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
|
Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
if (Status != EFI_ACCESS_DENIED) {
|
if (Status != EFI_ACCESS_DENIED) {
|
||||||
|
@ -1207,9 +1229,9 @@ BdsTftpLoadImage (
|
||||||
Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);
|
Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);
|
||||||
Print (L"\n");
|
Print (L"\n");
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
Print (L"Downloading failed, file larger than expected.\n");
|
Print (L"Downloading failed, file larger than expected.\n");
|
||||||
gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
Loading…
Reference in New Issue