1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
generated by cgit v1.3.1 (git 2.54.0) at 2026-07-14 10:21:31 +0000
ight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long *//*
* FirmwareUpgrade.c
*
* Created on: Dec 24, 2018
* Author: shlomo
*/
#include "include.h"
#include "Communication/CommunicationTask.h"
#include <DataDef.h>
#include <Communication/PMR/FirmwareUpgrade/ActivateVersionRequest.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ActivateVersionResponse.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ActivateVersionRequest.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ActivateVersionResponse.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ValidateVersionRequest.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ValidateVersionResponse.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ValidateVersionRequest.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/ValidateVersionResponse.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/VersionFileDestination.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/VersionFileDescriptor.pb-c.h>
#include <Communication/PMR/FirmwareUpgrade/VersionPackageDescriptor.pb-c.h>
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
#include "drivers/FPGA/Full_Vme/FPGA_Programming_Up.h"
#include "drivers/FPGA/Full_Vme/ispvme/vmopcode.h"
#include "drivers/Flash_ram/FlashProgram.h"
#include "Common/Utilities/Utils.h"
#include "Common/SWUpdate/FileSystem.h"
#include "Modules/Control/Control.h"
#include "Modules/AlarmHandling/AlarmHandling.h"
extern Semaphore_Handle FFS_Sem;
int NumberOfFiles = 0,CurrentRunningFile;
int CurrentFileSize = 0;
uint32_t ActivateVersionControlId = 0xFF;
char activateString[100];
char ActivateToken[36+1]={0};
bool Reboot = false;
bool SwUpgradeActive(void)
{
if (ActivateVersionControlId != 0xFF)
{
//Reboot = false;
return true;
}
return false;
}
uint32_t ActivateVersionCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
{
ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT;
MessageContainer responseContainer;
bool last = true;
usnprintf(activateString, 1000, "file %d of %d bytes %d of %d",CurrentRunningFile,NumberOfFiles,vme_index,CurrentFileSize);
Report(activateString,__FILE__,__LINE__,(int)CurrentRunningFile,RpWarning,CurrentFileSize,0);
if (CurrentRunningFile<NumberOfFiles)
{
last = false;
}
responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, ActivateToken, last, &response, &activate_version_response__pack, &activate_version_response__get_packed_size);
responseContainer.has_continuous = true;
responseContainer.continuous = true;
uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
size_t container_size = message_container__pack(&responseContainer, container_buffer);
my_free(responseContainer.data.data);
SendChars(container_buffer, container_size);
if (last == true)
{
if (SafeRemoveControlCallback(ActivateVersionControlId, ActivateVersionCallBackFunction )==OK)
ActivateVersionControlId = 0xFF;
else
LOG_ERROR(255,"ActivateVersionCallBackFunction");
if (Reboot == true)
{
LOG_ERROR(255,"Update successful, Rebooting in 5 seconds");
Task_sleep (eOneSecond*5);
Power_Reset();
}
}
return OK;
}
int File_i = 0;
uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer)
{
void* buffer = NULL;
uint32_t Bytes = 0;
char SWUpgradePath[100];
char FullPath[50];
FRESULT Fresult = FR_OK;
FILINFO* fno = 0;
fno = my_malloc(sizeof(FILINFO));
if (fno == 0)
return ERROR;
MessageContainer responseContainer;
ActivateVersionRequest* request = activate_version_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT;
VersionPackageDescriptor* VersionPackage;// = VERSION_PACKAGE_DESCRIPTOR__INIT;
FPGA_ID FileDestinationToFPGAId[VERSION_FILE_DESTINATION__FPGA3+1] = {MAX_FPGA,FPGA1,FPGA2,FPGA3};
ustrncpy (ActivateToken, requestContainer->token,36);
strncpy (SWUpgradePath,request->path,99);
SWUpgradePath[99] = NULL;
strcat(SWUpgradePath,"/package.cfg");
Fresult = FileRead(SWUpgradePath, &Bytes, &buffer);
if (Fresult == FR_OK)
{
VersionPackage = version_package_descriptor__unpack(NULL,Bytes,buffer);
NumberOfFiles = VersionPackage->n_filedescriptors;
Report("ActivateVersionRequestFunc",__FILE__,__LINE__,(int)NumberOfFiles,RpWarning,Bytes,0);
if (NumberOfFiles)
{
CurrentRunningFile = 0;
File_i = 0;
//add control 1 second
ActivateVersionControlId = AddControlCallback(NULL, ActivateVersionCallBackFunction, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
}
for (File_i = 0;File_i<VersionPackage->n_filedescriptors;File_i++)
{
CurrentFileSize = -1;
//vme_index = 0;
switch(VersionPackage->filedescriptors[File_i]->destination)
{
case VERSION_FILE_DESTINATION__MCU:
CurrentRunningFile++;
break;
case VERSION_FILE_DESTINATION__FPGA1:
case VERSION_FILE_DESTINATION__FPGA2:
case VERSION_FILE_DESTINATION__FPGA3:
//validate
//update
usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename);
Reboot = true;
memset (fno,0,sizeof(FILINFO));
Fresult = f_stat(FullPath,fno);
CurrentFileSize = fno->fsize;
Fresult = FPGA_Programming_Request( FileDestinationToFPGAId[VersionPackage->filedescriptors[File_i]->destination], FullPath, false);
break;
case VERSION_FILE_DESTINATION__ConfigParams:
usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename);
Fresult = f_unlink("//SYSINFO//EMBPARAM.CFG");
Fresult |= f_rename (FullPath, "//SYSINFO//EMBPARAM.CFG");
LoadConfigurationParamsFromFile(true);
CurrentRunningFile++;
break;
case VERSION_FILE_DESTINATION__ProcessParams:
usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename);
Fresult = f_unlink("//SYSINFO//PROCESSP.CFG");
Fresult |= f_rename (FullPath, "//SYSINFO//PROCESSP.CFG");
LoadProcessParamsFromFile();
CurrentRunningFile++;
break;
case VERSION_FILE_DESTINATION__AlarmParams:
usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename);
Fresult = f_unlink("//SYSINFO//ALARM.CFG");
Fresult |= f_rename (FullPath, "//SYSINFO//ALARM.CFG");
//AlarmHandlingLoadFile();
FlashInit();
Reboot = true;
CurrentRunningFile++;
break;
case VERSION_FILE_DESTINATION__GeneralHWConfigParams:
usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename);
Fresult = f_unlink("//SYSINFO//GENHWCFG.CFG");
Fresult |= f_rename (FullPath, "//SYSINFO//GENHWCFG.CFG");
HWConfigurationLoadFile();
CurrentRunningFile++;
break;
default:
LOG_ERROR (VersionPackage->filedescriptors[File_i]->destination,"wrong file update Destination");
Fresult = FR_INVALID_NAME;
break;
}
}
}
responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, requestContainer->token, false, &response, &activate_version_response__pack, &activate_version_response__get_packed_size);
responseContainer.has_continuous = true;
responseContainer.continuous = true;
if (Fresult!= OK)
{
responseContainer.error = FileError_to_ErrorCode[Fresult];
responseContainer.errormessage = "Activate Version Request error";
responseContainer.continuous = false;
}
uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
size_t container_size = message_container__pack(&responseContainer, container_buffer);
my_free(responseContainer.data.data);
activate_version_request__free_unpacked(request,NULL);
SendChars(container_buffer, container_size);
return OK;
}
uint32_t ValidateVersionRequestFunc(MessageContainer* requestContainer)
{
uint32_t status = OK;
MessageContainer responseContainer;
ValidateVersionRequest* request = validate_version_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
ValidateVersionResponse response = VALIDATE_VERSION_RESPONSE__INIT;
responseContainer = createContainer(MESSAGE_TYPE__ValidateVersionResponse, requestContainer->token, false, &response, &validate_version_response__pack, &validate_version_response__get_packed_size);
if (status!= OK)
{
responseContainer.error = ERROR_CODE__INVALID_UPLOAD_ID;
responseContainer.errormessage = "Validate Version Request error";
}
responseContainer.continuous = false;
uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
size_t container_size = message_container__pack(&responseContainer, container_buffer);
my_free(responseContainer.data.data);
validate_version_request__free_unpacked(request,NULL);
SendChars(container_buffer, container_size);
return OK;
}
|