extract server image version and unit tests

This commit is contained in:
Hendrik Schutter 2021-01-07 23:10:36 +01:00
parent c985ee6031
commit d8c9239ed7
8 changed files with 72 additions and 25 deletions

View File

@ -68,7 +68,7 @@ https_client_ret_t https_clientInitialize()
return i32RetHTTPClient;
}
https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32BytesRead)
https_client_ret_t https_clientRetrieveData(char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32BytesRead)
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK;
int32_t i32RetRetrieveData = ESP_OK;

View File

@ -66,7 +66,7 @@ typedef int32_t https_client_ret_t;
typedef struct HTTPS_Client HTTPS_Client_t;
https_client_ret_t https_clientInitialize();
https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32BytesRead);
https_client_ret_t https_clientRetrieveData(char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32BytesRead);
https_client_ret_t https_clientDeinitialize();
#endif /* H_HTTPS_CLIENT */

View File

@ -17,7 +17,7 @@
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
#endif /* H_MESH_OTA */

View File

@ -41,7 +41,7 @@ bool bNewerVersion(const char* pu8Local, const char* pu8Remote) {
return bReturn;
}
esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
{
/*
Offset value
@ -68,9 +68,7 @@ esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, ui
if(pu8Data[u32DataIndex] == 0xe9)
{
//magic byte found
printf("\n magic byte found: %i\n", u32DataIndex);
//printf("\n magic byte found: %i\n", u32DataIndex);
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
{
//search first dot in version number
@ -80,7 +78,7 @@ esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, ui
{
//first do found
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
printf("First dot offset: %i\n", u32FirstDotOffset);
//printf("First dot offset: %i\n", u32FirstDotOffset);
}
}
u8FirstDotIndex++;
@ -96,7 +94,7 @@ esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, ui
{
//second do found
u32SecondDotOffset = (u32FirstDotOffset+(u8SecondDotIndex+2));
printf("Second dot offset: %i\n", u32SecondDotOffset);
//printf("Second dot offset: %i\n", u32SecondDotOffset);
}
}
u8SecondDotIndex++;
@ -131,7 +129,7 @@ esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, ui
return errReturn;
}
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
{
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
@ -142,11 +140,13 @@ esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLeng
if(err == ESP_OK)
{
printf("\n Image start found: %i\n", u32StartOffset);
//printf("\nImage start found: %i\n", u32StartOffset);
//extract image version
printf("remote version number %s\n", pc8RemoteVersionNumber);
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11);
pc8RemoteVersionNumber[12] = '\0';
//printf("remote version number %s\n\n", pc8RemoteVersionNumber);
}

View File

@ -3,7 +3,7 @@
//with http response + 0.0.1
uint8_t dataWithHttpRespone0_0_1[] =
char dataWithHttpRespone0_0_1[] =
{
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2f, 0x31, 0x2e, 0x31, 0x34, 0x2e, 0x32, 0xd, 0xa, 0x44,
0x61, 0x74, 0x65, 0x3a, 0x20, 0x54, 0x68, 0x75, 0x2c, 0x20, 0x30, 0x37, 0x20, 0x4a, 0x61, 0x6e, 0x20, 0x32, 0x30, 0x32, 0x31, 0x20, 0x31, 0x33, 0x3a, 0x34, 0x38, 0x3a, 0x32, 0x36, 0x20, 0x47, 0x4d, 0x54, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74,
@ -34,7 +34,7 @@ uint8_t dataWithHttpRespone0_0_1[] =
//without http response + 0.0.1
uint8_t dataWithoutHttpRespone0_0_1[] =
char dataWithoutHttpRespone0_0_1[] =
{
0xe9, 0x7, 0x2, 0x20, 0x5c, 0x12, 0x8, 0x40, 0xee, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x20, 0x0, 0x40, 0x3f, 0xe4, 0x55, 0x3, 0x0, 0x32, 0x54, 0xcd, 0xab, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
@ -57,7 +57,7 @@ uint8_t dataWithoutHttpRespone0_0_1[] =
};
//without http response + 9999.999.999
uint8_t dataWithoutHttpRespone999_999_999[] =
char dataWithoutHttpRespone999_999_999[] =
{
0xe9, 0x7, 0x2, 0x20, 0x5c, 0x12, 0x8, 0x40, 0xee, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x20, 0x0, 0x40, 0x3f, 0xec, 0x44, 0x3, 0x0, 0x32, 0x54, 0xcd, 0xab, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x39, 0x39, 0x39, 0x2e, 0x39, 0x39, 0x39, 0x2e, 0x39, 0x39, 0x39, 0x0, 0x0,
@ -82,7 +82,7 @@ uint8_t dataWithoutHttpRespone999_999_999[] =
//with http response + 999.999.999
uint8_t dataWithHttpRespone999_999_999[] =
char dataWithHttpRespone999_999_999[] =
{
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2f, 0x31, 0x2e, 0x31, 0x34, 0x2e, 0x32, 0xd, 0xa, 0x44,
0x61, 0x74, 0x65, 0x3a, 0x20, 0x54, 0x68, 0x75, 0x2c, 0x20, 0x30, 0x37, 0x20, 0x4a, 0x61, 0x6e, 0x20, 0x32, 0x30, 0x32, 0x31, 0x20, 0x31, 0x35, 0x3a, 0x31, 0x33, 0x3a, 0x32, 0x39, 0x20, 0x47, 0x4d, 0x54, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74,
@ -112,7 +112,7 @@ uint8_t dataWithHttpRespone999_999_999[] =
};
//with http response + 999.9.999
uint8_t dataWithHttpRespone999_9_999[] =
char dataWithHttpRespone999_9_999[] =
{
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2f, 0x31, 0x2e, 0x31, 0x34, 0x2e, 0x32, 0xd, 0xa, 0x44,
0x61, 0x74, 0x65, 0x3a, 0x20, 0x54, 0x68, 0x75, 0x2c, 0x20, 0x30, 0x37, 0x20, 0x4a, 0x61, 0x6e, 0x20, 0x32, 0x30, 0x32, 0x31, 0x20, 0x31, 0x35, 0x3a, 0x31, 0x33, 0x3a, 0x32, 0x39, 0x20, 0x47, 0x4d, 0x54, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74,
@ -142,7 +142,7 @@ uint8_t dataWithHttpRespone999_9_999[] =
};
//with http response + 999.99.999
uint8_t dataWithHttpRespone999_99_999[] =
char dataWithHttpRespone999_99_999[] =
{
0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2f, 0x31, 0x2e, 0x31, 0x34, 0x2e, 0x32, 0xd, 0xa, 0x44,
0x61, 0x74, 0x65, 0x3a, 0x20, 0x54, 0x68, 0x75, 0x2c, 0x20, 0x30, 0x37, 0x20, 0x4a, 0x61, 0x6e, 0x20, 0x32, 0x30, 0x32, 0x31, 0x20, 0x31, 0x35, 0x3a, 0x31, 0x33, 0x3a, 0x32, 0x39, 0x20, 0x47, 0x4d, 0x54, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74,

View File

@ -156,8 +156,55 @@ TEST_CASE("with http response + 999.99.999", "[find start offset in firmware im
}
}
// ### ### ### distinguish newer image version ### ### ###
TEST_CASE("extract version 0.0.1", "[extract image version number]")
{
char versionLocal[] = "0.0.0"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone0_0_1)/sizeof(dataWithHttpRespone0_0_1[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone0_0_1, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("extract version 999.999.999", "[extract image version number]")
{
char versionLocal[] = "0.0.0"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_999_999)/sizeof(dataWithHttpRespone999_999_999[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone999_999_999, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("extract version 999.99.999", "[extract image version number]")
{
char versionLocal[] = "999.100.999"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_99_999)/sizeof(dataWithHttpRespone999_99_999[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone999_99_999, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_FALSE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}

View File

@ -488,7 +488,7 @@ static void test(void *pvParameters)
{
esp_err_t err;
uint32_t u32BufferLenght = 1024U;
unsigned char buffer[1024U];
char buffer[1024U];
uint32_t u32BytesRead = 0;
char pcRemoteVersionNumber[12];

View File

@ -32,7 +32,7 @@ CONFIG_APP_COMPILE_TIME_DATE=y
# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set
# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set
CONFIG_APP_PROJECT_VER_FROM_CONFIG=y
CONFIG_APP_PROJECT_VER="999.9.999"
CONFIG_APP_PROJECT_VER="0.0.1"
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
# end of Application manager