This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

function update via bootloader

My firmware support upgrade by means of a bootloader (USB bootloader). I do not wan't to upgrade all the firmware, but only a specific function in the firmware.

My problem with updating all the firmware at once is that if a user removes power from the target while upating, it won't be possible to recover the target unless some form of backup is on the target board or physical re-porgramming of the target with a programmer.

I do not have the option of a backup.

So to be safe, I only want to update the specific function, and after all that is the only thing that will be changed in the firmware.

The function is compiled at an absolute address and does not use any interrupts.

I am faced with several problems.

1.) Is it possible to compile the function by itself, since the function does use other functions from the project? Because if I want to update the function only I will need a HEX file containing the data of the function only.If possible, how do I do this?

2.) What happens if I size of the function changes, will the rest of the project be able to detect the end address of the function. What affect will this have on the stack, PC etc.?

Parents
  • this, to the full extent is HARDWARE dependent. To update a function only, with a backup, you need to have two (multiples of) flash pages. The least you can erase will be a flash page. YES, I know there is "byte updateable flash", but that can crash with a power failure at a precise moment (I have seen that), since the monniker "byte updateable flash" is not what it is, but what it appears to be.

    Describe your hardware.

    Have you considered using serial memory as the backup, whit some intelligence, that can be made power fail safe.

    Erik

Reply
  • this, to the full extent is HARDWARE dependent. To update a function only, with a backup, you need to have two (multiples of) flash pages. The least you can erase will be a flash page. YES, I know there is "byte updateable flash", but that can crash with a power failure at a precise moment (I have seen that), since the monniker "byte updateable flash" is not what it is, but what it appears to be.

    Describe your hardware.

    Have you considered using serial memory as the backup, whit some intelligence, that can be made power fail safe.

    Erik

Children
  • Sorry

    You guys have me wrong.

    I'm not very good with explaining what I'd like to achieve so let me try again.

    My firmware has a function/procedure that needs to be changed regularly. So what I want to do, is, instead of reloading the whole firmware, I just update the sector in flash where the specific function/procedure is located.

    I do not wan't to reload all the firmware because of safety precautions, memory space and a few other reasons. External memory or any kind of backup is not possible. Any ways it wouldn't be neccesarry if I update the function only.

    Because this function changes regularly, I want to be able to compile it on its own instead of compiling all the firmware every time. Then by compiling the function on its own, I get a HEX/OBJ file containing the data of the function ONLY which enables me to upload it to flash where the function is located.

    Example:

    **Project Function Update**

    void main(void) {}

    void Bootloader(void) {}

    void function1(void) {}

    void function2(void) {} //@ 0x3000 in flash

    Function2 is the function that needs to be updated.

    Can this be done, what implications does it have and how do I compile a function by itself when uses resources from the project.

  • You guys have me wrong.
    I do not believe I do

    Can this be done, what implications does it have
    yes, with proper HARDWARE.

    which '51 derivative do you use?
    how much space does the 'permanent' code occupy ?
    how big is the 'replaceable function'
    internal or external code storage (if external - in what)

    Erik

  • Erik Muland -> erikm??

    Anyways

    I'm using a C8051F320 from Silabs.
    My permanent code occupies about 10K of INTERNAL flash.
    The replaceble function does not have a fixed size and will vary depending on what the function does. I can't give you an estimate cause I haven't completed the first one and still need to write a few more.

    There must be a way to achieve this without the need for complex hardware.

    I know a good solid design can save a lot time, money and frustration BUT elegant code and compiler manupilation does magic.

    But give me your thoughts please, that is the reason why I am at this forum.

    Thanks

  • Ok, with a 512 byte page size let's give your 'fixed' code a bit of room to grow, say to 12k. Then if your 'flexible' function is less than 2k it can work. 12k +2k +2k = 16k.

    One way: you set a 'serial number' in the flexfunc and if you call the flexfunc with operation code n it returns the serial number. You read the flexfunc at 12k and the one at 14k set a flag which to use and voila!. Make the flexfunc so that if there is an incomplete write or whatever the serial number is screwed up

    Erik

  • OK, but I have more than 2 functions (many more) say for instance 20 different functions. There won't be enough memory to store 20 functions.

    And what if I want to improve or change a function? That is why I need to be able to change the fucntion by uploading it via a bootloader.

    And then I come back to what I asked. If I want to change or improve a function, how do I compile it so that I obtain a HEX file containing the data of the function only. This allows me to upload only the code of the function and not all the firmware.

    This eliminates the risk of erasing the startup, bootloader and main code functions.

  • And then I come back to what I asked. If I want to change or improve a function, how do I compile it so that I obtain a HEX file containing the data of the function only. This allows me to upload only the code of the function and not all the firmware.

    you can compile the function that won't be a problem, but you can't link it without the rest.

    Here is what I have done in the past:
    - compile and link the app
    - convert it to a binary (HexToBin)
    - ectract your code starting at binoffset 0x3000

    The above will only work if the update funktion is at the end of your code. You will need to write some tools to extract the function. Of course your firmware needs to have some checks if the update is successfull.

    But keep attention:
    var overlaying can very critical in such cases.
    you can not use more vars in your function after the product is delivered unless you have a special mempool reserved for that in your firmware.

    Thomas

  • Hi Thomas

    Good to know there is someone who have tried this before.

    Yes, I thought it would have to be something like this, just maybe there was a way to skip the writing of a tool to extract the required data. But as you say, "but you can't link it without the rest."

    I will make sure that my variables is in place for the overlay process with every function.

    One last question:

    The app knows the start address of the function since I compile it at a fixed address (0x3000). So the calling address of this function is known. But what about the return address, will there be any problems with the overlay process when the function changes in size??

  • But what about the return address, will there be any problems with the overlay process when the function changes in size??

    no that won't be any problem since the return address is poped from the stack.
    One last thing I forgot:
    all used lib functions have to be already in the code.
    You will need a snapshot of your shiped code and have to make sure that no new lib functions will be included. This will be the hardest task I think.

    My approach for the last projects was a bit different:
    I build two different apps update code at 0x0000
    main firmware at 0x2000. With some tests you can ensure that update code is always startable even after a broken download. That will be much more stable if update and firmware resist in different flashpages.

    Thomas

  • Thomas

    you can not use more vars in your function after the product is delivered unless you have a special mempool reserved for that in your firmware.

    How can I reserve a mempool/memory space for future variables?

    MC

  • How can I reserve a mempool/memory space for future variables?
    that depends on the memory you have in reserve
    One way would to declare a array or struct globally in your app with a fixed address. This memory space can then be used in your function.

    Thomas