Skip to content

Commit 013458a

Browse files
committed
makefile to generate bootloader-nosd.uf2
everything seems working
1 parent d594cbc commit 013458a

File tree

7 files changed

+78
-72
lines changed

7 files changed

+78
-72
lines changed

Makefile

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ ifeq ($(DEBUG), 1)
210210

211211
CFLAGS += -ggdb -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
212212
IPATH += $(RTT_SRC)/RTT
213-
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT_printf.c
214213
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
215214
endif
216215

@@ -314,7 +313,58 @@ endif
314313
.PHONY: all clean flash dfu-flash sd gdbflash gdb
315314

316315
# default target to build
317-
all: $(BUILD)/$(OUT_FILE)-nosd.out $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).uf2
316+
all: $(BUILD)/$(OUT_FILE).out $(BUILD)/$(OUT_FILE)-nosd.hex $(BUILD)/$(OUT_FILE)-nosd.uf2 $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).zip
317+
318+
#------------------- Compile rules -------------------
319+
320+
# Create build directories
321+
$(BUILD):
322+
@$(MK) $@
323+
324+
clean:
325+
@$(RM) $(BUILD)
326+
327+
# Create objects from C SRC files
328+
$(BUILD)/%.o: %.c
329+
@echo CC $(notdir $<)
330+
@$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
331+
332+
# Assemble files
333+
$(BUILD)/%.o: %.S
334+
@echo AS $(notdir $<)
335+
@$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $<
336+
337+
# Link
338+
$(BUILD)/$(OUT_FILE).out: $(BUILD) $(OBJECTS)
339+
@echo LD $(notdir $@)
340+
@$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group
341+
@$(SIZE) $@
342+
343+
#------------------- Binary generator -------------------
344+
345+
# Create hex file (no sd, no mbr)
346+
$(BUILD)/$(OUT_FILE).hex: $(BUILD)/$(OUT_FILE).out
347+
@echo CR $(notdir $@)
348+
@$(OBJCOPY) -O ihex $< $@
349+
350+
# Hex file with mbr (still no SD)
351+
$(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE).hex
352+
@echo CR $(notdir $@)
353+
@python lib/intelhex/scripts/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX)
354+
355+
# Bootolader only uf2
356+
$(BUILD)/$(OUT_FILE)-nosd.uf2: $(BUILD)/$(OUT_FILE)-nosd.hex
357+
@echo CR $(notdir $@)
358+
python lib/uf2/utils/uf2conv.py -f 0x239A0029 -c -o $@ $^
359+
360+
# merge bootloader and sd hex together
361+
$(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_FILE).hex
362+
@echo CR $(notdir $@)
363+
@python lib/intelhex/scripts/hexmerge.py -o $@ $< $(SD_HEX)
364+
365+
# Create pkg zip file for bootloader+SD combo to use with DFU CDC
366+
$(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_FILE).hex
367+
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@
318368

319369
#------------------- Flash target -------------------
320370

@@ -342,7 +392,7 @@ erase:
342392
# flash SD only
343393
sd:
344394
@echo Flashing: $(SD_HEX)
345-
$(NRFJPROG) --program $(SD_HEX) -f nrf52 --sectorerase --reset
395+
$(NRFJPROG) --program $(SD_HEX) -f nrf52 --sectorerase --reset
346396

347397
# flash MBR only
348398
mbr:
@@ -353,53 +403,5 @@ gdbflash: $(BUILD)/$(MERGED_FILE).hex
353403
@echo Flashing: $<
354404
@$(GDB_BMP) -nx --batch -ex 'load $<' -ex 'compare-sections' -ex 'kill'
355405

356-
gdb: $(BUILD)/$(OUT_FILE)-nosd.out
406+
gdb: $(BUILD)/$(OUT_FILE).out
357407
$(GDB_BMP) $<
358-
359-
#------------------- Compile rules -------------------
360-
361-
# Create build directories
362-
$(BUILD):
363-
@$(MK) $@
364-
365-
clean:
366-
@$(RM) $(BUILD)
367-
368-
# Create objects from C SRC files
369-
$(BUILD)/%.o: %.c
370-
@echo CC $(notdir $<)
371-
@$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
372-
373-
# Assemble files
374-
$(BUILD)/%.o: %.S
375-
@echo AS $(notdir $<)
376-
@$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $<
377-
378-
# Link
379-
$(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS)
380-
@echo LD $(notdir $@)
381-
@$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group
382-
@$(SIZE) $@
383-
384-
#------------------- Binary generator -------------------
385-
386-
# Create hex file
387-
$(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.out
388-
@echo CR $(notdir $@)
389-
@$(OBJCOPY) -O ihex $< $@
390-
391-
# merge bootloader and sd hex together
392-
$(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_FILE)-nosd.hex
393-
@echo CR $(notdir $@)
394-
@mergehex -q -m $< $(SD_HEX) -o $@
395-
396-
$(BUILD)/$(MERGED_FILE).uf2: $(BUILD)/$(MERGED_FILE).hex
397-
@echo CR $(notdir $@)
398-
python lib/uf2/utils/uf2conv.py -f 0x239A0029 -c -o $@ $^
399-
400-
# Create pkg zip file for bootloader+SD combo to use with DFU Serial
401-
.PHONY: genpkg
402-
genpkg: $(BUILD)/$(MERGED_FILE).zip
403-
404-
$(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_FILE)-nosd.hex
405-
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@

README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,20 @@ This is a CDC/DFU/UF2 bootloader for nRF52 boards.
2020
- Particle Xenon
2121

2222
UF2 is an easy-to-use bootloader that appears as a flash drive. You can just copy `.uf2`-format
23-
application images to the flash drive to load new firmware.
24-
See https://github.com/Microsoft/uf2 and https://github.com/adafruit/uf2-samdx1
25-
for more information.
23+
application images to the flash drive to load new firmware. See https://github.com/Microsoft/uf2 and https://github.com/adafruit/uf2-samdx1 for more information.
2624

27-
[adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil),
28-
a modified version of [Nordic nrfutil](https://github.com/NordicSemiconductor/pc-nrfutil),
29-
is required to perform DFU.
30-
Install `python3` if it is not installed already and run this command to install adafruit-nrfutil from PyPi:
25+
[adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil), a modified version of [Nordic nrfutil](https://github.com/NordicSemiconductor/pc-nrfutil), is required to perform DFU. Install `python3` if it is not installed already and run this command to install adafruit-nrfutil from PyPi:
3126

3227
```
3328
$ pip3 install --user adafruit-nrfutil
3429
```
3530

36-
This repository depends on the following submodules:
37-
38-
- [tinyusb](https://github.com/hathach/tinyusb)
39-
- [nrfx](https://github.com/NordicSemiconductor/nrfx)
40-
41-
Note that `tinyusb` also includes `nrfx` as a submodule, so you need
42-
to initialize and update submodules with the `--recursive`` flag.
43-
4431
Clone this repo with following commands, or fork it for your own development
4532

4633
```
4734
git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader
4835
cd Adafruit_nRF52_Bootloader
49-
git submodule update --init --recursive
36+
git submodule update --init
5037
```
5138

5239
## Features
@@ -111,6 +98,7 @@ Prerequisites
11198

11299
- ARM GCC
113100
- Nordic's [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
101+
- [Python IntelHex](https://pypi.org/project/IntelHex/)
114102

115103
To build:
116104

lib/sdk11/components/libraries/bootloader_dfu/bootloader.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,14 @@ void bootloader_app_start(void)
358358

359359
if ( is_sd_existed() )
360360
{
361+
PRINTF("SoftDevice exist\r\n");
361362
// App starts after SoftDevice
362363
app_addr = SD_SIZE_GET(MBR_SIZE);
363364
fwd_ret = sd_softdevice_vector_table_base_set(app_addr);
364365
}else
365366
{
367+
PRINTF("SoftDevice not exist\r\n");
368+
366369
// App starts right after MBR
367370
app_addr = MBR_SIZE;
368371
sd_mbr_command_t command =
@@ -377,6 +380,8 @@ void bootloader_app_start(void)
377380
// unlikely failed to forward vector table, manually set forward address
378381
if ( fwd_ret != NRF_SUCCESS )
379382
{
383+
PRINT_HEX(fwd_ret);
384+
380385
// MBR use first 4-bytes of SRAM to store foward address
381386
*(uint32_t *)(0x20000000) = app_addr;
382387
}

lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ static void dfu_prepare_func_app_erase(uint32_t image_size)
150150

151151
for ( uint32_t i = 0; i < page_count; i++ )
152152
{
153-
nrfx_nvmc_page_erase(DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE);
153+
uint32_t const addr = DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE;
154+
PRINTF("Erase 0x%08lX\r\n", addr);
155+
nrfx_nvmc_page_erase(addr);
154156
}
155157

156158
// invoke complete callback

segger/Adafruit_nRF52_Bootloader.emProject

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@
332332
<file file_name="../src/boards/feather_nrf52840_express/board.h" />
333333
<file file_name="../src/boards/feather_nrf52840_express/pinconfig.c" />
334334
</folder>
335+
<file file_name="../src/boards/boards.c" />
336+
<file file_name="../src/boards/boards.h" />
335337
</folder>
336-
<file file_name="../src/boards.c" />
337-
<file file_name="../src/boards.h" />
338338
<folder
339339
Name="cmsis"
340340
exclude=""

src/flash_nrf5x.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ void flash_nrf5x_flush (bool need_erase)
4545
// - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems.
4646
//
4747
// Note: MSC uf2 does not erase page in advance like dfu serial
48-
if ( need_erase ) nrfx_nvmc_page_erase(_fl_addr);
48+
if ( need_erase )
49+
{
50+
PRINTF("Erase 0x%08lX\r\n", _fl_addr);
51+
nrfx_nvmc_page_erase(_fl_addr);
52+
}
4953

54+
PRINTF("Write 0x%08lX\r\n", _fl_addr);
5055
nrfx_nvmc_words_write(_fl_addr, (uint32_t *) _fl_buf, FLASH_PAGE_SIZE / 4);
5156
}
5257

src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ bool is_ota(void)
144144

145145
void softdev_mbr_init(void)
146146
{
147+
PRINTF("SD_MBR_COMMAND_INIT_SD\r\n");
147148
sd_mbr_command_t com = { .command = SD_MBR_COMMAND_INIT_SD };
148149
sd_mbr_command(&com);
149150
}
@@ -153,6 +154,8 @@ void softdev_mbr_init(void)
153154
//--------------------------------------------------------------------+
154155
int main(void)
155156
{
157+
PRINTF("Bootlaoder Start\r\n");
158+
156159
// Populate Boot Address and MBR Param into MBR if not already
157160
// MBR_BOOTLOADER_ADDR/MBR_PARAM_PAGE_ADDR are used if available, else UICR registers are used
158161
// Note: skip it for now since this will prevent us to change the size of bootloader in the future
@@ -271,6 +274,7 @@ int main(void)
271274

272275
if (bootloader_app_is_valid() && !bootloader_dfu_sd_in_progress())
273276
{
277+
PRINTF("App is valid\r\n");
274278
if ( is_sd_existed() )
275279
{
276280
// MBR forward IRQ to SD (if not already)

0 commit comments

Comments
 (0)