Skip to content

Commit d11accc

Browse files
authored
Merge pull request #473 from dgarske/swap_tail_type
Fix for error dereferencing type-punned pointer in update_flash.c `wolfBoot_swap_and_final_erase`
2 parents b3f3b53 + 64f3a39 commit d11accc

File tree

10 files changed

+86
-88
lines changed

10 files changed

+86
-88
lines changed

IDE/Renesas/e2studio/RA6M4/Readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ Application Entry Address: 0x00010200
229229
Magic: WOLF
230230
Version: 01
231231
Status: FF
232-
Tail Mgc:
232+
Trailer Magic:
233233

234234
=== Update Partition[00080000] ===
235235
Magic:
236236
Version: 00
237237
Status: FF
238-
Tail Mgc:
238+
Trailer Magic:
239239
Current Firmware Version : 1
240240

241241
Calling wolfBoot_success()
@@ -250,16 +250,16 @@ Called wolfBoot_success()
250250
Magic: WOLF
251251
Version: 01
252252
Status: 00
253-
Tail Mgc: BOOT
253+
Trailer Magic: BOOT
254254

255255
=== Update Partition[00080000] ===
256256
Magic:
257257
Version: 00
258258
Status: FF
259-
Tail Mgc:
259+
Trailer Magic:
260260
```
261261
262-
You can see the state is Success("00") and Tail Magic number becomes "BOOT".
262+
You can see the state is Success("00") and Trailer Magic number becomes "BOOT".
263263
You can also see flashing each LED light in 1 second. Notable things about V1 application,
264264
it will also call wolfBoot_update_trigger() so that it tells wolfBoot that new version exists.
265265
We are going to generate and download V2 application into "Update partition".
@@ -302,13 +302,13 @@ Application Entry Address: 0x00010200
302302
Magic: WOLF
303303
Version: 02
304304
Status: 00
305-
Tail Mgc: BOOT
305+
Trailer Magic: BOOT
306306

307307
=== Update Partition[00080000] ===
308308
Magic: WOLF
309309
Version: 01
310310
Status: FF
311-
Tail Mgc:
311+
Trailer Magic:
312312
Current Firmware Version : 2
313313

314314
Calling wolfBoot_success()
@@ -317,14 +317,14 @@ Called wolfBoot_success()
317317
Magic: WOLF
318318
Version: 02
319319
Status: 00
320-
Tail Mgc: BOOT
320+
Trailer Magic: BOOT
321321

322322
=== Update Partition[00080000] ===
323323
Magic: WOLF
324324
Version: 01
325325
Status: FF
326-
Tail Mgc:
326+
Trailer Magic:
327327
```
328328
329-
You can see "Current Firmware Version : 2". The state is Success("00") and Tail Magic number becomes "BOOT".
329+
You can see "Current Firmware Version : 2". The state is Success("00") and Tailer Magic number becomes "BOOT".
330330
You can also see flashing each LED light in 5 second at this new version.

IDE/Renesas/e2studio/RA6M4/Readme_wSCE.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ Application Entry Address: 0x00020200
247247
Magic: WOLF
248248
Version: 01
249249
Status: FF
250-
Tail Mgc:
250+
Trailer Magic:
251251

252252
=== Update Partition[00090000] ===
253253
Magic:
254254
Version: 00
255255
Status: FF
256-
Tail Mgc:
256+
Trailer Magic:
257257
Current Firmware Version : 1
258258

259259
Calling wolfBoot_success()
@@ -269,16 +269,16 @@ Called wolfBoot_success()
269269
Magic: WOLF
270270
Version: 01
271271
Status: 00
272-
Tail Mgc: BOOT
272+
Trailer Magic: BOOT
273273

274274
=== Update Partition[00090000] ===
275275
Magic:
276276
Version: 00
277277
Status: FF
278-
Tail Mgc:
278+
Trailer Magic:
279279
```
280280
281-
You can see the state is Success("00") and Tail Magic number becomes "BOOT".
281+
You can see the state is Success("00") and Trailer Magic number becomes "BOOT".
282282
You can also see flashing each LED light in 1 second. Notable things about V1 application,
283283
it will also call wolfBoot_update_trigger() so that it tells wolfBoot that new version exists.
284284
We are going to generate and download V2 application into "Update partition".
@@ -318,13 +318,13 @@ Application Entry Address: 0x00020200
318318
Magic: WOLF
319319
Version: 02
320320
Status: 10
321-
Tail Mgc: BOOT
321+
Trailer Magic: BOOT
322322

323323
=== Update Partition[00090000] ===
324324
Magic: WOLF
325325
Version: 01
326326
Status: FF
327-
Tail Mgc:
327+
Trailer Magic:
328328
Current Firmware Version : 2
329329

330330
Calling wolfBoot_success()
@@ -333,13 +333,13 @@ Called wolfBoot_success()
333333
Magic: WOLF
334334
Version: 02
335335
Status: 00
336-
Tail Mgc: BOOT
336+
Trailer Magic: BOOT
337337

338338
=== Update Partition[00090000] ===
339339
Magic: WOLF
340340
Version: 01
341341
Status: 70
342-
Tail Mgc: BOOT
342+
Trailer Magic: BOOT
343343
```
344-
You can see "Current Firmware Version : 2". The state is Success("00") and Tail Magic number becomes "BOOT".
344+
You can see "Current Firmware Version : 2". The state is Success("00") and Trailer Magic number becomes "BOOT".
345345
You can also see flashing each LED light in 5 second at this new version.

IDE/Renesas/e2studio/RA6M4/app_RA/src/app_RA.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void blink(int interval)
4040

4141
/* LED type structure */
4242
bsp_leds_t leds = g_bsp_leds;
43-
43+
4444
#if BSP_TZ_SECURE_BUILD
4545

4646
/* Enter non-secure code */
@@ -59,8 +59,8 @@ static void blink(int interval)
5959
{
6060
/* Enable access to the PFS registers */
6161
R_BSP_PinAccessEnable();
62-
63-
62+
63+
6464
/* Update each LEDs*/
6565
for (uint32_t i = 0; i < leds.led_count; i++)
6666
{
@@ -69,18 +69,18 @@ static void blink(int interval)
6969

7070
/* Write to this pin */
7171
R_BSP_PinWrite((bsp_io_port_pin_t) pin, pin_level);
72-
72+
7373
/* Delay */
7474
R_BSP_SoftwareDelay(delay, bsp_delay_units);
7575
}
76-
76+
7777
/* Protect PFS registers */
7878
R_BSP_PinAccessDisable();
7979

8080
/* Toggle level for next write */
8181
if (BSP_IO_LEVEL_LOW == pin_level) {
8282
pin_level = BSP_IO_LEVEL_HIGH;
83-
}
83+
}
8484
else {
8585
pin_level = BSP_IO_LEVEL_LOW;
8686
}
@@ -104,7 +104,7 @@ static void printPart(uint8_t *part)
104104
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
105105
myprintf("Status: %02x\n", state);
106106
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
107-
myprintf("Tail Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
107+
myprintf("Trailer Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
108108

109109
#ifdef WOLFBOOT_DEBUG_PARTION
110110
v = (uint32_t *)part;

IDE/Renesas/e2studio/RX72N/Readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ application V1.
211211
Magic: WOLF
212212
Version: 01
213213
Status: ff (New)
214-
Tail Mgc: ����
214+
Trailer Magic: ����
215215
216216
=== Update Partition[ffdf8000] ===
217217
Magic: ����
218218
Version: 00
219219
Status: ff (New)
220-
Tail Mgc: ����
220+
Trailer Magic: ����
221221
222222
Current Firmware Version: 1
223223
Hit any key to call wolfBoot_success the firmware.
@@ -231,13 +231,13 @@ state and wait for any key again.
231231
Magic: WOLF
232232
Version: 01
233233
Status: 00 (Success)
234-
Tail Mgc: BOOT
234+
Trailer Magic: BOOT
235235
236236
=== Update Partition[ffdf8000] ===
237237
Magic: ����
238238
Version: 00
239239
Status: 00 (Success)
240-
Tail Mgc: BOOT
240+
Trailer Magic: BOOT
241241
242242
```
243243
You can see the state is Success("00").
@@ -280,13 +280,13 @@ Firmware Update is triggered
280280
Magic: WOLF
281281
Version: 01
282282
Status: 00 (Success)
283-
Tail Mgc: BOOT
283+
Trailer Magic: BOOT
284284
285285
=== Update Partition[ffdf8000] ===
286286
Magic: ����
287287
Version: 00
288288
Status: 70 (Updating)
289-
Tail Mgc: BOOT
289+
Trailer Magic: BOOT
290290
```
291291

292292
Since this is just a trigger, the application can continue the process.
@@ -309,13 +309,13 @@ information.
309309
Magic: WOLF
310310
Version: 02
311311
Status: 10
312-
Tail Mgc: BOOT
312+
Trailer Magic: BOOT
313313
314314
=== Update Partition[ffdf8000] ===
315315
Magic: WOLF
316316
Version: 01
317317
Status: 30
318-
Tail Mgc: BOOT
318+
Trailer Magic: BOOT
319319
320320
Current Firmware Version: 2
321321
```

IDE/Renesas/e2studio/RX72N/Readme_withTSIP.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ application V1.
270270
Magic: WOLF
271271
Version: 01
272272
Status: ff
273-
Tail Mgc: ����
273+
Trailer Magic: ����
274274
275275
=== Update Partition[ffe20000] ===
276276
Magic: WOLF
277277
Version: 02
278278
Status: ff
279-
Tail Mgc: ����
279+
Trailer Magic: ����
280280
281281
Current Firmware Version: 1
282282
Hit any key to call wolfBoot_success the firmware.
@@ -294,13 +294,13 @@ You can see the state is Success("00").
294294
Magic: WOLF
295295
Version: 01
296296
Status: 00
297-
Tail Mgc: BOOT
297+
Trailer Magic: BOOT
298298
299299
=== Update Partition[ffe20000] ===
300300
Magic: WOLF
301301
Version: 02
302302
Status: ff
303-
Tail Mgc: ����
303+
Trailer Magic: ����
304304
305305
Hit any key to update the firmware.
306306
```
@@ -361,13 +361,13 @@ information.
361361
Magic: WOLF
362362
Version: 02
363363
Status: 10
364-
Tail Mgc: BOOT
364+
Trailer Magic: BOOT
365365
366366
=== Update Partition[ffe20000] ===
367367
Magic: ����
368368
Version: 00
369369
Status: ff
370-
Tail Mgc: ����
370+
Trailer Magic: ����
371371
372372
Current Firmware Version: 2
373373
```

IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void printPart(uint8_t *part)
5656
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
5757
printf("Status: %02x (%s)\n", state,state2str(state));
5858
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
59-
printf("Tail Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
59+
printf("Trailer Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
6060

6161
#ifdef WOLFBOOT_DEBUG_PARTION
6262
v = (uint32_t *)part;

docs/Targets.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,13 +2074,13 @@ wolfBoot HAL Init
20742074
Magic: WOLF
20752075
Version: 01
20762076
Status: ff (New)
2077-
Tail Mgc: ˇˇˇˇ
2077+
Trailer Magic: ˇˇˇˇ
20782078

20792079
=== Update Partition[ffef0000] ===
20802080
Magic: ˇˇˇˇ
20812081
Version: 00
20822082
Status: ff (New)
2083-
Tail Mgc: ˇˇˇˇ
2083+
Trailer Magic: ˇˇˇˇ
20842084

20852085
Current Firmware Version: 1
20862086
Hit any key to call wolfBoot_success the firmware.
@@ -2189,13 +2189,13 @@ wolfBoot HAL Init
21892189
Magic: WOLF
21902190
Version: 01
21912191
Status: ff (New)
2192-
Tail Mgc: ˇˇˇˇ
2192+
Trailer Magic: ˇˇˇˇ
21932193
21942194
=== Update Partition[ffdf0000] ===
21952195
Magic: ˇˇˇˇ
21962196
Version: 00
21972197
Status: ff (New)
2198-
Tail Mgc: ˇˇˇˇ
2198+
Trailer Magic: ˇˇˇˇ
21992199
22002200
Current Firmware Version: 1
22012201
Hit any key to call wolfBoot_success the firmware.

src/libwolfboot.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len
17651765
int i;
17661766
int flash_read_size;
17671767
int read_remaining = len;
1768-
int unaligned_head_size, unaligned_tail_size;
1768+
int unaligned_head_size, unaligned_trailer_size;
17691769
uint8_t part;
17701770
uintptr_t base_address;
17711771

@@ -1817,8 +1817,8 @@ int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len
18171817
iv_counter++;
18181818
}
18191819
/* Trim the read size to align with the Encryption Blocks. Read the
1820-
* remaining unaligned tail bytes after, since the `data` buffer won't have
1821-
* enough space to handle the extra bytes.
1820+
* remaining unaligned trailer bytes after, since the `data` buffer won't
1821+
* have enough space to handle the extra bytes.
18221822
*/
18231823
flash_read_size = read_remaining & ~(ENCRYPT_BLOCK_SIZE - 1);
18241824
if (ext_flash_read(address, data, flash_read_size) != flash_read_size)
@@ -1835,17 +1835,17 @@ int RAMFUNCTION ext_flash_decrypt_read(uintptr_t address, uint8_t *data, int len
18351835
data += flash_read_size;
18361836
read_remaining -= flash_read_size;
18371837

1838-
/* Read the unaligned tail bytes. */
1839-
unaligned_tail_size = read_remaining;
1840-
if (unaligned_tail_size > 0)
1838+
/* Read the unaligned trailer bytes. */
1839+
unaligned_trailer_size = read_remaining;
1840+
if (unaligned_trailer_size > 0)
18411841
{
18421842
uint8_t dec_block[ENCRYPT_BLOCK_SIZE];
18431843
if (ext_flash_read(address, block, ENCRYPT_BLOCK_SIZE)
18441844
!= ENCRYPT_BLOCK_SIZE)
18451845
return -1;
18461846
crypto_decrypt(dec_block, block, ENCRYPT_BLOCK_SIZE);
1847-
XMEMCPY(data, dec_block, unaligned_tail_size);
1848-
read_remaining -= unaligned_tail_size;
1847+
XMEMCPY(data, dec_block, unaligned_trailer_size);
1848+
read_remaining -= unaligned_trailer_size;
18491849
}
18501850
return (len - read_remaining);
18511851
}

0 commit comments

Comments
 (0)