Author Topic: Firmware download  (Read 4210 times)

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Firmware download
« on: July 16, 2012, 01:46:59 PM »
Hi,

Firmware can easily been update through FTP or HTTP, but is there a way to get the firmware back ?
Using a specific command I want to read back the firmware, but how can I do to have the correct format with MagicNumber and CRC as µTaskerConvert does.


Regards



Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3069
    • View Profile
    • uTasker
Re: Firmware download
« Reply #1 on: July 16, 2012, 04:05:43 PM »
Hi Hervé

When the new firmware is copied it is stored in a temporary location together with an extra header which is checked to verify that it is a suitable software version. After the content has been copied to Flash the backup is deleted, otherwise it wouk be reloaded each time the board starts.

If you want to copy the software back you would need to see it as a file (or else the application would have to handle it in a manner to make it look like a file). One possibility would be to use an User File System entry that is generated by the application on startup with its length (maybe it coudl simply count the amount of content before a number of 'xff are foudn in Flash) and then it coudl be retrieved by using FTP or HTTP as well. I would then use the retrieved binary as input to uTaskerCovert to generate an uploadable format again.

If you would prefer the format to correspond to the original upload format the application woudl need to add the header by treating the content with the same algorithms used by uTaskerConvert.

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: Firmware download
« Reply #2 on: July 18, 2012, 03:32:40 PM »
Thanks Mark,

I test the download with that code :

Code: [Select]
static const CHAR gen_firm[]  = "µH00";                              // command to get back the firmware
static const CHAR gen_bmp[]  = "µH20";                               // command to generate a BMP from the present LCD display content

static const USER_FILE user_files[] = {
    {"favicon.ico", (unsigned char *)_favicon, sizeof(_favicon), MIME_ICON, FILE_VISIBLE},
    {"index.htm", (unsigned char *)start_page, sizeof(start_page), MIME_HTML, FILE_VISIBLE},
    {"LCD.BMP", (unsigned char *)gen_bmp, sizeof(gen_bmp), MIME_HTML, FILE_INVISIBLE},
    {"SOFT.BIN", (unsigned char *)gen_firm, sizeof(gen_firm), MIME_HTML, FILE_INVISIBLE},  //MIME_HTML car il faut générer le bin...
    {0}                                                                  // end of list
};
So I can use a web browser to get http://192.168.167.223/SOFT.BIN
Code: [Select]
        if (*ptrBuffer == '0') {
ulong TotalSize = (long)Image$$ER_IROM1$$Length +  (long)Image$$RW_IRAM1$$RW$$Length;
        int Idx = 0;
LENGTH_CHUNK_COUNT Chunk = (TxLength - 1);                   // the present chunk reference

            http_session->ucDynamicFlags |= GENERATING_DYNAMIC_BINARY;   // ensure the HTTP server knows that we are generating binary content
            if (Chunk > TotalSize/256) {                        // after generating all file stop
                return 0;
            }

            *usLengthToSend = 256;                                       //  {21}
            if (Chunk == (TotalSize/256)) {                       // signal last chunk to ensure that no padding is added
                http_session->ucDynamicFlags |= LAST_DYNAMIC_CONTENT_DATA;
            }
cPtr = cValue;
            while (Idx < 256) {                                            // {21}
                *cPtr++ = * (char *)((long)Image$$ER_IROM1$$Base + (Chunk*256) + Idx);
                Idx++;
            }
            *usLengthToSend = (cPtr - cValue);                           // length of code to insert*/
  return cValue; 
        }

It works fine, even if I got problem to know exactly the end of the image due to compressed zone on memory. But that's it!

I think I could add ulCodeLength, usMagicNumber and usCRC at the beginning of the transmission, to form the header.

I have only a strange behaviour : when I try to get SOFT.BIN it does not work.... If I try with SOFT.BINN or SOFT.BINOOO, It works !!!!
Is there a detection of BIN file excepting from MIME_TYPE ?

Regards

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3069
    • View Profile
    • uTasker
Re: Firmware download
« Reply #3 on: July 23, 2012, 09:24:10 PM »
Hi Hervé

I can't explain this - do you have any more information in the meantime?

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: Firmware download
« Reply #4 on: July 26, 2012, 03:35:09 PM »
Hi Mark,

Sorry but now it works even with .BIN extension, I don't know what could have happened.

Now I've done the same to get the parameter area in a file....
But go problem to upload it back, as is not stored in the file system....

Thanks.
Hervé