Skip to content

Commit 13e2406

Browse files
committed
DM: update m4 bootloader for multiple targets
1 parent 2b39437 commit 13e2406

File tree

6 files changed

+304
-10
lines changed

6 files changed

+304
-10
lines changed
-512 Bytes
Binary file not shown.

bootloaders/metroM4/Makefile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,21 @@ SIZE=$(ARM_GCC_PATH)size
5858
# -----------------------------------------------------------------------------
5959
# Boards definitions
6060
BOARD_ID?=FEATHER_M4
61+
BOARD_CHIP?=__SAMD51G19A__
6162

6263
# -----------------------------------------------------------------------------
6364
# Compiler options
64-
CFLAGS_EXTRA=-D__SAMD51G19A__ -DBOARD_ID_$(BOARD_ID)
65+
CFLAGS_EXTRA=-D$(BOARD_CHIP) -DBOARD_ID_$(BOARD_ID)
6566
CFLAGS=-mthumb -mcpu=cortex-m4 -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
6667
ifdef DEBUG
6768
CFLAGS+=-g3 -O1 -DDEBUG=1
6869
else
6970
CFLAGS+=-Os -DDEBUG=0
7071
endif
7172

72-
#DM: hack b/c I don't know how things work
73-
#ELF=$(NAME).elf
74-
ELF=samd51_sam_ba.elf
75-
BIN=samd51_sam_ba.bin
76-
HEX=samd51_sam_ba.hex
73+
ELF=$(BOARD_ID)_sam_ba.elf
74+
BIN=$(BOARD_ID)_ba.bin
75+
HEX=$(BOARD_ID)_sam_ba.hex
7776

7877

7978
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.5.0/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/"
@@ -114,7 +113,7 @@ all: print_info $(SOURCES) $(BIN) $(HEX) $(AS_BUILD)
114113
$(ELF): Makefile $(BUILD_PATH) $(OBJECTS)
115114
@echo ----------------------------------------------------------
116115
@echo Creating ELF binary
117-
"$(CC)" -L. -L$(BUILD_PATH) $(LDFLAGS) -Os -Wl,--gc-sections -save-temps -Tbootloader_samd51.ld -Wl,-Map,"$(BUILD_PATH)/$(NAME).map" -o "$(BUILD_PATH)/$(ELF)" -Wl,--start-group $(OBJECTS) -lm -Wl,--end-group
116+
"$(CC)" -L. -L$(BUILD_PATH) $(LDFLAGS) -Os -Wl,--gc-sections -save-temps -Tbootloader_$(BOARD_ID).ld -Wl,-Map,"$(BUILD_PATH)/$(NAME).map" -o "$(BUILD_PATH)/$(ELF)" -Wl,--start-group $(OBJECTS) -lm -Wl,--end-group
118117
"$(NM)" "$(BUILD_PATH)/$(ELF)" >"$(BUILD_PATH)/$(NAME)_symbols.txt"
119118
"$(SIZE)" --format=sysv -t -x $(BUILD_PATH)/$(ELF)
120119

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
3+
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
See the GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/* Linker script to configure memory regions.
21+
* Need modifying for a specific board.
22+
* FLASH.ORIGIN: starting address of flash
23+
* FLASH.LENGTH: length of flash
24+
* RAM.ORIGIN: starting address of RAM bank 0
25+
* RAM.LENGTH: length of RAM bank 0
26+
*/
27+
28+
MEMORY
29+
{
30+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x4000 /* First 16KB used by bootloader */
31+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000-0x0004 /* 4 bytes used by bootloader to keep data between resets */
32+
}
33+
34+
/* Linker script to place sections and symbol values. Should be used together
35+
* with other linker script that defines memory regions FLASH and RAM.
36+
* It references following symbols, which must be defined in code:
37+
* Reset_Handler : Entry of reset handler
38+
*
39+
* It defines following symbols, which code can use without definition:
40+
* __exidx_start
41+
* __exidx_end
42+
* __copy_table_start__
43+
* __copy_table_end__
44+
* __zero_table_start__
45+
* __zero_table_end__
46+
* __etext
47+
* __data_start__
48+
* __preinit_array_start
49+
* __preinit_array_end
50+
* __init_array_start
51+
* __init_array_end
52+
* __fini_array_start
53+
* __fini_array_end
54+
* __data_end__
55+
* __bss_start__
56+
* __bss_end__
57+
* __end__
58+
* end
59+
* __HeapLimit
60+
* __StackLimit
61+
* __StackTop
62+
* __stack
63+
* __sketch_vectors_ptr
64+
*/
65+
ENTRY(Reset_Handler)
66+
67+
SECTIONS
68+
{
69+
. = ORIGIN(FLASH);
70+
71+
.vectors :
72+
{
73+
KEEP(*(.isr_vector))
74+
} > FLASH
75+
76+
.text :
77+
{
78+
*(.text*)
79+
80+
KEEP(*(.init))
81+
KEEP(*(.fini))
82+
83+
/* .ctors */
84+
*crtbegin.o(.ctors)
85+
*crtbegin?.o(.ctors)
86+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
87+
*(SORT(.ctors.*))
88+
*(.ctors)
89+
90+
/* .dtors */
91+
*crtbegin.o(.dtors)
92+
*crtbegin?.o(.dtors)
93+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
94+
*(SORT(.dtors.*))
95+
*(.dtors)
96+
97+
*(.rodata*)
98+
99+
KEEP(*(.eh_frame*))
100+
} > FLASH
101+
102+
.ARM.extab :
103+
{
104+
*(.ARM.extab* .gnu.linkonce.armextab.*)
105+
} > FLASH
106+
107+
__exidx_start = .;
108+
.ARM.exidx :
109+
{
110+
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
111+
} > FLASH
112+
__exidx_end = .;
113+
114+
/* To copy multiple ROM to RAM sections,
115+
* uncomment .copy.table section and,
116+
* define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
117+
/*
118+
.copy.table :
119+
{
120+
. = ALIGN(4);
121+
__copy_table_start__ = .;
122+
LONG (__etext)
123+
LONG (__data_start__)
124+
LONG (__data_end__ - __data_start__)
125+
LONG (__etext2)
126+
LONG (__data2_start__)
127+
LONG (__data2_end__ - __data2_start__)
128+
__copy_table_end__ = .;
129+
} > FLASH
130+
*/
131+
132+
/* To clear multiple BSS sections,
133+
* uncomment .zero.table section and,
134+
* define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
135+
/*
136+
.zero.table :
137+
{
138+
. = ALIGN(4);
139+
__zero_table_start__ = .;
140+
LONG (__bss_start__)
141+
LONG (__bss_end__ - __bss_start__)
142+
LONG (__bss2_start__)
143+
LONG (__bss2_end__ - __bss2_start__)
144+
__zero_table_end__ = .;
145+
} > FLASH
146+
*/
147+
148+
__etext = .;
149+
PROVIDE(__sketch_vectors_ptr = ORIGIN(FLASH) + LENGTH(FLASH));
150+
151+
152+
.data : AT (__etext)
153+
{
154+
__data_start__ = .;
155+
*(vtable)
156+
*(.data*)
157+
158+
. = ALIGN(4);
159+
/* preinit data */
160+
PROVIDE_HIDDEN (__preinit_array_start = .);
161+
KEEP(*(.preinit_array))
162+
PROVIDE_HIDDEN (__preinit_array_end = .);
163+
164+
. = ALIGN(4);
165+
/* init data */
166+
PROVIDE_HIDDEN (__init_array_start = .);
167+
KEEP(*(SORT(.init_array.*)))
168+
KEEP(*(.init_array))
169+
PROVIDE_HIDDEN (__init_array_end = .);
170+
171+
172+
. = ALIGN(4);
173+
/* finit data */
174+
PROVIDE_HIDDEN (__fini_array_start = .);
175+
KEEP(*(SORT(.fini_array.*)))
176+
KEEP(*(.fini_array))
177+
PROVIDE_HIDDEN (__fini_array_end = .);
178+
179+
KEEP(*(.jcr*))
180+
. = ALIGN(4);
181+
/* All data end */
182+
__data_end__ = .;
183+
184+
} > RAM
185+
186+
.bss :
187+
{
188+
. = ALIGN(4);
189+
__bss_start__ = .;
190+
*(.bss*)
191+
*(COMMON)
192+
. = ALIGN(4);
193+
__bss_end__ = .;
194+
} > RAM
195+
196+
.heap (COPY):
197+
{
198+
__end__ = .;
199+
PROVIDE(end = .);
200+
*(.heap*)
201+
__HeapLimit = .;
202+
} > RAM
203+
204+
/* .stack_dummy section doesn't contains any symbols. It is only
205+
* used for linker to calculate size of stack sections, and assign
206+
* values to stack symbols later */
207+
.stack_dummy (COPY):
208+
{
209+
*(.stack*)
210+
} > RAM
211+
212+
/* Set stack top to end of RAM, and stack limit move down by
213+
* size of stack_dummy section */
214+
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
215+
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
216+
PROVIDE(__stack = __StackTop);
217+
218+
__ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ;
219+
220+
/* Check if data + heap + stack exceeds RAM limit */
221+
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
222+
}

bootloaders/metroM4/samd51_sam_ba.cproj

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,76 @@
128128
<CleanTarget>clean</CleanTarget>
129129
<ExternalMakeFilePath>Makefile</ExternalMakeFilePath>
130130
</PropertyGroup>
131+
<PropertyGroup Condition=" '$(Configuration)' == 'featherm4' ">
132+
<ToolchainSettings>
133+
<ArmGcc xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
134+
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
135+
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
136+
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
137+
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
138+
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
139+
<armgcc.compiler.symbols.DefSymbols>
140+
<ListValues>
141+
<Value>DEBUG</Value>
142+
</ListValues>
143+
</armgcc.compiler.symbols.DefSymbols>
144+
<armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level>
145+
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
146+
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
147+
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
148+
<armgcc.linker.libraries.Libraries>
149+
<ListValues>
150+
<Value>libm</Value>
151+
</ListValues>
152+
</armgcc.linker.libraries.Libraries>
153+
<armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections>
154+
<armgcc.linker.miscellaneous.LinkerFlags>-Tsamd21j18a_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
155+
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
156+
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
157+
</ArmGcc>
158+
</ToolchainSettings>
159+
<UsesExternalMakeFile>True</UsesExternalMakeFile>
160+
<OutputDirectory />
161+
<BuildTarget>DEBUG=1 all BOARD_ID=FEATHER_M4 BOARD_CHIP=__SAMD51G19A__</BuildTarget>
162+
<CleanTarget>clean</CleanTarget>
163+
<ExternalMakeFilePath>Makefile</ExternalMakeFilePath>
164+
<OutputPath>bin\featherm4\</OutputPath>
165+
</PropertyGroup>
166+
<PropertyGroup Condition=" '$(Configuration)' == 'metrom4' ">
167+
<ToolchainSettings>
168+
<ArmGcc xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
169+
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
170+
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
171+
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
172+
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
173+
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
174+
<armgcc.compiler.symbols.DefSymbols>
175+
<ListValues>
176+
<Value>DEBUG</Value>
177+
</ListValues>
178+
</armgcc.compiler.symbols.DefSymbols>
179+
<armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level>
180+
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
181+
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
182+
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
183+
<armgcc.linker.libraries.Libraries>
184+
<ListValues>
185+
<Value>libm</Value>
186+
</ListValues>
187+
</armgcc.linker.libraries.Libraries>
188+
<armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections>
189+
<armgcc.linker.miscellaneous.LinkerFlags>-Tsamd21j18a_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
190+
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
191+
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
192+
</ArmGcc>
193+
</ToolchainSettings>
194+
<UsesExternalMakeFile>True</UsesExternalMakeFile>
195+
<OutputDirectory />
196+
<BuildTarget>DEBUG=1 all BOARD_ID=METRO_M4 BOARD_CHIP=__SAMD51J20A__</BuildTarget>
197+
<CleanTarget>clean</CleanTarget>
198+
<ExternalMakeFilePath>Makefile</ExternalMakeFilePath>
199+
<OutputPath>bin\metrom4\</OutputPath>
200+
</PropertyGroup>
131201
<ItemGroup>
132202
<Compile Include="board_definitions.h">
133203
<SubType>compile</SubType>
@@ -209,7 +279,10 @@
209279
</Compile>
210280
</ItemGroup>
211281
<ItemGroup>
212-
<None Include="bootloader_samd51.ld">
282+
<None Include="bootloader_FEATHER_M4.ld">
283+
<SubType>compile</SubType>
284+
</None>
285+
<None Include="bootloader_METRO_M4.ld">
213286
<SubType>compile</SubType>
214287
</None>
215288
<None Include="Makefile">

bootloaders/metroM4/samdx1_sam_ba.atsln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Global
1111
Release|ARM = Release|ARM
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.ActiveCfg = Debug|ARM
15-
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.Build.0 = Debug|ARM
14+
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.ActiveCfg = metrom4|ARM
15+
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.Build.0 = metrom4|ARM
1616
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.ActiveCfg = Release|ARM
1717
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.Build.0 = Release|ARM
1818
EndGlobalSection

0 commit comments

Comments
 (0)