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

Boot loader working and why

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



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Boot loader working and why
PostPosted: Wed Sep 19, 2007 2:23 pm     Reply with quote

Some points I learned along the way to making a bootloader.

I started with theByteFactory bootloader becasue it was in C and I had space for it. I then replaced the communication code with my version based very loosely on the CCS loader.c .
A note about loader.c it's a good starting point, but some things are in the wrong order. There is no error checking and it needs a lot of work. I think I ended up with about 5 of the original lines of code... !

I added dedicated protocol to allow re-sending is a line of the hex file if it did not come across as it should have. As the serial connection is by wireless (blue teeth) there is a possibility of losing a connection or getting corrupted reception.

I changed the way data is written and simply write a block (lines worth of the hex file) at a time.
Take Note:
Make sure when writing less than getenv("FLASH_WRITE_SIZE") that you do this : read a block of getenv("FLASH_WRITE_SIZE") size / then modify the read data with the data you need to write / and then write back the entire block.

Also take care of statements at the end of the hex file.
I'm using the PIC18F6720 one of the early Erratas said to insert two 0XFF and move the reset vector up two bytes. That complicated things. take care when reaching the end of the hex file you may find instruction to write FF's at address zero... ! Be careful not to clobber the first few bytes, this was an early mistake. !

Finally the reason it now works:
Between the bootloader reset vector and the application vector there should be FFs and after the interrupt vectors there should be 00's.

It's not enough to re-create the vector values you must re-create the the rest of the first few bytes exactly as they originally were in the application hex file.

All this is complicated by the fact that some chips have a getenv("FLASH_ERASE_SIZE"); size greater than the getenv("FLASH_WRITE_SIZE"); size so that has to be taken into account.
It's described in the CCS help for write_program_eeprom()

Performance could be improved a little but loading 120K of code via a bootloader takes time. If I increase the block write to 64 bytes it may take less time. The slow down is not having interrupt driven comms.. in the bootloader. so small delay between bytes that are sent by the PC is needed to avoid data loss.

Once again thanks to everyone for the help.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Sep 20, 2007 4:06 am     Reply with quote

Thank you, Hans, for sharing us your experience, let me add some thoughts. I have also written a bootloader based on theByteFactory's into a 18F25J10.
The speciality of this chip is the 1024 bytes of erase block size and 64 bytes of write block size. and a RAM size of only 1024 bytes. So in lack of RAM I did not have the possibility to read a block into RAM, modify it and write it back. So I came to an assumption that a .hex file defines data in a sequence of strictly increasing memory addresses. So I do not read the erase-block, just write them in sequence. (you might get a speed increase doing so, with the caveat of never having a hex file jumping back-and-forth in memory addresses)

Re: delay between characters. I use a buffer that stores one line of a hex file with no extra operations required between the arriving bytes in the same line. Lines are getting processed only after CR has arrived. So a delay (I use 10ms) only after each line and no (or a very short) delay between the characters is OK for me. (this would mean a speed increase for you also, I think)
Guest








PostPosted: Thu Sep 20, 2007 1:32 pm     Reply with quote

libor wrote:
Thank you, Hans, for sharing us your experience, let me add some thoughts. I have also written a bootloader based on theByteFactory's into a 18F25J10.
The speciality of this chip is the 1024 bytes of erase block size and 64 bytes of write block size. and a RAM size of only 1024 bytes. So in lack of RAM I did not have the possibility to read a block into RAM, modify it and write it back. So I came to an assumption that a .hex file defines data in a sequence of strictly increasing memory addresses. So I do not read the erase-block, just write them in sequence. (you might get a speed increase doing so, with the caveat of never having a hex file jumping back-and-forth in memory addresses)

Re: delay between characters. I use a buffer that stores one line of a hex file with no extra operations required between the arriving bytes in the same line. Lines are getting processed only after CR has arrived. So a delay (I use 10ms) only after each line and no (or a very short) delay between the characters is OK for me. (this would mean a speed increase for you also, I think)

Sure if the hex file only increases in the address you are safe.
But if you have special cases then the CCS compiler puts some lower address stuff at the end of the hex file, which means you must do a read/modify/write.
Of course that can be adjusted by editing the file, but I wanted to avoid that.
OK about speed increase, yes there is plenty of room to experiment. Next thing it to put the boot loader at bottom end of memory and take advantage of block block read/write protect to be able to keep my code private. That's another disadvantage of putting the boot loader high.
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