Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

feat: Add pre-commit, typos, and git-cliff for automation and check #31

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: local
hooks:
- id: cargo-fmt
name: cargo fmt
description: Format files with rustfmt.
entry: bash -c 'cargo fmt -- --check'
language: rust
files: \.rs$
args: []
- id: typos
name: typos
description: check typo
entry: bash -c 'typos'
language: rust
files: \.*$
pass_filenames: false
- id: cargo-check
name: cargo check
description: Check the package for errors.
entry: bash -c 'cargo check --target riscv64imac-unknown-none-elf --all --no-default-features'
language: rust
files: \.rs$
pass_filenames: false
- id: cargo-clippy
name: cargo clippy
description: Lint rust sources
entry: bash -c 'cargo clippy --target riscv64imac-unknown-none-elf --all --no-default-features -- -D warnings'
language: rust
files: \.rs$
pass_filenames: false
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.

---
## [unreleased]
33 changes: 24 additions & 9 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ args = ["build", "-prustsbi-prototyper", "--release", "--features=nemu,payload"]

[tasks.prototyper-nemu]
command = "rust-objcopy"
args = ["--binary-architecture=riscv64", "target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper",
"--output-target=binary", "target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin"
args = [
"--binary-architecture=riscv64",
"target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper",
"--output-target=binary",
"target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin",
]
dependencies = ["prototyper-nemu-build"]

[tasks.prototyper-build]
command = "cargo"
args = ["build", "-prustsbi-prototyper", "--release", "--target", "riscv64imac-unknown-none-elf", "-Zbuild-std=core"]
env = {"RUSTFLAGS"="-C relocation-model=pie -C link-arg=-pie" }
args = [
"build",
"-prustsbi-prototyper",
"--release",
"--target",
"riscv64imac-unknown-none-elf",
"-Zbuild-std=core",
]
env = { "RUSTFLAGS" = "-C relocation-model=pie -C link-arg=-pie" }

[tasks.prototyper]
command = "rust-objcopy"
args = ["--binary-architecture=riscv64", "target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper",
"--output-target=binary", "target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin"
args = [
"--binary-architecture=riscv64",
"target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper",
"--output-target=binary",
"target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin",
]
dependencies = ["prototyper-build"]

Expand All @@ -34,8 +47,11 @@ args = ["build", "-prustsbi-test-kernel", "--release"]

[tasks.test-kernel]
command = "rust-objcopy"
args = ["--binary-architecture=riscv64", "target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel",
"--output-target=binary", "target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel.bin"
args = [
"--binary-architecture=riscv64",
"target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel",
"--output-target=binary",
"target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel.bin",
]
dependencies = ["test-kernel-build"]

Expand All @@ -48,4 +64,3 @@ rm rustsbi-test-kernel.its
cd ../../../
'''
dependencies = ["prototyper", "test-kernel"]

49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@

RustSBI Prototyper is a developing RISC-V Secure Bootloader solution. It can be integrated with the Rust or C language ecosystem to form a complete RISC-V bootloader ecosystem.

## Setting Up the Development Environment

### Install Cargo Make

Cargo Make is a Rust task runner and build tool, which is essential for development.

```bash
cargo install cargo-make
```

### Optional Tools

The following tools are not mandatory but can be useful for enhancing your development experience.

#### Install pre-commit

pre-commit is a tool that runs code checks before you commit your code.

```bash
pipx install pre-commit

# After installation, run pre-commit install to set it up for your project.
pre-commit install
```

#### Install Cargo Deny

Cargo deny is a Cargo plugin used to check the security of your dependencies.

```bash
cargo install --locked cargo-deny
```

#### Install typos

typos is a spell-checking tool.

```bash
cargo install typos-cli
```

#### Install git cliff

git cliff is a tool for generating changelogs.

```bash
cargo install git-cliff
```

## License

This project is dual-licensed under MIT or Mulan-PSL v2. See [LICENSE-MIT](./LICENSE-MIT) and [LICENSE-MULAN](./LICENSE-MULAN) for details.
7 changes: 7 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[default.extend-words]
rela = "rela"
sie = "sie"
stip = "stip"

[files]
extend-exclude = ["CHANGELOG.md"]
68 changes: 68 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[changelog]
header = """
# Changelog\n
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.\n
"""

body = """
---
{% if version %}
{% if previous.version %}
## [{{ version | trim_start_matches(pat="v") }}]($REPO/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% endif %}
{% else %}
## [unreleased]
{% endif %}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim | upper_first }}
{% for commit in commits | filter(attribute="scope") | sort(attribute="scope") %}
- **({{commit.scope}})**{% if commit.breaking %} [**breaking**]{% endif %} {{ commit.message|trim }} - ([{{ commit.id | truncate(length=7, end="") }}]($REPO/commit/{{ commit.id }})) - {{ commit.author.name }}
{%- endfor -%}
{% raw %}\n{% endraw %}
{%- for commit in commits %}
{%- if not commit.scope -%}
- {% if commit.breaking %} [**breaking**]{% endif %}{{ commit.message|trim }} - ([{{ commit.id | truncate(length=7, end="") }}]($REPO/commit/{{ commit.id }})) - {{ commit.author.name }}
{%- endif -%}
{% endfor -%}
{% endfor %}\n
"""

footer = "<!-- generated by git-cliff -->"
trim = true
postprocessors = [
{ pattern = '\$REPO', replace = "https://github.com/rustsbi/prototyper" },
]

[git]
conventional_commits = true
filter_unconventional = false
split_commits = false
commit_preprocessors = []
commit_parsers = [
{ message = "\\[skip", skip = true },
{ message = "\\p{Han}", skip = true },
{ message = "^feat", group = "Features" },
{ message = "^fix", group = "Bug Fixes" },
{ message = "^doc", group = "Documentation" },
{ message = "^perf", group = "Performance" },
{ message = "^refactor", group = "Refactoring" },
{ message = "^style", group = "Style" },
{ message = "^revert", group = "Revert" },
{ message = "^test", group = "Tests" },
{ message = "^chore\\(version\\):", skip = true },
{ message = "^chore", group = "Miscellaneous Chores" },
{ message = ".*", group = "Other" },
{ body = ".*security", group = "Security" },
]
protect_breaking_commits = false
filter_commits = false
tag_pattern = "v[0-9].*"
skip_tags = "v0.1.0-beta.1"
ignore_tags = ""
topo_order = false
sort_commits = "oldest"
22 changes: 11 additions & 11 deletions docs/booting-test-kernel-in-qemu-using-uboot-and-rustsbi.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

[环境配置](#环境配置)小节给出了本教程的环境配置方法,用户在使用本教程时需要先完成环境配置小节内容。

[使用U-Boot SPL启动Test Kerenl](#使用U-Boot-SPL启动Test-Kerenl)小节给出了只使用U-Boot SPL的启动流程。
[使用U-Boot SPL启动Test Kernel](#使用U-Boot-SPL启动Test-Kernel)小节给出了只使用U-Boot SPL的启动流程。

[使用U-Boot SPL和U-Boot启动Test Kerenl](#使用U-Boot-SPL和U-Boot启动Test-Kerenl)小节给出了同时使用U-Boot SPL和U-Boot的启动流程。
[使用U-Boot SPL和U-Boot启动Test Kernel](#使用U-Boot-SPL和U-Boot启动Test-Kernel)小节给出了同时使用U-Boot SPL和U-Boot的启动流程。

本教程使用软件版本如下:

Expand Down Expand Up @@ -52,7 +52,7 @@ $ riscv64-linux-gnu-gcc --version

它将输出以下版本信息

```
```
riscv64-linux-gnu-gcc (GCC) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand All @@ -66,7 +66,7 @@ $ qemu-system-riscv64 --version

它将输出以下版本信息

```
```
QEMU emulator version 9.0.1
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
```
Expand All @@ -91,7 +91,7 @@ Clone U-Boot
$ git clone https://github.com/u-boot/u-boot.git && cd u-boot && git checkout v2024.04 && cd ..
```

## 使用U-Boot SPL启动Test Kerenl
## 使用U-Boot SPL启动Test Kernel
### 编译RustSBI Prototyper和Test Kernel

进入prototyper目录
Expand Down Expand Up @@ -121,7 +121,7 @@ $ cd u-boot
``` shell
$ export ARCH=riscv
$ export CROSS_COMPILE=riscv64-linux-gnu-
$ export OPENSBI=../prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin
$ export OPENSBI=../prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin
```

生成`.config`文件
Expand Down Expand Up @@ -155,10 +155,10 @@ $ cd workshop
``` shell
$ qemu-system-riscv64 -M virt -smp 1 -m 256M -nographic \
-bios ./u-boot/spl/u-boot-spl \
-device loader,file=./prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel.itb,addr=0x80200000
-device loader,file=./prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-test-kernel.itb,addr=0x80200000
```

## 使用U-Boot SPL和U-Boot启动Test Kerenl
## 使用U-Boot SPL和U-Boot启动Test Kernel
### 编译RustSBI Prototyper和Test Kernel

进入prototyper目录
Expand Down Expand Up @@ -188,7 +188,7 @@ $ cd u-boot
``` shell
$ export ARCH=riscv
$ export CROSS_COMPILE=riscv64-linux-gnu-
$ export OPENSBI=../prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin
$ export OPENSBI=../prototyper/target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper.bin
```

生成`.config`文件
Expand All @@ -202,7 +202,7 @@ $ make menuconfig

U-Boot 配置选项将加载到终端。导航到 `Boot options` $\rightarrow$ `bootcmd value` 并将以下内容写入 `bootcmd` 值:

```
```
ext4load virtio 0:1 84000000 rustsbi-test-kernel.bin; booti 0x84000000 - ${fdtcontroladdr}
```

Expand Down Expand Up @@ -315,4 +315,4 @@ $ qemu-system-riscv64 -M virt -smp 1 -m 256M -nographic \
-device loader,file=./u-boot/u-boot.itb,addr=0x80200000 \
-blockdev driver=file,filename=./test-kernel.img,node-name=hd0 \
-device virtio-blk-device,drive=hd0
```
```
8 changes: 4 additions & 4 deletions prototyper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {

// 1. Init FDT
// parse the device tree.
// TODO: shoule remove `fail:device_tree_format`.
// TODO: should remove `fail:device_tree_format`.
let dtb = dt::parse_device_tree(fdt_addr).unwrap_or_else(fail::device_tree_format);
let dtb = dtb.share();

Expand Down Expand Up @@ -104,7 +104,7 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
info!("Model: {}", model.iter().next().unwrap_or("<unspecified>"));
}
info!("Clint device: {}", ipi_base_address);
info!("Console deivce: {}", console_base_address);
info!("Console device: {}", console_base_address);
info!(
"Chosen stdout item: {}",
tree.chosen
Expand Down Expand Up @@ -194,7 +194,7 @@ unsafe extern "C" fn start() -> ! {
core::arch::asm!(
// 1. Turn off interrupt.
" csrw mie, zero",
// 2. Initialize programming langauge runtime.
// 2. Initialize programming language runtime.
// only clear bss if hartid matches preferred boot hart id.
" csrr t0, mhartid",
" bne t0, zero, 4f",
Expand All @@ -216,7 +216,7 @@ unsafe extern "C" fn start() -> ! {
" li t1, 1
lla t0, 6f
lw t0, 0(t0)
bne t0, t1, 4b",
bne t0, t1, 4b",
"5:",
// 4. Prepare stack for each hart.
" call {locate_stack}",
Expand Down
1 change: 1 addition & 0 deletions prototyper/src/sbi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rfence::SbiRFence;

#[derive(RustSBI, Default)]
#[rustsbi(dynamic)]
#[allow(clippy::upper_case_acronyms)]
pub struct SBI<'a, C: ConsoleDevice, I: IpiDevice, R: ResetDevice> {
#[rustsbi(console)]
pub console: Option<SbiConsole<'a, C>>,
Expand Down
7 changes: 1 addition & 6 deletions prototyper/src/sbi/rfence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ fn validate_address_range(start_addr: usize, size: usize) -> Result<usize, SbiRe
return Err(SbiRet::invalid_address());
}

let end_addr = start_addr + size;
if end_addr > usize::MAX {
Ok(usize::MAX)
} else {
Ok(size)
}
Ok(size)
}

/// Processes a remote fence operation by sending IPI to target harts.
Expand Down
Loading