📄 update.c
字号:
goto UpdateGetFirstActError;
}
// 开始读取真正的 升级数据.
FSFileSeek(gUpdateFile , gSetupFwOffset , 0); // FSEEK_SET
if (FSFileRead(gUpdateHeadBuffer , RKUD_HEAD_MAX , gUpdateFile) < (RKUD_HEAD_MAX / 2))
{
TR("Read file[%d] Failed 1!" , RKUD_HEAD_MAX);
goto UpdateGetFirstActError;
}
ph = (PIMAGE_RESBIN_DIRECTORY)gUpdateHeadBuffer;
//判断头部 是否正确,还有其他判断可以省略.
if (ph->Size != sizeof(IMAGE_RESBIN_DIRECTORY) ||
ph->Magic != RKB_MAGIC_FLAG || ph->NumberOfNamedEntries == 0)
{
TR("Error file 1!" , "");
goto UpdateGetFirstActError;
}
//获取第一个升级操作,必须为 VERSION 操作.
pSetupItem = (PRK_SETUPITEM_STR)((INT8U*)ph + ph->OffsetOfNamedEntries);
if (pSetupItem->Size > 0 && pSetupItem->Option == RKST_OPTION_VERSION)
{
pSetupItem->OffsetToData += gSetupFwOffset;
if (IUpdateGetVersion(pSetupItem , gUpdateFile))
{
TR("Get Version Failed!" , "");
goto UpdateGetFirstActError;
}
*Err = 0;
return pSetupItem;
}
UpdateGetFirstActError:
UpdateCancle(NULL);
*Err = 10;
return NULL;
}
/*********************************************************************************
Name : UpdateCancle
Desc : 退出 升级操作.
Param :
lastAction : 上一个 操作数据.
Return : 无.
Global : 无.
Note :
Author : HUANGSL
Log :
*********************************************************************************/
void UpdateCancle(void *lastAction)
{
// PRK_SETUPITEM_STR pSetupItem = (PRK_SETUPITEM_STR)lastAction;
if (gUpdateFile)
{
FSFileClose(gUpdateFile);
gUpdateFile = NULL;
}
if (gpSetupVersion != NULL)
{
FREE(gpSetupVersion);
gpSetupVersion = NULL;
gpSetupSwVersion = NULL;
gpSetupHwVersion = NULL;
gpSetupSwSerialString = NULL;
}
FREE(gUpdateHeadBuffer);
gUpdateHeadBuffer = NULL;
gUpdateSecondTime = 0;
}
/*********************************************************************************
Name : UpdateGetNextAction
Desc : 取得升级 信息的下一个操作.
Param :
lastAction : 上一个 操作数据.
Return : NULL:失败,表示操作已经结束. 其他 : 操作数据.
Global : 无.
Note :
Author : HUANGSL
Log :
*********************************************************************************/
void *UpdateGetNextAction(void *lastAction)
{
PRK_SETUPITEM_STR pSetupItem = (PRK_SETUPITEM_STR)lastAction;
pSetupItem++;
if (pSetupItem->Size > 0)
{
pSetupItem->OffsetToData += gSetupFwOffset; // OFFSET RESET!
return pSetupItem;
}
//外部 调用.
// UpdateCancle( pSetupItem );
return NULL;
}
/*lingzhaojun add for file copy*/
INT32 UpdataFileCopy(RK_SETUPITEM_STR *pItem)
{
MY_FILE *filedes, *filesrc;
UINT32 FileSize, CopySize, Result, NameLen = pItem->OffsetToData - pItem->Param[0];
INT32 Err = -1;
FSFileSeek(gUpdateFile , pItem->Param[0] , 0);
Result = FSFileRead(filename, NameLen, gUpdateFile);
filedes = FSFileOpen((const char*)filename, "wb");
if (!filedes)
goto exit;
filesrc = gUpdateFile;
FSFileSeek(filesrc , pItem->OffsetToData , 0);
FileSize = pItem->SizeOfBytes;
if (!FileSize)
goto exit;
while (FileSize)
{
if (FileSize > FileCopySize)
CopySize = FileCopySize;
else
CopySize = FileSize;
Result = FSFileRead(CopyBuf, CopySize, filesrc);
if (Result < CopySize)
goto exit;
Result = FSFileWrite(CopyBuf, CopySize, filedes);
if (Result < CopySize)
goto exit;
FileSize = FileSize - CopySize;
}
Err = 0;
exit:
FSFileClose(filedes);
return RKST_RESULT_OKNEXT;
}
/*********************************************************************************
Name : IUpdateActionHandlerSelf
Desc : 处理具体的升级操作,并 进行界面显示.
Param :
currAction : 需要处理的 操作数据.
win : 当前父窗口指针.
Return : 0:操作成功,其他: 操作失败.
Global : 无.
Note :
Author : HUANGSL
Log :
*********************************************************************************/
INT32U IUpdateActionHandlerSelf(void *currAction , WINDOW* win)
{
PRK_SETUPITEM_STR pItem = (PRK_SETUPITEM_STR)currAction;
switch (pItem->Option)
{
case RKST_OPTION_MKDIR:
break;
case RKST_OPTION_FCOPY:
return UpdataFileCopy((RK_SETUPITEM_STR *)pItem);
break;
case RKST_OPTION_FSOPER:
// return ISetupFsOper(pItem->OffsetToData, gUpdateFile);
return RKST_RESULT_OKNEXT ;//0xfffffffe;
case RKST_OPTION_DELAY:
SetupDelayMs(pItem->Param[0]);
break;
case RKST_OPTION_VERSION: //测试 版本信息.
return IUpdateVersionHandler(pItem , gUpdateFile , win);
// break;
case RKST_OPTION_FSDEL:
if (pItem->SizeOfBytes > 0)
{
}
else
{
}
return 0xfffffffd;
default:
{
TR("UNKnow Operation[%d]" , pItem->Option);
return RKST_RESULT_OKNEXT ;//0xfffffffe;
}
}
return RKST_RESULT_OKSTAY;
}
/*********************************************************************************
Name : UpdateActionHandler
Desc : 处理具体的升级操作,并 进行界面显示.
Param :
currAction : 需要处理的 操作数据.
win : 当前父窗口指针.
Return : 0:操作成功,其他: 操作失败.
Global : 无.
Note :
Author : HUANGSL
Log :
*********************************************************************************/
INT32U UpdateActionHandler(void *currAction , WINDOW* win)
{
INT32U r;
PRK_SETUPITEM_STR pSetupItem;
gUpdateSecondTime++;
pSetupItem = (PRK_SETUPITEM_STR)currAction;
while (pSetupItem->Size > 0 && pSetupItem->Option != RKST_OPTION_NULL)
{
if (gUpdateSecondTime == 1)
{
pSetupItem->OffsetToData += gSetupFwOffset;
}
#if defined(SETUP) || defined(_MSC_VER) //080526,huangsl,此功能目前暂时没有实现.
if ((r = ISetupProcessItem(gUpdateFile , pSetupItem)) != 0)
{
#if defined(_MSC_VER)
Sleep(500);
#endif
if (r == 0xffffffff)
{
return 0;
}
else
{
return 100;
}
}
#endif // defined(SETUP) || defined(_MSC_VER)
#if defined(_MSC_VER) //仿真下显示拷贝文件.
Sleep(100);
#endif
pSetupItem++;
}
return r;
}
PRK_SWVERSION gpSetupVersion; //系统 版本信息.
PSWVERSION_REGKEY gpSetupSwVersion; //平台版本 信息.
PHWVERSION_REGKEY gpSetupHwVersion; // 硬件 版本信息.
PRK_SWVERSION GetSetUpVersion(void)
{
return gpSetupVersion;
}
PSWVERSION_REGKEY GetSwVersion(void)
{
return gpSetupSwVersion;
}
PHWVERSION_REGKEY GetHwVersion(void)
{
return gpSetupHwVersion;
}
void UpdateActionStart(void)
{
ISystemReboot(0x01); // 从 升级启动 .
}
/*****************************************************************************/
/****************************************************************/
//---------END OF FILE---------//
/****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -