/** @file
Boot functions implementation for UefiPxeBc Driver.
Copyright (c) 2009 - 2011, 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
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 "PxeBcImpl.h"
/**
Display the string of the boot item.
If the length of the boot item string beyond 70 Char, just display 70 Char.
@param[in] Str The pointer to the string.
@param[in] Len The length of the string.
**/
)
{
//
// Cut off the chars behind 70th.
//
//
// Restore the original 70th char.
//
}
/**
Select and maintain the boot prompt if needed.
@param[in] Private Pointer to PxeBc private data.
@retval EFI_SUCCESS Selected boot prompt done.
@retval EFI_TIMEOUT Selected boot prompt timed out.
@retval EFI_NOT_FOUND The proxy offer is not Pxe10.
@retval EFI_ABORTED User cancelled the operation.
@retval EFI_NOT_READY Reading the input key from the keyboard has not finish.
**/
)
{
TimeoutEvent = NULL;
DescendEvent = NULL;
//
// Only ProxyPxe10 offer needs boot prompt.
//
if (OfferType != PxeOfferTypeProxyPxe10) {
return EFI_NOT_FOUND;
}
//
// There is no specified ProxyPxe10 for IPv6 in PXE and UEFI spec.
//
return EFI_SUCCESS;
}
//
// The valid scope of Timeout refers to PXE2.1 spec.
//
if (Timeout == 0) {
return EFI_SUCCESS;
}
if (Timeout == 255) {
return EFI_TIMEOUT;
}
//
// Create and start a timer as timeout event.
//
NULL,
NULL,
);
return Status;
}
);
goto ON_EXIT;
}
//
// Create and start a periodic timer as descend event by second.
//
NULL,
NULL,
);
goto ON_EXIT;
}
);
goto ON_EXIT;
}
//
// Display the boot item and cursor on the screen.
//
}
continue;
}
//
// Parse the input key by user.
//
switch (InputKey.UnicodeChar) {
case CTRL ('c'):
break;
case CTRL ('m'):
case 'm':
case 'M':
break;
default:
continue;
}
} else {
case SCAN_F8:
break;
case SCAN_ESC:
break;
default:
continue;
}
}
break;
}
//
// Reset the cursor on the screen.
//
if (DescendEvent != NULL) {
}
if (TimeoutEvent != NULL) {
}
return Status;
}
/**
Select the boot menu by user's input.
@param[in] Private Pointer to PxeBc private data.
@param[out] Type The type of the menu.
@param[in] UseDefaultItem Use default item or not.
@retval EFI_ABORTED User cancel operation.
@retval EFI_SUCCESS Select the boot menu success.
@retval EFI_NOT_READY Read the input key from the keybroad has not finish.
**/
)
{
Select = 1;
Index = 0;
*Type = 0;
//
// There is no specified ProxyPxe10 for IPv6 in PXE and UEFI spec.
//
return EFI_SUCCESS;
}
//
// Display the boot menu on the screen.
//
if (MenuSize == 0) {
return EFI_DEVICE_ERROR;
}
Index++;
}
if (UseDefaultItem) {
return EFI_SUCCESS;
}
}
//
// Select the boot item by user in the boot menu.
//
do {
//
// Highlight selected row.
//
LastSelect = Select;
}
switch (InputKey.UnicodeChar) {
case CTRL ('c'):
break;
break;
case ' ':
case 'd':
case 'D':
break;
case 'u':
case 'U':
break;
default:
}
}
case SCAN_LEFT:
case SCAN_UP:
if (Select != 0) {
Select--;
}
break;
case SCAN_DOWN:
case SCAN_RIGHT:
Select--;
}
break;
case SCAN_PAGE_UP:
case SCAN_HOME:
Select = 0;
break;
case SCAN_PAGE_DOWN:
case SCAN_END:
break;
case SCAN_ESC:
return EFI_ABORTED;
}
//
// Unhighlight the last selected row.
//
} while (!Finish);
//
// Swap the byte order.
//
return EFI_SUCCESS;
}
/**
Parse out the boot information from the last Dhcp4 reply packet.
@param[in, out] Private Pointer to PxeBc private data.
@param[out] BufferSize Size of the boot file to be downloaded.
@retval EFI_SUCCESS Successfully parsed out all the boot information.
@retval Others Failed to parse out the boot information.
**/
)
{
*BufferSize = 0;
//
// Get the last received Dhcp4 reply packet.
//
if (Mode->PxeReplyReceived) {
} else if (Mode->ProxyOfferReceived) {
} else {
}
//
// Parse the boot server Ipv4 address by next server address.
// If this field isn't available, use option 54 instead.
//
CopyMem (
sizeof (EFI_IPv4_ADDRESS)
);
CopyMem (
sizeof (EFI_IPv4_ADDRESS)
);
}
//
// Parse the boot file name by option.
//
//
// Parse the boot file size by option.
//
//
// The field of boot file size is 512 bytes in unit.
//
} else {
//
// Get the bootfile size by tftp command if no option available.
//
NULL,
NULL,
);
}
//
// Save the value of boot file size.
//
//
// Display all the information: boot server address, boot file name and boot file size.
//
AsciiPrint ("\n Server IP address is ");
return Status;
}
/**
Parse out the boot information from the last Dhcp6 reply packet.
@param[in, out] Private Pointer to PxeBc private data.
@param[out] BufferSize Size of the boot file to be downloaded.
@retval EFI_SUCCESS Successfully parsed out all the boot information.
@retval EFI_BUFFER_TOO_SMALL
@retval Others Failed to parse out the boot information.
**/
)
{
*BufferSize = 0;
//
// Get the last received Dhcp6 reply packet.
//
if (Mode->PxeReplyReceived) {
} else if (Mode->ProxyOfferReceived) {
} else {
}
//
// Parse (m)tftp server ip address and bootfile name.
//
);
return Status;
}
//
// Parse the value of boot file size.
//
//
// Parse it out if have the boot file parameter option.
//
Status = PxeBcExtractBootFileParam ((CHAR8 *) Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM]->Data, &Value);
return Status;
}
//
// The field of boot file size is 512 bytes in unit.
//
} else {
//
// Send get file size command by tftp if option unavailable.
//
NULL,
NULL,
);
}
//
// Save the value of boot file size.
//
//
// Display all the information: boot server address, boot file name and boot file size.
//
AsciiPrint ("\n Server IP address is ");
return Status;
}
/**
Extract the discover information and boot server entry from the
cached packets if unspecified.
@param[in] Private Pointer to PxeBc private data.
@param[in] Type The type of bootstrap to perform.
@param[in, out] Info Pointer to EFI_PXE_BASE_CODE_DISCOVER_INFO.
@param[out] BootEntry Pointer to PXEBC_BOOT_SVR_ENTRY.
@param[out] SrvList Pointer to EFI_PXE_BASE_CODE_SRVLIST.
@retval EFI_SUCCESS Successfully extracted the information.
@retval EFI_DEVICE_ERROR Failed to extract the information.
**/
)
{
//
// There is no vendor options specified in DHCPv6, so take BootFileUrl in the last cached packet.
//
} else {
//
// Address is not acquired or no discovery options.
//
return EFI_INVALID_PARAMETER;
}
//
// Parse the boot server entry from the vendor option in the last cached packet.
//
//
// Get the multicast discover ip address from vendor option if has.
//
}
if (Info->MustUseList) {
break;
}
}
if (!IsFound) {
return EFI_DEVICE_ERROR;
}
}
}
return EFI_SUCCESS;
}
/**
Build the discover packet and send out for boot server.
@param[in] Private Pointer to PxeBc private data.
@param[in] Type PxeBc option boot item type.
@param[in] Layer Pointer to option boot item layer.
@param[in] UseBis Use BIS or not.
@param[in] DestIp Pointer to the destination address.
@param[in] IpCount The count of the server address.
@param[in] SrvList Pointer to the server address list.
@retval EFI_SUCCESS Successfully discovered boot file.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
@retval EFI_NOT_FOUND Can't get the PXE reply packet.
@retval Others Failed to discover boot file.
**/
)
{
return PxeBcDhcp6Discover (
Type,
);
} else {
return PxeBcDhcp4Discover (
Type,
);
}
}
/**
Discover all the boot information for boot file.
@param[in, out] Private Pointer to PxeBc private data.
@param[out] BufferSize Size of the boot file to be downloaded.
@retval EFI_SUCCESS Successfully obtained all the boot information .
@retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.
@retval EFI_ABORTED User cancel current operation.
@retval Others Failed to parse out the boot information.
**/
)
{
//
// other pxe boot information.
//
return Status;
}
//
// Select a boot server from boot server list.
//
if (Status == EFI_SUCCESS) {
//
// Choose by user's input.
//
} else if (Status == EFI_TIMEOUT) {
//
// Choose by default item.
//
}
if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {
//
// Local boot(PXE bootstrap server) need abort
//
return EFI_ABORTED;
}
//
// Start to discover the boot server to get (m)tftp server ip address, bootfile
// name and bootfile size.
//
return Status;
}
}
//
// Parse the boot information.
//
} else {
}
return Status;
}
/**
Install PxeBaseCodeCallbackProtocol if not installed before.
@param[in, out] Private Pointer to PxeBc private data.
@param[out] NewMakeCallback If TRUE, it is a new callback.
Otherwise, it is not new callback.
@retval EFI_SUCCESS PxeBaseCodeCallbackProtocol installed succesfully.
@retval Others Failed to install PxeBaseCodeCallbackProtocol.
**/
)
{
//
// Check whether PxeBaseCodeCallbackProtocol already installed.
//
);
if (Status == EFI_UNSUPPORTED) {
CopyMem (
sizeof (EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL)
);
//
// Install a default callback if user didn't offer one.
//
);
return Status;
}
}
return EFI_SUCCESS;
}
/**
Uninstall PxeBaseCodeCallbackProtocol.
@param[in] Private Pointer to PxeBc private data.
@param[in] NewMakeCallback If TRUE, it is a new callback.
Otherwise, it is not new callback.
**/
)
{
if (NewMakeCallback) {
);
}
}
/**
Download one of boot file in the list, and it's special for IPv6.
@param[in] Private Pointer to PxeBc private data.
@param[in, out] BufferSize Size of user buffer for input;
required buffer size for output.
@param[in] Buffer Pointer to user buffer.
@retval EFI_SUCCESS Read one of boot file in the list successfully.
@retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.
@retval EFI_NOT_FOUND There is no proper boot file available.
@retval Others Failed to download boot file in the list.
**/
)
{
//
// Try to download the boot file if everything is ready.
//
NULL,
);
} else {
}
return Status;
}
/**
Load boot file into user buffer.
@param[in] Private Pointer to PxeBc private data.
@param[in, out] BufferSize Size of user buffer for input;
required buffer size for output.
@param[in] Buffer Pointer to user buffer.
@retval EFI_SUCCESS Get all the boot information successfully.
@retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.
@retval EFI_ABORTED User cancelled the current operation.
@retval Others Failed to parse out the boot information.
**/
)
{
RequiredSize = 0;
//
// Install pxebc callback protocol if hasn't been installed yet.
//
return Status;
}
if (Private->BootFileSize == 0) {
//
// Discover the boot information about the bootfile if hasn't.
//
goto ON_EXIT;
}
if (PXEBC_IS_SIZE_OVERFLOWED (RequiredSize)) {
//
// It's error if the required buffer size is beyond the system scope.
//
goto ON_EXIT;
} else if (RequiredSize > 0) {
//
// Get the right buffer size of the bootfile required.
//
//
// It's buffer too small if the size of user buffer is smaller than the required.
//
goto ON_EXIT;
}
//
// Try to download another bootfile in list if failed to get the filesize of the last one.
// It's special for the case of IPv6.
//
goto ON_EXIT;
}
//
// It's buffer too small if the size of user buffer is smaller than the required.
//
goto ON_EXIT;
}
//
// Begin to download the bootfile if everything is ready.
//
AsciiPrint ("\n Downloading NBP file...\n");
);
} else {
NULL,
);
}
if (Status == EFI_SUCCESS) {
AsciiPrint ("\n Succeed to download NBP file.\n");
return EFI_SUCCESS;
AsciiPrint ("\n PXE-E05: Buffer size is smaller than the requested file.\n");
} else if (Status == EFI_DEVICE_ERROR) {
AsciiPrint ("\n PXE-E07: Network device error.\n");
} else if (Status == EFI_OUT_OF_RESOURCES) {
AsciiPrint ("\n PXE-E09: Could not allocate I/O buffers.\n");
} else if (Status == EFI_NO_MEDIA) {
AsciiPrint ("\n PXE-E12: Could not detect network connection.\n");
} else if (Status == EFI_NO_RESPONSE) {
AsciiPrint ("\n PXE-E16: No offer received.\n");
} else if (Status == EFI_TIMEOUT) {
AsciiPrint ("\n PXE-E18: Server response timeout.\n");
} else if (Status == EFI_ABORTED) {
AsciiPrint ("\n PXE-E21: Remote boot cancelled.\n");
} else if (Status == EFI_ICMP_ERROR) {
AsciiPrint ("\n PXE-E22: Client received ICMP error from server.\n");
} else if (Status == EFI_TFTP_ERROR) {
AsciiPrint ("\n PXE-E23: Client received TFTP error from server.\n");
} else if (Status == EFI_NOT_FOUND) {
AsciiPrint ("\n PXE-E53: No boot filename received.\n");
} else if (Status != EFI_BUFFER_TOO_SMALL) {
AsciiPrint ("\n PXE-E99: Unexpected network error.\n");
}
return Status;
}