Обновление платы на V2

This commit is contained in:
cfif 2026-05-28 11:28:55 +03:00
parent 8541ad0802
commit 916318f6ef
2 changed files with 22 additions and 87 deletions

View File

@ -949,10 +949,6 @@ static uint16_t vUDS_check_Programming_Preconditions(tCanUds *env, eUdsRoutineCo
return 0xFF00 | UDS_error_sub_functionNotSupported; return 0xFF00 | UDS_error_sub_functionNotSupported;
} }
env->CheckSum_BlockMain = false;
env->CheckSum_BlockCalib = false;
env->CheckSum_BlockMeta = false;
// env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; // env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess;
// return 4 + 1; // return 4 + 1;
return 4; return 4;
@ -992,33 +988,8 @@ static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlTy
if (crc32_calc == crc32_received) { if (crc32_calc == crc32_received) {
env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess;
if (env->udsBlock == UDS_BlockMain) {
env->CheckSum_BlockMain = true;
}
if (env->udsBlock == UDS_BlockCalib) {
env->CheckSum_BlockCalib = true;
}
if (env->udsBlock == UDS_BlockMeta) {
env->CheckSum_BlockMeta = true;
}
} else { } else {
env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; env->dataResponse[4] = UDS_routine_RoutineStartStopFailure;
if (env->udsBlock == UDS_BlockMain) {
env->CheckSum_BlockMain = false;
}
if (env->udsBlock == UDS_BlockCalib) {
env->CheckSum_BlockCalib = false;
}
if (env->udsBlock == UDS_BlockMeta) {
env->CheckSum_BlockMeta = false;
}
} }
@ -1046,8 +1017,6 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u
env->udsBlock = UDS_BlockMain; env->udsBlock = UDS_BlockMain;
} else if (eraseMemory->memoryAddress == ADR_HEX_BlockCalib) { } else if (eraseMemory->memoryAddress == ADR_HEX_BlockCalib) {
env->udsBlock = UDS_BlockCalib; env->udsBlock = UDS_BlockCalib;
} else if (eraseMemory->memoryAddress == ADR_HEX_BlockMeta) {
env->udsBlock = UDS_BlockMeta;
} }
if (env->udsBlock == UDS_BlockInit) { if (env->udsBlock == UDS_BlockInit) {
@ -1067,10 +1036,6 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u
result = env->clear_flash_func(ADR_HEX_Mapped_BlockCalib, SIZE_HEX_BlockCalib); result = env->clear_flash_func(ADR_HEX_Mapped_BlockCalib, SIZE_HEX_BlockCalib);
} }
if (env->udsBlock == UDS_BlockMeta) {
result = env->clear_flash_func(ADR_HEX_Mapped_BlockMeta, SIZE_HEX_BlockMeta);
}
// bool result = FLASHDRIVER_FlashEraseBlock(FLASH_BLOCK_SELECT1); // bool result = FLASHDRIVER_FlashEraseBlock(FLASH_BLOCK_SELECT1);
if (result) { if (result) {
@ -1094,53 +1059,41 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType
return 0xFF00 | UDS_error_sub_functionNotSupported; return 0xFF00 | UDS_error_sub_functionNotSupported;
} }
char *version_id_main = (char *) (ADR_HEX_BlockMain + 0x400); // char *version_id_main = (char *) (ADR_HEX_BlockMain + 0x400);
int result = memcmp(version_id_main, version_id, 9); // int result = memcmp(version_id_main, version_id, 9);
// if (result != 0) {
// LoggerErrorStatic(LOGGER, LOG_SIGN, "Software incompatibility");
// env->dataResponse[4] = 3;
// return 4 + 1;
// }
if ((env->CheckSum_BlockMain == false) || (env->CheckSum_BlockCalib == false) || (env->CheckSum_BlockMeta == false)) { setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending);
LoggerErrorStatic(LOGGER, LOG_SIGN, "At least one logical block missing"); uint32_t crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockMain, SIZE_HEX_BlockMain - 4,
env->dataResponse[4] = 4; SendUpdatePendingCrc, env, 200);
return 4 + 1; crc32_calc = UdsCrc32Finalize(crc32_calc);
}
uint32_t crc32_file = (*(uint32_t *) (ADR_HEX_Mapped_BlockMain + SIZE_HEX_BlockMain - 4));
if (crc32_calc != crc32_file) {
env->dataResponse[4] = UDS_routine_RoutineStartStopFailure;
if (result != 0) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "Software incompatibility");
env->dataResponse[4] = 3;
return 4 + 1; return 4 + 1;
} }
setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending);
crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockCalib, SIZE_HEX_BlockCalib - 4,
uint32_t crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockMain,
SIZE_HEX_BlockMain + SIZE_HEX_BlockCalib + SIZE_HEX_BlockMeta - 4,
SendUpdatePendingCrc, env, 200); SendUpdatePendingCrc, env, 200);
crc32_calc = UdsCrc32Finalize(crc32_calc); crc32_calc = UdsCrc32Finalize(crc32_calc);
memcpy(&env->data->data[1024], (uint8_t *) ADR_HEX_Mapped_BlockMeta, SIZE_HEX_BlockMeta); crc32_file = (*(uint32_t *) (ADR_HEX_Mapped_BlockCalib + SIZE_HEX_BlockCalib - 4));
uint32_t *crcFromFlash = (uint32_t *)&env->data->data[1024 + SIZE_HEX_BlockMeta - 4];
*crcFromFlash = crc32_calc;
result = env->clear_flash_func(ADR_HEX_Mapped_BlockMeta, SIZE_HEX_BlockMeta); if (crc32_calc != crc32_file) {
env->dataResponse[4] = UDS_routine_RoutineStartStopFailure;
if (result == false) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "General failure");
env->dataResponse[4] = 1;
return 4 + 1; return 4 + 1;
} }
result = env->write_flash_func(ADR_HEX_Mapped_BlockMeta, &env->data->data[1024], SIZE_HEX_BlockMeta);
if (result == false) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "General failure");
env->dataResponse[4] = 1;
return 4 + 1;
}
#if (LOG_UDS == 1)
LoggerFormatInfo(LOGGER, LOG_SIGN, "Update Crc: 0x%08X", *crcFromFlash)
#endif
env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess;
return 4 + 1; return 4 + 1;
@ -1444,10 +1397,6 @@ static uint16_t RequestDownload_34(tCanUds *env) {
env->udsBlock = UDS_BlockCalib; env->udsBlock = UDS_BlockCalib;
} }
if (com->memoryAddress == ADR_HEX_BlockMeta) {
env->udsBlock = UDS_BlockMeta;
}
if (env->udsBlock == UDS_BlockInit) { if (env->udsBlock == UDS_BlockInit) {
return setResponseError(env, UDS_RequestDownload, UDS_error_requestSequenceError); return setResponseError(env, UDS_RequestDownload, UDS_error_requestSequenceError);
} }
@ -1471,13 +1420,6 @@ static uint16_t RequestDownload_34(tCanUds *env) {
} }
if (env->udsBlock == UDS_BlockMeta) {
if (com->memorySize > SIZE_HEX_BlockMeta) {
return setResponseError(env, UDS_RequestDownload, UDS_error_requestOutOfRange);
}
}
if (env->currentSession == UDS_session_defaultSession) { if (env->currentSession == UDS_session_defaultSession) {
return setResponseError(env, UDS_RoutineControl, UDS_error_conditionsNotCorrect); return setResponseError(env, UDS_RoutineControl, UDS_error_conditionsNotCorrect);

View File

@ -22,15 +22,12 @@
#define ADR_HEX_BlockMain 0x01020000 #define ADR_HEX_BlockMain 0x01020000
#define ADR_HEX_BlockCalib 0x010D0000 #define ADR_HEX_BlockCalib 0x010D0000
#define ADR_HEX_BlockMeta 0x010FF800
#define ADR_HEX_Mapped_BlockMain 0x01100000 #define ADR_HEX_Mapped_BlockMain 0x01100000
#define ADR_HEX_Mapped_BlockCalib 0x011B0000 #define ADR_HEX_Mapped_BlockCalib 0x011B0000
#define ADR_HEX_Mapped_BlockMeta 0x011DF800
#define SIZE_HEX_BlockMain (704 * 1024) #define SIZE_HEX_BlockMain (704 * 1024)
#define SIZE_HEX_BlockCalib (190 * 1024) #define SIZE_HEX_BlockCalib (192 * 1024)
#define SIZE_HEX_BlockMeta (2 * 1024)
#define LEN_DEBUG_UDS_BUFF 128 #define LEN_DEBUG_UDS_BUFF 128
@ -152,7 +149,6 @@ typedef enum {
typedef enum { typedef enum {
UDS_BlockMain = 0, UDS_BlockMain = 0,
UDS_BlockCalib = 1, UDS_BlockCalib = 1,
UDS_BlockMeta = 2,
UDS_BlockInit = 0xff UDS_BlockInit = 0xff
} eUdsBlock; } eUdsBlock;
@ -212,9 +208,6 @@ typedef struct {
uint32_t DownloadFirmwareSize; uint32_t DownloadFirmwareSize;
eUdsBlock udsBlock; eUdsBlock udsBlock;
bool CheckSum_BlockMain;
bool CheckSum_BlockCalib;
bool CheckSum_BlockMeta;
uint32_t CurrentBlockAdr; uint32_t CurrentBlockAdr;
uint32_t CurrentBlockSize; uint32_t CurrentBlockSize;