feat(kernel): the GPT reader, and Zuse from a GPT identity partition
The stick, increment 2 (plan 2026-10-26-stick-2-gpt-reader; docs/v4.0.0/
STICK.md 3 and 4: GPT for boot media and installed disks). kernel/src/gpt.c:
a CRC-32; gpt_read(), which checks the protective MBR, the primary header and
the partition-entry array (both CRCs, the revision, the sizes, the geometry);
and a partition as a blkio device, refusing blocks past its end. The two
StarshipOS partition types: identity 23BEBFE1-4817-4CF3-A537-9069BF159788,
Artemis BCD7B586-1C8E-4EEF-86A3-273A8D8EE624.
The v4 drive path: a GPT disk is used only through its StarshipOS identity
partition, and that partition -- never the disk -- is given to the block
subsystem, in a raw identity drive's place; a GPT disk with no StarshipOS
partition, or a damaged table ("GPT: a USB drive has a damaged partition
table -- not used"), is not attached (Captain Bob's ruling on the plan); a
disk with no GPT is read raw, as always. Pulling the drive detaches the
partition and ends her session. Reads only.
Red (amd64): gpt_zuse 193158, gpt_hotplug 193804, gpt_foreign 194713,
gpt_bad_crc 194947. Green: 195409, 195627, 195854, 200136; gpt_zuse aarch64
200424, riscv64 200839 (the 64 MiB partition attached, 48724 user blocks,
not the 72 MiB disk); the identity gate's and increment 1's sessions,
201119-203403, all pass.
Accepted (with the KERNEL_ARGS fix that follows): suite EXIT 0; 214300,
214507, 214911, POST 538/538, dict_hash 0xfec8c47cfc6f437f; test-32, 39
modules, 0 failures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
03099f2c51
commit
3cc4937c93
@@ -24,6 +24,7 @@
|
||||
#include "starkernel/homeblocks_sig.h"
|
||||
#include "starkernel/capsule_zuse_boot.h"
|
||||
#include "starkernel/kbd_input.h"
|
||||
#include "starkernel/gpt.h"
|
||||
#ifdef ARCH_AMD64
|
||||
#include "starkernel/ioapic.h"
|
||||
#include "starkernel/i8042.h"
|
||||
@@ -43,12 +44,26 @@ static uint8_t g_zuse_root_pubkey[32];
|
||||
static int g_zuse_root_known;
|
||||
static struct blkio_dev *g_zuse_dev;
|
||||
|
||||
/* A blkio_dev per slot, per xHCI controller, as repl.c's g_usb_ctrl. */
|
||||
/* A drive in a USB slot: the raw disk; its StarshipOS identity partition as
|
||||
* a device of its own, when it has a GPT with one; and the one of the two
|
||||
* given to the block subsystem, if either was (a GPT disk is never given
|
||||
* whole: docs/v4.0.0/plans/2026-10-26-stick-2-gpt-reader.md, ruled). */
|
||||
typedef struct {
|
||||
blkio_dev_t raw;
|
||||
blkio_dev_t part;
|
||||
gpt_part_dev_t part_state;
|
||||
blkio_dev_t *used;
|
||||
} sk_v4_drive_t;
|
||||
|
||||
/* One per slot, per xHCI controller, as repl.c's g_usb_ctrl. */
|
||||
static struct {
|
||||
blkio_dev_t *slots;
|
||||
uint32_t count;
|
||||
sk_v4_drive_t *slots;
|
||||
uint32_t count;
|
||||
} g_usb[XHCI_MAX_CONTROLLERS];
|
||||
|
||||
#define SK_V4_GPT_PARTS 16u
|
||||
static gpt_part_t g_gpt_parts[SK_V4_GPT_PARTS];
|
||||
|
||||
static uint64_t g_last_beat;
|
||||
static int g_said_no_genesis;
|
||||
|
||||
@@ -93,17 +108,42 @@ void sk_v4_identity_boot(void)
|
||||
|
||||
/* A drive that has arrived: given to the block subsystem (Artemis's, the
|
||||
* kernel's), then, if it is Zuse's, her session begins. */
|
||||
static int sk_v4_drive_arrived(blkio_dev_t *dev)
|
||||
static int sk_v4_drive_arrived(sk_v4_drive_t *d)
|
||||
{
|
||||
blkio_dev_t *dev = &d->raw;
|
||||
homeblocks_sig_t sig;
|
||||
homeblocks_sig_result_t sig_rc = homeblocks_sig_check(dev, HOMEBLOCKS_SIG_START_FBLOCK, &sig);
|
||||
homeblocks_sig_result_t sig_rc;
|
||||
uint8_t seed[32], pubkey[32];
|
||||
zuse_drive_t which;
|
||||
unsigned nparts;
|
||||
int gpt_rc, idx;
|
||||
|
||||
/* GPT first (docs/v4.0.0/STICK.md 4): a disk with a valid GPT is used
|
||||
* through its StarshipOS identity partition only; one with no such
|
||||
* partition, or a damaged table, is not used at all; a disk with no GPT
|
||||
* is read raw, as an identity drive always has been. */
|
||||
d->used = (blkio_dev_t *)0;
|
||||
gpt_rc = gpt_read(&d->raw, g_gpt_parts, SK_V4_GPT_PARTS, &nparts);
|
||||
if (gpt_rc == GPT_BAD) {
|
||||
console_println("GPT: a USB drive has a damaged partition table -- not used");
|
||||
return 1;
|
||||
}
|
||||
if (gpt_rc == GPT_OK) {
|
||||
idx = gpt_find(g_gpt_parts, nparts, gpt_type_starship_identity);
|
||||
if (idx < 0) return 1; /* no StarshipOS partition: not ours to use */
|
||||
if (gpt_part_open(&d->part, &d->part_state, &d->raw, &g_gpt_parts[idx]) != BLKIO_OK) {
|
||||
console_println("GPT: a USB drive's identity partition is not on 1 KiB blocks -- not used");
|
||||
return 1;
|
||||
}
|
||||
dev = &d->part;
|
||||
}
|
||||
|
||||
sig_rc = homeblocks_sig_check(dev, HOMEBLOCKS_SIG_START_FBLOCK, &sig);
|
||||
if (blk_subsys_attach_device(dev) != BLK_OK) {
|
||||
console_println("xhci: USB MSC block-subsystem attach failed");
|
||||
return 0;
|
||||
}
|
||||
d->used = dev;
|
||||
if (g_zuse_session) return 1;
|
||||
|
||||
which = capsule_zuse_boot_check(dev, sig_rc, &sig, seed, pubkey);
|
||||
@@ -134,8 +174,12 @@ static int sk_v4_drive_arrived(blkio_dev_t *dev)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void sk_v4_drive_left(blkio_dev_t *dev)
|
||||
static void sk_v4_drive_left(sk_v4_drive_t *d)
|
||||
{
|
||||
blkio_dev_t *dev = d->used;
|
||||
|
||||
if (!dev) return; /* never given to the block subsystem */
|
||||
d->used = (blkio_dev_t *)0;
|
||||
blk_subsys_detach_device(dev);
|
||||
if (dev != g_zuse_dev) return;
|
||||
g_zuse_session = 0;
|
||||
@@ -164,8 +208,8 @@ static void sk_v4_idle(void)
|
||||
xhci_dev_t *xdev = xhci_dev_at(xc);
|
||||
if (!xdev) continue;
|
||||
if (!g_usb[xc].slots || g_usb[xc].count < xdev->max_slots + 1) {
|
||||
size_t bytes = (size_t)(xdev->max_slots + 1) * sizeof(blkio_dev_t);
|
||||
blkio_dev_t *fresh = (blkio_dev_t *)kmalloc_aligned(bytes, 64);
|
||||
size_t bytes = (size_t)(xdev->max_slots + 1) * sizeof(sk_v4_drive_t);
|
||||
sk_v4_drive_t *fresh = (sk_v4_drive_t *)kmalloc_aligned(bytes, 64);
|
||||
if (!fresh) continue;
|
||||
memset(fresh, 0, bytes);
|
||||
g_usb[xc].slots = fresh;
|
||||
@@ -175,7 +219,7 @@ static void sk_v4_idle(void)
|
||||
xhci_msc_slot_t *ms = xhci_msc_slot_for(xdev, slot);
|
||||
if (!ms || !ms->bot_msc_attach_pending) continue;
|
||||
ms->bot_msc_attach_pending = 0;
|
||||
if (blkio_usb_open_msc(&g_usb[xc].slots[slot], xdev, slot) == 0 &&
|
||||
if (blkio_usb_open_msc(&g_usb[xc].slots[slot].raw, xdev, slot) == 0 &&
|
||||
sk_v4_drive_arrived(&g_usb[xc].slots[slot]))
|
||||
ms->bot_msc_attached = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user