Skip to content

Commit c42dce0

Browse files
committed
add debug linker when building with DEBUG=1
extend bootloader start to reserved app for debug build
1 parent 6f86906 commit c42dce0

File tree

5 files changed

+311
-6
lines changed

5 files changed

+311
-6
lines changed

Makefile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
2727
MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex
2828

2929
# linker by MCU eg. nrf52840.ld
30-
LD_FILE = linker/$(MCU_SUB_VARIANT).ld
30+
ifeq ($(DEBUG), 1)
31+
LD_FILE = linker/$(MCU_SUB_VARIANT)_debug.ld
32+
else
33+
LD_FILE = linker/$(MCU_SUB_VARIANT).ld
34+
endif
3135

3236
GIT_VERSION := $(shell git describe --dirty --always --tags)
3337
GIT_SUBMODULE_VERSIONS := $(shell git submodule status | cut -d" " -f3,4 | paste -s -d" " -)
@@ -109,17 +113,17 @@ ifeq ($(MCU_SUB_VARIANT),nrf52)
109113
SD_NAME = s132
110114
DFU_DEV_REV = 0xADAF
111115
CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132
112-
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
116+
DFU_APP_DATA_RESERVED=7*4096
113117
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
114118
SD_NAME = s140
115119
DFU_DEV_REV = 52833
116120
CFLAGS += -DNRF52833_XXAA -DS140
117-
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
121+
DFU_APP_DATA_RESERVED=7*4096
118122
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
119123
SD_NAME = s140
120124
DFU_DEV_REV = 52840
121125
CFLAGS += -DNRF52840_XXAA -DS140
122-
CFLAGS += -DDFU_APP_DATA_RESERVED=10*4096
126+
DFU_APP_DATA_RESERVED=10*4096
123127
else
124128
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
125129
endif
@@ -321,8 +325,18 @@ ifeq ($(DEBUG), 1)
321325
RTT_SRC = lib/SEGGER_RTT
322326
IPATH += $(RTT_SRC)/RTT
323327
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
328+
DFU_APP_DATA_RESERVED = 0
329+
330+
# expand bootloader address to 28KB of reserved app
331+
ifeq ($(MCU_SUB_VARIANT),nrf52840)
332+
CFLAGS += -DBOOTLOADER_REGION_START=0xED000
333+
else
334+
CFLAGS += -DBOOTLOADER_REGION_START=0x6D000
335+
endif
324336
endif
325337

338+
CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED)
339+
326340
#------------------------------------------------------------------------------
327341
# Linker Flags
328342
#------------------------------------------------------------------------------

lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ static inline bool is_sd_existed(void)
4848
#define CODE_PAGE_SIZE 0x1000 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
4949

5050
#if defined(NRF52832_XXAA) || defined(NRF52833_XXAA)
51-
// Flash = 512 KB
51+
// Flash = 512 KB, allow to be defined in debug mode
52+
#ifndef BOOTLOADER_REGION_START
5253
#define BOOTLOADER_REGION_START 0x00074000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
54+
#endif
5355
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x0007E000 /**< The field specifies the page location of the mbr params page address. */
5456
#define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
5557

5658
#elif defined(NRF52840_XXAA)
57-
// Flash = 1024 KB
59+
// Flash = 1024 KB, allow to be defined in debug mode
60+
#ifndef BOOTLOADER_REGION_START
5861
#define BOOTLOADER_REGION_START 0x000F4000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
62+
#endif
5963
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x000FE000 /**< The field specifies the page location of the mbr params page address. */
6064
#define BOOTLOADER_SETTINGS_ADDRESS 0x000FF000 /**< The field specifies the page location of the bootloader settings address. */
6165

linker/nrf52833_debug.ld

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Linker script to configure memory regions. */
2+
3+
SEARCH_DIR(.)
4+
GROUP(-lgcc -lc -lnosys)
5+
6+
MEMORY
7+
{
8+
/** Flash start address for the bootloader. This setting will also be stored in UICR to allow the
9+
* MBR to init the bootloader when starting the system. This value must correspond to
10+
* BOOTLOADER_REGION_START found in dfu_types.h. The system is prevented from starting up if
11+
* those values do not match. The check is performed in main.c, see
12+
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
13+
*/
14+
/* due to lack of flash for debug, we will use reserved app to extend bootloader size */
15+
FLASH (rx) : ORIGIN = 0x74000-28K, LENGTH = 0x7E000-0x74000-2K + 28K
16+
17+
BOOTLOADER_CONFIG (r): ORIGIN = 0x7E000 - 2K, LENGTH = 2K
18+
19+
/** Location of mbr params page in flash. */
20+
MBR_PARAMS_PAGE (rw) : ORIGIN = 0x0007E000, LENGTH = 0x1000
21+
22+
/** Location of bootloader setting in flash. */
23+
BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0007F000, LENGTH = 0x1000
24+
25+
26+
27+
/** RAM Region for bootloader. */
28+
/* Avoid conflict with NOINIT for OTA bond sharing */
29+
RAM (rwx) : ORIGIN = 0x20008000, LENGTH = 0x20020000-0x20008000
30+
31+
/* Location for double reset detection, no init */
32+
DBL_RESET (rwx) : ORIGIN = 0x20007F7C, LENGTH = 0x04
33+
34+
/** Location of non initialized RAM. Non initialized RAM is used for exchanging bond information
35+
* from application to bootloader when using buttonless DFU OTA. */
36+
NOINIT (rwx) : ORIGIN = 0x20007F80, LENGTH = 0x80
37+
38+
39+
40+
/** Location in UICR where bootloader start address is stored. */
41+
UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04
42+
43+
/** Location in UICR where mbr params page address is stored. */
44+
UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04
45+
}
46+
47+
SECTIONS
48+
{
49+
.fs_data_out ALIGN(4):
50+
{
51+
PROVIDE( __start_fs_data = .);
52+
KEEP(*(fs_data))
53+
PROVIDE( __stop_fs_data = .);
54+
} = 0
55+
56+
.bootloaderConfig :
57+
{
58+
KEEP(*(.bootloaderConfig))
59+
} > BOOTLOADER_CONFIG
60+
61+
/* Place the bootloader settings page in flash. */
62+
.bootloaderSettings(NOLOAD) :
63+
{
64+
65+
} > BOOTLOADER_SETTINGS
66+
67+
/* Write the bootloader address in UICR. */
68+
.uicrBootStartAddress :
69+
{
70+
KEEP(*(.uicrBootStartAddress))
71+
} > UICR_BOOTLOADER
72+
73+
/* Place the mbr params page in flash. */
74+
.mbrParamsPage(NOLOAD) :
75+
{
76+
77+
} > MBR_PARAMS_PAGE
78+
79+
/* Write the bootloader address in UICR. */
80+
.uicrMbrParamsPageAddress :
81+
{
82+
KEEP(*(.uicrMbrParamsPageAddress))
83+
} > UICR_MBR_PARAM_PAGE
84+
85+
.dbl_reset(NOLOAD) :
86+
{
87+
88+
} > DBL_RESET
89+
90+
/* No init RAM section in bootloader. Used for bond information exchange. */
91+
.noinit(NOLOAD) :
92+
{
93+
94+
} > NOINIT
95+
96+
/* other placements follow here... */
97+
}
98+
99+
INCLUDE "nrf_common.ld"

linker/nrf52840_debug.ld

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Linker script to configure memory regions. */
2+
3+
SEARCH_DIR(.)
4+
GROUP(-lgcc -lc -lnosys)
5+
6+
MEMORY
7+
{
8+
/** Flash start address for the bootloader. This setting will also be stored in UICR to allow the
9+
* MBR to init the bootloader when starting the system. This value must correspond to
10+
* BOOTLOADER_REGION_START found in dfu_types.h. The system is prevented from starting up if
11+
* those values do not match. The check is performed in main.c, see
12+
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
13+
*/
14+
/* due to lack of flash for debug, we will use reserved app to extend bootloader size */
15+
FLASH (rx) : ORIGIN = 0xF4000-28K, LENGTH = 0xFE000-0xF4000 - 2K + 28K /* 38 KB */
16+
17+
BOOTLOADER_CONFIG (r): ORIGIN = 0xFE000 - 2K, LENGTH = 2K
18+
19+
/** Location of mbr params page in flash. */
20+
MBR_PARAMS_PAGE (rw) : ORIGIN = 0xFE000, LENGTH = 0x1000
21+
22+
/** Location of bootloader setting in flash. */
23+
BOOTLOADER_SETTINGS (rw) : ORIGIN = 0xFF000, LENGTH = 0x1000
24+
25+
26+
27+
/** RAM Region for bootloader. */
28+
/* Avoid conflict with NOINIT for OTA bond sharing */
29+
RAM (rwx) : ORIGIN = 0x20008000, LENGTH = 0x20040000-0x20008000
30+
31+
/* Location for double reset detection, no init */
32+
DBL_RESET (rwx) : ORIGIN = 0x20007F7C, LENGTH = 0x04
33+
34+
/** Location of non initialized RAM. Non initialized RAM is used for exchanging bond information
35+
* from application to bootloader when using buttonless DFU OTA. */
36+
NOINIT (rwx) : ORIGIN = 0x20007F80, LENGTH = 0x80
37+
38+
39+
40+
/** Location in UICR where bootloader start address is stored. */
41+
UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04
42+
43+
/** Location in UICR where mbr params page address is stored. */
44+
UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04
45+
}
46+
47+
SECTIONS
48+
{
49+
.fs_data_out ALIGN(4):
50+
{
51+
PROVIDE( __start_fs_data = .);
52+
KEEP(*(fs_data))
53+
PROVIDE( __stop_fs_data = .);
54+
} = 0
55+
56+
.bootloaderConfig :
57+
{
58+
KEEP(*(.bootloaderConfig))
59+
} > BOOTLOADER_CONFIG
60+
61+
/* Place the bootloader settings page in flash. */
62+
.bootloaderSettings(NOLOAD) :
63+
{
64+
65+
} > BOOTLOADER_SETTINGS
66+
67+
/* Write the bootloader address in UICR. */
68+
.uicrBootStartAddress :
69+
{
70+
KEEP(*(.uicrBootStartAddress))
71+
} > UICR_BOOTLOADER
72+
73+
/* Place the mbr params page in flash. */
74+
.mbrParamsPage(NOLOAD) :
75+
{
76+
77+
} > MBR_PARAMS_PAGE
78+
79+
/* Write the bootloader address in UICR. */
80+
.uicrMbrParamsPageAddress :
81+
{
82+
KEEP(*(.uicrMbrParamsPageAddress))
83+
} > UICR_MBR_PARAM_PAGE
84+
85+
.dbl_reset(NOLOAD) :
86+
{
87+
88+
} > DBL_RESET
89+
90+
/* No init RAM section in bootloader. Used for bond information exchange. */
91+
.noinit(NOLOAD) :
92+
{
93+
94+
} > NOINIT
95+
96+
/* other placements follow here... */
97+
}
98+
99+
INCLUDE "nrf_common.ld"

linker/nrf52_debug.ld

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Linker script to configure memory regions. */
2+
3+
SEARCH_DIR(.)
4+
GROUP(-lgcc -lc -lnosys)
5+
6+
MEMORY
7+
{
8+
/** Flash start address for the bootloader. This setting will also be stored in UICR to allow the
9+
* MBR to init the bootloader when starting the system. This value must correspond to
10+
* BOOTLOADER_REGION_START found in dfu_types.h. The system is prevented from starting up if
11+
* those values do not match. The check is performed in main.c, see
12+
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
13+
*/
14+
FLASH (rx) : ORIGIN = 0x74000-28K, LENGTH = 0x7E000-0x74000+28K /* 40 KB */
15+
16+
/** Location of mbr params page in flash. */
17+
MBR_PARAMS_PAGE (rw) : ORIGIN = 0x7E000, LENGTH = 0x1000
18+
19+
/** Location of bootloader setting in flash. */
20+
BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x7F000, LENGTH = 0x1000
21+
22+
23+
24+
/** RAM Region for bootloader. */
25+
RAM (rwx) : ORIGIN = 0x20008000, LENGTH = 0x20010000-0x20008000
26+
27+
/* Location for double reset detection, no init */
28+
DBL_RESET (rwx) : ORIGIN = 0x20007F7C, LENGTH = 0x04
29+
30+
/** Location of non initialized RAM. Non initialized RAM is used for exchanging bond information
31+
* from application to bootloader when using buttonless DFU OTA. */
32+
NOINIT (rwx) : ORIGIN = 0x20007F80, LENGTH = 0x80
33+
34+
35+
36+
/** Location in UICR where bootloader start address is stored. */
37+
UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04
38+
39+
/** Location in UICR where mbr params page address is stored. */
40+
UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04
41+
}
42+
43+
SECTIONS
44+
{
45+
.fs_data_out ALIGN(4):
46+
{
47+
PROVIDE( __start_fs_data = .);
48+
KEEP(*(fs_data))
49+
PROVIDE( __stop_fs_data = .);
50+
} = 0
51+
52+
/* Place the bootloader settings page in flash. */
53+
.bootloaderSettings(NOLOAD) :
54+
{
55+
56+
} > BOOTLOADER_SETTINGS
57+
58+
/* Write the bootloader address in UICR. */
59+
.uicrBootStartAddress :
60+
{
61+
KEEP(*(.uicrBootStartAddress))
62+
} > UICR_BOOTLOADER
63+
64+
/* Place the mbr params page in flash. */
65+
.mbrParamsPage(NOLOAD) :
66+
{
67+
68+
} > MBR_PARAMS_PAGE
69+
70+
/* Write the bootloader address in UICR. */
71+
.uicrMbrParamsPageAddress :
72+
{
73+
KEEP(*(.uicrMbrParamsPageAddress))
74+
} > UICR_MBR_PARAM_PAGE
75+
76+
.dbl_reset(NOLOAD) :
77+
{
78+
79+
} > DBL_RESET
80+
81+
/* No init RAM section in bootloader. Used for bond information exchange. */
82+
.noinit(NOLOAD) :
83+
{
84+
85+
} > NOINIT
86+
/* other placements follow here... */
87+
}
88+
89+
INCLUDE "nrf_common.ld"

0 commit comments

Comments
 (0)