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-gpu-driver/blob/main/gsp/fw.om # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / gsp / fw.om` 749 lines ยท 13838 bytes Raw Blame History 1 note gsp/fw.om: GSP firmware container inspection in seeded Omega (OM-1). Ports the inspect path of 2 note aienux PR #441 native/kernel/tools/ck_gsp_fw_inspect.c (in_bounds, inspect_buf, print_report, 3 note cmd_inspect) for firmware version 580.173.02 (default family gb10y). Library unit: no main. 4 note Prefix fw. Needs gsp/sha2.om concatenated first. The file is read with pread from an open fd, 5 note never mapped and never a device. Also holds the shared stdout writer (fwo*) that gsp/bindata.om 6 note and fwprep.om print through, and the strerror texts the C prints. 7 note Deviation (documented): the section string table is copied into a 16 MiB global; a larger one is 8 note refused with reason 29 after the C's bounds check and before its NUL check. The C keeps the whole 9 note file in memory; this port preads only the header, the section table, the string table, the 10 note version and note bytes, and streams the three SHA-256 digests (same results). 11 const FWOCAP ulong 65536 12 const FWSTMX ulong `16777216` 13 const FWNONE ulong 999 14 global fwob uchar 65536 15 global fwon ulong 1 16 global fwofd int 1 17 global fwoerr ulong 1 18 global fwsgb ulong 80 19 global fwsgl ulong 80 20 global fwok ulong 1 21 global fwpath uchar 4096 22 global fwpathn ulong 1 23 global fwhd uchar 64 24 global fwsh uchar 16384 25 global fwst uchar `16777216` 26 global fwstn ulong 1 27 global fwbuf uchar 128 28 global fwshn ulong 1 29 global fwnsec ulong 1 30 global fwsn ulong 256 31 global fwsty ulong 256 32 global fwsof ulong 256 33 global fwssz ulong 256 34 global fwlen ulong 1 35 global fwimx ulong 1 36 global fwvx ulong 1 37 global fwbx ulong 1 38 global fwsx ulong 1 39 global fwver uchar 64 40 global fwvern ulong 1 41 global fwbidh uchar 128 42 global fwbidn ulong 1 43 global fwhxf uchar 64 44 global fwhxi uchar 64 45 global fwhxs uchar 64 46 note segment k of FWTXT is the text between the k-th and (k+1)-th '|' (segment 0 is empty). 47 note 1..28 are the C refusal reasons in check order, 29 the deviation reason, 30.. report pieces, 48 note 54.. strerror texts (glibc wording); 68..70 more strerror texts for fwprep's write paths. 49 text FWTXT "|short header: file smaller than an ELF64 header|ELF magic missing|not ELF64 (EI_CLASS)|not little-endian (EI_DATA)|EI_VERSION is not 1|e_type is not ET_REL (the pinned container is a relocatable object)|e_machine is not RISC-V (243)|e_shentsize is not 64|e_shnum is 0: no section header table|e_shnum above this tool's limit (256)|e_shstrndx out of range|section header table outside the file|section string table outside the file or empty|section string table not NUL-terminated|section name index outside the string table|section bounds: offset+size outside the file|missing section .fwimage|.fwimage empty|missing section .fwversion|missing section .note.gnu.build-id|missing section: no signature section for this chip family|signature section empty|version section size not in 1..63|version string not NUL-terminated|version mismatch against the pinned driver version|build-id note too short|build-id note is not an NT_GNU_BUILD_ID note|build-id note descriptor size out of range|section string table above this port's 16 MiB buffer|file | bytes=| family=| expect_version=|section | type=| offset=| size=|(null)|fwversion |build_id |signature_section |sha256_file |sha256_fwimage |sha256_signature |RESULT OK|RESULT REFUSED |.fwimage|.fwversion|.note.gnu.build-id|.fwsignature_gb10y|580.173.02|gb10y|GNU|No such file or directory|Permission denied|Is a directory|File too large|Input/output error|Not a directory|Too many levels of symbolic links|File name too long|Unknown error |open |: |short read|Too many open files|Cannot allocate memory|File exists|No space left on device|Read-only file system|.fwsignature_gb20y|gb20y|" 50 text FWHEXD "`0123456789abcdef`" 51 note build the segment table once 52 fn fwsetup to void 53 if eq get fwok 0 1 54 ret 55 end 56 put fwok 0 1 57 seg = ulong 0 58 put fwsgb 0 0 59 put fwsgl 0 0 60 for i ulong len FWTXT 61 c = get FWTXT i 62 if eq c 124 63 seg = add seg 1 64 put fwsgb seg add i 1 65 put fwsgl seg 0 66 else 67 put fwsgl seg add get fwsgl seg 1 68 end 69 end 70 put fwon 0 0 71 put fwofd 0 1 72 put fwoerr 0 0 73 end 74 note ---- buffered writer: fwob[0..fwon) goes to fd fwofd; a failed write sets fwoerr 1 ---- 75 fn fwoflush to long 76 n = get fwon 0 77 p = ulong 0 78 while lt p n bound 999999 79 r = write get fwofd 0 fwob p sub n p 80 if le r 0 81 put fwoerr 0 1 82 put fwon 0 0 83 ret -5 84 end 85 p = add p ulong r 86 end 87 put fwon 0 0 88 ret 0 89 end 90 fn fwoc c uchar to void 91 if ge get fwon 0 FWOCAP 92 z = fwoflush 93 end 94 n = get fwon 0 95 put fwob n c 96 put fwon 0 add n 1 97 end 98 note print segment k of FWTXT 99 fn fwos k ulong to void 100 b = get fwsgb k 101 for i ulong get fwsgl k 102 fwoc get FWTXT add b i 103 end 104 end 105 note print v in decimal 106 fn fwodec v ulong to void 107 d = new uchar 24 0 108 n = ulong 0 109 x = v 110 while lt n 24 bound 24 111 put d n add uchar rem x 10 48 112 n = add n 1 113 x = div x 10 114 if eq x 0 115 break 116 end 117 end 118 while gt n 0 bound 24 119 n = sub n 1 120 fwoc get d n 121 end 122 end 123 note print v in lowercase hex without leading zeros (C %x) 124 fn fwohex v ulong to void 125 d = new uchar 24 0 126 n = ulong 0 127 x = v 128 while lt n 24 bound 24 129 put d n get FWHEXD rem x 16 130 n = add n 1 131 x = div x 16 132 if eq x 0 133 break 134 end 135 end 136 while gt n 0 bound 24 137 n = sub n 1 138 fwoc get d n 139 end 140 end 141 note print shhx[0..2n) (call shhex n first) 142 fn fwohx n ulong to void 143 for i ulong mul n 2 144 fwoc get shhx i 145 end 146 end 147 fn fwopath to void 148 for i ulong get fwpathn 0 149 fwoc get fwpath i 150 end 151 end 152 note print the strerror text of errno e (positive) 153 fn fwoerrno e ulong to void 154 k = ulong 0 155 if eq e 2 156 k = 54 157 end 158 if eq e 13 159 k = 55 160 end 161 if eq e 21 162 k = 56 163 end 164 if eq e 27 165 k = 57 166 end 167 if eq e 5 168 k = 58 169 end 170 if eq e 20 171 k = 59 172 end 173 if eq e 40 174 k = 60 175 end 176 if eq e 36 177 k = 61 178 end 179 if eq e 24 180 k = 66 181 end 182 if eq e 12 183 k = 67 184 end 185 if eq e 17 186 k = 68 187 end 188 if eq e 28 189 k = 69 190 end 191 if eq e 30 192 k = 70 193 end 194 if eq k 0 195 fwos 62 196 fwodec e 197 ret 198 end 199 fwos k 200 end 201 note ---- pread loops, one per destination global: 0, -errno, or -5 when the file ends early ---- 202 fn fwrdhd fd int off ulong n ulong to long 203 q = ulong 0 204 while lt q n bound 999999 205 r = pread fd fwhd q sub n q long add off q 206 if lt r 0 207 ret r 208 end 209 if eq r 0 210 ret -5 211 end 212 q = add q ulong r 213 end 214 ret 0 215 end 216 fn fwrdsh fd int off ulong n ulong to long 217 q = ulong 0 218 while lt q n bound 999999 219 r = pread fd fwsh q sub n q long add off q 220 if lt r 0 221 ret r 222 end 223 if eq r 0 224 ret -5 225 end 226 q = add q ulong r 227 end 228 ret 0 229 end 230 fn fwrdst fd int off ulong n ulong to long 231 q = ulong 0 232 while lt q n bound 999999 233 r = pread fd fwst q sub n q long add off q 234 if lt r 0 235 ret r 236 end 237 if eq r 0 238 ret -5 239 end 240 q = add q ulong r 241 end 242 ret 0 243 end 244 fn fwrdbf fd int off ulong n ulong to long 245 q = ulong 0 246 while lt q n bound 999999 247 r = pread fd fwbuf q sub n q long add off q 248 if lt r 0 249 ret r 250 end 251 if eq r 0 252 ret -5 253 end 254 q = add q ulong r 255 end 256 ret 0 257 end 258 note ---- little-endian readers (C rd16/rd32/rd64) over fwhd, fwsh, fwbuf ---- 259 fn fwh16 p ulong to ulong 260 ret or ulong get fwhd p shl ulong get fwhd add p 1 8 261 end 262 fn fwh64 p ulong to ulong 263 v = ulong 0 264 for i ulong 8 265 v = or v shl ulong get fwhd add p i mul i 8 266 end 267 ret v 268 end 269 fn fws32 p ulong to ulong 270 v = ulong 0 271 for i ulong 4 272 v = or v shl ulong get fwsh add p i mul i 8 273 end 274 ret v 275 end 276 fn fws64 p ulong to ulong 277 v = ulong 0 278 for i ulong 8 279 v = or v shl ulong get fwsh add p i mul i 8 280 end 281 ret v 282 end 283 fn fwb32 p ulong to ulong 284 v = ulong 0 285 for i ulong 4 286 v = or v shl ulong get fwbuf add p i mul i 8 287 end 288 ret v 289 end 290 note C in_bounds: off + size <= len without overflow 291 fn fwinb off ulong size ulong flen ulong to ulong 292 if gt off flen 293 ret 0 294 end 295 if le size sub flen off 296 ret 1 297 end 298 ret 0 299 end 300 note does the NUL-terminated name at fwst[off] equal segment k? 301 fn fwnmeq off ulong k ulong to ulong 302 b = get fwsgb k 303 l = get fwsgl k 304 n = get fwstn 0 305 for i ulong l 306 p = add off i 307 if ge p n 308 ret 0 309 end 310 if ne get fwst p get FWTXT add b i 311 ret 0 312 end 313 end 314 p2 = add off l 315 if ge p2 n 316 ret 0 317 end 318 if ne get fwst p2 0 319 ret 0 320 end 321 ret 1 322 end 323 note checks 1..12 (C inspect_buf lines 123-138): returns 0, a reason, or 1000 on an I/O error 324 fn fwchk1 fd int flen ulong to ulong 325 if lt flen 64 326 ret 1 327 end 328 r = fwrdhd fd 0 64 329 if ne r 0 330 ret 1000 331 end 332 note magic 0x7f 'E' 'L' 'F' = 127 69 76 70 333 m = ulong 0 334 if ne get fwhd 0 127 335 m = 1 336 end 337 if ne get fwhd 1 69 338 m = 1 339 end 340 if ne get fwhd 2 76 341 m = 1 342 end 343 if ne get fwhd 3 70 344 m = 1 345 end 346 if eq m 1 347 ret 2 348 end 349 if ne get fwhd 4 2 350 ret 3 351 end 352 if ne get fwhd 5 1 353 ret 4 354 end 355 if ne get fwhd 6 1 356 ret 5 357 end 358 if ne fwh16 16 1 359 ret 6 360 end 361 if ne fwh16 18 243 362 ret 7 363 end 364 if ne fwh16 58 64 365 ret 8 366 end 367 n = fwh16 60 368 if eq n 0 369 ret 9 370 end 371 if gt n 256 372 ret 10 373 end 374 if ge fwh16 62 n 375 ret 11 376 end 377 if eq fwinb fwh64 40 mul n 64 flen 0 378 ret 12 379 end 380 put fwshn 0 n 381 r = fwrdsh fd fwh64 40 mul n 64 382 if ne r 0 383 ret 1000 384 end 385 ret 0 386 end 387 note checks 13..16 (C lines 139-154): string table, then every section header in order 388 fn fwchk2 fd int flen ulong to ulong 389 si = mul fwh16 62 64 390 so = fws64 add si 24 391 ss = fws64 add si 32 392 if eq ss 0 393 ret 13 394 end 395 if eq fwinb so ss flen 0 396 ret 13 397 end 398 if gt ss FWSTMX 399 ret 29 400 end 401 r = fwrdst fd so ss 402 if ne r 0 403 ret 1000 404 end 405 if ne get fwst sub ss 1 0 406 ret 14 407 end 408 put fwstn 0 ss 409 ret fwsecs flen 410 end 411 note C lines 145-154: every section header in order; records each before checking the next 412 fn fwsecs flen ulong to ulong 413 for i ulong get fwshn 0 414 b = mul i 64 415 nm = fws32 b 416 ty = fws32 add b 4 417 of = fws64 add b 24 418 sz = fws64 add b 32 419 if ge nm get fwstn 0 420 ret 15 421 end 422 if ne ty 8 423 if gt sz 0 424 if eq fwinb of sz flen 0 425 ret 16 426 end 427 end 428 end 429 k = get fwnsec 0 430 put fwsn k nm 431 put fwsty k ty 432 put fwsof k of 433 put fwssz k sz 434 put fwnsec 0 add k 1 435 end 436 ret 0 437 end 438 note checks 17..22 (C lines 155-168): the strcmp chain, last match wins 439 fn fwchk3 to ulong 440 put fwimx 0 FWNONE 441 put fwvx 0 FWNONE 442 put fwbx 0 FWNONE 443 put fwsx 0 FWNONE 444 for i ulong get fwnsec 0 445 o = get fwsn i 446 if eq fwnmeq o 47 1 447 put fwimx 0 i 448 else 449 if eq fwnmeq o 48 1 450 put fwvx 0 i 451 else 452 if eq fwnmeq o 49 1 453 put fwbx 0 i 454 else 455 if eq fwnmeq o 50 1 456 put fwsx 0 i 457 end 458 end 459 end 460 end 461 end 462 x = get fwimx 0 463 if eq x FWNONE 464 ret 17 465 end 466 if eq get fwsty x 8 467 ret 18 468 end 469 if eq get fwssz x 0 470 ret 18 471 end 472 if eq get fwvx 0 FWNONE 473 ret 19 474 end 475 if eq get fwbx 0 FWNONE 476 ret 20 477 end 478 x = get fwsx 0 479 if eq x FWNONE 480 ret 21 481 end 482 if eq get fwsty x 8 483 ret 22 484 end 485 if eq get fwssz x 0 486 ret 22 487 end 488 ret 0 489 end 490 note checks 23..25 (C lines 170-175): .fwversion size, NUL, equality with the pin "580.173.02" 491 fn fwchk4 fd int to ulong 492 x = get fwvx 0 493 sz = get fwssz x 494 if eq get fwsty x 8 495 ret 23 496 end 497 if eq sz 0 498 ret 23 499 end 500 if ge sz 64 501 ret 23 502 end 503 r = fwrdbf fd get fwsof x sz 504 if ne r 0 505 ret 1000 506 end 507 if ne get fwbuf sub sz 1 0 508 ret 24 509 end 510 n = ulong 0 511 while lt n sz bound 64 512 if eq get fwbuf n 0 513 break 514 end 515 put fwver n get fwbuf n 516 n = add n 1 517 end 518 put fwvern 0 n 519 if ne sz add get fwsgl 51 1 520 ret 25 521 end 522 b = get fwsgb 51 523 for i ulong get fwsgl 51 524 if ne get fwbuf i get FWTXT add b i 525 ret 25 526 end 527 end 528 ret 0 529 end 530 note checks 26..28 (C lines 177-185): the NT_GNU_BUILD_ID note, then its hex 531 fn fwchk5 fd int to ulong 532 x = get fwbx 0 533 sz = get fwssz x 534 if eq get fwsty x 8 535 ret 26 536 end 537 if lt sz 16 538 ret 26 539 end 540 n = sz 541 if gt n 80 542 n = 80 543 end 544 r = fwrdbf fd get fwsof x n 545 if ne r 0 546 ret 1000 547 end 548 m = ulong 0 549 if ne fwb32 0 4 550 m = 1 551 end 552 note "GNU\0" = 71 78 85 0 553 if ne get fwbuf 12 71 554 m = 1 555 end 556 if ne get fwbuf 13 78 557 m = 1 558 end 559 if ne get fwbuf 14 85 560 m = 1 561 end 562 if ne get fwbuf 15 0 563 m = 1 564 end 565 if ne fwb32 8 3 566 m = 1 567 end 568 if eq m 1 569 ret 27 570 end 571 d = fwb32 4 572 if eq d 0 573 ret 28 574 end 575 if gt d 64 576 ret 28 577 end 578 if gt add 16 d sz 579 ret 28 580 end 581 fwbidhx d 582 ret 0 583 end 584 note lowercase hex of the d note descriptor bytes fwbuf[16..16+d) into fwbidh (C hex) 585 fn fwbidhx d ulong to void 586 for i ulong d 587 c = get fwbuf add 16 i 588 put fwbidh mul i 2 get FWHEXD shr c 4 589 put fwbidh add mul i 2 1 get FWHEXD and c 15 590 end 591 put fwbidn 0 mul d 2 592 end 593 note the three SHA-256 digests as lowercase hex in fwhxf / fwhxi / fwhxs; 0 or 1000 on an I/O error 594 fn fwdig fd int flen ulong to ulong 595 sh2init 0 596 sh2init 1 597 sh2init 2 598 r = sh2file 0 fd 0 flen 599 if ne r 0 600 ret 1000 601 end 602 x = get fwimx 0 603 r = sh2file 1 fd get fwsof x get fwssz x 604 if ne r 0 605 ret 1000 606 end 607 x = get fwsx 0 608 r = sh2file 2 fd get fwsof x get fwssz x 609 if ne r 0 610 ret 1000 611 end 612 sh2fin 0 613 shhex 32 614 for i ulong 64 615 put fwhxf i get shhx i 616 end 617 sh2fin 1 618 shhex 32 619 for i ulong 64 620 put fwhxi i get shhx i 621 end 622 sh2fin 2 623 shhex 32 624 for i ulong 64 625 put fwhxs i get shhx i 626 end 627 ret 0 628 end 629 note all checks in the C order: 0 = every check passed, 1..29 = refusal reason, 1000 = I/O error 630 fn fwcheck fd int flen ulong to ulong 631 put fwnsec 0 0 632 put fwlen 0 flen 633 e = fwchk1 fd flen 634 if ne e 0 635 ret e 636 end 637 e = fwchk2 fd flen 638 if ne e 0 639 ret e 640 end 641 e = fwchk3 642 if ne e 0 643 ret e 644 end 645 e = fwchk4 fd 646 if ne e 0 647 ret e 648 end 649 e = fwchk5 fd 650 if ne e 0 651 ret e 652 end 653 ret fwdig fd flen 654 end 655 note print the NUL-terminated name at fwst[off], or (null) when it is empty 656 fn fwoname off ulong to void 657 if eq get fwst off 0 658 fwos 38 659 ret 660 end 661 note the string table is NUL-terminated (check 14), so the name ends inside it; chunked for the 662 note 999999 bound (a name may run up to 16 MiB) 663 p = off 664 go = ulong 1 665 while eq go 1 bound 20 666 while ne get fwst p 0 bound 999999 667 fwoc get fwst p 668 p = add p 1 669 end 670 if eq get fwst p 0 671 go = 0 672 end 673 end 674 end 675 note C cmd_inspect + print_report for an open fd of flen bytes, path in fwpath[0..fwpathn). 676 note Returns 0 = RESULT OK, 2 = RESULT REFUSED, 1 = I/O error (the C prints "short read" on 677 note stderr and nothing on stdout; here the buffered file line is dropped and the caller reports). 678 fn fwinsp fd int flen ulong to ulong 679 fwsetup 680 mk = get fwon 0 681 fwos 30 682 fwopath 683 fwos 31 684 fwodec flen 685 fwos 32 686 fwos 52 687 fwos 33 688 fwos 51 689 fwoc 10 690 e = fwcheck fd flen 691 if eq e 1000 692 put fwon 0 mk 693 ret 1 694 end 695 for i ulong get fwnsec 0 696 fwos 34 697 fwodec i 698 fwoc 32 699 fwoname get fwsn i 700 fwos 35 701 fwodec get fwsty i 702 fwos 36 703 fwodec get fwsof i 704 fwos 37 705 fwodec get fwssz i 706 fwoc 10 707 end 708 if ne e 0 709 fwos 46 710 fwos e 711 fwoc 10 712 ret 2 713 end 714 fwos 39 715 for i ulong get fwvern 0 716 fwoc get fwver i 717 end 718 fwoc 10 719 fwos 40 720 for i ulong get fwbidn 0 721 fwoc get fwbidh i 722 end 723 fwoc 10 724 fwos 41 725 fwos 50 726 fwos 37 727 fwodec get fwssz get fwsx 0 728 fwoc 10 729 fwos 42 730 for i ulong 64 731 fwoc get fwhxf i 732 end 733 fwoc 10 734 fwos 43 735 for i ulong 64 736 fwoc get fwhxi i 737 end 738 fwos 37 739 fwodec get fwssz get fwimx 0 740 fwoc 10 741 fwos 44 742 for i ulong 64 743 fwoc get fwhxs i 744 end 745 fwoc 10 746 fwos 45 747 fwoc 10 748 ret 0 749 end