|
|
View previous topic :: View next topic |
Author |
Message |
hwstar
Joined: 15 May 2010 Posts: 10
|
Forcing a boot loader live in a restricted address range |
Posted: Sat Sep 18, 2010 8:47 pm |
|
|
I want to have the compiler bomb out when a boot loader I'm currently
developing exceeds 1K in size. The boot loader occupies 0x0000 to 0x3FF
and I'd like the compiler to throw an error if the size of the boot loader
exceeds 1024 bytes.
I tried to use:
Code: |
#pragma org 0x0400,0x3FFF {}
|
to reserve all program memory except the bottom 1024 bytes, but the CCS compiler complains as follows:
Code: |
CCS PCM C Compiler
Registered to: Stephen Rodgers
bloader
in /home/srodgers/projects/notfree/pic-projects/bootloader/
Compiling: bloader.c
1 Errors, 0 Warnings, Time: 2 Seconds
Error[300] bloader.c 17 : More info: Segment at 00000-007FF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 00800-00FFF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 01000-017FF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 01800-01FFF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 02000-027FF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 02800-02FFF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 03000-037FF (0000 used)
Error[300] bloader.c 17 : More info: Segment at 03800-03FFF (0000 used)
Error[300] bloader.c 17 : More info: Attempted to create: 00400-03FFF for #org
Error[126] bloader.c 17 : Invalid ORG range
1 Errors, 0 Warnings.
|
Additional data:
Processor: PIC16F1938
CCS compiler 4.108 for Linux
Code snippet from boot loader:
Code: |
/*
/ Boot loader program
*/
#include <16F1938.h>
#pragma reserve 0x16C:0x16F
#pragma nolist
#include <stdlib.h>
#pragma list
#pragma fuses HS, PLL, WDT, PUT, NOLVP
#pragma use delay(clock=32Mhz, restart_wdt)
#pragma use fast_io(ALL)
#pragma use rs232(baud=57600, UART1, ERRORS, RESTART_WDT)
#include "bootloader.h"
#pragma org 0x0400,0x3FFF {}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 19, 2010 6:31 pm |
|
|
What's in bootloader.h ?
What are your defined values for LOADER_START and LOADER_SIZE ? |
|
|
hwstar
Joined: 15 May 2010 Posts: 10
|
|
Posted: Tue Sep 21, 2010 10:25 am |
|
|
bootloader.h contains #defines for TOTAL_PROGRAM_MEMORY LOADER_START, LOADER_SIZE, APP_START, and APP_SIZE
Here's what's in bootloader.h
Code: |
#define TOTAL_PROGRAM_MEMORY 0x4000
#define LOADER_START 0x0000
#define LOADER_SIZE 0x400
#define APP_START LOADER_SIZE
#define APP_SIZE (TOTAL_PROGRAM_MEMORY - LOADER_SIZE)
|
Give the above bootloader.h constants, the #pragma org statement actually reads as follows in bloader.c:
#pragma org APP_START, TOTAL_PROGRAM_MEMORY-1 {}
What I'm attempting to do is to exclude the use of 0x0400 to 0x3FFF by the boot loader program. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 21, 2010 12:01 pm |
|
|
Quote: | the #pragma org statement actually reads as follows in bloader.c: |
I can't find any CCS file called bloader.c.
I need a compilable program so I can attempt to solve the problem.
Make it as short as possible. Don't post CCS files that I already have.
I need to be able to copy and paste your program into an MPLAB project
so I can study the problem. |
|
|
hwstar
Joined: 15 May 2010 Posts: 10
|
|
Posted: Tue Sep 21, 2010 7:39 pm |
|
|
Ok, I reduced it down to this:
Code: |
#include <16F1938.h>
#pragma fuses HS, PLL, WDT, PUT, NOLVP
// Clock speed
#pragma use delay(clock=32Mhz, restart_wdt)
#define TOTAL_PROGRAM_MEMORY 16384 // Number of words of program memory (2x words) PIC16F1938
#define LOADER_SIZE 0x400 // Loader size in words
#define APP_SIZE (TOTAL_PROGRAM_MEMORY - LOADER_SIZE)
#pragma org LOADER_SIZE, TOTAL_PROGRAM_MEMORY -1 {} /*** Remove this and it compiles perfectly! ***/
// Top level
main()
{
for(;;);
}
/*
* END
*/
|
Additional note: Adding a #pragma org 0 before the address range excluded reduces the number of error messages to 1 and you only get:
Code: |
Error[126] bloader.c 191 : Invalid ORG range Reset vector is at 0x0000
1 Errors, 0 Warnings.
|
What I'm trying to do is reserve most of the program memory for the
app, and if the boot loader gets too large, I want it to fail in the compilation process.
Steve. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 22, 2010 10:02 pm |
|
|
It took me a while to remember what this one was. The answer is that
you have to block off the memory with one #org statement per ROM
page. See the program below.
I tested the following program with vs. 4.112. If I uncomment the last
delay_cycles(1), which is a NOP, the compiler will give an "Out of Rom"
error.
Code: |
#include <16F1938.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// Prevent the compiler from using any ROM above the first 1K.
#org 0x0400, 0x07FF {} // Rom page 0 (upper half only)
#org 0x0800, 0x0FFF {} // Rom page 1 (2K words)
#org 0x1000, 0x17FF {} // Rom page 2 (2K words)
#org 0x1800, 0x1FFF {} // Rom page 3 (2K words)
#org 0x2000, 0x27FF {} // Rom page 4 (2K words)
#org 0x2800, 0x2FFF {} // Rom page 5 (2K words)
#org 0x3000, 0x37FF {} // Rom page 6 (2K words)
#org 0x3800, 0x3FFF {} // Rom page 7 (2K words)
//==========================================
void main()
{
float a, b, c;
printf("Hello World\n\r");
printf("abcdeghijklmnopqrstuvwxyz\n\r");
printf("0123456789ABCDEF\n\r");
c = a * b;
c = a / b;
c = a + b;
c = a - b;
c = a * 1.234;
c = a / 1.234;
c = a + 1.234;
c = a - 1.234;
c = a * a;
delay_cycles(1);
//delay_cycles(1);
while(1);
}
|
|
|
|
hwstar
Joined: 15 May 2010 Posts: 10
|
|
Posted: Thu Sep 23, 2010 12:20 pm |
|
|
Thanks for the tip. Will try it this evening.
Steve. |
|
|
|
|
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
|