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

Loader.c Question

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Loader.c Question
PostPosted: Wed Apr 03, 2019 10:05 am     Reply with quote

In the CCS example code loader.c

Once the addr has been constructed the line which tests the addr seems to allow write to the bootloader area ! which could overwrite the bootloader...

Code:

if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < getenv("PROGRAM_MEMORY"))
                     


Is this correct ?

To protect the bootloader I suggest it it should be:

Code:

if ( addr > LOADER_END && addr < getenv("PROGRAM_MEMORY"))
                     


Or did I miss something ?

Added Question:
Am I correct in thinking if I use the suggested code change it should also protect the interrupt vector table ... I'm using the PIC18F47K42
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed Apr 03, 2019 10:23 am     Reply with quote

Think about it. What happens if it is between LOADER_ADDR, and
LOADER_END?. The result will be _false_ so it won't save the data.

addr has to be < LOADER_ADDR _or_ greater than LOADER_END for
the result to ever be 'TRUE'. So if it is between LOADER_ADDR and
LOADER_END, the result will always be false.

It is done this way, to be able to cope both with bootloaders at the
start of memory, and ones that are at the end of memory. Your test
would not allow these later type to work....
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Apr 03, 2019 10:31 am     Reply with quote

Ttelmah wrote:
Think about it. What happens if it is between LOADER_ADDR, and
LOADER_END?. The result will be _false_ so it won't save the data.

addr has to be < LOADER_ADDR _or_ greater than LOADER_END for
the result to ever be 'TRUE'. So if it is between LOADER_ADDR and
LOADER_END, the result will always be false.

It is done this way, to be able to cope both with bootloaders at the
start of memory, and ones that are at the end of memory. Your test
would not allow these later type to work....


Good point.
For me I'm only considering bootloader at start of memory.
I recently had a BL failure during loading and can't figure out how it failed other then a bad write...

So doing only BL at start my suggestion should protect the BL code and interrupt vector table.

I guess this will work so long ad the interrupt code reside at the same locations for each update.
May be I should ORG the ISR's ?

Any suggestions ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed Apr 03, 2019 10:42 am     Reply with quote

Now, PIC's with vector tables are new/rare beasties (for PIC16/18's).
Not sure how the bootloader IRQ relocation will work for these. I'd
suspect CCS will have coded it to generate a relocation for every vectpr,
and it's relocation code is part of the bootloader, so it'll automatically
be protected, and the 'real' table will be part of the loaded code.
The key thing that makes the location test 'work' of course is it's use
of brackets, so it tests if the location is below the start or above the end,
and then combines the result of this with the test for being below the
end of memory.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Apr 03, 2019 10:59 am     Reply with quote

Ttelmah wrote:
Now, PIC's with vector tables are new/rare beasties (for PIC16/18's).
Not sure how the bootloader IRQ relocation will work for these. I'd
suspect CCS will have coded it to generate a relocation for every vectpr,
and it's relocation code is part of the bootloader, so it'll automatically
be protected, and the 'real' table will be part of the loaded code.
The key thing that makes the location test 'work' of course is it's use
of brackets, so it tests if the location is below the start or above the end,
and then combines the result of this with the test for being below the
end of memory.


Thanks.... Still concerned as to why the BL failed. I've been using the CCS loader in other pics for years and not had any issues at all even with COMs loss the BL just restarts.

Of course I've tested this 47K46 BL by breaking COMs in the middle of a load session and have always been able to start over.

Any suggestions ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Thu Apr 04, 2019 2:56 am     Reply with quote

Can you describe more about the failure?. What happened?.
47K46?. No such chip....
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