Skip to content

Commit fb0dbeb

Browse files
committed
docs: add notes on extending intel_fw
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 85c3558 commit fb0dbeb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [`intel_fw`](intro.md)
22
- [Architecture and Design](architecture.md)
3+
- [Extend with new variants and features](extend.md)
34
- [Intel platforms](platforms.md)
45
- [Knowledge on Firmware Images](knowledge.md)
56
- [Obtaining firmware images](images.md)

docs/extend.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Extend with new variants and features
2+
3+
The following is a brief list of guiding principles to extend `intel_fw`.
4+
As a library, it should to adhere to those as requirements in order to provide
5+
guarantees to applications working with it. Generally, it should follow the
6+
[Rust API guidelines](https://rust-lang.github.io/api-guidelines/about.html).
7+
8+
## Do not panic!
9+
10+
Parsing firmware means looking for and acting on offsets and sizes frequently,
11+
and they always need to be checked to stay within the bounds of the given data.
12+
Never `unwrap()`, which means an _intentional panic_, in case something cannot
13+
be found, read, or recognized. Instead, return instances of `Self` for structs,
14+
wrapped in a `Result<Self, CustomError>` or possibly `Option<Self>`.
15+
16+
## Continuous parsing
17+
18+
There are circumstances under which a parser encounters an issue. It can be
19+
that offsets do not make sense, magic bytes (struct markers) are not as they
20+
were expected, or new variants are found with samples not encountered before.
21+
In those situations, it is desirable to follow a best-effort strategy. I.e.,
22+
when there is still remaining data that could be parsed, keep going.
23+
24+
## Let apps provide feedback
25+
26+
In other words, **let the consuming application take care** of taking the result
27+
apart. Nested structures mean that whenever a node in a graph turns into an
28+
`Error` or `None`, other nodes beside it may still provide useful information.
29+
That information helps the user of an app to understand the context and possibly
30+
report what they are facing or look into the issue themselves.
31+
32+
## Errors and context
33+
34+
In order to make sense of an error, context is important. During development, it
35+
can be helpful to print out information right within a specific parser. However,
36+
a final app is typically not run in development mode, but as a release. In that
37+
moment, semantic errors will help to identify possible problems. Include offsets
38+
and sizes (or `Range`s) for the application to tell exactly where the problem
39+
is, and it can choose to e.g. dump a contextual hex view on the data.

0 commit comments

Comments
 (0)