@@ -209,26 +209,20 @@ def repair(self, cur_os):
209209 else :
210210 logging .info ("'asahi' dir not found in ESP" )
211211
212- def install_files (self , cur_os ):
213- logging .info ("StubInstaller.install_files()" )
214- logging .info (f"VGID: { self .osi .vgid } " )
215- logging .info (f"OS info: { self .osi } " )
216-
217- p_progress ("Beginning stub OS install..." )
212+ def load_identity (self ):
218213 self .get_paths ()
219214
220215 logging .info ("Parsing metadata..." )
221216
222- sysver = plistlib .load (self .open ("SystemVersion.plist" ))
223217 manifest = plistlib .load (self .open ("BuildManifest.plist" ))
224- bootcaches = plistlib .load (self .open ("usr/standalone/bootcaches.plist" ))
218+ self . bootcaches = plistlib .load (self .open ("usr/standalone/bootcaches.plist" ))
225219 self .flush_progress ()
226220
227221 if self .is_ota :
228- variant = "macOS Customer Software Update"
222+ self . variant = "macOS Customer Software Update"
229223 behavior = "Update"
230224 else :
231- variant = "macOS Customer"
225+ self . variant = "macOS Customer"
232226 behavior = "Erase"
233227
234228 self .manifest = manifest
@@ -237,7 +231,7 @@ def install_files(self, cur_os):
237231 identity ["ApChipID" ] != f'0x{ self .sysinfo .chip_id :04X} ' or
238232 identity ["Info" ]["DeviceClass" ] != self .sysinfo .device_class or
239233 identity ["Info" ]["RestoreBehavior" ] != behavior or
240- identity ["Info" ]["Variant" ] != variant ):
234+ identity ["Info" ]["Variant" ] != self . variant ):
241235 continue
242236 break
243237 else :
@@ -248,6 +242,16 @@ def install_files(self, cur_os):
248242 self .all_identities = manifest ["BuildIdentities" ]
249243 self .identity = identity
250244 manifest ["BuildIdentities" ] = [identity ]
245+ return identity
246+
247+ def install_files (self , cur_os ):
248+ logging .info ("StubInstaller.install_files()" )
249+ logging .info (f"VGID: { self .osi .vgid } " )
250+ logging .info (f"OS info: { self .osi } " )
251+
252+ p_progress ("Beginning stub OS install..." )
253+ identity = self .load_identity ()
254+ sysver = plistlib .load (self .open ("SystemVersion.plist" ))
251255
252256 self .stub_info .update ({
253257 "vgid" : self .osi .vgid ,
@@ -292,13 +296,13 @@ def install_files(self, cur_os):
292296
293297 os .makedirs (self .pb_vgid , exist_ok = True )
294298
295- bless2 = bootcaches ["bless2" ]
299+ bless2 = self . bootcaches ["bless2" ]
296300
297301 restore_bundle = os .path .join (self .pb_vgid , bless2 ["RestoreBundlePath" ])
298302 os .makedirs (restore_bundle , exist_ok = True )
299303 restore_manifest = os .path .join (restore_bundle , "BuildManifest.plist" )
300304 with open (restore_manifest , "wb" ) as fd :
301- plistlib .dump (manifest , fd )
305+ plistlib .dump (self . manifest , fd )
302306 self .copy_idata .append ((restore_manifest , "BuildManifest.plist" ))
303307 self .extract ("SystemVersion.plist" , restore_bundle )
304308 self .extract ("RestoreVersion.plist" , restore_bundle )
@@ -311,10 +315,9 @@ def install_files(self, cur_os):
311315 self .extract_file ("BootabilityBundle/Restore/Firmware/Bootability.dmg.trustcache" ,
312316 os .path .join (restore_bundle , "Bootability/Bootability.trustcache" ))
313317
314- self .extract_tree (f"Firmware/Manifests/restore/{ variant } /" , restore_bundle )
318+ self .extract_tree (f"Firmware/Manifests/restore/{ self . variant } /" , restore_bundle )
315319
316320 copied = set ()
317- self .kernel_path = None
318321 for key , val in identity ["Manifest" ].items ():
319322 if key in ("BaseSystem" , "OS" , "Ap,SystemVolumeCanonicalMetadata" ,
320323 "RestoreRamDisk" , "RestoreTrustCache" ):
@@ -328,8 +331,6 @@ def install_files(self, cur_os):
328331 if path .startswith ("kernelcache." ):
329332 name = os .path .basename (path )
330333 self .copy_idata .append ((os .path .join (restore_bundle , name ), name ))
331- if self .kernel_path is None :
332- self .kernel_path = os .path .join (restore_bundle , name )
333334 copied .add (path )
334335
335336 self .flush_progress ()
@@ -404,7 +405,10 @@ def collect_firmware(self, pkg):
404405 shutil .rmtree ("fud_firmware" )
405406
406407 os .makedirs ("fud_firmware" , exist_ok = True )
408+ bless2 = self .bootcaches ["bless2" ]
409+ restore_bundle = os .path .join (self .pb_vgid , bless2 ["RestoreBundlePath" ])
407410 copied = set ()
411+ kernel_path = None
408412 for identity in [self .identity ]:
409413 if (identity ["Info" ]["RestoreBehavior" ] != "Erase" or
410414 identity ["Info" ]["Variant" ] != "macOS Customer" ):
@@ -419,6 +423,10 @@ def collect_firmware(self, pkg):
419423 "StaticTrustCache" , "SystemVolume" ):
420424 continue
421425 path = val ["Info" ]["Path" ]
426+ if path .startswith ("kernelcache." ):
427+ name = os .path .basename (path )
428+ if kernel_path is None :
429+ kernel_path = os .path .join (restore_bundle , name )
422430 if (not val ["Info" ].get ("IsFUDFirmware" , False )
423431 or val ["Info" ].get ("IsLoadedByiBoot" , False )
424432 or val ["Info" ].get ("IsLoadedByiBootStage1" , False )
@@ -450,7 +458,7 @@ def collect_firmware(self, pkg):
450458 col = ISPFWCollection ("recovery/usr/sbin/" )
451459 pkg .add_files (sorted (col .files ()))
452460 logging .info ("Collecting Kernel firmware" )
453- col = KernelFWCollection (self . kernel_path )
461+ col = KernelFWCollection (kernel_path )
454462 pkg .add_files (sorted (col .files ()))
455463 logging .info ("Making fallback firmware archive" )
456464 subprocess .run (["tar" , "czf" , "all_firmware.tar.gz" ,
0 commit comments