blob: fd977ac2fd40db5d3ad11379b24fa42f52f4c2f3 [file] [log] [blame]
Andrew Geisslerdc9d6142023-05-19 09:38:37 -05001From 83e423497afecc202a3a50c3e472161390056ebd Mon Sep 17 00:00:00 2001
2From: Emekcan Aras <emekcan.aras@arm.com>
3Date: Mon, 15 May 2023 10:47:27 +0100
4Subject: [PATCH 4/4] Platform: Corstone1000: Calculate the new CRC32 value
5 after changing the metadata
6
7Calculates the new CRC32 value for the metadata struct after chaing a value
8during the capsule update. It also updates the CRC32 field in the metadata
9so it doesn't fail the CRC check after a succesfull capsule update.
10It also skips doing a sanity check the BL2 nv counter after the capsule
11update since the tfm bl1 does not sync metadata and nv counters in OTP during
12the boot anymore.
13
14Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
15Upstream-Status: Pending [Not submitted to upstream yet]
16---
17 .../arm/corstone1000/fw_update_agent/fwu_agent.c | 10 +++++++---
18 1 file changed, 7 insertions(+), 3 deletions(-)
19
20diff --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
21index afd8d66e42..f564f2902c 100644
22--- a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c
23+++ b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c
24@@ -802,6 +802,8 @@ static enum fwu_agent_error_t flash_full_capsule(
25 }
26 metadata->active_index = previous_active_index;
27 metadata->previous_active_index = active_index;
28+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
29+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
30
31 ret = metadata_write(metadata);
32 if (ret) {
33@@ -913,6 +915,8 @@ static enum fwu_agent_error_t accept_full_capsule(
34 if (ret) {
35 return ret;
36 }
37+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
38+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
39
40 ret = metadata_write(metadata);
41 if (ret) {
42@@ -1007,6 +1011,8 @@ static enum fwu_agent_error_t fwu_select_previous(
43 if (ret) {
44 return ret;
45 }
46+ metadata->crc_32 = crc32((uint8_t *)&metadata->version,
47+ sizeof(struct fwu_metadata) - sizeof(uint32_t));
48
49 ret = metadata_write(metadata);
50 if (ret) {
51@@ -1119,8 +1125,7 @@ static enum fwu_agent_error_t update_nv_counters(
52
53 FWU_LOG_MSG("%s: enter\n\r", __func__);
54
55- for (int i = 0; i <= FWU_MAX_NV_COUNTER_INDEX; i++) {
56-
57+ for (int i = 1; i <= FWU_MAX_NV_COUNTER_INDEX; i++) {
58 switch (i) {
59 case FWU_BL2_NV_COUNTER:
60 tfm_nv_counter_i = PLAT_NV_COUNTER_BL1_0;
61@@ -1141,7 +1146,6 @@ static enum fwu_agent_error_t update_nv_counters(
62 if (err != TFM_PLAT_ERR_SUCCESS) {
63 return FWU_AGENT_ERROR;
64 }
65-
66 if (priv_metadata->nv_counter[i] < security_cnt) {
67 return FWU_AGENT_ERROR;
68 } else if (priv_metadata->nv_counter[i] > security_cnt) {
69--
702.17.1
71