[fota] add lynq_fota function
Change-Id: I2ed8d4e1383692424c0b36be5c583b635190ea0d
diff --git a/mbtk/include/mbtk/mbtk_fota.h b/mbtk/include/mbtk/mbtk_fota.h
index db55155..8724166 100755
--- a/mbtk/include/mbtk/mbtk_fota.h
+++ b/mbtk/include/mbtk/mbtk_fota.h
@@ -89,6 +89,12 @@
*******************************************************************************/
int mbtk_fota_done(int is_reboot);
+int mbtk_fota_done1(int is_reboot);
+
+
+
+int mbtk_fota_status(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/mbtk/lynq_lib/src/lynq_fota.c b/mbtk/lynq_lib/src/lynq_fota.c
index 049bc08..dfb96be 100755
--- a/mbtk/lynq_lib/src/lynq_fota.c
+++ b/mbtk/lynq_lib/src/lynq_fota.c
@@ -1,9 +1,43 @@
#include "lynq-qser-fota.h"
#include "mbtk_type.h"
+#include "mbtk_fota.h"
+
+
+char addr_buf[128]={0};
+int segment_size =0;
+
+
+int fota_cb(int status, int percent)
+{
+// printf("status: %d, percent: %d%%\n", status, percent);
+ return 0;
+}
int lynq_rock_main(int first_run)
{
UNUSED(first_run);
+ printf("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ printf("addr_buf:%s, segment_size:%d\n", addr_buf, segment_size);
+ ret = mbtk_fota_init(fota_cb);
+ if(!strcmp(addr_buf, "http"))
+ {
+
+ ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
+ }
+ else
+ {
+ ret =mbtk_fota_fw_write(addr_buf, segment_size);
+ }
+
+ if(ret)
+ {
+ printf("lynq_rock_main fail\n");
+ return -1;
+ }
+
+ mbtk_fota_done1(1);
return 0;
@@ -13,20 +47,51 @@
{
UNUSED(value);
UNUSED(size);
+ printf("111%s, %d", __FUNCTION__, __LINE__);
+ if(value == NULL)
+ {
+ return -1;
+ }
+
+ memset(addr_buf, 0, sizeof(addr_buf));
+ memcpy(addr_buf, value, strlen(value));
+ segment_size = size;
+
+ printf("addr_buf:%s, value:%s\n", addr_buf, value);
+ printf("segment_size:%d, size:%d\n", segment_size, size);
return 0;
}
int lynq_fota_nrestart(void)
{
+ printf("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ ret = mbtk_fota_init(fota_cb);
+ if(!strcmp(addr_buf, "http"))
+ {
+ ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
+ }
+ else
+ {
+ ret =mbtk_fota_fw_write(addr_buf, segment_size);
+ }
+
+ if(ret)
+ {
+ printf("lynq_fota_nrestart fail\n");
+ return -1;
+ }
return 0;
}
int lynq_get_upgrade_status(void)
{
+ printf("%s, %d", __FUNCTION__, __LINE__);
- return 0;
+ return mbtk_fota_status();
}
diff --git a/mbtk/mbtk_lib/src/mbtk_fota.c b/mbtk/mbtk_lib/src/mbtk_fota.c
index a26e2a6..424f64d 100755
--- a/mbtk/mbtk_lib/src/mbtk_fota.c
+++ b/mbtk/mbtk_lib/src/mbtk_fota.c
@@ -29,8 +29,10 @@
static struct blob_buf b;
static fota_callback fota_cb = NULL;
sem_t sem;
-volatile int fota_dowload_flag = 0;
-
+volatile int fota_dowload_flag = -1;
+//3: upding
+//4: updata success
+//5: updata fail
enum {
ATTR_SMSGPS,
@@ -96,17 +98,17 @@
notify_str = blobmsg_get_string(tb[ATTR_SMSGPS]);
len = strlen(notify_str);
fota_log("%s : %s\r\n", __FUNCTION__, notify_str);
- printf("L11111%s : %s\r\n", __FUNCTION__, notify_str);
+// printf("L11111%s : %s\r\n", __FUNCTION__, notify_str);
if (strstr_n(notify_str, "start")) {
fota_cb(0, 0);
} else if (strstr_n(notify_str, "end[1]")) {
fota_cb(0, 100);
- fota_dowload_flag = 1;
+ fota_dowload_flag = 4;
// sem_post(&sem);
printf("download firmware success!\r\n");
} else if (strstr_n(notify_str, "end[0]")) {
fota_cb(1, 100);
- fota_dowload_flag = 2;
+ fota_dowload_flag = 5;
// sem_post(&sem);
printf("download firmware fail!\r\n");
}
@@ -140,7 +142,7 @@
*******************************************************************************/
int mbtk_fota_fw_write(char* fname, int segment_size)
{
- fota_dowload_flag = 0;
+ fota_dowload_flag = 3;
printf("mbtk_fota_fw_write start2\n");
int L = 1;
int ret = -1;
@@ -162,23 +164,23 @@
{
if(L == 1)
{
- printf("%s, L:%d", __FUNCTION__,L);
+ // printf("%s, L:%d", __FUNCTION__,L);
L++;
}
/* V2¨´¡Á¡Â */
// sem_wait(&sem);
// break;
- if(fota_dowload_flag != 0)
+ if(fota_dowload_flag != 3)
{
- printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);
+ // printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);
break;
}
}
#endif
- printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);
- printf("mbtk_fota_fw_write end \n");
- if(fota_dowload_flag == 1)
+// printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);
+// printf("mbtk_fota_fw_write end \n");
+ if(fota_dowload_flag == 4)
{
ret = 0;
}
@@ -206,7 +208,7 @@
{
printf("mbtk_fota_fw_write_by_url start1\n");
int ret = -1, L = 1;
- fota_dowload_flag = 0;
+ fota_dowload_flag = 3;
static struct ubus_request req;
int _segment_size;
blob_buf_init(&b, 0);
@@ -226,23 +228,23 @@
{
if(L == 1)
{
- printf("%s, L:%d", __FUNCTION__,L);
+ // printf("%s, L:%d", __FUNCTION__,L);
L++;
}
/* V2¨´¡Á¡Â */
// sem_wait(&sem);
// break;
- if(fota_dowload_flag != 0)
+ if(fota_dowload_flag != 3)
{
- printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);
+ // printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);
break;
}
}
- printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);
- printf("mbtk_fota_fw_write_by_url end \n");
- if(fota_dowload_flag == 1)
+ // printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);
+ // printf("mbtk_fota_fw_write_by_url end \n");
+ if(fota_dowload_flag == 4)
{
ret = 0;
}
@@ -287,6 +289,16 @@
system("reboot");
}
return 0;
+
+}
+
+int mbtk_fota_done1(int is_reboot)
+{
+ if (is_reboot) {
+ system("sync");
+ system("reboot");
+ }
+ return 0;
}
void* mbtk_fota_thread(void* argc)
@@ -351,3 +363,9 @@
return 1;
}
+int mbtk_fota_status(void)
+{
+ return fota_dowload_flag;
+}
+
+
diff --git a/mbtk/test/fota_test.c b/mbtk/test/fota_test.c
index 328222f..0984443 100755
--- a/mbtk/test/fota_test.c
+++ b/mbtk/test/fota_test.c
@@ -2,7 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
-#include "mbtk_audio.h"
+#include "lynq-qser-fota.h"
@@ -25,6 +25,75 @@
while(1)
{
printf("=========fota========2\n"
+ "\t 0 lynq_fota_set_addr_value\n"
+ "\t 1 lynq_rock_main\n"
+ "\t 2 lynq_fota_nrestart\n"
+ "\t 3 lynq_get_upgrade_status\n"
+ "\t 4 Close \n"
+ "=========================\n");
+
+ fflush(stdin);
+ fgets(operator, sizeof(operator), stdin);
+ opt = atoi(operator);
+
+ switch(opt)
+ {
+ case 0://"ql_fota_start"
+ {
+ ret = lynq_fota_set_addr_value("/tmp/updata.bin", 26976256);
+ if(ret)
+ {
+ printf("lynq_fota_set_addr_value failed, ret=%d\n", ret);
+ }
+
+ break;
+ }
+ case 1://"ql_fota_start"
+ {
+ ret = lynq_rock_main(1);
+ printf("lynq_rock_main() ret:%d!\n", ret);
+
+ break;
+ }
+ case 2://"ql_fota_start"
+ {
+ ret = lynq_fota_nrestart();
+ printf("lynq_fota_nrestart() ret:%d!\n", ret);
+
+ break;
+ }
+ case 3://"ql_fota_start"
+ {
+ ret = lynq_get_upgrade_status();
+
+ printf("lynq_get_upgrade_status() ret:%d!\n", ret);
+
+ break;
+ }
+ default://"ql_fota_start"
+ {
+ printf("break\n");
+ return 0;
+ }
+ }
+ }
+ return 0;
+}
+
+
+int main_1(void)
+{
+ int cmdIdx = 0,i=0;
+ int ret = 0;
+ int type_path = 0;
+ char path[256] = {0};
+ char operator[10];
+ int opt = 0;
+
+
+ while(1)
+ {
+ printf("=========fota========2\n"
"\t 0 ql_fota_init\n"
"\t 1 ql_fota_fw_write_by_url\n"
"\t 2 ql_fota_fw_write\n"