ladybird/Userland/Utilities/fdtdump.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/MappedFile.h>
2021-12-08 00:06:38 +03:00
#include <LibCore/System.h>
#include <LibDeviceTree/Validation.h>
2021-12-08 00:06:38 +03:00
#include <LibMain/Main.h>
2021-12-08 00:06:38 +03:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
2021-12-08 00:06:38 +03:00
TRY(Core::System::pledge("stdio rpath"));
DeprecatedString filename;
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);
// 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));
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));
return 0;
}