Skip to content

Commit de79f8c

Browse files
committed
first dfu release (still non functional)
1 parent ed0a147 commit de79f8c

22 files changed

Lines changed: 8027 additions & 11 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ Mkfile.old
5252
dkms.conf
5353
.vscode/
5454
apps/firmware/build/_build/
55+
.DS_Store
56+
apps/firmware/dfu_images/private.key
57+
apps/firmware/dfu_images/public_key.c
58+
_build/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "nRF5_SDK_17.0.2_d674dde"]
22
path = nRF5_SDK_17.0.2_d674dde
33
url = https://github.com/acalatrava/nRF5_SDK_17.0.2_d674dde
4+
[submodule "apps/secure_bootloader/micro-ecc"]
5+
path = apps/secure_bootloader/micro-ecc
6+
url = https://github.com/kmackay/micro-ecc

apps/firmware/README.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
11
# OpenHaystack compatible firmware for Moko M1
22

3-
Go to `build` directory and issue `make install` to compile and load the program to the device.
3+
## Installing prerequisites
4+
5+
### Get submodules
6+
```
7+
git submodule init
8+
git submodule update
9+
```
10+
11+
### Compile micro-ecc library
12+
```
13+
cd secure_bootloader/micro-ecc-build
14+
make
15+
```
16+
17+
### Generate public/private keypair
18+
```
19+
cd apps/firmware/dfu_images
20+
nrfutil keys generate private.key
21+
nrfutil keys display --key pk --format code private.key --out_file public_key.c
22+
```
23+
24+
### Compile secure_bootloader
25+
```
26+
cd secure_bootloader/build
27+
make
28+
```
29+
30+
### Copy the bootloader to the dfu_images directory
31+
```
32+
cp _build/secure_bootloader_moko.hex ../../firmware/dfu_images
33+
cd ../../
34+
```
35+
36+
### Compile the firmeare
37+
```
38+
cd firmware/build
39+
make
40+
cd ../dfu_images
41+
```
42+
43+
### Complete the final image file
44+
Copy the firmware hex to `dfu_images` directory
45+
```
46+
cp ../../firmware/build/_build/nrf52810_xxaa.hex .
47+
```
48+
49+
Generate a DFU settings page
50+
```
51+
nrfutil settings generate --family NRF52810 --application nrf52810_xxaa.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 bl_settings.hex
52+
```
53+
54+
Merge the bootloader settings, the bootloader itself, the softdevice and the app
55+
```
56+
mergehex -m bl_settings.hex secure_bootloader_moko.hex nrf52810_xxaa.hex ../../../nRF5_SDK_17.0.2_d674dde/components/softdevice/s112/hex/s112_nrf52_7.2.0_softdevice.hex --output full_dfu.hex
57+
```
458

5-
Other commands are:
6-
`make flash` to flash only the firmware code
7-
`make flash_softdevice` to flash only the softdevice
8-
`make erase` to erase the contents from the chip

apps/firmware/build/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ SRC_FILES += \
5353
$(PROJ_DIR)/ble_stack.c \
5454
$(PROJ_DIR)/openhaystack.c \
5555
$(PROJ_DIR)/main.c \
56+
$(PROJ_DIR)/dfu/ble_dfu_bonded.c \
57+
$(PROJ_DIR)/dfu/ble_dfu_unbonded.c \
58+
$(PROJ_DIR)/dfu/ble_dfu.c \
59+
$(PROJ_DIR)/dfu/nrf_dfu_svci.c \
5660
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
5761
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
5862
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
@@ -165,6 +169,9 @@ INC_FOLDERS += \
165169
$(SDK_ROOT)/components/libraries/usbd \
166170
$(SDK_ROOT)/components/libraries/stack_guard \
167171
$(SDK_ROOT)/components/libraries/log/src \
172+
$(SDK_ROOT)/components/libraries/bootloader \
173+
$(SDK_ROOT)/components/libraries/bootloader/dfu \
174+
$(SDK_ROOT)/components/libraries/bootloader/ble_dfu \
168175

169176
# Libraries common to all targets
170177
LIB_FILES += \
@@ -195,6 +202,9 @@ CFLAGS += -mfloat-abi=soft
195202
# keep every function in a separate section, this allows linker to discard unused ones
196203
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
197204
CFLAGS += -fno-builtin -fshort-enums
205+
# dfu
206+
CFLAGS += -DNRF_DFU_TRANSPORT_BLE=1
207+
CFLAGS += -DBL_SETTINGS_ACCESS_ONLY
198208

199209
# C++ flags common to all targets
200210
CXXFLAGS += $(OPT)
@@ -215,6 +225,9 @@ ASMFLAGS += -DNRFX_COREDEP_DELAY_US_LOOP_CYCLES=3
215225
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7
216226
ASMFLAGS += -DS112
217227
ASMFLAGS += -DSOFTDEVICE_PRESENT
228+
#dfu
229+
ASMFLAGS += -DNRF_DFU_TRANSPORT_BLE=1
230+
ASMFLAGS += -DBL_SETTINGS_ACCESS_ONLY
218231

219232
# Linker flags
220233
LDFLAGS += $(OPT)
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/* Linker script to configure memory regions. */
2+
3+
SEARCH_DIR(.)
4+
GROUP(-lgcc -lc -lnosys)
5+
6+
MEMORY
7+
{
8+
FLASH (rx) : ORIGIN = 0x28000, LENGTH = 0x6000
9+
RAM (rwx) : ORIGIN = 0x20002390, LENGTH = 0x3c70
10+
uicr_bootloader_start_address (r) : ORIGIN = 0x00000FF8, LENGTH = 0x4
11+
uicr_mbr_params_page (r) : ORIGIN = 0x00000FFC, LENGTH = 0x4
12+
mbr_params_page (r) : ORIGIN = 0x0002E000, LENGTH = 0x1000
13+
bootloader_settings_page (r) : ORIGIN = 0x0002F000, LENGTH = 0x1000
14+
}
15+
16+
SECTIONS
17+
{
18+
. = ALIGN(4);
19+
.uicr_bootloader_start_address :
20+
{
21+
PROVIDE(__start_uicr_bootloader_start_address = .);
22+
KEEP(*(SORT(.uicr_bootloader_start_address*)))
23+
PROVIDE(__stop_uicr_bootloader_start_address = .);
24+
} > uicr_bootloader_start_address
25+
. = ALIGN(4);
26+
.uicr_mbr_params_page :
27+
{
28+
PROVIDE(__start_uicr_mbr_params_page = .);
29+
KEEP(*(SORT(.uicr_mbr_params_page*)))
30+
PROVIDE(__stop_uicr_mbr_params_page = .);
31+
} > uicr_mbr_params_page
32+
. = ALIGN(4);
33+
.mbr_params_page(NOLOAD) :
34+
{
35+
PROVIDE(__start_mbr_params_page = .);
36+
KEEP(*(SORT(.mbr_params_page*)))
37+
PROVIDE(__stop_mbr_params_page = .);
38+
} > mbr_params_page
39+
. = ALIGN(4);
40+
.bootloader_settings_page(NOLOAD) :
41+
{
42+
PROVIDE(__start_bootloader_settings_page = .);
43+
KEEP(*(SORT(.bootloader_settings_page*)))
44+
PROVIDE(__stop_bootloader_settings_page = .);
45+
} > bootloader_settings_page
46+
}
47+
48+
SECTIONS
49+
{
50+
. = ALIGN(4);
51+
.mem_section_dummy_ram :
52+
{
53+
}
54+
.log_dynamic_data :
55+
{
56+
PROVIDE(__start_log_dynamic_data = .);
57+
KEEP(*(SORT(.log_dynamic_data*)))
58+
PROVIDE(__stop_log_dynamic_data = .);
59+
} > RAM
60+
.log_filter_data :
61+
{
62+
PROVIDE(__start_log_filter_data = .);
63+
KEEP(*(SORT(.log_filter_data*)))
64+
PROVIDE(__stop_log_filter_data = .);
65+
} > RAM
66+
.fs_data :
67+
{
68+
PROVIDE(__start_fs_data = .);
69+
KEEP(*(.fs_data))
70+
PROVIDE(__stop_fs_data = .);
71+
} > RAM
72+
73+
} INSERT AFTER .data;
74+
75+
SECTIONS
76+
{
77+
.mem_section_dummy_rom :
78+
{
79+
}
80+
.crypto_data :
81+
{
82+
PROVIDE(__start_crypto_data = .);
83+
KEEP(*(SORT(.crypto_data*)))
84+
PROVIDE(__stop_crypto_data = .);
85+
} > FLASH
86+
.log_const_data :
87+
{
88+
PROVIDE(__start_log_const_data = .);
89+
KEEP(*(SORT(.log_const_data*)))
90+
PROVIDE(__stop_log_const_data = .);
91+
} > FLASH
92+
.nrf_queue :
93+
{
94+
PROVIDE(__start_nrf_queue = .);
95+
KEEP(*(.nrf_queue))
96+
PROVIDE(__stop_nrf_queue = .);
97+
} > FLASH
98+
.dfu_trans :
99+
{
100+
PROVIDE(__start_dfu_trans = .);
101+
KEEP(*(SORT(.dfu_trans*)))
102+
PROVIDE(__stop_dfu_trans = .);
103+
} > FLASH
104+
.nrf_balloc :
105+
{
106+
PROVIDE(__start_nrf_balloc = .);
107+
KEEP(*(.nrf_balloc))
108+
PROVIDE(__stop_nrf_balloc = .);
109+
} > FLASH
110+
.svc_data :
111+
{
112+
PROVIDE(__start_svc_data = .);
113+
KEEP(*(.svc_data))
114+
PROVIDE(__stop_svc_data = .);
115+
} > FLASH
116+
.sdh_ble_observers :
117+
{
118+
PROVIDE(__start_sdh_ble_observers = .);
119+
KEEP(*(SORT(.sdh_ble_observers*)))
120+
PROVIDE(__stop_sdh_ble_observers = .);
121+
} > FLASH
122+
.sdh_req_observers :
123+
{
124+
PROVIDE(__start_sdh_req_observers = .);
125+
KEEP(*(SORT(.sdh_req_observers*)))
126+
PROVIDE(__stop_sdh_req_observers = .);
127+
} > FLASH
128+
.sdh_state_observers :
129+
{
130+
PROVIDE(__start_sdh_state_observers = .);
131+
KEEP(*(SORT(.sdh_state_observers*)))
132+
PROVIDE(__stop_sdh_state_observers = .);
133+
} > FLASH
134+
.sdh_stack_observers :
135+
{
136+
PROVIDE(__start_sdh_stack_observers = .);
137+
KEEP(*(SORT(.sdh_stack_observers*)))
138+
PROVIDE(__stop_sdh_stack_observers = .);
139+
} > FLASH
140+
.sdh_soc_observers :
141+
{
142+
PROVIDE(__start_sdh_soc_observers = .);
143+
KEEP(*(SORT(.sdh_soc_observers*)))
144+
PROVIDE(__stop_sdh_soc_observers = .);
145+
} > FLASH
146+
147+
} INSERT AFTER .text
148+
149+
150+
INCLUDE "nrf_common.ld"

apps/firmware/config/sdk_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@
12941294

12951295

12961296
#ifndef BLE_DFU_ENABLED
1297-
#define BLE_DFU_ENABLED 0
1297+
#define BLE_DFU_ENABLED 1
12981298
#endif
12991299

13001300
// <q> NRF_DFU_BLE_BUTTONLESS_SUPPORTS_BONDS - Buttonless DFU supports bonds.
@@ -6550,7 +6550,7 @@
65506550

65516551

65526552
#ifndef NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY
6553-
#define NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY 0
6553+
#define NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY 1
65546554
#endif
65556555

65566556
// <q> NRF_PWR_MGMT_CONFIG_USE_SCHEDULER - Module will use @ref app_scheduler.
@@ -9999,7 +9999,7 @@
99999999

1000010000

1000110001
#ifndef NRF_SDH_BLE_SERVICE_CHANGED
10002-
#define NRF_SDH_BLE_SERVICE_CHANGED 0
10002+
#define NRF_SDH_BLE_SERVICE_CHANGED 1
1000310003
#endif
1000410004

1000510005
// </h>

0 commit comments

Comments
 (0)