1. 修复脏页检查问题

This commit is contained in:
coffee 2025-12-26 13:53:36 +08:00
parent a4795e62c9
commit 05e1e0557b
3 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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 ;
}

View File

@ -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;