forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdtdump.cpp
49 lines (37 loc) · 1.68 KB
/
fdtdump.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2021, Andrew Kaster <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/MappedFile.h>
#include <LibCore/System.h>
#include <LibDeviceTree/FlattenedDeviceTree.h>
#include <LibDeviceTree/Validation.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath"));
DeprecatedString filename;
Core::ArgsParser args;
args.add_positional_argument(filename, "File to process", "file", Core::ArgsParser::Required::Yes);
args.parse(arguments);
// FIXME: Figure out how to do this sanely from stdin
auto file = TRY(Core::MappedFile::map(filename));
if (file->size() < sizeof(DeviceTree::FlattenedDeviceTreeHeader)) {
warnln("Not enough data in {} to contain a device tree header!", filename);
return 1;
}
auto const* fdt_header = reinterpret_cast<DeviceTree::FlattenedDeviceTreeHeader const*>(file->data());
auto bytes = ReadonlyBytes { file->data(), file->size() };
TRY(DeviceTree::dump(*fdt_header, bytes));
auto compatible = TRY(DeviceTree::slow_get_property<StringView>("/compatible"sv, *fdt_header, bytes));
auto compatible_strings = compatible.split_view('\0');
dbgln("compatible with: {}", compatible_strings);
auto bootargs = TRY(DeviceTree::slow_get_property<StringView>("/chosen/bootargs"sv, *fdt_header, bytes));
dbgln("bootargs: {}", bootargs);
auto cpu_compatible = TRY(DeviceTree::slow_get_property<StringView>("/cpus/cpu@0/compatible"sv, *fdt_header, bytes));
dbgln("cpu0 compatible: {}", cpu_compatible);
return 0;
}