Skip to content

Commit 61e53b9

Browse files
committed
da14531: Add support for new chip
1 parent f12c725 commit 61e53b9

85 files changed

Lines changed: 4687 additions & 174 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ make -j8 bootloader-btc
5555
make -j8 bootloader-btc-development
5656
make -j8 bootloader-btc-production
5757

58+
make -j8 bootloader-plus
59+
make -j8 bootloader-plus-development
60+
5861
# Firmware
5962
make -j8 firmware
6063
make -j8 firmware-btc

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "external/optiga-trust-m"]
1414
path = external/optiga-trust-m
1515
url = https://github.com/BitBoxSwiss/optiga-trust-m.git
16+
[submodule "external/embedded-swd"]
17+
path = external/embedded-swd
18+
url = https://github.com/BitBoxSwiss/embedded-swd

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ string(APPEND CMAKE_C_FLAGS " -Wno-cast-function-type")
328328

329329
# Enable stack protection on release builds
330330
if(NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG")
331-
string(APPEND CMAKE_C_FLAGS " -fstack-protector-all")
331+
string(APPEND CMAKE_C_FLAGS " -fstack-protector-strong")
332332
if(CMAKE_CROSSCOMPILING)
333333
# Path to empty dummy libssp and libssp_shared. '-llibssp -llibssp_shared' is automatically added
334334
# with '-fstack-protector-all', but we don't need them as we have our own custom

Makefile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ firmware-btc: | build
6464
firmware-debug: | build-debug
6565
$(MAKE) -C build-debug firmware.elf
6666
bootloader: | build
67-
$(MAKE) -C build bootloader.elf
67+
$(MAKE) -C build bb02-bl-multi.elf
6868
bootloader-development: | build
69-
$(MAKE) -C build bootloader-development.elf
69+
$(MAKE) -C build bb02-bl-multi-development.elf
70+
bootloader-plus: | build
71+
$(MAKE) -C build bb02p-bl-multi.elf
72+
bootloader-plus-development: | build
73+
$(MAKE) -C build bb02p-bl-multi-development.elf
7074
bootloader-development-locked: | build
71-
$(MAKE) -C build bootloader-development-locked.elf
75+
$(MAKE) -C build bb02-bl-multi-development-locked.elf
7276
bootloader-production: | build
73-
$(MAKE) -C build bootloader-production.elf
77+
$(MAKE) -C build bb02-bl-multi-production.elf
7478
bootloader-btc: | build
75-
$(MAKE) -C build bootloader-btc.elf
79+
$(MAKE) -C build bb02-bl-btconly.elf
7680
bootloader-btc-development: | build
77-
$(MAKE) -C build bootloader-btc-development.elf
81+
$(MAKE) -C build bb02-bl-btconly-development.elf
7882
bootloader-btc-production: | build
79-
$(MAKE) -C build bootloader-btc-production.elf
83+
$(MAKE) -C build bb02-bl-btconly-production.elf
8084
factory-setup: | build
8185
$(MAKE) -C build factory-setup.elf
8286
docs: | build
@@ -106,15 +110,17 @@ run-valgrind-on-unit-tests:
106110
flash-dev-firmware:
107111
./py/load_firmware.py build/bin/firmware.bin --debug
108112
jlink-flash-bootloader-development: | build
109-
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bootloader-development.jlink
113+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02-bl-multi-development.jlink
114+
jlink-flash-bootloader-plus-development: | build
115+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02p-bl-multi-development.jlink
110116
jlink-flash-bootloader-development-locked: | build
111-
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bootloader-development-locked.jlink
117+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02-bl-multi-development-locked.jlink
112118
jlink-flash-bootloader: | build
113-
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bootloader.jlink
119+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02-bl-multi.jlink
114120
jlink-flash-bootloader-btc-development: | build
115-
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bootloader-btc-development.jlink
121+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02-bl-btc-development.jlink
116122
jlink-flash-bootloader-btc: | build
117-
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bootloader-btc.jlink
123+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/bb02-bl-btc.jlink
118124
jlink-flash-firmware: | build
119125
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build/scripts/firmware.jlink
120126
jlink-flash-firmware-btc: | build
@@ -133,12 +139,16 @@ jlink-flash-set-securechip-optiga:
133139
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./scripts/set-securechip-optiga.jlink
134140
jlink-flash-set-bb02plus:
135141
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./scripts/set-bb02plus.jlink
142+
jlink-erase-firmware-quick:
143+
JLinkExe -NoGui 1 -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./scripts/erase-firmware-quick.jlink
136144
jlink-gdb-server:
137145
JLinkGDBServer -nogui -if SWD -device ATSAMD51J20 -speed 4000
138146
rtt-client:
139147
telnet localhost 19021
140148
run-debug:
141149
arm-none-eabi-gdb -x scripts/jlink.gdb build-debug/bin/firmware.elf
150+
run-bootloader:
151+
arm-none-eabi-gdb -x scripts/jlink-bootloader.gdb build/bin/bb02p-bl-multi-development.elf
142152
dockerinit:
143153
./scripts/container.sh build --pull --force-rm --no-cache -t shiftcrypto/firmware_v2:$(shell cat .containerversion) .
144154
dockerpull:

bitbox-da14531-firmware.o

24.4 KB
Binary file not shown.

external/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ if(CMAKE_CROSSCOMPILING)
116116
asf4-drivers/hal/src/hal_io.c
117117
asf4-drivers/hal/src/hal_sha_sync.c
118118
asf4-drivers/hpl/systick/hpl_systick.c
119+
asf4-drivers/hal/src/hal_usart_async.c
120+
asf4-drivers/hal/utils/src/utils_ringbuffer.c
119121
asf4-drivers/hpl/gclk/hpl_gclk.c
120122
asf4-drivers/hpl/oscctrl/hpl_oscctrl.c
121123
asf4-drivers/hpl/mclk/hpl_mclk.c
@@ -142,6 +144,8 @@ if(CMAKE_CROSSCOMPILING)
142144

143145
target_link_libraries(asf4-drivers-min samd51a-ds)
144146
set_property(TARGET asf4-drivers-min PROPERTY INTERFACE_LINK_LIBRARIES "")
147+
target_compile_options(asf4-drivers-min PRIVATE -Wno-cast-qual
148+
-Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations)
145149

146150
target_include_directories(asf4-drivers-min SYSTEM
147151
PUBLIC
@@ -240,6 +244,22 @@ set_property(TARGET asf4-drivers PROPERTY INTERFACE_LINK_LIBRARIES "")
240244
-Wno-pedantic -Wno-incompatible-pointer-types -Wno-unused-parameter -Wno-unused-variable -Wno-cast-qual
241245
-Wno-switch-default -Wno-format-nonliteral -Wno-missing-prototypes -Wno-missing-declarations
242246
)
247+
add_library(embedded-swd
248+
embedded-swd/dap.c
249+
embedded-swd/dap_target.c
250+
)
251+
target_include_directories(embedded-swd SYSTEM PUBLIC
252+
embedded-swd
253+
)
254+
target_link_libraries(embedded-swd
255+
PRIVATE
256+
CMSIS
257+
)
258+
target_link_libraries(embedded-swd
259+
PUBLIC
260+
samd51a-ds
261+
)
262+
243263
endif() # CMAKE_CROSSCOMPILING
244264

245265
# fatfs must to be linked together with a diskio middleware:

external/asf4-drivers/Config/hpl_sercom_config.h

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,238 @@
66

77
#include <peripheral_clk_config.h>
88

9+
#ifndef CONF_SERCOM_0_USART_ENABLE
10+
#define CONF_SERCOM_0_USART_ENABLE 1
11+
#endif
12+
13+
// <h> Basic Configuration
14+
15+
// <q> Receive buffer enable
16+
// <i> Enable input buffer in SERCOM module
17+
// <id> usart_rx_enable
18+
#ifndef CONF_SERCOM_0_USART_RXEN
19+
#define CONF_SERCOM_0_USART_RXEN 1
20+
#endif
21+
22+
// <q> Transmitt buffer enable
23+
// <i> Enable output buffer in SERCOM module
24+
// <id> usart_tx_enable
25+
#ifndef CONF_SERCOM_0_USART_TXEN
26+
#define CONF_SERCOM_0_USART_TXEN 1
27+
#endif
28+
29+
// <o> Frame parity
30+
// <0x0=>No parity
31+
// <0x1=>Even parity
32+
// <0x2=>Odd parity
33+
// <i> Parity bit mode for USART frame
34+
// <id> usart_parity
35+
#ifndef CONF_SERCOM_0_USART_PARITY
36+
#define CONF_SERCOM_0_USART_PARITY 0x0
37+
#endif
38+
39+
// <o> Character Size
40+
// <0x0=>8 bits
41+
// <0x1=>9 bits
42+
// <0x5=>5 bits
43+
// <0x6=>6 bits
44+
// <0x7=>7 bits
45+
// <i> Data character size in USART frame
46+
// <id> usart_character_size
47+
#ifndef CONF_SERCOM_0_USART_CHSIZE
48+
#define CONF_SERCOM_0_USART_CHSIZE 0x0
49+
#endif
50+
51+
// <o> Stop Bit
52+
// <0=>One stop bit
53+
// <1=>Two stop bits
54+
// <i> Number of stop bits in USART frame
55+
// <id> usart_stop_bit
56+
#ifndef CONF_SERCOM_0_USART_SBMODE
57+
#define CONF_SERCOM_0_USART_SBMODE 0
58+
#endif
59+
60+
// <o> Baud rate <1-6250000>
61+
// <i> USART baud rate setting
62+
// <id> usart_baud_rate
63+
#ifndef CONF_SERCOM_0_USART_BAUD
64+
#define CONF_SERCOM_0_USART_BAUD 115200
65+
#endif
66+
67+
// </h>
68+
69+
// <e> Advanced configuration
70+
// <id> usart_advanced
71+
#ifndef CONF_SERCOM_0_USART_ADVANCED_CONFIG
72+
#define CONF_SERCOM_0_USART_ADVANCED_CONFIG 0
73+
#endif
74+
75+
// <q> Run in stand-by
76+
// <i> Keep the module running in standby sleep mode
77+
// <id> usart_arch_runstdby
78+
#ifndef CONF_SERCOM_0_USART_RUNSTDBY
79+
#define CONF_SERCOM_0_USART_RUNSTDBY 0
80+
#endif
81+
82+
// <q> Immediate Buffer Overflow Notification
83+
// <i> Controls when the BUFOVF status bit is asserted
84+
// <id> usart_arch_ibon
85+
#ifndef CONF_SERCOM_0_USART_IBON
86+
#define CONF_SERCOM_0_USART_IBON 0
87+
#endif
88+
89+
// <q> Start of Frame Detection Enable
90+
// <i> Will wake the device from any sleep mode if usart_init and usart_enable was run priort to going to sleep. (receive buffer must be enabled)
91+
// <id> usart_arch_sfde
92+
#ifndef CONF_SERCOM_0_USART_SFDE
93+
#define CONF_SERCOM_0_USART_SFDE 0
94+
#endif
95+
96+
// <q> Collision Detection Enable
97+
// <i> Collision detection enable
98+
// <id> usart_arch_cloden
99+
#ifndef CONF_SERCOM_0_USART_CLODEN
100+
#define CONF_SERCOM_0_USART_CLODEN 0
101+
#endif
102+
103+
// <o> Operating Mode
104+
// <0x0=>USART with external clock
105+
// <0x1=>USART with internal clock
106+
// <i> Drive the shift register by an internal clock generated by the baud rate generator or an external clock supplied on the XCK pin.
107+
// <id> usart_arch_clock_mode
108+
#ifndef CONF_SERCOM_0_USART_MODE
109+
#define CONF_SERCOM_0_USART_MODE 0x1
110+
#endif
111+
112+
// Does not do anything in USRT mode
113+
#define CONF_SERCOM_0_USART_SAMPR 0x0
114+
#define CONF_SERCOM_0_USART_SAMPA 0x0
115+
#define CONF_SERCOM_0_USART_FRACTIONAL 0x0
116+
117+
// <o> Data Order
118+
// <0=>MSB is transmitted first
119+
// <1=>LSB is transmitted first
120+
// <i> Data order of the data bits in the frame
121+
// <id> usart_arch_dord
122+
#ifndef CONF_SERCOM_0_USART_DORD
123+
#define CONF_SERCOM_0_USART_DORD 1
124+
#endif
125+
126+
// Does not do anything in UART mode
127+
#define CONF_SERCOM_0_USART_CPOL 0
128+
129+
// Does not do anything in USRT mode
130+
#define CONF_SERCOM_0_USART_ENC 0
131+
132+
// Does not do anything in USRT mode
133+
#define CONF_SERCOM_0_USART_LIN_SLAVE_ENABLE 0
134+
135+
// <o> Debug Stop Mode
136+
// <i> Behavior of the baud-rate generator when CPU is halted by external debugger.
137+
// <0=>Keep running
138+
// <1=>Halt
139+
// <id> usart_arch_dbgstop
140+
#ifndef CONF_SERCOM_0_USART_DEBUG_STOP_MODE
141+
#define CONF_SERCOM_0_USART_DEBUG_STOP_MODE 0
142+
#endif
143+
144+
// </e>
145+
146+
#ifndef CONF_SERCOM_0_USART_INACK
147+
#define CONF_SERCOM_0_USART_INACK 0x0
148+
#endif
149+
150+
#ifndef CONF_SERCOM_0_USART_DSNACK
151+
#define CONF_SERCOM_0_USART_DSNACK 0x0
152+
#endif
153+
154+
#ifndef CONF_SERCOM_0_USART_MAXITER
155+
#define CONF_SERCOM_0_USART_MAXITER 0x7
156+
#endif
157+
158+
#ifndef CONF_SERCOM_0_USART_GTIME
159+
#define CONF_SERCOM_0_USART_GTIME 0x2
160+
#endif
161+
162+
#define CONF_SERCOM_0_USART_RXINV 0x0
163+
#define CONF_SERCOM_0_USART_TXINV 0x0
164+
165+
#ifndef CONF_SERCOM_0_USART_CMODE
166+
#define CONF_SERCOM_0_USART_CMODE 0
167+
#endif
168+
169+
#ifndef CONF_SERCOM_0_USART_RXPO
170+
#define CONF_SERCOM_0_USART_RXPO 1 /* RX is on PIN_PA05 */
171+
#endif
172+
173+
#ifndef CONF_SERCOM_0_USART_TXPO
174+
#define CONF_SERCOM_0_USART_TXPO 2 /* TX is on PIN_PA04 */
175+
#endif
176+
177+
/* Set correct parity settings in register interface based on PARITY setting */
178+
#if CONF_SERCOM_0_USART_LIN_SLAVE_ENABLE == 1
179+
#if CONF_SERCOM_0_USART_PARITY == 0
180+
#define CONF_SERCOM_0_USART_PMODE 0
181+
#define CONF_SERCOM_0_USART_FORM 4
182+
#else
183+
#define CONF_SERCOM_0_USART_PMODE CONF_SERCOM_0_USART_PARITY - 1
184+
#define CONF_SERCOM_0_USART_FORM 5
185+
#endif
186+
#else /* #if CONF_SERCOM_0_USART_LIN_SLAVE_ENABLE == 0 */
187+
#if CONF_SERCOM_0_USART_PARITY == 0
188+
#define CONF_SERCOM_0_USART_PMODE 0
189+
#define CONF_SERCOM_0_USART_FORM 0
190+
#else
191+
#define CONF_SERCOM_0_USART_PMODE CONF_SERCOM_0_USART_PARITY - 1
192+
#define CONF_SERCOM_0_USART_FORM 1
193+
#endif
194+
#endif
195+
196+
// Calculate BAUD register value in UART mode
197+
#if CONF_SERCOM_0_USART_SAMPR == 0
198+
#ifndef CONF_SERCOM_0_USART_BAUD_RATE
199+
#define CONF_SERCOM_0_USART_BAUD_RATE \
200+
65536 - ((65536 * 16.0f * CONF_SERCOM_0_USART_BAUD) / CONF_GCLK_SERCOM0_CORE_FREQUENCY)
201+
#endif
202+
#ifndef CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH
203+
#define CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH 0
204+
#endif
205+
#elif CONF_SERCOM_0_USART_SAMPR == 1
206+
#ifndef CONF_SERCOM_0_USART_BAUD_RATE
207+
#define CONF_SERCOM_0_USART_BAUD_RATE \
208+
((CONF_GCLK_SERCOM0_CORE_FREQUENCY) / (CONF_SERCOM_0_USART_BAUD * 16)) - (CONF_SERCOM_0_USART_FRACTIONAL / 8)
209+
#endif
210+
#ifndef CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH
211+
#define CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH 0
212+
#endif
213+
#elif CONF_SERCOM_0_USART_SAMPR == 2
214+
#ifndef CONF_SERCOM_0_USART_BAUD_RATE
215+
#define CONF_SERCOM_0_USART_BAUD_RATE \
216+
65536 - ((65536 * 8.0f * CONF_SERCOM_0_USART_BAUD) / CONF_GCLK_SERCOM0_CORE_FREQUENCY)
217+
#endif
218+
#ifndef CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH
219+
#define CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH 0
220+
#endif
221+
#elif CONF_SERCOM_0_USART_SAMPR == 3
222+
#ifndef CONF_SERCOM_0_USART_BAUD_RATE
223+
#define CONF_SERCOM_0_USART_BAUD_RATE \
224+
((CONF_GCLK_SERCOM0_CORE_FREQUENCY) / (CONF_SERCOM_0_USART_BAUD * 8)) - (CONF_SERCOM_0_USART_FRACTIONAL / 8)
225+
#endif
226+
#ifndef CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH
227+
#define CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH 0
228+
#endif
229+
#elif CONF_SERCOM_0_USART_SAMPR == 4
230+
#ifndef CONF_SERCOM_0_USART_BAUD_RATE
231+
#define CONF_SERCOM_0_USART_BAUD_RATE \
232+
65536 - ((65536 * 3.0f * CONF_SERCOM_0_USART_BAUD) / CONF_GCLK_SERCOM0_CORE_FREQUENCY)
233+
#endif
234+
#ifndef CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH
235+
#define CONF_SERCOM_0_USART_RECEIVE_PULSE_LENGTH 0
236+
#endif
237+
#endif
238+
239+
#include <peripheral_clk_config.h>
240+
9241
#ifndef SERCOM_I2CM_CTRLA_MODE_I2C_MASTER
10242
#define SERCOM_I2CM_CTRLA_MODE_I2C_MASTER (5 << 2)
11243
#endif

0 commit comments

Comments
 (0)