summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path_to_text.c
blob: a7a513047fefd753472ec65897067edb22b0b5b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 *  EFI device path interface
 *
 *  Copyright (c) 2017 Heinrich Schuchardt
 *
 *  SPDX-License-Identifier:     GPL-2.0+
 */

#include <common.h>
#include <efi_loader.h>

#define MEDIA_DEVICE_PATH 4
#define FILE_PATH_MEDIA_DEVICE_PATH 4

const efi_guid_t efi_guid_device_path_to_text_protocol =
		EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;

uint16_t *efi_convert_device_node_to_text(
		struct efi_device_path_protocol *device_node,
		bool display_only,
		bool allow_shortcuts)
{
	EFI_ENTRY("%p, %d, %d", device_node, display_only, allow_shortcuts);

	EFI_EXIT(EFI_UNSUPPORTED);
	return NULL;
}

uint16_t *efi_convert_device_path_to_text(
		struct efi_device_path_protocol *device_path,
		bool display_only,
		bool allow_shortcuts)
{
	EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts);

	unsigned long buffer_size;
	efi_status_t r;
	uint16_t *buffer = NULL;

	switch (device_path->type) {
	case MEDIA_DEVICE_PATH:
		switch (device_path->sub_type) {
		case FILE_PATH_MEDIA_DEVICE_PATH:
			buffer_size = device_path->length - 4;
			r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
					      buffer_size, (void **) &buffer);
			if (r == EFI_SUCCESS)
				memcpy(buffer, device_path->data, buffer_size);
			break;
		}
	}

	if (buffer) {
		EFI_EXIT(EFI_SUCCESS);
	} else {
		debug("type %d, subtype %d\n",
		      device_path->type, device_path->sub_type);
		EFI_EXIT(EFI_UNSUPPORTED);
	}

	return buffer;
}

const struct efi_device_path_to_text_protocol efi_device_path_to_text = {
	.convert_device_node_to_text = efi_convert_device_node_to_text,
	.convert_device_path_to_text = efi_convert_device_path_to_text,
};