aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/ipxe/efi/efi_path.h2
-rw-r--r--src/interface/efi/efi_path.c43
2 files changed, 45 insertions, 0 deletions
diff --git a/src/include/ipxe/efi/efi_path.h b/src/include/ipxe/efi/efi_path.h
index c1d53e7..f52410e 100644
--- a/src/include/ipxe/efi/efi_path.h
+++ b/src/include/ipxe/efi/efi_path.h
@@ -13,11 +13,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DevicePath.h>
+struct uri;
struct usb_function;
extern EFI_DEVICE_PATH_PROTOCOL *
efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri );
extern EFI_DEVICE_PATH_PROTOCOL * efi_usb_path ( struct usb_function *func );
extern EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *interface );
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
index 162400a..6201c02 100644
--- a/src/interface/efi/efi_path.c
+++ b/src/interface/efi/efi_path.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
+#include <ipxe/uri.h>
#include <ipxe/usb.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
@@ -61,6 +62,48 @@ size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
}
/**
+ * Construct EFI device path for URI
+ *
+ * @v uri URI
+ * @ret path EFI device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri ) {
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ URI_DEVICE_PATH *uripath;
+ size_t uri_len;
+ size_t uripath_len;
+ size_t len;
+
+ /* Calculate device path length */
+ uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
+ uripath_len = ( sizeof ( *uripath ) + uri_len );
+ len = ( uripath_len + sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ uripath = ( ( void * ) path );
+ uripath->Header.Type = MESSAGING_DEVICE_PATH;
+ uripath->Header.SubType = MSG_URI_DP;
+ uripath->Header.Length[0] = ( uripath_len & 0xff );
+ uripath->Header.Length[1] = ( uripath_len >> 8 );
+ format_uri ( uri, uripath->Uri, uri_len );
+ end = ( ( ( void * ) path ) + uripath_len );
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ return path;
+}
+
+/**
* Construct EFI device path for USB function
*
* @v func USB function