ECE 320 · Week 6
Modern Computer: Embedded Systems
Three labels an overlay needs for a stock driver: the compatible string, the bus address, and the status.
Week 6 of 10 · Das Frite
ECE 320 · Week 6 · In class
Three labels an overlay needs for a stock driver: the compatible string, the bus address, and the status.
- The lab binds the kernel's DS3231 driver.
- Show
/sysbefore the overlay and after it. - ECEC 201's C GPIO program is not this week's work.
ECE 320 · Week 6 · In class
The homework is those three labels and nothing else.
- No overlay source on the homework page.
- Disable the overlay on the second pass, confirm the earlier listing returns, and enable it again.
ECE 320 · Week 6 · Lecture
The kernel learns the board from the device tree
- The device tree is data, not code: nodes for buses and devices, each with properties.
- The running tree is visible under
/proc/device-tree, one directory per node. - A device on an I2C bus cannot announce itself; unless a node describes it, no driver binds it.
- An overlay adds or changes nodes in the base tree without rebuilding it.
ECE 320 · Week 6 · Lecture
The I2C pins on the header
- 3.3 V
- Ground
- I2C
Other pins are dimmed. Colours as on the Das Frite pinout, where each pin's name is. The square pad is pin 1.
ECE 320 · Week 6 · Lecture
Three labels a stock driver needs
| Property | Answers |
|---|---|
compatible | which driver: it must match a string the driver lists |
reg | where on the bus: for I2C, the device's 7-bit address |
status | whether to use it: "okay" or "disabled" |
The driver's string comes from its binding document; the address comes from the part's datasheet.
ECE 320 · Week 6 · Lecture
The shape of an overlay
/dts-v1/;
/plugin/;
&i2c_bus_label {
status = "okay";
mydev@48 {
compatible = "vendor,mydev";
reg = <0x48>;
status = "okay";
};
};
ECE 320 · Week 6 · Lecture
Compile it, then enable it with ldto
dtc -@ -I dts -O dtb -o mydev.dtbo mydev.dts
ldto list # the stock overlays
ldto info <stock> # shows the overlay directory
sudo cp mydev.dtbo <that directory>/
sudo ldto enable mydev # applied live, until reboot
ldto active # what is applied now
sudo ldto disable mydev
ldtoanddtcare on the image;-@keeps the labels the overlay refers to.
ECE 320 · Week 6 · Lecture
Proving it bound: /sys before and after
ls /sys/bus/i2c/devices/lists devices by bus number and address, such as1-0048.- Each device directory has a
driverlink once a driver binds; no link, no bind. - A bound driver may also add its own class directory, for example under
/sys/class/. - Take the "before" listing first: it is the only proof the overlay made the difference.
ECE 320 · Week 6 · Lab
Lab
- Read the live device tree.
- Write an overlay that binds the kernel's DS3231 driver, and show `/sys` before and after. Do not submit ECEC 201's C GPIO program. Second pass: disable the overlay, confirm the before listing returns, and enable it again.
- Assemble the lab hand-in: The overlay source that binds the DS3231, and the `/sys` listing from before and after.
ECE 320 · Week 6 · Lab
Hand in
The overlay source that binds the DS3231, and the `/sys` listing from before and after.
ECE 320 · Week 6 · Homework
Homework
- List the compatible string, the bus address, and the status as three labels, with no overlay source.
ECE 320 · Week 6 · Homework
Turn in
Those three labels.
ECE 320 · Week 6 · Read
Read
On the lab site: Module 9, Device tree and pin multiplexing. This week grades your overlay source and the two listings.
ECE 320 · Week 6 · Next
Week 7
How an I2C address byte differs from an SPI chip-select edge.