Skip to main content

tinyboot_core/
lib.rs

1#![no_std]
2#![warn(missing_docs)]
3
4//! Platform-agnostic bootloader core.
5//!
6//! Implements the boot state machine, protocol dispatcher, and app validation.
7//! Platform-specific behaviour is injected via the traits in [`traits::boot`].
8
9/// App-side tinyboot client (poll, confirm, command handling).
10pub mod app;
11/// Boot state machine and entry point.
12pub mod core;
13/// Protocol frame dispatcher.
14pub mod protocol;
15/// Fixed-size ring buffer for buffered flash writes.
16pub mod ringbuf;
17/// Platform abstraction traits.
18pub mod traits;
19
20pub use crate::core::Core;
21
22// Re-export so version macros can use `$crate::pkg_version!()`.
23#[doc(hidden)]
24pub use tinyboot_protocol::pkg_version;
25
26/// Read the version from the `__tb_version` linker symbol.
27///
28/// This symbol is defined by `tb-boot.x` / `tb-app.x` and points to the
29/// `.tb_version` section populated by [`boot_version!`] or [`app_version!`].
30#[inline(always)]
31pub fn tinyboot_version() -> u16 {
32    unsafe extern "C" {
33        static __tb_version: u16;
34    }
35    unsafe { ::core::ptr::read_volatile(&raw const __tb_version) }
36}
37
38/// Define the `.tb_version` static using the calling crate's version.
39/// Place this at module scope in your bootloader binary.
40#[macro_export]
41macro_rules! boot_version {
42    () => {
43        #[unsafe(link_section = ".tb_version")]
44        #[used]
45        static _BOOT_VERSION: u16 = $crate::pkg_version!();
46    };
47}
48
49/// Define the `.tb_version` static using the calling crate's version.
50/// Place this at module scope in your application binary.
51#[macro_export]
52macro_rules! app_version {
53    () => {
54        #[unsafe(link_section = ".tb_version")]
55        #[used]
56        static _APP_VERSION: u16 = $crate::pkg_version!();
57    };
58}