From cb52530d262c6b52e989da8f5f450fe1fc60c71d Mon Sep 17 00:00:00 2001 From: wenyi Date: Sun, 5 Mar 2023 22:28:11 +0800 Subject: [PATCH] UPDATE: Need to insert sd card when using swupdate to upgrade --- app/bmc/webserver.c | 54 +++++++++++++----- .../board/100ask/dragon/sys_partition-bak.bin | Bin 2048 -> 0 bytes .../board/100ask/dragon/sys_partition.bin | Bin 3072 -> 3072 bytes .../board/100ask/dragon/sys_partition.fex | 11 ++-- 4 files changed, 44 insertions(+), 21 deletions(-) delete mode 100644 br2t113pro/board/100ask/dragon/sys_partition-bak.bin diff --git a/app/bmc/webserver.c b/app/bmc/webserver.c index 57c2b417..5bbc240e 100755 --- a/app/bmc/webserver.c +++ b/app/bmc/webserver.c @@ -410,6 +410,7 @@ static int get_ubi_num(void) return ret; } +static const char* swupdate_file = "/mnt/sdcard/update.bin"; static int swupdate_cmd(void) { char cmd[256] = {0}; @@ -422,7 +423,7 @@ static int swupdate_cmd(void) printf("error\n"); return -1; } - snprintf(cmd,sizeof(cmd),"swupdate -i %s -e stable,upgrade_ubi%d",updateFilePath,ver); + snprintf(cmd,sizeof(cmd),"swupdate -i %s -e stable,upgrade_ubi%d",swupdate_file,ver); FILE* pp = popen(cmd,"r"); if(pp) { @@ -482,40 +483,61 @@ static int swupdate_cmd(void) printf("--------------UPDATE faild--------------------\n"); } printf("=================system will reboot ====================\n"); + sprintf(cmd,"rm %s",swupdate_file); + system(cmd); sleep(3); system("reboot"); // reboot(); } +static bool isMountSDcard(char* mountPoint) +{ + if(NULL == mountPoint) + return false; + int fd = -1; + char buff[1024]; + if((fd = open("/proc/mounts",O_RDONLY)) < 0) + { + printf("open /proc/mounts error\n"); + return false; + } + while(read(fd,buff,1024)>0) + { + if(strstr(buff,mountPoint)) + { + close(fd); + return true; + } + } + close(fd); + return false; +} + + - //TODO static void uploadFirmware(Webs *wp) { WebsKey *s; WebsUpload *up; + char cmd[128]; char sessionIdBuf[128] = {0}; int sessionIdBufLen = sizeof(sessionIdBuf); -// if (websCheckSession(wp, sessionIdBuf, &sessionIdBufLen) == 0) -// { -// Printf("get wp->session NULL\n"); -// websSetStatus(wp, 401); -// websWriteHeaders(wp, -1, 0); -// websWriteHeader(wp, "Content-Type", "text/plain"); -// websWriteEndHeaders(wp); -// websWrite(wp,"{\"response\":[{\"result\":\"err:login auth\"}]}"); -// websDone(wp); -// return ; -// } - websSetStatus(wp, 200); websWriteHeaders(wp, -1, 0); websWriteHeader(wp, "Content-Type", "text/plain"); -// websWriteEndHeaders(wp); websWriteEndHeaders(wp); + + if(!isMountSDcard("/mnt/sdcard")) + { + websWrite(wp,"{\"response\":[{\"result\":\"err:no sdcard\"}]}"); + websDone(wp); + return ; + } + if (scaselessmatch(wp->method, "POST")) { for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) { up = (WebsUpload*)(s->content.value.symbol); @@ -528,6 +550,8 @@ static void uploadFirmware(Webs *wp) websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string); } } + sprintf(cmd,"mv %s %s;sync",updateFilePath,swupdate_file); + system(cmd); websWrite(wp,"{\"response\":[{\"result\":\"ok\"}]}"); websDone(wp); printf("upload Filename=%s\n",up->clientFilename); diff --git a/br2t113pro/board/100ask/dragon/sys_partition-bak.bin b/br2t113pro/board/100ask/dragon/sys_partition-bak.bin deleted file mode 100644 index 703b7550376e815bc8580912444053d7ffbdb61a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2048 zcmdUw%SyvQ7=@>`g1GcODz0_o!i~5T*CjCt2HGS{l6qOiO+g>Qg)VgC1qDS>P!vH? zP`uz%_!OQ$jZ!3a&ejQOCjWdre3Qv#SfLFmRl%W(y=7~u^lic|V2>=F_=z6|jW|KK zl$WF*u9Q%!hC0h_ka@Qx_epXim^3qwagwtMPS#=_Tc}}<(G(*er{AOwH4!A+&rLn6U$#PT*!FreU+siq#-#+Pg0Io{-9g==W;0B26 zcTD=7kbbA6-&v7oTHkZh?*g36*R;Nuq~8_kcTM`;fMf2zJJRo-^m`!v9>Fo!?}_w# zCjDNDya~et{F-y-^?f7#-U~m|{qj-dsY#{mFih&&jl)#W%lo6#`BfYB+$DMQWlFh0 zJO57M*sXSJ_`8z^4j6pHddDOiRh6xEGryxGOJmH7WwcWC>#6N~aWCV<(U=gDEB)TF bNc(LoficGNmMJwiH9b2cC#!ko-~4<5N*U8c diff --git a/br2t113pro/board/100ask/dragon/sys_partition.bin b/br2t113pro/board/100ask/dragon/sys_partition.bin index b6cd5cfde8b259289790a198f1c11de026fa0432..b882f11e18bf5a9e35c454db2517c73b4d38e43c 100644 GIT binary patch delta 38 rcmZpWXpqwMI5~_xh^e7-@+x*|Muy4n*rg^vVCQ9I*!+%Nhy?)JQwtOT diff --git a/br2t113pro/board/100ask/dragon/sys_partition.fex b/br2t113pro/board/100ask/dragon/sys_partition.fex index 2afc2021..3db72b3d 100644 --- a/br2t113pro/board/100ask/dragon/sys_partition.fex +++ b/br2t113pro/board/100ask/dragon/sys_partition.fex @@ -35,7 +35,7 @@ size = 16384 [partition] name = boot-resource - size = 34438 + size = 8192 downloadfile = "boot-resource.fex" user_type = 0x8000 @@ -54,19 +54,19 @@ size = 16384 [partition] name = boot - size = 35200 + size = 8192 downloadfile = "boot.fex" user_type = 0x8000 [partition] name = rootfs - size = 65536 + size = 81920 downloadfile = "rootfs-ubifs.fex" user_type = 0x8000 [partition] - name = rootfsbak - size = 65536 + name = recovery + size = 81920 downloadfile = "rootfs-ubifs.fex" user_type = 0x8000 @@ -85,4 +85,3 @@ size = 16384 [partition] name = UDISK user_type = 0x8100 -