Обновление
This commit is contained in:
parent
2fedb1f691
commit
796427dcf7
|
|
@ -9,14 +9,21 @@
|
|||
#include "StorageIO.h"
|
||||
#include "LoggerInterface.h"
|
||||
|
||||
typedef enum {
|
||||
STORAGE_TYPE_D_DATA,
|
||||
STORAGE_TYPE_P_DATA
|
||||
} eTypeStorageOnFlashFlagchip;
|
||||
|
||||
typedef struct {
|
||||
uint32_t mainFlashPageAddress;
|
||||
uint32_t recoveryFlashPageAddress;
|
||||
eTypeStorageOnFlashFlagchip TypeStorageOnFlashFlagchip;
|
||||
tLoggerInterface *logger;
|
||||
} tStorageOnFlashFlagchip;
|
||||
|
||||
void vStorageOnFlashFlagchip_Init(
|
||||
tStorageOnFlashFlagchip *env,
|
||||
eTypeStorageOnFlashFlagchip TypeStorageOnFlashFlagchip,
|
||||
uint32_t mainPage,
|
||||
uint32_t recoveryPage
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ static uint32_t xStorageOnFlashArtery_Crc(uint8_t *data, size_t len) {
|
|||
return crc;
|
||||
}
|
||||
|
||||
static uint32_t xStorageOnFlashArtery_CrcFlash(uint8_t *addressOnFlash, size_t len) {
|
||||
static uint32_t xStorageOnFlashArtery_CrcFlash(tStorageOnFlashFlagchip *env, uint8_t *addressOnFlash, size_t len) {
|
||||
uint32_t crc = 0;
|
||||
|
||||
size_t left = len;
|
||||
|
|
@ -27,7 +27,12 @@ static uint32_t xStorageOnFlashArtery_CrcFlash(uint8_t *addressOnFlash, size_t l
|
|||
|
||||
uint32_t word;
|
||||
while (addressOnFlash < end) {
|
||||
word = iInternalFlashPage_ReadWord((uint32_t) addressOnFlash);
|
||||
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
word = D_iInternalFlashPage_ReadWord((uint32_t) addressOnFlash);
|
||||
} else {
|
||||
word = P_iInternalFlashPage_ReadWord((uint32_t) addressOnFlash);
|
||||
}
|
||||
|
||||
for (uint8_t sub_byte = 0; (sub_byte < 4) && (left); ++sub_byte) {
|
||||
crc += ((uint8_t *) &word)[sub_byte];
|
||||
|
|
@ -54,19 +59,38 @@ xStorageOnFlashFlagchip_DumpOn(
|
|||
//
|
||||
// size_t dataSizeOnFlash = sInternalFlashPage_Write(pageAddress, 0x0, env->data, env->size);
|
||||
|
||||
size_t dataSizeOnFlash = bInternalFlashPage_DumpFromRam(pageAddress, data, size);
|
||||
size_t dataSizeOnFlash;
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
dataSizeOnFlash = D_bInternalFlashPage_DumpFromRam(pageAddress, data, size);
|
||||
} else {
|
||||
dataSizeOnFlash = P_bInternalFlashPage_DumpFromRam(pageAddress, data, size);
|
||||
}
|
||||
|
||||
if (dataSizeOnFlash < size) {
|
||||
return STORAGE_ERR_DEVICE;
|
||||
}
|
||||
|
||||
uint64_t dataCrc64 = dataCrc;
|
||||
if (sInternalFlashPage_Write(pageAddress, dataSizeOnFlash, (uint8_t *) &dataCrc64, 8) != 8) {
|
||||
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
if (D_sInternalFlashPage_Write(pageAddress, dataSizeOnFlash, (uint8_t *) &dataCrc64, 8) != 8) {
|
||||
return STORAGE_ERR_DEVICE;
|
||||
}
|
||||
} else {
|
||||
if (P_sInternalFlashPage_Write(pageAddress, dataSizeOnFlash, (uint8_t *) &dataCrc64, 8) != 8) {
|
||||
return STORAGE_ERR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t flashCalcCrc = xStorageOnFlashArtery_CrcFlash((uint8_t *) pageAddress, size );
|
||||
uint32_t flashReedCrc = iInternalFlashPage_ReadWord(pageAddress + dataSizeOnFlash);
|
||||
|
||||
uint32_t flashCalcCrc = xStorageOnFlashArtery_CrcFlash(env, (uint8_t *) pageAddress, size);
|
||||
|
||||
uint32_t flashReedCrc;
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
flashReedCrc = D_iInternalFlashPage_ReadWord(pageAddress + dataSizeOnFlash);
|
||||
} else {
|
||||
flashReedCrc = P_iInternalFlashPage_ReadWord(pageAddress + dataSizeOnFlash);
|
||||
}
|
||||
|
||||
if ((flashCalcCrc == flashReedCrc) && (flashCalcCrc == dataCrc)) {
|
||||
return STORAGE_OK;
|
||||
|
|
@ -100,14 +124,26 @@ eStorageStatus xStorageOnFlashFlagchip_Load(tStorageOnFlashFlagchip *env, void *
|
|||
|
||||
size_t offset_crc = size - 8;
|
||||
|
||||
uint32_t recoveryCrcCalc = xStorageOnFlashArtery_CrcFlash((uint8_t *) env->recoveryFlashPageAddress, offset_crc);
|
||||
uint32_t recoveryCrcReed = iInternalFlashPage_ReadWord(env->recoveryFlashPageAddress + offset_crc);
|
||||
uint32_t recoveryCrcCalc = xStorageOnFlashArtery_CrcFlash(env, (uint8_t *) env->recoveryFlashPageAddress, offset_crc);
|
||||
|
||||
uint32_t recoveryCrcReed;
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
recoveryCrcReed = D_iInternalFlashPage_ReadWord(env->recoveryFlashPageAddress + offset_crc);
|
||||
} else {
|
||||
recoveryCrcReed = P_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, offset_crc);
|
||||
uint32_t mainCrcReed = iInternalFlashPage_ReadWord(env->mainFlashPageAddress + offset_crc);
|
||||
uint32_t mainCrcCalc = xStorageOnFlashArtery_CrcFlash(env, (uint8_t *) env->mainFlashPageAddress, offset_crc);
|
||||
|
||||
uint32_t mainCrcReed;
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
mainCrcReed = D_iInternalFlashPage_ReadWord(env->mainFlashPageAddress + offset_crc);
|
||||
} else {
|
||||
mainCrcReed = P_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)
|
||||
|
|
@ -117,21 +153,39 @@ eStorageStatus xStorageOnFlashFlagchip_Load(tStorageOnFlashFlagchip *env, void *
|
|||
|
||||
if (recoveryCrcOk && mainCrcOk) {
|
||||
if (recoveryCrcReed == mainCrcReed) {
|
||||
sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc);
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
D_sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc);
|
||||
} else {
|
||||
P_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, offset_crc);
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
D_sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, offset_crc);
|
||||
} else {
|
||||
P_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, offset_crc);
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
D_sInternalFlashPage_Read(env->recoveryFlashPageAddress, 0x0, data, offset_crc);
|
||||
} else {
|
||||
P_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, offset_crc);
|
||||
if (env->TypeStorageOnFlashFlagchip == STORAGE_TYPE_D_DATA) {
|
||||
D_sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc);
|
||||
} else {
|
||||
P_sInternalFlashPage_Read(env->mainFlashPageAddress, 0x0, data, offset_crc);
|
||||
}
|
||||
return xStorageOnFlashFlagchip_DumpOn(env, mainCrcCalc, env->recoveryFlashPageAddress, data, offset_crc);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -141,8 +195,10 @@ eStorageStatus xStorageOnFlashFlagchip_Load(tStorageOnFlashFlagchip *env, void *
|
|||
}
|
||||
|
||||
void vStorageOnFlashFlagchip_Init(
|
||||
tStorageOnFlashFlagchip *env, uint32_t mainPage, uint32_t recoveryPage
|
||||
tStorageOnFlashFlagchip *env, eTypeStorageOnFlashFlagchip TypeStorageOnFlashFlagchip, uint32_t mainPage,
|
||||
uint32_t recoveryPage
|
||||
) {
|
||||
env->TypeStorageOnFlashFlagchip = TypeStorageOnFlashFlagchip;
|
||||
env->mainFlashPageAddress = mainPage;
|
||||
env->recoveryFlashPageAddress = recoveryPage;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue