Skip to main content

consortium_data/
lib.rs

1// Copyright 2026 Ethan Wu
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17//! Static chip data for the Consortium project, embedded at compile time.
18//!
19//! This crate owns the chip-family databases (`database/memory/*.yaml`), the
20//! generated per-core chip dumps (`database/chip/*.json`), the extracted
21//! peripheral register definitions (`database/peri/`), and the vendor
22//! device-tree sources (`database/dts/`).
23//! It also owns the resolvers that turn a `[profile] chip` part number into a
24//! parsed [`database::ChipDatabase`] or a per-core [`chipmap::ChipMap`].
25//!
26//! # Why it is embedded rather than read from disk
27//!
28//! `csti` is installed as a binary and run from a user's project directory, which
29//! has no `database/` in it. Every datum here is therefore compiled in — YAML and
30//! JSON through `include_str!`, the device-tree tree through `include_dir!` — so
31//! resolution works regardless of the working directory and cannot break because a
32//! data file moved. The cost is binary size and a rebuild on every data change,
33//! which is the right trade for a build tool.
34//!
35//! # What each module resolves
36//!
37//! | Module       | Source                       | Answers                              |
38//! | ------------ | ---------------------------- | ------------------------------------ |
39//! | [`database`] | `database/memory/*.yaml`      | What does this chip *family* offer — coprocessors, memory regions and aliases, peripherals, doorbells? |
40//! | [`chipmap`]  | `database/chip/*.json`        | What can *one core* reach — peripheral MMIO bases and NVIC numbers? |
41//! | [`dts`]      | `database/dts/{imx9,stm32mp2}` | Which vendor board or SoC device tree do we build on top of? |
42//!
43//! The split between the first two matters. A family database says the chip *has* an
44//! LPUART2; a chip map says *this core* can see it. Because there is one JSON file
45//! per core, the set of peripherals in a core's file **is** the set that core can
46//! reach — which is exactly the filter `consortium-cfg` applies when validating
47//! `[peripheral.<name>] owner`.
48//!
49//! The same chip dumps also feed `scripts/pac/gen_interrupts.py` and
50//! `scripts/pac/gen_peripherals.py`, which generate the PAC's interrupt tables and
51//! the chip HAL's singleton map. One source for all three is what keeps a HAL
52//! singleton, a PAC interrupt number, and a validated manifest in agreement.
53//!
54//! # Generated and imported data
55//!
56//! Treat everything under `database/` as **generated or vendored**, not authored.
57//! Change the generation workflow (the `just pac-*` recipes and `scripts/pac/`)
58//! rather than editing a large data file by hand.
59//!
60//! Schema types come from `consortium-cfg-common`, which exists partly so this crate
61//! can deserialize into them without depending on the codegen crate that depends on
62//! it.
63//!
64//! # Licensing
65//!
66//! This crate carries a compound SPDX expression rather than inheriting the
67//! workspace `Apache-2.0`, because it redistributes vendor material. Vendor device
68//! trees under `database/dts/` **must be dual-licensed** — GPL-only files cannot
69//! ship. See that directory's `README.md` before adding one.
70
71pub mod chipmap;
72pub mod database;
73pub mod dts;
74mod error;
75
76pub use error::DataError;