|
|
View previous topic :: View next topic |
Author |
Message |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
bootloader #org and more |
Posted: Thu Apr 01, 2010 8:43 pm |
|
|
I tried modifying the CCS bootloader for PIC18F2520.
I think I got something wrong with the #org statements LOADER_END etc.
Here is a summary of the files showing the values for #org etc.
Any idea where the mistake is ?
Thanks
hansw
bootloader.h
Code: |
#define LOADER_END 0x7FF
#define LOADER_SIZE 0x5FF
|
Code: |
////bootLoader.c/////////////////////////
#include "bootloader.h"
#include "loader.c"
#org LOADER_END+2, LOADER_END+20
void application(void)
{
while(TRUE);
}
#org 0x40,0x1AF
void main(void)
{
load_program();
}
#ORG default
#int_global
void isr(void)
{
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}
|
Code: |
/////loader.c/////////////////////////////////////////
#ORG LOADER_ADDR+10, LOADER_END auto=0 default
void real_load_program (void)
{
CCS type bootloader code here
}
#ORG default
#ORG LOADER_ADDR, LOADER_ADDR+9
void load_program(void)
{
real_load_program();
}
|
The bootloader.hex
Code: |
:0400000020EF00F0FD
:0800080004EF04F00000000009
:1000100000000000000000000CEF04F010009EAA99
:10002000FED7ABCF05F0AECF01F005A202D0AB9862
:0E003000AB8883EF01F09EA8FED7AD6E000CEA
:10004000F86AD09EEA6AE96AB8866C0EAF6E000E56
:10005000B06EA60EAC6E900EAB6E00000000C150EC
:10013000006EF29E0F01550EA76EAA0EA76EA68244
|
more here
Code: |
:10014000A6B2FED7A6940050F212FF000001F29C66
:0A015000F29EF2BEFDD754DB03005F
:1001B000EA6A490EE96EEF500DE0010E016E006A29
:1001C000002EFED7012EFBD75B0E006E002EFED751
:0601D000EF2EF3D7000C36
:040200006ED8000CA8
:06020A00816B826B825142
:10021000010829E380C003F07FC0E9FF80C0EAFF46
|
more here
Code: |
:1004F000806B120E7F6E89DE7BC04EF001C04DF026
:1005000048A003D0060E97DD02D0110E94DD110E27
:0E05100092DDE8D6060E8FDD060E8DDD000CA6
:04080000FFD7000C12
:020000040030CA
:0E00000000C2180E008781000FC00FE00F40F5
:00000001FF
|
the application.hex
Code: |
:04080000DDEF18F020
:08080800046ED8CF05F0E0CF2B
:1008100006F00001E9CF0CF0EACF07F0E1CF08F0D5
:10082000E2CF09F0D9CF0AF0DACF0BF0F3CF12F014
|
lots more here
Code: |
:1038600010E307E13851305D0CE303E137512F5D80
:1038700008E300016AD4ADC2AFF2ACC2AEF21C9A4A
:1038800003010201030148D6D3CF00F07C0ED3160A
:08389000030000C0D3FF030098
:020000040030CA
:0E00000000C2180E008781000FC00FE00F40F5
:00000001FF |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 02, 2010 10:14 am |
|
|
You need to tell us what the problem is. Does it not compile ?
How does it fail ? Tell us how you are testing it.
Also tell us your compiler version. |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
The issue |
Posted: Sat Apr 03, 2010 5:51 am |
|
|
Sorry about that !
I was more interested to know if the #org, LOADER_END, LOADER_SIZE are correct, in relation to the start and end of the hex files !
CCS is OK but the examples do not spell out the principal behind the code construction.
What is the reason for LOADER_END and LOADER_SIZE etc. ?
Why are there statement like "default" for the LOADER_SIZE etc.
How do these relate to the HEX file ?
I know there are lots of code snippets, but none really explain WHY they are doing what they do. !
COMPILER: For this project PCH. I'm using what ever the latest version is. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Apr 03, 2010 7:13 am |
|
|
I agree, that the bootloader examples are not particularly instructive. But by studying them thoroughly, you should be
able to understand the principle.
The first point is to understand the bootloader application layout and some details about reset and interrupt
vectors. Generally, the bootloader is intended not be overwritten after initial (factory) programming. It may be
protected against unwanted overwrites. It should be functional even with a deleted or damaged main application,
so it must own the bottom flash block, where reset and interrupt vectors are located.
By including the code in bootloader.h and defining or undefining the bootloader constant, you choose either to
build the bootloader or the main application. If you build the bootloader, a dummy main function is also generated,
that's later replaced by the main code.
By importing the bootloader hex-file to the main application, you can build an all-in-one image, that can be used
for initial programming and application through bootloader update as well.
If you have a special problem, you may want to tell in which regard you want to modify the existing bootloader example.
P.S: The bootloader example basically has three files:
bootloader.h // common definitions for bootloader and main application
ex_bootloader.c // the bootloader application
ex_bootload.c // a short main application example
The basic process is to compile bootloader and main application, program the bootloader to the device and
load the main application by the bootloader. As said above, the process can be shortened by importing the bootloader
image to the main application to generate a single hex-file.
The generated hex-file contains what you requested by the #org and similar preprocessor commands. If you
understand the principle concept, you'll easily identify the respective code parts in the image. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sat Apr 03, 2010 11:17 am |
|
|
FvM wrote: | I agree, that the bootloader examples are not particularly instructive. But by studying them thoroughly, you should be
able to understand the principle. |
No kidding.
Through all the CCS examples and lately a bunch of Microchip examples,
There's a lot of "what" documented, but not "when" or "why" explained with it.
I find it disappointing.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Apr 04, 2010 10:58 am |
|
|
The statement was meant serious. The bootloader applications are understandable when you get the concept behind it.
But I didn't want to justify missing documentation from CCS side, I basically agree about the "when" and "why".
Microchip has better documentation, I think, they released ANs related to bootloader concepts and implementation. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Apr 04, 2010 11:08 am |
|
|
FvM wrote: |
The statement was meant serious. The bootloader applications are understandable when you get the concept behind it.
But I didn't want to justify missing documentation from CCS side, I basically agree about the "when" and "why".
|
I agree with you. I did a bootloader for the PIC18F46J11 that's fabulous.. but with some more commenting on behalf of the original CCS bootloader authors, I wouldn't have had to read and tinker as long had their mere comments been more detailed.
A lot of times when I code, I start with an outline of what I want to do... then I fill in the outline (which turn into comments) with code. Along the way when I realized I have to do something a certain way, I usually fill in WHY as well so the next poor slob doesn't suffer with the uncommented code like I may have had to. :D
Quote: |
Microchip has better documentation, I think, they released ANs related to bootloader concepts and implementation. |
Yes, MCHP has much better docs. (Although I still find typos and errors) Their PIC32 stuff, which I've been swimming in lately, has a lot of the "how" and "why" missing from the linker docs though. Building a bootloader integrated with the application leaves a lot of questions their docs, FAE's and forum members can't seem to answer. I had to go ask my gcc toting embedded linux buddies. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
|
Posted: Sun Apr 04, 2010 3:31 pm |
|
|
FvM wrote: | I agree, that the bootloader examples are not particularly instructive. But by studying them thoroughly, you should be
able to understand the principle.
P.S: The bootloader example basically has three files:
bootloader.h // common definitions for bootloader and main application
ex_bootloader.c // the bootloader application
ex_bootload.c // a short main application example
|
I think the list should also include loader.c !
Anyway thanks for all the help and comments.
The LST file contains all the addresses of the vectors which must be replaced.
When or if I ever get this clear in my head I'll make a point of posting something (text) and perhaps someone can check it for accuracy.
I stumbled through two bootloaders before but never really took the time to understand what was going on. Credit to CCS at least the examples worked, but that does not help me understand why.
The #IMPORT and #EXPORT are useful but they are producing bad hex files.
Again the CCS help on #IMPORT and #EXPORT is pitiful.
What I need to do is produce a text with graphics (memory map) for a particular chip (PIC18F2520 in my case) to show the vector location etc. and explain each step.
hansw |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Apr 05, 2010 12:38 am |
|
|
Quote: | I think the list should also include loader.c ! |
Yes, it's included included in ex_bootloader.c and contains the application-independant part of the bootloader. Thanks for clarifying.
I must confess, that I didn't exactly understand from your post, what's the intention of your modification, so I didn't try to guess what may have went wrong. I also have difficulties to imagine the full application layout from snippets. If you tell about the intention, others can suggest what should be changed to the original example. I agree, that a verbose documentation, including application layout and everything would be preferable.
Regarding export and import, only import is needed with a bootloader normally, if you want to include the bootloader image with the application.
In main.c it could look like
Code: | #include "bootloader.h"
#import(FILE=xx_bootloader.hex,HEX,RANGE=0:0x07FF) |
Simply, the complete bootloader image (without the dummy main) is imported. |
|
|
bertronicom
Joined: 17 Nov 2004 Posts: 26 Location: University of Cantabria -SPAIN
|
CCS bootloader doesn't compiler |
Posted: Wed May 05, 2010 4:09 pm |
|
|
I have modified the ex_bootloader.c as follows,
Code: |
#include <Afo_system.h>
#define _bootloader
#include <bootloader.h>
#include <loader.c>
#org LOADER_END+2,LOADER_END+20
void application(void) {
printf( "\r\n<%s> \r\n", VERSION);
while(1){
if (kbhit()){
Rx_Char = getc();
if(Rx_Char=='p')
Write_Eeprom ( 0, 77 );
reset_cpu();
}
}
}
#org 0x40,0x7F
//#org 0x40,0x1AF
void main(void) {
if ( Read_Eeprom ( 0 )==77) {
printf( "bootloading... \r\n");
load_program();
Write_Eeprom ( 0, 0 );
reset_cpu();
}
application();
}
#ORG default
#int_global
void isr(void) {
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}
|
out of rom, a segment of the program is too large (application)
bootloader.h and loader.c weren't modified.
Any suggestion?? |
|
|
|
|
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
|