summaryrefslogtreecommitdiff
path: root/meta-arm/meta-arm-bsp/recipes-bsp/trusted-firmware-m/files/corstone1000/0003-Platform-Corstone1000-Calculate-the-new-CRC32-value-.patch
blob: bf7aba8de8bf35c18ff752a34b7eed49ac21fb96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From 88cfce2e04913d48ec8636b6a3550d71ebdd49c4 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] 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) {