Bugfix: firmware sizes must align with flash erase unit (4k)

(cherry picked from commit 5393e924ba)
This commit is contained in:
Peter D. Gray 2023-09-08 22:06:38 +02:00 committed by doc-hex
parent ecb4804c2f
commit c6d6adcf4e
4 changed files with 14 additions and 5 deletions

View File

@ -293,8 +293,12 @@ def doit(keydir, outfn=None, build_dir=None, high_water=False,
# bugfix: size must be non-page aligned, so extra bytes are erased past end
if (body_len % 4096) == 0:
body_len += 512
assert body_len % 512 == 0, body_len
assert body_len % 512 == 0, body_len
else:
# bugfix: PSRAM-based products (Mk4, Q1) need to erase 4k blocks, so
# trouble happens if final binary isn't aligned to that size.
body_len = align_to(body_len, 4096)
assert body_len % 4096 == 0, body_len
# pad out
vectors = pad_to(vectors, FW_HEADER_OFFSET)

View File

@ -1,3 +1,7 @@
## 5.1.4 - 2023-09-08
- Bugfix: Most users would see a red light after upgrade to 5.1.3 from 5.1.2. Fixed.
## 5.1.3 - 2023-09-07
- New Feature: Batch sign multiple PSBT files. `Advanced/Tools -> File Management -> Batch Sign PSBT`

View File

@ -335,7 +335,7 @@ psram_do_upgrade(const uint8_t *start, uint32_t size)
if(dest % FLASH_ERASE_SIZE == 0) {
// page erase as we go
rv = flash_page_erase(dest);
#if 1
#if 0
if(rv) {
puts2("erase rv=");
puthex2(rv);
@ -347,7 +347,7 @@ psram_do_upgrade(const uint8_t *start, uint32_t size)
memcpy(&tmp, start+pos, 8);
rv = flash_burn(dest, tmp);
#if 1
#if 0
if(rv) {
puts2("burn rv=");
puthex2(rv);

View File

@ -102,7 +102,8 @@ checksum_flash(uint8_t fw_digest[32], uint8_t world_digest[32], uint32_t fw_leng
const uint8_t *base = (const uint8_t *)BL_FLASH_BASE;
checksum_more(&ctx, &total_len, base, ((uint8_t *)MCU_KEYS)-base);
// Probably-blank area after firmware, and filesystem area
// Probably-blank area after firmware, and filesystem area.
// Important: firmware images (fw_length) must be aligned with flash erase unit size (4k).
const uint8_t *fs = start + fw_length;
const uint8_t *last = base + MAIN_FLASH_SIZE;
checksum_more(&ctx, &total_len, fs, last-fs);