Skip to content

Commit ba6deee

Browse files
committed
新增 CLAUDE.md 文件,提供项目概述、构建系统、架构和测试指南
1 parent f7bfbb6 commit ba6deee

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

CLAUDE.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
`ostool` is a Rust-based OS development toolkit that simplifies building and testing operating systems with Qemu and U-Boot. The project consists of a main CLI tool (`ostool`) and a library (`uboot-shell`) for U-Boot communication.
8+
9+
## Build System
10+
11+
This is a Cargo workspace with two main members:
12+
- `ostool/` - Main CLI application
13+
- `uboot-shell/` - U-Boot communication library
14+
15+
### Common Commands
16+
17+
**Build the project:**
18+
```bash
19+
cargo build --workspace
20+
```
21+
22+
**Build release version:**
23+
```bash
24+
cargo build --workspace --release
25+
```
26+
27+
**Run tests:**
28+
```bash
29+
cargo test --workspace
30+
```
31+
32+
**Check code formatting:**
33+
```bash
34+
cargo fmt --all -- --check
35+
```
36+
37+
**Run linter:**
38+
```bash
39+
cargo clippy --workspace --all-features
40+
```
41+
42+
**Install local version:**
43+
```bash
44+
cargo install --path ostool
45+
```
46+
47+
The project uses Rust 2024 edition and requires `rust-objcopy` and `llvm-tools-preview` components.
48+
49+
## Architecture
50+
51+
### Core Components
52+
53+
**Main CLI (`ostool/src/main.rs`):**
54+
- Entry point with clap-based command parsing
55+
- Commands: `build`, `run qemu`, `run uboot`, `run tftp`, `cargo-test`, `board-test`, `defconfig`
56+
57+
**Project Management (`ostool/src/project.rs`):**
58+
- `Project` struct manages workspace, configuration, and build metadata
59+
- Handles `.project.toml` configuration files
60+
- Supports multiple architectures: aarch64, riscv64, x86_64
61+
62+
**Step System (`ostool/src/step/`):**
63+
- `Step` trait defines build pipeline operations
64+
- Concrete steps: `Compile`, `Qemu`, `Uboot`, `Tftp`, `CargoTestPrepare`
65+
- Each step can be executed sequentially in the pipeline
66+
67+
**Configuration (`ostool/src/config/`):**
68+
- `ProjectConfig` stores compile, Qemu, and U-Boot settings
69+
- Supports multiple build systems: Cargo, Custom shell commands
70+
- Configuration files use TOML format
71+
72+
**U-Boot Shell Library (`uboot-shell/`):**
73+
- Handles serial communication with U-Boot
74+
- Implements YMODEM protocol for file transfers
75+
- Provides shell-like interaction interface
76+
77+
### Configuration File Format
78+
79+
`.project.toml` structure:
80+
```toml
81+
[compile]
82+
target = "aarch64-unknown-none"
83+
84+
[compile.build.Custom]
85+
shell = ["make ARCH=aarch64"]
86+
kernel = "path/to/kernel.bin"
87+
88+
[qemu]
89+
machine = "virt"
90+
cpu = "cortex-a57"
91+
graphic = false
92+
93+
[uboot]
94+
serial = "COM3"
95+
baud_rate = 115200
96+
```
97+
98+
### Key Design Patterns
99+
100+
- **Step Pattern**: Operations implement `Step` trait for pipeline execution
101+
- **Configuration-driven**: Behavior controlled by TOML configuration files
102+
- **Multi-architecture**: Supports aarch64, riscv64, x86_64 through abstraction
103+
- **Workspace-aware**: Integrates with Cargo workspaces for metadata
104+
105+
## Testing
106+
107+
The project includes unit tests and integration tests. Use `cargo test` to run them. The CI workflow runs tests on x86_64 Linux and includes Qemu installation for integration testing.

0 commit comments

Comments
 (0)