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

Functions under same section

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



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

Functions under same section
PostPosted: Wed Oct 10, 2012 12:25 am     Reply with quote

Hi all ,

i m trying to share common modules between bootloader and application code , for that i need to put function s under same section , in general the method to do this is using __attribute__

syntax
int __attribute__((section("sharedFunc"))) shared_function_1(void)
{
}

, when i m using this syntax its throwing error in ccs compiler , so experts may help me to use the correct syntax that should be used with ccs compiler to do the same ..
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 1:11 am     Reply with quote

It is not going to be easy.

CCS, is not at heart a linked compiler. Basically it is single pass, but does now allow external stuff to be linked to some extent.
It does not though allow relocatable 'libraries' as such.
Hence it doesn't support functions like __attribute__.
Also, by default, if a function is only used a few times, the compiler will normally 'inline' them. This is because of the very limited stack space available. When dealing with chip that only allow in some cases half a dozen calls on the stack, calling things more than is needed, can be disastrous.

What you will have to do, is create a _fixed_ 'library'. Decide on a block of memory to hold your shared functions, which is inside the bootloader range, so they won't get destroyed by the bootloader. Then declare the functions in a separate file, using #ORG to place them in this block, and using #EXPORT so their entry points are available to be used by the code. Compile these to form a .o file, then in both the bootloader and the main code, #IMPORT from this.

It is also worth understanding, that some functions _cannot_ be used this way. Things like printf for example, do _not_ compile to generic versions covering all possible values, but deliberately only include the components used be the exact calls made to them. This is done simply because the 'generic' version would be too large to fit in many PIC's. What you can do though is use this for things like maths libraries, but the number of times such libraries should be needed by a bootloader, is very limited.....

Best Wishes
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

chance for bootloader code corruption
PostPosted: Wed Oct 10, 2012 3:35 am     Reply with quote

If we do like this means there is chance to corrupt the bootloader code I think, though we are compiling bootloader and application with shared functions (object file), the application hex file will includes the shared modules which is in the bootloader code address range.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 3:57 am     Reply with quote

Most PIC bootloaders are developed almost totally separately from the applications they will load. Most bootloaders are programmed in assembler, as its often simpler with less 'gotchas' than C, and it can fit into the limited protected bootloader areas available on most PICs.

There is therefore generally NO sharing of code whatsoever between bootloaders and bootloaded applications. There does generally need to be a sharing of processor set-up (i.e. fuses) between loaders and apps, as changing fuses during bootloading, while *possible*, is fraught with problems, often leading to "bricked" PIC due to imcompatible fuse configurations which then have to be reprogrammed from scratch.

So, any bootloader/app combo that uses shared code is almost certainly diagnostic of poor systems design. In reality, there isn't much to share: serial handler (or device for whatever means the bootloader accepts code). Bootloaders generally don't need to deal with interrupts, or at least are much simplified if they don't. So all that you really need to worry about is revectoring reset.

There are many good bootloaders available on the net (and some poor ones no doubt). Some free, other for moderate cost. Reinventing the wheel is not required. There have been many long threads on this forum about C bootloaders, which are difficult to get right, are bloated and generally a poor and expensive substitute for a decent assembler loader.

Also re-read the previous comments. CCS C doesn't have a linker and doesn't have object files. All "library code" is shared at source level, and source level ONLY.

So, maybe you might think about what your requirement really is, and get the system design right to make your job easier, rather than harder.

RF Developer.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

Re: chance for bootloader code corruption
PostPosted: Wed Oct 10, 2012 4:30 am     Reply with quote

m_embedded wrote:
If we do like this means there is chance to corrupt the bootloader code i think,though we are compiling bootloader and appliation with shared functions (object file), the application hex file will includes the shared modules which is in the bootloader code address range.


No.
That's the whole point.

You write the bootloader to protect an address range that is "it's".
You write the shared functions to be separately built, but include this into the address range that the bootloader protects.

Means these functions cannot be updated, except by loading a new bootloader, but they remain as a fixed resource.

This becomes possibly necessary when dealing with bootloader's that use a large resource like the USB drivers, _but_ brings the downside that these drivers used by the application, can't then be updated. Remember that memory is erased in blocks, and you can't be running code from a block that you erase.

Best Wishes
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

How to mix bootloader and Application code
PostPosted: Wed Oct 10, 2012 4:57 am     Reply with quote

Thank you Ttelmah and RF_Developer, I have consider both of your valid points. Actually my bootloader is using gprs to update the code. In bootloader I have used both sms and gprs funtionalities so my code size has gone beyond the limit. So I have planned before to use shared modules, now considering RF_Developer points i have planned to do this in different way.

Though my application code is using gprs/gsm driver, I will download and store the firmware (via gprs) in EEPROM and then from bootloader I will update the code to program memory.

According to this idea, when first time firmware dump, I supposed to mix bootloader and application code in one hex file and download. Otherwise I need to give option to update firmware through bootloader in offline mode (rs232 ). Hence I don't have provision in my board for rs232, I need to go for first option.

Now my question is how to mix bootloader and application code and from one hex file ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 5:08 am     Reply with quote

Load them both into MPLAB, and export as a single file.

There are other ways, but this is about the simplest.

Best Wishes
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 8:24 am     Reply with quote

Ttelmah wrote:
Load them both into MPLAB, and export as a single file.

There are other ways, but this is about the simplest.

Best Wishes

Thanks Ttelmah, I have tried what you said, its working ...
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