mirror of https://github.com/ipxe/ipxe.git
[efi] Split device path functions out to efi_path.c
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/171/head
parent
bcf858c56d
commit
2bf0fd39ca
|
@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <assert.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_driver.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/Protocol/UsbIo.h>
|
||||
#include <ipxe/usb.h>
|
||||
|
@ -206,7 +207,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
|
|||
path = usbio->path;
|
||||
usbpath = usbio->usbpath;
|
||||
usbpath->InterfaceNumber = interface;
|
||||
end = efi_devpath_end ( path );
|
||||
end = efi_path_end ( path );
|
||||
|
||||
/* Locate handle for this endpoint's interface */
|
||||
if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path,
|
||||
|
@ -1503,7 +1504,7 @@ static int usbio_path ( struct usbio_device *usbio ) {
|
|||
path = u.interface;
|
||||
|
||||
/* Locate end of device path and sanity check */
|
||||
len = efi_devpath_len ( path );
|
||||
len = efi_path_len ( path );
|
||||
if ( len < sizeof ( *usbpath ) ) {
|
||||
DBGC ( usbio, "USBIO %s underlength device path\n",
|
||||
efi_handle_name ( handle ) );
|
||||
|
|
|
@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||
#include <ipxe/efi/efi_snp.h>
|
||||
#include <ipxe/efi/efi_download.h>
|
||||
#include <ipxe/efi/efi_file.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_wrap.h>
|
||||
#include <ipxe/efi/efi_pxe.h>
|
||||
|
@ -75,7 +75,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) {
|
|||
size_t len;
|
||||
|
||||
/* Calculate device path lengths */
|
||||
prefix_len = efi_devpath_len ( parent );
|
||||
prefix_len = efi_path_len ( parent );
|
||||
name_len = strlen ( image->name );
|
||||
filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
|
||||
( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _IPXE_EFI_PATH_H
|
||||
#define _IPXE_EFI_PATH_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* EFI device paths
|
||||
*
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/Protocol/DevicePath.h>
|
||||
|
||||
extern EFI_DEVICE_PATH_PROTOCOL *
|
||||
efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
|
||||
extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
|
||||
|
||||
#endif /* _IPXE_EFI_PATH_H */
|
|
@ -9,13 +9,9 @@
|
|||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/Protocol/DevicePath.h>
|
||||
|
||||
struct device;
|
||||
|
||||
extern EFI_DEVICE_PATH_PROTOCOL *
|
||||
efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
|
||||
extern size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path );
|
||||
extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
||||
EFI_HANDLE *parent );
|
||||
extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
|
||||
|
|
|
@ -54,7 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <ipxe/efi/efi_driver.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_snp.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_block.h>
|
||||
|
||||
/** ACPI table protocol protocol */
|
||||
|
@ -288,7 +288,7 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
|
|||
}
|
||||
|
||||
/* Calculate length of private data */
|
||||
prefix_len = efi_devpath_len ( snpdev->path );
|
||||
prefix_len = efi_path_len ( snpdev->path );
|
||||
uri_len = format_uri ( uris[0], NULL, 0 );
|
||||
vendor_len = ( sizeof ( *vendor ) +
|
||||
( ( uri_len + 1 /* NUL */ ) * sizeof ( wchar_t ) ) );
|
||||
|
@ -551,7 +551,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
|
|||
}
|
||||
|
||||
/* Check if this device is a child of our block device */
|
||||
prefix_len = efi_devpath_len ( block->path );
|
||||
prefix_len = efi_path_len ( block->path );
|
||||
if ( memcmp ( path.path, block->path, prefix_len ) != 0 ) {
|
||||
/* Not a child device */
|
||||
rc = -ENOTTY;
|
||||
|
@ -561,7 +561,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
|
|||
sandev->drive, efi_devpath_text ( path.path ) );
|
||||
|
||||
/* Construct device path for boot image */
|
||||
end = efi_devpath_end ( path.path );
|
||||
end = efi_path_end ( path.path );
|
||||
prefix_len = ( ( ( void * ) end ) - ( ( void * ) path.path ) );
|
||||
filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
|
||||
( filename ?
|
||||
|
|
|
@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <ipxe/base16.h>
|
||||
#include <ipxe/vsprintf.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/Protocol/ComponentName.h>
|
||||
#include <ipxe/efi/Protocol/ComponentName2.h>
|
||||
#include <ipxe/efi/Protocol/DevicePathToText.h>
|
||||
|
@ -378,7 +378,7 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
|||
/* If we have no DevicePathToText protocol then use a raw hex string */
|
||||
if ( ! efidpt ) {
|
||||
DBG ( "[No DevicePathToText]" );
|
||||
len = efi_devpath_len ( path );
|
||||
len = efi_path_len ( path );
|
||||
base16_encode ( path, len, text, sizeof ( text ) );
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||
#include <ipxe/efi/Protocol/ComponentName2.h>
|
||||
#include <ipxe/efi/Protocol/DevicePath.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_driver.h>
|
||||
|
||||
/** @file
|
||||
|
@ -202,7 +202,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
|
|||
efi_handle_name ( device ), strerror ( rc ) );
|
||||
goto err_open_path;
|
||||
}
|
||||
path_len = ( efi_devpath_len ( path.path ) + sizeof ( *path_end ) );
|
||||
path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) );
|
||||
|
||||
/* Allocate and initialise structure */
|
||||
efidev = zalloc ( sizeof ( *efidev ) + path_len );
|
||||
|
|
|
@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||
#include <ipxe/rotate.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_driver.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/Protocol/LoadedImage.h>
|
||||
|
||||
/** Image handle passed to entry point */
|
||||
|
@ -252,7 +252,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
|
|||
* path, since the device handle itself may become invalidated
|
||||
* when we load our own drivers.
|
||||
*/
|
||||
device_path_len = ( efi_devpath_len ( device_path ) +
|
||||
device_path_len = ( efi_path_len ( device_path ) +
|
||||
sizeof ( EFI_DEVICE_PATH_PROTOCOL ) );
|
||||
if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, device_path_len,
|
||||
&device_path_copy ) ) != 0 ) {
|
||||
|
|
|
@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <ipxe/process.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
|
||||
#include <ipxe/efi/Guid/FileInfo.h>
|
||||
#include <ipxe/efi/Guid/FileSystemInfo.h>
|
||||
|
@ -425,7 +425,7 @@ static int efi_local_open_resolved ( struct efi_local *local,
|
|||
static int efi_local_open_path ( struct efi_local *local, const char *path ) {
|
||||
FILEPATH_DEVICE_PATH *fp = container_of ( efi_loaded_image->FilePath,
|
||||
FILEPATH_DEVICE_PATH, Header);
|
||||
size_t fp_len = ( fp ? efi_devpath_len ( &fp->Header ) : 0 );
|
||||
size_t fp_len = ( fp ? efi_path_len ( &fp->Header ) : 0 );
|
||||
char base[ fp_len / 2 /* Cannot exceed this length */ ];
|
||||
size_t remaining = sizeof ( base );
|
||||
size_t len;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* EFI device paths
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find end of device path
|
||||
*
|
||||
* @v path Path to device
|
||||
* @ret path_end End of device path
|
||||
*/
|
||||
EFI_DEVICE_PATH_PROTOCOL * efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
||||
|
||||
while ( path->Type != END_DEVICE_PATH_TYPE ) {
|
||||
path = ( ( ( void * ) path ) +
|
||||
/* There's this amazing new-fangled thing known as
|
||||
* a UINT16, but who wants to use one of those? */
|
||||
( ( path->Length[1] << 8 ) | path->Length[0] ) );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find length of device path (excluding terminator)
|
||||
*
|
||||
* @v path Path to device
|
||||
* @ret path_len Length of device path
|
||||
*/
|
||||
size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
||||
EFI_DEVICE_PATH_PROTOCOL *end = efi_path_end ( path );
|
||||
|
||||
return ( ( ( void * ) end ) - ( ( void * ) path ) );
|
||||
}
|
|
@ -33,6 +33,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_driver.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_watchdog.h>
|
||||
#include <ipxe/efi/efi_snp.h>
|
||||
|
@ -1714,7 +1715,7 @@ static int efi_snp_probe ( struct net_device *netdev ) {
|
|||
"%s", netdev->name );
|
||||
|
||||
/* Allocate the new device path */
|
||||
path_prefix_len = efi_devpath_len ( efidev->path );
|
||||
path_prefix_len = efi_path_len ( efidev->path );
|
||||
snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
|
||||
sizeof ( *vlanpath ) + sizeof ( *path_end ) );
|
||||
if ( ! snpdev->path ) {
|
||||
|
|
|
@ -63,6 +63,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <ipxe/efi/efi_hii.h>
|
||||
#include <ipxe/efi/efi_snp.h>
|
||||
#include <ipxe/efi/efi_strings.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <config/branding.h>
|
||||
|
||||
|
@ -680,7 +681,7 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
|
|||
}
|
||||
|
||||
/* Allocate the new device path */
|
||||
path_prefix_len = efi_devpath_len ( snpdev->path );
|
||||
path_prefix_len = efi_path_len ( snpdev->path );
|
||||
snpdev->hii_child_path = zalloc ( path_prefix_len +
|
||||
sizeof ( *vendor_path ) +
|
||||
sizeof ( *path_end ) );
|
||||
|
|
|
@ -30,7 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
#include <ipxe/efi/efi_utils.h>
|
||||
#include <ipxe/efi/efi_path.h>
|
||||
#include <ipxe/efi/efi_driver.h>
|
||||
#include <ipxe/efi/efi_usb.h>
|
||||
#include <ipxe/usb.h>
|
||||
|
@ -1120,7 +1120,7 @@ static int efi_usb_install ( struct efi_usb_device *usbdev,
|
|||
|
||||
/* Calculate device path length */
|
||||
path_count = ( usb_depth ( usbdev->usb ) + 1 );
|
||||
path_prefix_len = efi_devpath_len ( efidev->path );
|
||||
path_prefix_len = efi_path_len ( efidev->path );
|
||||
path_len = ( path_prefix_len + ( path_count * sizeof ( *usbpath ) ) +
|
||||
sizeof ( *path_end ) );
|
||||
|
||||
|
|
|
@ -32,36 +32,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find end of device path
|
||||
*
|
||||
* @v path Path to device
|
||||
* @ret path_end End of device path
|
||||
*/
|
||||
EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
||||
|
||||
while ( path->Type != END_DEVICE_PATH_TYPE ) {
|
||||
path = ( ( ( void * ) path ) +
|
||||
/* There's this amazing new-fangled thing known as
|
||||
* a UINT16, but who wants to use one of those? */
|
||||
( ( path->Length[1] << 8 ) | path->Length[0] ) );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find length of device path (excluding terminator)
|
||||
*
|
||||
* @v path Path to device
|
||||
* @ret path_len Length of device path
|
||||
*/
|
||||
size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
|
||||
EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path );
|
||||
|
||||
return ( ( ( void * ) end ) - ( ( void * ) path ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate parent device supporting a given protocol
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue