Skip to content

Commit b89eb2a

Browse files
committed
refactor: update dtbwalker to 0.1.3 for early qemu
Signed-off-by: YdrMaster <ydrml@hotmail.com>
1 parent e5ab409 commit b89eb2a

File tree

6 files changed

+40
-31
lines changed

6 files changed

+40
-31
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"rust.all_targets": false,
77
// For Rust Analyzer plugin users:
88
"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
9-
"rust-analyzer.checkOnSave.enable": false,
9+
"rust-analyzer.checkOnSave.allTargets": false,
1010
// Other settings
1111
// For clap
1212
"rust-analyzer.procMacro.attributes.enable": true,

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustsbi-qemu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ riscv = "0.8"
1111
spin = "0.9"
1212
r0 = "1"
1313
uart_16550 = "0.2"
14-
dtb-walker = "0.1.1"
14+
dtb-walker = "0.1.3"
1515
qemu-exit = "3.0"

rustsbi-qemu/src/device_tree.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<const N: usize> Display for StringInline<N> {
2727

2828
/// 解析设备树。
2929
pub(crate) fn parse(opaque: usize) -> BoardInfo {
30-
use dtb_walker::{Dtb, DtbObj, Property, WalkOperation::*};
30+
use dtb_walker::{Dtb, DtbObj, HeaderError as E, Property, WalkOperation::*};
3131
const CPUS: &[u8] = b"cpus";
3232
const MEMORY: &[u8] = b"memory";
3333
const SOC: &[u8] = b"soc";
@@ -44,7 +44,12 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
4444
test: 0..0,
4545
clint: 0..0,
4646
};
47-
let dtb = unsafe { Dtb::from_raw_parts(opaque as _) }.unwrap();
47+
let dtb = unsafe {
48+
Dtb::from_raw_parts_filtered(opaque as _, |e| {
49+
matches!(e, E::Misaligned(4) | E::LastCompVersion(16))
50+
})
51+
}
52+
.unwrap();
4853
ans.dtb.end += dtb.total_size();
4954
dtb.walk(|path, obj| match obj {
5055
DtbObj::SubNode { name } => {

test-kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ riscv = "0.8"
1313
spin = "0.9"
1414
r0 = "1"
1515
uart_16550 = "0.2"
16-
dtb-walker = "0.1.1"
16+
dtb-walker = "0.1.3"

test-kernel/src/main.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -260,31 +260,35 @@ struct BoardInfo {
260260
}
261261

262262
fn parse_smp(dtb_pa: usize) -> BoardInfo {
263-
use dtb_walker::{Dtb, DtbObj, Property, WalkOperation::*};
263+
use dtb_walker::{Dtb, DtbObj, HeaderError as E, Property, WalkOperation::*};
264264

265265
let mut ans = BoardInfo { smp: 0, uart: 0 };
266-
unsafe { Dtb::from_raw_parts(dtb_pa as _) }
267-
.unwrap()
268-
.walk(|path, obj| match obj {
269-
DtbObj::SubNode { name } => {
270-
if path.last().is_empty() && (name == b"cpus" || name == b"soc") {
271-
StepInto
272-
} else if path.last() == b"cpus" && name.starts_with(b"cpu@") {
273-
ans.smp += 1;
274-
StepOver
275-
} else if path.last() == b"soc" && name.starts_with(b"uart") {
276-
StepInto
277-
} else {
278-
StepOver
279-
}
266+
unsafe {
267+
Dtb::from_raw_parts_filtered(dtb_pa as _, |e| {
268+
matches!(e, E::Misaligned(4) | E::LastCompVersion(16))
269+
})
270+
}
271+
.unwrap()
272+
.walk(|path, obj| match obj {
273+
DtbObj::SubNode { name } => {
274+
if path.last().is_empty() && (name == b"cpus" || name == b"soc") {
275+
StepInto
276+
} else if path.last() == b"cpus" && name.starts_with(b"cpu@") {
277+
ans.smp += 1;
278+
StepOver
279+
} else if path.last() == b"soc" && name.starts_with(b"uart") {
280+
StepInto
281+
} else {
282+
StepOver
280283
}
281-
DtbObj::Property(Property::Reg(mut reg)) => {
282-
if path.last().starts_with(b"uart") {
283-
ans.uart = reg.next().unwrap().start;
284-
}
285-
StepOut
284+
}
285+
DtbObj::Property(Property::Reg(mut reg)) => {
286+
if path.last().starts_with(b"uart") {
287+
ans.uart = reg.next().unwrap().start;
286288
}
287-
DtbObj::Property(_) => StepOver,
288-
});
289+
StepOut
290+
}
291+
DtbObj::Property(_) => StepOver,
292+
});
289293
ans
290294
}

0 commit comments

Comments
 (0)