Skip to content

Commit af3cb84

Browse files
committed
优化shell log
1 parent c9b3324 commit af3cb84

File tree

6 files changed

+290
-95
lines changed

6 files changed

+290
-95
lines changed

Cargo.lock

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

uboot-shell/Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
[package]
2-
name = "uboot-shell"
3-
version = "0.1.9"
4-
edition = "2024"
5-
description = "A crate for communicating with u-boot"
62
authors = ["周睿 <zrufo747@outlook.com>"]
7-
license = "MIT"
8-
keywords = ["u-boot", "shell", "embedded"]
93
categories = ["os", "embedded", "development-tools"]
4+
description = "A crate for communicating with u-boot"
5+
edition = "2024"
6+
keywords = ["u-boot", "shell", "embedded"]
7+
license = "MIT"
8+
name = "uboot-shell"
109
repository = "https://github.com/ZR233/ostool/ostool"
10+
version = "0.1.10"
1111

1212
[dependencies]
1313
colored = "3"
14+
log = "0.4"
1415

1516
[dev-dependencies]
17+
indicatif = "0.18"
1618
ntest = "0.9"
1719
serialport = "4.6"
18-
indicatif = "0.17"
20+
env_logger = "0.11"

uboot-shell/examples/loady.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
use std::{
2-
io::Read,
32
net::TcpStream,
4-
process::{Child, Command, Stdio},
3+
process::{Child, Command},
54
time::Duration,
65
};
76

7+
use log::{debug, info};
88
use uboot_shell::UbootShell;
99

1010
fn main() {
11+
env_logger::init();
12+
1113
let (mut out, mut uboot) = new_uboot();
1214

13-
uboot.loady(0x40200000, "Cargo.toml", |_r, _a| {}).unwrap();
15+
uboot
16+
.loady(0x40200000, "Cargo.toml", |r, a| {
17+
debug!("{r}/{a}");
18+
})
19+
.unwrap();
1420

15-
println!("finish");
21+
info!("finish");
1622
let _ = out.kill();
1723
let _ = out.wait();
1824
}
1925

2026
fn new_uboot() -> (Child, UbootShell) {
21-
// qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -bios assets/u-boot.bin
22-
let mut out = Command::new("qemu-system-aarch64")
27+
// qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -bios assets/u-boot.bin -serial tcp::12345,server
28+
let out = Command::new("qemu-system-aarch64")
2329
.args([
2430
"-machine",
2531
"virt",
2632
"-cpu",
2733
"cortex-a57",
2834
"-nographic",
2935
"-serial",
30-
"tcp::12345,server,nowait",
36+
"tcp::12345,server",
3137
"-bios",
3238
"assets/u-boot.bin",
3339
])
34-
.stdout(Stdio::piped())
3540
.spawn()
3641
.unwrap();
3742

38-
let stdout = out.stdout.take().unwrap();
39-
let mut buff = vec![];
40-
for i in stdout.bytes() {
41-
buff.push(i.unwrap());
42-
if String::from_utf8_lossy(&buff).contains("qemu") {
43-
break;
43+
let tx;
44+
45+
loop {
46+
std::thread::sleep(Duration::from_millis(100));
47+
match TcpStream::connect("127.0.0.1:12345") {
48+
Ok(s) => {
49+
tx = s;
50+
break;
51+
}
52+
Err(e) => {
53+
println!("wait for qemu serial port ready: {e}");
54+
}
4455
}
4556
}
4657

47-
let tx = TcpStream::connect("127.0.0.1:12345").unwrap();
48-
4958
let rx = tx.try_clone().unwrap();
50-
rx.set_read_timeout(Some(Duration::from_secs(1))).unwrap();
51-
59+
rx.set_read_timeout(Some(Duration::from_millis(300)))
60+
.unwrap();
61+
println!("connect ok");
5262
(out, UbootShell::new(tx, rx).unwrap())
5363
}

0 commit comments

Comments
 (0)