From patchwork Sun Jan 16 15:14:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1580471 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=KTbofO2x; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JcJWD2w8vz9sRR for ; Mon, 17 Jan 2022 02:15:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 20E0B82F87; Sun, 16 Jan 2022 16:15:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="KTbofO2x"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1262E8351F; Sun, 16 Jan 2022 16:14:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7537582FC8 for ; Sun, 16 Jan 2022 16:14:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from workstation5.fritz.box (ip-88-152-144-107.hsi03.unitymediagroup.de [88.152.144.107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id E20CF4196D; Sun, 16 Jan 2022 15:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642346090; bh=ucHfNAWE7A3YY7RXp3LB+PmXa2pvoih9HOFJbMuktxM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KTbofO2xUTuWzwb3udarJyEA7O85I1QCCQ296K7NsDExFQyvUuSMEis7Au+nQjBp3 VeGuBQUqleqiCk+Za0NObtLTbEViqJXTFa3RYdo8hA3wkKNcu8nktiZ6TLGlz5VCcO sXWF58kZ/fjE1lsyd8BPxJ4xC9eX15zTJDLqHkBwfAi2TyA+40toaUKpP3jbQx8dwR cyqUwyENuAp/n3d6/DSCx5iXOctugdVKO8wFEYwKreAcixIPR9ULKKGqkvnlsqZ14Y tpwZp7fzR3jmUeBaDMd4/1ffjszhTSO1d/T18mOIQtIzMsKRukcwmB65VQBkJX9v1d jCDJ0JcnetFow== From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Rasmus Villemoes , Patrick Delaunay , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 2/8] lib: printf code %pUs for GUID text representation Date: Sun, 16 Jan 2022 16:14:35 +0100 Message-Id: <20220116151441.219566-3-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220116151441.219566-1-heinrich.schuchardt@canonical.com> References: <20220116151441.219566-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean In different places text representations are used for GUIDs, e.g. * command efidebug * command part list for GPT partitions To allow reducing code duplication introduce a new printf code %pUs. It will call uuid_guid_get_str() to get a text representation. If none is found it will fallback to %pUl and print a hexadecimal representation. Signed-off-by: Heinrich Schuchardt --- lib/vsprintf.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index de9f236b90..2c0cc1647e 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -255,8 +255,8 @@ static char *number(char *buf, char *end, u64 num, return buf; } -static char *string(char *buf, char *end, char *s, int field_width, - int precision, int flags) +static char *string(char *buf, char *end, const char *s, int field_width, + int precision, int flags) { int len, i; @@ -387,12 +387,14 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width, * %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10 * %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 * %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10 + * %pUs: GUID text representation if known or fallback to %pUl */ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, int precision, int flags, const char *fmt) { char uuid[UUID_STR_LEN + 1]; int str_format; + const char *str; switch (*(++fmt)) { case 'L': @@ -404,6 +406,13 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, case 'B': str_format = UUID_STR_FORMAT_STD | UUID_STR_UPPER_CASE; break; + case 's': + str = uuid_guid_get_str(addr); + if (str) + return string(buf, end, str, + field_width, precision, flags); + str_format = UUID_STR_FORMAT_GUID; + break; default: str_format = UUID_STR_FORMAT_STD; break;