Skip to content

Commit 6b04dbf

Browse files
committed
dts: only generate getters for okay nodes
Code generated for disabled nodes produces Rust compiler errors, thus we must not generate getters for unavailable nodes. Fixes building for RP2350 (otherwise passes and works). > A node is considered enabled if its status property > is either ``"okay"`` or not defined > For backwards compatibility, the value ``"ok"`` > is treated the same as ``"okay"`` Signed-off-by: Dmitrii Sharshakov <[email protected]>
1 parent dd73abc commit 6b04dbf

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

zephyr-build/src/devicetree/augment.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,31 @@ impl RawInfo {
191191
Self::Myself => {
192192
let ord = node.ord;
193193
let rawdev = format_ident!("__device_dts_ord_{}", ord);
194-
quote! {
195-
/// Get the raw `const struct device *` of the device tree generated node.
196-
pub unsafe fn get_instance_raw() -> *const crate::raw::device {
197-
&crate::raw::#rawdev
198-
}
199-
#[allow(dead_code)]
200-
pub(crate) unsafe fn get_static_raw() -> &'static #static_type {
201-
&STATIC
202-
}
194+
match node.get_single_string("status") {
195+
Some("okay") | Some("ok") | None => {
196+
quote! {
197+
/// Get the raw `const struct device *` of the device tree generated node.
198+
pub unsafe fn get_instance_raw() -> *const crate::raw::device {
199+
&crate::raw::#rawdev
200+
}
201+
#[allow(dead_code)]
202+
pub(crate) unsafe fn get_static_raw() -> &'static #static_type {
203+
&STATIC
204+
}
203205

204-
static UNIQUE: crate::device::Unique = crate::device::Unique::new();
205-
static STATIC: #static_type = #static_type::new();
206-
pub fn get_instance() -> Option<#device_id> {
207-
unsafe {
208-
let device = get_instance_raw();
209-
#device_id::new(&UNIQUE, &STATIC, device)
206+
static UNIQUE: crate::device::Unique = crate::device::Unique::new();
207+
static STATIC: #static_type = #static_type::new();
208+
pub fn get_instance() -> Option<#device_id> {
209+
unsafe {
210+
let device = get_instance_raw();
211+
#device_id::new(&UNIQUE, &STATIC, device)
212+
}
213+
}
210214
}
211215
}
216+
_ => {
217+
quote! {}
218+
}
212219
}
213220
}
214221
Self::Phandle(pname) => {

0 commit comments

Comments
 (0)