Skip to content

Commit

Permalink
fdt-v2: rename raw namespace to decode
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Burdukiewicz <bartlomiej.burdukiewicz@gmail.com>
  • Loading branch information
dev-0x7C6 committed Jul 2, 2024
1 parent 8906efe commit 69305d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
15 changes: 6 additions & 9 deletions src/fdt/fdt-header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include <types.hpp>

namespace fdt {

namespace raw {
namespace fdt::decode {
struct header {
u32 magic;
u32 totalsize;
Expand All @@ -22,18 +20,17 @@ struct property {
u32 len;
u32 nameoff;
};
}; // namespace raw

constexpr auto is_magic_invalid(const fdt::raw::header &v) -> bool {
constexpr auto is_magic_invalid(const header &v) -> bool {
constexpr auto header_magic_value = 0xD00DFEED;
return v.magic != header_magic_value;
}

constexpr auto is_version_unsupported(const fdt::raw::header &v) -> bool {
constexpr auto is_version_unsupported(const header &v) -> bool {
constexpr auto header_support_above = 16;
return v.version <= header_support_above;
}
}; // namespace fdt

static_assert(sizeof(fdt::raw::header) == 40);
static_assert(sizeof(fdt::raw::property) == 8);
} // namespace fdt::decode
static_assert(sizeof(fdt::decode::header) == 40);
static_assert(sizeof(fdt::decode::property) == 8);
10 changes: 5 additions & 5 deletions src/fdt/fdt-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ auto parse(token_types::node_end &&token, context &) -> fdt::parser::token {
}

auto parse(token_types::property &&token, context &ctx) -> fdt::parser::token {
const auto header = read_data_32be<fdt::raw::property>(ctx.state.data);
const auto header = read_data_32be<decode::property>(ctx.state.data);
ctx.state.skip += align(sizeof(header)) + align(header.len);
ctx.state.data += sizeof(header);

Expand Down Expand Up @@ -72,18 +72,18 @@ auto foreach_token_type(std::variant<Ts...>, const u32 token_id, fdt::parser::co
auto fdt::parser::parse(std::string_view view, std::string_view root_name) -> std::expected<fdt::parser::tokens, fdt::parser::error> {
using error = fdt::parser::error;

if (view.size() < sizeof(fdt::raw::header))
if (view.size() < sizeof(decode::header))
return std::unexpected(error::invalid_header);

const auto header = read_data_32be<fdt::raw::header>(view.data());
const auto header = read_data_32be<decode::header>(view.data());

if (fdt::is_magic_invalid(header))
if (decode::is_magic_invalid(header))
return std::unexpected(error::invalid_magic);

if (view.size() < header.totalsize)
return std::unexpected(error::data_truncated);

if (fdt::is_version_unsupported(header))
if (decode::is_version_unsupported(header))
return std::unexpected(error::unsupported_version);

const auto dt_struct = view.data() + header.off_dt_struct;
Expand Down

0 comments on commit 69305d3

Please sign in to comment.