Commit 3e6012ef authored by Federico Vaga's avatar Federico Vaga

bootloader: build missing bootloader and linker script

Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent a433e31c
*~
\#*\#
.*
\ No newline at end of file
make-dir/
\ No newline at end of file
......@@ -159,8 +159,8 @@ static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
};
STATIC_CONST_STRING_DESC_LANGID( langID, 0x04, 0x09 );
STATIC_CONST_STRING_DESC( iManufacturer, L"Energy Micro AS" );
STATIC_CONST_STRING_DESC( iProduct , L"EFM32 USB CDC serial port device" );
STATIC_CONST_STRING_DESC( iManufacturer, 'E','n','e','r','g','y',' ','M','i','c','r','o',' ','A','S' );
STATIC_CONST_STRING_DESC( iProduct , 'E','F','M','3','2',' ','U','S','B',' ','C','D','C',' ','s','e','r','i','a','l',' ','p','o','r','t',' ','d','e','v','i','c','e' );
static const void * const strings[] =
{
......
/* Linker script for Silicon Labs EFM32GG devices */
/* */
/* This file is subject to the license terms as defined in ARM's */
/* CMSIS END USER LICENSE AGREEMENT.pdf, governing the use of */
/* Example Code. */
/* */
/* Silicon Laboratories, Inc. 2014 */
MEMORY
{
FLASH (rx) : ORIGIN = 0x20000000, LENGTH = 0x4000
RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 131072
}
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .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*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
__etext = .;
.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN (4);
*(.ram)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.bss :
{
__bss_start__ = .;
*(.bss*)
*(COMMON)
__bss_end__ = .;
} > RAM
.heap :
{
__end__ = .;
end = __end__;
_end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy :
{
*(.stack)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
/* Linker script for Silicon Labs EFM32GG devices */
/* */
/* This file is subject to the license terms as defined in ARM's */
/* CMSIS END USER LICENSE AGREEMENT.pdf, governing the use of */
/* Example Code. */
/* */
/* Silicon Laboratories, Inc. 2014 */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x4000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 131072
}
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .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*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
__etext = .;
.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN (4);
*(.ram)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.bss :
{
__bss_start__ = .;
*(.bss*)
*(COMMON)
__bss_end__ = .;
} > RAM
.heap :
{
__end__ = .;
end = __end__;
_end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy :
{
*(.stack)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
......@@ -80,7 +80,7 @@ static void StartRTC( void );
#pragma location=0x200000dc
__no_init uint32_t bootloaderCRC;
#else
#error Undefined toolkit
/* #error Undefined toolkit */
#endif
/**************************************************************************//**
......@@ -119,8 +119,10 @@ int main(void)
/* Calculate CRC16 for the bootloader itself and the Device Information page. */
/* This is used for production testing and can safely be omitted in */
/* your own code. */
/*
bootloaderCRC = CRC_calc((void *) 0x0, (void *) BOOTLOADER_SIZE);
bootloaderCRC |= CRC_calc((void *) 0x0FE081B2, (void *) 0x0FE08200) << 16;
bootloaderCRC |= CRC_calc((void *) 0x0FE081B2, (void *) 0x0FE08200) << 16;
*/
StartRTC();
......
####################################################################
# Makefile #
####################################################################
.SUFFIXES: # ignore builtin rules
.PHONY: all debug release clean flash
####################################################################
# Definitions #
####################################################################
DEVICE = EFM32GG330F1024
PROJECTNAME_MAIN = usb_uart_bootloader
PROJECTNAME = usb_uart_bootloader_loader
# Name of interface configuration file used by OpenOCD
OOCD_IFACE ?= stlink-v2-1
OBJ_DIR = build
EXE_DIR = exe
LST_DIR = lst
####################################################################
# Definitions of toolchain. #
# You might need to do changes to match your system setup #
####################################################################
# Change path to the tools according to your system configuration
# DO NOT add trailing whitespace chars, they do matter !
WINDOWSCS ?= GNU Tools ARM Embedded\4.7 2012q4
LINUXCS ?= /opt/gcc-arm-none-eabi-4_8-2014q1
RMDIRS := rm -rf
RMFILES := rm -rf
ALLFILES := /*.*
NULLDEVICE := /dev/null
SHELLNAMES := $(ComSpec)$(COMSPEC)
# HACK: Separately specifiy includes dir so we can keep it separate from the application.
#COMMONSW := C:/Users/xxxxxx/AppData/Roaming/energymicro
COMMONSW := ../../common
# Try autodetecting the environment
ifeq ($(SHELLNAMES),)
# Assume we are making on a Linux platform
TOOLDIR := $(LINUXCS)
else
QUOTE :="
ifneq ($(COMSPEC),)
# Assume we are making on a mingw/msys/cygwin platform running on Windows
# This is a convenient place to override TOOLDIR, DO NOT add trailing
# whitespace chars, they do matter !
TOOLDIR := $(PROGRAMFILES)/$(WINDOWSCS)
ifeq ($(findstring cygdrive,$(shell set)),)
# We were not on a cygwin platform
NULLDEVICE := NUL
endif
else
# Assume we are making on a Windows platform
# This is a convenient place to override TOOLDIR, DO NOT add trailing
# whitespace chars, they do matter !
SHELL := $(SHELLNAMES)
TOOLDIR := $(ProgramFiles)/$(WINDOWSCS)
RMDIRS := rd /s /q
RMFILES := del /s /q
ALLFILES := \*.*
NULLDEVICE := NUL
endif
endif
# Create directories and do a clean which is compatible with parallell make
$(shell mkdir $(OBJ_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(EXE_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(LST_DIR)>$(NULLDEVICE) 2>&1)
ifeq (clean,$(findstring clean, $(MAKECMDGOALS)))
ifneq ($(filter $(MAKECMDGOALS),all debug release),)
$(shell $(RMFILES) $(OBJ_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(EXE_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(LST_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
endif
endif
CC = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-gcc$(QUOTE)
LD = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ld$(QUOTE)
AR = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ar$(QUOTE)
OBJCOPY = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objcopy$(QUOTE)
DUMP = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objdump$(QUOTE)
####################################################################
# Flags #
####################################################################
# -MMD : Don't generate dependencies on system header files.
# -MP : Add phony targets, useful when a h-file is removed from a project.
# -MF : Specify a file to write the dependencies to.
DEPFLAGS = -MMD -MP -MF $(@:.o=.d)
#
# Add -Wa,-ahld=$(LST_DIR)/$(@F:.o=.lst) to CFLAGS to produce assembly list files
#
override CFLAGS += -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb \
-ffunction-sections \
-fdata-sections -fomit-frame-pointer \
$(DEPFLAGS)
override ASMFLAGS += -x assembler-with-cpp -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb
#
# NOTE: The -Wl,--gc-sections flag may interfere with debugging using gdb.
#
#override LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3 \
#-mthumb -T$(COMMONSW)/Device/EnergyMicro/EFM32GG/Source/G++/efm32gg.ld \
# -Wl,--gc-sections
#LOADER_LDFLAGS = $(LDFLAGS)
override LOADER_LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3 \
-mthumb -T../efm32gg-rom.ld \
-Wl,--gc-sections
override LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3 \
-mthumb -T../efm32gg-ram.ld \
-Wl,--gc-sections
LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
INCLUDEPATHS += \
-I$(COMMONSW) \
-I$(COMMONSW)/CMSIS/Include \
-I$(COMMONSW)/Device/EnergyMicro/EFM32GG/Include \
-I$(COMMONSW)/emlib/inc \
-I$(COMMONSW)/usb/inc \
-I$(COMMONSW)/kits/common/drivers \
-I../
####################################################################
# Files #
####################################################################
C_SRC_MAIN += \
$(COMMONSW)/Device/EnergyMicro/EFM32GG/Source/system_efm32gg.c \
$(COMMONSW)/emlib/src/em_system.c \
$(COMMONSW)/emlib/src/em_cmu.c \
$(COMMONSW)/emlib/src/em_emu.c \
$(COMMONSW)/emlib/src/em_dma.c \
$(COMMONSW)/emlib/src/em_rtc.c \
$(COMMONSW)/emlib/src/em_assert.c \
$(COMMONSW)/emlib/src/em_gpio.c \
$(COMMONSW)/emlib/src/em_prs.c \
$(COMMONSW)/emlib/src/em_int.c \
$(COMMONSW)/emlib/src/em_timer.c \
$(COMMONSW)/emlib/src/em_usart.c \
$(COMMONSW)/kits/common/drivers/retargetio.c \
$(COMMONSW)/usb/src/em_usbd.c \
$(COMMONSW)/usb/src/em_usbdch9.c \
$(COMMONSW)/usb/src/em_usbhal.c \
$(COMMONSW)/usb/src/em_usbdep.c \
$(COMMONSW)/usb/src/em_usbdint.c \
$(COMMONSW)/usb/src/em_usbtimer.c \
../autobaud.c \
../boot.c \
../bootldio.c \
../cdc.c \
../crc.c \
../flash.c \
../main.c \
../retargetdebug.c \
../xmodem.c
C_SRC_LOADER += \
$(COMMONSW)/Device/EnergyMicro/EFM32GG/Source/system_efm32gg.c \
../boot.c \
../loader.c
s_SRC +=
S_SRC += \
$(COMMONSW)/Device/EnergyMicro/EFM32GG/Source/GCC/startup_efm32gg.S
####################################################################
# Rules #
####################################################################
C_FILES_MAIN = $(notdir $(C_SRC_MAIN) )
C_FILES = $(notdir $(C_SRC) )
S_FILES = $(notdir $(S_SRC) $(s_SRC) )
#make list of source paths, sort also removes duplicates
C_PATHS_MAIN = $(sort $(dir $(C_SRC_MAIN) ) )
C_PATHS = $(sort $(dir $(C_SRC) ) )
S_PATHS = $(sort $(dir $(S_SRC) $(s_SRC) ) )
C_OBJS_MAIN = $(addprefix $(OBJ_DIR)/, $(C_FILES_MAIN:.c=.o))
C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
S_OBJS = $(if $(S_SRC), $(addprefix $(OBJ_DIR)/, $(S_FILES:.S=.o)))
s_OBJS = $(if $(s_SRC), $(addprefix $(OBJ_DIR)/, $(S_FILES:.s=.o)))
C_DEPS_MAIN = $(addprefix $(OBJ_DIR)/, $(C_FILES_MAIN:.c=.d))
C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
OBJS_MAIN = $(C_OBJS_MAIN) $(S_OBJS) $(s_OBJS)
OBJS = $(C_OBJS) $(S_OBJS) $(s_OBJS)
vpath %.c $(C_PATHS_MAIN):$(C_PATHS)
#vpath %.c_loader $(C_PATHS)
vpath %.s $(S_PATHS)
vpath %.S $(S_PATHS)
# Default build is debug build
all: debug_bootloader debug_bootloader_loader
debug: debug_bootloader debug_bootloader_loader
#release: release_bootloader debug_bootloader_loader
release: release_bootloader release_bootloader_loader
debug_bootloader: CFLAGS += -DDEBUG -Os -g3
debug_bootloader: $(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.bin
#debug_bootloader: $(EXE_DIR)/$(PROJECTNAME_MAIN).bin
release_bootloader: CFLAGS += -DNDEBUG -Os
release_bootloader: $(EXE_DIR)/$(PROJECTNAME_MAIN).bin
debug_bootloader_loader: CFLAGS += -DDEBUG -Os -g3
debug_bootloader_loader: $(EXE_DIR)/$(PROJECTNAME).bin
release_bootloader_loader: CFLAGS += -DNDEBUG -Os
release_bootloader_loader: $(EXE_DIR)/$(PROJECTNAME).bin
# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c
@echo "Building file: $<"
$(CC) $(CFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c_loader
@echo "Building file: $<"
$(CC) $(CFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Assemble .s/.S files
$(OBJ_DIR)/%.o: %.s
@echo "Assembling $<"
$(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
$(OBJ_DIR)/%.o: %.S
@echo "Assembling $<"
$(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Link
$(EXE_DIR)/$(PROJECTNAME_MAIN).out: $(OBJS_MAIN)
@echo "Linking target: $@"
$(CC) $(LDFLAGS) $(OBJS_MAIN) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME_MAIN).out
# HACK: Also allow for non-relocated version for debugging
$(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.out: $(OBJS_MAIN)
@echo "Linking target: $@"
$(CC) $(LOADER_LDFLAGS) $(OBJS_MAIN) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.out
#$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME).out
$(EXE_DIR)/$(PROJECTNAME).out: $(OBJS)
@echo "Linking target: $@"
$(CC) $(LOADER_LDFLAGS) $(OBJS) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME).out
# Create binary file
$(EXE_DIR)/$(PROJECTNAME_MAIN).bin: $(EXE_DIR)/$(PROJECTNAME_MAIN).out
@echo "Creating binary file"
$(OBJCOPY) -O binary $(EXE_DIR)/$(PROJECTNAME_MAIN).out $(EXE_DIR)/$(PROJECTNAME_MAIN).bin
@echo "Deleting loader.o to ensure it does not exist yet"
$(RM) $(OBJ_DIR)\loader.o
$(RM) ..\bootld.h
@echo "Creating blob file needed by loader loader..."
wine $(PWD)/../bin2h.exe $(PWD)/$(EXE_DIR)/$(PROJECTNAME_MAIN).bin $(PWD)/../bootld.h -v bootloader
# HACK: Also allow for a non-relocated-to-RAM version of 'main' for debugging. But still use the RAM version of the loader main when building loader-loader.
$(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.bin: $(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.out
@echo "Creating binary file"
$(OBJCOPY) -O binary $(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.out $(EXE_DIR)/$(PROJECTNAME_MAIN)-rom.bin
@echo "Deleting loader.o to ensure it does not exist yet"
$(RM) $(OBJ_DIR)\loader.o
$(RM) ..\bootld.h
@echo "Creating blob file needed by loader loader..."
wine $(PWD)/../bin2h.exe $(PWD)/$(EXE_DIR)/$(PROJECTNAME_MAIN).bin $(PWD)/../bootld.h -v bootloader
$(EXE_DIR)/$(PROJECTNAME).bin: $(EXE_DIR)/$(PROJECTNAME).out
@echo "Creating binary file"
$(OBJCOPY) -O binary $(EXE_DIR)/$(PROJECTNAME).out $(EXE_DIR)/$(PROJECTNAME).bin
# Uncomment next line to produce assembly listing of entire program
# $(DUMP) -h -S -C $(EXE_DIR)/$(PROJECTNAME).out>$(LST_DIR)/$(PROJECTNAME)out.lst
clean:
ifeq ($(filter $(MAKECMDGOALS),all debug release),)
$(RMDIRS) $(OBJ_DIR) $(LST_DIR) $(EXE_DIR)
endif
flash: $(EXE_DIR)/$(PROJECTNAME).bin
openocd -s $(COMMONSW)/openocd -f interface/$(OOCD_IFACE).cfg -f init.cfg -c "program $(EXE_DIR)/$(PROJECTNAME).bin 0 verify reset"
# include auto-generated dependency files (explicit rules)
ifneq (clean,$(findstring clean, $(MAKECMDGOALS)))
-include $(C_DEPS)
endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment