diff --git a/include/HFlashServer.h b/include/HFlashServer.h index 2c52880..83f2668 100644 --- a/include/HFlashServer.h +++ b/include/HFlashServer.h @@ -63,7 +63,7 @@ #define HFLASH_SYNC_PAGE_INFO_TIME 800 #endif -///< 同步备份页表信息时间ms +///< 同步备份和备份页表信息时间ms #ifndef HFLASH_SYNC_BACKUP_TIME #define HFLASH_SYNC_BACKUP_TIME 1000 #endif diff --git a/src/HFlashMem.c b/src/HFlashMem.c index a5bf592..c41cf33 100644 --- a/src/HFlashMem.c +++ b/src/HFlashMem.c @@ -101,16 +101,18 @@ static void CheckSyncCache() uint16_t needErase = sInfo.useNum; uint8_t heat = MAX_HEAT; + uint8_t waitWrite = 0; for (uint16_t i = 0; i < sInfo.useNum; ++i) { // 检查哪个页的异步擦除, 现在擦除完成 if (sOpts->cache[i].eraseStatus == kEraseStart) { sOpts->cache[i].eraseStatus = kWaitWrite; } + waitWrite |= sOpts->cache[i].isDirty; // 寻找需要擦除的页 if (sOpts->cache[i].isDirty && sOpts->cache[i].eraseStatus == kEraseWait) { // 查找最低热度的优先擦除 - if (sOpts->cache[i].heat < heat) { + if (sOpts->cache[i].heat <= heat) { heat = sOpts->cache[i].heat; needErase = i; } @@ -137,7 +139,7 @@ static void CheckSyncCache() sOpts->ioctl(sOpts->cache[needErase].addr, kHFlashMemIOErase, NULL); } - if (sInfo.needWaitErase == 0) { + if (sInfo.needWaitErase == 0 && waitWrite == 0) { if (sCheckTimer != HTIMER_INVALID) { HTimerRemove(sCheckTimer); sCheckTimer = HTIMER_INVALID; @@ -160,7 +162,7 @@ static HFlashMemCache *FindCache(uint32_t addr, uint8_t create, uint8_t needRead addr = Align4K(addr); if (addr + HFLASH_BLOCK_SIZE > sOpts->flashSize) { LogE("flash addr[0x%08x] size[%d] overflow", addr, sOpts->flashSize); - return 0; + return NULL; } for (uint16_t i = 0; i < sInfo.useNum; ++i) { @@ -308,7 +310,7 @@ void HFlashMemInit(HFlashMemOpts *opts) return ; } - if (IS_4K(sOpts->flashSize) == 0) { + if (sOpts->flashSize == 0 || IS_4K(sOpts->flashSize) == 0) { FATAL_ERROR("flash Size not 4k align"); return ; } diff --git a/src/HFlashServer.c b/src/HFlashServer.c index 65a5fed..988c9f1 100644 --- a/src/HFlashServer.c +++ b/src/HFlashServer.c @@ -679,6 +679,11 @@ static uint8_t IsOverLap(HFlashAddr_t srcAddr, uint32_t size, HFlashAddr_t dstAd return 1; } + if (srcAddr == dstAddr) { + FATAL_ERROR("addr[0x%08x] dstAddr[%d] overflow", srcAddr, dstAddr); + return 1; + } + // 非重叠 if (srcEnd <= dstAddr || dstEnd <= srcAddr) { return 0;