Add loadable/ - build infrastructure for small ram executables.

Also reserve 1k ram for these in the main firmware
(Makefile.inc variable RAMCODE)
This commit is contained in:
Stefan `Sec` Zehl 2011-06-15 23:31:02 +02:00
parent daa08fb31c
commit 37b8a8b8ed
8 changed files with 199 additions and 20 deletions

View File

@ -19,6 +19,7 @@ INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core
include $(ROOT_PATH)/Makefile.inc include $(ROOT_PATH)/Makefile.inc
LDFLAGS+= -Wl,--gc-sections
VPATH += lpc1xxx VPATH += lpc1xxx
OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o
@ -36,8 +37,27 @@ LD_PATH = lpc1xxx
LD_SCRIPT = $(LD_PATH)/linkscript.ld LD_SCRIPT = $(LD_PATH)/linkscript.ld
LD_TEMP = $(LD_PATH)/memory.ld LD_TEMP = $(LD_PATH)/memory.ld
### User targets:
all: $(OUTFILE).bin all: $(OUTFILE).bin
protect: $(OUTFILE).bin
$(LPCFIX) -p 2 $(OUTFILE).bin
loadables: $(OUTFILE).elf
@cd loadable && $(MAKE)
clean:
rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex
@cd core && $(MAKE) clean
@cd tools && $(MAKE) clean
@cd lcd && $(MAKE) clean
@cd modules && $(MAKE) clean
@cd filesystem && $(MAKE) clean
@cd loadable && $(MAKE) clean
### Internal targets
%.o : %.c %.o : %.c
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
@ -56,32 +76,24 @@ filesystem/libfat.a:
tools/lpcfix: tools/lpcfix:
cd tools && $(MAKE) cd tools && $(MAKE)
$(OUTFILE).bin: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP):
-@echo "MEMORY" > $(LD_TEMP) -@echo "MEMORY" > $(LD_TEMP)
-@echo "{" >> $(LD_TEMP) -@echo "{" >> $(LD_TEMP)
-@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP) -@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP)
-@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)" >> $(LD_TEMP) -@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)-$(RAMCODE)" >> $(LD_TEMP)
-@echo "}" >> $(LD_TEMP) -@echo "}" >> $(LD_TEMP)
-@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP) -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP)
$(LD) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS)
$(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP)
$(CC) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS)
-@echo "" -@echo ""
$(SIZE) $(OUTFILE).elf $(SIZE) $(OUTFILE).elf
-@echo "" -@echo ""
$(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin
%.bin: %.elf
$(OBJCOPY) $(OCFLAGS) -O binary $< $@
-@echo "" -@echo ""
$(LPCFIX) -c $(OUTFILE).bin $(LPCFIX) -c $@
protect: $(OUTFILE).bin .PHONY: $(LD_TEMP) lcd/liblcd.a modules/libmodules.a filesystem/libfat.a
$(LPCFIX) -p 2 $(OUTFILE).bin
clean:
rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex
@cd core && $(MAKE) clean
@cd tools && $(MAKE) clean
@cd lcd && $(MAKE) clean
@cd modules && $(MAKE) clean
@cd filesystem && $(MAKE) clean
.PHONY: lcd/liblcd.a modules/libmodules.a filesystem/libfat.a

View File

@ -7,6 +7,7 @@
TARGET = LPC13xx TARGET = LPC13xx
FLASH = 32K FLASH = 32K
SRAM = 8K SRAM = 8K
RAMCODE=1K
# For USB HID support the LPC134x reserves 384 bytes from the sram, # For USB HID support the LPC134x reserves 384 bytes from the sram,
# if you don't want to use the USB features, just use 0 here. # if you don't want to use the USB features, just use 0 here.
@ -19,7 +20,8 @@ SRAM_USB = 384
CROSS_COMPILE = arm-none-eabi- CROSS_COMPILE = arm-none-eabi-
AS = $(CROSS_COMPILE)gcc AS = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size SIZE = $(CROSS_COMPILE)size
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump OBJDUMP = $(CROSS_COMPILE)objdump
@ -39,5 +41,5 @@ CPU_TYPE = cortex-$(CORTEX_TYPE)
########################################################################## ##########################################################################
CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin
LDFLAGS = -nostartfiles -mthumb -mcpu=$(CPU_TYPE) -Wl,--gc-sections LDFLAGS = -nostartfiles

3
loadable/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.elf
*.bin
*.h

12
loadable/Makefile Normal file
View File

@ -0,0 +1,12 @@
# Make doesn't allow dependencies on parent directory, so we need to
# run make from one level up:
MAKEFILE=loadable/Makefile.sub
MAKE+=--no-print-directory
all:
@cd .. && $(MAKE) -f $(MAKEFILE)
clean:
@cd .. && $(MAKE) -f $(MAKEFILE) clean

47
loadable/Makefile.sub Normal file
View File

@ -0,0 +1,47 @@
DIR?= loadable
##########################################################################
# User configuration and firmware specific object files
##########################################################################
SRCS = $(wildcard $(DIR)/*.c)
OBJS = $(foreach mod,$(SRCS),$(subst .c,.o,$(mod)))
ELFS = $(foreach mod,$(SRCS),$(subst .c,.elf,$(mod)))
BINS = $(foreach mod,$(SRCS),$(subst .c,.bin,$(mod)))
HDRS = $(foreach mod,$(SRCS),$(subst .c,.h,$(mod)))
##########################################################################
# GNU GCC compiler flags
##########################################################################
ROOT_PATH?= .
INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core
include $(ROOT_PATH)/Makefile.inc
##########################################################################
# Compiler settings, parameters and flags
##########################################################################
FIRMWARE=$(ROOT_PATH)/$(OUTFILE).elf
LDFILE=$(DIR)/loadable.ld
CFLAGS+=-mlong-calls
LDFLAGS+= -R $(FIRMWARE)
all: $(OBJS) $(ELFS) $(BINS) $(HDRS)
%.o : %.c
$(CC) $(CFLAGS) -o $@ $<
%.elf: %.o $(FIRMWARE) $(LDFILE)
$(LD) $(LDFLAGS) -T $(LDFILE) -o $@ $<
$(SIZE) $@
%.bin: %.elf
$(OBJCOPY) $(OCFLAGS) -O binary $< $@
%.h: %.bin $(DIR)/bin2h.pl
$(DIR)/bin2h.pl $<
clean:
cd $(DIR) && rm -f *.o *.elf *.bin
.SUFFIXES:

41
loadable/bin2h.pl Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/perl
#
# vim:set ts=4 sw=4:
use strict;
sub dwim{
local $/=undef;
my $file=shift;
open(IN,"<:bytes",$file) || die "Can't open $file: $!";
my @bytes=unpack("C*",<IN>);
close(IN);
$file=~s/\.[^.]+$//;
open(OUT,">","${file}.h") || die "Can't write ${file}.h: $!";
$file=~s!.*/!!;
print OUT "const uint16_t loadable_${file}_size = ", scalar @bytes, ";\n";
print OUT "const uint8_t loadable_${file}[] = {\n";
my $ctr=0;
for(@bytes){
print OUT "\t" if($ctr==0);
printf OUT "0x%02x, ",$_;
if(++$ctr==8){
print OUT "\n";
$ctr=0;
};
};
print OUT "\n" if($ctr!=0);
print OUT "};\n";
close(OUT);
};
for(@ARGV){
dwim($_);
};

10
loadable/blinktest.c Normal file
View File

@ -0,0 +1,10 @@
#include <sysinit.h>
#include "basic/basic.h"
void ram(void){
for (int x=0;x<20;x++){
gpioSetValue (RB_LED1, x%2);
delayms(50);
};
};

52
loadable/loadable.ld Normal file
View File

@ -0,0 +1,52 @@
MEMORY
{
sram(rwx): ORIGIN = 0x10001800, LENGTH = 2K
}
sram_top = ORIGIN(sram) + LENGTH(sram);
ENTRY(boot_entry)
SECTIONS
{
.text :
{
*(.text*)
*(.rodata*)
} > sram
/*
* More information about Special Section Indexes is available in the
* free "ELF for the ARM Architecture" document from ARM Limited
* http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
*
*/
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > sram
__exidx_start = .;
.ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } > sram
__exidx_end = .;
_etext = .;
.data : AT (__exidx_end)
{
_data = .;
*(vtable)
*(.data*)
_edata = .;
} > sram
/* zero initialized data */
.bss :
{
_bss = .;
*(.bss*)
*(COMMON)
_ebss = .;
} > sram
end = .;
/* For GDB compatibility we decrease the top with 16 bytes */
stack_entry = sram_top - 16;
}