@@ -172,7 +172,10 @@ def green(string):
172172 print (f"\n \033 [01;32m{ string } \033 [0m" , flush = True )
173173
174174
175- def prepare_initrd (architecture , rootfs_format = 'cpio' , gh_json_file = None ):
175+ def prepare_initrd (architecture ,
176+ rootfs_format = 'cpio' ,
177+ gh_json_file = None ,
178+ modules = None ):
176179 """
177180 Returns a decompressed initial ramdisk.
178181
@@ -228,6 +231,24 @@ def prepare_initrd(architecture, rootfs_format='cpio', gh_json_file=None):
228231 (dst := src .with_suffix ('' )).unlink (missing_ok = True )
229232 subprocess .run (['zstd' , '-d' , src , '-o' , dst , '-q' ], check = True )
230233
234+ if modules :
235+ # "new" cpio magic bytes
236+ cpio_sig = bytes ([0x30 , 0x37 , 0x30 , 0x37 , 0x30 , 0x31 ])
237+ with modules .open ('rb' ) as module_file :
238+ if module_file .read (6 ) != cpio_sig :
239+ raise RuntimeError (
240+ f"{ modules } does not have cpio magic bytes, was it generated with the 'modules-cpio-pkg' target?"
241+ )
242+
243+ (new_dst :=
244+ dst .parent .joinpath ('rootfs-modules.cpio' )).unlink (missing_ok = True )
245+ with subprocess .Popen (['cat' , dst , modules ],
246+ stdout = subprocess .PIPE ,
247+ stderr = subprocess .STDOUT ) as proc , new_dst .open (
248+ 'xb' ) as dst_file :
249+ dst_file .write (proc .stdout .read ())
250+ dst = new_dst
251+
231252 return dst
232253
233254
0 commit comments