add-bsp
Add a new Board Support Package (BSP) crate to the Tyrne workspace — from crate skeleton through boot checklist to first QEMU or hardware boot.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add a new Board Support Package (BSP) crate to the Tyrne workspace — from crate skeleton through boot checklist to first QEMU or hardware boot.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | add-bsp |
| description | Add a new Board Support Package (BSP) crate to the Tyrne workspace — from crate skeleton through boot checklist to first QEMU or hardware boot. |
| when-to-use | When adding support for a new hardware target (e.g. Raspberry Pi 4, a custom board) or when porting the kernel to a new QEMU machine type. |
Length note. This skill intentionally exceeds the ~200-line soft limit in the skills README. Bringing up a new board is irreducibly long — the
boot.stemplate (step 4) and the smoke-test diagnostic table (step 10) are load-bearing checklist content, not padding, and a partial procedure here would be more dangerous than a long one. Kept whole rather than split or moved to a guide.
Before starting, the agent must have:
rpi4, qemu-virt).aarch64-unknown-none).If the boot EL or peripheral map is unknown, stop and ask the maintainer before proceeding.
Follow the write-adr skill. The ADR must document:
Do not write boot code before this ADR is Accepted.
bsp-<target>/
Cargo.toml
build.rs (if a linker script needs to be emitted)
linker.ld
src/
boot.s (reset vector — assembly only)
main.rs (kernel_entry and panic handler)
console.rs (Console impl for the target's UART)
cpu.rs (Cpu + ContextSwitch impl for the target)
Cargo.toml must set:
[package]
name = "tyrne-bsp-<target>"
edition = "2021"
[[bin]]
name = "tyrne-bsp-<target>"
path = "src/main.rs"
[dependencies]
tyrne-hal = { path = "../hal" }
tyrne-kernel = { path = "../kernel" }
Add the crate to [workspace] in the root Cargo.toml.
Read docs/standards/bsp-boot-checklist.md in full.
Execute each item before moving to the next. Do not assume any item is already satisfied on a new target:
| # | Item | Common mistake |
|---|---|---|
| 1 | Exception level confirmed | Assuming EL1 when hardware enters EL2 |
| 2 | CPACR_EL1.FPEN = 0b11 set in boot.s | Forgetting → NEON trap, silent hang |
| 3 | VBAR configured before enabling IRQs | Missing → any exception = silent hang |
| 4 | SP 16-byte aligned at first bl | Wrong linker alignment → AAPCS64 fault |
| 5 | BSS zeroed before kernel_entry | Uninitialised statics → subtle UB |
| 6 | Context-switch fn is #[unsafe(naked)] | Using #[inline(never)] → sp corruption |
boot.sMinimum content (aarch64 EL1 example):
.section .text.boot, "ax"
.global _start
_start:
/* 1. Set stack pointer */
adrp x0, __stack_top
add x0, x0, :lo12:__stack_top
mov sp, x0
/* 2. Enable FP/SIMD — do not rely on CPACR_EL1 reset value */
mov x0, #0x300000 // FPEN = 0b11
msr cpacr_el1, x0
isb
/* 3. Zero BSS */
adrp x0, __bss_start
add x0, x0, :lo12:__bss_start
adrp x1, __bss_end
add x1, x1, :lo12:__bss_end
0: cmp x0, x1
b.hs 1f
str xzr, [x0], #8
b 0b
1:
bl kernel_entry
2: wfe
b 2b
Adjust for EL2→EL1 transition if the target enters at EL2 (add msr hcr_el2, … / eret sequence before step 1).
cpu.rsCopy the structure from bsp-qemu-virt/src/cpu.rs.
Cpu trait: current_core_id, disable_irqs, restore_irq_state, wait_for_interrupt, instruction_barrier.ContextSwitch trait with #[unsafe(naked)] context_switch_asm that saves all AAPCS64 callee-saved registers: x19–x28, fp, lr, sp, and d8–d15.Aarch64TaskContext layout (168 bytes, repr(C)) and the same field offsets.unsafe block to the audit log per the justify-unsafe skill.console.rsImplement tyrne_hal::Console for the target UART. Follow the existing Pl011Uart implementation. Each UART model is different; check the datasheet for the FIFO-full flag and data-register offsets.
main.rskernel_entry must:
tyrne: hello from kernel_main).tyrne_kernel::sched to register tasks and start the scheduler.-> !).Provide a #[panic_handler] that writes to the console and loops.
Model on bsp-qemu-virt/linker.ld. At minimum:
.text.boot first so _start is at the load address.__bss_start and __bss_end to 8 bytes.__stack_top to 16 bytes.Create tools/run-<target>.sh. For QEMU targets, model on tools/run-qemu.sh:
--int-log flag (-d int -D /tmp/qemu_int.log) for silent-hang debugging.For real hardware, document the flashing command (e.g. openocd, rpiboot, cargo flash).
Boot the kernel and confirm:
tyrne: hello from kernel_main
tyrne: starting cooperative scheduler
tyrne: task A — iteration 0
tyrne: task B — iteration 0
...
tyrne: task A done; spinning
If the kernel hangs silently, run with --int-log (QEMU) or attach a JTAG debugger (real hardware) and check for the following before anything else:
grep "Taking exception" /tmp/qemu_int.logSee docs/standards/bsp-boot-checklist.md for the full diagnostic table.
Per commit-style.md:
feat(bsp-<target>): initial BSP — boot to kernel_entry on <target>
Body: one sentence on what the BSP proves (e.g. "boots to kernel_entry on RPi4 CM4 at EL2→EL1; PL011 console confirmed").
Trailer: Refs: ADR-NNNN (the boot-flow ADR from step 1).
cargo build --target <triple> -p tyrne-bsp-<target> succeeds with zero warnings.unsafe block has a // SAFETY: comment with (a) why needed, (b) invariants, (c) why alternatives rejected; audit log updated.context_switch_asm is #[unsafe(naked)] and saves d8–d15 in addition to x19–x28, fp, lr, sp.--int-log (or equivalent) is documented.commit-style.md.boot.s without checking the EL. QEMU virt enters EL1; RPi4 enters EL2. The CPACR_EL1 sequence is only needed if the kernel runs at EL1; at EL2 you need CPTR_EL2.#[inline(never)] instead of #[unsafe(naked)] for the context switch. The compiler will still emit a prologue. See docs/standards/unsafe-policy.md §5a.Aarch64TaskContext. NEON is enabled at boot; the compiler may allocate d8–d15 in any function. Omitting them silently corrupts task state at higher optimisation levels..bss is zero; if the hardware or QEMU does not zero it, every static initialised to zero will have garbage values.docs/standards/bsp-boot-checklist.md — ordered checklist with diagnostic table.docs/standards/unsafe-policy.md — #[unsafe(naked)] rule (§5a) and general unsafe discipline.bsp-qemu-virt/ — reference BSP implementation.ContextSwitch trait contract.Propose and draft a new Architecture Decision Record (ADR) in MADR format for Tyrne.
Run an independent verification pass over artefacts in `Proposed` / `In Review` waiting-for-promotion states. Distinct from code-review (style + correctness on a diff) and security-review (adversarial axis pass) — this skill verifies that the artefacts' claims about their own state match reality and produces a Done-promotion verdict.
Produce a review artifact in `docs/analysis/reviews/<type>-reviews/`, following that type's master plan. Works for business / code / security / performance-optimization reviews.
Change an existing Tyrne standard correctly — write or update the motivating ADR first, then update the standard file.
Add a new Rust crate to the Tyrne workspace following the dependency policy in `infrastructure.md`.
Introduce or audit an `unsafe` region in Tyrne — writing the `SAFETY:` comment, adding the audit-log entry, and queuing security review.