Patch Detail
Show a patch.
GET /api/patches/9158/?format=api
{ "id": 9158, "url": "https://patchwork.libcamera.org/api/patches/9158/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9158/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200803211733.1037019-5-niklas.soderlund@ragnatech.se>", "date": "2020-08-03T21:17:28", "name": "[libcamera-devel,v6,4/9] libcamera: utils: Add method to lookup firmware ID in sysfs", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "61f6a91c0409f66053f830a0d73b0b583c17da8c", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9158/mbox/", "series": [ { "id": 1185, "url": "https://patchwork.libcamera.org/api/series/1185/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1185", "date": "2020-08-03T21:17:24", "name": "libcamera: Generate unique and stable camera IDs", "version": 6, "mbox": "https://patchwork.libcamera.org/series/1185/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9158/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9158/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 26877BD87B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 3 Aug 2020 21:18:05 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D2E7D61B02;\n\tMon, 3 Aug 2020 23:18:04 +0200 (CEST)", "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B7F54605A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 3 Aug 2020 23:18:01 +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 9db76d77-d5ce-11ea-86ee-0050569116f7;\n\tMon, 03 Aug 2020 23:16:37 +0200 (CEST)" ], "X-Halon-ID": "9db76d77-d5ce-11ea-86ee-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": "Mon, 3 Aug 2020 23:17:28 +0200", "Message-Id": "<20200803211733.1037019-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.28.0", "In-Reply-To": "<20200803211733.1037019-1-niklas.soderlund@ragnatech.se>", "References": "<20200803211733.1037019-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v6 4/9] libcamera: utils: Add method to\n\tlookup firmware ID in sysfs", "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 devices firmware description is recorded differently in sysfs\ndepending on if the devices uses OF or ACPI. Add a helper to abstract\nthis, allowing users to not 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/utils.h | 2 +\n src/libcamera/utils.cpp | 61 ++++++++++++++++++++++++++++++\n 2 files changed, 63 insertions(+)", "diff": "diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nindex 45cd6f120c51586b..69977340e2593db6 100644\n--- a/include/libcamera/internal/utils.h\n+++ b/include/libcamera/internal/utils.h\n@@ -200,6 +200,8 @@ details::StringSplitter split(const std::string &str, const std::string &delim);\n std::string libcameraBuildPath();\n std::string libcameraSourcePath();\n \n+int tryLookupFirmwareID(const std::string &devPath, std::string *id);\n+\n constexpr unsigned int alignDown(unsigned int value, unsigned int alignment)\n {\n \treturn value / alignment * alignment;\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex 615df46ac142a2a9..07ebce61f230e5f0 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -9,6 +9,7 @@\n \n #include <dlfcn.h>\n #include <elf.h>\n+#include <fstream>\n #include <iomanip>\n #include <limits.h>\n #include <link.h>\n@@ -444,6 +445,66 @@ std::string libcameraSourcePath()\n \treturn path + \"/\";\n }\n \n+/**\n+ * \\brief Try to read a device firmware ID from sysfs\n+ * \\param[in] devPath Path in sysfs to search\n+ * \\param[out] id Location to store ID if found\n+ *\n+ * The ID recorded in the devices firmware description is recorded differently\n+ * in sysfs depending on if the devices uses OF or ACPI. This helper abstracts\n+ * this away, allowing callers to not 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 -ENOMEM \\a id is nullptr\n+ * \\retval -EINVAL Error when looking up firmware ID\n+ * \\retval -ENODEV No firmware ID aviable for device\n+ */\n+int tryLookupFirmwareID(const std::string &devPath, std::string *id)\n+{\n+\tstruct stat statbuf;\n+\tstd::string path;\n+\n+\tif (!id)\n+\t\treturn -EINVAL;\n+\n+\t/* Try to lookup ID as if the system where OF-based. */\n+\tpath = devPath + \"/of_node\";\n+\tif (stat(path.c_str(), &statbuf) == 0) {\n+\t\tchar *ofPath = realpath(path.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/* Try to lookup ID as if the system where ACPI-based. */\n+\tpath = devPath + \"/firmware_node/path\";\n+\tif (stat(path.c_str(), &statbuf) == 0) {\n+\t\tstd::ifstream file(path.c_str());\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 /**\n * \\fn alignDown(unsigned int value, unsigned int alignment)\n * \\brief Align \\a value down to \\a alignment\n", "prefixes": [ "libcamera-devel", "v6", "4/9" ] }