@@ -384,7 +384,8 @@ static rom_error_t rom_ext_boot(boot_data_t *boot_data,
384384
385385OT_WARN_UNUSED_RESULT
386386static rom_error_t boot_svc_next_boot_bl0_slot_handler (
387- boot_svc_msg_t * boot_svc_msg , boot_data_t * boot_data ) {
387+ boot_svc_msg_t * boot_svc_msg , boot_data_t * boot_data ,
388+ boot_log_t * boot_log ) {
388389 uint32_t active_slot = boot_data -> primary_bl0_slot ;
389390 uint32_t primary_slot = boot_svc_msg -> next_boot_bl0_slot_req .primary_bl0_slot ;
390391 rom_error_t error = kErrorOk ;
@@ -401,6 +402,8 @@ static rom_error_t boot_svc_next_boot_bl0_slot_handler(
401402 // Read the boot data back to ensure the correct slot is booted this
402403 // time.
403404 HARDENED_RETURN_IF_ERROR (boot_data_read (lc_state , boot_data ));
405+ // Update the boot log.
406+ boot_log -> primary_bl0_slot = boot_data -> primary_bl0_slot ;
404407 break ;
405408 case kBootSlotUnspecified :
406409 // Do nothing.
@@ -487,7 +490,8 @@ static rom_error_t boot_svc_min_sec_ver_handler(boot_svc_msg_t *boot_svc_msg,
487490}
488491
489492OT_WARN_UNUSED_RESULT
490- static rom_error_t handle_boot_svc (boot_data_t * boot_data ) {
493+ static rom_error_t handle_boot_svc (boot_data_t * boot_data ,
494+ boot_log_t * boot_log ) {
491495 boot_svc_msg_t * boot_svc_msg = & retention_sram_get ()-> creator .boot_svc_msg ;
492496 // TODO(lowRISC#22387): Examine the boot_svc code paths for boot loops.
493497 if (boot_svc_msg -> header .identifier == kBootSvcIdentifier ) {
@@ -500,7 +504,8 @@ static rom_error_t handle_boot_svc(boot_data_t *boot_data) {
500504 break ;
501505 case kBootSvcNextBl0SlotReqType :
502506 HARDENED_CHECK_EQ (msg_type , kBootSvcNextBl0SlotReqType );
503- return boot_svc_next_boot_bl0_slot_handler (boot_svc_msg , boot_data );
507+ return boot_svc_next_boot_bl0_slot_handler (boot_svc_msg , boot_data ,
508+ boot_log );
504509 case kBootSvcMinBl0SecVerReqType :
505510 HARDENED_CHECK_EQ (msg_type , kBootSvcMinBl0SecVerReqType );
506511 return boot_svc_min_sec_ver_handler (boot_svc_msg , boot_data );
@@ -582,6 +587,10 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
582587 boot_log -> rom_ext_major = self -> version_major ;
583588 boot_log -> rom_ext_minor = self -> version_minor ;
584589 boot_log -> rom_ext_size = CHIP_ROM_EXT_SIZE_MAX ;
590+ // Even though `primary_bl0_slot` can be changed by boot svc, we initialize
591+ // it here so the "SetNextBl0" can do a one-time override of the RAM copy
592+ // of `boot_data`.
593+ boot_log -> primary_bl0_slot = boot_data -> primary_bl0_slot ;
585594
586595 // Initialize the chip ownership state.
587596 rom_error_t error ;
@@ -602,7 +611,7 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
602611 uint32_t reset_reasons = retention_sram_get ()-> creator .reset_reasons ;
603612 uint32_t skip_boot_svc = reset_reasons & (1 << kRstmgrReasonLowPowerExit );
604613 if (skip_boot_svc == 0 ) {
605- error = handle_boot_svc (boot_data );
614+ error = handle_boot_svc (boot_data , boot_log );
606615 if (error == kErrorWriteBootdataThenReboot ) {
607616 // Boot services reports errors by writing a status code into the reply
608617 // messages. Regardless of whether a boot service request produced an
@@ -618,7 +627,6 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
618627 boot_log -> ownership_transfers = boot_data -> ownership_transfers ;
619628 boot_log -> rom_ext_min_sec_ver = boot_data -> min_security_version_rom_ext ;
620629 boot_log -> bl0_min_sec_ver = boot_data -> min_security_version_bl0 ;
621- boot_log -> primary_bl0_slot = boot_data -> primary_bl0_slot ;
622630 boot_log_digest_update (boot_log );
623631
624632 if (uart_break_detect (kRescueDetectTime ) == kHardenedBoolTrue ) {
0 commit comments