{"id":9185,"url":"https://patchwork.libcamera.org/api/1.1/patches/9185/?format=json","web_url":"https://patchwork.libcamera.org/patch/9185/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200804161358.1628962-3-niklas.soderlund@ragnatech.se>","date":"2020-08-04T16:13:51","name":"[libcamera-devel,v7,2/9] libcamera: sysfs: Add method to lookup firmware ID","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1ed391979a8f5230a153a29398853cbb71ff1ccf","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9185/mbox/","series":[{"id":1190,"url":"https://patchwork.libcamera.org/api/1.1/series/1190/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1190","date":"2020-08-04T16:13:49","name":"libcamera: Generate unique and stable camera IDs","version":7,"mbox":"https://patchwork.libcamera.org/series/1190/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9185/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9185/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 417EEBD87A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Aug 2020 16:14:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ECCF160555;\n\tTue,  4 Aug 2020 18:14:24 +0200 (CEST)","from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C29660547\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Aug 2020 18:14:21 +0200 (CEST)","from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de\n\t[84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 8d526a04-d66d-11ea-b48b-0050569116f7;\n\tTue, 04 Aug 2020 18:14:20 +0200 (CEST)"],"X-Halon-ID":"8d526a04-d66d-11ea-b48b-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  4 Aug 2020 18:13:51 +0200","Message-Id":"<20200804161358.1628962-3-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20200804161358.1628962-1-niklas.soderlund@ragnatech.se>","References":"<20200804161358.1628962-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v7 2/9] libcamera: sysfs: Add method to\n\tlookup firmware ID","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"A systems firmware description is recorded differently in sysfs\ndepending if the system uses OF or ACPI. Add a helper to abstract\nthis, allowing users not to care which of the two are used.\n\nFor OF-based systems the ID is the full path of the device in the\ndevice tree description. For ACPI-based systems the ID is the ACPI\nfirmware nodes path. Both ID sources are guaranteed to be unique and\npersistent as long as the firmware of the system is not changed.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/internal/sysfs.h |  2 ++\n src/libcamera/sysfs.cpp            | 57 ++++++++++++++++++++++++++++++\n 2 files changed, 59 insertions(+)","diff":"diff --git a/include/libcamera/internal/sysfs.h b/include/libcamera/internal/sysfs.h\nindex 72f436205d8d30e8..ef8ec55909d85bf9 100644\n--- a/include/libcamera/internal/sysfs.h\n+++ b/include/libcamera/internal/sysfs.h\n@@ -15,6 +15,8 @@ namespace sysfs {\n \n std::string charDevPath(const std::string &devicePath);\n \n+int firmwareId(const std::string &path, std::string *id);\n+\n } /* namespace sysfs */\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/sysfs.cpp b/src/libcamera/sysfs.cpp\nindex 3b2920663e9c3bcc..98be4df9d38e6fa8 100644\n--- a/src/libcamera/sysfs.cpp\n+++ b/src/libcamera/sysfs.cpp\n@@ -7,9 +7,11 @@\n \n #include \"libcamera/internal/sysfs.h\"\n \n+#include <fstream>\n #include <sys/stat.h>\n #include <sys/sysmacros.h>\n \n+#include \"libcamera/internal/file.h\"\n #include \"libcamera/internal/log.h\"\n \n /**\n@@ -43,6 +45,61 @@ std::string charDevPath(const std::string &devicePath)\n \treturn dev.str();\n }\n \n+/**\n+ * \\brief Try to read a device firmware ID from sysfs\n+ * \\param[in] path Path in sysfs to search\n+ * \\param[out] id Location to store ID if found\n+ *\n+ * A systems firmware description is recorded differently in sysfs depending if\n+ * the system uses OF or ACPI. Add a helper to abstract this, allowing users not\n+ * to care which of the two are used.\n+ *\n+ * For OF-based systems the ID is the full path of the device in the device tree\n+ * description. For ACPI-based systems the ID is the ACPI firmware nodes path.\n+ * Both ID sources are guaranteed to be unique and persistent as long as the\n+ * firmware of the system is not changed.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -EINVAL Error when looking up firmware ID\n+ * \\retval -ENODEV No firmware ID available for \\a path\n+ */\n+int firmwareId(const std::string &path, std::string *id)\n+{\n+\tASSERT(id);\n+\n+\t/* ID lookup for OF-based systems */\n+\tFile ofFile(path + \"/of_node\");\n+\tif (ofFile.exists()) {\n+\t\tchar *ofPath = realpath(ofFile.fileName().c_str(), nullptr);\n+\t\tif (!ofPath)\n+\t\t\treturn -EINVAL;\n+\n+\t\t*id = ofPath;\n+\t\tfree(ofPath);\n+\n+\t\tstatic const std::string dropStr = \"/sys/firmware/devicetree/\";\n+\t\tif (id->find(dropStr) == 0)\n+\t\t\tid->erase(0, dropStr.length());\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/* ID lookup for ACPI-based systems */\n+\tFile acpiFile(path + \"/firmware_node/path\");\n+\tif (acpiFile.exists()) {\n+\t\tstd::ifstream file(acpiFile.fileName());\n+\t\tif (!file.is_open())\n+\t\t\treturn -EINVAL;\n+\n+\t\tstd::getline(file, *id);\n+\t\tfile.close();\n+\n+\t\treturn 0;\n+\t}\n+\n+\treturn -ENODEV;\n+}\n+\n } /* namespace sysfs */\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v7","2/9"]}