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:
parent
daa08fb31c
commit
37b8a8b8ed
48
Makefile
48
Makefile
|
@ -19,6 +19,7 @@ INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core
|
|||
|
||||
include $(ROOT_PATH)/Makefile.inc
|
||||
|
||||
LDFLAGS+= -Wl,--gc-sections
|
||||
VPATH += lpc1xxx
|
||||
OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o
|
||||
|
||||
|
@ -36,8 +37,27 @@ LD_PATH = lpc1xxx
|
|||
LD_SCRIPT = $(LD_PATH)/linkscript.ld
|
||||
LD_TEMP = $(LD_PATH)/memory.ld
|
||||
|
||||
### User targets:
|
||||
|
||||
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
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
|
@ -56,32 +76,24 @@ filesystem/libfat.a:
|
|||
tools/lpcfix:
|
||||
cd tools && $(MAKE)
|
||||
|
||||
$(OUTFILE).bin: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX)
|
||||
$(LD_TEMP):
|
||||
-@echo "MEMORY" > $(LD_TEMP)
|
||||
-@echo "{" >> $(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 "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 ""
|
||||
$(SIZE) $(OUTFILE).elf
|
||||
-@echo ""
|
||||
$(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin
|
||||
|
||||
%.bin: %.elf
|
||||
$(OBJCOPY) $(OCFLAGS) -O binary $< $@
|
||||
-@echo ""
|
||||
$(LPCFIX) -c $(OUTFILE).bin
|
||||
$(LPCFIX) -c $@
|
||||
|
||||
protect: $(OUTFILE).bin
|
||||
$(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
|
||||
.PHONY: $(LD_TEMP) lcd/liblcd.a modules/libmodules.a filesystem/libfat.a
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
TARGET = LPC13xx
|
||||
FLASH = 32K
|
||||
SRAM = 8K
|
||||
RAMCODE=1K
|
||||
|
||||
# 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.
|
||||
|
@ -19,7 +20,8 @@ SRAM_USB = 384
|
|||
CROSS_COMPILE = arm-none-eabi-
|
||||
AS = $(CROSS_COMPILE)gcc
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
LD = $(CROSS_COMPILE)gcc
|
||||
LD = $(CROSS_COMPILE)ld
|
||||
REALLD = $(CROSS_COMPILE)ld
|
||||
SIZE = $(CROSS_COMPILE)size
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
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
|
||||
LDFLAGS = -nostartfiles -mthumb -mcpu=$(CPU_TYPE) -Wl,--gc-sections
|
||||
LDFLAGS = -nostartfiles
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
*.elf
|
||||
*.bin
|
||||
*.h
|
|
@ -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
|
||||
|
|
@ -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:
|
|
@ -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($_);
|
||||
};
|
|
@ -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);
|
||||
};
|
||||
};
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue