interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / core / pi5_marker.h

70 lines · 3785 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* pi5_marker.h -- the layer below the sealed Store, proved on the Pi 5 card
18 * (AIENOS-PI5 step 3). The Store itself needs production keys, which are
19 * BLOCKED_OPERATOR (svc/store_boot.c), so the Pi image does not open it. What
20 * the Store needs from the card is: GPT partition view in, multi-sector
21 * writes with flush, bytes back identical after a reboot. This module
22 * proves exactly that on a bounded scratch region at the END of the AIENOS
23 * partition view, written only through that view (dev/disk_part.h).
24 *
25 * Region: CK_PI5_MARKER_SECS sectors. Sector 0 is the header, the rest a
26 * payload that is a pure function of (seed, sector, offset), so a later boot
27 * can verify it byte for byte without storing a copy:
28 * header: magic "AIENPI5M", version, generation, payload sectors, seed,
29 * CRC32 of the payload, CRC32 of the header's first 40 bytes.
30 * First boot, region all zero: write payload, flush, write header, flush,
31 * read back: CK_PI5_MARKER_FORMATTED. Later boot, valid header: payload
32 * read (multi-sector) and compared with the regenerated pattern, then
33 * generation + 1 is written and read back: CK_PI5_MARKER_REOPENED. Anything
34 * else (neither zero nor a valid marker) is refused and nothing is written.
35 *
36 * Freestanding (no libc): the caller supplies the buffer. */
37#ifndef AIENOS_CK_PI5_MARKER_H
38#define AIENOS_CK_PI5_MARKER_H
39#include <stdint.h>
40#include "disk.h"
41#include "../dev/disk_part.h"
42
43#define CK_PI5_MARKER_SECS 64u /* 32 KiB: one header sector + 63 payload sectors */
44#define CK_PI5_MARKER_BUF_BYTES (CK_PI5_MARKER_SECS * DISK_SECTOR_BYTES)
45#define CK_PI5_MARKER_SEED 0x41494e5049354d31ull
46
47enum {
48 CK_PI5_MARKER_FORMATTED = 1, /* blank region: written, flushed, read back identical */
49 CK_PI5_MARKER_REOPENED = 2, /* valid marker: payload identical, generation bumped and read back */
50 CK_PI5_MARKER_EIO = -501, /* a read, write or flush failed */
51 CK_PI5_MARKER_EREFUSED = -502, /* region is neither blank nor a valid marker: nothing written */
52 CK_PI5_MARKER_ECORRUPT = -503, /* valid header, payload does not match: nothing written */
53 CK_PI5_MARKER_EVERIFY = -504, /* read back after a write differs */
54 CK_PI5_MARKER_ESIZE = -505, /* view smaller than the region, or not 512-byte blocks */
55};
56
57/* d is the AIENOS partition view. buf is CK_PI5_MARKER_BUF_BYTES, 64-aligned.
58 * *generation is set on success. */
59int ck_pi5_marker_run(const disk_dev *d, uint8_t *buf, uint64_t *generation);
60const char *ck_pi5_marker_strerror(int rc);
61
62/* The sealed Store's view of the AIENOS partition on the Pi card: the same
63 * partition with the marker region reserved. *out ends before the last
64 * CK_PI5_MARKER_SECS sectors, rounded down to whole CK_LAYOUT_UNIT units, so
65 * the Store's units 4..U-2 and its probe unit U-1 (dev/disk_layout.h) never
66 * touch a marker sector, and the marker never touches the Store. Every image
67 * that writes either one uses this split. CK_PI5_MARKER_ESIZE when full is
68 * invalid, not 512-byte blocks, or too small for one unit plus the marker. */
69int ck_pi5_store_view(const ck_part *full, ck_part *out);
70#endif