From 50f93d14ff554f14265dc3d78e3785f6cd063eab Mon Sep 17 00:00:00 2001 From: vikke1234 Date: Thu, 13 Jul 2023 15:38:52 +0300 Subject: [PATCH] patterns/fdt: Fix flattened device tree parsing (#140) * Fix flattened device tree parsing Fix parsing to support multiple FDTs in a file and non-zero base addresses. * Fix string parsing Parent offset wasn't being taken into account when looking for prop names. --- patterns/fdt.pat | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/patterns/fdt.pat b/patterns/fdt.pat index 27fe0ea..04a4071 100644 --- a/patterns/fdt.pat +++ b/patterns/fdt.pat @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -26,7 +27,7 @@ struct AlignTo { struct FDTReserveEntry { u64 address; type::Size size; - + if (address == 0x00 && size == 0x00) break; }; @@ -51,7 +52,7 @@ struct FDTStructureBlock { u32 nameoff; char value[len]; AlignTo<4>; - char name[] @ parent.header.off_dt_strings + nameoff; + char name[] @ address(parent) + parent.header.off_dt_strings + nameoff; } else if (token == FDTToken::FDT_NOP || token == FDTToken::FDT_END_NODE) { // Nothing to do } else { @@ -62,9 +63,9 @@ struct FDTStructureBlock { struct FDT { FDTHeader header; std::assert(header.version == 17, "Unsupported format version"); - - FDTStructureBlock structureBlocks[while(true)] @ header.off_dt_struct; - FDTReserveEntry reserveEntries[while(true)] @ header.off_mem_rsvmap; + + FDTStructureBlock structureBlocks[while(true)] @ addressof(this) + header.off_dt_struct; + FDTReserveEntry reserveEntries[while(true)] @ addressof(this) + header.off_mem_rsvmap; }; -FDT fdt @ 0x00; \ No newline at end of file +std::mem::MagicSearch<"\xD0\x0D\xFE\xED", FDT> fdt @ std::mem::base_address();