3b11dff
From patchwork Tue Sep  6 13:44:25 2022
3b11dff
Content-Type: text/plain; charset="utf-8"
3b11dff
MIME-Version: 1.0
3b11dff
Content-Transfer-Encoding: 7bit
3b11dff
X-Patchwork-Submitter: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
X-Patchwork-Id: 1674857
3b11dff
Return-Path: <u-boot-bounces@lists.denx.de>
3b11dff
X-Original-To: incoming@patchwork.ozlabs.org
3b11dff
Delivered-To: patchwork-incoming@legolas.ozlabs.org
3b11dff
Authentication-Results: legolas.ozlabs.org;
3b11dff
 spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
3b11dff
 (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;
3b11dff
 envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>)
3b11dff
Authentication-Results: legolas.ozlabs.org;
3b11dff
	dkim=pass (2048-bit key;
3b11dff
 unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256
3b11dff
 header.s=google header.b=wUY2RcfH;
3b11dff
	dkim-atps=neutral
3b11dff
Received: from phobos.denx.de (phobos.denx.de
3b11dff
 [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])
3b11dff
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
3b11dff
	 key-exchange X25519 server-signature ECDSA (P-384))
3b11dff
	(No client certificate requested)
3b11dff
	by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMRT72TCPz1yhd
3b11dff
	for <incoming@patchwork.ozlabs.org>; Tue,  6 Sep 2022 23:44:43 +1000 (AEST)
3b11dff
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
3b11dff
	by phobos.denx.de (Postfix) with ESMTP id 498F2849CE;
3b11dff
	Tue,  6 Sep 2022 15:44:39 +0200 (CEST)
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 dmarc=pass (p=none dis=none) header.from=linaro.org
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
	dkim=pass (2048-bit key;
3b11dff
 unprotected) header.d=linaro.org header.i=@linaro.org header.b="wUY2RcfH";
3b11dff
	dkim-atps=neutral
3b11dff
Received: by phobos.denx.de (Postfix, from userid 109)
3b11dff
 id A8842849CF; Tue,  6 Sep 2022 15:44:37 +0200 (CEST)
3b11dff
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
3b11dff
X-Spam-Level: 
3b11dff
X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,
3b11dff
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,
3b11dff
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2
3b11dff
Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com
3b11dff
 [IPv6:2a00:1450:4864:20::52d])
3b11dff
 (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))
3b11dff
 (No client certificate requested)
3b11dff
 by phobos.denx.de (Postfix) with ESMTPS id 403A5849AA
3b11dff
 for <u-boot@lists.denx.de>; Tue,  6 Sep 2022 15:44:35 +0200 (CEST)
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 dmarc=pass (p=none dis=none) header.from=linaro.org
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org
3b11dff
Received: by mail-ed1-x52d.google.com with SMTP id x73so8243364ede.10
3b11dff
 for <u-boot@lists.denx.de>; Tue, 06 Sep 2022 06:44:35 -0700 (PDT)
3b11dff
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;
3b11dff
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
3b11dff
 :to:from:from:to:cc:subject:date;
3b11dff
 bh=YBbhuTYZcGSI4FSsstTIADofj6ZEC8vsTpd/U8gWDlU=;
3b11dff
 b=wUY2RcfHqhMQ1dgd2my7jtmfsgHjAF8xFa3HnTkB/tUGQL/oQyls7ODcVui/VImHlf
3b11dff
 Ah33xwYqK1nwEuoS8HqkWcksTr48pKf/EikkkBbHif0XnfS4oySI3RHo7WW6Yi8HQUoP
3b11dff
 tbuQ3LPSYgo+62HaqTYVoJ2g6jc1qiEFe/+y6hR2BfmyKd0g/SxwLS9P1QuQosdhX+uO
3b11dff
 DKWWukFYFV06Nn7x/3oiyoXq33VAWatgQBv/sPC7dBgh/EpnobDpI8NhNhJAkFIcAUrU
3b11dff
 B91PBwNRtB1Lsf+Eo3WjLtQbinL3h/VvogRSvZEoKCmHY5dbTYB8G1uNzksnK6QecIRu
3b11dff
 q9qA==
3b11dff
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
3b11dff
 d=1e100.net; s=20210112;
3b11dff
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
3b11dff
 :to:from:x-gm-message-state:from:to:cc:subject:date;
3b11dff
 bh=YBbhuTYZcGSI4FSsstTIADofj6ZEC8vsTpd/U8gWDlU=;
3b11dff
 b=KfQ/P0sYI7szdfgs6GA5oPXctzQ8yfxjRs7PgVHFg7jl09SeFl3jpKzaMGbC7GlEgM
3b11dff
 JXt2VP6w9TndL/D71cR8w9BObY2mZJoLRP/s25LpSU6izkisnuueyGeqKegGEfGE+4B3
3b11dff
 9xaG/EUlPZmHlAem6bOf9Dl6lE5WkT6SnTDopwODIbcTAWlIa8Gjtw9XBaaa8iRnVuTn
3b11dff
 S3IwY9R7DLaSFBQXTVHmAYnhCc2b5XCRKlSNwmDE65+LqvOdAu3MTbA5/YyL9pEPjHi9
3b11dff
 4q0ZQksAE0olpQQwxyjHrvz7h7ktSuJoesa/A4dX3PEbzSbBmPI1CGtPy27/luAUCH3F
3b11dff
 e8Vw==
3b11dff
X-Gm-Message-State: ACgBeo2YRons+T+T1+BdP4+uyEFge3LrQ/gS2VYwuVZg325XGZ8HVnXH
3b11dff
 Lq8no+qriMaFPrto6+L889ufiYLHsm+dZQ==
3b11dff
X-Google-Smtp-Source: 
3b11dff
 AA6agR6coLdFIB45xwZJzpltd9Qfi6bEAn6J22G77ibwSDNyt1L1YbxRL9dlK4pmf9A6n2RN31Ug2w==
3b11dff
X-Received: by 2002:aa7:c84f:0:b0:446:2bfb:5a63 with SMTP id
3b11dff
 g15-20020aa7c84f000000b004462bfb5a63mr17498596edt.172.1662471874779;
3b11dff
 Tue, 06 Sep 2022 06:44:34 -0700 (PDT)
3b11dff
Received: from localhost.localdomain ([46.103.15.185])
3b11dff
 by smtp.gmail.com with ESMTPSA id
3b11dff
 p23-20020a056402501700b0043ba7df7a42sm8473330eda.26.2022.09.06.06.44.33
3b11dff
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
3b11dff
 Tue, 06 Sep 2022 06:44:34 -0700 (PDT)
3b11dff
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
To: u-boot@lists.denx.de
3b11dff
Cc: trini@konsulko.com, sjg@chromium.org, heinrich.schuchardt@canonical.com,
3b11dff
 pbrobinson@gmail.com, Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
Subject: [PATCH 1/2] smbios: Simplify reporting of unknown values
3b11dff
Date: Tue,  6 Sep 2022 16:44:25 +0300
3b11dff
Message-Id: <20220906134426.53748-1-ilias.apalodimas@linaro.org>
3b11dff
X-Mailer: git-send-email 2.37.2
3b11dff
MIME-Version: 1.0
3b11dff
X-BeenThere: u-boot@lists.denx.de
3b11dff
X-Mailman-Version: 2.1.39
3b11dff
Precedence: list
3b11dff
List-Id: U-Boot discussion <u-boot.lists.denx.de>
3b11dff
List-Unsubscribe: <https://lists.denx.de/options/u-boot>,
3b11dff
 <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>
3b11dff
List-Archive: <https://lists.denx.de/pipermail/u-boot/>
3b11dff
List-Post: <mailto:u-boot@lists.denx.de>
3b11dff
List-Help: <mailto:u-boot-request@lists.denx.de?subject=help>
3b11dff
List-Subscribe: <https://lists.denx.de/listinfo/u-boot>,
3b11dff
 <mailto:u-boot-request@lists.denx.de?subject=subscribe>
3b11dff
Errors-To: u-boot-bounces@lists.denx.de
3b11dff
Sender: "U-Boot" <u-boot-bounces@lists.denx.de>
3b11dff
X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de
3b11dff
X-Virus-Status: Clean
3b11dff
3b11dff
If a value is not valid during the DT or SYSINFO parsing,  we explicitly
3b11dff
set that to "Unknown Product" and "Unknown" for the product and
3b11dff
manufacturer respectively.  It's cleaner if we move the checks insisde
3b11dff
smbios_add_string() and always report "Unknown" regardless of the missing
3b11dff
field.
3b11dff
3b11dff
pre-patch dmidecode
3b11dff
<snip>
3b11dff
Handle 0x0001, DMI type 1, 27 bytes
3b11dff
System Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown Product
3b11dff
        Version: Not Specified
3b11dff
        Serial Number: Not Specified
3b11dff
        UUID: Not Settable
3b11dff
        Wake-up Type: Reserved
3b11dff
        SKU Number: Not Specified
3b11dff
        Family: Not Specified
3b11dff
3b11dff
Handle 0x0002, DMI type 2, 14 bytes
3b11dff
Base Board Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown Product
3b11dff
        Version: Not Specified
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Not Specified
3b11dff
        Features:
3b11dff
                Board is a hosting board
3b11dff
        Location In Chassis: Not Specified
3b11dff
        Chassis Handle: 0x0000
3b11dff
        Type: Motherboard
3b11dff
<snip>
3b11dff
3b11dff
post-patch dmidecode:
3b11dff
3b11dff
Handle 0x0001, DMI type 1, 27 bytes
3b11dff
System Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Unknown
3b11dff
        UUID: Not Settable
3b11dff
        Wake-up Type: Reserved
3b11dff
        SKU Number: Unknown
3b11dff
        Family: Unknown
3b11dff
3b11dff
Handle 0x0002, DMI type 2, 14 bytes
3b11dff
Base Board Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Unknown
3b11dff
        Features:
3b11dff
                Board is a hosting board
3b11dff
        Location In Chassis: Not Specified
3b11dff
        Chassis Handle: 0x0000
3b11dff
        Type: Motherboard
3b11dff
3b11dff
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
---
3b11dff
 lib/smbios.c | 17 +++--------------
3b11dff
 1 file changed, 3 insertions(+), 14 deletions(-)
3b11dff
3b11dff
diff --git a/lib/smbios.c b/lib/smbios.c
3b11dff
index d7f4999e8b2a..fcc8686993ef 100644
3b11dff
--- a/lib/smbios.c
3b11dff
+++ b/lib/smbios.c
3b11dff
@@ -102,7 +102,7 @@ static int smbios_add_string(struct smbios_ctx *ctx, const char *str)
3b11dff
 	int i = 1;
3b11dff
 	char *p = ctx->eos;
3b11dff
 
3b11dff
-	if (!*str)
3b11dff
+	if (!str || !*str)
3b11dff
 		str = "Unknown";
3b11dff
 
3b11dff
 	for (;;) {
3b11dff
@@ -151,8 +151,7 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
3b11dff
 		const char *str;
3b11dff
 
3b11dff
 		str = ofnode_read_string(ctx->node, prop);
3b11dff
-		if (str)
3b11dff
-			return smbios_add_string(ctx, str);
3b11dff
+		return smbios_add_string(ctx, str);
3b11dff
 	}
3b11dff
 
3b11dff
 	return 0;
3b11dff
@@ -231,7 +230,7 @@ static int smbios_write_type0(ulong *current, int handle,
3b11dff
 	t->vendor = smbios_add_string(ctx, "U-Boot");
3b11dff
 
3b11dff
 	t->bios_ver = smbios_add_prop(ctx, "version");
3b11dff
-	if (!t->bios_ver)
3b11dff
+	if (!strcmp(ctx->last_str, "Unknown"))
3b11dff
 		t->bios_ver = smbios_add_string(ctx, PLAIN_VERSION);
3b11dff
 	if (t->bios_ver)
3b11dff
 		gd->smbios_version = ctx->last_str;
3b11dff
@@ -281,11 +280,7 @@ static int smbios_write_type1(ulong *current, int handle,
3b11dff
 	fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
3b11dff
 	smbios_set_eos(ctx, t->eos);
3b11dff
 	t->manufacturer = smbios_add_prop(ctx, "manufacturer");
3b11dff
-	if (!t->manufacturer)
3b11dff
-		t->manufacturer = smbios_add_string(ctx, "Unknown");
3b11dff
 	t->product_name = smbios_add_prop(ctx, "product");
3b11dff
-	if (!t->product_name)
3b11dff
-		t->product_name = smbios_add_string(ctx, "Unknown Product");
3b11dff
 	t->version = smbios_add_prop_si(ctx, "version",
3b11dff
 					SYSINFO_ID_SMBIOS_SYSTEM_VERSION);
3b11dff
 	if (serial_str) {
3b11dff
@@ -315,11 +310,7 @@ static int smbios_write_type2(ulong *current, int handle,
3b11dff
 	fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
3b11dff
 	smbios_set_eos(ctx, t->eos);
3b11dff
 	t->manufacturer = smbios_add_prop(ctx, "manufacturer");
3b11dff
-	if (!t->manufacturer)
3b11dff
-		t->manufacturer = smbios_add_string(ctx, "Unknown");
3b11dff
 	t->product_name = smbios_add_prop(ctx, "product");
3b11dff
-	if (!t->product_name)
3b11dff
-		t->product_name = smbios_add_string(ctx, "Unknown Product");
3b11dff
 	t->version = smbios_add_prop_si(ctx, "version",
3b11dff
 					SYSINFO_ID_SMBIOS_BASEBOARD_VERSION);
3b11dff
 	t->asset_tag_number = smbios_add_prop(ctx, "asset-tag");
3b11dff
@@ -344,8 +335,6 @@ static int smbios_write_type3(ulong *current, int handle,
3b11dff
 	fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
3b11dff
 	smbios_set_eos(ctx, t->eos);
3b11dff
 	t->manufacturer = smbios_add_prop(ctx, "manufacturer");
3b11dff
-	if (!t->manufacturer)
3b11dff
-		t->manufacturer = smbios_add_string(ctx, "Unknown");
3b11dff
 	t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
3b11dff
 	t->bootup_state = SMBIOS_STATE_SAFE;
3b11dff
 	t->power_supply_state = SMBIOS_STATE_SAFE;
3b11dff
3b11dff
From patchwork Tue Sep  6 13:44:26 2022
3b11dff
Content-Type: text/plain; charset="utf-8"
3b11dff
MIME-Version: 1.0
3b11dff
Content-Transfer-Encoding: 7bit
3b11dff
X-Patchwork-Submitter: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
X-Patchwork-Id: 1674858
3b11dff
Return-Path: <u-boot-bounces@lists.denx.de>
3b11dff
X-Original-To: incoming@patchwork.ozlabs.org
3b11dff
Delivered-To: patchwork-incoming@legolas.ozlabs.org
3b11dff
Authentication-Results: legolas.ozlabs.org;
3b11dff
 spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
3b11dff
 (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;
3b11dff
 envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>)
3b11dff
Authentication-Results: legolas.ozlabs.org;
3b11dff
	dkim=pass (2048-bit key;
3b11dff
 unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256
3b11dff
 header.s=google header.b=wBCOiKYw;
3b11dff
	dkim-atps=neutral
3b11dff
Received: from phobos.denx.de (phobos.denx.de
3b11dff
 [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])
3b11dff
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
3b11dff
	 key-exchange X25519 server-signature ECDSA (P-384))
3b11dff
	(No client certificate requested)
3b11dff
	by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMRTM5pHRz1yhk
3b11dff
	for <incoming@patchwork.ozlabs.org>; Tue,  6 Sep 2022 23:44:55 +1000 (AEST)
3b11dff
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
3b11dff
	by phobos.denx.de (Postfix) with ESMTP id 3639F849EA;
3b11dff
	Tue,  6 Sep 2022 15:44:53 +0200 (CEST)
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 dmarc=pass (p=none dis=none) header.from=linaro.org
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
	dkim=pass (2048-bit key;
3b11dff
 unprotected) header.d=linaro.org header.i=@linaro.org header.b="wBCOiKYw";
3b11dff
	dkim-atps=neutral
3b11dff
Received: by phobos.denx.de (Postfix, from userid 109)
3b11dff
 id E57FC84A1A; Tue,  6 Sep 2022 15:44:51 +0200 (CEST)
3b11dff
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
3b11dff
X-Spam-Level: 
3b11dff
X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,
3b11dff
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,
3b11dff
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2
3b11dff
Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com
3b11dff
 [IPv6:2a00:1450:4864:20::52f])
3b11dff
 (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))
3b11dff
 (No client certificate requested)
3b11dff
 by phobos.denx.de (Postfix) with ESMTPS id 60CD0849AA
3b11dff
 for <u-boot@lists.denx.de>; Tue,  6 Sep 2022 15:44:49 +0200 (CEST)
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 dmarc=pass (p=none dis=none) header.from=linaro.org
3b11dff
Authentication-Results: phobos.denx.de;
3b11dff
 spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org
3b11dff
Received: by mail-ed1-x52f.google.com with SMTP id z21so5172669edi.1
3b11dff
 for <u-boot@lists.denx.de>; Tue, 06 Sep 2022 06:44:49 -0700 (PDT)
3b11dff
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;
3b11dff
 h=content-transfer-encoding:mime-version:references:in-reply-to
3b11dff
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date;
3b11dff
 bh=KsGBN7dLy4q3TeQQmsDywPtn2m3V5eSK1ppBgO8D3xg=;
3b11dff
 b=wBCOiKYwM4mGDZUo6l68tblLVt57cCnO0dlzFPj9+m6cwKXe3agxiM3w4t9T5c822i
3b11dff
 vHmFd2F08bUrX81t/h4PDzg0mngbB9Rc9o4i3td1G9Zw6NdmogU7T7gEUyKKcTc80AWl
3b11dff
 QbbYgxulWB5Eg2dTQ3tlb2xmb5BU1/X0zl/rOC6l89urohdQtpIJ4XgFlijFlBgxh8XD
3b11dff
 aHytniLKGTLlVdJAIobcF9aM/ihpO7LPTDZ4SPCBt4t9+UWGW7vuTPDPDkCRiaaFestv
3b11dff
 9P32ZrGj43CH92zBQtpgZICS0UhzD3oYWJkwsmFbfxddgY5VD5SQi69VzD1CfFOvTGgX
3b11dff
 5HBg==
3b11dff
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
3b11dff
 d=1e100.net; s=20210112;
3b11dff
 h=content-transfer-encoding:mime-version:references:in-reply-to
3b11dff
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
3b11dff
 :subject:date;
3b11dff
 bh=KsGBN7dLy4q3TeQQmsDywPtn2m3V5eSK1ppBgO8D3xg=;
3b11dff
 b=h1yL2aMN8ooI48PrqxwSNjw+MAj6qGtRMJjV8AWmRfv7nVQ97I/cXbauy/NItVEWP0
3b11dff
 eO4WFqVMQO+xyGn1S5w0MXYGVbEpVNxf0gwM7n7Ad+K2E2PDHyu6glGTvcqCW11gPGOJ
3b11dff
 uNDyo6pu7OtmOBso2OaL5eMGhw66ZGqQbzlQtO0mhqJf1RtQ9fRduRZrfTzAR9wIrM4Y
3b11dff
 qR3iK6b4O97tu0W0SctGf3rCNzI2bDv/zBKRvfSJ6q7s4DhLDxBJyQjySBo0Ee6UIwKc
3b11dff
 5q8zldycF/JfIbqzlJe6DaeoeDbzJ7qLBPvDmxQ7owSV9ftEa8lh/IIdPn13uDL2Bxjz
3b11dff
 WLbg==
3b11dff
X-Gm-Message-State: ACgBeo0DsGDn9dDw7GQ5K44iwyXJqKH0pM3NWFxuDlmBNzKLyzH8SEzb
3b11dff
 03ImCopxuD/6oyVtH7ygeEl2Cc6GlNzVNQ==
3b11dff
X-Google-Smtp-Source: 
3b11dff
 AA6agR6kpp8KIkqO+/pui5Dy7mRTrk+S2U0k99eVOJv3PGkIDZ8H0oqIBypOwW5nogFds0FAjF4TXg==
3b11dff
X-Received: by 2002:a05:6402:f18:b0:44d:9a45:394 with SMTP id
3b11dff
 i24-20020a0564020f1800b0044d9a450394mr12375719eda.138.1662471889015;
3b11dff
 Tue, 06 Sep 2022 06:44:49 -0700 (PDT)
3b11dff
Received: from localhost.localdomain ([46.103.15.185])
3b11dff
 by smtp.gmail.com with ESMTPSA id
3b11dff
 p23-20020a056402501700b0043ba7df7a42sm8473330eda.26.2022.09.06.06.44.48
3b11dff
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
3b11dff
 Tue, 06 Sep 2022 06:44:48 -0700 (PDT)
3b11dff
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
To: u-boot@lists.denx.de
3b11dff
Cc: trini@konsulko.com, sjg@chromium.org, heinrich.schuchardt@canonical.com,
3b11dff
 pbrobinson@gmail.com, Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
Subject: [PATCH 2/2] smbios: Fallback to the default DT if sysinfo nodes are
3b11dff
 missing
3b11dff
Date: Tue,  6 Sep 2022 16:44:26 +0300
3b11dff
Message-Id: <20220906134426.53748-2-ilias.apalodimas@linaro.org>
3b11dff
X-Mailer: git-send-email 2.37.2
3b11dff
In-Reply-To: <20220906134426.53748-1-ilias.apalodimas@linaro.org>
3b11dff
References: <20220906134426.53748-1-ilias.apalodimas@linaro.org>
3b11dff
MIME-Version: 1.0
3b11dff
X-BeenThere: u-boot@lists.denx.de
3b11dff
X-Mailman-Version: 2.1.39
3b11dff
Precedence: list
3b11dff
List-Id: U-Boot discussion <u-boot.lists.denx.de>
3b11dff
List-Unsubscribe: <https://lists.denx.de/options/u-boot>,
3b11dff
 <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>
3b11dff
List-Archive: <https://lists.denx.de/pipermail/u-boot/>
3b11dff
List-Post: <mailto:u-boot@lists.denx.de>
3b11dff
List-Help: <mailto:u-boot-request@lists.denx.de?subject=help>
3b11dff
List-Subscribe: <https://lists.denx.de/listinfo/u-boot>,
3b11dff
 <mailto:u-boot-request@lists.denx.de?subject=subscribe>
3b11dff
Errors-To: u-boot-bounces@lists.denx.de
3b11dff
Sender: "U-Boot" <u-boot-bounces@lists.denx.de>
3b11dff
X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de
3b11dff
X-Virus-Status: Clean
3b11dff
3b11dff
In order to fill in the SMBIOS tables U-Boot currently relies on a
3b11dff
"u-boot,sysinfo-smbios" compatible node.  This is fine for the boards
3b11dff
that already include such nodes.  However with some recent EFI changes,
3b11dff
the majority of boards can boot up distros, which usually rely on
3b11dff
things like dmidecode etc for their reporting.  For boards that
3b11dff
lack this special node the SMBIOS output looks like:
3b11dff
3b11dff
System Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Unknown
3b11dff
        UUID: Not Settable
3b11dff
        Wake-up Type: Reserved
3b11dff
        SKU Number: Unknown
3b11dff
        Family: Unknown
3b11dff
3b11dff
This looks problematic since most of the info are "Unknown".  The DT spec
3b11dff
specifies standard properties containing relevant information like
3b11dff
'model' and 'compatible' for which the suggested format is
3b11dff
<manufacturer,model>.  So let's add a last resort to our current
3b11dff
smbios parsing.  If none of the sysinfo properties are found,  we can
3b11dff
scan the root node for 'model' and 'compatible'.
3b11dff
3b11dff
pre-patch dmidecode:
3b11dff
<snip>
3b11dff
Handle 0x0001, DMI type 1, 27 bytes
3b11dff
System Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Unknown
3b11dff
        UUID: Not Settable
3b11dff
        Wake-up Type: Reserved
3b11dff
        SKU Number: Unknown
3b11dff
        Family: Unknown
3b11dff
3b11dff
Handle 0x0002, DMI type 2, 14 bytes
3b11dff
Base Board Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Product Name: Unknown
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Unknown
3b11dff
        Features:
3b11dff
                Board is a hosting board
3b11dff
        Location In Chassis: Not Specified
3b11dff
        Chassis Handle: 0x0000
3b11dff
        Type: Motherboard
3b11dff
3b11dff
Handle 0x0003, DMI type 3, 21 bytes
3b11dff
Chassis Information
3b11dff
        Manufacturer: Unknown
3b11dff
        Type: Desktop
3b11dff
        Lock: Not Present
3b11dff
        Version: Not Specified
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Not Specified
3b11dff
        Boot-up State: Safe
3b11dff
        Power Supply State: Safe
3b11dff
        Thermal State: Safe
3b11dff
        Security Status: None
3b11dff
        OEM Information: 0x00000000
3b11dff
        Height: Unspecified
3b11dff
        Number Of Power Cords: Unspecified
3b11dff
        Contained Elements: 0
3b11dff
<snip>
3b11dff
3b11dff
post-pastch dmidecode:
3b11dff
<snip>
3b11dff
Handle 0x0001, DMI type 1, 27 bytes
3b11dff
System Information
3b11dff
        Manufacturer: socionext,developer-box
3b11dff
        Product Name: Socionext Developer Box
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Unknown
3b11dff
        UUID: Not Settable
3b11dff
        Wake-up Type: Reserved
3b11dff
        SKU Number: Unknown
3b11dff
        Family: Unknown
3b11dff
3b11dff
Handle 0x0002, DMI type 2, 14 bytes
3b11dff
Base Board Information
3b11dff
        Manufacturer: socionext,developer-box
3b11dff
        Product Name: Socionext Developer Box
3b11dff
        Version: Unknown
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Unknown
3b11dff
        Features:
3b11dff
                Board is a hosting board
3b11dff
        Location In Chassis: Not Specified
3b11dff
        Chassis Handle: 0x0000
3b11dff
        Type: Motherboard
3b11dff
3b11dff
Handle 0x0003, DMI type 3, 21 bytes
3b11dff
Chassis Information
3b11dff
        Manufacturer: socionext,developer-box
3b11dff
        Type: Desktop
3b11dff
        Lock: Not Present
3b11dff
        Version: Not Specified
3b11dff
        Serial Number: Not Specified
3b11dff
        Asset Tag: Not Specified
3b11dff
        Boot-up State: Safe
3b11dff
        Power Supply State: Safe
3b11dff
        Thermal State: Safe
3b11dff
        Security Status: None
3b11dff
        OEM Information: 0x00000000
3b11dff
        Height: Unspecified
3b11dff
        Number Of Power Cords: Unspecified
3b11dff
        Contained Elements: 0
3b11dff
<snip>
3b11dff
3b11dff
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3b11dff
---
3b11dff
 lib/smbios.c | 41 +++++++++++++++++++++++++++++++++++++++--
3b11dff
 1 file changed, 39 insertions(+), 2 deletions(-)
3b11dff
3b11dff
diff --git a/lib/smbios.c b/lib/smbios.c
3b11dff
index fcc8686993ef..f2eb961f514b 100644
3b11dff
--- a/lib/smbios.c
3b11dff
+++ b/lib/smbios.c
3b11dff
@@ -43,6 +43,20 @@
3b11dff
 
3b11dff
 DECLARE_GLOBAL_DATA_PTR;
3b11dff
 
3b11dff
+/**
3b11dff
+ * struct sysifno_to_dt - Mapping of sysinfo strings to DT
3b11dff
+ *
3b11dff
+ * @sysinfo_str: sysinfo string
3b11dff
+ * @dt_str: DT string
3b11dff
+ */
3b11dff
+static const struct {
3b11dff
+	const char *sysinfo_str;
3b11dff
+	const char *dt_str;
3b11dff
+} sysifno_to_dt[] = {
3b11dff
+	{ .sysinfo_str = "product", .dt_str = "model" },
3b11dff
+	{ .sysinfo_str = "manufacturer", .dt_str = "compatible" },
3b11dff
+};
3b11dff
+
3b11dff
 /**
3b11dff
  * struct smbios_ctx - context for writing SMBIOS tables
3b11dff
  *
3b11dff
@@ -87,6 +101,18 @@ struct smbios_write_method {
3b11dff
 	const char *subnode_name;
3b11dff
 };
3b11dff
 
3b11dff
+static const char *convert_sysinfo_to_dt(const char *sysinfo_str)
3b11dff
+{
3b11dff
+	int i;
3b11dff
+
3b11dff
+	for (i = 0; i < ARRAY_SIZE(sysifno_to_dt); i++) {
3b11dff
+		if (!strcmp(sysinfo_str, sysifno_to_dt[i].sysinfo_str))
3b11dff
+			return sysifno_to_dt[i].dt_str;
3b11dff
+	}
3b11dff
+
3b11dff
+	return NULL;
3b11dff
+}
3b11dff
+
3b11dff
 /**
3b11dff
  * smbios_add_string() - add a string to the string area
3b11dff
  *
3b11dff
@@ -148,9 +174,20 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
3b11dff
 			return smbios_add_string(ctx, val);
3b11dff
 	}
3b11dff
 	if (IS_ENABLED(CONFIG_OF_CONTROL)) {
3b11dff
-		const char *str;
3b11dff
+		const char *str = NULL;
3b11dff
 
3b11dff
-		str = ofnode_read_string(ctx->node, prop);
3b11dff
+		/*
3b11dff
+		 * If the node is not valid fallback and try the entire DT
3b11dff
+		 * so we can at least fill in maufacturer and board type
3b11dff
+		 */
3b11dff
+		if (!ofnode_valid(ctx->node)) {
3b11dff
+			const char *nprop = convert_sysinfo_to_dt(prop);
3b11dff
+
3b11dff
+			if (nprop)
3b11dff
+				str = ofnode_read_string(ofnode_root(), nprop);
3b11dff
+		} else {
3b11dff
+			str = ofnode_read_string(ctx->node, prop);
3b11dff
+		}
3b11dff
 		return smbios_add_string(ctx, str);
3b11dff
 	}
3b11dff