Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/driver/fwprep.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / driver / fwprep.om` 613 lines ยท 12660 bytes Raw Blame History 1 note fwprep.om: the GB10 firmware inputs for the bring-up chain, from files only (OM-1 seeded omc). 2 note Usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b] 3 note FWFILE gsp_ga10x.bin (580.173.02), inspected as ck_gsp_fw_inspect inspect does 4 note OGKMSRC open-gpu-kernel-modules-580.173.02 tree; its two profile-specific bindata files are read as 5 note ck_gsp_bindata_extract extract does (src/nvidia/generated/g_bindata_kgspGetBinArchive*) 6 note OUTDIR must be new for gb20b (commit marker fw.gb20b.manifest). The default directory 7 note gets fmc.img fmc.hash fmc.pubkey fmc.sig bl.img, then fw.manifest (written to 8 note fw.manifest.tmp and renamed; fw.manifest is unlinked first, so a refused or failed run 9 note never leaves a manifest behind; consumers read the outputs only through it) 10 note stdout: the inspect report, the FMC extract report, the boot extract report (the C tools' exact 11 note bytes, without --out), then "fwprep ..." lines. Exit 0 ok, 1 usage or FWFILE open/read error 12 note (stderr), 2 refused, 3 output write failure. 13 note Build: cat gsp/sha2.om gsp/inflate.om gsp/fw.om gsp/bindata.om fwprep.om | build/omc > fwprep 14 note Prefix fwp. Host only: reads files, writes OUTDIR; no device. 15 global fwpok ulong 1 16 global fwp20 ulong 1 17 global fwparg uchar 32 18 text FWPGB20 "gb20b" 19 note sha256 of the installed 580.173.02 firmware and the exact GB20B vendor archives, 20 note in FMC then boot order, from open-gpu-kernel-modules `20e4e6e19cc26ba47b5cbe23130a396be100c427`. 21 text FWPGSP "`32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963`" 22 text FWPARCH "`035179cfd878d6bed7308842b0d95612fbb0390149ebee7532b23f375727d8b671e3c512eaa78c60518f6c907826df36bed8e9cbbe8ea8257ca0b1c45d131dec`" 23 text FWPERR20 "fwprep REFUSED GB20B input digest" 24 global fwpsgb ulong 80 25 global fwpsgl ulong 80 26 global fwpst uchar 128 27 global fwpsrc uchar 4096 28 global fwpsrcn ulong 1 29 global fwpout uchar 4096 30 global fwpoutn ulong 1 31 global fwpp uchar 4096 32 global fwppn ulong 1 33 global fwprn uchar 8200 34 global fwpoo ulong 5 35 global fwpon ulong 5 36 global fwpoh uchar 320 37 global fwpdo ulong 1 38 global fwpsz ulong 2 39 global fwpsh uchar 128 40 note FWPTXT segments: 1 "fwprep ", 2 usage, 3..5 bindata paths, 6..7 functions, 8..13 labels, 41 note 14..20 output names, 21.. messages, 33.. manifest pieces, 43..63 the 21 RM_RISCV_UCODE_DESC 42 note words in struct order (C riscv_desc), 64.. more pieces 43 text FWPTXT "|fwprep |usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b]|/src/nvidia/generated/|g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c|g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c|kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B|kgspGetBinArchiveGspRmBoot_GB10B|UCODE_IMAGE|UCODE_HASH|UCODE_PKEY|UCODE_SIG|UCODE_IMAGE_PROD|UCODE_DESC_PROD|fmc.img|fmc.hash|fmc.pubkey|fmc.sig|bl.img|fw.manifest|fw.manifest.tmp|REFUSED unexpected function | in |REFUSED missing label |wrote | bytes=| sha256=|RESULT OK|FAILED |makedir |write |rename |: |fwmanifest 1|fwversion |build_id |fw_file bytes=|fwimage offset=| size=|fwsignature .fwsignature_gb10y offset=|fmc_src |boot_src |bl_desc UCODE_DESC_PROD| version=| bootloader_off=| bootloader_size=| bl_param_off=| bl_param_size=| elf_off=| elf_size=| app_version=| manifest_off=| manifest_size=| mdata_off=| mdata_size=| mcode_off=| mcode_size=| monitor_enabled=| swbrom_code_off=| swbrom_code_size=| swbrom_data_off=| swbrom_data_size=| fb_reserved=| signed_as_code=|out |end|open |short read|REFUSED firmware|REFUSED bindata |g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB20B.c|g_bindata_kgspGetBinArchiveGspRmBoot_GB20B.c|kgspGetBinArchiveGspRmFmcGfwProdSigned_GB20B|kgspGetBinArchiveGspRmBoot_GB20B|fwsignature .fwsignature_gb20y offset=|fw.gb20b.manifest|fw.gb20b.manifest.tmp|" 44 fn fwpsetup to void 45 if eq get fwpok 0 1 46 ret 47 end 48 put fwpok 0 1 49 seg = ulong 0 50 for i ulong len FWPTXT 51 c = get FWPTXT i 52 if eq c 124 53 seg = add seg 1 54 put fwpsgb seg add i 1 55 put fwpsgl seg 0 56 else 57 put fwpsgl seg add get fwpsgl seg 1 58 end 59 end 60 end 61 fn fwpos k ulong to void 62 b = get fwpsgb k 63 for i ulong get fwpsgl k 64 fwoc get FWPTXT add b i 65 end 66 end 67 fn fwppath to void 68 for i ulong get fwppn 0 69 fwoc get fwpp i 70 end 71 end 72 note fwpp = OUTDIR "/" segment k 73 fn fwpmk k ulong to void 74 n = get fwpoutn 0 75 for i ulong n 76 put fwpp i get fwpout i 77 end 78 put fwpp n 47 79 n = add n 1 80 b = get fwpsgb k 81 for i ulong get fwpsgl k 82 put fwpp n get FWPTXT add b i 83 n = add n 1 84 end 85 put fwppn 0 n 86 end 87 note bdpath = OGKMSRC "/src/nvidia/generated/" segment k 88 fn fwpbdp k ulong to void 89 n = get fwpsrcn 0 90 for i ulong n 91 put bdpath i get fwpsrc i 92 end 93 for s ulong 2 94 g = ulong 3 95 if eq s 1 96 g = k 97 end 98 b = get fwpsgb g 99 for i ulong get fwpsgl g 100 put bdpath n get FWPTXT add b i 101 n = add n 1 102 end 103 end 104 put bdpathn 0 n 105 end 106 note one line to stderr: segment k, then the path in fwpath (when wp 1), then ": " strerror e (e > 0) 107 fn fwperr k ulong wp ulong e ulong to void 108 z = fwoflush 109 put fwofd 0 2 110 fwpos k 111 if eq wp 1 112 fwopath 113 end 114 if gt e 0 115 fwpos 32 116 fwoerrno e 117 end 118 fwoc 10 119 z = fwoflush 120 put fwofd 0 1 121 end 122 note Select the production archives, commit marker, manifest signature and ELF family together. 123 note The same slots drive matching and reporting. The default table remains GB10B. 124 fn fwpprof to ulong 125 n = argread 4 fwparg 0 32 126 if ne n long len FWPGB20 127 ret 1 128 end 129 for i ulong len FWPGB20 130 if ne get fwparg i get FWPGB20 i 131 ret 1 132 end 133 end 134 for i ulong 4 135 put fwpsgb add 4 i get fwpsgb add 70 i 136 put fwpsgl add 4 i get fwpsgl add 70 i 137 end 138 for i ulong 2 139 put fwpsgb add 19 i get fwpsgb add 75 i 140 put fwpsgl add 19 i get fwpsgl add 75 i 141 end 142 put fwpsgb 39 get fwpsgb 74 143 put fwpsgl 39 get fwpsgl 74 144 if ne fwfamily FWFAM20 0 145 ret 1 146 end 147 put fwp20 0 1 148 ret 0 149 end 150 note arguments into fwpath (FWFILE), fwpsrc, fwpout: 0, or 1 on a usage error 151 fn fwpargs to ulong 152 if eq argcnt 5 153 if ne fwpprof 0 154 ret 1 155 end 156 else 157 if ne argcnt 4 158 ret 1 159 end 160 end 161 a = argread 1 fwpath 0 4096 162 if lt a 1 163 ret 1 164 end 165 put fwpathn 0 ulong a 166 b = argread 2 fwpsrc 0 4000 167 if lt b 1 168 ret 1 169 end 170 put fwpsrcn 0 ulong b 171 c = argread 3 fwpout 0 4000 172 if lt c 1 173 ret 1 174 end 175 put fwpoutn 0 ulong c 176 ret 0 177 end 178 note C cmd_inspect on FWFILE: 0 OK, 2 refused, 1 open or read error (C stderr wording) 179 fn fwpfw to ulong 180 fd = fopen fwpath 0 get fwpathn 0 524288 0 181 if lt fd 0 182 fwperr 66 1 ulong neg fd 183 ret 1 184 end 185 s = fstat int fd fwpst 0 128 186 if lt s 0 187 c = fclose int fd 188 fwperr 66 1 ulong neg s 189 ret 1 190 end 191 sz = ulong 0 192 for i ulong 8 193 sz = or sz shl ulong get fwpst add 48 i mul i 8 194 end 195 md = ulong 0 196 for i ulong 4 197 md = or md shl ulong get fwpst add 16 i mul i 8 198 end 199 note S_IFMT `0170000` = 61440, S_IFDIR `0040000` = 16384: a directory is "Is a directory" (21) 200 if eq and md 61440 16384 201 c = fclose int fd 202 fwperr 66 1 21 203 ret 1 204 end 205 e = fwinsp int fd sz 206 c = fclose int fd 207 if eq e 1 208 fwperr 67 0 0 209 ret 1 210 end 211 ret e 212 end 213 note does the label of block i equal FWPTXT segment k? 214 fn fwpleq i ulong k ulong to ulong 215 b = get fwpsgb k 216 l = get fwpsgl k 217 if ne get bdlbl i l 218 ret 0 219 end 220 a = mul i 64 221 m = ulong 1 222 for j ulong l 223 if ne get bdlb add a j get FWPTXT add b j 224 m = 0 225 end 226 end 227 ret m 228 end 229 note block whose label equals FWPTXT segment k, or BDNONE 230 fn fwpfind k ulong to ulong 231 for i ulong get bdn 0 232 if eq fwpleq i k 1 233 ret i 234 end 235 end 236 ret BDNONE 237 end 238 note "fwprep REFUSED missing label L in FILE" 239 fn fwpmiss k ulong f ulong to ulong 240 fwpos 1 241 fwpos 23 242 fwpos k 243 fwpos 22 244 fwpos f 245 fwoc 10 246 ret 2 247 end 248 note record block for label segment k as output slot o; 2 (refused) when it is missing 249 fn fwpslot k ulong f ulong o ulong to ulong 250 i = fwpfind k 251 if eq i BDNONE 252 ret fwpmiss k f 253 end 254 put fwpoo o get bdpo i 255 put fwpon o get bdpn i 256 ret 0 257 end 258 note extract bindata file f (segment 4 FMC or 5 boot) whose function must be segment fn 259 fn fwpbd f ulong fs ulong w ulong to ulong 260 fwpbdp f 261 e = bdfile 262 put fwpsz w get bdfsz 0 263 for i ulong 64 264 put fwpsh add mul w 64 i get bdfsh i 265 end 266 if ne e 0 267 fwpos 1 268 fwpos 69 269 fwpos f 270 fwoc 10 271 ret 2 272 end 273 b = get fwpsgb fs 274 l = get fwpsgl fs 275 m = ulong 1 276 if ne get bdfnl 0 l 277 m = 0 278 else 279 for j ulong l 280 if ne get bdfn j get FWPTXT add b j 281 m = 0 282 end 283 end 284 end 285 if eq m 0 286 fwpos 1 287 fwpos 21 288 bdofn 0 289 fwpos 22 290 fwpos f 291 fwoc 10 292 ret 2 293 end 294 ret 0 295 end 296 fn fwpfmc to ulong 297 e = fwpbd 4 6 0 298 if ne e 0 299 ret e 300 end 301 e = fwpslot 8 4 0 302 if ne e 0 303 ret e 304 end 305 e = fwpslot 9 4 1 306 if ne e 0 307 ret e 308 end 309 e = fwpslot 10 4 2 310 if ne e 0 311 ret e 312 end 313 ret fwpslot 11 4 3 314 end 315 fn fwpboot to ulong 316 e = fwpbd 5 7 1 317 if ne e 0 318 ret e 319 end 320 e = fwpslot 12 5 4 321 if ne e 0 322 ret e 323 end 324 i = fwpfind 13 325 if eq i BDNONE 326 ret fwpmiss 13 5 327 end 328 put fwpdo 0 get bdpo i 329 ret 0 330 end 331 note "fwprep FAILED : " on stdout 332 fn fwpfail k ulong e ulong to ulong 333 fwpos 1 334 fwpos 28 335 fwpos k 336 fwppath 337 fwpos 32 338 fwoerrno e 339 fwoc 10 340 ret 3 341 end 342 note write bdpl[o..o+n) to OUTDIR/segment k: 0 or a positive errno (5 for a zero-byte write) 343 fn fwpwf k ulong o ulong n ulong to ulong 344 fwpmk k 345 fd = fopen fwpp 0 get fwppn 0 524865 420 346 if lt fd 0 347 ret ulong neg fd 348 end 349 q = ulong 0 350 while lt q n bound 999999 351 r = write int fd bdpl add o q sub n q 352 if lt r 1 353 c = fclose int fd 354 if lt r 0 355 ret ulong neg r 356 end 357 ret 5 358 end 359 q = add q ulong r 360 end 361 c = fclose int fd 362 if lt c 0 363 ret ulong neg c 364 end 365 ret 0 366 end 367 note write output slot o as segment k and print its line; 0 or 3 368 fn fwpput o ulong k ulong to ulong 369 e = fwpwf k get fwpoo o get fwpon o 370 if ne e 0 371 ret fwpfail 30 e 372 end 373 bdsh256 get fwpoo o get fwpon o 374 shhex 32 375 for i ulong 64 376 put fwpoh add mul o 64 i get shhx i 377 end 378 fwpos 1 379 fwpos 24 380 fwpos k 381 fwpos 25 382 fwodec get fwpon o 383 fwpos 26 384 fwohx 32 385 fwoc 10 386 ret 0 387 end 388 fn fwpohx o ulong to void 389 for i ulong 64 390 fwoc get fwpoh add mul o 64 i 391 end 392 end 393 note little-endian u32 word w of the boot UCODE_DESC_PROD plain bytes 394 fn fwpw32 w ulong to ulong 395 p = add get fwpdo 0 mul w 4 396 v = ulong 0 397 for k ulong 4 398 v = or v shl ulong get bdpl add p k mul k 8 399 end 400 ret v 401 end 402 note manifest lines 1..6: the firmware and the two bindata inputs 403 fn fwpman1 to void 404 fwpos 33 405 fwoc 10 406 fwpos 34 407 for i ulong get fwvern 0 408 fwoc get fwver i 409 end 410 fwoc 10 411 fwpos 35 412 for i ulong get fwbidn 0 413 fwoc get fwbidh i 414 end 415 fwoc 10 416 fwpos 36 417 fwodec get fwlen 0 418 fwpos 26 419 for i ulong 64 420 fwoc get fwhxf i 421 end 422 fwoc 10 423 fwpos 37 424 fwodec get fwsof get fwimx 0 425 fwpos 38 426 fwodec get fwssz get fwimx 0 427 fwpos 26 428 for i ulong 64 429 fwoc get fwhxi i 430 end 431 fwoc 10 432 fwpos 39 433 fwodec get fwsof get fwsx 0 434 fwpos 38 435 fwodec get fwssz get fwsx 0 436 fwpos 26 437 for i ulong 64 438 fwoc get fwhxs i 439 end 440 fwoc 10 441 for w ulong 2 442 fwpos add 40 w 443 fwpos add 4 w 444 fwpos 25 445 fwodec get fwpsz w 446 fwpos 26 447 for i ulong 64 448 fwoc get fwpsh add mul w 64 i 449 end 450 fwoc 10 451 end 452 end 453 note manifest: the descriptor words, the outputs, "end" 454 fn fwpman2 to void 455 fwpos 42 456 for w ulong 21 457 fwpos add 43 w 458 fwodec fwpw32 w 459 end 460 fwoc 10 461 for o ulong 5 462 fwpos 64 463 fwpos add 14 o 464 fwpos 25 465 fwodec get fwpon o 466 fwpos 26 467 fwpohx o 468 fwoc 10 469 end 470 fwpos 65 471 fwoc 10 472 end 473 note write fw.manifest.tmp through the fw.om writer, then rename it to fw.manifest; 0 or 3 474 fn fwpman to ulong 475 z = fwoflush 476 oe = get fwoerr 0 477 fwpmk 20 478 fd = fopen fwpp 0 get fwppn 0 524865 420 479 if lt fd 0 480 ret fwpfail 30 ulong neg fd 481 end 482 put fwofd 0 int fd 483 put fwoerr 0 0 484 fwpman1 485 fwpman2 486 z = fwoflush 487 we = get fwoerr 0 488 put fwofd 0 1 489 put fwoerr 0 oe 490 c = fclose int fd 491 if eq we 1 492 ret fwpfail 30 5 493 end 494 if lt c 0 495 ret fwpfail 30 ulong neg c 496 end 497 ret fwpren 498 end 499 note rename fw.manifest.tmp to fw.manifest (renameat2 packed list: u16 count, then u16 len + bytes) 500 fn fwpren to ulong 501 put fwprn 0 2 502 put fwprn 1 0 503 n = ulong 2 504 for s ulong 2 505 fwpmk sub 20 s 506 l = get fwppn 0 507 put fwprn n uchar rem l 256 508 put fwprn add n 1 uchar div l 256 509 n = add n 2 510 for i ulong l 511 put fwprn add n i get fwpp i 512 end 513 n = add n l 514 end 515 r = renames fwprn 0 n 0 516 if lt r 0 517 ret fwpfail 31 ulong neg r 518 end 519 fwpos 1 520 fwpos 24 521 fwpos 19 522 fwoc 10 523 ret 0 524 end 525 note make OUTDIR (an existing one is fine) and write every output, the manifest last 526 fn fwpwrite to ulong 527 r = makedir fwpout 0 get fwpoutn 0 493 528 if lt r 0 529 if or ne r -17 eq get fwp20 0 1 530 for i ulong get fwpoutn 0 531 put fwpp i get fwpout i 532 end 533 put fwppn 0 get fwpoutn 0 534 ret fwpfail 29 ulong neg r 535 end 536 end 537 for o ulong 5 538 e = fwpput o add 14 o 539 if ne e 0 540 ret e 541 end 542 end 543 ret fwpman 544 end 545 note Bind the selected section and archive payloads to the complete pinned inputs before output. 546 fn fwppins to ulong 547 for i ulong 64 548 if ne get fwhxf i get FWPGSP i 549 ret 0 550 end 551 end 552 for i ulong 128 553 if ne get fwpsh i get FWPARCH i 554 ret 0 555 end 556 end 557 ret 1 558 end 559 fn fwprun to ulong 560 e = fwpfw 561 if eq e 2 562 fwpos 1 563 fwpos 68 564 fwoc 10 565 end 566 if ne e 0 567 ret e 568 end 569 e = fwpfmc 570 if ne e 0 571 ret e 572 end 573 e = fwpboot 574 if ne e 0 575 ret e 576 end 577 if eq get fwp20 0 1 578 if eq fwppins 0 579 for i ulong len FWPERR20 580 fwoc get FWPERR20 i 581 end 582 fwoc 10 583 ret 2 584 end 585 end 586 e = fwpwrite 587 if ne e 0 588 ret e 589 end 590 fwpos 1 591 fwpos 27 592 fwoc 10 593 ret 0 594 end 595 fn main to int 596 fwsetup 597 bdsetup 598 fwpsetup 599 if ne fwpargs 0 600 fwperr 2 0 0 601 ret 1 602 end 603 if eq get fwp20 0 0 604 fwpmk 19 605 u = unlink fwpp 0 get fwppn 0 606 end 607 e = fwprun 608 z = fwoflush 609 if and eq e 0 eq get fwoerr 0 1 610 ret 3 611 end 612 ret int e 613 end