From eb70ba8594fb1d0121fc85d39b119d5872eb5eed Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 12 Oct 2026 06:57:56 -0500 Subject: [PATCH 1/2] native v1 P08 cut C (host, part 2): SEC2 chain-of-trust message encoder + workflow-file guard (refs #286) ck_gsp_cot_encode (native/kernel/tools): byte-exact encoder, decoder and refusal tests for the message the pinned driver (nvidia-open 580.173.02) sends to SEC2 to boot the GSP-FMC on GB10B: MCTP transport dword (0xC0000000 single packet, SEID 0), NVDM header (0x1410DE7E, type COT), NVDM_PAYLOAD_COT version 1 (860 packed bytes: image address, image size in frtsSysmemSize, hash 48, public key 384, signature 384, boot-args address), the 868-byte EMEM packet with QUEUE_TAIL 864, and GSP_FMC_BOOT_PARAMS (88 bytes, natural layout, offsets checked against the compiler). Every field, value and register step is cited file:line from the driver source in docs/GB10_FIRMWARE_INVENTORY.md section 10; known unknowns 1 and 2 updated. Self-test: layouts, golden header words, round trips, 46 mutations and every header truncation refused by name: CK_GSP_COT_ENCODE_SELFTEST PASS (80 checks), same under ASan/UBSan. `make -C native/kernel gsp-cot-test`, part of `make test`. Nothing is sent to a device. Also: scripts/workflow_files_check.sh + .github/workflows/workflow-files.yml, an always-on check that fails when GitHub refused a workflow file on the commit (a failed run with zero jobs never shows in the PR checks; that is how ck-kernel.yml stayed silent for four hours today). Tested locally: REFUSED on f47f6c7, OK on 20847ab. Required checks on main now include crumb and AIEN Verification; this check is to be added once it has run on main. Co-Authored-By: Claude Fable 5.1 --- .crumb | 18 +- .github/workflows/workflow-files.yml | 27 ++ docs/.crumb | 8 +- docs/GB10_FIRMWARE_INVENTORY.md | 120 ++++- native/.crumb | 16 +- native/kernel/.crumb | 16 +- native/kernel/Makefile | 17 +- native/kernel/tools/.crumb | 10 +- native/kernel/tools/ck_gsp_cot_encode.c | 617 ++++++++++++++++++++++++ scripts/.crumb | 10 +- scripts/workflow_files_check.sh | 36 ++ 11 files changed, 840 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/workflow-files.yml create mode 100644 native/kernel/tools/ck_gsp_cot_encode.c create mode 100755 scripts/workflow_files_check.sh diff --git a/.crumb b/.crumb index 5fc298a6..d9c437a4 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "7e7934c11eb156bf4249648ef757d6135570877703a1ccab214c07cb5a57e235", + "digest": "0893e0c34b7443fafe6a41c7ca2d0db8a9482bcf4aa0412bbb60efab02d31b94", "last_commit": "f47f6c7", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "362c8c616872caca2069f3e748db0d8fb7c807bff2771679c4973481a15901f2", + "digest": "cc6320946ab6360e3bdd81cdc6b753e5c82839961602bbe41d9aaa1dd4e068a6", "last_commit": "f47f6c7", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "8f2ba6515d449096eccaa96e1d710d5556e36425d1b82eb8ef096d85200059f9", + "digest": "348804e26984e873db9914d2a3ebfcf6c9ea02619247d78809999011b354e048", "last_commit": "22eb360", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:49ee7a6b7ab0a6a96d0329f00ef1839ff64e47aba7d5717ea27f8bbc865ace9f", - "compiled_at": "2026-10-12T11:44:52Z", + "children_root": "sha256:e13f620786d98cea7090138ea217f1f821440fed426d80155536c0796b04b7cb", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:1ee2a15770e45746c15c5cdea47206165cf26eda84c4a39d1746c1096d89e9cc", + "digest": "sha256:f21da1407d59d7d4318635517bb9d45937a68c04c2747fbfd9254d559b750432", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3087, - "generated_at_commit": "f47f6c76286d7c85b9d038afc730619c54266a9f", - "source_tree": "sha256:8e951d5463b4dde2502e3e2c7324bae7586f14fb04ef2355bc493b66ec6120e1" + "files": 3090, + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:1079486b153c956a636f7eb5008f95b01f388730a1682ff5cc5789c1f4a8067f" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/workflow-files.yml b/.github/workflows/workflow-files.yml new file mode 100644 index 00000000..00cf3702 --- /dev/null +++ b/.github/workflows/workflow-files.yml @@ -0,0 +1,27 @@ +# Always-on guard: a workflow file GitHub cannot parse yields a run with zero +# jobs that never shows in the PR checks, so the job it carries silently stops +# running (2026-10-12: ck-kernel.yml, four hours). This job has no path filter +# and is a required check on main, so that silence becomes a red check. +name: Workflow files accepted + +on: + pull_request: + push: + branches: [main] + +permissions: + actions: read + contents: read + +jobs: + accepted: + name: workflow files accepted + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - name: Every workflow run on this commit has jobs + env: + GH_TOKEN: ${{ github.token }} + SHA: ${{ github.event.pull_request.head.sha || github.sha }} + run: sh scripts/workflow_files_check.sh "$SHA" diff --git a/docs/.crumb b/docs/.crumb index f1139326..0469dded 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:baea130f2c52779b57d90139beb66ac01b21ab499d113471a334be5500f3e369", - "compiled_at": "2026-10-12T11:39:56Z", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:7e7934c11eb156bf4249648ef757d6135570877703a1ccab214c07cb5a57e235", + "digest": "sha256:0893e0c34b7443fafe6a41c7ca2d0db8a9482bcf4aa0412bbb60efab02d31b94", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 70, - "generated_at_commit": "22eb3603074e5df77df9914dbd301d67122564b5", - "source_tree": "sha256:5641e25791a12e563582b9a529277f203c5ac192ffce39e8720ed47adc0edc19" + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:c774a2fac1bee6917cd97c6f4df2cca4b540bec809b44a59914e6a26fe23f4e6" }, "owner_lane": "", "provenance": { diff --git a/docs/GB10_FIRMWARE_INVENTORY.md b/docs/GB10_FIRMWARE_INVENTORY.md index ac12670a..44803046 100644 --- a/docs/GB10_FIRMWARE_INVENTORY.md +++ b/docs/GB10_FIRMWARE_INVENTORY.md @@ -249,11 +249,11 @@ code into AIENOS would require carrying the MIT notice (none was copied here). firmware metadata" by `ck_gsp_fw_inspect`. The next host-only steps that do not need the machine: (a) a small extractor over the two public `g_bindata_*_GB10B.c` files that writes the eight arrays as files with - digests (our own tool, no Python); (b) a C struct definition and encoder for - `NVDM_PAYLOAD_COT` and the MCTP/NVDM headers with fixture tests, from - `src/nvidia/inc/kernel/gpu/fsp/kern_fsp_cot_payload.h`, - `fsp/fsp_nvdm_format.h`, `fsp/fsp_mctp_format.h` (not yet read); (c) the - `GspFwWprMeta` and GSP-FMC argument layouts from the same source tree. + digests (our own tool, no Python); (b) DONE 2026-10-12: the encoder, decoder + and refusal tests for `NVDM_PAYLOAD_COT`, the MCTP/NVDM headers, the EMEM + packet and `GSP_FMC_BOOT_PARAMS` are `ck_gsp_cot_encode` (section 10); + (c) remaining: an encoder for `GspFwWprMeta` (256 bytes, layout known, the + GH100 populate values not yet traced) and the libos init-argument block. - The machine-side part of cut C (first SEC2 command, FMC boot, GSP-RM init done) is an attended-window item under the P08 rules: documented cold power state, no prior Linux GPU initialization, camera, abort rule, and the @@ -261,11 +261,17 @@ code into AIENOS would require carrying the MIT notice (none was copied here). ## 8. Known unknowns -1. [UNKNOWN] The exact `NVDM_PAYLOAD_COT` field layout, `cotPayloadVersion`, - `cotPayloadSignatureSize` and `cotPayloadPublicKeySize` values for GB10B - (set in the SEC2 object constructor; not read). -2. [UNKNOWN] The `GspFwWprMeta`, GSP-FMC argument block (`pGspFmcArgumentsCached`) - and libos init-argument layouts this FMC build expects. +1. RESOLVED 2026-10-12 [SOURCE]: the `NVDM_PAYLOAD_COT` layout is 860 packed + bytes, GB10B uses version 1, signature and key sizes 384, hash 48; the + whole wire format is in section 10 and checked by `ck_gsp_cot_encode`. +2. [PARTLY RESOLVED 2026-10-12] `GSP_FMC_BOOT_PARAMS` (88 bytes, section 10) + and the `GspFwWprMeta` struct (256 bytes, `gsp/gsp_fw_wpr_meta.h`, magic + `0xdc3aae21371a60b3`, revision 1; GB10B zeroes `vgaWorkspaceSize`, + `pmuReservedSize` and `nonWprHeapSize`, kernel_gsp_gb10b.c:32-55) are + known. [UNKNOWN] the values `kgspPopulateWprMeta_GH100` computes (radix3 + ELF placement, heap sizes, WPR carveout) and the libos init-argument block + (`gsp_init_args.h` gives `GSP_ARGUMENTS_CACHED`; the libos block itself not + traced). 3. [UNKNOWN] What SEC2 requires to be already true when the first command arrives (its own firmware loaded by the SoC boot chain? clocks? power state?), and whether UEFI leaves the GPU in that state at AIENOS entry. @@ -293,9 +299,95 @@ binary), kernel_gsp_gh100.c (prepare, bootstrap), kernel_gsp_gb100.c, kernel_gsp_gb10b.c, kernel_gsp_booter.c and kernel_gsp_fwsec.c (grep only), kernel_sec2_gb10b.c, g_kernel_gsp_nvoc.c/.h, g_kernel_sec2_nvoc.c, g_kern_fsp_nvoc.c (property tables only), the two GB10B bindata files -(metadata comments only), README.md, COPYING, the firmware copyright file. Not -read: kern_fsp_cot_payload.h, the NVDM/MCTP format headers, kernel_sec2.c -(`ksec2SendMessage`), the GSP RPC layer, dev_sec_pri.h register values, ACR or -GSP internals (not available). No Context7 or web manual covers this layer; the +(metadata comments only), README.md, COPYING, the firmware copyright file; +for section 10 also kern_fsp_cot_payload.h, fsp_nvdm_format.h, +fsp_mctp_format.h, fsp_emem_channels.h, kernel_sec2.c (`ksec2SendMessage`, +`ksec2PollForCanSend`), g_kernel_sec2_nvoc.c/.h (version, sizes, SEID), +gspifpub.h, gsp_init_args.h, gsp_fw_wpr_meta.h, kernel_gsp_gh100.c +(`kgspSetupGspFmcArgs`), and published/blackwell/gb10b dev_sec_pri.h, +dev_gsp.h, dev_falcon_v4.h. Not read: the GSP RPC layer, the libos +init-argument block, ACR or GSP internals (not available). No Context7 or web manual covers this layer; the DGX Spark user guide is silent on GSP firmware loading (DOCS SILENT on native GSP bring-up). + +## 10. The SEC2 chain-of-trust message, byte for byte [SOURCE] + +Everything in this section is read from open-gpu-kernel-modules tag +580.173.02 and mirrored by `native/kernel/tools/ck_gsp_cot_encode.c` +(`make -C native/kernel gsp-cot-test`, part of `make test`). Nothing here was +sent to the device. + +Transport. NVDM (NVIDIA Data Model) over MCTP over SEC2 EMEM channel 0, +1024 bytes (`fsp/fsp_emem_channels.h:9-11`; `kernel_sec2_gb10b.c:36-41`, +`:322-333`). A packet is two header dwords then the payload +(`kernel_sec2.c:50-52`, `:305-325`): + +| dword | field | value for the boot message | source | +|---|---|---|---| +| 0 | MCTP transport header: SOM bit 31, EOM bit 30, SEQ 29:28, TO 27, TAG 26:24, SEID 23:16, DEID 15:8, RSVD 7:4, VERSION 3:0 | `0xC0000000` (SOM=1, EOM=1, SEQ=0, SEID=0; the driver sets only those four) | `fsp_mctp_format.h:8-16`; `kernel_sec2.c:319-321`; SEID 0 for GB10B `g_kernel_sec2_nvoc.c:879-888`, `g_kernel_sec2_nvoc.h:907-909` | +| 1 | NVDM header: TYPE 6:0 = 0x7e (vendor PCI), IC 7 = 0, VENDOR_ID 23:8 = 0x10de, NVDM_TYPE 31:24 | `0x1410DE7E` (NVDM_TYPE_COT = 0x14) | `fsp_mctp_format.h:17-22`; `fsp_nvdm_format.h:14`; `kernel_sec2_gb10b.c:391-402` | + +A message longer than 1016 bytes would continue in packets that carry only +the MCTP dword with SOM=0 and SEQ = (n mod 4) (`kernel_sec2.c:330-357`); the +boot message is 860 bytes, so it is always one packet, and the driver sends +only this one command on the channel (`kernel_sec2_gb10b.c:719-722`). + +Payload `NVDM_PAYLOAD_COT`, `#pragma pack(1)`, 860 bytes +(`src/nvidia/inc/kernel/gpu/fsp/kern_fsp_cot_payload.h:12-29`): + +| offset | size | field | GB10B value | source | +|---|---|---|---|---| +| 0 | 2 | version | 1 | `g_kernel_sec2_nvoc.c:478-482` | +| 2 | 2 | size | 860 (`sizeof`) | `kernel_sec2_gb10b.c:580-581` | +| 4 | 8 | gspFmcSysmemOffset | physical address of the GSP-FMC image in system memory | `:507` | +| 12 | 8 | frtsSysmemOffset | 0 (never set) | `:578` zero-fill | +| 20 | 4 | frtsSysmemSize | the GSP-FMC image size (195,912), sic | `:508` | +| 24 | 8 | frtsVidmemOffset | 0 | `:578` | +| 32 | 4 | frtsVidmemSize | 0 | `:578` | +| 36 | 48 | hash384 | `UCODE_HASH` array | `:514` | +| 84 | 384 | publicKey | `UCODE_PKEY` array | `:526-527`; size `g_kernel_sec2_nvoc.c:475-476` | +| 468 | 384 | signature | `UCODE_SIG` array | `:519-520`; size `g_kernel_sec2_nvoc.c:472-473` | +| 852 | 8 | gspBootArgsSysmemOffset | physical address of `GSP_FMC_BOOT_PARAMS` | `:532`, `:241-258` | + +The packet is therefore 868 bytes. It is written at EMEM offset 0 with the +write auto-increment bit, one dword at a time, then QUEUE_HEAD(0) = 0 and +QUEUE_TAIL(0) = 864 (padded size minus one dword) (`kernel_sec2_gb10b.c: +700-732`, `:108-152`, `:160-210`). The channel may be written only while +HEAD == TAIL (`:344-356`, polled `kernel_sec2.c:605-640`); the command counts +as handled once FALCON_MAILBOX0 no longer reads `0xc001cafe` (`:285-297`); +before the boot the driver also waits until the GSP falcon's HWCFG2 register +reads non-zero and not the `0xBADF41xx` "target locked" pattern (`:262-281`). +Register addresses for GB10B: `published/blackwell/gb10b/dev_sec_pri.h` +(MAILBOX0/1, QUEUE_HEAD/TAIL(i), EMEMC(i), EMEMD(i)), `dev_gsp.h` (NV_PGSP +base), `dev_falcon_v4.h` (HWCFG2); the tool does not use them. + +Boot arguments the payload points at: `GSP_FMC_BOOT_PARAMS` +(`src/nvidia/arch/nvalloc/common/inc/gsp/gspifpub.h`), natural C layout, 88 +bytes on the LP64 ABI the driver and this host share (the self-test checks the +offsets against the compiler); filled by `kgspSetupGspFmcArgs_GH100` +(`kernel_gsp_gh100.c:415-470`), allocated 4 KiB aligned (`:164`): + +| offset | size | field | fresh-boot value | +|---|---|---|---| +| 0 | 4 | initParams.regkeys | 0 unless CC or NVLink proxy keys | +| 8 | 4 | bootGspRmParams.target | DMA target of the descriptor (0 FB, 1 coherent sysmem, 2 non-coherent sysmem) | +| 12 | 4 | bootGspRmParams.gspRmDescSize | 256 (`sizeof GspFwWprMeta`) | +| 16 | 8 | bootGspRmParams.gspRmDescOffset | physical address of the `GspFwWprMeta` | +| 24 | 8 | bootGspRmParams.wprCarveoutOffset | not set by the driver (0) | +| 32 | 4 | bootGspRmParams.wprCarveoutSize | not set (0) | +| 36 | 1 | bootGspRmParams.bIsGspRmBoot | 1 | +| 40 | 4 | gspRmParams.target | DMA target of the libos init arguments | +| 48 | 8 | gspRmParams.bootArgsOffset | physical address of the libos init arguments | +| 56 | 24 | gspSpdmParams | only with SPDM (assumed off) | +| 80 | 8 | gspRmMemParams.flushSysmemAddrVal{Lo,Hi} | only with CC (0) | + +INFERRED, enforced by the tool but not a driver check: the image address is +4 KiB aligned (the driver maps `NV_ALIGN_UP(size, 0x1000)` bytes of +page-granular system memory, `kernel_sec2_gb10b.c:489-495`) and every +system address fits the 41-bit DMA window `/proc/driver/nvidia/gpus` reports +for this GPU (section 2; `--dma-bits` overrides). + +Evidence 2026-10-12 on the box: `CK_GSP_COT_ENCODE_SELFTEST: PASS` (80 checks: +both layouts against the compiler, golden header words, encode/decode round +trips, 46 field mutations and every header truncation refused by name), same +under ASan/UBSan. diff --git a/native/.crumb b/native/.crumb index 34313b0e..931a7101 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "363106d1f490a2b01ec6e574586fba7608c4d21daa15f8193a6eb6c09436b771", - "last_commit": "22eb360", + "digest": "335672c68d3199b2bf0393776ee1415c7d5dd67bd11ab5229d0c6d3c261a36f5", + "last_commit": "f47f6c7", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:b131138811cf35bc55eaf03588d4811aedb64faed4f43d833f5744c5b59cf78d", - "compiled_at": "2026-10-12T11:39:56Z", + "children_root": "sha256:15b7f47927a490dca0f1274ab21b3e8929646e5b8510e8f1f33be02e16dd79d7", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:362c8c616872caca2069f3e748db0d8fb7c807bff2771679c4973481a15901f2", + "digest": "sha256:cc6320946ab6360e3bdd81cdc6b753e5c82839961602bbe41d9aaa1dd4e068a6", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 470, - "generated_at_commit": "22eb3603074e5df77df9914dbd301d67122564b5", - "source_tree": "sha256:f04c1759895b503bd9e16472e7390e4548af3a69bafe559cd4bd4ab865111550" + "files": 471, + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:a7d6fe71fe72f3315c62c83ab5a330220eb31a6a3d07be8e18ca0738a3ebe04a" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 632d4982..4c495593 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -93,21 +93,21 @@ "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { - "digest": "17933def2bc3028812efbff34692c71e95e21d7c423e64646a3f2ad9dc5777ea", - "last_commit": "e90226b", + "digest": "544d6b8c2ccf34b032a365b1ce1af2b6cef275e015751f9a08718a9b5b9e9d4f", + "last_commit": "f47f6c7", "name": "tools", "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:c02bf658c88780c2019300a9cc12cb47465a58d3c8a7f9536ebdb3ca37f28d31", - "compiled_at": "2026-10-12T11:39:56Z", + "children_root": "sha256:bd02cebd8705f33186b3996f745c024798c218972391e8cc6d793788d35c9a2b", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:363106d1f490a2b01ec6e574586fba7608c4d21daa15f8193a6eb6c09436b771", + "digest": "sha256:335672c68d3199b2bf0393776ee1415c7d5dd67bd11ab5229d0c6d3c261a36f5", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 306, - "generated_at_commit": "22eb3603074e5df77df9914dbd301d67122564b5", - "source_tree": "sha256:e6ca170ff7a8f29ca37248259e42598bbb44d61d116f5f357f301e91eb2ffea1" + "files": 307, + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:123c2e532b0928c681ba474d6385ab561697bab48ef8eb8c17237de09e6292f4" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 9c0d1971..97dc199a 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -1066,8 +1066,8 @@ smmu-l2-mutants: $(OUT)/host/test_smmu else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ if [ $$fail = 0 ]; then echo "CK_SMMU_L2_MUTANTS: PASS"; else echo "CK_SMMU_L2_MUTANTS: FAIL"; exit 1; fi -test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart gsp-fw-inspect-test - @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart gsp-fw-inspect-test,$^); do $$t || fail=1; done; \ +test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test + @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test,$^); do $$t || fail=1; done; \ if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS"; else echo "CK_CORE_HOST: FAIL"; exit 1; fi sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) @@ -1468,6 +1468,19 @@ gsp-fw-inspect-test: $(GSP_FW_TOOL) echo "$$out" | grep -q '^sha256_file $(GSP_FW_SHA256)$$' && echo "CK_GSP_FW_INSPECT_PIN: PASS" || { echo "CK_GSP_FW_INSPECT_PIN: FAIL (digest differs from the pin)"; exit 1; }; \ else echo "CK_GSP_FW_INSPECT_PIN: NOT_RUN ($(GSP_FW_FILE) absent)"; fi +# ---- host encoder/decoder for the SEC2 chain-of-trust boot message (aienos#286 cut C/D host work) ---- +# Byte-exact NVDM-over-MCTP packet and GSP_FMC_BOOT_PARAMS layouts from the pinned +# driver source; self-test = layouts, golden headers, round trips, every mutation refused. +# Never loads anything. docs/GB10_FIRMWARE_INVENTORY.md section 10. +GSP_COT_TOOL := $(OUT)/host/ck_gsp_cot_encode +$(GSP_COT_TOOL): $(KDIR)/tools/ck_gsp_cot_encode.c $(NATIVE)/argus/sha256.c $(NATIVE)/argus/sha256.h + @mkdir -p $(dir $@) + $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_gsp_cot_encode.c $(NATIVE)/argus/sha256.c +gsp-cot-encode: $(GSP_COT_TOOL) +gsp-cot-test: $(GSP_COT_TOOL) + $(GSP_COT_TOOL) selftest | grep -E '^CK_GSP_COT_ENCODE_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_COT_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } + @$(GSP_COT_TOOL) selftest | tail -1 + # ---- host checker for the AIENOS_CK_SCREEN gate (scripts/qemu_ck_screen_test.sh) ---- FB_CHECK_TOOL := $(OUT)/host/ck_fb_check $(FB_CHECK_TOOL): $(KDIR)/tools/ck_fb_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/fbcon.h $(KDIR)/core/font8x8.h diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb index ed60363b..e749c346 100644 --- a/native/kernel/tools/.crumb +++ b/native/kernel/tools/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T11:39:56Z", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:17933def2bc3028812efbff34692c71e95e21d7c423e64646a3f2ad9dc5777ea", + "digest": "sha256:544d6b8c2ccf34b032a365b1ce1af2b6cef275e015751f9a08718a9b5b9e9d4f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 13, - "generated_at_commit": "22eb3603074e5df77df9914dbd301d67122564b5", - "source_tree": "sha256:7881dde2c31a3a3cef6c69fbb636f2ca6d6c4e9c12ad199c1a92c870e68764d6" + "files": 14, + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:9dfee8bc08b527940f95dfc286ca69933a45d817697046de0b05b0805bea4e86" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tools/ck_gsp_cot_encode.c b/native/kernel/tools/ck_gsp_cot_encode.c new file mode 100644 index 00000000..4b60eb5d --- /dev/null +++ b/native/kernel/tools/ck_gsp_cot_encode.c @@ -0,0 +1,617 @@ +/* ck_gsp_cot_encode -- host tool: byte-exact encoder, decoder and refusal + * tests for the message the pinned Linux driver (nvidia-open 580.173.02) + * sends to SEC2 to boot the GSP first-stage image (GSP-FMC) on the GB10 + * (aienos#286 cut C/D host work: "parsers and refusal tests for firmware + * metadata. No loading"). docs/GB10_FIRMWARE_INVENTORY.md section 10 is the + * report this tool backs. Nothing here touches a device. + * + * Wire format, every line from open-gpu-kernel-modules tag 580.173.02: + * - Transport: NVDM (NVIDIA Data Model) over MCTP over the SEC2 EMEM + * channel 0, 1024 bytes (src/nvidia/arch/nvalloc/common/inc/fsp/ + * fsp_emem_channels.h:9-11; kernel_sec2_gb10b.c:36-41, :322-333). + * - A packet is two header dwords then the payload (kernel_sec2.c:50-52, + * :305-325). Dword 0 is the MCTP transport header (fsp_mctp_format.h: + * 8-16: SOM bit 31, EOM bit 30, SEQ 29:28, TO 27, TAG 26:24, SEID 23:16, + * DEID 15:8, RSVD 7:4, VERSION 3:0); the driver sets only SOM, EOM, + * SEID and SEQ (kernel_sec2.c:319-321; kern_fsp_gh100.c:319-322). + * Dword 1 is the NVDM message header (fsp_mctp_format.h:17-22: + * TYPE 6:0 = 0x7e vendor-PCI, IC bit 7 = 0, VENDOR_ID 23:8 = 0x10de, + * NVDM_TYPE 31:24; kernel_sec2_gb10b.c:391-402). + * - The boot message is NVDM_TYPE_COT = 0x14 (fsp_nvdm_format.h:14) and + * the GB10B SEID is 0 for every type (g_kernel_sec2_nvoc.c:879-888, + * g_kernel_sec2_nvoc.h:907-909). The driver sends it as one packet + * (payload <= 1016 bytes; kernel_sec2.c:305-308) and never sends a + * second command on this channel (kernel_sec2_gb10b.c:719-722). + * - Payload: NVDM_PAYLOAD_COT, packed, 860 bytes (src/nvidia/inc/kernel/ + * gpu/fsp/kern_fsp_cot_payload.h:12-29): version u16, size u16, + * gspFmcSysmemOffset u64, frtsSysmemOffset u64, frtsSysmemSize u32, + * frtsVidmemOffset u64, frtsVidmemSize u32, hash384 48 B, publicKey + * 384 B, signature 384 B, gspBootArgsSysmemOffset u64. GB10B uses + * version 1 (g_kernel_sec2_nvoc.c:478-482), size = 860 + * (kernel_sec2_gb10b.c:580-581), signature and key sizes 384 + * (g_kernel_sec2_nvoc.c:472-476). The driver zero-fills the payload and + * sets only gspFmcSysmemOffset, frtsSysmemSize (= the GSP-FMC image + * size, sic), hash384, signature, publicKey and gspBootArgsSysmemOffset + * (kernel_sec2_gb10b.c:507-532, :578); frtsSysmemOffset and the two + * frtsVidmem fields stay 0. + * - After the packet is written at EMEM offset 0 with auto-increment, + * QUEUE_HEAD = 0 and QUEUE_TAIL = padded size - 4 (kernel_sec2_gb10b.c: + * 700-732); SEC2 sets HEAD = TAIL when it has taken the packet + * (:344-356) and MAILBOX0 leaves 0xc001cafe when the command is handled + * (:285-297). + * - Boot arguments the payload points at: GSP_FMC_BOOT_PARAMS + * (src/nvidia/arch/nvalloc/common/inc/gsp/gspifpub.h), natural C layout + * (not packed), 88 bytes on the AArch64 LP64 ABI the driver and this + * host share; filled by kgspSetupGspFmcArgs_GH100 + * (kernel_gsp_gh100.c:415-470): descriptor = GspFwWprMeta (256 bytes, + * gsp_fw_wpr_meta.h) on a fresh boot, bIsGspRmBoot = true, bootArgs = + * the libos init arguments, SPDM and flush fields only with CC. + * + * Refusals this tool enforces when encoding or decoding (reason strings are + * the test oracle): zero or unaligned image address, address beyond the DMA + * window, zero image size, hash/key/signature length not 48/384/384, zero + * boot-args address, payload version or size field wrong, non-zero + * reserved FRTS fields, payload that does not fit one packet, header dwords + * that are not the single-packet COT shape, packet length not a dword + * multiple, DMA target out of range, descriptor size not 256, boot flag + * not set. + * + * INFERRED (not a driver check): the image address must be 4 KiB aligned + * (the driver maps NV_ALIGN_UP(size, 0x1000) bytes of page-granular system + * memory, kernel_sec2_gb10b.c:489-495) and every system address must fit + * the 41-bit DMA window /proc/driver/nvidia/gpus reports for this GPU + * (--dma-bits overrides). + * + * ck_gsp_cot_encode selftest layout, golden headers, round trips, + * every mutation and truncation refused + * ck_gsp_cot_encode layout print the two layouts as "field offset size" + * ck_gsp_cot_encode encode --fmc-addr HEX --fmc-size N --hash FILE + * --key FILE --sig FILE --bootargs-addr HEX [--dma-bits N] [--out FILE] + * build the packet; prints header words, + * sizes, tail offset and SHA-256 + * Hosted C, no outside libraries (SHA-256 is the kernel's own, native/argus). + * Never part of an image. No Python. */ +#include +#include +#include +#include +#include + +#include "sha256.h" + +/* ---- constants from the driver (SOURCE lines in the header comment) ---- */ +#define EMEM_CHANNEL_BYTES 1024u +#define PACKET_HEADER_BYTES 8u +#define PACKET_PAYLOAD_CAP (EMEM_CHANNEL_BYTES - PACKET_HEADER_BYTES) +#define NVDM_TYPE_COT 0x14u +#define MCTP_MSG_TYPE_VENDOR_PCI 0x7eu +#define MCTP_VENDOR_ID_NV 0x10deu +#define COT_VERSION_GB10B 1u +#define COT_HASH_BYTES 48u +#define COT_KEY_BYTES 384u +#define COT_SIG_BYTES 384u +#define COT_PAYLOAD_BYTES 860u +#define COT_PACKET_BYTES (PACKET_HEADER_BYTES + COT_PAYLOAD_BYTES) /* 868 */ +#define FMC_PARAMS_BYTES 88u +#define WPR_META_BYTES 256u +#define DMA_BITS_DEFAULT 41u +#define GSP_DMA_TARGET_COUNT 3u + +/* NVDM_PAYLOAD_COT offsets (packed). */ +#define COT_OFF_VERSION 0u +#define COT_OFF_SIZE 2u +#define COT_OFF_FMC_ADDR 4u +#define COT_OFF_FRTS_SYSMEM_OFF 12u +#define COT_OFF_FRTS_SYSMEM_SIZE 20u +#define COT_OFF_FRTS_VIDMEM_OFF 24u +#define COT_OFF_FRTS_VIDMEM_SIZE 32u +#define COT_OFF_HASH 36u +#define COT_OFF_KEY 84u +#define COT_OFF_SIG 468u +#define COT_OFF_BOOTARGS_ADDR 852u + +/* GSP_FMC_BOOT_PARAMS offsets (natural layout, LP64). */ +#define FMC_OFF_REGKEYS 0u +#define FMC_OFF_BOOT_TARGET 8u +#define FMC_OFF_BOOT_DESC_SIZE 12u +#define FMC_OFF_BOOT_DESC_OFFSET 16u +#define FMC_OFF_BOOT_WPR_OFFSET 24u +#define FMC_OFF_BOOT_WPR_SIZE 32u +#define FMC_OFF_BOOT_IS_GSP_RM 36u +#define FMC_OFF_RM_TARGET 40u +#define FMC_OFF_RM_BOOTARGS 48u +#define FMC_OFF_SPDM_TARGET 56u +#define FMC_OFF_SPDM_PAYLOAD_OFF 64u +#define FMC_OFF_SPDM_PAYLOAD_SIZE 72u +#define FMC_OFF_FLUSH_LO 80u +#define FMC_OFF_FLUSH_HI 84u + +/* Mirrors of the driver's declarations, used only to check the offsets + * above against the compiler's own layout at self-test time. */ +#pragma pack(1) +typedef struct { + uint16_t version; + uint16_t size; + uint64_t gspFmcSysmemOffset; + uint64_t frtsSysmemOffset; + uint32_t frtsSysmemSize; + uint64_t frtsVidmemOffset; + uint32_t frtsVidmemSize; + uint32_t hash384[12]; + uint32_t publicKey[96]; + uint32_t signature[96]; + uint64_t gspBootArgsSysmemOffset; +} mirror_cot_payload; +#pragma pack() +typedef enum { M_TARGET_A, M_TARGET_B, M_TARGET_C, M_TARGET_COUNT } mirror_dma_target; +typedef struct { uint32_t regkeys; } mirror_init_params; +typedef struct { + mirror_dma_target target; + uint32_t gspRmDescSize; + uint64_t gspRmDescOffset; + uint64_t wprCarveoutOffset; + uint32_t wprCarveoutSize; + uint8_t bIsGspRmBoot; +} mirror_acr_params; +typedef struct { mirror_dma_target target; uint64_t bootArgsOffset; } mirror_rm_params; +typedef struct { mirror_dma_target target; uint64_t payloadBufferOffset; uint32_t payloadBufferSize; } mirror_spdm_params; +typedef struct { uint32_t flushSysmemAddrValLo; uint32_t flushSysmemAddrValHi; } mirror_mem_params; +typedef struct { + mirror_init_params initParams; + mirror_acr_params bootGspRmParams; + mirror_rm_params gspRmParams; + mirror_spdm_params gspSpdmParams; + mirror_mem_params gspRmMemParams; +} mirror_fmc_boot_params; + +/* ---- inputs and results ---- */ +typedef struct { + uint64_t fmc_sysmem_addr; + uint32_t fmc_size; + const uint8_t *hash; size_t hash_len; + const uint8_t *key; size_t key_len; + const uint8_t *sig; size_t sig_len; + uint64_t bootargs_sysmem_addr; + unsigned dma_bits; /* 0 = DMA_BITS_DEFAULT */ +} cot_inputs; + +typedef struct { + uint32_t regkeys; + uint32_t desc_target; + uint32_t desc_size; + uint64_t desc_offset; + uint64_t wpr_carveout_offset; + uint32_t wpr_carveout_size; + uint8_t is_gsp_rm_boot; + uint32_t bootargs_target; + uint64_t bootargs_offset; + uint32_t spdm_target; + uint64_t spdm_payload_offset; + uint32_t spdm_payload_size; + uint32_t flush_lo, flush_hi; + unsigned dma_bits; +} fmc_inputs; + +static void put16(uint8_t *p, uint16_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); } +static void put32(uint8_t *p, uint32_t v) { for (int i = 0; i < 4; i++) p[i] = (uint8_t)(v >> (8 * i)); } +static void put64(uint8_t *p, uint64_t v) { for (int i = 0; i < 8; i++) p[i] = (uint8_t)(v >> (8 * i)); } +static uint16_t get16(const uint8_t *p) { return (uint16_t)(p[0] | (p[1] << 8)); } +static uint32_t get32(const uint8_t *p) { uint32_t v = 0; for (int i = 3; i >= 0; i--) v = (v << 8) | p[i]; return v; } +static uint64_t get64(const uint8_t *p) { uint64_t v = 0; for (int i = 7; i >= 0; i--) v = (v << 8) | p[i]; return v; } + +static int addr_ok(uint64_t a, unsigned dma_bits, int need_page_align, const char **why, const char *what) { + if (dma_bits == 0) dma_bits = DMA_BITS_DEFAULT; + if (a == 0) { *why = "zero address"; return 0; } + if (dma_bits < 64 && (a >> dma_bits) != 0) { *why = "address beyond the DMA window"; return 0; } + if (need_page_align && (a & 0xfffu) != 0) { *why = "image address not 4 KiB aligned"; return 0; } + (void)what; + return 1; +} + +/* ---- headers ---- */ +int cot_mctp_header(unsigned som, unsigned eom, unsigned seid, unsigned seq, uint32_t *out, const char **why) { + if (som > 1 || eom > 1) { *why = "som/eom not a bit"; return -1; } + if (seid > 0xff) { *why = "seid out of range"; return -1; } + if (seq > 3) { *why = "seq out of range"; return -1; } + *out = ((uint32_t)som << 31) | ((uint32_t)eom << 30) | ((uint32_t)seq << 28) | ((uint32_t)seid << 16); + return 0; +} +int cot_nvdm_header(unsigned nvdm_type, uint32_t *out, const char **why) { + if (nvdm_type > 0xff) { *why = "nvdm type out of range"; return -1; } + *out = MCTP_MSG_TYPE_VENDOR_PCI | (MCTP_VENDOR_ID_NV << 8) | ((uint32_t)nvdm_type << 24); + return 0; +} + +/* ---- NVDM_PAYLOAD_COT version 1 ---- */ +int cot_payload_encode(const cot_inputs *in, uint8_t out[COT_PAYLOAD_BYTES], const char **why) { + if (!in || !out) { *why = "null argument"; return -1; } + if (!addr_ok(in->fmc_sysmem_addr, in->dma_bits, 1, why, "fmc")) return -1; + if (in->fmc_size == 0) { *why = "zero image size"; return -1; } + if (!in->hash || in->hash_len != COT_HASH_BYTES) { *why = "hash length not 48"; return -1; } + if (!in->key || in->key_len != COT_KEY_BYTES) { *why = "public key length not 384"; return -1; } + if (!in->sig || in->sig_len != COT_SIG_BYTES) { *why = "signature length not 384"; return -1; } + if (!addr_ok(in->bootargs_sysmem_addr, in->dma_bits, 0, why, "bootargs")) return -1; + memset(out, 0, COT_PAYLOAD_BYTES); + put16(out + COT_OFF_VERSION, COT_VERSION_GB10B); + put16(out + COT_OFF_SIZE, COT_PAYLOAD_BYTES); + put64(out + COT_OFF_FMC_ADDR, in->fmc_sysmem_addr); + put32(out + COT_OFF_FRTS_SYSMEM_SIZE, in->fmc_size); + memcpy(out + COT_OFF_HASH, in->hash, COT_HASH_BYTES); + memcpy(out + COT_OFF_KEY, in->key, COT_KEY_BYTES); + memcpy(out + COT_OFF_SIG, in->sig, COT_SIG_BYTES); + put64(out + COT_OFF_BOOTARGS_ADDR, in->bootargs_sysmem_addr); + return 0; +} +/* Decode and re-check. On success the hash/key/sig pointers point into buf. */ +int cot_payload_decode(const uint8_t *buf, size_t len, cot_inputs *out, unsigned dma_bits, const char **why) { + if (!buf || !out) { *why = "null argument"; return -1; } + if (len != COT_PAYLOAD_BYTES) { *why = "payload length not 860"; return -1; } + if (get16(buf + COT_OFF_VERSION) != COT_VERSION_GB10B) { *why = "payload version not 1"; return -1; } + if (get16(buf + COT_OFF_SIZE) != COT_PAYLOAD_BYTES) { *why = "payload size field not 860"; return -1; } + if (get64(buf + COT_OFF_FRTS_SYSMEM_OFF) != 0) { *why = "frtsSysmemOffset not zero"; return -1; } + if (get64(buf + COT_OFF_FRTS_VIDMEM_OFF) != 0) { *why = "frtsVidmemOffset not zero"; return -1; } + if (get32(buf + COT_OFF_FRTS_VIDMEM_SIZE) != 0) { *why = "frtsVidmemSize not zero"; return -1; } + memset(out, 0, sizeof *out); + out->fmc_sysmem_addr = get64(buf + COT_OFF_FMC_ADDR); + out->fmc_size = get32(buf + COT_OFF_FRTS_SYSMEM_SIZE); + out->hash = buf + COT_OFF_HASH; out->hash_len = COT_HASH_BYTES; + out->key = buf + COT_OFF_KEY; out->key_len = COT_KEY_BYTES; + out->sig = buf + COT_OFF_SIG; out->sig_len = COT_SIG_BYTES; + out->bootargs_sysmem_addr = get64(buf + COT_OFF_BOOTARGS_ADDR); + out->dma_bits = dma_bits; + if (!addr_ok(out->fmc_sysmem_addr, dma_bits, 1, why, "fmc")) return -1; + if (out->fmc_size == 0) { *why = "zero image size"; return -1; } + if (!addr_ok(out->bootargs_sysmem_addr, dma_bits, 0, why, "bootargs")) return -1; + return 0; +} + +/* ---- one EMEM packet ---- */ +int cot_packet_encode(const uint8_t *payload, size_t len, unsigned nvdm_type, uint8_t out[EMEM_CHANNEL_BYTES], + size_t *out_len, uint32_t *tail_offset, const char **why) { + uint32_t h0, h1; + if (!payload || !out || !out_len || !tail_offset) { *why = "null argument"; return -1; } + if (len == 0) { *why = "empty payload"; return -1; } + if (len > PACKET_PAYLOAD_CAP) { *why = "payload does not fit one packet"; return -1; } + if (cot_mctp_header(1, 1, 0, 0, &h0, why) != 0) return -1; + if (cot_nvdm_header(nvdm_type, &h1, why) != 0) return -1; + memset(out, 0, EMEM_CHANNEL_BYTES); + put32(out, h0); + put32(out + 4, h1); + memcpy(out + PACKET_HEADER_BYTES, payload, len); + *out_len = (PACKET_HEADER_BYTES + len + 3u) & ~3u; /* NV_ALIGN_UP(size, 4) */ + *tail_offset = (uint32_t)(*out_len - 4u); /* TAIL = last dword written */ + return 0; +} +/* Accepts exactly the single-packet COT shape. payload_out points into buf. */ +int cot_packet_decode(const uint8_t *buf, size_t len, const uint8_t **payload_out, size_t *payload_len, const char **why) { + uint32_t h0, h1, want; + if (!buf || !payload_out || !payload_len) { *why = "null argument"; return -1; } + if (len < PACKET_HEADER_BYTES + 1) { *why = "packet shorter than the headers"; return -1; } + if (len > EMEM_CHANNEL_BYTES) { *why = "packet larger than the channel"; return -1; } + if ((len & 3u) != 0) { *why = "packet length not a dword multiple"; return -1; } + h0 = get32(buf); h1 = get32(buf + 4); + if ((h0 >> 31) != 1) { *why = "SOM not set"; return -1; } + if (((h0 >> 30) & 1u) != 1) { *why = "EOM not set"; return -1; } + if (((h0 >> 28) & 3u) != 0) { *why = "seq not zero"; return -1; } + if (((h0 >> 16) & 0xffu) != 0) { *why = "seid not zero"; return -1; } + if ((h0 & 0x0fffffffu) != 0) { *why = "mctp reserved bits set"; return -1; } + cot_nvdm_header(NVDM_TYPE_COT, &want, why); + if (h1 != want) { + if ((h1 & 0x7fu) != MCTP_MSG_TYPE_VENDOR_PCI) { *why = "nvdm msg type not vendor-pci"; return -1; } + if (((h1 >> 8) & 0xffffu) != MCTP_VENDOR_ID_NV) { *why = "nvdm vendor id not nvidia"; return -1; } + if ((h1 >> 24) != NVDM_TYPE_COT) { *why = "nvdm type not COT"; return -1; } + *why = "nvdm IC bit set"; return -1; + } + *payload_out = buf + PACKET_HEADER_BYTES; + *payload_len = len - PACKET_HEADER_BYTES; + return 0; +} + +/* ---- GSP_FMC_BOOT_PARAMS ---- */ +int fmc_params_encode(const fmc_inputs *in, uint8_t out[FMC_PARAMS_BYTES], const char **why) { + if (!in || !out) { *why = "null argument"; return -1; } + if (in->desc_target >= GSP_DMA_TARGET_COUNT) { *why = "descriptor DMA target out of range"; return -1; } + if (in->desc_size != WPR_META_BYTES) { *why = "descriptor size not 256"; return -1; } + if (!addr_ok(in->desc_offset, in->dma_bits, 0, why, "desc")) return -1; + if (in->is_gsp_rm_boot != 1) { *why = "bIsGspRmBoot not set"; return -1; } + if (in->bootargs_target >= GSP_DMA_TARGET_COUNT) { *why = "boot-args DMA target out of range"; return -1; } + if (!addr_ok(in->bootargs_offset, in->dma_bits, 0, why, "bootargs")) return -1; + if (in->spdm_target >= GSP_DMA_TARGET_COUNT) { *why = "SPDM DMA target out of range"; return -1; } + memset(out, 0, FMC_PARAMS_BYTES); + put32(out + FMC_OFF_REGKEYS, in->regkeys); + put32(out + FMC_OFF_BOOT_TARGET, in->desc_target); + put32(out + FMC_OFF_BOOT_DESC_SIZE, in->desc_size); + put64(out + FMC_OFF_BOOT_DESC_OFFSET, in->desc_offset); + put64(out + FMC_OFF_BOOT_WPR_OFFSET, in->wpr_carveout_offset); + put32(out + FMC_OFF_BOOT_WPR_SIZE, in->wpr_carveout_size); + out[FMC_OFF_BOOT_IS_GSP_RM] = in->is_gsp_rm_boot; + put32(out + FMC_OFF_RM_TARGET, in->bootargs_target); + put64(out + FMC_OFF_RM_BOOTARGS, in->bootargs_offset); + put32(out + FMC_OFF_SPDM_TARGET, in->spdm_target); + put64(out + FMC_OFF_SPDM_PAYLOAD_OFF, in->spdm_payload_offset); + put32(out + FMC_OFF_SPDM_PAYLOAD_SIZE, in->spdm_payload_size); + put32(out + FMC_OFF_FLUSH_LO, in->flush_lo); + put32(out + FMC_OFF_FLUSH_HI, in->flush_hi); + return 0; +} +int fmc_params_decode(const uint8_t *buf, size_t len, fmc_inputs *out, unsigned dma_bits, const char **why) { + if (!buf || !out) { *why = "null argument"; return -1; } + if (len != FMC_PARAMS_BYTES) { *why = "params length not 88"; return -1; } + memset(out, 0, sizeof *out); + out->regkeys = get32(buf + FMC_OFF_REGKEYS); + out->desc_target = get32(buf + FMC_OFF_BOOT_TARGET); + out->desc_size = get32(buf + FMC_OFF_BOOT_DESC_SIZE); + out->desc_offset = get64(buf + FMC_OFF_BOOT_DESC_OFFSET); + out->wpr_carveout_offset = get64(buf + FMC_OFF_BOOT_WPR_OFFSET); + out->wpr_carveout_size = get32(buf + FMC_OFF_BOOT_WPR_SIZE); + out->is_gsp_rm_boot = buf[FMC_OFF_BOOT_IS_GSP_RM]; + out->bootargs_target = get32(buf + FMC_OFF_RM_TARGET); + out->bootargs_offset = get64(buf + FMC_OFF_RM_BOOTARGS); + out->spdm_target = get32(buf + FMC_OFF_SPDM_TARGET); + out->spdm_payload_offset = get64(buf + FMC_OFF_SPDM_PAYLOAD_OFF); + out->spdm_payload_size = get32(buf + FMC_OFF_SPDM_PAYLOAD_SIZE); + out->flush_lo = get32(buf + FMC_OFF_FLUSH_LO); + out->flush_hi = get32(buf + FMC_OFF_FLUSH_HI); + out->dma_bits = dma_bits; + /* padding bytes must be zero: 4..7, 37..39, 44..47, 60..63, 76..79 */ + for (size_t i = 0; i < len; i++) { + int pad = (i >= 4 && i < 8) || (i >= 37 && i < 40) || (i >= 44 && i < 48) || (i >= 60 && i < 64) || (i >= 76 && i < 80); + if (pad && buf[i] != 0) { *why = "padding byte not zero"; return -1; } + } + uint8_t re[FMC_PARAMS_BYTES]; + if (fmc_params_encode(out, re, why) != 0) return -1; + if (memcmp(re, buf, FMC_PARAMS_BYTES) != 0) { *why = "re-encode differs"; return -1; } + return 0; +} + +/* ---- self-test ---- */ +static int fails; +static void check(int ok, const char *what) { + printf(" %s %s\n", ok ? "ok " : "FAIL", what); + if (!ok) fails++; +} +static void expect_refused(int rc, const char *why, const char *want, const char *what) { + int ok = rc != 0 && why && strcmp(why, want) == 0; + printf(" %s refused: %s", ok ? "ok " : "FAIL", what); + if (!ok) printf(" (rc=%d why=%s want=%s)", rc, why ? why : "(null)", want); + printf("\n"); + if (!ok) fails++; +} + +static int selftest(void) { + const char *why = ""; + printf("CK_GSP_COT_ENCODE_SELFTEST: begin\n"); + + /* 1. layouts against the compiler's own view of the mirrored structs */ + check(sizeof(mirror_cot_payload) == COT_PAYLOAD_BYTES, "NVDM_PAYLOAD_COT is 860 bytes"); + check(offsetof(mirror_cot_payload, version) == COT_OFF_VERSION && + offsetof(mirror_cot_payload, size) == COT_OFF_SIZE && + offsetof(mirror_cot_payload, gspFmcSysmemOffset) == COT_OFF_FMC_ADDR && + offsetof(mirror_cot_payload, frtsSysmemOffset) == COT_OFF_FRTS_SYSMEM_OFF && + offsetof(mirror_cot_payload, frtsSysmemSize) == COT_OFF_FRTS_SYSMEM_SIZE && + offsetof(mirror_cot_payload, frtsVidmemOffset) == COT_OFF_FRTS_VIDMEM_OFF && + offsetof(mirror_cot_payload, frtsVidmemSize) == COT_OFF_FRTS_VIDMEM_SIZE && + offsetof(mirror_cot_payload, hash384) == COT_OFF_HASH && + offsetof(mirror_cot_payload, publicKey) == COT_OFF_KEY && + offsetof(mirror_cot_payload, signature) == COT_OFF_SIG && + offsetof(mirror_cot_payload, gspBootArgsSysmemOffset) == COT_OFF_BOOTARGS_ADDR, + "NVDM_PAYLOAD_COT field offsets"); + check(sizeof(mirror_fmc_boot_params) == FMC_PARAMS_BYTES && sizeof(mirror_dma_target) == 4, "GSP_FMC_BOOT_PARAMS is 88 bytes"); + check(offsetof(mirror_fmc_boot_params, initParams) == FMC_OFF_REGKEYS && + offsetof(mirror_fmc_boot_params, bootGspRmParams) == FMC_OFF_BOOT_TARGET && + offsetof(mirror_fmc_boot_params, bootGspRmParams.gspRmDescSize) == FMC_OFF_BOOT_DESC_SIZE && + offsetof(mirror_fmc_boot_params, bootGspRmParams.gspRmDescOffset) == FMC_OFF_BOOT_DESC_OFFSET && + offsetof(mirror_fmc_boot_params, bootGspRmParams.wprCarveoutOffset) == FMC_OFF_BOOT_WPR_OFFSET && + offsetof(mirror_fmc_boot_params, bootGspRmParams.wprCarveoutSize) == FMC_OFF_BOOT_WPR_SIZE && + offsetof(mirror_fmc_boot_params, bootGspRmParams.bIsGspRmBoot) == FMC_OFF_BOOT_IS_GSP_RM && + offsetof(mirror_fmc_boot_params, gspRmParams) == FMC_OFF_RM_TARGET && + offsetof(mirror_fmc_boot_params, gspRmParams.bootArgsOffset) == FMC_OFF_RM_BOOTARGS && + offsetof(mirror_fmc_boot_params, gspSpdmParams) == FMC_OFF_SPDM_TARGET && + offsetof(mirror_fmc_boot_params, gspSpdmParams.payloadBufferOffset) == FMC_OFF_SPDM_PAYLOAD_OFF && + offsetof(mirror_fmc_boot_params, gspSpdmParams.payloadBufferSize) == FMC_OFF_SPDM_PAYLOAD_SIZE && + offsetof(mirror_fmc_boot_params, gspRmMemParams) == FMC_OFF_FLUSH_LO && + offsetof(mirror_fmc_boot_params, gspRmMemParams.flushSysmemAddrValHi) == FMC_OFF_FLUSH_HI, + "GSP_FMC_BOOT_PARAMS field offsets"); + + /* 2. golden header words */ + uint32_t h; + check(cot_mctp_header(1, 1, 0, 0, &h, &why) == 0 && h == 0xC0000000u, "MCTP first+last packet, seid 0, seq 0 = 0xC0000000"); + check(cot_mctp_header(0, 1, 0, 3, &h, &why) == 0 && h == 0x70000000u, "MCTP last continuation seq 3 = 0x70000000"); + check(cot_mctp_header(0, 0, 0, 1, &h, &why) == 0 && h == 0x10000000u, "MCTP middle packet seq 1 = 0x10000000"); + check(cot_mctp_header(1, 1, 0x2a, 0, &h, &why) == 0 && h == 0xC02A0000u, "MCTP seid lands in bits 23:16"); + check(cot_nvdm_header(NVDM_TYPE_COT, &h, &why) == 0 && h == 0x1410DE7Eu, "NVDM header for COT = 0x1410DE7E"); + expect_refused(cot_mctp_header(1, 1, 0, 4, &h, &why), why, "seq out of range", "mctp seq 4"); + expect_refused(cot_mctp_header(2, 1, 0, 0, &h, &why), why, "som/eom not a bit", "mctp som 2"); + expect_refused(cot_mctp_header(1, 1, 256, 0, &h, &why), why, "seid out of range", "mctp seid 256"); + expect_refused(cot_nvdm_header(256, &h, &why), why, "nvdm type out of range", "nvdm type 256"); + + /* 3. payload round trip */ + static uint8_t hash[COT_HASH_BYTES], key[COT_KEY_BYTES], sig[COT_SIG_BYTES]; + for (unsigned i = 0; i < COT_HASH_BYTES; i++) hash[i] = (uint8_t)(0x10 + i); + for (unsigned i = 0; i < COT_KEY_BYTES; i++) key[i] = (uint8_t)(0x20 + i); + for (unsigned i = 0; i < COT_SIG_BYTES; i++) sig[i] = (uint8_t)(0x30 + i); + cot_inputs in = { 0x0000012345670000ull, 195912u, hash, COT_HASH_BYTES, key, COT_KEY_BYTES, sig, COT_SIG_BYTES, 0x00000123456a0000ull, 0 }; + uint8_t pl[COT_PAYLOAD_BYTES], pkt[EMEM_CHANNEL_BYTES]; + size_t pkt_len = 0; uint32_t tail = 0; + check(cot_payload_encode(&in, pl, &why) == 0, "payload encodes"); + check(get16(pl) == 1 && get16(pl + 2) == 860, "payload version 1 size 860"); + check(get64(pl + COT_OFF_FMC_ADDR) == in.fmc_sysmem_addr && get32(pl + COT_OFF_FRTS_SYSMEM_SIZE) == in.fmc_size, "image address and size in place"); + check(memcmp(pl + COT_OFF_HASH, hash, 48) == 0 && memcmp(pl + COT_OFF_KEY, key, 384) == 0 && memcmp(pl + COT_OFF_SIG, sig, 384) == 0, "hash, key, signature in place"); + check(get64(pl + COT_OFF_BOOTARGS_ADDR) == in.bootargs_sysmem_addr, "boot-args address in place"); + { int zero = 1; for (unsigned i = COT_OFF_FRTS_SYSMEM_OFF; i < COT_OFF_HASH; i++) if (i < COT_OFF_FRTS_SYSMEM_SIZE || i >= COT_OFF_FRTS_VIDMEM_OFF) zero &= pl[i] == 0; check(zero, "reserved FRTS fields zero"); } + cot_inputs back; + check(cot_payload_decode(pl, sizeof pl, &back, 0, &why) == 0 && back.fmc_sysmem_addr == in.fmc_sysmem_addr && back.fmc_size == in.fmc_size && + back.bootargs_sysmem_addr == in.bootargs_sysmem_addr && memcmp(back.hash, hash, 48) == 0 && memcmp(back.key, key, 384) == 0 && memcmp(back.sig, sig, 384) == 0, + "payload decodes to the same fields"); + check(cot_packet_encode(pl, sizeof pl, NVDM_TYPE_COT, pkt, &pkt_len, &tail, &why) == 0 && pkt_len == COT_PACKET_BYTES && tail == COT_PACKET_BYTES - 4u, + "packet is 868 bytes, tail dword offset 864"); + check(get32(pkt) == 0xC0000000u && get32(pkt + 4) == 0x1410DE7Eu && memcmp(pkt + 8, pl, sizeof pl) == 0, "packet = headers + payload"); + { const uint8_t *p; size_t n; check(cot_packet_decode(pkt, pkt_len, &p, &n, &why) == 0 && n == COT_PAYLOAD_BYTES && memcmp(p, pl, n) == 0, "packet decodes"); } + { uint8_t one[3] = {1, 2, 3}; size_t n; uint32_t t; check(cot_packet_encode(one, 3, NVDM_TYPE_COT, pkt, &n, &t, &why) == 0 && n == 12 && t == 8, "3-byte payload pads to 12, tail 8"); } + + /* 4. payload encode refusals, one field at a time */ + cot_inputs m; + m = in; m.fmc_sysmem_addr = 0; expect_refused(cot_payload_encode(&m, pl, &why), why, "zero address", "image address 0"); + m = in; m.fmc_sysmem_addr = 0x12345670800ull; expect_refused(cot_payload_encode(&m, pl, &why), why, "image address not 4 KiB aligned", "image address unaligned"); + m = in; m.fmc_sysmem_addr = 1ull << 41; expect_refused(cot_payload_encode(&m, pl, &why), why, "address beyond the DMA window", "image address at 2^41"); + m = in; m.fmc_sysmem_addr = 1ull << 41; m.dma_bits = 42; check(cot_payload_encode(&m, pl, &why) == 0, "2^41 accepted with --dma-bits 42"); + m = in; m.fmc_size = 0; expect_refused(cot_payload_encode(&m, pl, &why), why, "zero image size", "image size 0"); + m = in; m.hash_len = 47; expect_refused(cot_payload_encode(&m, pl, &why), why, "hash length not 48", "hash 47 bytes"); + m = in; m.hash = NULL; expect_refused(cot_payload_encode(&m, pl, &why), why, "hash length not 48", "hash null"); + m = in; m.key_len = 385; expect_refused(cot_payload_encode(&m, pl, &why), why, "public key length not 384", "key 385 bytes"); + m = in; m.sig_len = 0; expect_refused(cot_payload_encode(&m, pl, &why), why, "signature length not 384", "signature empty"); + m = in; m.bootargs_sysmem_addr = 0; expect_refused(cot_payload_encode(&m, pl, &why), why, "zero address", "boot-args address 0"); + m = in; m.bootargs_sysmem_addr = 1ull << 41; expect_refused(cot_payload_encode(&m, pl, &why), why, "address beyond the DMA window", "boot-args at 2^41"); + expect_refused(cot_payload_encode(NULL, pl, &why), why, "null argument", "null inputs"); + + /* 5. payload decode refusals */ + uint8_t d[COT_PAYLOAD_BYTES]; + cot_payload_encode(&in, pl, &why); +#define MUT(setup, want, what) do { memcpy(d, pl, sizeof d); setup; expect_refused(cot_payload_decode(d, sizeof d, &back, 0, &why), why, want, what); } while (0) + expect_refused(cot_payload_decode(pl, 859, &back, 0, &why), why, "payload length not 860", "payload 859 bytes"); + expect_refused(cot_payload_decode(pl, 861, &back, 0, &why), why, "payload length not 860", "payload 861 bytes"); + MUT(put16(d, 2), "payload version not 1", "version 2"); + MUT(put16(d, 0), "payload version not 1", "version 0"); + MUT(put16(d + 2, 859), "payload size field not 860", "size field 859"); + MUT(put64(d + COT_OFF_FRTS_SYSMEM_OFF, 0x1000), "frtsSysmemOffset not zero", "frtsSysmemOffset set"); + MUT(put64(d + COT_OFF_FRTS_VIDMEM_OFF, 1), "frtsVidmemOffset not zero", "frtsVidmemOffset set"); + MUT(put32(d + COT_OFF_FRTS_VIDMEM_SIZE, 1), "frtsVidmemSize not zero", "frtsVidmemSize set"); + MUT(put64(d + COT_OFF_FMC_ADDR, 0), "zero address", "decoded image address 0"); + MUT(put64(d + COT_OFF_FMC_ADDR, 0x1010), "image address not 4 KiB aligned", "decoded image address unaligned"); + MUT(put64(d + COT_OFF_FMC_ADDR, 1ull << 41), "address beyond the DMA window", "decoded image address at 2^41"); + MUT(put32(d + COT_OFF_FRTS_SYSMEM_SIZE, 0), "zero image size", "decoded image size 0"); + MUT(put64(d + COT_OFF_BOOTARGS_ADDR, 0), "zero address", "decoded boot-args 0"); +#undef MUT + + /* 6. packet refusals */ + cot_packet_encode(pl, sizeof pl, NVDM_TYPE_COT, pkt, &pkt_len, &tail, &why); + { uint8_t big[PACKET_PAYLOAD_CAP + 1]; size_t n; uint32_t t; memset(big, 0, sizeof big); + expect_refused(cot_packet_encode(big, sizeof big, NVDM_TYPE_COT, pkt, &n, &t, &why), why, "payload does not fit one packet", "payload 1017 bytes"); + check(cot_packet_encode(big, PACKET_PAYLOAD_CAP, NVDM_TYPE_COT, pkt, &n, &t, &why) == 0 && n == 1024 && t == 1020, "payload 1016 bytes fills the channel exactly"); + expect_refused(cot_packet_encode(big, 0, NVDM_TYPE_COT, pkt, &n, &t, &why), why, "empty payload", "payload 0 bytes"); + cot_packet_encode(pl, sizeof pl, NVDM_TYPE_COT, pkt, &pkt_len, &tail, &why); } + uint8_t q[EMEM_CHANNEL_BYTES]; const uint8_t *p; size_t n; +#define PMUT(setup, want, what) do { memcpy(q, pkt, sizeof q); setup; expect_refused(cot_packet_decode(q, pkt_len, &p, &n, &why), why, want, what); } while (0) + PMUT(put32(q, 0x40000000u), "SOM not set", "SOM cleared"); + PMUT(put32(q, 0x80000000u), "EOM not set", "EOM cleared"); + PMUT(put32(q, 0xD0000000u), "seq not zero", "seq 1"); + PMUT(put32(q, 0xC0050000u), "seid not zero", "seid 5"); + PMUT(put32(q, 0xC8000000u), "mctp reserved bits set", "TO bit set"); + PMUT(put32(q, 0xC0000001u), "mctp reserved bits set", "version nibble set"); + PMUT(put32(q + 4, 0x1510DE7Eu), "nvdm type not COT", "nvdm type 0x15 (FSP_RESPONSE)"); + PMUT(put32(q + 4, 0x1410DF7Eu), "nvdm vendor id not nvidia", "vendor id off by one"); + PMUT(put32(q + 4, 0x1410DE7Fu), "nvdm msg type not vendor-pci", "msg type 0x7f"); + PMUT(put32(q + 4, 0x1410DEFEu), "nvdm IC bit set", "IC bit set"); +#undef PMUT + expect_refused(cot_packet_decode(pkt, pkt_len - 1, &p, &n, &why), why, "packet length not a dword multiple", "packet 867 bytes"); + expect_refused(cot_packet_decode(pkt, 1028, &p, &n, &why), why, "packet larger than the channel", "packet 1028 bytes"); + { int all = 1; for (size_t t = 0; t < PACKET_HEADER_BYTES + 1; t++) { if (cot_packet_decode(pkt, t, &p, &n, &why) == 0) all = 0; } + check(all, "every truncation 0..8 refused"); } + { const uint8_t *pp; size_t nn; cot_packet_decode(pkt, pkt_len, &pp, &nn, &why); + expect_refused(cot_payload_decode(pp, nn - 4, &back, 0, &why), why, "payload length not 860", "packet with a short payload"); } + + /* 7. FMC boot params round trip and refusals */ + fmc_inputs f = { 0, 1, WPR_META_BYTES, 0x0000012345680000ull, 0, 0, 1, 1, 0x00000123456c0000ull, 0, 0, 0, 0, 0, 0 }; + uint8_t fb[FMC_PARAMS_BYTES]; fmc_inputs fback; + check(fmc_params_encode(&f, fb, &why) == 0, "FMC params encode"); + check(get32(fb + FMC_OFF_BOOT_TARGET) == 1 && get32(fb + FMC_OFF_BOOT_DESC_SIZE) == 256 && get64(fb + FMC_OFF_BOOT_DESC_OFFSET) == f.desc_offset && + fb[FMC_OFF_BOOT_IS_GSP_RM] == 1 && get64(fb + FMC_OFF_RM_BOOTARGS) == f.bootargs_offset, "FMC params fields in place"); + check(fmc_params_decode(fb, sizeof fb, &fback, 0, &why) == 0 && fback.desc_offset == f.desc_offset && fback.bootargs_offset == f.bootargs_offset && fback.desc_target == 1, "FMC params decode"); + fmc_inputs g; + g = f; g.desc_target = 3; expect_refused(fmc_params_encode(&g, fb, &why), why, "descriptor DMA target out of range", "desc target 3"); + g = f; g.desc_size = 255; expect_refused(fmc_params_encode(&g, fb, &why), why, "descriptor size not 256", "desc size 255"); + g = f; g.desc_offset = 0; expect_refused(fmc_params_encode(&g, fb, &why), why, "zero address", "desc offset 0"); + g = f; g.is_gsp_rm_boot = 0; expect_refused(fmc_params_encode(&g, fb, &why), why, "bIsGspRmBoot not set", "boot flag clear"); + g = f; g.bootargs_target = 3; expect_refused(fmc_params_encode(&g, fb, &why), why, "boot-args DMA target out of range", "boot-args target 3"); + g = f; g.bootargs_offset = 1ull << 41; expect_refused(fmc_params_encode(&g, fb, &why), why, "address beyond the DMA window", "boot-args at 2^41"); + g = f; g.spdm_target = 7; expect_refused(fmc_params_encode(&g, fb, &why), why, "SPDM DMA target out of range", "SPDM target 7"); + fmc_params_encode(&f, fb, &why); + { uint8_t e[FMC_PARAMS_BYTES]; memcpy(e, fb, sizeof e); e[5] = 1; expect_refused(fmc_params_decode(e, sizeof e, &fback, 0, &why), why, "padding byte not zero", "padding byte 5 set"); + memcpy(e, fb, sizeof e); e[FMC_OFF_BOOT_IS_GSP_RM] = 0; expect_refused(fmc_params_decode(e, sizeof e, &fback, 0, &why), why, "bIsGspRmBoot not set", "decoded boot flag clear"); + memcpy(e, fb, sizeof e); put32(e + FMC_OFF_BOOT_DESC_SIZE, 512); expect_refused(fmc_params_decode(e, sizeof e, &fback, 0, &why), why, "descriptor size not 256", "decoded desc size 512"); + expect_refused(fmc_params_decode(fb, 87, &fback, 0, &why), why, "params length not 88", "params 87 bytes"); } + + printf("CK_GSP_COT_ENCODE_SELFTEST: %s (%d failures)\n", fails ? "FAIL" : "PASS", fails); + return fails ? 1 : 0; +} + +static void layout(void) { + printf("NVDM_PAYLOAD_COT version 1, packed, %u bytes (kern_fsp_cot_payload.h:13-28)\n", COT_PAYLOAD_BYTES); + printf("version %u 2\nsize %u 2\ngspFmcSysmemOffset %u 8\nfrtsSysmemOffset %u 8\nfrtsSysmemSize %u 4\nfrtsVidmemOffset %u 8\nfrtsVidmemSize %u 4\nhash384 %u 48\npublicKey %u 384\nsignature %u 384\ngspBootArgsSysmemOffset %u 8\n", + COT_OFF_VERSION, COT_OFF_SIZE, COT_OFF_FMC_ADDR, COT_OFF_FRTS_SYSMEM_OFF, COT_OFF_FRTS_SYSMEM_SIZE, COT_OFF_FRTS_VIDMEM_OFF, COT_OFF_FRTS_VIDMEM_SIZE, COT_OFF_HASH, COT_OFF_KEY, COT_OFF_SIG, COT_OFF_BOOTARGS_ADDR); + printf("packet: mctp 0xC0000000 at 0, nvdm 0x1410DE7E at 4, payload at 8, length %u, QUEUE_TAIL %u, QUEUE_HEAD 0\n", COT_PACKET_BYTES, COT_PACKET_BYTES - 4u); + printf("GSP_FMC_BOOT_PARAMS natural layout, %u bytes (gspifpub.h)\n", FMC_PARAMS_BYTES); + printf("initParams.regkeys %u 4\nbootGspRmParams.target %u 4\nbootGspRmParams.gspRmDescSize %u 4\nbootGspRmParams.gspRmDescOffset %u 8\nbootGspRmParams.wprCarveoutOffset %u 8\nbootGspRmParams.wprCarveoutSize %u 4\nbootGspRmParams.bIsGspRmBoot %u 1\ngspRmParams.target %u 4\ngspRmParams.bootArgsOffset %u 8\ngspSpdmParams.target %u 4\ngspSpdmParams.payloadBufferOffset %u 8\ngspSpdmParams.payloadBufferSize %u 4\ngspRmMemParams.flushSysmemAddrValLo %u 4\ngspRmMemParams.flushSysmemAddrValHi %u 4\n", + FMC_OFF_REGKEYS, FMC_OFF_BOOT_TARGET, FMC_OFF_BOOT_DESC_SIZE, FMC_OFF_BOOT_DESC_OFFSET, FMC_OFF_BOOT_WPR_OFFSET, FMC_OFF_BOOT_WPR_SIZE, FMC_OFF_BOOT_IS_GSP_RM, FMC_OFF_RM_TARGET, FMC_OFF_RM_BOOTARGS, FMC_OFF_SPDM_TARGET, FMC_OFF_SPDM_PAYLOAD_OFF, FMC_OFF_SPDM_PAYLOAD_SIZE, FMC_OFF_FLUSH_LO, FMC_OFF_FLUSH_HI); +} + +static uint8_t *read_file(const char *path, size_t *len) { + FILE *f = fopen(path, "rb"); + if (!f) return NULL; + uint8_t *buf = malloc(4096); + size_t cap = 4096, n = 0; + if (!buf) { fclose(f); return NULL; } + for (;;) { + size_t r = fread(buf + n, 1, cap - n, f); + n += r; + if (n < cap) break; + uint8_t *nb = realloc(buf, cap * 2); + if (!nb) { free(buf); fclose(f); return NULL; } + buf = nb; cap *= 2; + } + fclose(f); + *len = n; + return buf; +} + +static int encode_cli(int argc, char **argv) { + const char *hash_p = NULL, *key_p = NULL, *sig_p = NULL, *out_p = NULL, *why = ""; + cot_inputs in; memset(&in, 0, sizeof in); + for (int i = 2; i < argc; i++) { + const char *a = argv[i], *v = (i + 1 < argc) ? argv[i + 1] : NULL; + if (!v) { fprintf(stderr, "missing value for %s\n", a); return 2; } + if (!strcmp(a, "--fmc-addr")) in.fmc_sysmem_addr = strtoull(v, NULL, 16); + else if (!strcmp(a, "--fmc-size")) in.fmc_size = (uint32_t)strtoul(v, NULL, 0); + else if (!strcmp(a, "--hash")) hash_p = v; + else if (!strcmp(a, "--key")) key_p = v; + else if (!strcmp(a, "--sig")) sig_p = v; + else if (!strcmp(a, "--bootargs-addr")) in.bootargs_sysmem_addr = strtoull(v, NULL, 16); + else if (!strcmp(a, "--dma-bits")) in.dma_bits = (unsigned)strtoul(v, NULL, 0); + else if (!strcmp(a, "--out")) out_p = v; + else { fprintf(stderr, "unknown option %s\n", a); return 2; } + i++; + } + if (!hash_p || !key_p || !sig_p) { fprintf(stderr, "need --hash --key --sig\n"); return 2; } + size_t hl = 0, kl = 0, sl = 0; + uint8_t *hb = read_file(hash_p, &hl), *kb = read_file(key_p, &kl), *sb = read_file(sig_p, &sl); + if (!hb || !kb || !sb) { fprintf(stderr, "cannot read an input file\n"); return 2; } + in.hash = hb; in.hash_len = hl; in.key = kb; in.key_len = kl; in.sig = sb; in.sig_len = sl; + uint8_t pl[COT_PAYLOAD_BYTES], pkt[EMEM_CHANNEL_BYTES]; + size_t n = 0; uint32_t tail = 0; + if (cot_payload_encode(&in, pl, &why) != 0 || cot_packet_encode(pl, sizeof pl, NVDM_TYPE_COT, pkt, &n, &tail, &why) != 0) { + printf("RESULT REFUSED %s\n", why); + return 2; + } + uint8_t dg[32]; + sha256_hash(pkt, n, dg); + printf("mctp_header 0x%08x\nnvdm_header 0x%08x\npayload_version %u\npayload_size %u\npacket_len %zu\nqueue_head 0\nqueue_tail %u\nfmc_addr 0x%llx\nfmc_size %u\nbootargs_addr 0x%llx\nsha256_packet ", + get32(pkt), get32(pkt + 4), get16(pl), get16(pl + 2), n, tail, (unsigned long long)in.fmc_sysmem_addr, in.fmc_size, (unsigned long long)in.bootargs_sysmem_addr); + for (int i = 0; i < 32; i++) printf("%02x", dg[i]); + printf("\n"); + if (out_p) { + FILE *f = fopen(out_p, "wb"); + if (!f || fwrite(pkt, 1, n, f) != n) { printf("RESULT REFUSED cannot write output\n"); if (f) fclose(f); return 2; } + fclose(f); + } + printf("RESULT OK\n"); + free(hb); free(kb); free(sb); + return 0; +} + +int main(int argc, char **argv) { + if (argc >= 2 && !strcmp(argv[1], "selftest")) return selftest(); + if (argc >= 2 && !strcmp(argv[1], "layout")) { layout(); return 0; } + if (argc >= 2 && !strcmp(argv[1], "encode")) return encode_cli(argc, argv); + fprintf(stderr, "usage: ck_gsp_cot_encode selftest | layout | encode --fmc-addr HEX --fmc-size N --hash F --key F --sig F --bootargs-addr HEX [--dma-bits N] [--out F]\n"); + return 2; +} diff --git a/scripts/.crumb b/scripts/.crumb index dd38a699..6c7ab731 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T10:28:17Z", + "compiled_at": "2026-10-12T11:57:55Z", "compiler": "crumb-compile/1", - "digest": "sha256:8f2ba6515d449096eccaa96e1d710d5556e36425d1b82eb8ef096d85200059f9", + "digest": "sha256:348804e26984e873db9914d2a3ebfcf6c9ea02619247d78809999011b354e048", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 83, - "generated_at_commit": "56d125f12abf2b8ba2886d6da4d86fda8dd244b3", - "source_tree": "sha256:7988f7a7c826487fa7709995435d980b07c43f7788773a03e3394fc1be0c3517" + "files": 84, + "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", + "source_tree": "sha256:8a24952f080c725f45f951d689db199366d345ccbc97a847ecdf4698bf8ff22f" }, "owner_lane": "", "provenance": { diff --git a/scripts/workflow_files_check.sh b/scripts/workflow_files_check.sh new file mode 100755 index 00000000..dde7e1b1 --- /dev/null +++ b/scripts/workflow_files_check.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Fail when GitHub refused any workflow file on a commit. +# +# A workflow file GitHub cannot parse (for example an unquoted ": " inside a +# step name) produces a run that is recorded as "failure" with zero jobs, and +# that run never appears in a pull request's checks list, so the job it was +# supposed to run silently never runs. 2026-10-12: .github/workflows/ +# ck-kernel.yml was in that state for four hours (aienos#318). This script +# runs from an always-on workflow and turns that silence into a red check. +# +# scripts/workflow_files_check.sh +# Needs: gh with a token that can read Actions (GITHUB_TOKEN in CI), and +# GITHUB_REPOSITORY (owner/name; defaults to aien-dev/aienos). POSIX sh, no +# Python. Exit 0 when every workflow run on the commit has at least one job, +# 1 when one does not, 2 on usage or API error. +set -eu +sha="${1:-}" +[ -n "$sha" ] || { echo "usage: $0 " >&2; exit 2; } +repo="${GITHUB_REPOSITORY:-aien-dev/aienos}" +settle="${WORKFLOW_FILES_SETTLE_SECONDS:-20}" +[ "$settle" -gt 0 ] && sleep "$settle" # let GitHub record the push-event runs +runs=$(gh api "repos/$repo/actions/runs?head_sha=$sha&per_page=100" \ + --jq '.workflow_runs[] | select(.conclusion == "failure") | "\(.id) \(.path)"') \ + || { echo "WORKFLOW_FILES: ERROR cannot list runs for $sha" >&2; exit 2; } +bad=0 +for id in $(printf '%s\n' "$runs" | awk 'NF {print $1}'); do + path=$(printf '%s\n' "$runs" | awk -v i="$id" '$1 == i {print $2}') + n=$(gh api "repos/$repo/actions/runs/$id/jobs" --jq '.total_count') \ + || { echo "WORKFLOW_FILES: ERROR cannot read jobs of run $id" >&2; exit 2; } + if [ "$n" = 0 ]; then + echo "WORKFLOW_FILES: REFUSED $path (run $id failed with no jobs: GitHub did not accept the file)" + bad=1 + fi +done +[ "$bad" = 0 ] && echo "WORKFLOW_FILES: OK (every workflow run on $sha has jobs)" +exit "$bad" From 22f8f8a5a34c7a6baf2b18849fd91e772737cc2c Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 12 Oct 2026 07:21:28 -0500 Subject: [PATCH 2/2] native v1 P08 cut C (host, part 3): GB10B bindata extractor with own DEFLATE/SHA-384, boot-path trace (refs #286) ck_gsp_bindata_extract (native/kernel/tools): strict parser for the two public generated files g_bindata_kgspGetBinArchive{GspRmBoot, GspRmFmcGfwProdSigned}_GB10B.c of nvidia-open 580.173.02 (MIT). Checks the generated-file grammar, array identifiers, storage records, archive table, size limits; inflates compressed arrays with our own raw-DEFLATE decoder (stored/fixed/dynamic) and verifies the CRC-32 + ISIZE trailer; decodes RM_RISCV_UCODE_DESC (version 5, 256-byte aligned regions inside the image); checks UCODE_HASH == SHA-384(UCODE_IMAGE) with our own SHA-384; writes the eight arrays as files with sha256 digests. Refuses anything else by name (exit 2). Never loads anything. Makefile: gsp-bindata-extract / gsp-bindata-test (in `make test`), driver files optional under GSP_BINDATA_DIR; pin of the FMC image, the boot PROD image and the decoded descriptor; NOT_RUN when the files are absent. docs/GB10_FIRMWARE_INVENTORY.md: 3.3 digests, storage format (gzip body without header, bin_data.c + nouveau script lines 107-108), descriptor values, archive selection (gb100 -> ga102 storage HAL); 7 (a) DONE; 8 item 6 resolved on the host side (which image goes where, WprMeta bootloader fields); 9 read list; new section 11: tool, checks, evidence, and the FSP / SEC2 / direct boot decision with the post-send wait chain (GB10B: no FSP, SEC2 path). Evidence: CK_GSP_BINDATA_EXTRACT_SELFTEST PASS (124 checks) plain and under ASan/UBSan; both GB10B files RESULT OK arrays=4; CK_GSP_BINDATA_PIN PASS; foreign file refused. Co-Authored-By: Claude Fable 5.1 --- .crumb | 22 +- docs/.crumb | 8 +- docs/GB10_FIRMWARE_INVENTORY.md | 165 ++- native/.crumb | 16 +- native/kernel/.crumb | 18 +- native/kernel/Makefile | 34 +- native/kernel/tools/.crumb | 12 +- native/kernel/tools/ck_gsp_bindata_extract.c | 1139 ++++++++++++++++++ 8 files changed, 1353 insertions(+), 61 deletions(-) create mode 100644 native/kernel/tools/ck_gsp_bindata_extract.c diff --git a/.crumb b/.crumb index d9c437a4..1e13cc87 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "0893e0c34b7443fafe6a41c7ca2d0db8a9482bcf4aa0412bbb60efab02d31b94", - "last_commit": "f47f6c7", + "digest": "67c7dafea9dd11fce8a30e2758fc9c0553d5e75c442bc6c2c22f134a090a5008", + "last_commit": "e09825a", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "cc6320946ab6360e3bdd81cdc6b753e5c82839961602bbe41d9aaa1dd4e068a6", - "last_commit": "f47f6c7", + "digest": "00b3df5ff408cf07d222d4ebd836026a58a12532ff116b765594246a09a901bc", + "last_commit": "e09825a", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { "digest": "348804e26984e873db9914d2a3ebfcf6c9ea02619247d78809999011b354e048", - "last_commit": "22eb360", + "last_commit": "e09825a", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:e13f620786d98cea7090138ea217f1f821440fed426d80155536c0796b04b7cb", - "compiled_at": "2026-10-12T11:57:55Z", + "children_root": "sha256:5e6b18b2f6fa0f85281593d5f46a2a039850a7a3bca50f3f06ad88dc557626f9", + "compiled_at": "2026-10-12T12:21:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:f21da1407d59d7d4318635517bb9d45937a68c04c2747fbfd9254d559b750432", + "digest": "sha256:815433c9c8cef1effe798105427e5d1f18af2014f0d2265838d91ac870214cf6", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3090, - "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", - "source_tree": "sha256:1079486b153c956a636f7eb5008f95b01f388730a1682ff5cc5789c1f4a8067f" + "files": 3091, + "generated_at_commit": "e09825afddde294659ca4a06354990e7ff530b62", + "source_tree": "sha256:6ffa7e6c4e272b46b100fa2f8b698c7d25588870c03b2f320d513ae2297e926a" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 0469dded..9a9abe12 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:baea130f2c52779b57d90139beb66ac01b21ab499d113471a334be5500f3e369", - "compiled_at": "2026-10-12T11:57:55Z", + "compiled_at": "2026-10-12T12:21:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:0893e0c34b7443fafe6a41c7ca2d0db8a9482bcf4aa0412bbb60efab02d31b94", + "digest": "sha256:67c7dafea9dd11fce8a30e2758fc9c0553d5e75c442bc6c2c22f134a090a5008", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 70, - "generated_at_commit": "20847ab80738c427be90ca3a1ba0c6b69ee0a90c", - "source_tree": "sha256:c774a2fac1bee6917cd97c6f4df2cca4b540bec809b44a59914e6a26fe23f4e6" + "generated_at_commit": "e09825afddde294659ca4a06354990e7ff530b62", + "source_tree": "sha256:479955d7d585b02e7323f4dbdbab0ac2ad395207ce4475eb4138b985ba7cb9ad" }, "owner_lane": "", "provenance": { diff --git a/docs/GB10_FIRMWARE_INVENTORY.md b/docs/GB10_FIRMWARE_INVENTORY.md index 44803046..370d15fe 100644 --- a/docs/GB10_FIRMWARE_INVENTORY.md +++ b/docs/GB10_FIRMWARE_INVENTORY.md @@ -35,6 +35,12 @@ the driver on the box; fetched read-only into a scratch directory, not vendored) container exactly as the driver does, refuses every malformed shape it was given in its self-test (22 mutations plus every truncation), and proves the file on this box matches the pinned digest. It never loads anything. +- Two more hosted tools, same rule (nothing is ever sent to the chip): + `ck_gsp_cot_encode` builds and checks the exact message the driver sends to + SEC2 (section 10), and `ck_gsp_bindata_extract` reads the eight GB10B + firmware arrays out of the public driver source with our own inflater and + hash code, cross-checks every size, record and digest, and writes them as + files (section 11). `make -C native/kernel test` runs all three self-tests. - The largest remaining unknowns for a native bring-up (section 8) are the SEC2 command protocol details beyond what the driver source shows, the exact GspFwWprMeta/boot-argument layout expected by this GSP-FMC build, and @@ -93,15 +99,35 @@ The driver embeds these as C byte arrays ("bindata") with an MIT licence header `kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B` [g_kernel_gsp_nvoc.c:924-926] (debug-fused parts use the `...DebugSigned_GB10B` archive, [889-891]). -| Archive label | Original file name (NVIDIA internal) | Bytes | -|---|---|---| -| GspRmBoot_GB10B UCODE_IMAGE_PROD | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_image.bin | 196,608 | -| GspRmBoot_GB10B UCODE_DESC_PROD | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_desc.bin | 84 (RM_RISCV_UCODE_DESC) | -| GspRmBoot_GB10B UCODE_IMAGE_DBG / DESC_DBG | ..._dbg_image.bin / ..._dbg_desc.bin | 196,608 / 84 | -| GspRmFmcGfwProdSigned_GB10B UCODE_IMAGE | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_gfw_image.bin | 195,912 | -| GspRmFmcGfwProdSigned_GB10B UCODE_HASH | g_gsp_gb10b_dyn_prd_gfw_hash.bin | 48 (SHA-384) | -| GspRmFmcGfwProdSigned_GB10B UCODE_SIG | g_gsp_gb10b_dyn_prd_gfw_sig.bin | 384 | -| GspRmFmcGfwProdSigned_GB10B UCODE_PKEY | g_gsp_gb10b_dyn_prd_gfw_pub_key.bin | 384 | +| Archive label | Original file name (NVIDIA internal) | Bytes | Stored as | sha256 of the bytes [OBSERVED] | +|---|---|---|---|---| +| GspRmBoot_GB10B UCODE_IMAGE_PROD | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_image.bin | 196,608 | raw | 427a691d8453f02548d395f40ac900eb0d5b8ea864e8f14f958eef890ba400a2 | +| GspRmBoot_GB10B UCODE_DESC_PROD | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_desc.bin | 84 (RM_RISCV_UCODE_DESC) | deflate, 28 bytes | 8371a29f1c68da89b73bdc87af477c37f0b4e05939c58379d0e3d29efc5575b5 | +| GspRmBoot_GB10B UCODE_IMAGE_DBG | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_dbg_image.bin | 196,608 | raw | 709b88a88fc7ae9bd56b010bcc0a8269d4d40b3c0454aa5b366e8d562d83a404 | +| GspRmBoot_GB10B UCODE_DESC_DBG | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_dbg_desc.bin | 84 | deflate, 28 bytes | 8371a29f... (byte-identical to DESC_PROD) | +| GspRmFmcGfwProdSigned_GB10B UCODE_IMAGE | kernel/inc/gspcc/bin/g_gsp_gb10b_dyn_prd_gfw_image.bin | 195,912 | raw | b13ead4b9a6b8a0d268f3094cc4f4521d6be8a9a525edbc9a8f3f397c86f1f2e | +| GspRmFmcGfwProdSigned_GB10B UCODE_HASH | g_gsp_gb10b_dyn_prd_gfw_hash.bin | 48 (SHA-384) | raw | f0389f3a9ce3bb6093e80bfc924bbe2a4ece0199b080a37f64bc1fef63f7500c | +| GspRmFmcGfwProdSigned_GB10B UCODE_SIG | g_gsp_gb10b_dyn_prd_gfw_sig.bin | 384 | raw | 9db429257a18e7c5c1a3df185001c671e21bec4e94c719a574d2ce72e2e07272 | +| GspRmFmcGfwProdSigned_GB10B UCODE_PKEY | g_gsp_gb10b_dyn_prd_gfw_pub_key.bin | 384 | raw | e9bbc669c27ad8827b5bbc2b2f52fdb47718659a651088869a5f3b11d2df7816 | + +Digests measured 2026-10-12 by `ck_gsp_bindata_extract` over the two files +fetched from the 580.173.02 tag (raw.githubusercontent.com, path +`src/nvidia/generated/`); the 580.173.02 Makefile pin +(`make -C native/kernel gsp-bindata-test`) checks the two image digests and +the decoded descriptor on every run. `UCODE_HASH` equals SHA-384 of +`UCODE_IMAGE` [OBSERVED, checked by the tool]. + +Array storage format [SOURCE]: each array is a `BINDATA_STORAGE_PVT` record +(uncompressed size, compressed size, data pointer, bCompressed, +bFileOverride, bReferencedDuringLoad) and an archive table +(`BINDATA_ARCHIVE` with `entryNum` and label/storage pairs) [bin_data_pvt.h, +bin_data.h]. A compressed array is a gzip member without the 10-byte gzip +header: raw DEFLATE, then CRC-32 and ISIZE, little endian. The driver inflates +it with its own zlib-style decoder (`utilGzAllocate`/`utilGzGetData`, +bin_data.c:36-45,96); the nouveau extractor prepends exactly that header +before `gzip.decompress` [nouveau/extract-firmware-nouveau.py:107-108]. +The 28-byte descriptor is 20 bytes of fixed-Huffman DEFLATE plus the two +trailers [OBSERVED]; our decoder verifies both. Source files: `src/nvidia/generated/g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c` (2,466,261 bytes of C) and @@ -111,9 +137,27 @@ file. The README says the `nouveau/` script "is used to extract some of the firmware binary images (and related data) encoded in the source code and store them as distinct files. These files are used by the Nouveau device driver" [README.md:170-173]; that script knows gh100, gb100 and gb202 FMC images, not -gb10b [nouveau/extract-firmware-nouveau.py:655-662,775-781]. Extracting the -GB10B arrays would be our own small step over the same public source. -[INFERRED (high)] +gb10b [nouveau/extract-firmware-nouveau.py:655-662,775-781]. DONE +2026-10-12: `ck_gsp_bindata_extract` (section 11) is that step, written +against the generated-file grammar and the storage records, not against the +nouveau script. + +Descriptor decode [SOURCE rmRiscvUcode.h:36-87, 21 u32 fields; OBSERVED +values]: version 5; bootloader/riscvElf/swbrom offsets and sizes 0; +manifest at 0x0 size 0xa00; monitorData at 0xa00 size 0xa600; monitorCode at +0xb000 size 0x24d00 (ends at 0x2fd00, inside the 196,608-byte image); +bIsMonitorEnabled 1; appVersion 0; fbReservedSize 0; bSignedAsCode 0. The +driver shifts these offsets by `RISCV_BR_ADDR_ALIGNMENT` = 8 bits when it +programs them [kernel_gsp_gh100.c:47, kernel_gsp_ga102.c:44], so the tool +refuses any region that is not 256-byte aligned. + +Which archive the driver picks for GB10B [SOURCE]: the HAL dispatch for +`kgspGetGspRmBootUcodeStorage` lands on the GB100 variant +[kernel_gsp_gb100.c:115-149], which outside confidential computing calls the +GA102 variant [kernel_gsp_ga102.c:101-120]: the `GspRmBoot` archive's +`UCODE_IMAGE_PROD` and `UCODE_DESC_PROD` (the DBG pair only on a debug-fused +part). The `GspRmFmcGfwProdSigned` quartet goes into the SEC2 chain-of-trust +payload (section 10). ### 3.4 Pieces that are NOT on the host side at all @@ -247,9 +291,9 @@ code into AIENOS would require carrying the MIT notice (none was copied here). - Cut C "inventory" is done by this document; "parsers and refusal tests for firmware metadata" by `ck_gsp_fw_inspect`. The next host-only steps that do - not need the machine: (a) a small extractor over the two public - `g_bindata_*_GB10B.c` files that writes the eight arrays as files with - digests (our own tool, no Python); (b) DONE 2026-10-12: the encoder, decoder + not need the machine: (a) DONE 2026-10-12: `ck_gsp_bindata_extract` + (section 11) writes the eight arrays as files with digests, own DEFLATE and + SHA-384, `make -C native/kernel gsp-bindata-test`; (b) DONE 2026-10-12: the encoder, decoder and refusal tests for `NVDM_PAYLOAD_COT`, the MCTP/NVDM headers, the EMEM packet and `GSP_FMC_BOOT_PARAMS` are `ck_gsp_cot_encode` (section 10); (c) remaining: an encoder for `GspFwWprMeta` (256 bytes, layout known, the @@ -282,11 +326,19 @@ code into AIENOS would require carrying the MIT notice (none was copied here). mapping, channel, submit) but which RPCs are mandatory is not established. 5. [UNKNOWN] Whether the confidential-computing (`_cc_`) sections or the SPDM session are ever required on this platform. Assumed not [INFERRED (high)]. -6. [UNKNOWN] The exact meaning of the `GspRmBoot_GB10B` image versus the - `GspRmFmcGfwProdSigned_GB10B` image (both ~196 KiB): the SEC2 path sends the - FMC archive, the boot-binary preparation copies the GspRmBoot image and its - RM_RISCV_UCODE_DESC; which one the GSP's boot ROM consumes on GB10B, and how - the descriptor offsets are used, was not traced end to end. +6. [RESOLVED on the host side 2026-10-12, SOURCE; consumer side INFERRED + (medium)] `GspRmFmcGfwProdSigned_GB10B` (image, hash, signature, public + key) is what SEC2 receives in the chain-of-trust payload (section 10). + `GspRmBoot_GB10B` (image plus RM_RISCV_UCODE_DESC) is what + `kgspPopulateWprMeta_GH100` describes to the FMC as the "GSP-FMC ucode" + bootloader: `sizeOfBootloader`, `sysmemAddrOfBootloader`, + `bootloaderCodeOffset`/`DataOffset`/`ManifestOffset` come from that image + and the descriptor's monitorCode/monitorData/manifest offsets + [kernel_gsp_gh100.c:295-335]; the direct boot-ROM path programs the same + three regions into `NV_PGSP_FALCON_BCR_DMAADDR_*` [kernel_gsp_gh100.c: + `_kgspBootstrapGspFmc_GH100`], which GB10B does not take (section 11). + Who reads the WprMeta bootloader fields on the SEC2 path (FMC or ACR) runs + inside NVIDIA code and is not readable. 7. [UNKNOWN] Reset and re-open behavior on GB10B after a failed FMC boot (`kgspResetHw_GB100` waits for "reset access"); needed for the resource-incarnation protection (#285) before any repeated attempt. @@ -305,7 +357,13 @@ fsp_mctp_format.h, fsp_emem_channels.h, kernel_sec2.c (`ksec2SendMessage`, `ksec2PollForCanSend`), g_kernel_sec2_nvoc.c/.h (version, sizes, SEID), gspifpub.h, gsp_init_args.h, gsp_fw_wpr_meta.h, kernel_gsp_gh100.c (`kgspSetupGspFmcArgs`), and published/blackwell/gb10b dev_sec_pri.h, -dev_gsp.h, dev_falcon_v4.h. Not read: the GSP RPC layer, the libos +dev_gsp.h, dev_falcon_v4.h; for sections 3.3 and 11 also rmRiscvUcode.h, +bin_data.c, bin_data.h, bin_data_pvt.h, kernel_gsp_ga102.c, +nouveau/extract-firmware-nouveau.py (lines 82-114 only), kernel_gsp_gh100.c +(`kgspBootstrap_GH100`, `_kgspLockdownReleasedOrFmcError`, +`kgspPopulateWprMeta_GH100`, `_kgspBootstrapGspFmc_GH100`), g_kern_fsp_nvoc.c +(the `PDB_PROP_KFSP_IS_MISSING` chip list), and the full bindata record +tables of both GB10B files. Not read: the GSP RPC layer, the libos init-argument block, ACR or GSP internals (not available). No Context7 or web manual covers this layer; the DGX Spark user guide is silent on GSP firmware loading (DOCS SILENT on native GSP bring-up). @@ -391,3 +449,68 @@ Evidence 2026-10-12 on the box: `CK_GSP_COT_ENCODE_SELFTEST: PASS` (80 checks: both layouts against the compiler, golden header words, encode/decode round trips, 46 field mutations and every header truncation refused by name), same under ASan/UBSan. + +## 11. Extracted arrays and the GB10B boot decision [SOURCE] + +Tool: `native/kernel/tools/ck_gsp_bindata_extract.c` (hosted C, no +dependencies beyond our own `native/argus/sha256.c`; SHA-384, CRC-32 and the +raw-DEFLATE decoder, stored/fixed/dynamic blocks, are in the tool). +`make -C native/kernel gsp-bindata-extract` builds it; +`make -C native/kernel gsp-bindata-test` runs the self-test and, when the two +driver files are present under `GSP_BINDATA_DIR` (default +`~/.cache/aienos/open-gpu-kernel-modules-580.173.02`), the pin check; it is +part of `make test`. Without the files the pin line reads `NOT_RUN`, never +PASS. + +What it checks before it writes a byte: the generated-file grammar +(`FUNCTION`, `FILE NAME`, `FILE TYPE BINARY`, `COMPRESSION`, `COMPLEX_STRUCT +NO`, `DATA SIZE`, `COMPRESSED SIZE`), the array identifier +`kgspBinArchive_BINDATA_LABEL_