Ver código fonte

New update interface

zhangbo 5 anos atrás
pai
commit
cf2a2bd8a5

+ 1 - 1
app/goahead-3.6.5/projects/goahead-linux-static-me.h

@@ -232,7 +232,7 @@
     #define ME_GOAHEAD_UPLOAD 1
 #endif
 #ifndef ME_GOAHEAD_UPLOAD_DIR
-    #define ME_GOAHEAD_UPLOAD_DIR "tmp"
+    #define ME_GOAHEAD_UPLOAD_DIR "/var/tmp"
 #endif
 #ifndef ME_GOAHEAD_XFRAME_HEADER
     #define ME_GOAHEAD_XFRAME_HEADER "SAMEORIGIN"

+ 8 - 1
app/goahead-3.6.5/src/goahead.c

@@ -200,7 +200,14 @@ websDefineAction("getAllUserInfo", getAllUserInfo);
 websDefineAction("setUserPassword", setUserPassword);
 websDefineAction("addUser", addUser);
 websDefineAction("delUser", delUser);
- websDefineAction("uploadTest", uploadTest);
+
+//update firmware
+websDefineAction("uploadTest", uploadTest);
+websDefineAction("prepareDevice", prepareDevice);
+websDefineAction("uploadFirmware", uploadFirmware);
+websDefineAction("updateFlash", updateFlash);
+websDefineAction("getUpdateProgress", getUpdateProgress);
+websDefineAction("resetBmc", resetBmc);
 
 
 

+ 1 - 1
app/goahead-3.6.5/src/http.c

@@ -799,7 +799,7 @@ static void readEvent(Webs *wp)
     }
 
 
-//    printf("%s>>>>>>>>rxbuf->endp>>>>>>>\n",rxbuf->endp);
+    //printf(">>>rxbuf->endp: %p\n",rxbuf->endp);
     // ME_GOAHEAD_LIMIT_BUFFER
     if ((nbytes = websRead(wp, (char*) rxbuf->endp, ME_GOAHEAD_LIMIT_BUFFER)) > 0) {//调用socketRead,读HTTP请求.rxbuf->endp是上一次的数据尾,每次读之后接上
  //       printf("%d>>>>>>>>2222>>>>>>>\n",nbytes);//一次读了多少字节

+ 2 - 2
app/goahead-3.6.5/src/upload.c

@@ -222,7 +222,7 @@ static void processUploadHeader(Webs *wp, char *line)
             } else if (scaselesscmp(key, "name") == 0) {
                 wfree(wp->uploadVar);
                 wp->uploadVar = sclone(value);
-
+                printf("log1: name: %s\n", wp->uploadVar);
             } else if (scaselesscmp(key, "filename") == 0) {
                 if (wp->uploadVar == 0) {
                     websError(wp, HTTP_CODE_BAD_REQUEST, "Bad upload state. Missing name field");
@@ -241,7 +241,7 @@ static void processUploadHeader(Webs *wp, char *line)
                     Create the file to hold the uploaded data
                  */
                 wfree(wp->uploadTmp);
-                if ((wp->uploadTmp = websTempFile("/var/tmp", "tmp")) == 0) {
+                if ((wp->uploadTmp = websTempFile(uploadDir, "tmp")) == 0) {
                     websError(wp, HTTP_CODE_INTERNAL_SERVER_ERROR,
                         "Cannot create upload temp file %s. Check upload temp dir %s", wp->uploadTmp, uploadDir);
                     return;

+ 17 - 0
app/goahead-3.6.5/src/web_interface/inc/fw_update.h

@@ -1,6 +1,23 @@
+/*
+	BMC固件更新流程
+1、	调用prepareDevice(wp), 杀死除goahead以外的所有进程
+2、	调用uploadFireware(wp), 开始上传固件到/var/www/goahead/tmp/tmp.uImage
+3、	调用updateFlash(wp), updateFlash会新建一个进程来将tmp.uImage写到Flash里面去。
+4、	循环调用getUpdateProgre(wp),来获取Flash的更新进度,返回百分比。
+5、  等到getUpdateProgress(wp)返回100%时,调用resetBmc(wp),复位BMC让新固件生效。
+
+
+*/
+
 #ifndef __FW_UPDATE_H__
 #define __FW_UPDATE_H__
 
 #include "goahead.h"
 
+void prepareDevice(Webs *wp);
+void uploadFirmware(Webs *wp);
+void updateFlash(Webs *wp);
+void getUpdateProgress(Webs *wp);
+void resetBmc(Webs *wp);
+
 #endif /* __FW_UPDATE_H__ */

+ 173 - 0
app/goahead-3.6.5/src/web_interface/src/fw_update.c

@@ -0,0 +1,173 @@
+#include    "goahead.h"
+#include    "libipmi_IPM.h"
+#include    "com_IPMIDefs.h"
+#include    "ResultUtils.h"
+#include    "cJSON.h"
+#include    "libipmi_storlead_OEM.h"
+#include    "libsensor.h"
+#include    <stdio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+static uint8_t progress = 0;
+/* 进入固件更新模式
+* 杀死所有其它进程
+*/
+void prepareDevice(Webs *wp)
+{
+    printf("Update Firmware: Prepare Device...\n");
+    //TODO: kill all other process
+    progress = 0;
+    sleep(1);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    //websWriteHeader(wp, "","prepareDevice");
+    websWriteEndHeaders(wp);
+    //websWrite(wp, "%s", pStr);
+    //websFlush(wp, 0);
+    websDone(wp);
+    printf("Update Firmware: Prepare Device Ok.\n");
+}
+
+/* 接收上传的固件
+*/
+void uploadFirmware(Webs *wp)
+{
+    WebsKey         *s;
+    WebsUpload      *up;
+    char            *upfile;
+   
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteHeader(wp, "Content-Type", "text/plain");
+    websWriteEndHeaders(wp);
+    if (scaselessmatch(wp->method, "POST")) {
+        for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
+            up = s->content.value.symbol;
+            websWrite(wp, "FILE: %s\r\n", s->name.value.string);
+            websWrite(wp, "FILENAME=%s\r\n", up->filename);
+            websWrite(wp, "CLIENT=%s\r\n", up->clientFilename);
+            websWrite(wp, "TYPE=%s\r\n", up->contentType);
+            websWrite(wp, "SIZE=%d\r\n", up->size);
+            upfile = sfmt("%s/tmp/%s", websGetDocuments(), "tmp.uImage"/*up->clientFilename*/);
+            printf("upfile: %s\n", upfile);
+            if (rename(up->filename, upfile) < 0) {
+                error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
+            }
+            wfree(upfile);
+        }
+        websWrite(wp, "\r\nVARS:\r\n");
+        for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) {
+            websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string);
+        }
+    }
+    websDone(wp);
+    printf("Update Firmware: Upload Firmware oK.\n");
+}
+
+/*
+    开始执行固件更新
+    擦除Flash,写Flash
+*/
+void updateFlash(Webs *wp)
+{
+    printf("Update Firmware: Update Flash...\n");
+    //TODO: 
+    
+
+    sleep(1);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    //websWriteHeader(wp, "updateFlash");
+    websWriteEndHeaders(wp);
+    //websWrite(wp, "%s", pStr);
+    //websFlush(wp, 0);
+    websDone(wp);
+}
+
+
+/*
+    获取Flash更新的进度
+    返回 Flash更新的百分比。
+*/
+void getUpdateProgress(Webs *wp)
+{
+    uint8_t progressStr[5] = {0};
+    //TODO: 
+    if(progress < 100)
+        progress++;
+    sprintf(progressStr, "%d%%", progress);
+    printf("Update Firmware: %s\n", progressStr);
+
+    char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON_AddStringToObject(root, "msg", progressStr);
+    cJSON_AddNumberToObject(root, "code", 200);
+    
+
+    pStr = cJSON_PrintUnformatted(root);
+
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    //websWriteHeader(wp, "getUpdateProgress");
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+}
+
+void resetBmc(Webs *wp)
+{
+    printf("Update Firmware: Reset BMC...\n");
+    //TODO: 
+    if(progress < 100)
+        progress++;
+
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    //websWriteHeader(wp, "resetBmc");
+    websWriteEndHeaders(wp);
+    //websWrite(wp, "%s", pStr);
+    //websFlush(wp, 0);
+    websDone(wp);
+}
+
+
+
+
+// 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);
+
+// }