2021-10-18 04:10:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
#include <AK/ByteString.h>
|
2021-10-18 04:10:47 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2021-11-23 13:32:25 +03:00
|
|
|
#include <LibCore/MappedFile.h>
|
2021-12-08 00:06:38 +03:00
|
|
|
#include <LibCore/System.h>
|
2023-02-13 01:52:16 +03:00
|
|
|
#include <LibDeviceTree/FlattenedDeviceTree.h>
|
2021-10-18 04:10:47 +03:00
|
|
|
#include <LibDeviceTree/Validation.h>
|
2021-12-08 00:06:38 +03:00
|
|
|
#include <LibMain/Main.h>
|
2021-10-18 04:10:47 +03:00
|
|
|
|
2021-12-08 00:06:38 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2021-10-18 04:10:47 +03:00
|
|
|
{
|
2021-12-08 00:06:38 +03:00
|
|
|
TRY(Core::System::pledge("stdio rpath"));
|
2021-10-18 04:10:47 +03:00
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
ByteString filename;
|
2021-10-18 04:10:47 +03:00
|
|
|
|
|
|
|
Core::ArgsParser args;
|
|
|
|
args.add_positional_argument(filename, "File to process", "file", Core::ArgsParser::Required::Yes);
|
2021-12-08 00:06:38 +03:00
|
|
|
args.parse(arguments);
|
2021-10-18 04:10:47 +03:00
|
|
|
|
|
|
|
// FIXME: Figure out how to do this sanely from stdin
|
2021-12-08 00:06:38 +03:00
|
|
|
auto file = TRY(Core::MappedFile::map(filename));
|
2021-10-18 04:10:47 +03:00
|
|
|
|
2023-09-12 21:21:23 +03:00
|
|
|
if (TRY(file->size()) < sizeof(DeviceTree::FlattenedDeviceTreeHeader)) {
|
2021-10-18 04:10:47 +03:00
|
|
|
warnln("Not enough data in {} to contain a device tree header!", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-17 20:25:55 +03:00
|
|
|
auto const* fdt_header = reinterpret_cast<DeviceTree::FlattenedDeviceTreeHeader const*>(file->data());
|
2023-09-26 01:54:34 +03:00
|
|
|
auto bytes = file->bytes();
|
2021-10-18 04:10:47 +03:00
|
|
|
|
2023-02-17 20:25:55 +03:00
|
|
|
TRY(DeviceTree::dump(*fdt_header, bytes));
|
2021-10-18 04:10:47 +03:00
|
|
|
|
2024-02-14 16:57:17 +03:00
|
|
|
auto compatible = TRY(DeviceTree::slow_get_property("/compatible"sv, *fdt_header, bytes)).as_strings();
|
|
|
|
dbgln("compatible with: {}", compatible);
|
2023-02-13 01:52:16 +03:00
|
|
|
|
2024-02-14 16:57:17 +03:00
|
|
|
auto bootargs = TRY(DeviceTree::slow_get_property("/chosen/bootargs"sv, *fdt_header, bytes)).as_string();
|
2023-02-13 01:52:16 +03:00
|
|
|
dbgln("bootargs: {}", bootargs);
|
|
|
|
|
2024-02-14 16:57:17 +03:00
|
|
|
auto cpu_compatible = TRY(DeviceTree::slow_get_property("/cpus/cpu@0/compatible"sv, *fdt_header, bytes)).as_string();
|
2023-02-13 01:52:16 +03:00
|
|
|
dbgln("cpu0 compatible: {}", cpu_compatible);
|
|
|
|
|
2023-02-17 20:25:55 +03:00
|
|
|
return 0;
|
2021-10-18 04:10:47 +03:00
|
|
|
}
|