Skip to content

Commit

Permalink
UPDATE: Need to insert sd card when using swupdate to upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyi0421 committed Mar 5, 2023
1 parent 18c8fb8 commit cb52530
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
54 changes: 39 additions & 15 deletions app/bmc/webserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Binary file not shown.
Binary file modified br2t113pro/board/100ask/dragon/sys_partition.bin
Binary file not shown.
11 changes: 5 additions & 6 deletions br2t113pro/board/100ask/dragon/sys_partition.fex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ size = 16384

[partition]
name = boot-resource
size = 34438
size = 8192
downloadfile = "boot-resource.fex"
user_type = 0x8000

Expand All @@ -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

Expand All @@ -85,4 +85,3 @@ size = 16384
[partition]
name = UDISK
user_type = 0x8100

0 comments on commit cb52530

Please sign in to comment.