[U-Boot] [PATCH 0/4] efi_convert_device_path_to_text

The patch series provides the DevicePathToText function for MAC addresses and some error corrections.
The 1st patch removes duplicate constants that we already have defined in efi_api.h.
The 2nd patch implements the DevicePathToText function for MAC addresses.
The 3rd patch supplies additional debug output.
The 4th patch adds a missing parameter check.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de
Heinrich Schuchardt (4): efi_loader: do not duplicate constants for device path efi_loader: DevicePathToText for MAC address efi_loader: debug info in efi_convert_device_path_to_text efi_loader: parameter check efi_convert_device_path_to_text
lib/efi_loader/efi_device_path_to_text.c | 40 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)

We should not duplicate existing constants used by the device path protocol.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- lib/efi_loader/efi_device_path_to_text.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index a7a513047f..3a92247f30 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -9,9 +9,6 @@ #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;
@@ -38,9 +35,9 @@ uint16_t *efi_convert_device_path_to_text( uint16_t *buffer = NULL;
switch (device_path->type) { - case MEDIA_DEVICE_PATH: + case DEVICE_PATH_TYPE_MEDIA_DEVICE: switch (device_path->sub_type) { - case FILE_PATH_MEDIA_DEVICE_PATH: + case DEVICE_PATH_SUB_TYPE_FILE_PATH: buffer_size = device_path->length - 4; r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, (void **) &buffer);

Implement DevicePathToText MAC address device path.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- lib/efi_loader/efi_device_path_to_text.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index 3a92247f30..c6ac5e52f3 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -9,6 +9,8 @@ #include <common.h> #include <efi_loader.h>
+#define MAC_OUTPUT_LEN 22 + const efi_guid_t efi_guid_device_path_to_text_protocol = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
@@ -35,6 +37,31 @@ uint16_t *efi_convert_device_path_to_text( uint16_t *buffer = NULL;
switch (device_path->type) { + case DEVICE_PATH_TYPE_MESSAGING_DEVICE: + switch (device_path->sub_type) { + case DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR: { + struct efi_device_path_mac_addr *dp = + (struct efi_device_path_mac_addr *)device_path; + int i; + + if (dp->if_type != 0 && dp->if_type != 1) + break; + r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, + 2 * MAC_OUTPUT_LEN, + (void **)&buffer); + if (r != EFI_SUCCESS) + break; + sprintf((char *)buffer, + "MAC(%02x%02x%02x%02x%02x%02x,0x%1x)", + dp->mac.addr[0], dp->mac.addr[1], + dp->mac.addr[2], dp->mac.addr[3], + dp->mac.addr[4], dp->mac.addr[5], + dp->if_type); + for (i = MAC_OUTPUT_LEN - 1; i >= 0; --i) + buffer[i] = ((uint8_t *)buffer)[i]; + break; + } + } case DEVICE_PATH_TYPE_MEDIA_DEVICE: switch (device_path->sub_type) { case DEVICE_PATH_SUB_TYPE_FILE_PATH:

The debug information provided by efi_convert_device_path_to_text is insufficient. The type and the subtype are needed to find out why the function did not support a conversion.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- lib/efi_loader/efi_device_path_to_text.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index c6ac5e52f3..746b34a377 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -32,6 +32,9 @@ uint16_t *efi_convert_device_path_to_text( { EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts);
+ debug("EFI: type %d, subtype %d\n", + device_path->type, device_path->sub_type); + unsigned long buffer_size; efi_status_t r; uint16_t *buffer = NULL;

Do not dereference NULL.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- lib/efi_loader/efi_device_path_to_text.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index 746b34a377..81a6a91e66 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -39,6 +39,11 @@ uint16_t *efi_convert_device_path_to_text( efi_status_t r; uint16_t *buffer = NULL;
+ if (!device_path) { + EFI_EXIT(EFI_INVALID_PARAMETER); + return NULL; + } + switch (device_path->type) { case DEVICE_PATH_TYPE_MESSAGING_DEVICE: switch (device_path->sub_type) {
participants (1)
-
Heinrich Schuchardt