summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_path.c
diff options
context:
space:
mode:
authorMichael Brown2020-10-16 16:09:15 +0200
committerMichael Brown2020-10-19 14:07:40 +0200
commitf2c826179aa03951c7da39211fc5754aa571d019 (patch)
tree05332c410cbd31d4df782d4c27c93e080035cade /src/interface/efi/efi_path.c
parent[usbblk] Allow USB block device to be described using an EFI device path (diff)
downloadipxe-f2c826179aa03951c7da39211fc5754aa571d019.tar.gz
ipxe-f2c826179aa03951c7da39211fc5754aa571d019.tar.xz
ipxe-f2c826179aa03951c7da39211fc5754aa571d019.zip
[efi] Provide efi_uri_path() to construct a URI device path
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface/efi/efi_path.c')
-rw-r--r--src/interface/efi/efi_path.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
index 162400a0..6201c023 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