1
1
Fork
You've already forked smoldtb
1

[DRAFT] Updating README and API documentation #1

Open
dreamos82 wants to merge 14 commits from dreamos82/smoldtb:update_documentation into master
pull from: dreamos82/smoldtb:update_documentation
merge into: r4:master
r4:master
Contributor
Copy link
No description provided.
API.md Outdated
@ -7,6 +7,22 @@ The API is split into three main groups of functions:
While the device tree specification (v0.4 at the time of writing) uses big-endian integers, the API for smoldtb uses the native endianness of the machine it was compiled for. It will handle the conversion to big-endian internally (if necessary).
## The basic workflow
Owner
Copy link

Capitalize title: The Basic Workflow

Capitalize title: `The Basic Workflow`
API.md Outdated
@ -9,1 +9,4 @@
## The basic workflow
Since every node in the dtb is different, is not possible to make assumptions on its format, so usually we should know what is the format of the node we are looking for.
Owner
Copy link

I think we can be more certain about what we're saying here: its not possible to make assumptions about its format, so we will need to know the format (properties and possible sub-nodes) we are looking for ahead of time.

I think we can be more certain about what we're saying here: `its not possible to make assumptions about its format, so we will need to know the format (properties and possible sub-nodes) we are looking for ahead of time.`
API.md Outdated
@ -10,0 +13,4 @@
To access a resource on the dtb, the workflow is more or less the same (assuming that the dtb has been correctly initialized):
* Identify the node that needs to be searched
Owner
Copy link

to be searched -> that we're looking for.

`to be searched` -> `that we're looking for`.
API.md Outdated
@ -10,0 +15,4 @@
* Identify the node that needs to be searched
* Search for it on the device tree, using the the `dtb_find` function
* If the node has been found, it's time to read the properties or children nodes in case we need. Using the function `dtb_stat_node` information about the topology of a node can be read.
Owner
Copy link

dtb_stat_node is really just a nice-to-have, its doesnt provide any practical uses for the dtb. While it can be nice to print this info, I'd phrase this step as something like For debugging it can be helpful to view some basic info about the node, like the number of properties/children/siblings. Using the function dtb_stat_node we can get this information.

`dtb_stat_node` is really just a nice-to-have, its doesnt provide any practical uses for the dtb. While it can be nice to print this info, I'd phrase this step as something like `For debugging it can be helpful to view some basic info about the node, like the number of properties/children/siblings. Using the function `dtb_stat_node` we can get this information.`
API.md Outdated
@ -10,0 +16,4 @@
* Identify the node that needs to be searched
* Search for it on the device tree, using the the `dtb_find` function
* If the node has been found, it's time to read the properties or children nodes in case we need. Using the function `dtb_stat_node` information about the topology of a node can be read.
* To get properties the functions `dtb_get_prop` or `dtb_find_prop` with the property needed can be used
Owner
Copy link

the end of this sentence has a weird flow, try the dtb_get_propordtb_find_prop functions can be used to locate the property of interest.

the end of this sentence has a weird flow, try `the `dtb_get_prop` or `dtb_find_prop` functions can be used to locate the property of interest.`
API.md Outdated
@ -10,0 +17,4 @@
* Search for it on the device tree, using the the `dtb_find` function
* If the node has been found, it's time to read the properties or children nodes in case we need. Using the function `dtb_stat_node` information about the topology of a node can be read.
* To get properties the functions `dtb_get_prop` or `dtb_find_prop` with the property needed can be used
- If a property has been found now is time to read its values using the `function read_prop_(values, pairs, triplets, quads)`
Owner
Copy link

code formatting starts too early.
Also all of these dot points are missing full stops on the end

code formatting starts too early. Also all of these dot points are missing full stops on the end
@ -10,0 +18,4 @@
* If the node has been found, it's time to read the properties or children nodes in case we need. Using the function `dtb_stat_node` information about the topology of a node can be read.
* To get properties the functions `dtb_get_prop` or `dtb_find_prop` with the property needed can be used
- If a property has been found now is time to read its values using the `function read_prop_(values, pairs, triplets, quads)`
* In case of parsing nodes, a good idea is first to call the `dtb_stat_node` function that populate a `dtb_node_stat` struct, and will contain the number of children, siblings and properties.
Owner
Copy link

again, this is nice for debugging info and viewing the layout of the tree, but its not needed for general use of the library. In fact using it will slow down your code, so I wouldnt advise it as a good idea. Mentioning that it exists and where it might be useful is good I think, but not for general operation.

again, this is nice for debugging info and viewing the layout of the tree, but its not needed for general use of the library. In fact using it will slow down your code, so I wouldnt advise it as a good idea. Mentioning that it exists and where it might be useful is good I think, but not for general operation.
dreamos82 marked this conversation as resolved
API.md Outdated
@ -10,0 +20,4 @@
- If a property has been found now is time to read its values using the `function read_prop_(values, pairs, triplets, quads)`
* In case of parsing nodes, a good idea is first to call the `dtb_stat_node` function that populate a `dtb_node_stat` struct, and will contain the number of children, siblings and properties.
Examples of its usare are in the `examples/folder`
Owner
Copy link

Leftover from a previous revision I think :)

Leftover from a previous revision I think :)
API.md Outdated
@ -36,3 +52,3 @@
`const char* dtb_read_string(dtb_prop* prop, size_t index)`: String-based properties can contain multiple null-terminated strings, `index` selects which string you want to read. If the index is out of bounds `NULL` is returned, otherwise a pointer to the ASCII-encoded text (as per the Device Tree v0.4 spec) is returned.
`size_t dtb_read_prop_values(dtb_prop* prop, size_t cell_count size_t* vals)`: The `cell_count` argument determines how many cells comprise a single value. This value is specific to the property you're trying to read and you should consult the spec about what to set this to. This function returns the number of values this property would contain for the given `cell_count`. If `vals` is non-null, this function will treat it as an array to write the values into. To use this function it's recommended to call it once with `vals = NULL` to determine how many values are present, then allocate space for the values, and then call the function again with `vals = your_buffer`.
`size_t dtb_read_prop_values(dtb_prop* prop, size_t cell_count, size_t* vals)`: The `cell_count` argument determines how many cells comprise a single value. This value is specific to the property you're trying to read and you should consult the spec about what to set this to. This function returns the number of values this property would contain for the given `cell_count` (remember that a `cell` is a unit of information consisting of 32 bits). If `vals` is non-null, this function will treat it as an array to write the values into. To use this function it's recommended to call it once with `vals = NULL` to determine how many values are present, then allocate space for the values, and then call the function again with `vals = your_buffer`.
Owner
Copy link

Lets keep any high level stuff about the format at the start of the docs, I dont think halfway through a function description is a good place to mention it. And these docs do expect you to be familiar with the device tree format, so I dont there's a need to repeat information that is covered in the DT spec. This may be harsh, but this isn't an educational resource about the DT format, just the library.

Lets keep any high level stuff about the format at the start of the docs, I dont think halfway through a function description is a good place to mention it. And these docs do expect you to be familiar with the device tree format, so I dont there's a need to repeat information that is covered in the DT spec. This may be harsh, but this isn't an educational resource about the DT format, just the library.
Examples.md Outdated
@ -0,0 +8,4 @@
The function below search for the root node, and prints the stat information associated with it. The information that we can obtain from the `dtb_stat_node` for a given node are:
* Its name
Owner
Copy link

All of these should end with full stops or commas. Also I wonder if this needs to be a list, or can be a regular sentence:

The information we can obtain from dtb_stat_node is: its name, and the numbers of children, siblings and properties.

All of these should end with full stops or commas. Also I wonder if this needs to be a list, or can be a regular sentence: > The information we can obtain from `dtb_stat_node` is: its name, and the numbers of children, siblings and properties.
Examples.md Outdated
@ -0,0 +14,4 @@
* Number of properties
```c
void read_node_stats() {
Owner
Copy link

opening curly brace on a new line please :)

opening curly brace on a new line please :)
@ -0,0 +19,4 @@
dtb_node_stat stat;
dtb_stat_node(node, &stat);
printf("%s: %lu siblings, %lu children, %lu properties.\r\n",
stat.name, stat.sibling_count, stat.child_count, stat.prop_count);
Owner
Copy link

some code style preferences: could you indent this line by 1 tab to show its a continuation of the previous statement

some code style preferences: could you indent this line by 1 tab to show its a continuation of the previous statement
dreamos82 marked this conversation as resolved
Examples.md Outdated
@ -0,0 +25,4 @@
## Read Properties of a Node
As an example, let's imagine we want to read the properties: `#address-cells` and `#size_cells`, these properties are quite special, since they specify the number of `<u32>` cells to represent the address and the size of the `reg` property in the children of the root node.
Owner
Copy link

I would break the sentence after #size-cells:

and #size-cells. These properties ...

and no need to specify what a cell is, the reader should already be familiar.

I would break the sentence after `#size-cells`: > and `#size-cells`. These properties ... and no need to specify what a cell is, the reader should already be familiar.
@ -0,0 +27,4 @@
As an example, let's imagine we want to read the properties: `#address-cells` and `#size_cells`, these properties are quite special, since they specify the number of `<u32>` cells to represent the address and the size of the `reg` property in the children of the root node.
After checking the dtb documentation, we know that both properties have a fixed size of a `<u32>` value.
Owner
Copy link

I'd reword this a little:

After checking the device tree specification, we know that both properties are encoded as a single cell.

I'd reword this a little: > After checking the device tree specification, we know that both properties are encoded as a single cell.
dreamos82 marked this conversation as resolved
@ -0,0 +31,4 @@
Assuming we got a reference to the root node the steps to get those properties are:
* Search for the property, using `dtb_find_prop` function
Owner
Copy link

end these with commas/full stops.

end these with commas/full stops.
dreamos82 marked this conversation as resolved
Examples.md Outdated
@ -0,0 +37,4 @@
The example below shows only how to get the `property_name` property, the code for the other one is the same.
```c
size_t read_cells_property(dtb_node *node, char *property_name) {
Owner
Copy link

opening curly brace on a newline.

opening curly brace on a newline.
Examples.md Outdated
@ -0,0 +41,4 @@
// To search a property we just need to pass the node containing it, and the property name
dtb_prop *addr_prop = dtb_find_prop(root_node, property_name);
if(addr_prop != NULL) {
// dtb_read_prop values requires three parameters: the property, the number of cells that compose a single value and the pointer to the variable that will contain the searched value
Owner
Copy link

underscore missing from function name.

underscore missing from function name.
@ -0,0 +48,4 @@
}
return 0;
}
```
Owner
Copy link

this example is actually wrong: dtb_read_prop_values (like all the other read_prop funcs) returns the number of elements that would be read for a given format. In this case the format is the number of cells.
The output is stored in an array, which is passed to the function as &address_cells in this case. So this example functions only returns the number of #address-cells or #size-cells properties, not their values.

It should look like:

size_t read_cells_property(dtb_node* node, const char* property_name)
{
 dtb_prop* prop = dtb_find_prop(node, property_name);
 if (prop == NULL)
 return 0;
 size_t result = 0;
 if (dtb_read_prop_values(prop, 1, &result) > 0)
 return result;
 return 0;
}
this example is actually wrong: `dtb_read_prop_values` (like all the other read_prop funcs) returns the number of elements that would be read for a given format. In this case the format is the number of cells. The output is stored in an array, which is passed to the function as `&address_cells` in this case. So this example functions only returns the number of `#address-cells` or `#size-cells` properties, not their values. It should look like: ```c size_t read_cells_property(dtb_node* node, const char* property_name) { dtb_prop* prop = dtb_find_prop(node, property_name); if (prop == NULL) return 0; size_t result = 0; if (dtb_read_prop_values(prop, 1, &result) > 0) return result; return 0; } ```
Author
Contributor
Copy link

not sure if i made the change requested or not.
And after 4 months i kind of forgot how smoldtb work! Btw can you confirm if i have made or not the change?

not sure if i made the change requested or not. And after 4 months i kind of forgot how smoldtb work! Btw can you confirm if i have made or not the change?
Examples.md Outdated
@ -0,0 +55,4 @@
```c
// These properties are stored in the root node, so we need a reference to it first
dtb_node *node = dtb_find("/");
if ( node != NULL) {
Owner
Copy link

change formatting to:

if (node != NULL)
{
change formatting to: ``` if (node != NULL) { ```
Examples.md Outdated
@ -0,0 +56,4 @@
// These properties are stored in the root node, so we need a reference to it first
dtb_node *node = dtb_find("/");
if ( node != NULL) {
size_t addr_size = read_cells_property(node, "#address-cells")
Owner
Copy link

missing semicolons

missing semicolons
@ -0,0 +61,4 @@
}
```
### Read properties using dtb_read_prop_pairs function (and friends)
Owner
Copy link

capitalize non-code parts of the title

capitalize non-code parts of the title
dreamos82 marked this conversation as resolved
@ -0,0 +63,4 @@
### Read properties using dtb_read_prop_pairs function (and friends)
Although we can use `dtb_read_prop_values`, in some cases the property values to be read are pairs, triplets, or quadruplets of values. Like in the `reg` property, where a typical value is similar to the following:
Owner
Copy link

nice example!

nice example!
dreamos82 marked this conversation as resolved
@ -0,0 +69,4 @@
reg = <0x00 0x80000000 0x00 0x8000000>;
```
the value type, according to the documentation is: ` <prop-encoded-array>` and every item in array is a pair of address and size. In this case we can make use of the `dtb_pair` struct, that it can contains a pair of values or a pair of value sizes. For example to read a value from a reg property:
Owner
Copy link

Capitalize start of the sentence.
Also I think the extra space at the start of the first code block can be removed :)

Capitalize start of the sentence. Also I think the extra space at the start of the first code block can be removed :)
dreamos82 marked this conversation as resolved
Examples.md Outdated
@ -0,0 +88,4 @@
// We return the number of pairs read
return number_of_pairs;
}
```
Owner
Copy link

This example is fine, but I think it might better to show reserving space for the returned values on the stack, as is the intended use-case. People can then choose not to use that method if they dont want to.
A lot of the comments here can be moved outside the code too, like assumptions about the global variables and description of the function arguments.
Would also be good to mention why we set the a and b fields of the layout to those values (because those are how each element of the reg property is described in the DT spec).

This example is fine, but I think it might better to show reserving space for the returned values on the stack, as is the intended use-case. People can then choose not to use that method if they dont want to. A lot of the comments here can be moved outside the code too, like assumptions about the global variables and description of the function arguments. Would also be good to mention why we set the `a` and `b` fields of the layout to those values (because those are how each element of the reg property is described in the DT spec).
dreamos82 marked this conversation as resolved
Examples.md Outdated
@ -0,0 +90,4 @@
}
```
The functions `dtb_read_prop_triplets` and `dtb_read_prop_quads` functon in the same way, with the exception that the layout and the values parameters are respectively of type: `dtb_triplet` and of `dtb_quad`
Owner
Copy link

nice, just a full stop at the end.

nice, just a full stop at the end.
@ -0,0 +92,4 @@
The functions `dtb_read_prop_triplets` and `dtb_read_prop_quads` functon in the same way, with the exception that the layout and the values parameters are respectively of type: `dtb_triplet` and of `dtb_quad`
## Read siblings of a node
Owner
Copy link

Capitalize title

Capitalize title
dreamos82 marked this conversation as resolved
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u update_documentation:dreamos82-update_documentation
git switch dreamos82-update_documentation

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff dreamos82-update_documentation
git switch dreamos82-update_documentation
git rebase master
git switch master
git merge --ff-only dreamos82-update_documentation
git switch dreamos82-update_documentation
git rebase master
git switch master
git merge --no-ff dreamos82-update_documentation
git switch master
git merge --squash dreamos82-update_documentation
git switch master
git merge --ff-only dreamos82-update_documentation
git switch master
git merge dreamos82-update_documentation
git push origin master
Sign in to join this conversation.
No reviewers
r4
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
r4/smoldtb!1
Reference in a new issue
r4/smoldtb
No description provided.
Delete branch "dreamos82/smoldtb:update_documentation"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?