|
@@ -9,6 +9,7 @@
|
|
|
#include <sys/socket.h>
|
|
|
#include <sys/un.h>
|
|
|
#include <unistd.h>
|
|
|
+#include <string.h>
|
|
|
|
|
|
static uint8_t progress = 0;
|
|
|
/* 进入固件更新模式
|
|
@@ -17,20 +18,20 @@ static uint8_t progress = 0;
|
|
|
void prepareDevice(Webs *wp)
|
|
|
{
|
|
|
printf("Update Firmware: Prepare Device...\n");
|
|
|
- //TODO: kill all other process
|
|
|
+ uint8_t cmd[50] = {0};
|
|
|
progress = 0;
|
|
|
- sleep(10);
|
|
|
+ //kill bmc_app
|
|
|
+ sprintf(cmd, "killall -9 bmc_app");
|
|
|
+ system(cmd);
|
|
|
char *pStr;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON * data = cJSON_CreateObject();
|
|
|
cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
cJSON_AddStringToObject(root, "msg", "");
|
|
|
cJSON_AddNumberToObject(root, "code", 200);
|
|
|
-
|
|
|
-
|
|
|
pStr = cJSON_PrintUnformatted(root);
|
|
|
-
|
|
|
printf("---> cJSON Str:\n%s\n", pStr);
|
|
|
+
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
websWriteEndHeaders(wp);
|
|
@@ -47,7 +48,8 @@ void prepareDevice(Webs *wp)
|
|
|
printf("Update Firmware: Prepare Device Ok.\n");
|
|
|
}
|
|
|
|
|
|
-/* 接收上传的固件
|
|
|
+/*
|
|
|
+ 接收上传的固件
|
|
|
*/
|
|
|
|
|
|
void uploadFirmware(Webs *wp)
|
|
@@ -98,16 +100,35 @@ void updateFlash(Webs *wp)
|
|
|
{
|
|
|
printf("Update Firmware: Update Flash...\n");
|
|
|
//TODO:
|
|
|
-
|
|
|
+ uint8_t cmd[50] = {0};
|
|
|
+ progress = 0;
|
|
|
|
|
|
- sleep(10);
|
|
|
+ //Call updateFW_app
|
|
|
+ sprintf(cmd, "/usr/bin/updateFW_app &");
|
|
|
+ system(cmd);
|
|
|
+ char *pStr;
|
|
|
+ cJSON * root = cJSON_CreateObject();
|
|
|
+ cJSON * data = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ cJSON_AddStringToObject(root, "msg", "");
|
|
|
+ cJSON_AddNumberToObject(root, "code", 200);
|
|
|
+ pStr = cJSON_PrintUnformatted(root);
|
|
|
+ printf("---> cJSON Str:\n%s\n", pStr);
|
|
|
+
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
- //websWriteHeader(wp, "updateFlash");
|
|
|
- websWriteEndHeaders(wp);
|
|
|
- //websWrite(wp, "%s", pStr);
|
|
|
- //websFlush(wp, 0);
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
+ websWrite(wp,"%s", pStr);
|
|
|
+ websFlush(wp, 0);
|
|
|
+ // websDone(wp);
|
|
|
+
|
|
|
+ if(pStr)
|
|
|
+ wfree(pStr);
|
|
|
+ if(root)
|
|
|
+ cJSON_Delete(root);
|
|
|
+
|
|
|
websDone(wp);
|
|
|
+ printf("Update Firmware: Prepare Device Ok.\n");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -117,16 +138,32 @@ void updateFlash(Webs *wp)
|
|
|
*/
|
|
|
void getUpdateProgress(Webs *wp)
|
|
|
{
|
|
|
- uint8_t progressStr[5] = {0};
|
|
|
- //TODO:
|
|
|
- if(progress < 100)
|
|
|
- progress++;
|
|
|
- sprintf(progressStr, "%d%%", progress);
|
|
|
+ uint8_t progressStr[10] = {0};
|
|
|
+ FILE *fp;
|
|
|
+
|
|
|
+ //TODO:
|
|
|
+ fp = fopen("/var/www/goahead/tmp/UpdateProgress.log", "r");
|
|
|
+ if(NULL == fp)
|
|
|
+ {
|
|
|
+ printf("Open UpdateProgress.log failed!\n");
|
|
|
+ websError(wp, 200, "Open UpdateProgress.log failed!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(NULL == fgets(progressStr, 10, fp))
|
|
|
+ {
|
|
|
+ printf("Read UpdateProgress.log failed!\n");
|
|
|
+ websError(wp, 200, "Read UpdateProgress.log failed!");
|
|
|
+ fclose(fp);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
printf("Update Firmware: %s\n", progressStr);
|
|
|
|
|
|
+
|
|
|
char *pStr;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
- cJSON_AddStringToObject(root, "msg", progressStr);
|
|
|
+ cJSON_AddStringToObject(root, "progress", progressStr);
|
|
|
cJSON_AddNumberToObject(root, "code", 200);
|
|
|
|
|
|
|
|
@@ -146,13 +183,17 @@ void getUpdateProgress(Webs *wp)
|
|
|
cJSON_Delete(root);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
void resetBmc(Webs *wp)
|
|
|
{
|
|
|
- printf("Update Firmware: Reset BMC...\n");
|
|
|
- //TODO:
|
|
|
- if(progress < 100)
|
|
|
- progress++;
|
|
|
+#define DEV_NAME "/dev/platform"
|
|
|
+#define IOCTL_MAGIC 'x'
|
|
|
+#define MAJOR_PLATFORM 100
|
|
|
+#define GENERATE_CMD(__MAGIC__, __MAJOR__, __CMD__) \
|
|
|
+ ((0x3<<30) | (__MAJOR__<<16) | (__MAGIC__<<8) | __CMD__)
|
|
|
+#define RESET_MCU GENERATE_CMD(IOCTL_MAGIC, MAJOR_PLATFORM, 2)
|
|
|
|
|
|
+ printf("Update Firmware: Reset BMC...\n");
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
//websWriteHeader(wp, "resetBmc");
|
|
@@ -160,6 +201,16 @@ void resetBmc(Webs *wp)
|
|
|
//websWrite(wp, "%s", pStr);
|
|
|
//websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
|
+
|
|
|
+ usleep(1000); //wait previous code
|
|
|
+ int fd = open(DEV_NAME, O_RDWR);
|
|
|
+ if(fd == -1)
|
|
|
+ {
|
|
|
+ printf("Open %s failed!\n", DEV_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ ioctl(fd, RESET_MCU, NULL);
|
|
|
+ close(fd);
|
|
|
}
|
|
|
|
|
|
|