Download a file for firmware upgrade

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Download a file for firmware upgrade

Giuseppe Modugno
I have a device running lwip stack and httpd server. The device has an
external 2MB SPI Flash memory. The CPU is a microcontroller with 512kB
internal Flash.

I'd like to upgrade the firmware (the internal Flash memory) by download
the new binary from Internet. The user can check the presence of a new
firmware version through the web pages answered from httpd.

When the user activates the remote upgrade, the device should download
the binary file from a server and save it to the external Flash memory.
After a reboot, the bootloader detects the new firmware on the external
memory and copy it to the internal Flash memory.

Now I don't know how to download a file from Internet. FTP client? HTTP
client? Any other protocol? I'd like to use a standard server (FTP,
HTTP, ...), anyway this isn't a must.

Please, give me a suggestion. Thank you.



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Ajay Bhargav (SiWi)

HTTP is easier to do.

 

  1. Open TCP Socket with ip and 80 port (or any other where HTTP service is running)
  2. Send a Get request to server
    GET /filename.ext HTTP/1.0<cr><lf>
    Host: hostname<cr><lf>
    <cr><lf>
    Hostname is required incase HTTP server has multiple virtual hosts.
  3. In response you will get HTTP headers and after then data.

You can try all of above using a simple telnet connection from console to server for testing purpose.

 

Regards,

Ajay Bhargav

 

From: [hidden email]
Sent: Monday, May 21, 2018 5:02 PM
To: [hidden email]
Subject: [lwip-users] Download a file for firmware upgrade

 

I have a device running lwip stack and httpd server. The device has an

external 2MB SPI Flash memory. The CPU is a microcontroller with 512kB

internal Flash.

 

I'd like to upgrade the firmware (the internal Flash memory) by download

the new binary from Internet. The user can check the presence of a new

firmware version through the web pages answered from httpd.

 

When the user activates the remote upgrade, the device should download

the binary file from a server and save it to the external Flash memory.

After a reboot, the bootloader detects the new firmware on the external

memory and copy it to the internal Flash memory.

 

Now I don't know how to download a file from Internet. FTP client? HTTP

client? Any other protocol? I'd like to use a standard server (FTP,

HTTP, ...), anyway this isn't a must.

 

Please, give me a suggestion. Thank you.

 

 

 

_______________________________________________

lwip-users mailing list

[hidden email]

https://lists.nongnu.org/mailman/listinfo/lwip-users

 


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Sergio R. Caprile
In reply to this post by Giuseppe Modugno
You can do whatever you want.
The question is probably not what can you do but what do you have
available to obtain what you need with lesser effort.
There are FTP clients around, I've collaborated in one of them using the
RAW API, search the list.
FTP is sometimes tricky and can give you some headaches with firewalls
(and/or admins).
For HTTP you need a client. I wouldn't just GET and hope everything is
fine unless I can manage both ends (that means: the server too) and
guarantee there won't be other stuff than my file. A HTTP client can be
quite complicated, but you just need to get one resource at a specific URI
You can even have a proprietary protocol running over TCP or UDP. If
your device will be sold and installed on corporate networks, you might
raise some concern among the net admins, asking to have open holes in
the firewall does not seem to be a good way to make friends.

My bet is to go for the user to upload the file, leveraging your web
server; but if you must go out and get it, then perhaps FTP is the
easiest full client and HTTP is the simplest firewall piercing. I don't
know if there are running clients around. Particularly for your API,
which you don't say. (I'm intentionally not considering TFTP for going
out because of the possible firewall issue, but if it is your network,
there is a client already available)

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Jim Pettinato
One other possibility you might want to consider is to implement an FTP (or TFTP) _server_, rather than a client, on your lwIP device; this allows for push updates if desired. The user can then (optionally) accept the new image for installation locally. Down side is that this is even trickier as far as piercing firewalls, since end users would need to allow external ftp access to the device in the field or use a local ftp client from behind the firewall to download the update to the lwIP device.


-----Original Message-----
From: lwip-users [mailto:lwip-users-bounces+jim.pettinato=[hidden email]] On Behalf Of Sergio R. Caprile
Sent: Monday, May 21, 2018 8:26 AM
To: [hidden email]
Subject: Re: [lwip-users] Download a file for firmware upgrade

You can do whatever you want.
The question is probably not what can you do but what do you have available to obtain what you need with lesser effort.
There are FTP clients around, I've collaborated in one of them using the RAW API, search the list.
FTP is sometimes tricky and can give you some headaches with firewalls (and/or admins).
For HTTP you need a client. I wouldn't just GET and hope everything is fine unless I can manage both ends (that means: the server too) and guarantee there won't be other stuff than my file. A HTTP client can be quite complicated, but you just need to get one resource at a specific URI You can even have a proprietary protocol running over TCP or UDP. If your device will be sold and installed on corporate networks, you might raise some concern among the net admins, asking to have open holes in the firewall does not seem to be a good way to make friends.

My bet is to go for the user to upload the file, leveraging your web server; but if you must go out and get it, then perhaps FTP is the easiest full client and HTTP is the simplest firewall piercing. I don't know if there are running clients around. Particularly for your API, which you don't say. (I'm intentionally not considering TFTP for going out because of the possible firewall issue, but if it is your network, there is a client already available)

_______________________________________________
lwip-users mailing list
[hidden email]
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.nongnu.org_mailman_listinfo_lwip-2Dusers&d=DwICAg&c=r_B2dqKkHczsuXPCSs5DOw&r=Ff303RP2ju9wUSYL2P1cGBtEK1syDf_ObW5leLha8yo&m=jjKDeebeofzLWM681_xyPLTIThzG-yCWeqOY0iP60bQ&s=8gfOdSZx85KndNC1SLnLV6jnsOguG69x_OqWqEfi5IY&e=

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Giuseppe Modugno
In reply to this post by Sergio R. Caprile
Il 21/05/2018 14:26, Sergio R. Caprile ha scritto:

> You can do whatever you want.
> The question is probably not what can you do but what do you have
> available to obtain what you need with lesser effort.
> There are FTP clients around, I've collaborated in one of them using the
> RAW API, search the list.
> FTP is sometimes tricky and can give you some headaches with firewalls
> (and/or admins).
> For HTTP you need a client. I wouldn't just GET and hope everything is
> fine unless I can manage both ends (that means: the server too) and
> guarantee there won't be other stuff than my file.

I couldn't understand your concerns about a minimalistic HTTP client
that opens that TCP connection, sends the GET request and wait for the
response (as Ajay suggested).

 > A HTTP client can be quite complicated, but you just need to get one
 > resource at a specific URI

I know a full HTTP client is a very complex piece of code, but I only
need to download a specific URI.


> You can even have a proprietary protocol running over TCP or UDP. If
> your device will be sold and installed on corporate networks, you might
> raise some concern among the net admins, asking to have open holes in
> the firewall does not seem to be a good way to make friends.

I know, but I'd prefer to avoid this approach.


> My bet is to go for the user to upload the file, leveraging your web
> server;

This is a good suggestion.  However the original question arises again:
how to upload a file to the Web server?  Should I use Javascript/jQuery
to choose and send a local file to httpd through POST method (that I'm
not actually using)?


> but if you must go out and get it, then perhaps FTP is the
> easiest full client and HTTP is the simplest firewall piercing.

I think a minimalistic HTTP GET request should be enough.


> I don't
> know if there are running clients around. Particularly for your API,
> which you don't say. (I'm intentionally not considering TFTP for going
> out because of the possible firewall issue, but if it is your network,
> there is a client already available)

No, the firmware binary file will be on the public Internet and the
device will be behind a NAT router... usually.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Ajay Bhargav (SiWi)

The minimalistic Get request I mentioned uses HTTP 1.0 not 1.1 because as you go to HTTP v1.1 server may send chunked encoding which is hard to decode and handle unless you use a good processing library something like:

https://github.com/h2o/picohttpparser.git

 

I used this parser in one of my project and it works great handling chunked encoding or any kind of HTTP response. But Since your requirement is simpler enough, I would suggest you stick with HTTP v1.0 and send get request as I mentioned. You will also get Content-Length in header which tells you size of file being downloaded.

 

Regards,

Ajay Bhargav

 

From: [hidden email]
Sent: Monday, May 21, 2018 6:18 PM
To: [hidden email]
Subject: Re: [lwip-users] Download a file for firmware upgrade

 

Il 21/05/2018 14:26, Sergio R. Caprile ha scritto:

> You can do whatever you want.

> The question is probably not what can you do but what do you have

> available to obtain what you need with lesser effort.

> There are FTP clients around, I've collaborated in one of them using the

> RAW API, search the list.

> FTP is sometimes tricky and can give you some headaches with firewalls

> (and/or admins).

> For HTTP you need a client. I wouldn't just GET and hope everything is

> fine unless I can manage both ends (that means: the server too) and

> guarantee there won't be other stuff than my file.

 

I couldn't understand your concerns about a minimalistic HTTP client

that opens that TCP connection, sends the GET request and wait for the

response (as Ajay suggested).

 

> A HTTP client can be quite complicated, but you just need to get one

> resource at a specific URI

 

I know a full HTTP client is a very complex piece of code, but I only

need to download a specific URI.

 

 

> You can even have a proprietary protocol running over TCP or UDP. If

> your device will be sold and installed on corporate networks, you might

> raise some concern among the net admins, asking to have open holes in

> the firewall does not seem to be a good way to make friends.

 

I know, but I'd prefer to avoid this approach.

 

 

> My bet is to go for the user to upload the file, leveraging your web

> server;

 

This is a good suggestion.  However the original question arises again:

how to upload a file to the Web server?  Should I use Javascript/jQuery

to choose and send a local file to httpd through POST method (that I'm

not actually using)?

 

 

> but if you must go out and get it, then perhaps FTP is the

> easiest full client and HTTP is the simplest firewall piercing.

 

I think a minimalistic HTTP GET request should be enough.

 

 

> I don't

> know if there are running clients around. Particularly for your API,

> which you don't say. (I'm intentionally not considering TFTP for going

> out because of the possible firewall issue, but if it is your network,

> there is a client already available)

 

No, the firmware binary file will be on the public Internet and the

device will be behind a NAT router... usually.

 

_______________________________________________

lwip-users mailing list

[hidden email]

https://lists.nongnu.org/mailman/listinfo/lwip-users

 


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Sergio R. Caprile
In reply to this post by Sergio R. Caprile
Concerns for just GETting: well, the server might return anything other
than 200 due to a number of reasons. Besides what Ajay himself mentions,
if I'm correct, 'host' is not an HTTP/1.0 header, and so behaviour would
be implementation dependent.
If you can manage the server you can make sure you always server what
you intend to. If you feel comfortable with a minimum GET then go ahead;
I'm not fond of those approaches as not implementing the standard some
times has unexpected outcomes. It is just my opinion. My bet would be to
first try that picohttpparser Ajay mentions.

Uploading: I'm no expert on the app tree httpd server, but you can
always do that if you have CGI support, which it does have. There is no
absolute need of a client side script, just a simple form POSTing
multipart will instruct the client to open a file requester to choose
the file, something like:
<html>
<head><title>Multipart POST</title></head>
<body>
<H1>File upload</H1>
<form ACTION="fileupload.cgi" METHOD="POST" enctype="multipart/form-data">
<table>
<tr><td>Filename
<td><input TYPE="TEXT" NAME="text" size=10 value="failneim">
<td><input TYPE="FILE" NAME="filename" SIZE=10>
</table>
<input TYPE="SUBMIT" VALUE="Upload!">
</form>
</body>
</html>
will do.
Of course a JS is nicer...
The user has to get the file first and then upload to the device. Not
latest technology, I know, you can do better with scripting.
The CGI itself is strongly dependent on the server, unfortunately.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Download a file for firmware upgrade

Sergio R. Caprile
BTW, there is an http_client in the apps subtree...
Perhaps your problem is solved ? Regards

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users