Skip to content

Commit 51859b4

Browse files
committed
Initial commit
0 parents  commit 51859b4

File tree

10 files changed

+924
-0
lines changed

10 files changed

+924
-0
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ci:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
rust-toolchain: [nightly]
12+
targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat]
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: dtolnay/rust-toolchain@nightly
16+
with:
17+
toolchain: ${{ matrix.rust-toolchain }}
18+
components: rust-src, clippy, rustfmt
19+
targets: ${{ matrix.targets }}
20+
- name: Check rust version
21+
run: rustc --version --verbose
22+
- name: Check code format
23+
run: cargo fmt --all -- --check
24+
- name: Clippy
25+
run: cargo clippy --target ${{ matrix.targets }} --all-features -- -A clippy::new_without_default
26+
- name: Build
27+
run: cargo build --target ${{ matrix.targets }} --all-features
28+
- name: Unit test
29+
if: ${{ matrix.targets == 'x86_64-unknown-linux-gnu' }}
30+
run: cargo test --target ${{ matrix.targets }} -- --nocapture
31+
32+
doc:
33+
runs-on: ubuntu-latest
34+
strategy:
35+
fail-fast: false
36+
permissions:
37+
contents: write
38+
env:
39+
default-branch: ${{ format('refs/heads/{0}', github.event.repository.default_branch) }}
40+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: dtolnay/rust-toolchain@nightly
44+
- name: Build docs
45+
continue-on-error: ${{ github.ref != env.default-branch && github.event_name != 'pull_request' }}
46+
run: |
47+
cargo doc --no-deps --all-features
48+
printf '<meta http-equiv="refresh" content="0;url=%s/index.html">' $(cargo tree | head -1 | cut -d' ' -f1) > target/doc/index.html
49+
- name: Deploy to Github Pages
50+
if: ${{ github.ref == env.default-branch }}
51+
uses: JamesIves/github-pages-deploy-action@v4
52+
with:
53+
single-commit: true
54+
branch: gh-pages
55+
folder: target/doc

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/target
2+
/.vscode
3+
.DS_Store
4+
Cargo.lock
5+
.axconfig.toml

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "axconfig_gen"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Yuekai Jia <equation618@gmail.com>"]
6+
description = "A TOML-based configuration generator for ArceOS"
7+
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0"
8+
homepage = "https://github.com/arceos-org/arceos"
9+
repository = "https://github.com/arceos-org/axconfig_gen"
10+
documentation = "https://docs.rs/axconfig_gen"
11+
keywords = ["arceos", "config", "toml"]
12+
categories = ["config", "parsing", "parser-implementations"]
13+
14+
[dependencies]
15+
toml_edit = { version = "0.22" }
16+
clap = { version = "4", features = ["derive"] }
17+
18+
[[bin]]
19+
name = "axconfig-gen"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# axconfig-gen

example_configs/defconfig.toml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Architecture identifier.
2+
arch = "x86_64" # str
3+
# Platform identifier.
4+
plat = "x86_64-qemu-q35" # str
5+
# Number of CPUs
6+
smp = 1 # uint
7+
8+
#
9+
# Kernel configs
10+
#
11+
[kernel]
12+
# Stack size of each task.
13+
task-stack-size = 0 # uint
14+
# Number of timer ticks per second (Hz). A timer tick may contain several timer
15+
# interrupts.
16+
ticks-per-sec = 0 # uint
17+
18+
#
19+
# Platform configs
20+
#
21+
[platform]
22+
# Base address of the whole physical memory.
23+
phys-memory-base = 0 # uint
24+
# Size of the whole physical memory.
25+
phys-memory-size = 0x800_0000 # uint
26+
# Base physical address of the kernel image.
27+
kernel-base-paddr = 0x20_0000 # uint
28+
# Base virtual address of the kernel image.
29+
kernel-base-vaddr = "0xffff_ff80_0020_0000" # uint
30+
# Linear mapping offset, for quick conversions between physical and virtual
31+
# addresses.
32+
phys-virt-offset = "0xffff_ff80_0000_0000" # uint
33+
# Offset of bus address and phys address. some boards, the bus address is
34+
# different from the physical address.
35+
phys-bus-offset = 0 # uint
36+
# Kernel address space base.
37+
kernel-aspace-base = "0xffff_ff80_0000_0000" # uint
38+
# Kernel address space size.
39+
kernel-aspace-size = "0x0000_007f_ffff_f000" # uint
40+
# Timer interrupt frequencyin Hz.
41+
timer-frequency = 0 # uint
42+
43+
#
44+
# Device specifications
45+
#
46+
[device]
47+
# MMIO regions with format (`base_paddr`, `size`).
48+
mmio-regions = [
49+
["0xb000_0000", "0x1000_0000"], # PCI config space
50+
["0xfe00_0000", "0xc0_0000"], # PCI devices
51+
["0xfec0_0000", "0x1000"], # IO APIC
52+
["0xfed0_0000", "0x1000"], # HPET
53+
["0xfee0_0000", "0x1000"], # Local APIC
54+
] # [(uint, uint)]
55+
# VirtIO MMIO regions with format (`base_paddr`, `size`).
56+
virtio-mmio-regions = [] # [(uint, uint)]
57+
# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table).
58+
pci-ecam-base = 0 # uint
59+
# End PCI bus number.
60+
pci-bus-end = 0 # uint
61+
# PCI device memory ranges (not used on x86).
62+
pci-ranges = [] # [(uint, uint)]

src/bin/axconfig-gen.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use std::io;
2+
3+
use axconfig_gen::Config;
4+
use clap::Parser;
5+
6+
#[derive(Parser, Debug)]
7+
#[command(version, about, long_about = None)]
8+
struct Args {
9+
/// Path to the config specification file
10+
#[arg(short, long, required = true)]
11+
spec: Vec<String>,
12+
13+
/// Path to the old config file
14+
#[arg(short = 'c', long)]
15+
oldconfig: Option<String>,
16+
17+
/// Path to the output config file
18+
#[arg(short, long)]
19+
output: Option<String>,
20+
}
21+
22+
fn main() -> io::Result<()> {
23+
let args = Args::parse();
24+
25+
let mut defconfig = Config::new();
26+
for spec in args.spec {
27+
let spec_toml = std::fs::read_to_string(spec)?;
28+
let sub_config = Config::from_toml(&spec_toml).unwrap();
29+
30+
defconfig.merge(&sub_config).unwrap();
31+
}
32+
33+
let output_config = if let Some(oldconfig_path) = args.oldconfig {
34+
let oldconfig_toml = std::fs::read_to_string(oldconfig_path)?;
35+
let oldconfig = Config::from_toml(&oldconfig_toml).unwrap();
36+
defconfig.update(&oldconfig).unwrap();
37+
defconfig
38+
} else {
39+
defconfig
40+
};
41+
42+
let output = output_config.gen_toml().unwrap();
43+
if let Some(path) = args.output {
44+
std::fs::write(path, output)?;
45+
} else {
46+
println!("{}", output);
47+
}
48+
49+
Ok(())
50+
}

0 commit comments

Comments
 (0)