Documentation ¶
Overview ¶
Package picfg models configuration files used by the Raspberry Pi bootloader
Implementation is based on the official documentation https://www.raspberrypi.org/documentation/configuration/config-txt/
A tl;dr; variant of the documentation is:
INI-style [section] key=value file with one exception when the key is "initramfs" then the value separator is " " instead of "=". Sections are stateful but this does not affect parsing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigTxt ¶
type ConfigTxt struct { Comments []string // Comments or white-space lines without trailing newlines. Sections []Section }
ConfigTxt represents the contents of a config.txt file.
The file is represented as a slice of sections. Each section starts with an optional conditional filter and is followed by a slice of parameters.
The representation can optionally preserve and restore comments. This makes round-trips less jarring, as comments are preserved and mostly retain their locations even when edited programmatically.
func (*ConfigTxt) Equal ¶ added in v1.4.0
Equal returns true if two configuration files are identical.
Equal checks that all the sections define the same parameters, in the same order and on the same line number. Equal also compares comments, even though if they have no semantic value.
func (ConfigTxt) MarshalText ¶
MarshalText implements TextMarshaler.
Comments are marshalled if present.
func (*ConfigTxt) UnmarshalText ¶
UnmarshalText implements TextUnmarshaler.
Parsed comments discarded. Create a new decoder and use PreserveComments before decoding to preserve them.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads and decodes config.txt from an input stream.
func NewDecoder ¶
NewDecoder returns a decoder that reads from r.
func (*Decoder) PreserveComments ¶ added in v1.1.0
func (dec *Decoder) PreserveComments()
PreserveComments makes the decoder preserve comments.
Comments are associated with files, sections, parameters.
IMPORTANT: Precise association of comments may change over time. All comments are parsed and preserved but the exact logic if a comment is associated to the preceding or following entity is not covered by API stability guarantees.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes and writes config.txt from an output stream.
func NewEncoder ¶
NewEncoder returns an encoder that writes to w.
type Location ¶
type Location struct { FileName string LineNo int // SeqNum is a sequence number, greater than zero and monotonically // increasing as the decoder reads files. Unlike LineNo, when an "include" // directive is read, the sequence number keeps increasing. // // Sequence number can be used to determine which of a pair of // parameters was read earlier. SeqNum uint }
Location pairs file name with a line number.
The decoder provides location for each section and parameter. The encoder ignores those values.
type Parameter ¶
type Parameter struct { Comments []string // Comments or white-space lines without trailing newlines. Name string Value string Location Location }
Parameter represents a single configurable entry.
Most parameters are represented as a key=value pair. Some keys can be assigned to multiple times for a stacking effect. This is not represented in the parser as the inner semantics of the firmware is not precisely documented.
As an exception, the "initramfs" key is not using "key=value" syntax and instead is using "key value", with a space instead of the equals sign.
func (*Parameter) Equal ¶ added in v1.4.0
Equal returns true if the two paramters have the same comments, name, value and location.
func (Parameter) MarshalText ¶
MarshalText implements TextMarshaler.
Comments do not undergo marshaling.
func (*Parameter) UnmarshalText ¶
UnmarshalText implements TextUnmarshaler.
Comments do not undergo marshaling.
type ParameterSyntaxError ¶
type ParameterSyntaxError struct {
Text []byte
}
ParameterSyntaxError reports inability to parse a key-value parameter.
func (*ParameterSyntaxError) Error ¶
func (err *ParameterSyntaxError) Error() string
Error implements the error interface.
type ParseError ¶
ParseError describes a parser error.
func (*ParseError) Unwrap ¶ added in v1.4.0
func (pe *ParseError) Unwrap() error
Unwrap returns the error that caused parsing to fail.
type Section ¶
type Section struct { Comments []string // Comments or white-space lines without trailing newlines. Filter string // Filter is either empty or matches /\[^]+\]/. Parameters []Parameter Location Location }
Section scopes parameters to an optional conditional filter.
The way a conditional filter impacts boot selection is stateful and depends on the filters in prior sections. To understand the effective set of filters that apply, use the StateTracker from the condfilter package. The parser does not offer this functionality.
Directories ¶
Path | Synopsis |
---|---|
Package condfilter implements conditional filters as distinct types.
|
Package condfilter implements conditional filters as distinct types. |