diff --git a/Src/StorageOnFlashFlagchip.c b/Src/StorageOnFlashFlagchip.c index e3f8357..f5bd017 100644 --- a/Src/StorageOnFlashFlagchip.c +++ b/Src/StorageOnFlashFlagchip.c @@ -97,18 +97,17 @@ static uint8_t xStorageOnFlashFlagchip_Dump(tStorageOnFlashFlagchip *env, void * eStorageStatus xStorageOnFlashFlagchip_Load(tStorageOnFlashFlagchip *env, void *data, size_t size) { - size = size - 8; - size_t dataSizeOnFlash = size;//(size + 3) & (~3); // выравниваем до кратного 4 (целое количество слов) + size_t offset_crc = size - 8; - uint32_t recoveryCrcCalc = xStorageOnFlashArtery_CrcFlash((uint8_t *) env->recoveryFlashPageAddress, size); - uint32_t recoveryCrcReed = iInternalFlashPage_ReadWord(env->recoveryFlashPageAddress + dataSizeOnFlash); + uint32_t recoveryCrcCalc = xStorageOnFlashArtery_CrcFlash((uint8_t *) env->recoveryFlashPageAddress, offset_crc); + uint32_t recoveryCrcReed = iInternalFlashPage_ReadWord(env->recoveryFlashPageAddress + offset_crc); LoggerFormatInfo(LOGGER, LOG_SIGN, "Crc recovery page (calc): 0x%08X", recoveryCrcCalc) LoggerFormatInfo(LOGGER, LOG_SIGN, "Crc recovery page (flash): 0x%08X", recoveryCrcReed) - uint32_t mainCrcCalc = xStorageOnFlashArtery_CrcFlash((uint8_t *) env->mainFlashPageAddress, size); - uint32_t mainCrcReed = iInternalFlashPage_ReadWord(env->mainFlashPageAddress + dataSizeOnFlash); + uint32_t mainCrcCalc = xStorageOnFlashArtery_CrcFlash((uint8_t *) env->mainFlashPageAddress, offset_crc); + uint32_t mainCrcReed = iInternalFlashPage_ReadWord(env->mainFlashPageAddress + offset_crc); LoggerFormatInfo(LOGGER, LOG_SIGN, "Crc main page (calc): 0x%08X", mainCrcCalc) LoggerFormatInfo(LOGGER, LOG_SIGN, "Crc main page (flash): 0x%08X", mainCrcReed) @@ -118,22 +117,22 @@ eStorageStatus xStorageOnFlashFlagchip_Load(tStorageOnFlashFlagchip *env, void * if (recoveryCrcOk && mainCrcOk) { if (recoveryCrcReed == mainCrcReed) { - sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, size); + sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc); return STORAGE_OK; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Data recovery main page (main page <- recovery) ") - sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, size); - return xStorageOnFlashFlagchip_DumpOn(env, recoveryCrcCalc, env->mainFlashPageAddress, data, size); + sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, offset_crc); + return xStorageOnFlashFlagchip_DumpOn(env, recoveryCrcCalc, env->mainFlashPageAddress, data, offset_crc); } } else if (recoveryCrcOk || mainCrcOk) { if (recoveryCrcOk) { LoggerInfoStatic(LOGGER, LOG_SIGN, "Data recovery main page (main page <- recovery)") - sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, size); - return xStorageOnFlashFlagchip_DumpOn(env, recoveryCrcCalc, env->mainFlashPageAddress, data, size); + sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, offset_crc); + return xStorageOnFlashFlagchip_DumpOn(env, recoveryCrcCalc, env->mainFlashPageAddress, data, offset_crc); } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Data recovery recovery page (main page -> recovery)") - sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, size); - return xStorageOnFlashFlagchip_DumpOn(env, mainCrcCalc, env->recoveryFlashPageAddress, data, size); + sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc); + return xStorageOnFlashFlagchip_DumpOn(env, mainCrcCalc, env->recoveryFlashPageAddress, data, offset_crc); } } else { return STORAGE_ERR_DATA;