Skip to content

Commit 5551729

Browse files
committed
rename
1 parent 0d702c0 commit 5551729

9 files changed

Lines changed: 20 additions & 21 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
2-
members = ["dtb-early-console", "hello"]
2+
members = ["any-uart", "hello"]
33
resolver = "3"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DTB Early console
1+
# Any Uart
22

33
[![Check, Build and Test](https://github.com/rcore-os/dtb-earyly-console/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/rcore-os/dtb-earyly-console/actions/workflows/ci.yml)
44

@@ -25,7 +25,7 @@ fn phys_to_virt(addr: usize) -> *mut u8 {
2525
addr as *mut u8
2626
}
2727

28-
if let Some((mut tx, _rx)) = dtb_early_console::init(NonNull::new(dtb_addr).unwrap(), phys_to_virt) {
28+
if let Some((mut tx, _rx)) = any_uart::init(NonNull::new(dtb_addr).unwrap(), phys_to_virt) {
2929
let _ = tx.write_str_blocking("Hello, world!\n");
3030
}
3131
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "dtb-early-console"
2+
name = "any-uart"
33
version = "0.1.0"
44
edition = "2024"
55
authors = ["周睿 <zrufo747@outlook.com>"]
66
description = "Init early console from device tree, mostly for Arm"
77
keywords = ["pl011", "no-std", "earlycon", "dtb", "arm"]
88
license = "MIT"
99
categories = ["no-std", "embedded", "hardware-support"]
10-
repository = "https://github.com/rcore-os/dtb-earyly-console"
10+
repository = "https://github.com/rcore-os/any-uart"
1111
readme = "../README.md"
1212

1313
[dependencies]
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,25 @@ pub fn init(fdt_addr: NonNull<u8>, fn_phys_to_virt: FnPhysToVirt) -> Option<(Sen
7575
pub(crate) struct UartData {
7676
pub base: usize,
7777
pub io_kind: IoKind,
78-
pub phys_to_virt: FnPhysToVirt,
7978
}
8079

8180
impl UartData {
81+
fn new(base: u64, io_kind: IoKind, f: FnPhysToVirt) -> Self {
82+
let mmio = f(base as _);
83+
84+
Self {
85+
base: mmio as _,
86+
io_kind,
87+
}
88+
}
89+
8290
pub fn reg_u8(&self, offset: usize) -> *mut u8 {
8391
self.reg(offset)
8492
}
8593

8694
pub fn reg<T: Sized>(&self, offset: usize) -> *mut T {
8795
unsafe {
88-
let ptr = (self.phys_to_virt)(self.base) as *mut T;
96+
let ptr = self.base as *mut T;
8997
ptr.add(offset)
9098
}
9199
}
@@ -95,12 +103,7 @@ fn fdt_stdout(chosen: &Chosen<'_>, f: FnPhysToVirt) -> Option<(Sender, Receiver)
95103
let stdout = chosen.stdout()?;
96104
let reg = stdout.node.reg()?.next()?;
97105
let io_kind = IoKind::Mmio32;
98-
let mmio = reg.address as usize;
99-
let uart = UartData {
100-
base: mmio,
101-
io_kind,
102-
phys_to_virt: f,
103-
};
106+
let uart = UartData::new(reg.address, io_kind, f);
104107

105108
for c in stdout.node.compatibles() {
106109
macro_rules! of_uart {
@@ -189,12 +192,8 @@ fn fdt_bootargs(chosen: &Chosen<'_>, f: FnPhysToVirt) -> Option<(Sender, Receive
189192
IoKind::from(param2)
190193
};
191194

192-
let mmio = u64::from_str_radix(addr_str.trim_start_matches("0x"), 16).ok()? as usize;
193-
let uart = UartData {
194-
base: mmio,
195-
io_kind,
196-
phys_to_virt: f,
197-
};
195+
let mmio = u64::from_str_radix(addr_str.trim_start_matches("0x"), 16).ok()?;
196+
let uart = UartData::new(mmio, io_kind, f);
198197

199198
if name.contains("8250") || name.contains("16550") {
200199
return Some(Ns16550::to_uart(uart));

hello/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
dtb-early-console = { path = "../dtb-early-console" }
7+
any-uart = { path = "../any-uart" }
88
fdt-parser = "0.4"
99

1010
[target.'cfg(target_arch = "aarch64")'.dependencies]

hello/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn rust_entry(_text_va: usize, fdt: *mut u8) -> ! {
7979
clean_bss();
8080
enable_fp();
8181

82-
if let Some((mut tx, _rx)) = dtb_early_console::init(NonNull::new(fdt).unwrap(), phys_to_virt) {
82+
if let Some((mut tx, _rx)) = any_uart::init(NonNull::new(fdt).unwrap(), phys_to_virt) {
8383
let _ = tx.write_str_blocking("Hello, world!\n");
8484

8585
let _ = tx.write_str_blocking("All tests passed!\n");

0 commit comments

Comments
 (0)