Page 1 of 2
reprogramming
Posted: Thu Dec 09, 2021 1:24 pm
by SeeCwriter
In v2.9.5 apps with a NANO and MOD5441X, there is a task that listens for a tcp connection to get a new firmware image. After accepting the connection function ReadS19ApplicationCodeFromStream( fd ) is called to get the image and reprogram the module. Works great.
For my v3.3.5 app using a NANO, I took that same task and replaced ReadS19ApplicationCodeFromStream( fd ) with ReadBinaryApplicationCodeFromStream( fd ). The image is downloaded and the function returns with a STREAM_UP_OK code, indicating success. The module reboots and I get this output in the serial terminal:
Code: Select all
Waiting 2sec to start 'A' to abort
Decomp Failed
Configured IP = 0.0.0.0
Configured Mask = 0.0.0.0
MAC Address= 00:03:f4:0e:e9:c1
Boot config valid
nb>Welcome to the Netburner Alternate Boot Monitor Command Program
Starting Monitor...
NetBurner MCF5441x Alternate Image Monitor v1.05 Jul 17 2020 11:10:04
HELP for help
nb>
Is that function not the right one to use?
Re: reprogramming
Posted: Thu Dec 09, 2021 4:00 pm
by pbreed
There is extra stuff in the bin beyond just the simple binary image.
It is prefixed with the platform definition...
1)Why are you doing this instead of just using the built in TCP stream update?
2)We should probably fix the readBinaryfrom stream so it ginores the platform stuff...
To do what you want...
Open the tcp connection...
call it fd...
if( SocketPeek(fd)=='S')
{
char c=' ';
while(c!='\n')
{
read(fd,&c,1);
}
}
Now give the fd to ReadFromStream....
That should work...
Re: reprogramming
Posted: Fri Dec 10, 2021 7:01 am
by SeeCwriter
We have customers that have hundreds of our product fielded and when they need a firmware update they don't want to have to use a utility, such as Autoupdate, or a webpage, to program them individually. Using the discovery webpage for v3.x products could probably work without actually opening a webpage, I just don't know how to explain it or even flowchart it in enough detail that a third party could write code to do it.
On your workaround, how can you test for an ascii character in binary data?
Is this what you mean?
Code: Select all
void tcp_reprogram( void *pd )
{
static IPADDR address;
static int listen_repro = listen( INADDR_ANY, (WORD) TCP_REPRO_PORT, 1 );
while ( true )
{
// This blocks until a connection request is made.
int fd = accept( listen_repro, &address, NULL, 0 );
if ( fd > 0 )
{
if ( SocketPeek(fd) == 'S' )
{
char c = ' ';
while ( c != '\n' ) read( fd, &c, 1 );
if ( ReadBinaryApplicationCodeFromStream( fd ) == STREAM_UP_OK )
{
writestring( fd, "Success!" );
OSTimeDly( TICKS_PER_SECOND );
close( fd );
ForceReboot();
}
writestring( fd, "Failed!" );
OSTimeDly( TICKS_PER_SECOND );
close( fd );
}
close( fd );
}
}
}
Re: reprogramming
Posted: Sat Dec 11, 2021 3:37 pm
by pbreed
Yes that was basically what I was recomending...
What tool presently opens the TCP connection and sends the file in your environment?
To use the 3.0 builtin update...
can use :
NBUPDATE command line tool.
WGET common tool to post a file..
Any library that supports a http post...
Write a routine from scratch... (Could steal from out NBUDATE tool)
basically just send a normal HTTP post to the correct url and include the file...
You could probably just use the tool you have now unmodified with the following:
Connect to port 20043. (Instead of whatever port your connecting to)
Copy some text to the beginning of the file that looks like an HTTP Post ...
If you want help with any of these let me know...
Re: reprogramming
Posted: Mon Dec 13, 2021 7:11 am
by SeeCwriter
I was not aware of nbupdate. I tried it and that might be all I need. What about feedback to the user? The utility outputs two strings to the console, one labeled uriReq, and one urlStr, which are identical, then the number 200. But there is nothing to indicate whether the reprogramming was successful or not. I can see that the NANO returns an HTTP packet that contains "Program Successful", but only the utility sees that.
Re: reprogramming
Posted: Tue Dec 14, 2021 2:59 pm
by pbreed
200 was success....
You could also modify nbupdate to do whatever... source is provided...
Re: reprogramming
Posted: Mon Dec 20, 2021 11:19 am
by SeeCwriter
I shared with our customer how they can program the module via the module's webpage or with the nbupdate utility. They are not interested in those methods. They want to write their own code to update firmware. So I captured the reprogramming process with wireshark and wrote a description of how to do it themselves using an HTTP Post and included http packets. Their next question is, "how much of the HTTP Post is required?" This is the Post that kicks off the process:
POST /appupdate.htm HTTP/1.1\r\nHost: 10.250.5.53:20034\r\nUser-Agent: Go-http-client/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip\r\n\r\n
I assume it's all required.
Re: reprogramming
Posted: Mon Dec 20, 2021 3:17 pm
by pbreed
Can they use WGET? (Can run from bash, batch file or any shell )
What platform are they doing it on and what source code language...
Tell me the platform and their dev environment and I'll make you an example.
Do you want encryption or username/password?
Re: reprogramming
Posted: Tue Dec 21, 2021 11:35 am
by SeeCwriter
I asked about their platform but they are being tight-lipped. They aren't giving up any details of their equipment. They are probably using Linux, but that is just a guess. And they aren't interested in using wget, the config webpage, or any utilities to do the reprogramming.
A few posts ago, I mentioned that I tried using function ReadBinaryApplicationCodeFromStream to read in an image file via a tcp connection. Reading the file from a tcp connection worked, and it was written to flash but apparently the image as received can't be used. Which is surprising since that function is used in an example app that reprograms a module by reading an image file from an sd drive. Is the format of an image on an sd drive different than what would be sent over a tcp connection?
Is there a version of ReadBinaryApplicationCodeFromStream that could be used with a tcp connection?
There is no requirement for encryption, usernames, passwords, or image signing, at this time. There was requirement for this, but they have backed off those requirements because too many other vendors they are using had a problem implementing them.
Using v3.3.5 on a NANO.
Re: reprogramming
Posted: Tue Dec 21, 2021 12:37 pm
by pbreed
ReadBinaryApplicationCodeFromStream is currently broken on Nano and SB800... we need to fix this, but as of today its broken.
Open TCP connection to 20034
send
POST /appupdate.html\r\n\r\n
<Contents of compiledapp.bin>
That should do the update... You can search for either
"200" or "Program Successful" in the returned TCP data after the send either one is indicative of success...
I just tried this as follows:
wrote
POST /appupdate.html\r\n\r\n to a file (header.txt).
I looked at the file with hex editor to make sure it had only a \r\n\r\n at the end and nothing else.
Then
copy /b Header.txt+TestApp.bin Combine.bin
Then used out utility TcpSendFile..
(My device was at 10.1.1.99)
TcpSendFile Combine.bin 10.1.1.99 20034
This worked...