From 73020f3567b7ef7ed3bdbb6383d7b1cadeeb72d3 Mon Sep 17 00:00:00 2001 From: Andreas Kurz Date: Fri, 9 May 2025 08:15:14 +0000 Subject: [PATCH 1/3] fix: add size optimization This flag is also present in the Makefile and optimises the resulting binary for the size of the binary. Without that flag the flash consumption would be too high to fit inside the allocated space. Signed-off-by: Andreas Kurz --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 567a815..d621647 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,7 @@ target_compile_options(bootloader PUBLIC -Wmissing-format-attribute -Wno-endif-labels -Wunreachable-code + -Os # Suppress warning caused by SDK -Wno-unused-parameter -Wno-expansion-to-defined -Wno-array-bounds ) @@ -333,4 +334,4 @@ add_custom_target(flash-mbr add_custom_target(flash-erase COMMAND ${NRFJPROG} -f nrf52 --eraseall - ) \ No newline at end of file + ) From ddcb2dba8c7090ced18a7a8b005ee79f168ae8e3 Mon Sep 17 00:00:00 2001 From: Andreas Kurz Date: Fri, 9 May 2025 10:31:05 +0200 Subject: [PATCH 2/3] chore: add documentation for CMake In this repository CMake and Make co-exists. Unfortunately there was no documentation on how to properly use CMake so this is a starting point. Signed-off-by: Andreas Kurz --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b4e3cdb..2929ae2 100644 --- a/README.md +++ b/README.md @@ -114,14 +114,20 @@ You must have have a J-Link available to "unbrick" your device. ### Build: -Firstly clone this repo with following commands +Firstly clone this repo including its submodules with following command: +``` +git clone --recurse-submodules -j8 https://github.com/adafruit/Adafruit_nRF52_Bootloader +``` + +For git versions before `2.13.0` you have to do that manually: ``` git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader cd Adafruit_nRF52_Bootloader git submodule update --init ``` +#### Build using `make` Then build it with `make BOARD={board} all`, for example: ``` @@ -137,6 +143,21 @@ Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056 Makefile:90: *** BOARD not defined. Stop ``` +#### Build using `cmake` + +Firstly initialize your build environment by passing your board to `cmake` via `-DBOARD={board}`: +``` +cmake -DBOARD=feather_nrf52840_express -S . -B _build -GNinja +``` + +And then build it with: +``` +cd _build +ninja +``` + +You can also use the generator of your choice. For example omit the `-GNinja` and then you can invoke `make` from inside `_build` instead of `ninja` + ### Flash To flash the bootloader (without softdevice/mbr) using JLink: From 70da7d88f4cdfd3eab65c4e8b3a6681b41393418 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Jun 2025 10:45:38 +0700 Subject: [PATCH 3/3] set CMAKE_BUILD_TYPE to MinSizeRel if not defined instead of forcing -Os add CONFIG_GPIO_AS_PINRESET --- CMakeLists.txt | 14 ++++++++++++-- README.md | 30 +++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d621647..36d85f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,10 @@ set(TINYUSB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb/src) set(UF2CONV_PY ${CMAKE_CURRENT_LIST_DIR}/lib/uf2/utils/uf2conv.py) set(UF2_FAMILY_ID_BOOTLOADER 0xd663823c) +if (NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") + set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Build type" FORCE) +endif () + #------------------- # Bootloader #------------------- @@ -131,7 +135,6 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") target_include_directories(bootloader PUBLIC lib/SEGGER_RTT/RTT ) - target_compile_definitions(bootloader PUBLIC CFG_DEBUG SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL @@ -170,12 +173,12 @@ target_compile_options(bootloader PUBLIC -Wmissing-format-attribute -Wno-endif-labels -Wunreachable-code - -Os # Suppress warning caused by SDK -Wno-unused-parameter -Wno-expansion-to-defined -Wno-array-bounds ) target_compile_definitions(bootloader PUBLIC SOFTDEVICE_PRESENT + CONFIG_GPIO_AS_PINRESET ) if (TRACE_ETM STREQUAL "1") @@ -335,3 +338,10 @@ add_custom_target(flash-mbr add_custom_target(flash-erase COMMAND ${NRFJPROG} -f nrf52 --eraseall ) + +# flash skip crc magic ( app valid = 0x0001, crc = 0x0000 ) +#add_custom_target(flash-skip-crc +# #COMMAND ${NRFJPROG} --memwr $(BOOT_SETTING_ADDR) --val 0x00000001 -f nrf52 +# COMMAND ${NRFJPROG} --memwr 0xFF000 --val 0x00000001 -f nrf52 +# #COMMAND ${NRFJPROG} --memwr 0x7F000 --val 0x00000001 -f nrf52 +# ) diff --git a/README.md b/README.md index 2929ae2..4c7066f 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ You must have have a J-Link available to "unbrick" your device. Firstly clone this repo including its submodules with following command: ``` -git clone --recurse-submodules -j8 https://github.com/adafruit/Adafruit_nRF52_Bootloader +git clone --recurse-submodules https://github.com/adafruit/Adafruit_nRF52_Bootloader ``` For git versions before `2.13.0` you have to do that manually: @@ -146,17 +146,33 @@ Makefile:90: *** BOARD not defined. Stop #### Build using `cmake` Firstly initialize your build environment by passing your board to `cmake` via `-DBOARD={board}`: -``` -cmake -DBOARD=feather_nrf52840_express -S . -B _build -GNinja + +```bash +mkdir build +cd build +cmake .. -DBOARD=feather_nrf52840_express ``` And then build it with: -``` -cd _build -ninja + +```bash +make ``` -You can also use the generator of your choice. For example omit the `-GNinja` and then you can invoke `make` from inside `_build` instead of `ninja` +You can also use the generator of your choice. For example adding the `-GNinja` and then you can invoke `ninja build` instead of `make`. + +To list all supported targets, run: + +```bash +cmake --build . --target help +``` + +To build individual targets, you can specify it directly with `make` or using `cmake --build`: + +```bash +make bootloader +cmake --build . --target bootloader +``` ### Flash