From 3488a599bfe0a92a0aec3cf421ef0c6f385f0737 Mon Sep 17 00:00:00 2001 From: James Churchill Date: Wed, 4 Dec 2024 17:56:39 +1100 Subject: [PATCH] Fix multi-line compatible parsing --- src/fdt/fdt-property-types.hpp | 2 +- src/fdt/fdt-view.cpp | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/fdt/fdt-property-types.hpp b/src/fdt/fdt-property-types.hpp index 35ba446..18fed62 100644 --- a/src/fdt/fdt-property-types.hpp +++ b/src/fdt/fdt-property-types.hpp @@ -26,7 +26,7 @@ struct property_info { }; const static QHash property_map = { - {"compatible", {property_type::string, word_size::custom}}, + {"compatible", {property_type::multiline, word_size::custom}}, {"phandle", {property_type::number, word_size::_32}}, {"pinctrl-names", {property_type::multiline, word_size::custom}}, }; diff --git a/src/fdt/fdt-view.cpp b/src/fdt/fdt-view.cpp index 662056d..ec0e552 100644 --- a/src/fdt/fdt-view.cpp +++ b/src/fdt/fdt-view.cpp @@ -41,11 +41,29 @@ string present(const fdt_property &property) { return name + " = \"" + value + "\";"; }; + auto result_multi = [&](auto &value) { + auto lines = value.split(0); + lines.removeLast(); + + string ret; + for (auto i = 0; i < lines.count(); ++i) { + if (i == lines.count() - 1) + ret += lines[i]; + else + ret += lines[i] + "\", \""; + } + + return result_str(std::move(ret)); + }; + if (property_map.contains(name)) { const property_info info = property_map.value(name); if (property_type::string == info.type) return result_str({data}); + if (property_type::multiline == info.type) + return result_multi(data); + if (property_type::number == info.type) return result(string::number(convert(*reinterpret_cast(data.data())))); } @@ -57,18 +75,7 @@ string present(const fdt_property &property) { return result(string::number(convert(*reinterpret_cast(data.data())))); if (names_regexp.match(name).hasMatch()) { - auto lines = data.split(0); - lines.removeLast(); - - string ret; - for (auto i = 0; i < lines.count(); ++i) { - if (i == lines.count() - 1) - ret += lines[i]; - else - ret += lines[i] + ", "; - } - - return result_str(std::move(ret)); + return result_multi(data); } if (std::count_if(data.begin(), data.end(), [](auto &&value) { return value == 0x00; }) == 1 &&