Open tomaka opened 4 years ago
The dtb
library has the advantage to be no_std
, meaning that we could parse the devicetree in order to determine the available memory before initializing the memory allocator.
More notes:
We could have a devicetree-interface
, making it possible for programs that have been loaded as drivers to get the devicetree nodes associated to them. This would be kind of similar to pci-interface
in that drivers use the environment to detect what they are supposed to run.
We could have a procedural macro taking a device tree as input (as a file or a string) that bundles all the necessary drivers automatically alongside with their devicetree nodes (w.r.t to the previous point).
I don't really know how to handle CPUs and memory. Maybe we could re-purpose standalone-kernel
as a library with a procedural macro, and let users do something like #[standalone_main(dtb_file = "foo.dtb")] fn main(_: impl PlatformSpecific) { }
.
For memory, we need a way to know the size of the kernel. I don't know how we can do that without using a custom linker scripts. This is unfortunate, as I'd prefer to be as target-agnostic as possible.
On platforms such as ARM or RISC-V we'll want to use device trees. (here's a good overview of device trees: http://www.ofitselfso.com/BeagleNotes/AboutTheDeviceTree.pdf)
This is related to how drivers should be loaded.
Some random notes:
Ideally, we would have some mapping between the possible values of
compatible
(cc https://www.kernel.org/doc/Documentation/devicetree/bindings/) and the hash of a driver module. This mapping would obviously have a trust factor in it.Obviously there's kind of an issue about loading drivers from the peer-to-peer network in that it would require an active network stack. Having a network stack probably requires 90% of the hardware's drivers to be bundled with the kernel, and at this point we might as well bundle the remaining 10%.
We could probably analyse device trees at compile-time and load the device drivers (either locally or from the peer-to-peer network) at compile-time before bundling them. The primary reason why Linux switched to device trees is so that people no longer need to add support for every single SoC to the upstream kernel, but I don't think being able to load devicetrees at runtime is important as long as compilation is easy.