From patchwork Fri Jul 21 17:12:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 792232 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xDclF2MX6z9sNw for ; Sat, 22 Jul 2017 03:12:25 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F1939C21D56; Fri, 21 Jul 2017 17:12:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A607BC21C5C; Fri, 21 Jul 2017 17:12:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B65F5C21C5C; Fri, 21 Jul 2017 17:12:17 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lists.denx.de (Postfix) with ESMTPS id 5366DC21C4F for ; Fri, 21 Jul 2017 17:12:17 +0000 (UTC) Received: from localhost.localdomain ([84.118.154.110]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LfXmv-1dxAZl1Itd-00p8js; Fri, 21 Jul 2017 19:12:16 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 21 Jul 2017 19:12:08 +0200 Message-Id: <20170721171208.3509-1-xypron.glpk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McpOYxiIixnzz+DFuz1E5AjoY6tr4qWwbELcUc9HFyuacQv 6FyTohECCTqLc7SCKm8MHmSWMin9A== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v3 1/1] efi_loader: implement ConvertDeviceNodeToText X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Move the logic for converting a node to text from efi_convert_device_path_to_text to convert_device_node_to_text. Provide a wrapper function convert_device_node_to_text_ext. As we use only shallow device paths so we can call directly call efi_device_node_to_text from efi_device_path_to_text. Add output for MAC addresses. Add output for not yet supported types/subtypes. Signed-off-by: Heinrich Schuchardt --- v4 Remove superfluous EFI_ENTRY. v3 This patch replaces the patch series starting at https://patchwork.ozlabs.org/patch/787983/ https://lists.denx.de/pipermail/u-boot/2017-July/298142.html --- lib/efi_loader/efi_device_path_to_text.c | 126 +++++++++++++++++++++++-------- 1 file changed, 96 insertions(+), 30 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..57e00bf777 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -6,62 +6,123 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include #include -#define MEDIA_DEVICE_PATH 4 -#define FILE_PATH_MEDIA_DEVICE_PATH 4 +#define MAC_OUTPUT_LEN 22 +#define UNKNOWN_OUTPUT_LEN 23 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( +static 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; + int i; + + switch (device_node->type) { + case DEVICE_PATH_TYPE_END: + return NULL; + case DEVICE_PATH_TYPE_MESSAGING_DEVICE: + switch (device_node->sub_type) { + case DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR: { + struct efi_device_path_mac_addr *dp = + (struct efi_device_path_mac_addr *)device_node; - 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; + 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) + return NULL; + 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_node->sub_type) { + case DEVICE_PATH_SUB_TYPE_FILE_PATH: + buffer_size = device_node->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); + if (r != EFI_SUCCESS) + return NULL; + memcpy(buffer, device_node->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); + /* + * For all node types that we do not yet support return + * 'UNKNOWN(type,subtype)'. + */ + if (!buffer) { + r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, + 2 * UNKNOWN_OUTPUT_LEN, + (void **)&buffer); + if (r != EFI_SUCCESS) + return NULL; + sprintf((char *)buffer, + "UNKNOWN(%04x,%04x)", + device_node->type, + device_node->sub_type); + for (i = UNKNOWN_OUTPUT_LEN - 1; i >= 0; --i) + buffer[i] = ((uint8_t *)buffer)[i]; } return buffer; } +static uint16_t EFIAPI *efi_convert_device_node_to_text_ext( + struct efi_device_path_protocol *device_node, + bool display_only, + bool allow_shortcuts) +{ + uint16_t *buffer; + + EFI_ENTRY("%p, %d, %d", device_node, display_only, allow_shortcuts); + + buffer = efi_convert_device_node_to_text(device_node, display_only, + allow_shortcuts); + + EFI_EXIT(EFI_SUCCESS); + return buffer; +} + +static uint16_t EFIAPI *efi_convert_device_path_to_text( + struct efi_device_path_protocol *device_path, + bool display_only, + bool allow_shortcuts) +{ + uint16_t *buffer; + + EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts); + + /* + * Our device paths are all of depth one. So its is sufficient to + * to convert the first node. + */ + buffer = efi_convert_device_node_to_text(device_path, display_only, + allow_shortcuts); + + EFI_EXIT(EFI_SUCCESS); + 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_node_to_text = efi_convert_device_node_to_text_ext, .convert_device_path_to_text = efi_convert_device_path_to_text, };