Skip to content

Commit

Permalink
drivers: stm32_bsec: fix timeouts initializations
Browse files Browse the repository at this point in the history
If OP-TEE is rescheduled right after the timeouts are initialized in
power_down_safmem() and power_up_safmem(), the timeout might be elapsed
when resuming the function. This would cause the while loop to break
instantly and there will be no delay between configuring the registers
and reading the status.

Initializes the timeout after configuring the registers.

Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Change-Id: Idd7e9151cdddb1db60e775f5b59ec5b8a1639815
Reviewed-on: https://gerrit.st.com/c/mpu/oe/optee/optee_os/+/312894
ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com>
ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
Reviewed-by: Etienne CARRIERE <etienne.carriere@foss.st.com>
Reviewed-by: Gatien CHEVALLIER <gatien.chevallier@st.com>
Tested-by: Gatien CHEVALLIER <gatien.chevallier@st.com>
Domain-Review: Gatien CHEVALLIER <gatien.chevallier@st.com>
  • Loading branch information
GseoC committed Jun 16, 2023
1 parent 9dee4e0 commit 6b37188
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions core/drivers/stm32_bsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,12 @@ static TEE_Result check_no_error(uint32_t otp_id, bool check_disturbed)

static TEE_Result power_up_safmem(void)
{
uint64_t timeout_ref = timeout_init_us(BSEC_TIMEOUT_US);
uint64_t timeout_ref = 0;

io_mask32(bsec_base() + BSEC_OTP_CONF_OFF, BSEC_CONF_POWER_UP_MASK,
BSEC_CONF_POWER_UP_MASK);

/*
* If a timeout is detected, test the condition again to consider
* cases where timeout is due to the executing TEE thread rescheduling.
*/
timeout_ref = timeout_init_us(BSEC_TIMEOUT_US);
while (!timeout_elapsed(timeout_ref))
if (bsec_status() & BSEC_MODE_PWR_MASK)
break;
Expand All @@ -238,14 +235,11 @@ static TEE_Result power_up_safmem(void)

static TEE_Result power_down_safmem(void)
{
uint64_t timeout_ref = timeout_init_us(BSEC_TIMEOUT_US);
uint64_t timeout_ref = 0;

io_mask32(bsec_base() + BSEC_OTP_CONF_OFF, 0, BSEC_CONF_POWER_UP_MASK);

/*
* If a timeout is detected, test the condition again to consider
* cases where timeout is due to the executing TEE thread rescheduling.
*/
timeout_ref = timeout_init_us(BSEC_TIMEOUT_US);
while (!timeout_elapsed(timeout_ref))
if (!(bsec_status() & BSEC_MODE_PWR_MASK))
break;
Expand Down

0 comments on commit 6b37188

Please sign in to comment.