From 569166107d4ea17ca12288af0c74a90169aa2d5d Mon Sep 17 00:00:00 2001 From: Li Ming Date: Thu, 7 Sep 2023 18:17:05 +0800 Subject: [PATCH 1/6] feat: add new command ldr and str to load/store to memory --- apps/fs/shell/src/cmd.rs | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/apps/fs/shell/src/cmd.rs b/apps/fs/shell/src/cmd.rs index 23f087fe39..dd652e892d 100644 --- a/apps/fs/shell/src/cmd.rs +++ b/apps/fs/shell/src/cmd.rs @@ -27,6 +27,8 @@ const CMD_TABLE: &[(&str, CmdHandler)] = &[ ("pwd", do_pwd), ("rm", do_rm), ("uname", do_uname), + ("ldr", do_ldr), + ("str", do_str) ]; fn file_type_to_char(ty: FileType) -> char { @@ -272,6 +274,83 @@ fn do_exit(_args: &str) { std::process::exit(0); } +fn do_ldr(args: &str) { + println!("ldr"); + if args.is_empty() { + println!("try: ldr ffff0000400fe000 / ldr ffff000040080000 ffff000040080008"); + } + + fn ldr_one(addr: &str) -> io::Result<()> { + println!("addr = {}", addr); + + if let Ok(parsed_addr) = u64::from_str_radix(addr, 16) { + let address: *const u64 = parsed_addr as *const u64; // 强制转换为合适的指针类型 + + let value: u64; + println!("Parsed address: {:p}", address); // 打印地址时使用 %p 格式化符号 + + unsafe { + value = *address; + } + + println!("Value at address {}: 0x{:X}", addr, value); // 使用输入的地址打印值 + } else { + println!("Failed to parse address."); + } + return Ok(()); + } + + for addr in args.split_whitespace() { + if let Err(e) = ldr_one(addr) { + print_err!("ldr", addr, e); + } + } +} + +fn do_str(args: &str) { + println!("str"); + if args.is_empty() { + println!("try: str ffff0000400fe000 12345678"); + } + + fn str_one(addr: &str, val: &str) -> io::Result<()> { + println!("addr = {}", addr); + println!("val = {}", val); + + if let Ok(parsed_addr) = u64::from_str_radix(addr, 16) { + let address: *mut u64 = parsed_addr as *mut u64; // 强制转换为合适的指针类型 + println!("Parsed address: {:p}", address); // 打印地址时使用 %p 格式化符号 + + if let Ok(parsed_val) = u64::from_str_radix(val, 16) { + let value: u64 = parsed_val; // 不需要将值转换为指针类型 + println!("Parsed value: 0x{:X}", value); // 直接打印解析的值 + + unsafe { + *address = value; + } + + println!("Write value at address {}: 0x{:X}", addr, value); // 使用输入的地址打印值 + } + } else { + println!("Failed to parse address."); + } + + Ok(()) + } + + let mut split_iter = args.split_whitespace(); + + if let Some(addr) = split_iter.next() { + println!("First element: {}", addr); + + if let Some(val) = split_iter.next() { + println!("Second element: {}", val); + str_one(addr, val).unwrap(); // 调用 str_one 函数并传递 addr 和 val + } + } + +} + pub fn run_cmd(line: &[u8]) { let line_str = unsafe { core::str::from_utf8_unchecked(line) }; let (cmd, args) = split_whitespace(line_str); From 89f02220f7c62e9d7338a7ac0f79c84afe8803f9 Mon Sep 17 00:00:00 2001 From: Li Ming Date: Fri, 15 Sep 2023 11:51:20 +0800 Subject: [PATCH 2/6] feat: add apps/cli to build a shell-like console but without fs --- Cargo.lock | 7 ++ Cargo.toml | 2 + apps/cli/Cargo.toml | 19 ++++++ apps/cli/src/cmd.rs | 155 +++++++++++++++++++++++++++++++++++++++++++ apps/cli/src/main.rs | 73 ++++++++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 apps/cli/Cargo.toml create mode 100644 apps/cli/src/cmd.rs create mode 100644 apps/cli/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b305bb4329..87adb63259 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,13 @@ dependencies = [ "axstd", ] +[[package]] +name = "arceos-cli" +version = "0.1.0" +dependencies = [ + "axstd", +] + [[package]] name = "arceos-display" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1db098f126..d3916bd8a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,8 +70,10 @@ members = [ "apps/task/yield", "apps/task/priority", "apps/task/tls", + "apps/cli", ] + [profile.release] lto = true diff --git a/apps/cli/Cargo.toml b/apps/cli/Cargo.toml new file mode 100644 index 0000000000..f5a776b9c0 --- /dev/null +++ b/apps/cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "arceos-cli" +version = "0.1.0" +edition = "2021" +authors = ["Yuekai Jia "] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +# use-ramfs = ["axstd/myfs", "dep:axfs_vfs", "dep:axfs_ramfs", "dep:crate_interface"] +default = [] + +[dependencies] +# axfs_vfs = { path = "../../../crates/axfs_vfs", optional = true } +# axfs_ramfs = { path = "../../../crates/axfs_ramfs", optional = true } +# crate_interface = { path = "../../../crates/crate_interface", optional = true } +# axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs"], optional = true } + +axstd = { path = "../../ulib/axstd", optional = true } \ No newline at end of file diff --git a/apps/cli/src/cmd.rs b/apps/cli/src/cmd.rs new file mode 100644 index 0000000000..9fed8c4cb5 --- /dev/null +++ b/apps/cli/src/cmd.rs @@ -0,0 +1,155 @@ +use std::io::{self}; + +#[cfg(all(not(feature = "axstd"), unix))] + +macro_rules! print_err { + ($cmd: literal, $msg: expr) => { + println!("{}: {}", $cmd, $msg); + }; + ($cmd: literal, $arg: expr, $err: expr) => { + println!("{}: {}: {}", $cmd, $arg, $err); + }; +} + +type CmdHandler = fn(&str); + +const CMD_TABLE: &[(&str, CmdHandler)] = &[ + ("exit", do_exit), + ("help", do_help), + ("uname", do_uname), + ("ldr", do_ldr), + ("str", do_str) +]; + +fn do_uname(_args: &str) { + let arch = option_env!("AX_ARCH").unwrap_or(""); + let platform = option_env!("AX_PLATFORM").unwrap_or(""); + let smp = match option_env!("AX_SMP") { + None | Some("1") => "", + _ => " SMP", + }; + let version = option_env!("CARGO_PKG_VERSION").unwrap_or("0.1.0"); + println!( + "ArceOS {ver}{smp} {arch} {plat}", + ver = version, + smp = smp, + arch = arch, + plat = platform, + ); +} + +fn do_help(_args: &str) { + println!("Available commands:"); + for (name, _) in CMD_TABLE { + println!(" {}", name); + } +} + +fn do_exit(_args: &str) { + println!("Bye~"); + std::process::exit(0); +} + +fn do_ldr(args: &str) { + println!("ldr"); + if args.is_empty() { + println!("try: ldr ffff0000400fe000 / ldr ffff000040080000 ffff000040080008"); + } + + fn ldr_one(addr: &str) -> io::Result<()> { + println!("addr = {}", addr); + + if let Ok(parsed_addr) = u64::from_str_radix(addr, 16) { + let address: *const u64 = parsed_addr as *const u64; // 强制转换为合适的指针类型 + + let value: u64; + println!("Parsed address: {:p}", address); // 打印地址时使用 %p 格式化符号 + + unsafe { + value = *address; + } + + println!("Value at address {}: 0x{:X}", addr, value); // 使用输入的地址打印值 + } else { + println!("Failed to parse address."); + } + return Ok(()); + } + + for addr in args.split_whitespace() { + if let Err(e) = ldr_one(addr) { + println!("ldr {} {}", addr, e); + } + } +} + + +// use crate::mem::phys_to_virt; +// use core::ptr::{read_volatile, write_volatile}; + +fn do_str(args: &str) { + println!("str"); + if args.is_empty() { + println!("try: str ffff0000400fe000 12345678"); + } + + fn str_one(addr: &str, val: &str) -> io::Result<()> { + println!("addr = {}", addr); + println!("val = {}", val); + + if let Ok(parsed_addr) = u64::from_str_radix(addr, 16) { + let address: *mut u64 = parsed_addr as *mut u64; // 强制转换为合适的指针类型 + println!("Parsed address: {:p}", address); // 打印地址时使用 %p 格式化符号 + + if let Ok(parsed_val) = u32::from_str_radix(val, 16) { + let value: u64 = parsed_val as u64; // 不需要将值转换为指针类型 + println!("Parsed value: 0x{:X}", value); // 直接打印解析的值 + + // let ptr = phys_to_virt(parsed_addr.into()).as_mut_ptr() as *mut u32; + unsafe { + *address = value; + // write_volatile(address, value); + // write_volatile(ptr, value); + } + + println!("Write value at address {}: 0x{:X}", addr, value); // 使用输入的地址打印值 + } + } else { + println!("Failed to parse address."); + } + + Ok(()) + } + + let mut split_iter = args.split_whitespace(); + + if let Some(addr) = split_iter.next() { + println!("First element: {}", addr); + + if let Some(val) = split_iter.next() { + println!("Second element: {}", val); + str_one(addr, val).unwrap(); // 调用 str_one 函数并传递 addr 和 val + } + } + +} + +pub fn run_cmd(line: &[u8]) { + let line_str = unsafe { core::str::from_utf8_unchecked(line) }; + let (cmd, args) = split_whitespace(line_str); + if !cmd.is_empty() { + for (name, func) in CMD_TABLE { + if cmd == *name { + func(args); + return; + } + } + println!("{}: command not found", cmd); + } +} + +fn split_whitespace(str: &str) -> (&str, &str) { + let str = str.trim(); + str.find(char::is_whitespace) + .map_or((str, ""), |n| (&str[..n], str[n + 1..].trim())) +} diff --git a/apps/cli/src/main.rs b/apps/cli/src/main.rs new file mode 100644 index 0000000000..e10360e87d --- /dev/null +++ b/apps/cli/src/main.rs @@ -0,0 +1,73 @@ +#![cfg_attr(feature = "axstd", no_std)] +#![cfg_attr(feature = "axstd", no_main)] + +#[macro_use] +#[cfg(feature = "axstd")] +extern crate axstd as std; + +mod cmd; + +// #[cfg(feature = "use-ramfs")] +// mod ramfs; + +use std::io::prelude::*; + +const LF: u8 = b'\n'; +const CR: u8 = b'\r'; +const DL: u8 = b'\x7f'; +const BS: u8 = b'\x08'; +const SPACE: u8 = b' '; + +const MAX_CMD_LEN: usize = 256; + +fn print_prompt() { + // print!( + // "arceos:{}$ ", + // path_to_str!(std::env::current_dir().unwrap()) + // ); + print!("arceos# "); + std::io::stdout().flush().unwrap(); +} + +#[cfg_attr(feature = "axstd", no_mangle)] +fn main() { + let mut stdin = std::io::stdin(); + let mut stdout = std::io::stdout(); + + let mut buf = [0; MAX_CMD_LEN]; + let mut cursor = 0; + cmd::run_cmd("help".as_bytes()); + print_prompt(); + + loop { + if stdin.read(&mut buf[cursor..cursor + 1]).ok() != Some(1) { + continue; + } + if buf[cursor] == b'\x1b' { + buf[cursor] = b'^'; + } + match buf[cursor] { + CR | LF => { + println!(); + if cursor > 0 { + cmd::run_cmd(&buf[..cursor]); + cursor = 0; + } + print_prompt(); + } + BS | DL => { + if cursor > 0 { + stdout.write_all(&[BS, SPACE, BS]).unwrap(); + cursor -= 1; + } + } + 0..=31 => {} + c => { + if cursor < MAX_CMD_LEN - 1 { + stdout.write_all(&[c]).unwrap(); + cursor += 1; + } + } + } + } +} From 0f989237baf5202effe7e82724dcd76efe0b1869 Mon Sep 17 00:00:00 2001 From: Li Ming Date: Fri, 15 Sep 2023 12:00:08 +0800 Subject: [PATCH 3/6] feat: add apps/boards/raspi4 to build apps on raspi4 board --- Cargo.lock | 8 +++ Cargo.toml | 1 + apps/boards/raspi4/Cargo.toml | 12 ++++ apps/boards/raspi4/src/main.rs | 104 +++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 apps/boards/raspi4/Cargo.toml create mode 100644 apps/boards/raspi4/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 87adb63259..12d08af516 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,6 +141,14 @@ dependencies = [ "axstd", ] +[[package]] +name = "arceos-raspi4" +version = "0.1.0" +dependencies = [ + "arm_pl011", + "axstd", +] + [[package]] name = "arceos-shell" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index d3916bd8a7..2d41b98b64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ members = [ "apps/task/priority", "apps/task/tls", "apps/cli", + "apps/boards/raspi4", ] diff --git a/apps/boards/raspi4/Cargo.toml b/apps/boards/raspi4/Cargo.toml new file mode 100644 index 0000000000..20ba2836e1 --- /dev/null +++ b/apps/boards/raspi4/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "arceos-raspi4" +version = "0.1.0" +edition = "2021" +authors = ["Yuekai Jia "] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axstd = { path = "../../../ulib/axstd", optional = true } + +arm_pl011 = { version = "0.1.0", path = "../../../crates/arm_pl011" } \ No newline at end of file diff --git a/apps/boards/raspi4/src/main.rs b/apps/boards/raspi4/src/main.rs new file mode 100644 index 0000000000..1266b761be --- /dev/null +++ b/apps/boards/raspi4/src/main.rs @@ -0,0 +1,104 @@ +#![cfg_attr(feature = "axstd", no_std)] +#![cfg_attr(feature = "axstd", no_main)] + +#[cfg(feature = "axstd")] +use axstd::println; +use arm_pl011::pl011::Pl011Uart; + +#[cfg_attr(feature = "axstd", no_mangle)] +fn main() { + println!("Hello, world!"); + + fn delay(seconds: u64) { + for i in 1..seconds+1 { + println!("{} ", i); + + fn fibonacci_recursive(n: u64) -> u64 { + if n == 0 { + return 0; + } + if n == 1 { + return 1; + } + return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2); + } + + fibonacci_recursive(34 + (i % 2)); + } + } + + let uart_base = 0xffff_0000_fe20_1000 as *mut u8; + let mut uart = Pl011Uart::new(uart_base); + + println!("start"); + { + // 鸣笛:0xFF_FC_05_02_60_00_67 + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x05); + uart.putchar(0x02); + uart.putchar(0x60); + uart.putchar(0x00); + uart.putchar(0x67); + } + delay(1); + + loop { + println!("forward"); + { + // 前进:0xff_fc_07_11_01_01_64_00_7e + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x07); + uart.putchar(0x11); + uart.putchar(0x01); + uart.putchar(0x01); + uart.putchar(0x64); + uart.putchar(0x00); + uart.putchar(0x7e); + } + delay(4); + + println!("stop"); + { + // 停止:0xff_fc_07_11_01_00_00_00_19 + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x07); + uart.putchar(0x11); + uart.putchar(0x01); + uart.putchar(0x00); + uart.putchar(0x00); + uart.putchar(0x00); + uart.putchar(0x19); + } + delay(1); + + println!("turn left"); + { + // 左转:0xff_fc_07_11_01_05_64_00_82 + // uart.putchar(0xff); + // uart.putchar(0xfc); + // uart.putchar(0x07); + // uart.putchar(0x11); + // uart.putchar(0x01); + // uart.putchar(0x05); + // uart.putchar(0x64); + // uart.putchar(0x00); + // uart.putchar(0x82); + + // 右转:0xff_fc_07_11_01_06_64_00_83 + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x07); + uart.putchar(0x11); + uart.putchar(0x01); + uart.putchar(0x06); + uart.putchar(0x64); + uart.putchar(0x00); + uart.putchar(0x83); + } + delay(1); + } + +} From 5d111b5cc8cd8a4f0e779f0d054d8d673a0677b9 Mon Sep 17 00:00:00 2001 From: limingth Date: Fri, 15 Sep 2023 12:09:57 +0800 Subject: [PATCH 4/6] Add apps/cli/README.md to show how to run cli and test ldr/str --- apps/cli/README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 apps/cli/README.md diff --git a/apps/cli/README.md b/apps/cli/README.md new file mode 100644 index 0000000000..be7f8c1f90 --- /dev/null +++ b/apps/cli/README.md @@ -0,0 +1,97 @@ + +### How to test cli app +``` + +# make A=apps/cli ARCH=aarch64 LOG=debug + Building App: cli, Arch: aarch64, Platform: aarch64-qemu-virt, App type: rust +cargo build --target aarch64-unknown-none-softfloat --target-dir /root/Github/Chenlong/arceos/target --release --manifest-path apps/cli/Cargo.toml --features "axstd/log-level-debug" + Compiling axlog v0.1.0 (/root/Github/Chenlong/arceos/modules/axlog) + Compiling axio v0.1.0 (/root/Github/Chenlong/arceos/crates/axio) + Compiling axhal v0.1.0 (/root/Github/Chenlong/arceos/modules/axhal) + Compiling axruntime v0.1.0 (/root/Github/Chenlong/arceos/modules/axruntime) + Compiling axfeat v0.1.0 (/root/Github/Chenlong/arceos/api/axfeat) + Compiling arceos_api v0.1.0 (/root/Github/Chenlong/arceos/api/arceos_api) + Compiling axstd v0.1.0 (/root/Github/Chenlong/arceos/ulib/axstd) + Compiling arceos-cli v0.1.0 (/root/Github/Chenlong/arceos/apps/cli) + Finished release [optimized] target(s) in 1.56s +rust-objcopy --binary-architecture=aarch64 apps/cli/cli_aarch64-qemu-virt.elf --strip-all -O binary apps/cli/cli_aarch64-qemu-virt.bin + +# make A=apps/cli ARCH=aarch64 LOG=debug run + Building App: cli, Arch: aarch64, Platform: aarch64-qemu-virt, App type: rust +cargo build --target aarch64-unknown-none-softfloat --target-dir /root/Github/Chenlong/arceos/target --release --manifest-path apps/cli/Cargo.toml --features "axstd/log-level-debug" + Finished release [optimized] target(s) in 0.09s +rust-objcopy --binary-architecture=aarch64 apps/cli/cli_aarch64-qemu-virt.elf --strip-all -O binary apps/cli/cli_aarch64-qemu-virt.bin + Running on qemu... +qemu-system-aarch64 -m 128M -smp 1 -cpu cortex-a72 -machine virt -kernel apps/cli/cli_aarch64-qemu-virt.bin -nographic + + d8888 .d88888b. .d8888b. + d88888 d88P" "Y88b d88P Y88b + d88P888 888 888 Y88b. + d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b. + d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b. + d88P 888 888 888 88888888 888 888 "888 + d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P +d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P" + +arch = aarch64 +platform = aarch64-qemu-virt +target = aarch64-unknown-none-softfloat +smp = 1 +build_mode = release +log_level = debug + +[ 0.004989 0 axruntime:126] Logging is enabled. +[ 0.006520 0 axruntime:127] Primary CPU 0 started, dtb = 0x44000000. +[ 0.007244 0 axruntime:129] Found physcial memory regions: +[ 0.007958 0 axruntime:131] [PA:0x40080000, PA:0x40089000) .text (READ | EXECUTE | RESERVED) +[ 0.009000 0 axruntime:131] [PA:0x40089000, PA:0x4008c000) .rodata (READ | RESERVED) +[ 0.009624 0 axruntime:131] [PA:0x4008c000, PA:0x40090000) .data .tdata .tbss .percpu (READ | WRITE | RESERVED) +[ 0.010322 0 axruntime:131] [PA:0x40090000, PA:0x400d0000) boot stack (READ | WRITE | RESERVED) +[ 0.011015 0 axruntime:131] [PA:0x400d0000, PA:0x400d1000) .bss (READ | WRITE | RESERVED) +[ 0.011629 0 axruntime:131] [PA:0x400d1000, PA:0x48000000) free memory (READ | WRITE | FREE) +[ 0.012414 0 axruntime:131] [PA:0x9000000, PA:0x9001000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.013030 0 axruntime:131] [PA:0x8000000, PA:0x8020000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.013626 0 axruntime:131] [PA:0xa000000, PA:0xa004000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.014252 0 axruntime:131] [PA:0x10000000, PA:0x3eff0000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.014855 0 axruntime:131] [PA:0x4010000000, PA:0x4020000000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.015583 0 axruntime:149] Initialize platform devices... +[ 0.016038 0 axruntime:185] Primary CPU 0 init OK. +Available commands: + exit + help + uname + ldr + str +arceos# help +Available commands: + exit + help + uname + ldr + str +arceos# uname +ArceOS 0.1.0 aarch64 aarch64-qemu-virt +arceos# ldr +ldr +try: ldr ffff0000400fe000 / ldr ffff000040080000 ffff000040080008 +arceos# str +str +try: str ffff0000400fe000 12345678 +arceos# str ffff000040080000 11223344 +str +First element: ffff000040080000 +Second element: 11223344 +addr = ffff000040080000 +val = 11223344 +Parsed address: 0xffff000040080000 +Parsed value: 0x11223344 +Write value at address ffff000040080000: 0x11223344 +arceos# ldr ffff000040080000 +ldr +addr = ffff000040080000 +Parsed address: 0xffff000040080000 +Value at address ffff000040080000: 0x11223344 +arceos# exit +Bye~ +[ 46.110566 0 axhal::platform::aarch64_common::psci:96] Shutting down... +``` From 02295d32782bb6d20a944e0592c63719c78ded23 Mon Sep 17 00:00:00 2001 From: limingth Date: Fri, 15 Sep 2023 12:38:13 +0800 Subject: [PATCH 5/6] Add apps/boards/raspi4/README.md to show how to run raspi4 demo --- apps/boards/raspi4/README.md | 142 +++++++++++++++++++++++++++++++++++ scripts/make/qemu.mk | 11 ++- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 apps/boards/raspi4/README.md diff --git a/apps/boards/raspi4/README.md b/apps/boards/raspi4/README.md new file mode 100644 index 0000000000..040524a233 --- /dev/null +++ b/apps/boards/raspi4/README.md @@ -0,0 +1,142 @@ + +``` +# make A=apps/boards/raspi4 ARCH=aarch64 PLATFORM=aarch64-raspi4 LOG=debug SMP=4 run + Building App: raspi4, Arch: aarch64, Platform: aarch64-raspi4, App type: rust +cargo build --target aarch64-unknown-none-softfloat --target-dir /root/Github/Chenlong/arceos/target --release --manifest-path apps/boards/raspi4/Cargo.toml --features "axstd/log-level-debug axstd/smp" + Compiling axconfig v0.1.0 (/root/Github/Chenlong/arceos/modules/axconfig) + Compiling spinlock v0.1.0 (/root/Github/Chenlong/arceos/crates/spinlock) + Compiling axhal v0.1.0 (/root/Github/Chenlong/arceos/modules/axhal) + Compiling axlog v0.1.0 (/root/Github/Chenlong/arceos/modules/axlog) + Compiling axruntime v0.1.0 (/root/Github/Chenlong/arceos/modules/axruntime) + Compiling axfeat v0.1.0 (/root/Github/Chenlong/arceos/api/axfeat) + Compiling arceos_api v0.1.0 (/root/Github/Chenlong/arceos/api/arceos_api) + Compiling axstd v0.1.0 (/root/Github/Chenlong/arceos/ulib/axstd) + Compiling arceos-raspi4 v0.1.0 (/root/Github/Chenlong/arceos/apps/boards/raspi4) + Finished release [optimized] target(s) in 1.59s +rust-objcopy --binary-architecture=aarch64 apps/boards/raspi4/raspi4_aarch64-raspi4.elf --strip-all -O binary apps/boards/raspi4/raspi4_aarch64-raspi4.bin + Running on qemu... +emu-system-aarch64 -m 2G -smp 4 -cpu cortex-a72 -machine raspi4b2g -kernel apps/boards/raspi4/raspi4_aarch64-raspi4.bin -nographic + + d8888 .d88888b. .d8888b. + d88888 d88P" "Y88b d88P Y88b + d88P888 888 888 Y88b. + d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b. + d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b. + d88P 888 888 888 88888888 888 888 "888 + d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P +d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P" + +arch = aarch64 +platform = aarch64-raspi4 +target = aarch64-unknown-none-softfloat +smp = 4 +build_mode = release +log_level = debug + +[ 0.013401 axruntime:126] Logging is enabled. +[ 0.017938 axruntime:127] Primary CPU 0 started, dtb = 0x100. +[ 0.020174 axruntime:129] Found physcial memory regions: +[ 0.022343 axruntime:131] [PA:0x80000, PA:0x87000) .text (READ | EXECUTE | RESERVED) +[ 0.025306 axruntime:131] [PA:0x87000, PA:0x89000) .rodata (READ | RESERVED) +[ 0.027690 axruntime:131] [PA:0x89000, PA:0x8d000) .data .tdata .tbss .percpu (READ | WRITE | RESERVED) +[ 0.029109 axruntime:131] [PA:0x8d000, PA:0x18d000) boot stack (READ | WRITE | RESERVED) +[ 0.030433 axruntime:131] [PA:0x18d000, PA:0x18e000) .bss (READ | WRITE | RESERVED) +[ 0.031586 axruntime:131] [PA:0x0, PA:0x1000) spintable (READ | WRITE | RESERVED) +[ 0.032880 axruntime:131] [PA:0x18e000, PA:0xfc000000) free memory (READ | WRITE | FREE) +[ 0.034360 axruntime:131] [PA:0xfe201000, PA:0xfe202000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.035648 axruntime:131] [PA:0xff841000, PA:0xff849000) mmio (READ | WRITE | DEVICE | RESERVED) +[ 0.036969 axruntime:149] Initialize platform devices... +[ 0.038219 axruntime::mp:18] starting CPU 1... +[ 0.040891 axruntime::mp:35] Secondary CPU 1 started. +[ 0.045548 axruntime::mp:18] starting CPU 2... +[ 0.046443 axruntime::mp:45] Secondary CPU 1 init OK. +[ 0.055724 axruntime::mp:35] Secondary CPU 2 started. +[ 0.056580 axruntime::mp:18] starting CPU 3... +[ 0.058083 axruntime::mp:45] Secondary CPU 2 init OK. +[ 0.063700 axruntime::mp:35] Secondary CPU 3 started. +[ 0.064109 axruntime::mp:45] Secondary CPU 3 init OK. +[ 0.068492 axruntime:185] Primary CPU 0 init OK. +Hello, world! +start +??`g1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 +turn left +??d?1 +forward +??d~1 +2 +3 +4 +stop +??1 + +``` diff --git a/scripts/make/qemu.mk b/scripts/make/qemu.mk index 3ed4326140..c8acab2578 100644 --- a/scripts/make/qemu.mk +++ b/scripts/make/qemu.mk @@ -19,12 +19,21 @@ qemu_args-riscv64 := \ -bios default \ -kernel $(OUT_BIN) +ifeq ($(PLATFORM_NAME), aarch64-raspi4) +qemu_args-aarch64 := \ + -cpu cortex-a72 \ + -machine raspi4b2g \ + -kernel $(OUT_BIN) +qemu_args-y := -m 2G -smp $(SMP) $(qemu_args-$(ARCH)) +else qemu_args-aarch64 := \ -cpu cortex-a72 \ -machine virt \ -kernel $(OUT_BIN) - qemu_args-y := -m 128M -smp $(SMP) $(qemu_args-$(ARCH)) +endif + +#qemu_args-y := -m 128M -smp $(SMP) $(qemu_args-$(ARCH)) qemu_args-$(BLK) += \ -device virtio-blk-$(vdev-suffix),drive=disk0 \ From c21503a85e5d08f49d4e1e9e9473a334d4947f1a Mon Sep 17 00:00:00 2001 From: Li Ming Date: Sun, 17 Sep 2023 13:48:20 +0800 Subject: [PATCH 6/6] Add how to run five-angle-star path code --- apps/boards/raspi4/README.md | 7 ++++ apps/boards/raspi4/src/main.rs | 61 ++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/apps/boards/raspi4/README.md b/apps/boards/raspi4/README.md index 040524a233..2382fa00b6 100644 --- a/apps/boards/raspi4/README.md +++ b/apps/boards/raspi4/README.md @@ -1,4 +1,11 @@ +### 编译生成 img 文件的命令 +``` +make A=apps/boards/raspi4 ARCH=aarch64 PLATFORM=aarch64-raspi4 LOG=debug SMP=4 run +cat ../rust-raspberrypi-OS-tutorials/06_uart_chainloader/kernel8.img apps/boards/raspi4/raspi4_aarch64-raspi4.bin > kernel8.img +``` + +### 编译过程记录 ``` # make A=apps/boards/raspi4 ARCH=aarch64 PLATFORM=aarch64-raspi4 LOG=debug SMP=4 run Building App: raspi4, Arch: aarch64, Platform: aarch64-raspi4, App type: rust diff --git a/apps/boards/raspi4/src/main.rs b/apps/boards/raspi4/src/main.rs index 1266b761be..c51ba6c389 100644 --- a/apps/boards/raspi4/src/main.rs +++ b/apps/boards/raspi4/src/main.rs @@ -57,7 +57,7 @@ fn main() { uart.putchar(0x00); uart.putchar(0x7e); } - delay(4); + delay(6); println!("stop"); { @@ -74,9 +74,64 @@ fn main() { } delay(1); - println!("turn left"); + println!("turn right"); { - // 左转:0xff_fc_07_11_01_05_64_00_82 + // // 左转:0xff_fc_07_11_01_05_64_00_82 + // uart.putchar(0xff); + // uart.putchar(0xfc); + // uart.putchar(0x07); + // uart.putchar(0x11); + // uart.putchar(0x01); + // uart.putchar(0x05); + // uart.putchar(0x64); + // uart.putchar(0x00); + // uart.putchar(0x82); + + // 右转:0xff_fc_07_11_01_06_64_00_83 + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x07); + uart.putchar(0x11); + uart.putchar(0x01); + uart.putchar(0x06); + uart.putchar(0x64); + uart.putchar(0x00); + uart.putchar(0x83); + } + delay(1); + // println!("forward"); + // { + // // 前进:0xff_fc_07_11_01_01_64_00_7e + // uart.putchar(0xff); + // uart.putchar(0xfc); + // uart.putchar(0x07); + // uart.putchar(0x11); + // uart.putchar(0x01); + // uart.putchar(0x01); + // uart.putchar(0x64); + // uart.putchar(0x00); + // uart.putchar(0x7e); + // } + // delay(4); + + println!("stop"); + { + // 停止:0xff_fc_07_11_01_00_00_00_19 + uart.putchar(0xff); + uart.putchar(0xfc); + uart.putchar(0x07); + uart.putchar(0x11); + uart.putchar(0x01); + uart.putchar(0x00); + uart.putchar(0x00); + uart.putchar(0x00); + uart.putchar(0x19); + } + delay(1); + + println!("turn right"); + { + // // 左转:0xff_fc_07_11_01_05_64_00_82 // uart.putchar(0xff); // uart.putchar(0xfc); // uart.putchar(0x07);