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