Device tree compiler and inspector in pure MoonBit: DTS to DTB, DTB back to DTS, and overlay application, with no dtc binary present.
| Capability | Status |
|---|---|
| 40-byte blob header, version 17 | done |
| Block tiling and alignment validation | done |
| Bounds-checked primitive reads | done |
| Struct block walk (nodes, properties) | done |
| Strings block lookup | done |
| Nesting limit and cycle guard | done |
| DTS lexer: identifiers, strings, numbers, comments | done |
| DTS parser: nodes, properties, typed values | done |
| Labels, &label and &{/path} references | done |
| /bits/ and /memreserve/ | done |
| DTB writer | done |
| Byte-identical to dtc on all three fixtures | done |
| CLI: compile and dump modes | done |
| Reference resolution, phandle assignment | done |
| DTS emitter | not started |
| Overlay application | not started |
moon testmoon run cmd/main -- internal/fixtures/nested.dts -o /tmp/out.dtb
dtc -q -I dts -O dtb -o /tmp/dtc.dtb internal/fixtures/nested.dts
cmp /tmp/out.dtb /tmp/dtc.dtb| File | Contents |
|---|---|
| dtbscope.mbt | Error type, cursor, hex formatting |
| reader.mbt | Bounds-checked reads of the primitive types |
| header.mbt | Blob header parse and validation |
| struct_block.mbt | Token walk, node tree, structural warnings |
| dts_token.mbt | Token kinds, spans, scanner state |
| dts_lex.mbt | Character rules and token scanning |
| dts_parse.mbt | Source grammar, value parsing, source tree |
| phandle.mbt | Label table, phandle numbering, reference rewrite |
| dtb_write.mbt | Blob encoder |
| cmd/main/ | Command line front end |
| tools/gen-fixtures.sh | Fixture regeneration |
| internal/fixtures/ | DTS sources and their compiled DTBs |
pub(all) suberror DtbError {
UnexpectedEnd(offset~ : Int64, needed~ : Int64, available~ : Int64)
BadMagic(magic~ : UInt)
BadValue(field~ : String, value~ : Int64)
OutOfBounds(what~ : String, offset~ : Int64, size~ : Int64, limit~ : Int64)
BadName(offset~ : Int64)
Inconsistent(what~ : String, detail~ : String)
LimitExceeded(what~ : String, limit~ : Int64)
Unsupported(what~ : String)
}impl Show for LexerErrorpub(all) suberror OverlayError {
UnknownSymbol(label~ : String)
MissingTarget(path~ : String)
BadFixup(detail~ : String)
NoSymbols
BadFragment(name~ : String)
Resolve(inner~ : ResolveError)
}impl Show for OverlayErrorpub(all) suberror ParseError {
Unexpected(token~ : TokenKind, expected~ : String, span~ : Span)
Lexical(inner~ : LexerError)
BadValue(detail~ : String, span~ : Span)
LimitExceeded(what~ : String, limit~ : Int)
Unsupported(what~ : String, span~ : Span)
}impl Show for ParseErrorpub(all) suberror ResolveError {
UnknownLabel(label~ : String)
UnknownPath(path~ : String)
DuplicateLabel(label~ : String, first~ : String, second~ : String)
DuplicatePhandle(value~ : UInt, first~ : String, second~ : String)
BadPhandle(value~ : UInt, node~ : String)
}impl Show for ResolveErrorpub(all) struct Bounds {
bytes : Bytes
start : Int64
limit : Int64
}pub(all) enum Endian {
Little
Big
}pub(all) struct Header {
totalsize : Int64
off_dt_struct : Int64
off_dt_strings : Int64
off_mem_rsvmap : Int64
version : UInt
last_comp_version : UInt
boot_cpuid_phys : UInt
size_dt_strings : Int64
size_dt_struct : Int64
}pub(all) struct Lexer {
source : String
pos : Int
line : Int
column : Int
in_bytes : Bool
}pub(all) struct Property {
name : String
value : Bytes
offset : Int64
}pub(all) struct SourceFile {
root : SourceNode
memreserves : Array[(UInt64, UInt64)]
is_plugin : Bool
fragments : Array[Fragment]
}pub(all) struct SourceNode {
name : String
labels : Array[String]
properties : Array[SourceProperty]
children : Array[SourceNode]
}pub(all) struct Span {
line : Int
column : Int
}pub(all) enum StructTag {
BeginNode
EndNode
Prop
Nop
End
}pub(all) enum TokenKind {
Ident(String)
String(String)
Number(UInt64)
LBrace
RBrace
LAngle
RAngle
LBracket
RBracket
LParen
RParen
Comma
Semicolon
Equals
Slash
Amp
Colon
Minus
HexByte(Byte)
Eof
}pub(all) enum Warning {
MissingEnd(offset~ : Int64)
TrailingData(offset~ : Int64, remaining~ : Int64)
}Install
Download zipDevice tree compiler and inspector in pure MoonBit: DTS to DTB, DTB back to DTS, and overlay application, with no dtc binary present.