@@ -167,16 +167,16 @@ impl FirmwareProcessor {
167167 // Load the manifest into DCCM.
168168 let manifest = Self :: load_manifest (
169169 & mut env. persistent_data ,
170- & mut txn,
170+ txn. as_deref_mut ( ) ,
171171 & mut env. soc_ifc ,
172172 & mut env. dma ,
173173 ) ;
174174 let manifest = okref ( & manifest) ?;
175175
176- let image_source = if env. soc_ifc . subsystem_mode ( ) {
177- caliptra_common:: verifier:: ImageSource :: McuSram ( & env. dma )
178- } else {
176+ let image_source = if let Some ( ref txn) = txn {
179177 caliptra_common:: verifier:: ImageSource :: MboxMemory ( txn. raw_mailbox_contents ( ) )
178+ } else {
179+ caliptra_common:: verifier:: ImageSource :: McuSram ( & env. dma )
180180 } ;
181181 let mut venv = FirmwareImageVerificationEnv {
182182 sha256 : & mut env. sha256 ,
@@ -214,10 +214,12 @@ impl FirmwareProcessor {
214214 report_boot_status ( FwProcessorExtendPcrComplete . into ( ) ) ;
215215
216216 // Load the image
217- Self :: load_image ( manifest, & mut txn, & mut env. soc_ifc , & mut env. dma ) ?;
217+ Self :: load_image ( manifest, txn. as_deref_mut ( ) , & mut env. soc_ifc , & mut env. dma ) ?;
218218
219219 // Complete the mailbox transaction indicating success.
220- txn. complete ( true ) ?;
220+ if let Some ( ref mut txn) = txn {
221+ txn. complete ( true ) ?;
222+ }
221223
222224 report_boot_status ( FwProcessorFirmwareDownloadTxComplete . into ( ) ) ;
223225
@@ -253,22 +255,24 @@ impl FirmwareProcessor {
253255 /// * `persistent_data` - Persistent data
254256 ///
255257 /// # Returns
256- /// * `MailboxRecvTxn` - Mailbox Receive Transaction
258+ /// * `Option<MailboxRecvTxn>` - Mailbox Receive Transaction (Some in passive mode, None in subsystem mode)
259+ /// * `u32` - Image size in bytes
257260 ///
258- /// Mailbox transaction handle (returned only for the FIRMWARE_LOAD command).
261+ /// In passive mode, the mailbox transaction handle is returned for the FIRMWARE_LOAD command.
262+ /// In subsystem mode, firmware is loaded via the recovery interface and None is returned.
259263 /// This transaction is ManuallyDrop because we don't want the transaction
260264 /// to be completed with failure until after handle_fatal_error is called.
261265 /// This prevents a race condition where the SoC reads FW_ERROR_NON_FATAL
262266 /// immediately after the mailbox transaction fails,
263- /// but before caliptra has set the FW_ERROR_NON_FATAL register.
267+ /// but before caliptra has set the FW_ERROR_NON_FATAL register.
264268 fn process_mailbox_commands < ' a > (
265269 soc_ifc : & mut SocIfc ,
266270 mbox : & ' a mut Mailbox ,
267271 pcr_bank : & mut PcrBank ,
268272 dma : & mut Dma ,
269273 env : & mut KatsEnv ,
270274 persistent_data : & mut PersistentData ,
271- ) -> CaliptraResult < ( ManuallyDrop < MailboxRecvTxn < ' a > > , u32 ) > {
275+ ) -> CaliptraResult < ( Option < ManuallyDrop < MailboxRecvTxn < ' a > > > , u32 ) > {
272276 let mut self_test_in_progress = false ;
273277 let subsystem_mode = soc_ifc. subsystem_mode ( ) ;
274278
@@ -312,7 +316,7 @@ impl FirmwareProcessor {
312316
313317 cprintln ! ( "[fwproc] Received Image of size {} bytes" , image_size_bytes) ;
314318 report_boot_status ( FwProcessorDownloadImageComplete . into ( ) ) ;
315- return Ok ( ( txn, image_size_bytes) ) ;
319+ return Ok ( ( Some ( txn) , image_size_bytes) ) ;
316320 }
317321
318322 // Handle RI_DOWNLOAD_FIRMWARE as a separate case since it needs mutable access to mbox
@@ -331,9 +335,8 @@ impl FirmwareProcessor {
331335 }
332336 cfi_assert_bool ( subsystem_mode) ;
333337
334- // Complete the command indicating success first, before accessing mbox again
338+ // Complete the command indicating success
335339 cprintln ! ( "[fwproc] Completing RI_DOWNLOAD_FIRMWARE command" ) ;
336- // Re-borrow mailbox to work around https://github.com/rust-lang/rust/issues/54663
337340 let txn = mbox
338341 . peek_recv ( )
339342 . ok_or ( CaliptraError :: FW_PROC_MAILBOX_STATE_INCONSISTENT ) ?;
@@ -343,10 +346,7 @@ impl FirmwareProcessor {
343346 drop ( txn) ;
344347
345348 // Now we can access mbox again since the transaction is complete
346- return Ok ( (
347- ManuallyDrop :: new ( mbox. recovery_recv_txn ( ) ) ,
348- RiDownloadFirmwareCmd :: execute ( dma, soc_ifc) ?,
349- ) ) ;
349+ return Ok ( ( None , RiDownloadFirmwareCmd :: execute ( dma, soc_ifc) ?) ) ;
350350 }
351351
352352 // NOTE: We use ManuallyDrop here because any error here becomes a fatal error
@@ -502,20 +502,27 @@ impl FirmwareProcessor {
502502
503503 /// Load the manifest
504504 ///
505+ /// # Arguments
506+ ///
507+ /// * `persistent_data` - Persistent data accessor
508+ /// * `txn` - Mailbox transaction (Some in passive mode, None in subsystem mode)
509+ /// * `soc_ifc` - SoC Interface
510+ /// * `dma` - DMA engine
511+ ///
505512 /// # Returns
506513 ///
507514 /// * `Manifest` - Caliptra Image Bundle Manifest
508515 #[ cfg_attr( not( feature = "no-cfi" ) , cfi_impl_fn) ]
509516 fn load_manifest (
510517 persistent_data : & mut PersistentDataAccessor ,
511- txn : & mut MailboxRecvTxn ,
518+ txn : Option < & mut MailboxRecvTxn > ,
512519 soc_ifc : & mut SocIfc ,
513520 dma : & mut Dma ,
514521 ) -> CaliptraResult < ImageManifest > {
515- if soc_ifc. subsystem_mode ( ) {
516- Self :: load_manifest_from_mcu ( persistent_data, soc_ifc, dma)
517- } else {
522+ if let Some ( txn) = txn {
518523 Self :: load_manifest_from_mbox ( persistent_data, txn)
524+ } else {
525+ Self :: load_manifest_from_mcu ( persistent_data, soc_ifc, dma)
519526 }
520527 }
521528
@@ -775,7 +782,7 @@ impl FirmwareProcessor {
775782 /// # Arguments
776783 ///
777784 /// * `manifest` - Manifest
778- /// * `txn` - Mailbox Receive Transaction
785+ /// * `txn` - Mailbox Receive Transaction (Some in passive mode, None in subsystem mode)
779786 /// * `soc_ifc` - SoC Interface
780787 /// * `dma` - DMA engine
781788 ///
@@ -784,14 +791,14 @@ impl FirmwareProcessor {
784791 #[ cfg_attr( not( feature = "no-cfi" ) , cfi_impl_fn) ]
785792 fn load_image (
786793 manifest : & ImageManifest ,
787- txn : & mut MailboxRecvTxn ,
794+ txn : Option < & mut MailboxRecvTxn > ,
788795 soc_ifc : & mut SocIfc ,
789796 dma : & mut Dma ,
790797 ) -> CaliptraResult < ( ) > {
791- if soc_ifc. subsystem_mode ( ) {
792- Self :: load_image_from_mcu ( manifest, soc_ifc, dma)
793- } else {
798+ if let Some ( txn) = txn {
794799 Self :: load_image_from_mbox ( manifest, txn)
800+ } else {
801+ Self :: load_image_from_mcu ( manifest, soc_ifc, dma)
795802 }
796803 }
797804
0 commit comments