|
@@ -11,19 +11,39 @@
|
|
|
#include <unistd.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
+/* IWDG */
|
|
|
+#define IOCTL_MAGIC 'x'
|
|
|
+#define GENERATE_CMD(__MAGIC__, __MAJOR__, __CMD__) \
|
|
|
+ ((0x3<<30) | (__MAJOR__<<16) | (__MAGIC__<<8) | __CMD__)
|
|
|
+#define MAJOR_IWDG 108
|
|
|
+#define FEED_WATCHDOG GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 0)
|
|
|
+#define START_IWATCHDOG GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 1)
|
|
|
+#define STOP_IWATCHDOG GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 2)
|
|
|
+
|
|
|
static uint8_t progress = 0;
|
|
|
+static uint8_t target_addr;
|
|
|
/* 进入固件更新模式
|
|
|
* 杀死所有其它进程
|
|
|
*/
|
|
|
void prepareDevice(Webs *wp)
|
|
|
{
|
|
|
- printf("Update Firmware: Prepare Device...\n");
|
|
|
- uint8_t cmd[50] = {0};
|
|
|
- progress = 0;
|
|
|
- //kill bmc_app
|
|
|
- sprintf(cmd, "killall -9 bmc_app");
|
|
|
- sprintf(cmd, "killall -9 damon.sh");
|
|
|
- system(cmd);
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
+ {
|
|
|
+ printf("Update Firmware: Prepare Device...\n");
|
|
|
+ progress = 0;
|
|
|
+ //kill bmc_app
|
|
|
+ system("killall -9 damon.sh");
|
|
|
+ printf("killall -9 damon.sh\n");
|
|
|
+ system("killall -9 bmc_app");
|
|
|
+ printf("killall -9 bmc_app\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //Do nothing
|
|
|
+ }
|
|
|
+
|
|
|
char *pStr;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON * data = cJSON_CreateObject();
|
|
@@ -58,17 +78,28 @@ void uploadFirmware(Webs *wp)
|
|
|
WebsKey *s;
|
|
|
WebsUpload *up;
|
|
|
char *upfile;
|
|
|
- if (scaselessmatch(wp->method, "POST")) {
|
|
|
- for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
|
|
- up = s->content.value.symbol;
|
|
|
- upfile = sfmt("%s/tmp/%s", websGetDocuments(), "tmp.uImage");
|
|
|
- if (rename(up->filename, upfile) < 0) {
|
|
|
- error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
|
|
+
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
+ {
|
|
|
+ if (scaselessmatch(wp->method, "POST")) {
|
|
|
+ for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
|
|
+ up = s->content.value.symbol;
|
|
|
+ upfile = sfmt("%s/tmp/%s", websGetDocuments(), "tmp.uImage");
|
|
|
+ if (rename(up->filename, upfile) < 0) {
|
|
|
+ error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
|
|
+ }
|
|
|
+ wfree(upfile);
|
|
|
}
|
|
|
- wfree(upfile);
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //Do nothing
|
|
|
+ }
|
|
|
+
|
|
|
char *pStr;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON * data = cJSON_CreateObject();
|
|
@@ -103,9 +134,19 @@ void updateFlash(Webs *wp)
|
|
|
uint8_t cmd[50] = {0};
|
|
|
progress = 0;
|
|
|
|
|
|
- //Call updateFW_app
|
|
|
- sprintf(cmd, "/usr/bin/updateFW_app &");
|
|
|
- system(cmd);
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
+ {
|
|
|
+ //Call updateFW_app
|
|
|
+ system("/usr/bin/updateFW_app &");
|
|
|
+ printf("/usr/bin/updateFW_app &");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //Do nothing
|
|
|
+ }
|
|
|
+
|
|
|
char *pStr;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON * data = cJSON_CreateObject();
|
|
@@ -128,7 +169,7 @@ void updateFlash(Webs *wp)
|
|
|
cJSON_Delete(root);
|
|
|
|
|
|
websDone(wp);
|
|
|
- printf("Update Firmware: Prepare Device Ok.\n");
|
|
|
+ printf("Update Firmware: Update Flash ok.\n");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -141,21 +182,31 @@ void getUpdateProgress(Webs *wp)
|
|
|
uint8_t progressStr[10] = {0};
|
|
|
FILE *fp;
|
|
|
|
|
|
- //TODO:
|
|
|
- fp = fopen("/var/www/goahead/tmp/UpdateProgress.log", "r");
|
|
|
- if(NULL == fp)
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
{
|
|
|
- printf("Open UpdateProgress.log failed!\n");
|
|
|
- websError(wp, 200, "Open UpdateProgress.log failed!");
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- if(NULL == fgets(progressStr, 10, 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- printf("Read UpdateProgress.log failed!\n");
|
|
|
- websError(wp, 200, "Read UpdateProgress.log failed!");
|
|
|
- fclose(fp);
|
|
|
- return;
|
|
|
+ sprintf(progressStr, "100");
|
|
|
}
|
|
|
|
|
|
char *pStr;
|
|
@@ -192,24 +243,33 @@ void getVerifyStatus(Webs *wp)
|
|
|
uint8_t verigyStr[13] = {0};
|
|
|
FILE *fp;
|
|
|
|
|
|
- //TODO:
|
|
|
- fp = fopen("/var/www/goahead/tmp/Verify.log", "r");
|
|
|
- if(NULL == fp)
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
{
|
|
|
- printf("Open Verify.log failed!\n");
|
|
|
- websError(wp, 200, "Open Verify.log failed!");
|
|
|
- return;
|
|
|
- }
|
|
|
+ //TODO:
|
|
|
+ fp = fopen("/var/www/goahead/tmp/Verify.log", "r");
|
|
|
+ if(NULL == fp)
|
|
|
+ {
|
|
|
+ printf("Open Verify.log failed!\n");
|
|
|
+ websError(wp, 200, "Open Verify.log failed!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if(NULL == fgets(verigyStr, 13, fp))
|
|
|
+ if(NULL == fgets(verigyStr, 13, fp))
|
|
|
+ {
|
|
|
+ printf("Read Verify.log failed!\n");
|
|
|
+ websError(wp, 200, "Read Verify.log failed!");
|
|
|
+ fclose(fp);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Update Firmware: %s\n", verigyStr);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- printf("Read Verify.log failed!\n");
|
|
|
- websError(wp, 200, "Read Verify.log failed!");
|
|
|
- fclose(fp);
|
|
|
- return;
|
|
|
+ sprintf(verigyStr, "Verify OK");
|
|
|
}
|
|
|
-
|
|
|
- printf("Update Firmware: %s\n", verigyStr);
|
|
|
|
|
|
|
|
|
char *pStr;
|
|
@@ -246,53 +306,24 @@ void resetBmc(Webs *wp)
|
|
|
printf("Update Firmware: Reset BMC...\n");
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
- //websWriteHeader(wp, "resetBmc");
|
|
|
websWriteEndHeaders(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)
|
|
|
+ wp->index = TEST_INDEX;
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
+ if(target_addr == 0x20)
|
|
|
{
|
|
|
- printf("Open %s failed!\n", DEV_NAME);
|
|
|
- }
|
|
|
+ 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);
|
|
|
+ ioctl(fd, RESET_MCU, NULL);
|
|
|
+ close(fd);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-// void getDeviceInfo(Webs *wp){
|
|
|
-
|
|
|
-// char *pStr;
|
|
|
-// cJSON * root = cJSON_CreateObject();
|
|
|
-// cJSON * data = cJSON_CreateObject();
|
|
|
-// cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
-// cJSON_AddStringToObject(root, "msg", "");
|
|
|
-// cJSON_AddNumberToObject(root, "code", 200);
|
|
|
-// cJSON_AddStringToObject(data, "buildTime", BuildTime);
|
|
|
-// cJSON_AddStringToObject(data, "fwVersion", FwVersion);
|
|
|
-// cJSON_AddStringToObject(data, "macAddr", MacAddr);
|
|
|
-// cJSON_AddStringToObject(data, "ipAddr", IpAddr);
|
|
|
-// cJSON_AddStringToObject(data, "netMode", "static");
|
|
|
-
|
|
|
-// pStr = cJSON_PrintUnformatted(root);
|
|
|
-
|
|
|
-// printf("---> cJSON Str:\n%s\n", pStr);
|
|
|
-// websSetStatus(wp, 200);
|
|
|
-// websWriteHeaders(wp, -1, 0);
|
|
|
-// websWriteEndHeaders(wp);
|
|
|
-// websWrite(wp, "%s", pStr);
|
|
|
-// websFlush(wp, 0);
|
|
|
-// websDone(wp);
|
|
|
-
|
|
|
-// if(pStr)
|
|
|
-// wfree(pStr);
|
|
|
-// if(root)
|
|
|
-// cJSON_Delete(root);
|
|
|
-
|
|
|
-// }
|