From nobody Thu Mar 03 13:08:40 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id DF0221A015A7; Thu, 3 Mar 2022 13:08:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K8WWr5xfmz3DRJ; Thu, 3 Mar 2022 13:08:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646312920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1Ru7hFpWTCPgA1j1s1Yn54q6Wjih8JyXrxVpY8GWBHo=; b=QzRwOM6iIqM2ovP8trq8Zgq5yZMWVs33nNQHU4YiX3yawolunN54daR4DpGq4TA62+A5cd QYg+wohOM65cqFo8FGjqOBpLjfQZj3hh9lwZfDqHogwlz27dm67Hkd/36BbiZ8QaohME+h bg2HnJT+1ALnhWWtbnfXUXsZbtoRmvcAjOQIiJAgvN/C+3v0W0JTz30hLmMzubTJ/9ydCz jTTbg364E26dorg+FGABl5Qhs4RwbYlwkv9ePhN7NwenwPAXvrl2+cIGQnn3QEgnk8Xv0/ YvWCUmBQdAHdCqJsGVcElm1ikzZvJVwuXQBdtUM4hLAwXGbGFkwsCxcE/F1ung== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AC1DF18429; Thu, 3 Mar 2022 13:08:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 223D8eYC088381; Thu, 3 Mar 2022 13:08:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 223D8eCa088380; Thu, 3 Mar 2022 13:08:40 GMT (envelope-from git) Date: Thu, 3 Mar 2022 13:08:40 GMT Message-Id: <202203031308.223D8eCa088380@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mike Karels Subject: git: b8b0c65e8a43 - main - Add serial-number to hw.fdt sysctl area if found in fdt. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b8b0c65e8a43cab95b97e28d3e3d73fc7d9c0a5e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646312920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1Ru7hFpWTCPgA1j1s1Yn54q6Wjih8JyXrxVpY8GWBHo=; b=kea68LtqzyrFTDSNpql3Zyd3zkuHrM0KYEwEQhWKfs6n43Tn7P92s/Srqwu4mVx5471fFo YAtDJ7WxSczYiujiN/6QUmDMbTn7PzGb3+mpM1EG1KMp3GVC4nMScC1Wkclv9fWb2VmjGG aCudZPJHKaGqv0Hn+mdKVIuuC0nqlAWJMOkUr2/K9UKlemqyDuiLyjzSSkfCAlUlSoAhvJ c8J3Xq8H1a6+2L+gJcYCcnuGOt5xPvTqkvRzzk6heBxSePhNIqWAQq8lmsU4xdilAvax+a j7N3Lzf9HJJ/SMjYXTzk0K1wH8OWqTrZY4XPVWyiOrZWE+IlIJaMfHCzadbPNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646312920; a=rsa-sha256; cv=none; b=h96RcgyCKk48eCyx9WdMjWnaek2u4IZnLeiwTWoim+8Z2p6UZ6riL/95zU2m3l13FmiZQ9 6Vdq92RLRTXb2mGtogmN4l+kRg6zBHYgZ5PydQhwwLkLBNxkPCxdpFCWmGGvo1SGNvQavQ vmQhMpdQFNHlP2gJx40f3wkR6joXfNV0aquv3aCdk4i8XoQwyIcz+QLmyDJsl+nWr/MqNh 70Afu0JeNsPbU6Te4oozh0MxoXHXrQfrnaDg+jhH6btBwXn0BRgbMbMnk+NzeNPPGLwgN4 mnWfj/4a2TCyGnQG34sWEyd5ze8QdDQMKzCyU6pTViI70IveSbctLkSjrkhT1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=b8b0c65e8a43cab95b97e28d3e3d73fc7d9c0a5e commit b8b0c65e8a43cab95b97e28d3e3d73fc7d9c0a5e Author: Mike Karels AuthorDate: 2022-02-23 20:42:30 +0000 Commit: Mike Karels CommitDate: 2022-03-03 13:08:32 +0000 Add serial-number to hw.fdt sysctl area if found in fdt. Add serial-number sysctl if that fdt property exists and is a printable string. While here, ensure that the hw.fdt sysctl values fit in the buffers provided so that they will be NUL-terminated. Tested on Raspberry Pi 3B+ and 4. MFC after: 5 days Reviewed by: manu imp Differential Revision: https://reviews.freebsd.org/D34356 --- sys/dev/ofw/ofw_fdt.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index a83f7cbdcb60..855bf6d5d14a 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -107,11 +108,13 @@ OFW_DEF(ofw_fdt); #define FDT_FBSDVER_LEN 16 #define FDT_MODEL_LEN 80 #define FDT_COMPAT_LEN 255 +#define FDT_SERIAL_LEN 32 static void *fdtp = NULL; static char fdt_model[FDT_MODEL_LEN]; static char fdt_compatible[FDT_COMPAT_LEN]; static char fdt_fbsd_version[FDT_FBSDVER_LEN]; +static char fdt_serial[FDT_SERIAL_LEN]; static int sysctl_handle_dtb(SYSCTL_HANDLER_ARGS) @@ -143,6 +146,10 @@ sysctl_register_fdt_oid(void *arg) SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO, "freebsd-version", CTLFLAG_RD, fdt_fbsd_version, FDT_FBSDVER_LEN, "FreeBSD DTS branding version"); + if (fdt_serial[0] != '\0') + SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), + OID_AUTO, "serial-number", CTLFLAG_RD, fdt_serial, + FDT_SERIAL_LEN, "Serial number"); } SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL); @@ -161,20 +168,44 @@ ofw_fdt_init(ofw_t ofw, void *data) fdtp = data; root = ofw_fdt_finddevice(NULL, "/"); len = ofw_fdt_getproplen(NULL, root, "model"); - bzero(fdt_model, FDT_MODEL_LEN); - ofw_fdt_getprop(NULL, root, "model", fdt_model, FDT_MODEL_LEN); + if (len > 0 && len <= FDT_MODEL_LEN) { + bzero(fdt_model, FDT_MODEL_LEN); + ofw_fdt_getprop(NULL, root, "model", fdt_model, FDT_MODEL_LEN); + } len = ofw_fdt_getproplen(NULL, root, "compatible"); - bzero(fdt_compatible, FDT_COMPAT_LEN); - ofw_fdt_getprop(NULL, root, "compatible", fdt_compatible, FDT_COMPAT_LEN); - /* Replace the middle '\0' with ' ' */ - for (i = 0; i < len - 1; i++) - if (fdt_compatible[i] == '\0') - fdt_compatible[i] = ' '; - if ((len = ofw_fdt_getproplen(NULL, root, "freebsd,dts-version")) > 0) { + if (len > 0 && len <= FDT_COMPAT_LEN) { + bzero(fdt_compatible, FDT_COMPAT_LEN); + ofw_fdt_getprop(NULL, root, "compatible", fdt_compatible, + FDT_COMPAT_LEN); + /* Replace the middle '\0' with ' ' */ + for (i = 0; i < len - 1; i++) + if (fdt_compatible[i] == '\0') + fdt_compatible[i] = ' '; + } + len = ofw_fdt_getproplen(NULL, root, "freebsd,dts-version"); + if (len > 0 && len <= FDT_FBSDVER_LEN) { bzero(fdt_fbsd_version, FDT_FBSDVER_LEN); ofw_fdt_getprop(NULL, root, "freebsd,dts-version", fdt_fbsd_version, FDT_FBSDVER_LEN); } + len = ofw_fdt_getproplen(NULL, root, "serial-number"); + if (len > 0 && len <= FDT_SERIAL_LEN) { + bzero(fdt_serial, FDT_SERIAL_LEN); + ofw_fdt_getprop(NULL, root, "serial-number", + fdt_serial, FDT_SERIAL_LEN); + /* + * Non-standard property; check for NUL-terminated + * printable string. + */ + for (i = 0; i < len - 1; i++) { + if (!isprint(fdt_serial[i])) { + fdt_serial[0] = '\0'; + break; + } + } + if (fdt_serial[len - 1] != '\0') + fdt_serial[0] = '\0'; + } return (0); }