From c89cd36f194f6549094ef25cb25a2ff6c3413689 Mon Sep 17 00:00:00 2001 From: TT Date: Sun, 23 Feb 2020 11:36:05 +0900 Subject: [PATCH] fix: checksum --- flash.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flash.c b/flash.c index ee63668..79ab95e 100644 --- a/flash.c +++ b/flash.c @@ -64,7 +64,7 @@ void flash_unlock(void) FLASH->KEYR = 0xCDEF89AB; } -#define rotate(x) ((x<<1) | (x&(1<<31)?1:0)) +#define rotate(x) (((x)<<1) | ((x)&(1<<31)?1:0)) static uint32_t checksum(const void *start, size_t len) @@ -73,7 +73,7 @@ checksum(const void *start, size_t len) uint32_t *tail = (uint32_t*)(start + len); uint32_t value = 0; while (p < tail) - value = rotate(value) | *p++; + value = rotate(value) + *p++; return value; } @@ -142,8 +142,7 @@ caldata_save(int id) dst = (uint16_t*)saveareas[id]; current_props.magic = CONFIG_MAGIC; - current_props.checksum = 0; - current_props.checksum = checksum(¤t_props, sizeof current_props); + current_props.checksum = checksum(¤t_props, sizeof current_props - sizeof current_props.checksum); flash_unlock();