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 / aienux / disk / pack_bundle.om

191 lines · 3718 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/disk/pack_bundle.om: Pure-Omega offline GspFwBundle (OMFWBND1) packer.
3note Packs local 0700 fwprep.om gb20b outputs (gsp_ga10x.bin, bl.img, fmc.img, fmc.hash,
4note fmc.pubkey, fmc.sig, bl_desc, optional weights) into one 4 KiB-aligned image with
5note 4 KiB TOC + per-entry SHA-256 digests. ZERO firmware bytes ever committed to git.
6note Compose: cat aienux/disk/sha256_bare.om aienux/disk/pack_bundle.om | omc > pack_bundle
7note Usage: pack_bundle OUTFILE APP_VER KIND1 FILE1 [KIND2 FILE2 ... up to 8 entries]
8
9global pb_arg uchar 512
10global pb_toc uchar 4096
11global pb_buf uchar 65536
12global pb_zero uchar 4096
13global pb_kind ulong 8
14global pb_off ulong 8
15global pb_sz ulong 8
16global pb_sha uchar 256
17global pb_stat uchar 144
18
19fn pb_w32 off ulong v ulong to void
20put pb_toc off uchar and v 255
21put pb_toc add off 1 uchar and shr v 8 255
22put pb_toc add off 2 uchar and shr v 16 255
23put pb_toc add off 3 uchar and shr v 24 255
24end
25
26fn pb_w64 off ulong v ulong to void
27pb_w32 off and v 4294967295
28pb_w32 add off 4 shr v 32
29end
30
31fn pb_getarg idx ulong to ulong
32n = argread idx pb_arg 0 511
33if lt n 1
34exit 2
35end
36put pb_arg ulong n 0
37ret ulong n
38end
39
40fn pb_parse_u64 n ulong to ulong
41if or eq n 0 gt n 20
42exit 2
43end
44v = ulong 0
45i = ulong 0
46while lt i n bound 20
47c = ulong get pb_arg i
48if or lt c 48 gt c 57
49exit 2
50end
51d = sub c 48
52if gt v 1844674407370955161
53exit 2
54end
55if eq v 1844674407370955161
56if gt d 5
57exit 2
58end
59end
60v = add mul v 10 d
61i = add i 1
62end
63ret v
64end
65
66fn pb_write_all fd int n ulong is_toc ulong is_zero ulong to void
67p = ulong 0
68while lt p n bound 999999
69r = long 0
70if ne is_toc 0
71r = write fd pb_toc p sub n p
72else
73if ne is_zero 0
74r = write fd pb_zero p sub n p
75else
76r = write fd pb_buf p sub n p
77end
78end
79if le r 0
80exit 5
81end
82p = add p ulong r
83end
84end
85
86fn pb_pack_entry ofd int idx ulong cur_off ulong to ulong
87kn = pb_getarg add 3 mul idx 2
88put pb_kind idx pb_parse_u64 kn
89fn_len = pb_getarg add 4 mul idx 2
90ifd = fopen pb_arg 0 fn_len 0 0
91if lt ifd 0
92exit 4
93end
94put pb_off idx cur_off
95s256_init
96tot = ulong 0
97while true bound 9223372036854775807
98rd = read int ifd pb_buf 0 65536
99if lt rd 0
100exit 4
101end
102if eq rd 0
103break
104end
105rn = ulong rd
106k = ulong 0
107while lt k rn bound 65536
108s256_byte get pb_buf k
109k = add k 1
110end
111pb_write_all ofd rn 0 0
112tot = add tot rn
113end
114z = fclose int ifd
115s256_fin
116put pb_sz idx tot
117for s ulong 32
118put pb_sha add mul idx 32 s get s2_out s
119end
120cur_off = add cur_off tot
121pad = rem sub 4096 rem cur_off 4096 4096
122if ne pad 0
123pb_write_all ofd pad 0 1
124cur_off = add cur_off pad
125end
126ret cur_off
127end
128
129fn pb_write_toc ofd int app_ver ulong nent ulong to void
130put pb_toc 0 79
131put pb_toc 1 77
132put pb_toc 2 70
133put pb_toc 3 87
134put pb_toc 4 66
135put pb_toc 5 78
136put pb_toc 6 68
137put pb_toc 7 49
138pb_w32 8 1
139pb_w32 12 app_ver
140pb_w32 16 nent
141pb_w32 20 0
142idx2 = ulong 0
143while lt idx2 nent bound 8
144eo = add 32 mul idx2 64
145pb_w32 eo get pb_kind idx2
146pb_w32 add eo 4 0
147pb_w64 add eo 8 get pb_off idx2
148pb_w64 add eo 16 get pb_sz idx2
149pb_w64 add eo 24 0
150for s2 ulong 32
151put pb_toc add add eo 32 s2 get pb_sha add mul idx2 32 s2
152end
153idx2 = add idx2 1
154end
155p = ulong 0
156while lt p 4096 bound 4096
157r = pwrite ofd pb_toc p sub 4096 p long p
158if le r 0
159exit 6
160end
161p = add p ulong r
162end
163end
164
165fn main to int
166ac = argcnt
167if or lt ac 5 ne rem sub ac 3 2 0
168ret 2
169end
170nent = div ulong sub ac 3 2
171if or eq nent 0 gt nent 8
172ret 2
173end
174an = pb_getarg 2
175app_ver = pb_parse_u64 an
176on = pb_getarg 1
177ofd = fopen pb_arg 0 on 577 384
178if lt ofd 0
179ret 3
180end
181pb_write_all int ofd 4096 0 1
182cur_off = ulong 4096
183idx = ulong 0
184while lt idx nent bound 8
185cur_off = pb_pack_entry int ofd idx cur_off
186idx = add idx 1
187end
188pb_write_toc int ofd app_ver nent
189z2 = fclose int ofd
190ret 0
191end