Skip to content

Commit 731a1a2

Browse files
committed
Set PROD_DBG_UNLOCK_IN_PROGRESS bit in runtime handle_request() to match ROM behavior
1 parent 8a58d6c commit 731a1a2

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

runtime/src/debug_unlock.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ProductionDebugUnlock {
5252
pub fn handle_request(
5353
&mut self,
5454
trng: &mut caliptra_drivers::Trng,
55-
soc_ifc: &caliptra_drivers::SocIfc,
55+
soc_ifc: &mut caliptra_drivers::SocIfc,
5656
dma: &mut caliptra_drivers::Dma,
5757
cmd_bytes: &[u8],
5858
resp: &mut [u8],
@@ -73,20 +73,32 @@ impl ProductionDebugUnlock {
7373
return Err(CaliptraError::RUNTIME_DEBUG_UNLOCK_INVALID_LIFECYCLE);
7474
}
7575

76-
// Use common function to create challenge
77-
let challenge =
78-
caliptra_common::debug_unlock::create_debug_unlock_challenge(trng, soc_ifc, dma, &req)?;
76+
// Set debug unlock in progress
77+
soc_ifc.set_ss_dbg_unlock_in_progress(true);
78+
79+
let result = (|| -> CaliptraResult<usize> {
80+
// Use common function to create challenge
81+
let challenge = caliptra_common::debug_unlock::create_debug_unlock_challenge(
82+
trng, soc_ifc, dma, &req,
83+
)?;
84+
85+
// Store the challenge for future token validation
86+
let stored_challenge = challenge.clone();
87+
self.last_challenge = Some(stored_challenge);
88+
self.last_request = Some(req);
7989

80-
// Store the challenge for future token validation
81-
let stored_challenge = challenge.clone();
82-
self.last_challenge = Some(stored_challenge);
83-
self.last_request = Some(req);
90+
cprintln!("[rt] Production debug unlock challenge generated");
8491

85-
cprintln!("[rt] Production debug unlock challenge generated");
92+
let resp = mutrefbytes::<ProductionAuthDebugUnlockChallenge>(resp)?;
93+
*resp = challenge;
94+
Ok(core::mem::size_of::<ProductionAuthDebugUnlockChallenge>())
95+
})();
8696

87-
let resp = mutrefbytes::<ProductionAuthDebugUnlockChallenge>(resp)?;
88-
*resp = challenge;
89-
Ok(core::mem::size_of::<ProductionAuthDebugUnlockChallenge>())
97+
if result.is_err() {
98+
soc_ifc.set_ss_dbg_unlock_in_progress(false);
99+
}
100+
101+
result
90102
}
91103

92104
/// Handle the production debug unlock token verification
@@ -127,9 +139,6 @@ impl ProductionDebugUnlock {
127139
.take()
128140
.ok_or(CaliptraError::RUNTIME_DEBUG_UNLOCK_NO_REQUEST)?;
129141

130-
// Set debug unlock in progress
131-
soc_ifc.set_ss_dbg_unlock_in_progress(true);
132-
133142
// Use the common validation logic
134143
let result = caliptra_common::debug_unlock::validate_debug_unlock_token(
135144
soc_ifc,

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fn execute_command(
543543
}
544544
CommandId::PRODUCTION_AUTH_DEBUG_UNLOCK_REQ => drivers.debug_unlock.handle_request(
545545
&mut drivers.trng,
546-
&drivers.soc_ifc,
546+
&mut drivers.soc_ifc,
547547
&mut drivers.dma,
548548
cmd_bytes,
549549
resp,

runtime/tests/runtime_integration_tests/test_debug_unlock.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ fn test_dbg_unlock_prod_success() {
166166
.unwrap()
167167
.unwrap();
168168

169+
// Verify in_progress bit is set after REQUEST completes
170+
assert!(model
171+
.soc_ifc()
172+
.ss_dbg_service_reg_rsp()
173+
.read()
174+
.prod_dbg_unlock_in_progress());
175+
169176
let challenge = ProductionAuthDebugUnlockChallenge::read_from_bytes(resp.as_slice()).unwrap();
170177
let reserved = [0u8; 3];
171178

0 commit comments

Comments
 (0)