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

Bootloader in Wrong segment

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 02, 2007 4:19 pm     Reply with quote

Quote:
This IS the bootloader not the program code.

Now I understand . This code is actually downloadable from here:
http://www.thebytefactory.com/download.asp?file=codeloader_h.c
Once I got a look at it, I was able to come up with a solution, or at least
hopefully. I modified the 'MAX_LOADABLE' constant to consume all
of the first 64KB of flash and part of the next 64KB. Then I created
an #if-else block to check the range. If the MAX_LOADABLE value
extends into the 2nd 64KB, then I use two #org statements. The key
is that #org apparently only works for 64 KB max. If you need more,
then you have to use a 2nd #org statement.
Code:

#if getenv("FUSE_SET:WDT")==TRUE
#define MAX_LOADABLE 0x16800   
#else
#define MAX_LOADABLE 0x16820   
#endif


#if MAX_LOADABLE > 0x0FFFF
#org 0x00008, 0x0FFFF {}   
#org 0x10000, MAX_LOADABLE {}
#else
#org 0x00008, MAX_LOADABLE {}
#endif
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Almost there
PostPosted: Sun Sep 02, 2007 5:06 pm     Reply with quote

PCM programmer wrote:
Quote:
This IS the bootloader not the program code.

Now I understand . This code is actually downloadable from here:
http://www.thebytefactory.com/download.asp?file=codeloader_h.c
Once I got a look at it, I was able to come up with a solution, or at least
hopefully. I modified the 'MAX_LOADABLE' constant to consume all
of the first 64KB of flash and part of the next 64KB. Then I created
an #if-else block to check the range. If the MAX_LOADABLE value
extends into the 2nd 64KB, then I use two #org statements. The key
is that #org apparently only works for 64 KB max. If you need more,
then you have to use a 2nd #org statement.
Code:

#if getenv("FUSE_SET:WDT")==TRUE
#define MAX_LOADABLE 0x16800   
#else
#define MAX_LOADABLE 0x16820   
#endif


#if MAX_LOADABLE > 0x0FFFF
#org 0x00008, 0x0FFFF {}   
#org 0x10000, MAX_LOADABLE {}
#else
#org 0x00008, MAX_LOADABLE {}
#endif


Thanks a lot I appreciate the help. It looks close and is certainly on the right track.
As you can see here the bootloader code ended up in the second segment
but not at the top.

So I tweaked the second $org and it moves it up some more but not all the way.
Code:

#if getenv("FUSE_SET:WDT")==TRUE
#define MAX_LOADABLE 0x16800   
#else
#define MAX_LOADABLE 0x16820   
#endif

#if MAX_LOADABLE > 0x0FFFF
#org 0x00008, 0x0FFFF {}   
#org 0x16800, MAX_LOADABLE {}  // adjusted this value
#else
#org 0x00008, MAX_LOADABLE {}
#endif

Are we looking at a third #org ?

Best regards
Hans W


.. with PCM Programmers original values
:020000040000FA
:1000000044EFB5F0FFFFFFFFFFFFFFFFFFFFFFFF24
:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
removed for brevity all locations FF
:10FFE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF21
:10FFF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF11
:020000040001F9
:10000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
:10680000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF98
removed for brevity all locations FF
:10681000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF88
:10682000FFFFE56719EFB4F0E6671AEFB4F022EF67
:10683000B4F0E62BE4C0EEFFE52F1AEFB4F0E62F3C
:106840001AEFB4F0000C9EAA23EFB4F0ABCF05F022
removed for brevity
:10706000000ECC21D86F000ECD21D96F000ECE219D
:10707000DA6F000ECFB1010EDAC0E7F0D9C0E6F04A
:10708000D8C0E5F0D7C0E4F0E96BE86F7FDC020E12
:10709000D76FE3D4FF000300FFFFFFFFFFFFFFFFF9
:1070A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
:1070B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
removed for brevity all locations FF
:10FFD000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF31
:10FFE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF21
:10FFF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF11
:020000040020DA
:080000000DF006F00FF006F010
:0200000400F00A
:08000000FFFFFFFFFFFFFFFF00
data eeprom
:0803F800FFFFFFFFFFFFFFFF05
:020000040030CA
:0E00000000060C0E83018100FFC0FFE0FF40F0
:00000001FF
;PIC18F6720
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

This seems to do the trick..
PostPosted: Sun Sep 02, 2007 5:15 pm     Reply with quote

The loader is reported as 2170 bytes
so I adjust as follows...

#define MAX_LOADABLE 0X1F780

:020000040001F9

:10FFC000000ECC21D86F000ECD21D96F000ECE21AE
:10FFD000DA6F000ECFB1010EDAC0E7F0D9C0E6F05B
:10FFE000D8C0E5F0D7C0E4F0E96BE86F7FDC020E23
:10FFF000D76FE3D4FF000300FFFFFFFFFFFFFFFF0A
:020000040020DA
:080000000FF006F00AF003F016
:0200000400F00A
:08000000FFFFFFFFFFFFFFFF00

Hans W
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 02, 2007 5:27 pm     Reply with quote

The numbers that I used were copied from their sample code, which
they say are set to work with various compiler versions, etc.
You've adjusted them to a more accurate value for your app.
Guest








Thanks again for the help
PostPosted: Sun Sep 02, 2007 7:49 pm     Reply with quote

PCM programmer wrote:
The numbers that I used were copied from their sample code, which
they say are set to work with various compiler versions, etc.
You've adjusted them to a more accurate value for your app.


PCM programmer just how or where did you get the info about using #org twice ? I would never have thought of that !

Anyway theByteFactory Bootloader needs a lot of work.
Next is handling 64 byte writes etc to speed up the load process.
With 120K of code to boot load this is going to take time. I may still do it from SD card directly and avoid the Bluetooth serial.
I have about 8-10K of ROM left so space is shoud not be an issue.

Hans W
Rick Harris



Joined: 06 Aug 2007
Posts: 2

View user's profile Send private message

bootloader noob
PostPosted: Sun Sep 02, 2007 9:11 pm     Reply with quote

Gents,

I'm impressed by the level of expertise available in this customer support forum, and have a quick question that's somewhat related to this thread.

I've been a C programmer for 20+ years, and am new to PIC programming. I have a PIC18F97J60 project that requires use of the Brush Electronics PIC18F97J60 Ethernet bootloader, and am so far unable to figure out how to actually load the bootloader into high memory. I'm using the CCS PCW v 4.46 Compiler, and any clues would be much appreciated.

This bootloader requires a GOTO to the bootloader in the first 4 instructions. Again, any clues on how to accomplish this would also be greatly appreciated.

Thanks!
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: bootloader noob
PostPosted: Fri Oct 24, 2008 11:51 pm     Reply with quote

Rick Harris wrote:
Gents,

I'm impressed by the level of expertise available in this customer support forum, and have a quick question that's somewhat related to this thread.

I've been a C programmer for 20+ years, and am new to PIC programming. I have a PIC18F97J60 project that requires use of the Brush Electronics PIC18F97J60 Ethernet bootloader, and am so far unable to figure out how to actually load the bootloader into high memory. I'm using the CCS PCW v 4.46 Compiler, and any clues would be much appreciated.

This bootloader requires a GOTO to the bootloader in the first 4 instructions. Again, any clues on how to accomplish this would also be greatly appreciated.

Thanks!


Just found this old thread but thought I should answer for completeness.

The Brush Electronics PIC18F97J60 bootloader is a high memory bootloader. You do not need to do anything to load it high. If however you wanted to move it down to leave free memory above the bootloader, you do this by modifying the platform specific defines located at the start of the bootloader source. Not that the bootloader, as shipped, will not load user code above the base address of the bootloader. If you wanted the bootloader to do this you would have to modify the address validation logic to allow programming above the end of the bootloader.

If you use interrupts in your code then the CCS compiler will insert the goto instruction automatically. For applications that do not use interrupts or just to be consistant you can add the following directive

Code:
   // reserve bootloader locations
#build(reset=0x00:0x07)


This dedicates the lower 8 bytes (four instructions) to the reset vector and forces a goto to be inserted.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Tue Mar 17, 2015 7:09 am     Reply with quote

I have the same problem. I'm using a PIC24HJ256GP610, CCS Compiler ver. 5.040 and a modified ex_pcd_bootloader.c

I want to save the space from 0x00000 till 0x103FF just for the bootloader. But as soon I include the header file of the bootloader into the application. The GOTO instruction is at address 0x0000 and not at addresss 0x10400 like it should be.

I have changed my bootloader hearder file code from

Code:
#define LOADER_SIZE 0x103FF
#define LOADER_END 0x103FF
#define LOADER_ADDR (LOADER_END - LOADER_SIZE)
.
.
.
#ifndef _bootloader
 #ifdef BOOTLOADER_AT_START
  #build (reset=LOADER_END+1,interrupt=LOADER_END+5)
  #org 0, LOADER_END {}
#endif
#endif


to


Code:
#define LOADER_SIZE 0x103FF
#define LOADER_END 0x103FF
#define LOADER_ADDR (LOADER_END - LOADER_SIZE)

#ifndef _bootloader
 #ifdef BOOTLOADER_AT_START
  #build (reset=LOADER_END+1,interrupt=LOADER_END+5)

    #if LOADER_END > 0x0FFFF
    #org 0x00000, 0x0FFFF {}
    #org 0x10000, LOADER_END {}
    #else
    #org 0x00000, LOADER_END {}
    #endif

#endif
#endif


the c code of the bootloader has before its main this code

Code:
#org LOADER_END+1,LOADER_END+5
void application(void)
{
   while(TRUE); // Dummy Applikation mit Endlosschleife
}

void main(void)
{
   if(input(PUSH_BUTTON)) // Beim Reset den Butten gedrückt halten
      {
....
      }
      application();
}


It works fine the Bootloader size till 0xFBFF (application has then a GOTO at address 0xFC00)
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Tue Mar 17, 2015 8:11 am     Reply with quote

As I said in your other thread about this, have you tried with the #ORG definitions that PCM_programmer posted?. You have changed the start address of the #ORG's to 0, while he used 8, to leave space for the goto instruction that sits at the start of memory. This may be preventing the double #ORG from working.
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Tue Mar 17, 2015 8:39 am     Reply with quote

Ttelmah wrote:
As I said in your other thread about this, have you tried with the #ORG definitions that PCM_programmer posted?. You have changed the start address of the #ORG's to 0, while he used 8, to leave space for the goto instruction that sits at the start of memory. This may be preventing the double #ORG from working.


Yes, I have tried that, but as I said in the other thread the GOTO instruction in my application is still not there where it should be. The first address in that file was always the address of LOADER_END+1, but this was only up to a LOADER_END address of 0xFBFF. Beyond that the first adress starts again from 0x000. I have tried different addresses for LOADER_END (beyond 0xFFFF) and it always starts at 0x000 and never goes beyond 0xFC00.

Here is my actual code. With the use of 8 instead of 0. (Even with 0 it dont changes anything)

Code:
#define LOADER_PAGES 2 // Bootloader belegt 2 Seiten (2048 Adressen des Speichers (0x000-0x7FF)
#define BOOTLOADER_AT_START
#define LOADER_SIZE 0X103FF // Größe des Bootloaders in Adressen
#define LOADER_END 0x103FF // Letzte Speicheradresse des Bootloaderbereiches
#define LOADER_ADDR (LOADER_END - LOADER_SIZE) // Bottloader start bei 0 (bei 0x0 GOTO Anweisung zum Bootloader)

#ifndef _bootloader
 #ifdef BOOTLOADER_AT_START
  #build (reset=LOADER_END+1,interrupt=LOADER_END+5) // Offset der IVT etc.
  #if LOADER_SIZE > 0x0FFFF
#org 0x00008, 0x0FFFF {}   
#org 0x10000, LOADER_SIZE {}
#else
#org 0x00008, LOADER_SIZE {}

#endif

#endif
#endif


The first address in the .lst file of the application is 0x400 (also for 0)

Code:
00400:  GOTO    10880
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