i'm trying to realize my self-updatable bootloader.
The working theory is the same as described in other threads: i have the main bootloader allocated at the boot-start address,
then a small function to update the bootloader, allocated at the last bootloader page.
When bootloader updating is needed, the main bootloader will load its new version into RAM, then will call the bootloader update routine
which will erase and update the main bootloader.
Obviously no interrupts will be used in boot update routine and also all SP functions used to write to boot area are to be allocated
after boot update routine.
In my case i have the main bootloader start at 0x40000 and i would put the bootloader update routine at 0x41E00 which is the
address of the last page in bootloader area.
It seems simple, but i didn't realize how to allocate boot-uploader and sp routines at that specific address.
First thing i tried, in the same bootloader AS6 project where i moved the .text section to 0x20000 (0x40000 in words),
i added a second named section .lastbootpage=0x20F00.
Then i declared a boot-update routine like:
__attribute__((section(".lastbootpage"))) void boot_update (void )
It works, the routine is then allocated at 0x41E00, but then i wanted to put some routines of sp_driver.s also there and i did:
.section .lastbootpage .global SP_EraseWriteBootPage SP_EraseWriteBootPage: in r19, RAMPZ ... ...
No compilation errors are given by avr-gcc, but the routines are then not allocated at that section-specific address any more.
It seems like section allocation for lastbootpage works when only one routine is declared to be allocated there.
My second trial was then to start a new project only containing the boot-update routine and its related sp_driver.s routines.
So i did, declaring section .text=0x20E00 and writing down my routine.
Looking the generated assembler seems now ok, but the interrupt vector table and clear bss and some other stuff is
added before the update routine.
I've looked around the forum and i've tried to use the -nostartfiles flag to get rid of that code i'll not use: no bss clear, no
interrupt table is needed, just the boot-update routine.
But the weird is now that, using the -nostartfiles flag, only the bss clear code is generated (16 bytes), no other code.
Here it is:
Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000010 00041e00 00041e00 00000074 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000000 00802000 00041e10 00000084 2**0 CONTENTS, ALLOC, LOAD, DATA 2 .comment 0000002f 00000000 00000000 00000084 2**0 CONTENTS, READONLY 3 .debug_aranges 00000068 00000000 00000000 000000b8 2**3 CONTENTS, READONLY, DEBUGGING 4 .debug_info 000003e1 00000000 00000000 00000120 2**0 CONTENTS, READONLY, DEBUGGING 5 .debug_abbrev 0000017b 00000000 00000000 00000501 2**0 CONTENTS, READONLY, DEBUGGING 6 .debug_line 00000331 00000000 00000000 0000067c 2**0 CONTENTS, READONLY, DEBUGGING 7 .debug_frame 00000024 00000000 00000000 000009b0 2**2 CONTENTS, READONLY, DEBUGGING 8 .debug_str 00000197 00000000 00000000 000009d4 2**0 CONTENTS, READONLY, DEBUGGING 9 .debug_ranges 00000030 00000000 00000000 00000b70 2**3 CONTENTS, READONLY, DEBUGGING Disassembly of section .text: 00041e00 <__ctors_end>: 41e00: 20 e2 ldi r18, 0x20 ; 32 41e02: a0 e0 ldi r26, 0x00 ; 0 41e04: b0 e2 ldi r27, 0x20 ; 32 41e06: 01 c0 rjmp .+2 ; 0x41e0a <.do_clear_bss_start> 00041e08 <.do_clear_bss_loop>: 41e08: 1d 92 st X+, r1 00041e0a <.do_clear_bss_start>: 41e0a: a0 30 cpi r26, 0x00 ; 0 41e0c: b2 07 cpc r27, r18 41e0e: e1 f7 brne .-8 ; 0x41e08 <.do_clear_bss_loop>
So, how can i allocate more than 1 piece of code at a specific address as i tried on my first attempt, or how can i correctly set the avr-gcc to generate only
the code related to the "main" routine ? no intialization, no vectors, nothing more than "int main (void)" compiled ?
Many thanks for your help.