CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Fault Tolerant bootloader and interrupt vector

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
moutinho



Joined: 12 May 2005
Posts: 31
Location: BRAZIL

View user's profile Send private message Visit poster's website MSN Messenger

Fault Tolerant bootloader and interrupt vector
PostPosted: Tue Jun 28, 2005 8:56 am     Reply with quote

Hi,

I have implemented a bootloader process using a GPRS modem. I am now working on issues related to fault tolerance such as a power failure during the update process.
I intend to change the interrupt vector during the update process and then swap to main() after the process is finished. If any failure happens during the update process, the process is restarted by jumping to bootloader area throught the reset vector.
I have used the write_program_memory() but it seems to erase a large memory area and I only need to replace the beginning four program fash code (GOTO XXXX).
Questions:
1) Is there a way to write only the desired four bytes program into 0x00000 flash location without erasing a large block (4 bytes used + remaining 63 bytes)?
2) Can I change the interrupt vector during program execution ?
3) Do I need to set another configuration such as fuses, etc ?

Thanks,
Andre
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 28, 2005 10:32 am     Reply with quote

Read the datasheet on the PIC that you are using. It will tell you the block size that must be erased. So to answer your question, no you can't just erase 4 bytes.

Why change the interrupt vector at all? Just do a test to see if you are in Bootloader mode. If so, the go HERE Else go THERE.

Can't change the fuses with bootloader.
moutinho



Joined: 12 May 2005
Posts: 31
Location: BRAZIL

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Tue Jun 28, 2005 10:54 am     Reply with quote

Hi,

I can�t do if so, then go HERE else go THERE, because once the memory update process is started, the main code is also updated. If any failure occurs during the main code write, the next reset process will not be able to restart the update process. The memory will be corrupted.

Thanks,
Andre

>
Mark wrote:
Read the datasheet on the PIC that you are using. It will >tell you the block size that must be erased. So to answer your question, >no you can't just erase 4 bytes.

>Why change the interrupt vector at all? Just do a test to see if you are >in Bootloader mode. If so, the go HERE Else go THERE.

>Can't change the fuses with bootloader.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 28, 2005 11:03 am     Reply with quote

Well I can do it so you should be able to as well. You probably don't understand what I mean so I will explain a bit more.

First off, the bootloader never gets changed so it always works (not really, I have a separate way of changing it if I want to but for this purpose it won't change). Now since the bootloader never changes, I should always be able to download new code in the event of a failure if I can enter bootloader mode. Well that is accomplished using a flag that is set and stored in the data eeprom of the device. There are a couple of ways mine can enter bootloader mode but basically they all store a value in the eeprom. On startup, this location is read and if the magic value is there, then I continue with the bootloader if not then I goto main. Notice that I said continue with the bootloader. That means that I always enter bootloader mode first and then decide if I should be in it or not.
moutinho



Joined: 12 May 2005
Posts: 31
Location: BRAZIL

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Tue Jun 28, 2005 11:20 am     Reply with quote

>Notice that I said continue with the bootloader. That means that I >always enter bootloader mode first and then decide if I should be in it or >not

Hi,
This is a good idea. I have thought to do it but I didn�t what to have my main() function application as the bootloader (). There exist a way to tell the compiler to start the execution at another function instead of main() ?

Thanks,
Andre





Mark wrote:
Well I can do it so you should be able to as well. You probably don't understand what I mean so I will explain a bit more.

First off, the bootloader never gets changed so it always works (not really, I have a separate way of changing it if I want to but for this purpose it won't change). Now since the bootloader never changes, I should always be able to download new code in the event of a failure if I can enter bootloader mode. Well that is accomplished using a flag that is set and stored in the data eeprom of the device. There are a couple of ways mine can enter bootloader mode but basically they all store a value in the eeprom. On startup, this location is read and if the magic value is there, then I continue with the bootloader if not then I goto main. Notice that I said continue with the bootloader. That means that I always enter bootloader mode first and then decide if I should be in it or not.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 28, 2005 11:29 am     Reply with quote

You would have 2 mains. Your bootloader main would goto the main of the application.

I used another compiler for my apps that have a bootloader you should be able to accomplish the same thing with this compiler the syntax is just a bit different.
moutinho



Joined: 12 May 2005
Posts: 31
Location: BRAZIL

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Tue Jun 28, 2005 11:33 am     Reply with quote

I will check this.
Thanks
Adnre


Mark wrote:
You would have 2 mains. Your bootloader main would goto the main of the application.

I used another compiler for my apps that have a bootloader you should be able to accomplish the same thing with this compiler the syntax is just a bit different.
bfemmel



Joined: 18 Jul 2004
Posts: 40
Location: San Carlos, CA.

View user's profile Send private message Visit poster's website

Boot Loader Survives Power Interruption
PostPosted: Tue Jun 28, 2005 4:50 pm     Reply with quote

moutinho,

To get the boot loader to survive a power outage or problem during download, the boot loader needs to behave like a separate program but doesn't need to be one.

In the main program, a command to download new code will cause the program to branch to the boot loader which is loaded at the top of the memory area. The first thing the boot loader does when we jump to that routine is to turn off all the interupts and reset the hardware. Then we replace the reset vector to jump to the load routine on startup. That way if the load is interrupted the program will start back at the loader instead of running garbage code. When the new code is installed, the last thing it will do is to replace the reset vector to the start of the new program.
Code:

#define LOADER_END      getenv("PROGRAM_MEMORY")-1

#define LOADER_SIZE        0x900
#define LOADER_ADDR LOADER_END-LOADER_SIZE+1

// Put this ORG statement  at the beginning of the loader routines
// which are in a separate C file
#ORG LOADER_ADDR+0x20, LOADER_END auto=0 default

void real_load_program ( void ) {
   unsigned int16 data[2];

   data[0] = READ_PROGRAM_EEPROM(LOADER_ADDR+0x10);
   data[1] = READ_PROGRAM_EEPROM(LOADER_ADDR+0x12);

   erase_program_eeprom (0x0000);
   write_program_memory(0x0000, data, 4);
. . .
   // get all the bytes from the host and place in memory
   // EXCEPT ! DON'T REPLACE LOADER CODE
. . .
      reset_cpu();
}


You can also have the loader routine return the program revision as 0000 instead of the actual revision. In this way, you will know that the main program is not running on bootup, only the loader.

Hope this helps. Very Happy

- Bruce
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group