Browse Source

only verify checksum after upgrades

Thomas Buck 1 year ago
parent
commit
27b51989ba
1 changed files with 5 additions and 5 deletions
  1. 5
    5
      main.c

+ 5
- 5
main.c View File

421
 };
421
 };
422
 static_assert(sizeof(struct image_header) == FLASH_PAGE_SIZE, "image_header must be FLASH_PAGE_SIZE bytes");
422
 static_assert(sizeof(struct image_header) == FLASH_PAGE_SIZE, "image_header must be FLASH_PAGE_SIZE bytes");
423
 
423
 
424
-static bool image_header_ok(struct image_header *hdr)
424
+static bool image_header_ok(struct image_header *hdr, bool check_crc)
425
 {
425
 {
426
 	uint32_t *vtor = (uint32_t *)hdr->vtor;
426
 	uint32_t *vtor = (uint32_t *)hdr->vtor;
427
 
427
 
428
 	uint32_t calc = calc_crc32((void *)hdr->vtor, hdr->size);
428
 	uint32_t calc = calc_crc32((void *)hdr->vtor, hdr->size);
429
 
429
 
430
-	// CRC has to match
431
-	if (calc != hdr->crc) {
430
+	// CRC has to match after flashing
431
+	if (check_crc && (calc != hdr->crc)) {
432
 		return false;
432
 		return false;
433
 	}
433
 	}
434
 
434
 
465
 		return TCP_COMM_RSP_ERR;
465
 		return TCP_COMM_RSP_ERR;
466
 	}
466
 	}
467
 
467
 
468
-	if (!image_header_ok(&hdr)) {
468
+	if (!image_header_ok(&hdr, true)) {
469
 		return TCP_COMM_RSP_ERR;
469
 		return TCP_COMM_RSP_ERR;
470
 	}
470
 	}
471
 
471
 
684
 
684
 
685
 	sleep_ms(10);
685
 	sleep_ms(10);
686
 
686
 
687
-	if (!should_stay_in_bootloader() && image_header_ok(&app_image_header)) {
687
+	if (!should_stay_in_bootloader() && image_header_ok(&app_image_header, false)) {
688
 		uint32_t vtor = *(uint32_t *)IMAGE_HEADER_ADDR;
688
 		uint32_t vtor = *(uint32_t *)IMAGE_HEADER_ADDR;
689
 		disable_interrupts();
689
 		disable_interrupts();
690
 		reset_peripherals();
690
 		reset_peripherals();

Loading…
Cancel
Save