summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2021-10-17 19:10:47 -0600
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-10-21 19:20:03 -0700
commit259ef765043caff5bbc1234c7b97270526bbb452 (patch)
tree0bf972c7d1c872eeae533c107a58d4d5dea37614 /Userland
parent644928314a4f33ed37d9998f44f9b4a2776aaec8 (diff)
downloadserenity-259ef765043caff5bbc1234c7b97270526bbb452.zip
Utilities: Add fdtdump for dumping OpenFirmware Device Trees
Use the new LibDeviceTree to dump the contents of the device tree blob (Flattened Device Tree) file passed on the command line.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/fdtdump.cpp44
2 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index cb95bc5391..a252b7c03d 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -62,6 +62,7 @@ target_link_libraries(copy LibGUI)
target_link_libraries(diff LibDiff)
target_link_libraries(disasm LibX86)
target_link_libraries(expr LibRegex)
+target_link_libraries(fdtdump LibDeviceTree)
target_link_libraries(file LibGfx LibIPC LibCompress)
target_link_libraries(functrace LibDebug LibX86)
target_link_libraries(gml-format LibGUI)
diff --git a/Userland/Utilities/fdtdump.cpp b/Userland/Utilities/fdtdump.cpp
new file mode 100644
index 0000000000..bc59de5543
--- /dev/null
+++ b/Userland/Utilities/fdtdump.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/MappedFile.h>
+#include <AK/String.h>
+#include <LibCore/ArgsParser.h>
+#include <LibDeviceTree/Validation.h>
+#include <serenity.h>
+
+int main(int argc, char* argv[])
+{
+ if (pledge("stdio rpath", nullptr) < 0) {
+ perror("pledge");
+ return 1;
+ }
+
+ String filename;
+
+ Core::ArgsParser args;
+ args.add_positional_argument(filename, "File to process", "file", Core::ArgsParser::Required::Yes);
+ args.parse(argc, argv);
+
+ // FIXME: Figure out how to do this sanely from stdin
+ auto maybe_file = MappedFile::map(filename);
+ if (maybe_file.is_error()) {
+ warnln("Unable to dump device tree from file {}: {}", filename, maybe_file.error().string());
+ return 1;
+ }
+ auto file = maybe_file.release_value();
+
+ if (file->size() < sizeof(DeviceTree::FlattenedDeviceTreeHeader)) {
+ warnln("Not enough data in {} to contain a device tree header!", filename);
+ return 1;
+ }
+
+ auto* fdt_header = reinterpret_cast<DeviceTree::FlattenedDeviceTreeHeader const*>(file->data());
+
+ bool valid = DeviceTree::dump(*fdt_header, static_cast<u8 const*>(file->data()), file->size());
+
+ return valid ? 0 : 1;
+}