[efi] Add efi_path_terminate() utility function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2023-01-23 19:07:35 +00:00
parent fcfb70bfb2
commit 204d39222a
5 changed files with 24 additions and 33 deletions

View File

@@ -96,9 +96,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) {
efi_snprintf ( filepath->PathName, ( name_len + 1 /* NUL */ ), efi_snprintf ( filepath->PathName, ( name_len + 1 /* NUL */ ),
"%s", image->name ); "%s", image->name );
end = ( ( ( void * ) filepath ) + filepath_len ); end = ( ( ( void * ) filepath ) + filepath_len );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
return path; return path;
} }

View File

@@ -21,6 +21,19 @@ struct fcp_description;
struct ib_srp_device; struct ib_srp_device;
struct usb_function; struct usb_function;
/**
* Terminate device path
*
* @v end End of device path to fill in
*/
static inline void efi_path_terminate ( EFI_DEVICE_PATH_PROTOCOL *end ) {
end->Type = END_DEVICE_PATH_TYPE;
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
end->Length[1] = 0;
}
extern EFI_DEVICE_PATH_PROTOCOL * extern EFI_DEVICE_PATH_PROTOCOL *
efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path ); efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path );
extern EFI_DEVICE_PATH_PROTOCOL * extern EFI_DEVICE_PATH_PROTOCOL *

View File

@@ -582,9 +582,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
sizeof ( efi_block_boot_filename ) ); sizeof ( efi_block_boot_filename ) );
} }
end = ( ( ( void * ) filepath ) + filepath_len ); end = ( ( ( void * ) filepath ) + filepath_len );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
DBGC ( sandev, "EFIBLK %#02x trying to load %s\n", DBGC ( sandev, "EFIBLK %#02x trying to load %s\n",
sandev->drive, efi_devpath_text ( boot_path ) ); sandev->drive, efi_devpath_text ( boot_path ) );

View File

@@ -161,9 +161,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_paths ( EFI_DEVICE_PATH_PROTOCOL *first, ... ) {
} }
va_end ( args ); va_end ( args );
end = dst; end = dst;
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
return path; return path;
} }
@@ -223,9 +221,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path ( struct net_device *netdev ) {
} else { } else {
end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) ); end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
} }
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
return path; return path;
} }
@@ -265,9 +261,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri ) {
uripath->Header.Length[1] = ( uripath_len >> 8 ); uripath->Header.Length[1] = ( uripath_len >> 8 );
format_uri ( uri, uripath->Uri, uri_len ); format_uri ( uri, uripath->Uri, uri_len );
end = ( ( ( void * ) path ) + uripath_len ); end = ( ( ( void * ) path ) + uripath_len );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
return path; return path;
} }
@@ -324,9 +318,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_iscsi_path ( struct iscsi_session *iscsi ) {
name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) ); name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) );
memcpy ( name, iscsi->target_iqn, name_len ); memcpy ( name, iscsi->target_iqn, name_len );
end = ( ( ( void * ) name ) + name_len ); end = ( ( ( void * ) name ) + name_len );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
/* Free temporary paths */ /* Free temporary paths */
free ( netpath ); free ( netpath );
@@ -366,9 +358,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_aoe_path ( struct aoe_device *aoedev ) {
satapath.sata.Header.Length[0] = sizeof ( satapath.sata ); satapath.sata.Header.Length[0] = sizeof ( satapath.sata );
satapath.sata.HBAPortNumber = aoedev->major; satapath.sata.HBAPortNumber = aoedev->major;
satapath.sata.PortMultiplierPortNumber = aoedev->minor; satapath.sata.PortMultiplierPortNumber = aoedev->minor;
satapath.end.Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( &satapath.end );
satapath.end.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
satapath.end.Length[0] = sizeof ( satapath.end );
/* Construct overall device path */ /* Construct overall device path */
path = efi_paths ( netpath, &satapath, NULL ); path = efi_paths ( netpath, &satapath, NULL );
@@ -409,9 +399,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_fcp_path ( struct fcp_description *desc ) {
path->fc.Header.Length[0] = sizeof ( path->fc ); path->fc.Header.Length[0] = sizeof ( path->fc );
memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) ); memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) );
memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) ); memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) );
path->end.Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( &path->end );
path->end.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
path->end.Length[0] = sizeof ( path->end );
return &path->fc.Header; return &path->fc.Header;
} }
@@ -463,9 +451,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_ib_srp_path ( struct ib_srp_device *ib_srp ) {
memcpy ( &ibpath->DeviceId, &id->ib.id_ext, memcpy ( &ibpath->DeviceId, &id->ib.id_ext,
sizeof ( ibpath->DeviceId ) ); sizeof ( ibpath->DeviceId ) );
end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) ); end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
return path; return path;
} }
@@ -511,9 +497,7 @@ EFI_DEVICE_PATH_PROTOCOL * efi_usb_path ( struct usb_function *func ) {
/* Construct device path */ /* Construct device path */
memcpy ( path, efidev->path, prefix_len ); memcpy ( path, efidev->path, prefix_len );
end = ( ( ( void * ) path ) + len - sizeof ( *end ) ); end = ( ( ( void * ) path ) + len - sizeof ( *end ) );
end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( end );
end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
end->Length[0] = sizeof ( *end );
usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) ); usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
usbpath->InterfaceNumber = func->interface[0]; usbpath->InterfaceNumber = func->interface[0];
for ( ; usb ; usbpath--, usb = usb->port->hub->usb ) { for ( ; usb ; usbpath--, usb = usb->port->hub->usb ) {

View File

@@ -704,9 +704,7 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
vendor_path->Header.Length[0] = sizeof ( *vendor_path ); vendor_path->Header.Length[0] = sizeof ( *vendor_path );
efi_snp_hii_random_guid ( &vendor_path->Guid ); efi_snp_hii_random_guid ( &vendor_path->Guid );
path_end = ( ( void * ) ( vendor_path + 1 ) ); path_end = ( ( void * ) ( vendor_path + 1 ) );
path_end->Type = END_DEVICE_PATH_TYPE; efi_path_terminate ( path_end );
path_end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
path_end->Length[0] = sizeof ( *path_end );
/* Create device path and child handle for HII association */ /* Create device path and child handle for HII association */
if ( ( efirc = bs->InstallMultipleProtocolInterfaces ( if ( ( efirc = bs->InstallMultipleProtocolInterfaces (