interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / driver / fwprep.om

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