blob: fd977ac2fd40db5d3ad11379b24fa42f52f4c2f3 [file] [log] [blame]
From 83e423497afecc202a3a50c3e472161390056ebd Mon Sep 17 00:00:00 2001
From: Emekcan Aras <emekcan.aras@arm.com>
Date: Mon, 15 May 2023 10:47:27 +0100
Subject: [PATCH 4/4] Platform: Corstone1000: Calculate the new CRC32 value
after changing the metadata
Calculates the new CRC32 value for the metadata struct after chaing a value
during the capsule update. It also updates the CRC32 field in the metadata
so it doesn't fail the CRC check after a succesfull capsule update.
It also skips doing a sanity check the BL2 nv counter after the capsule
update since the tfm bl1 does not sync metadata and nv counters in OTP during
the boot anymore.
Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
Upstream-Status: Pending [Not submitted to upstream yet]
---
.../arm/corstone1000/fw_update_agent/fwu_agent.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c
index afd8d66e42..f564f2902c 100644
--- a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c
+++ b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c
@@ -802,6 +802,8 @@ static enum fwu_agent_error_t flash_full_capsule(
}
metadata->active_index = previous_active_index;
metadata->previous_active_index = active_index;
+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
ret = metadata_write(metadata);
if (ret) {
@@ -913,6 +915,8 @@ static enum fwu_agent_error_t accept_full_capsule(
if (ret) {
return ret;
}
+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
ret = metadata_write(metadata);
if (ret) {
@@ -1007,6 +1011,8 @@ static enum fwu_agent_error_t fwu_select_previous(
if (ret) {
return ret;
}
+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
ret = metadata_write(metadata);
if (ret) {
@@ -1119,8 +1125,7 @@ static enum fwu_agent_error_t update_nv_counters(
FWU_LOG_MSG("%s: enter\n\r", __func__);
- for (int i = 0; i <= FWU_MAX_NV_COUNTER_INDEX; i++) {
-
+ for (int i = 1; i <= FWU_MAX_NV_COUNTER_INDEX; i++) {
switch (i) {
case FWU_BL2_NV_COUNTER:
tfm_nv_counter_i = PLAT_NV_COUNTER_BL1_0;
@@ -1141,7 +1146,6 @@ static enum fwu_agent_error_t update_nv_counters(
if (err != TFM_PLAT_ERR_SUCCESS) {
return FWU_AGENT_ERROR;
}
-
if (priv_metadata->nv_counter[i] < security_cnt) {
return FWU_AGENT_ERROR;
} else if (priv_metadata->nv_counter[i] > security_cnt) {
--
2.17.1