Minimal bootable disk image builder
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add ocaml-initramfs package, use it in space and uniboot

Extract initramfs building into a standalone package with Dir, File, and
Tree entry types. Replaces duplicated cpio logic in space/lib/build.ml
and uniboot/lib/uniboot.ml.

+7 -56
+1 -1
dune-project
··· 27 27 (gpt (>= 0.1)) 28 28 (mbr (>= 0.1)) 29 29 (squashfs (>= 0.1)) 30 - (cpio (>= 0.1)) 30 + (initramfs (>= 0.1)) 31 31 (cmdliner (>= 1.2)) 32 32 (fmt (>= 0.9)) 33 33 (logs (>= 0.7))
+1 -1
lib/dune
··· 1 1 (library 2 2 (name uniboot) 3 3 (public_name uniboot) 4 - (libraries bytesrw gpt mbr squashfs cpio fmt logs uuidm unix)) 4 + (libraries bytesrw gpt mbr squashfs initramfs fmt logs uuidm unix))
+4 -53
lib/uniboot.ml
··· 142 142 Log.info (fun m -> 143 143 m "Building initramfs from %d paths" (List.length paths)); 144 144 let entries = 145 - List.concat_map 145 + List.map 146 146 (fun path -> 147 - if Sys.is_directory path then begin 148 - (* Add directory and its contents recursively *) 149 - let entries = ref [] in 150 - let rec walk prefix dir = 151 - let items = Sys.readdir dir |> Array.to_list in 152 - List.iter 153 - (fun name -> 154 - let full = Filename.concat dir name in 155 - let cpio_name = Filename.concat prefix name in 156 - if Sys.is_directory full then begin 157 - entries := 158 - Cpio.directory ~perm:0o755 cpio_name :: !entries; 159 - walk cpio_name full 160 - end 161 - else 162 - let data = 163 - let ic = open_in_bin full in 164 - let len = in_channel_length ic in 165 - let s = Bytes.create len in 166 - really_input ic s 0 len; 167 - close_in ic; 168 - Bytes.unsafe_to_string s 169 - in 170 - let perm = 171 - let st = Unix.stat full in 172 - st.Unix.st_perm 173 - in 174 - entries := 175 - Cpio.regular ~perm ~name:cpio_name data :: !entries) 176 - items 177 - in 178 - let base = Filename.basename path in 179 - entries := Cpio.directory ~perm:0o755 base :: !entries; 180 - walk base path; 181 - List.rev !entries 182 - end 183 - else 184 - let data = 185 - let ic = open_in_bin path in 186 - let len = in_channel_length ic in 187 - let s = Bytes.create len in 188 - really_input ic s 0 len; 189 - close_in ic; 190 - Bytes.unsafe_to_string s 191 - in 192 - let name = Filename.basename path in 193 - let perm = 194 - let st = Unix.stat path in 195 - st.Unix.st_perm 196 - in 197 - [ Cpio.regular ~perm ~name data ]) 147 + if Sys.is_directory path then Initramfs.Tree path 148 + else Initramfs.File { name = Filename.basename path; path }) 198 149 paths 199 150 in 200 - let archive = Cpio.to_string entries in 151 + let archive = Initramfs.build entries in 201 152 let archive_len = String.length archive in 202 153 Log.info (fun m -> 203 154 m "Initramfs: %d entries, %d bytes" (List.length entries) archive_len);
+1 -1
uniboot.opam
··· 17 17 "gpt" {>= "0.1"} 18 18 "mbr" {>= "0.1"} 19 19 "squashfs" {>= "0.1"} 20 - "cpio" {>= "0.1"} 20 + "initramfs" {>= "0.1"} 21 21 "cmdliner" {>= "1.2"} 22 22 "fmt" {>= "0.9"} 23 23 "logs" {>= "0.7"}