Skip to content

Commit 68f1439

Browse files
committed
feat(security): finalize P10 CFI hardening & multi-stage boot protections
1 parent b9c7e77 commit 68f1439

49 files changed

Lines changed: 23024 additions & 25248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ if(TARGET toob_crypto_upstream)
129129
target_link_libraries(toob_stage1 PRIVATE toob_crypto toob_crypto_upstream)
130130
endif()
131131

132-
# 5.3.5 eFuse Link-Time Mocking Strategy (P10 Anti-Brick)
132+
# 5.3.5 Cloud Command Pipeline
133+
option(TOOB_FEATURE_CLOUD_COMMANDS "Enable Cloud Command Pipeline" ON)
134+
135+
# 5.3.6 eFuse Link-Time Mocking Strategy (P10 Anti-Brick)
133136
option(TOOB_MOCK_EFUSES "Use Link-Time Mocking for eFuses" ON)
134137
if(TOOB_MOCK_EFUSES)
135138
add_compile_definitions(TOOB_MOCK_EFUSES=1)

cli/examples/manifests/device.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[device]
2+
vendor = "espressif"
23
chip = "esp32c6"
34

45
[partitions]

cli/suit/toob_cloud_cmd.cddl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
toob_cloud_cmd = {
2+
1: bstr .size 32, ; device_id (SHA-256 Hash)
3+
2: uint .size 1, ; command (toob_cloud_cmd_t enum)
4+
3: uint .size 4, ; counter_min (Anti-Replay)
5+
4: uint .size 4, ; issued_at (Unix Timestamp)
6+
? 5: bstr, ; params (optional, command-specific)
7+
101: bstr .size 64, ; signature_ed25519 (EdDSA Signatur über den Rest der Map)
8+
}

cli/toob-cli/internal/suit/generator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ func Generate(outputDir, compilerRoot, projectRoot, cliVersion string) error {
3636
ui.Step("zcbor CLI found locally. Generating strict parsers...")
3737
}
3838

39+
cloudCmdCddl := filepath.Join(compilerRoot, "cli", "suit", "toob_cloud_cmd.cddl")
40+
3941
commands := [][]string{
4042
{"code", "-c", suitCddl, "--decode", "-t", "toob_suit", "--output-c", filepath.Join(outputDir, "boot_suit.c"), "--output-h", filepath.Join(outputDir, "boot_suit.h")},
4143
{"code", "-c", telemCddl, "--decode", "-t", "toob_telemetry", "--output-c", filepath.Join(outputDir, "toob_telemetry_decode.c"), "--output-h", filepath.Join(outputDir, "toob_telemetry_decode.h")},
4244
{"code", "-c", telemCddl, "--encode", "-t", "toob_telemetry", "--output-c", filepath.Join(outputDir, "toob_telemetry_encode.c"), "--output-h", filepath.Join(outputDir, "toob_telemetry_encode.h")},
45+
{"code", "-c", cloudCmdCddl, "--decode", "-t", "toob_cloud_cmd", "--output-c", filepath.Join(outputDir, "boot_cloud_cmd_decode.c"), "--output-h", filepath.Join(outputDir, "boot_cloud_cmd_decode.h")},
4346
}
4447

4548
for _, args := range commands {

cmake/toob_core.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ target_include_directories(toob_heatshrink PUBLIC common/lib/heatshrink)
5555
# die Datei zur Evaluierungszeit evtl. noch gar nicht im Filebaum liegt.
5656
set(GENERATED_SUIT_C "${CMAKE_BINARY_DIR}/generated/boot_suit.c")
5757
set(GENERATED_TELEMETRY_ENCODE_C "${CMAKE_BINARY_DIR}/generated/toob_telemetry_encode.c")
58-
set_source_files_properties(${GENERATED_SUIT_C} ${GENERATED_TELEMETRY_ENCODE_C} PROPERTIES GENERATED TRUE)
58+
set(GENERATED_CLOUD_CMD_C "${CMAKE_BINARY_DIR}/generated/boot_cloud_cmd_decode.c")
59+
set_source_files_properties(${GENERATED_SUIT_C} ${GENERATED_TELEMETRY_ENCODE_C} ${GENERATED_CLOUD_CMD_C} PROPERTIES GENERATED TRUE)
5960

6061
# M-BUILD GAP-Fix: Custom Command zum Aufrufen der SUIT & Config Generation
6162
add_custom_command(
6263
OUTPUT ${GENERATED_SUIT_C}
6364
${CMAKE_BINARY_DIR}/generated/toob_telemetry_decode.c
6465
${GENERATED_TELEMETRY_ENCODE_C}
66+
${GENERATED_CLOUD_CMD_C}
6567
${CMAKE_BINARY_DIR}/generated/generated_boot_config.h
6668
${CMAKE_BINARY_DIR}/generated/stage0_layout.ld
6769
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/generated
@@ -80,11 +82,16 @@ add_custom_command(
8082
add_custom_target(generate_manifest
8183
DEPENDS ${GENERATED_SUIT_C}
8284
${CMAKE_BINARY_DIR}/generated/toob_telemetry_decode.c
85+
${GENERATED_CLOUD_CMD_C}
8386
${CMAKE_BINARY_DIR}/generated/generated_boot_config.h
8487
${CMAKE_BINARY_DIR}/generated/stage0_layout.ld
8588
)
8689

8790

91+
# P10 Krypto-Härtung: Optionale echte Double-Execution der Ed25519 Verifikation.
92+
# Detektiert auch algorithmus-interne Faults auf Kosten von ~30-50ms Boot-Zeit.
93+
option(TOOB_DOUBLE_VERIFY "Enable double-execution of Ed25519 for highest fault resistance (~+30ms)" OFF)
94+
8895
add_library(toob_core STATIC
8996
${TOOB_CORE_DIR}/boot_main.c
9097
${TOOB_CORE_DIR}/boot_state.c
@@ -95,13 +102,18 @@ add_library(toob_core STATIC
95102
${TOOB_CORE_DIR}/boot_swap.c
96103
${TOOB_CORE_DIR}/boot_delta.c
97104
${TOOB_CORE_DIR}/boot_rollback.c
105+
${TOOB_CORE_DIR}/boot_cobs.c
98106
${TOOB_CORE_DIR}/boot_panic.c
107+
${TOOB_CORE_DIR}/boot_provisioning.c
99108
${TOOB_CORE_DIR}/boot_confirm.c
100109
${TOOB_CORE_DIR}/boot_diag.c
101110
${TOOB_CORE_DIR}/boot_energy.c
102111
${TOOB_CORE_DIR}/boot_multiimage.c
112+
${TOOB_CORE_DIR}/boot_identity.c
103113
${TOOB_CORE_DIR}/boot_delay.c
114+
${TOOB_CORE_DIR}/boot_cloud_cmd.c
104115
${GENERATED_SUIT_C}
116+
${GENERATED_CLOUD_CMD_C}
105117
)
106118

107119
# Harte Abhängigkeits-Schranke: Schützt vor Race-Conditions bei parallelen Builds (ninja -j8)!
@@ -120,6 +132,10 @@ else()
120132
target_compile_definitions(toob_core PUBLIC TOOB_MOCK_TEST)
121133
endif()
122134

135+
if(TOOB_DOUBLE_VERIFY)
136+
target_compile_definitions(toob_core PRIVATE TOOB_DOUBLE_VERIFY=1)
137+
endif()
138+
123139
# ------------------------------------------------------------------------------
124140
# 3. Include-Pfade & Linking & Härtung
125141
# ------------------------------------------------------------------------------

cmake/toob_libtoob.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
add_library(toob_libtoob STATIC
2222
${TOOB_SDK_DIR}/libtoob/toob_confirm.c
2323
${TOOB_SDK_DIR}/libtoob/toob_update.c
24+
${TOOB_SDK_DIR}/libtoob/toob_cloud_submit.c
2425
${TOOB_SDK_DIR}/libtoob/toob_diag.c
2526
${TOOB_SDK_DIR}/libtoob/toob_handoff.c
2627
${TOOB_SDK_DIR}/libtoob/toob_ota.c

cmake/toob_stage0.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ endif()
5757

5858
target_compile_definitions(toob_stage0 PRIVATE TOOB_MINIMAL_CRYPTO=1)
5959

60+
if(TOOB_ARCH STREQUAL "host" OR CMAKE_BUILD_TYPE STREQUAL "Debug")
61+
target_compile_definitions(toob_stage0 PRIVATE TOOB_ALLOW_DEV_BYPASS=1)
62+
endif()
63+
6064
# 2. Toob-Boot Core-Includes verfügbar machen (boot_types.h) + Generiertes Config
6165
target_include_directories(toob_stage0 PRIVATE
6266
${TOOB_STAGE0_DIR}/include

common/include/boot_hal.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <stddef.h>
2323
#include <stdint.h>
2424

25+
/* RTC-Backup Register Slot Allocation */
26+
#define RTC_SLOT_AUTH_ATTEMPTS 0
27+
2528
/* --- 1. Flash HAL (Non-Volatile Storage) --- */
2629

2730
#define TOOB_HAL_ABI_V2 0x02000000
@@ -139,13 +142,27 @@ typedef struct {
139142
const uint8_t *pubkey, size_t pubkey_len);
140143

141144
/* RNG */
145+
/**
146+
* @brief Generate cryptographic random bytes.
147+
* HAL-Contract: Die Implementierung MUSS NIST SP 800-90B
148+
* Repetition Count und Adaptive Proportion Tests intern
149+
* durchführen. Bei Versagen: BOOT_ERR_CRYPTO zurückgeben.
150+
*/
142151
boot_status_t (*random)(uint8_t *buf, size_t len);
143152

144153
uint32_t (*get_last_vendor_error)(void);
145154

146155
/* Hardware Roots (eFuse / OTP) */
147156
boot_status_t (*read_pubkey)(uint8_t *key, size_t key_len, uint8_t key_index);
157+
boot_status_t (*read_chip_uid)(uint8_t *buf, size_t max_len, size_t *out_len);
148158
boot_status_t (*read_dslc)(uint8_t *buffer, size_t *len);
159+
boot_status_t (*write_dslc)(const uint8_t *value, size_t len);
160+
/**
161+
* @brief Read hardware monotonic counter.
162+
* HAL-Contract: Die Implementierung MUSS den gelesenen Wert intern
163+
* durch Komplement-Prüfung (read + read_inverted) validieren und
164+
* bei Diskrepanz BOOT_ERR_VERIFY zurückgeben.
165+
*/
149166
boot_status_t (*read_monotonic_counter)(uint32_t *ctr);
150167
boot_status_t (*advance_monotonic_counter)(void);
151168

@@ -226,9 +243,32 @@ typedef struct {
226243
*/
227244
bool (*get_recovery_pin_state)(void);
228245

246+
/**
247+
* @brief Power-Cycle-Resiliente RTC-Backup Register.
248+
* HAL-Contract: Werte MÜSSEN über Brownout/Software-Reset hinweg
249+
* erhalten bleiben. Bei Hardware ohne RTC-Backup: NULL setzen.
250+
*/
251+
boot_status_t (*read_rtc_backup)(uint8_t slot, uint32_t *value);
252+
boot_status_t (*write_rtc_backup)(uint8_t slot, uint32_t value);
253+
229254
uint32_t min_battery_mv;
230255
} soc_hal_t;
231256

257+
/* --- 8. Provisioning HAL (Factory & Lifecycle) --- */
258+
259+
/**
260+
* @brief Factory Provisioning and Key-Lock Interface
261+
* Extracted from crypto_hal_t to enforce separation of concerns and
262+
* ensure that normal firmware cannot accidentally write eFuses.
263+
*/
264+
typedef struct {
265+
boot_status_t (*burn_pubkey)(const uint8_t *key, size_t len, uint8_t index);
266+
boot_status_t (*write_dslc)(uint8_t value);
267+
boot_status_t (*set_protection_bits)(uint32_t bitmask);
268+
boot_status_t (*enable_secure_boot)(void);
269+
boot_status_t (*enable_flash_encryption)(void);
270+
} provisioning_hal_t;
271+
232272
/* --- Master Platform Container --- */
233273

234274
/**
@@ -241,8 +281,9 @@ typedef struct {
241281
const crypto_hal_t *crypto; /**< PFLICHT */
242282
const clock_hal_t *clock; /**< PFLICHT */
243283
const wdt_hal_t *wdt; /**< PFLICHT */
244-
const console_hal_t *console; /**< Optional */
245-
const soc_hal_t *soc; /**< Optional */
284+
const console_hal_t *console; /**< Optional */
285+
const soc_hal_t *soc; /**< Optional */
286+
const provisioning_hal_t *provisioning; /**< Optional */
246287
} boot_platform_t;
247288

248289
/**

common/include/boot_types.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ typedef enum {
6868
BOOT_ERR_WAL_LOCKED = 0xF5C5C5C5, /**< Transaktion über WAL-Grenzen verboten */
6969
BOOT_RECOVERY_REQUESTED = 0xF6D6D6D6, /**< Manueller/Hardware-Ausgelöster Fallback auf Serial Rescue */
7070
BOOT_ERR_ABI_MISMATCH = 0xF7E7E7E7, /**< HAL ABI-Version eines Structs ist zu alt/inkompatibel */
71-
BOOT_ERR_DOWNGRADE = 0xF8F8F8F8 /**< Hybrid SVN Check fehlgeschlagen (Anti-Rollback) */
71+
BOOT_ERR_DOWNGRADE = 0xF8F8F8F8, /**< Hybrid SVN Check fehlgeschlagen (Anti-Rollback) */
72+
73+
/* Cloud Command Errors */
74+
BOOT_ERR_DEVICE_LOCKED = 0xF9090909,
75+
BOOT_ERR_CMD_REPLAY = 0xFA1A1A1A,
76+
BOOT_ERR_CMD_DEVICE_MISMATCH = 0xFB2B2B2B
7277
} boot_status_t;
7378

7479
/* --- 2. Hardware Reset Reasons --- */
@@ -88,6 +93,20 @@ typedef enum {
8893
RESET_REASON_HARD_FAULT = 6 /**< CPU Exception Triggered */
8994
} reset_reason_t;
9095

96+
/* --- 2.5 Cloud Command Types --- */
97+
98+
/**
99+
* @brief Identifiziert den Typ eines signierten Cloud Commands.
100+
*/
101+
typedef enum {
102+
TOOB_CMD_FORCE_UPDATE = 0x01,
103+
TOOB_CMD_KILLSWITCH = 0x02,
104+
TOOB_CMD_UNLOCK = 0x03,
105+
TOOB_CMD_ROTATE_KEY = 0x04,
106+
TOOB_CMD_WIPE = 0x05,
107+
TOOB_CMD_REVOKE = 0x06,
108+
} toob_cloud_cmd_t;
109+
91110
/* --- 3. Stage 1 / Stage 0 Communication & Identity --- */
92111

93112
/**

docs/plan.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
Hier ist mein Vorschlag für die Implementierungsreihenfolge, optimiert auf minimale Merge-Konflikte und maximale Testbarkeit nach jeder Phase.
2+
3+
---
4+
5+
## Phase 1: ABI-Fundament (Types, TMR, Handoff)
6+
7+
**Warum zuerst:** Jede spätere Phase baut auf diesen Typen und Struct-Layouts auf. Fehler hier propagieren in alles.
8+
9+
**Kritische Dateien:**
10+
11+
`common/include/boot_types.h` — Neue Enums (`toob_cloud_cmd_t`, `BOOT_ERR_DEVICE_LOCKED`, `BOOT_ERR_CMD_REPLAY`, `BOOT_ERR_CMD_DEVICE_MISMATCH`), neuer WAL-Intent (`WAL_INTENT_CLOUD_CMD = 12`, `WAL_INTENT_DEVICE_LOCKED = 13`). Agent muss die Hamming-Distance-Konvention der Error-Codes strikt einhalten und die bestehenden `_Static_assert`-Ketten nicht brechen.
12+
13+
`toobloader/core/include/boot_journal.h``wal_tmr_payload_t` wächst um `uint32_t kdm_sequence` und `uint32_t active_kdm_slot`. Die `_Static_assert(sizeof(wal_tmr_payload_t) == 40, ...)` muss auf den neuen Wert (48) aktualisiert werden. **Höchste Vorsicht:** Der `wal_sector_header_t` enthält die TMR inline und hat ebenfalls eine harte Size-Assert auf 64 Bytes. Die `_padding[8]` muss um die 8 zusätzlichen TMR-Bytes schrumpfen oder der Header wächst — beides hat Kaskadeneffekte auf das gesamte WAL-Layout.
14+
15+
`sdk/libtoob/include/libtoob_types.h``toob_handoff_t` bekommt `uint8_t device_id[32]` und `uint8_t wipe_requested`. Die Size-Assert (aktuell 40) und der `crc32_trailer`-Offset-Assert müssen synchron aktualisiert werden. `TOOB_HANDOFF_STRUCT_VERSION` geht auf `0x02000000`. Parallel die `toob_wal_sector_header_t` mit dem `_reserved_tmr_space` anpassen (aktuell 40 Bytes, muss zum neuen TMR passen).
16+
17+
`common/include/boot_hal.h``crypto_hal_t` bekommt den neuen Pflicht-Pointer `read_chip_uid`. Optional: `provisioning_hal_t` als neues Struct definieren (kann aber auch Phase H sein).
18+
19+
**Validierung nach Phase 1:** Sandbox-Build (`TOOB_ARCH=host`) muss sauber kompilieren. Alle `_Static_assert`s in `boot_journal.h`, `libtoob_types.h` und `boot_types.h` müssen passen. Bestehende Sandbox-Tests dürfen nicht brechen.
20+
21+
---
22+
23+
## Phase 2: Stage 0 DSLC-Gate
24+
25+
**Warum hier:** Unabhängig von allen anderen Phasen, kleiner Scope, sofort testbar. Blockiert keine anderen Arbeiten.
26+
27+
**Kritische Dateien:**
28+
29+
`toobloader/stage0/stage0_main.c` — Der Majority-Vote DSLC-Check wird **nach** `platform->crypto->init()` und **vor** `stage0_get_active_slot()` eingefügt. Agent muss beachten, dass `stage0_main.c` einen eigenen `boot_panic`-Stub hat (kein echtes Panic-System). Die neue `dead_halt()` muss als `_Noreturn static void` in dieselbe Datei. Der Development-Mode-Bypass (DSLC=0x00 + kein Key) greift in die existierende Signatur-Prüfung bei Punkt 8 ein.
30+
31+
`toobloader/stage0/include/stage0_crypto.h` — Keine neue Funktion nötig, `read_dslc` kommt über `platform->crypto`.
32+
33+
**Achtung:** Stage 0 hat keinen Zugriff auf `boot_journal.h` oder die WAL-Infrastruktur. Der Agent darf keine Core-Header einziehen. Stage 0 nutzt ausschließlich `boot_types.h`, `boot_hal.h`, `boot_crc32.h` und seinen eigenen `stage0_crypto.h`.
34+
35+
---
36+
37+
## Phase 3: CDDL-Schema + zcbor-Codegen
38+
39+
**Warum hier:** Die C-Strukturen für Cloud-Commands müssen existieren, bevor `boot_cloud_cmd.c` geschrieben werden kann.
40+
41+
**Kritische Dateien:**
42+
43+
Neue CDDL-Datei (z.B. `cddl/toob_cloud_cmd.cddl`) — Das Schema aus dem Plan. Agent muss sicherstellen, dass das zcbor-Codegen-Tooling (referenziert in `cmake/toob_core.cmake` unter `generate_manifest`) diese Datei mit aufnimmt.
44+
45+
`cmake/toob_core.cmake` — Der `add_custom_command` für `generate_manifest` muss den neuen CDDL-Input verarbeiten und `boot_cloud_cmd_types.h` / `boot_cloud_cmd_decode.c` generieren. Alternativ die Go-CLI erweitern.
46+
47+
`CMakeLists.txt` — Die neue `TOOB_FEATURE_CLOUD_COMMANDS`-Option einfügen, die `boot_cloud_cmd.c` bedingt kompiliert.
48+
49+
---
50+
51+
## Phase 4: Device-ID Derivation
52+
53+
**Warum hier:** Wird von Phase 5 (Cloud-Command-Verifikation) als Device-ID-Match benötigt, hat aber selbst keine Abhängigkeit auf die Command-Pipeline.
54+
55+
**Kritische Dateien:**
56+
57+
Neue Datei `toobloader/core/boot_identity.c` + `toobloader/core/include/boot_identity.h` — Implementiert `boot_derive_device_id(platform, out_id[32])`. Nutzt `platform->crypto->read_chip_uid()`, `platform->crypto->read_pubkey()` (Index 0), und `platform->crypto->hash_*()`. Agent muss den Domain-Separator-String `"toob-device-id-v1"` exakt wie spezifiziert einhashen.
58+
59+
`toobloader/core/boot_main.c` — In Block 5 (Handoff) die Device-ID berechnen und in `local_handoff.device_id` schreiben. **Vorsicht:** Die `boot_diag_seal()` und der Handoff-CRC müssen nach dem neuen Feld berechnet werden.
60+
61+
`sdk/libtoob/toob_handoff.c``toob_get_handoff()` und `toob_validate_handoff()` müssen die neue Struct-Größe und den neuen `TOOB_HANDOFF_STRUCT_VERSION` korrekt prüfen. Hier liegt ein subtiler Migrationspunkt: Geräte im Feld mit Version `0x01000000` dürfen nicht hart abstürzen. Der Agent sollte einen Fallback einbauen.
62+
63+
---
64+
65+
## Phase 5: `boot_cloud_cmd.c` (Kern der Killswitch-Logik)
66+
67+
**Warum hier:** Alle Abhängigkeiten (Types, CDDL-Parser, Device-ID, KDM-Konzept) sind jetzt da.
68+
69+
**Kritische Dateien:**
70+
71+
Neue Datei `toobloader/core/boot_cloud_cmd.c` + `toobloader/core/include/boot_cloud_cmd.h` — Die komplexeste neue Datei. Agent muss strikt das Sequencing-Protokoll einhalten (Parse → Device-ID → Counter → Verify → Advance → Dispatch). Jeder Schritt vor dem Counter-Advance darf **keinen** Seiteneffekt haben. Die KDM-Lade-Logik (A/B-Slot mit TMR-Sequenz-Check) ist eine eigene Subfunktion. Der Agent muss das bestehende Glitch-Shield-Pattern (Double-Check + `BOOT_GLITCH_DELAY()` + CFI-Akkumulator) konsistent anwenden — exakt wie in `boot_verify.c` und `boot_rollback.c`.
72+
73+
`toobloader/core/boot_panic.c` — Der `BOOT_ERR_DEVICE_LOCKED`-Reason muss den Firmware-Flash-Pfad in Block 3 sperren, aber den 2FA-Auth-Pfad (Block 2) weiterhin erlauben, mit der Erweiterung, dass nach erfolgreicher Auth ein UNLOCK-Envelope erwartet wird statt eines Firmware-Streams.
74+
75+
**Besondere Risiken:** Die `crypto_arena` wird von `boot_cloud_cmd.c` exklusiv beansprucht (Zero-Allocation). Der Agent muss sicherstellen, dass kein anderer Code gleichzeitig die Arena nutzt. Da Cloud-Commands vor der Update-Pipeline evaluiert werden, ist das sequenziell sicher — aber nur, wenn die Arena vor Rückgabe gesäubert wird (`boot_secure_zeroize`).
76+
77+
---
78+
79+
## Phase 6: `boot_state.c` Integration
80+
81+
**Warum hier:** Die Command-Pipeline steht, jetzt wird sie in den Orchestrator eingehängt.
82+
83+
**Kritische Dateien:**
84+
85+
`toobloader/core/boot_state.c` — Zwei neue Schritte zwischen Step 2 und Step 3:
86+
87+
Step 2.5: `_handle_cloud_cmd()` — Liest `CHIP_CLOUD_CMD_SLOT`, ruft `boot_cloud_cmd_evaluate()` auf. Bei `TOOB_CMD_KILLSWITCH` schreibt es `WAL_INTENT_DEVICE_LOCKED`. Bei `TOOB_CMD_FORCE_UPDATE` schreibt es `WAL_INTENT_UPDATE_PENDING` (und die normale Pipeline in Step 4 übernimmt). Der CFI-Akkumulator `state_cfi` braucht einen neuen Token (`CFI_STEP_2_5`). **Das ist der heikelste Eingriff:** Der Agent muss den `expected_cfi` am Ende von `state_cleanup` um den neuen Token erweitern und sicherstellen, dass der Token auch bei Skip-Pfaden (kein Command vorhanden) korrekt XOR'd wird.
88+
89+
Step 2.7: Lock-State-Check — Prüft ob `WAL_INTENT_DEVICE_LOCKED` der aktive Intent ist. Wenn ja, nur UNLOCK akzeptieren, sonst → `boot_panic(BOOT_ERR_DEVICE_LOCKED)`.
90+
91+
`toobloader/core/include/boot_state.h` — Kein neues Public-API nötig, aber der Lifecycle-Kommentar muss aktualisiert werden.
92+
93+
---
94+
95+
## Phase 7: libtoob OS-API + Handoff-Erweiterung
96+
97+
**Warum hier:** Die Bootloader-Seite ist fertig, jetzt die OS-Boundary.
98+
99+
**Kritische Dateien:**
100+
101+
`sdk/libtoob/include/libtoob.h` — Neue Funktionen: `toob_submit_cloud_command()`, `toob_get_device_id()`, `toob_is_device_locked()`.
102+
103+
Neue Datei `sdk/libtoob/toob_cloud_submit.c` — Schreibt den Envelope in `CHIP_CLOUD_CMD_SLOT` via `toob_os_flash_erase()` + `toob_os_flash_write()` mit CRC-Read-Back. Danach `toob_wal_naive_append()` mit `TOOB_WAL_INTENT_CLOUD_CMD`. Der Agent muss die bestehende `toob_wal_naive.c`-Lock-Logik beachten: `WAL_INTENT_CLOUD_CMD` darf parallel zu einem `WAL_INTENT_UPDATE_PENDING` existieren (unterschiedliche Slots).
104+
105+
`sdk/libtoob/include/libtoob_config_sandbox.h` — Neue Makros für `CHIP_CLOUD_CMD_SLOT`, `CHIP_KDM_SLOT_A`, `CHIP_KDM_SLOT_B`.
106+
107+
---
108+
109+
## Phase 8: Provisioning-HAL + CLI-Integration
110+
111+
**Warum hier:** Hängt von allem Vorherigen ab, hat aber keinen Einfluss auf den Runtime-Boot-Pfad.
112+
113+
**Kritische Dateien:**
114+
115+
`common/include/boot_hal.h` — Neues `provisioning_hal_t`-Struct. Optional als Feld in `boot_platform_t` (mit NULL-Default für Non-Provisioning-Builds).
116+
117+
`toobloader/core/boot_main.c` — DSLC-Check in Block 2.5 (nach Recovery-Pin, vor State-Machine): Wenn `DSLC == 0x00`, UART-Provisioning-Loop aufrufen statt `boot_state_run()`.
118+
119+
Neue Datei `toobloader/core/boot_provisioning.c` — COBS-basiertes UART-Protokoll, angelehnt an die existierende Logik in `boot_panic.c` Block 2/3.
120+
121+
## Zusammenfassung: Abhängigkeitsgraph
122+
123+
```
124+
Phase 1 (Types/ABI) ──┬──→ Phase 2 (Stage 0 DSLC)
125+
├──→ Phase 3 (CDDL/zcbor)
126+
├──→ Phase 4 (Device-ID)
127+
128+
└──→ Phase 3 + 4 ──→ Phase 5 (boot_cloud_cmd.c)
129+
130+
├──→ Phase 6 (boot_state.c)
131+
├──→ Phase 7 (libtoob API)
132+
└──→ Phase 8 (Provisioning)
133+
134+
└──→ Phase 9 (Tests)
135+
```
136+
137+
Phase 2 kann parallel zu 3-4 laufen. Phase 7 kann parallel zu 6 starten, sofern die Types aus Phase 1 stehen.

0 commit comments

Comments
 (0)