Commit 5684525
committed
Fix corruption of last boot sector with encryption
As reported by @reza-hdd in #589:
> When Firmware is large enough to consume all the allocated boot partition sectors, in the the final swap and erase operations (_wolfBoot_swap_and_final_erase_) the last sector of FW in Boot partition, which is used as a temporary sector for a copy operation, gets corrupted after being copied in external Swap partition and copied back. It looks like the contents are copied to the external Swap partition without being encrypted, but get decrypted when it is read back.
This was due to the function wolfBoot_copy_sector() assuming that all
copies having an external SWAP as destination would not need any
encryption, as the "normal" case during update is to copy already
encrypted sectors from UPDATE->SWAP.
In the final state, after the update is successfully applied, the
mechanism saves a copy of the last sector from BOOT->SWAP. In this case,
if the application is big enough, an extra function is needed to
encrypt the content of this last sector before writing it to SWAP.
Restoring the backup is OK (normal case SWAP->BOOT, decryption was
already there as also noted by the reporter).1 parent 3801b49 commit 5684525
3 files changed
+92
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
410 | 411 | | |
411 | 412 | | |
412 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
76 | 89 | | |
77 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
78 | 97 | | |
79 | 98 | | |
80 | 99 | | |
| |||
1039 | 1058 | | |
1040 | 1059 | | |
1041 | 1060 | | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
| 1061 | + | |
| 1062 | + | |
1045 | 1063 | | |
1046 | 1064 | | |
1047 | 1065 | | |
| |||
1073 | 1091 | | |
1074 | 1092 | | |
1075 | 1093 | | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
| 1094 | + | |
| 1095 | + | |
1079 | 1096 | | |
1080 | 1097 | | |
1081 | 1098 | | |
| |||
1111 | 1128 | | |
1112 | 1129 | | |
1113 | 1130 | | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
| 1131 | + | |
| 1132 | + | |
1117 | 1133 | | |
1118 | 1134 | | |
1119 | 1135 | | |
| |||
1790 | 1806 | | |
1791 | 1807 | | |
1792 | 1808 | | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
1797 | 1812 | | |
1798 | 1813 | | |
1799 | 1814 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
155 | 159 | | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
202 | 207 | | |
203 | 208 | | |
204 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
205 | 260 | | |
206 | 261 | | |
207 | 262 | | |
| |||
293 | 348 | | |
294 | 349 | | |
295 | 350 | | |
296 | | - | |
| 351 | + | |
| 352 | + | |
297 | 353 | | |
298 | 354 | | |
299 | 355 | | |
300 | 356 | | |
| 357 | + | |
301 | 358 | | |
302 | 359 | | |
303 | 360 | | |
| |||
321 | 378 | | |
322 | 379 | | |
323 | 380 | | |
| 381 | + | |
324 | 382 | | |
325 | 383 | | |
326 | 384 | | |
| |||
461 | 519 | | |
462 | 520 | | |
463 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
464 | 526 | | |
465 | 527 | | |
466 | 528 | | |
| |||
0 commit comments