I am trying to write a bootloader that fits within a 4Kbyte space and I'm trying to keep the essential code as small as possible.
However, with the standard default setup from the CMSDK Cortex M0 enviroment, even with a empty main(), I notice that it has already taken up almost 2.5Kbytes
Looking further into the compiled code, I noticed that crt0.o uses some functions which are taking up space some of them below ( dumped from *nm)
20000430 00000004 D _impure_ptr 3000022a 00000004 T main 30000438 00000010 T atexit 30000324 00000018 t register_fini 30000230 00000020 T exit 30000448 00000034 T __libc_fini_array 30000198 00000044 T Reset_Handler 30000250 00000048 T __libc_init_array 30000298 0000008c T memset 30000000 000000c0 T __isr_vector 3000047c 000000d4 T __register_exitproc 3000033c 000000fc T __call_exitprocs
What does crt0.o do anyways and I thought all the necessary copy-downs from Flash to RAM are already defined in startup_CMSDK_CM0.s.
Can I exclude calling this file and go straight to startup_CMSDK_CM0.s?
Also looking at the linker script sections.ld there are references to crt and ctors. Can I exclude those as well?
/* .ctors */ *crtbegin.o(.ctors) *crtbegin?.o(.ctors) *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) *(SORT(.ctors.*)) *(.ctors) /* .dtors */ *crtbegin.o(.dtors) *crtbegin?.o(.dtors) *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) *(SORT(.dtors.*)) *(.dtors) *(.rodata*)
Just starting out with programming on Cortex M0 so any help is appreciated, cheers.
Found more proper solution by looking at the example code in the GCC install rather than from CMSDK. I used the setup and switches from samples/src/minimum and it compiles to a very small code now.
I noticed that could have been a typo in the CMSDK ARM package for the startup_CMSDK_CM0.s. With a '*.s' this causes GCC not to preprocess the file and thus causing all the defines (for eg stack pointer etc) not to be evaluated. This was also the reason I count not redefine __START to another value.
I renamed it to startup_CMSDK_CM0.S which indicates that it needs to be preprocessed and all the defines work now.