Skip to content

Commit

Permalink
Merge pull request #319 from adafruit/add-slash-screen
Browse files Browse the repository at this point in the history
Add slash screen
  • Loading branch information
ladyada authored Jan 5, 2024
2 parents 101a54d + 3d920bf commit 64d8e34
Show file tree
Hide file tree
Showing 14 changed files with 757 additions and 55 deletions.
52 changes: 44 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.17)
find_package(Python COMPONENTS Interpreter)

if (NOT DEFINED BOARD)
message(FATAL_ERROR "BOARD is not defined")
Expand Down Expand Up @@ -30,13 +31,14 @@ set(SDK ${CMAKE_CURRENT_LIST_DIR}/lib/sdk/components)
set(SOFTDEVICE ${CMAKE_CURRENT_LIST_DIR}/lib/softdevice)
set(TUSB ${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)

#-------------------
# Bootloader
#-------------------
set(CMAKE_EXECUTABLE_SUFFIX .elf)
add_executable(bootloader)
#set_target_properties(bootloader PROPERTIES OUTPUT_NAME "${BOARD}_bootloader.elf")


# SD_VERSION can be overwritten by board.cmake
if(NOT DEFINED SD_VERSION)
Expand All @@ -51,6 +53,8 @@ target_sources(bootloader PUBLIC
src/dfu_init.c
src/flash_nrf5x.c
src/main.c
src/screen.c
src/images.c
src/boards/boards.c
# nrfx
${NRFX}/drivers/src/nrfx_power.c
Expand Down Expand Up @@ -112,19 +116,37 @@ target_include_directories(bootloader PUBLIC
${SOFTDEVICE}/mbr/headers
)

# Debug option
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# TODO not work yet, also need to add segger rtt, DFU_APP_DATA_RESERVED=0, BOOTLOADER_REGION_START=0xED000
set(LD_FILE ${CMAKE_CURRENT_LIST_DIR}/linker/${MCU_VARIANT}_debug.ld)
message(FATAL_ERROR "Debug build not supported yet")

target_sources(bootloader PUBLIC
lib/SEGGER_RTT/RTT/SEGGER_RTT.c
)
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
DFU_APP_DATA_RESERVED=0
)

if (MCU_VARIANT STREQUAL "nrf52840")
target_compile_definitions(bootloader PUBLIC BOOTLOADER_REGION_START=0xEA000)
else ()
target_compile_definitions(bootloader PUBLIC BOOTLOADER_REGION_START=0x6D000)
endif ()
else ()
set(LD_FILE ${CMAKE_CURRENT_LIST_DIR}/linker/${MCU_VARIANT}.ld)
endif ()

target_link_options(bootloader PUBLIC
"LINKER:--script=${LD_FILE}"
-L${NRFX}/mdk
--specs=nosys.specs
--specs=nano.specs
--specs=nosys.specs --specs=nano.specs
)
target_compile_options(bootloader PUBLIC
-fno-builtin
Expand All @@ -149,7 +171,6 @@ target_compile_options(bootloader PUBLIC
)
target_compile_definitions(bootloader PUBLIC
SOFTDEVICE_PRESENT
DFU_APP_DATA_RESERVED=7*4096
)

if (TRACE_ETM STREQUAL "1")
Expand Down Expand Up @@ -195,6 +216,7 @@ endif ()
if (MCU_VARIANT STREQUAL "nrf52")
set(SD_NAME s132)
set(DFU_DEV_REV 0xADAF)
set(DFU_APP_DATA_RESERVED 7*4096)
target_compile_definitions(bootloader PUBLIC
NRF52
NRF52832_XXAA
Expand All @@ -207,6 +229,7 @@ if (MCU_VARIANT STREQUAL "nrf52")
elseif (MCU_VARIANT STREQUAL "nrf52833")
set(SD_NAME s140)
set(DFU_DEV_REV 52833)
set(DFU_APP_DATA_RESERVED 7*4096)
target_compile_definitions(bootloader PUBLIC
NRF52833_XXAA
S140
Expand All @@ -218,6 +241,8 @@ elseif (MCU_VARIANT STREQUAL "nrf52833")
elseif (MCU_VARIANT STREQUAL "nrf52840")
set(SD_NAME s140)
set(DFU_DEV_REV 52840)
# App reserved 40KB (8+32) to match circuitpython for 840
set(DFU_APP_DATA_RESERVED 10*4096)
target_compile_definitions(bootloader PUBLIC
NRF52840_XXAA
S140
Expand All @@ -233,6 +258,10 @@ endif ()
set(SD_FILENAME ${SD_NAME}_nrf52_${SD_VERSION})
set(SD_HEX ${SOFTDEVICE}/${SD_FILENAME}/${SD_FILENAME}_softdevice.hex)

if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(bootloader PUBLIC DFU_APP_DATA_RESERVED=${DFU_APP_DATA_RESERVED})
endif ()

#----------------------------------
# Get UF2 version from git
#----------------------------------
Expand All @@ -257,12 +286,12 @@ math(EXPR MK_BOOTLOADER_VERSION "(${RELEASE_VERSION_MAJOR} << 16) + (${RELEASE_V
cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS MK_BOOTLOADER_VERSION)

target_compile_definitions(bootloader PUBLIC
UF2_VERSION_BASE="${GIT_VERSION}"
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS}"
BLEDIS_FW_VERSION="${GIT_VERSION} ${SD_NAME} ${SD_VERSION}"
MK_BOOTLOADER_VERSION=${MK_BOOTLOADER_VERSION}
)


#----------------------------------
# Post build
#----------------------------------
Expand All @@ -276,6 +305,8 @@ add_custom_command(TARGET bootloader POST_BUILD
add_custom_command(TARGET bootloader POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:bootloader> $<TARGET_FILE_DIR:bootloader>/bootloader.bin
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:bootloader> $<TARGET_FILE_DIR:bootloader>/bootloader.hex
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/tools/hexmerge.py --overlap=replace -o $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.hex $<TARGET_FILE_DIR:bootloader>/bootloader.hex ${MBR_HEX}
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} -c -o $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.uf2 $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.hex
VERBATIM)

#----------------------------------
Expand All @@ -286,11 +317,16 @@ if (NOT DEFINED NRFJPROG)
set(NRFJPROG nrfjprog)
endif()

add_custom_target(flash
add_custom_target(flash-jlink
DEPENDS bootloader
COMMAND ${NRFJPROG} --program $<TARGET_FILE:bootloader> --verify --sectoranduicrerase -f nrf52 --reset
)

add_custom_target(flash-uf2
DEPENDS bootloader
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} --deploy $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.uf2
)

add_custom_target(flash-sd
COMMAND ${NRFJPROG} --program ${SD_HEX} --verify --sectorerase -f nrf52 --reset
)
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ else ifeq ($(MCU_SUB_VARIANT),nrf52840)
SD_NAME = s140
DFU_DEV_REV = 52840
CFLAGS += -DNRF52840_XXAA -DS140
# App reserved 40KB to match circuitpython for 840
# App reserved 40KB (8+32) to match circuitpython for 840
DFU_APP_DATA_RESERVED=10*4096
else
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
Expand All @@ -139,6 +139,8 @@ C_SRC += \
src/dfu_init.c \
src/flash_nrf5x.c \
src/main.c \
src/screen.c \
src/images.c \

# all files in boards
C_SRC += src/boards/boards.c
Expand Down Expand Up @@ -314,6 +316,7 @@ ifneq ($(USE_NFCT),yes)
endif

CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DUF2_VERSION_BASE='"$(GIT_VERSION)"'
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"'
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"'

Expand All @@ -328,9 +331,9 @@ ifeq ($(DEBUG), 1)
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
DFU_APP_DATA_RESERVED = 0

# expand bootloader address to 28KB of reserved app
# expand bootloader address to 28KB/40KB of reserved app
ifeq ($(MCU_SUB_VARIANT),nrf52840)
CFLAGS += -DBOOTLOADER_REGION_START=0xED000
CFLAGS += -DBOOTLOADER_REGION_START=0xEA000
else
CFLAGS += -DBOOTLOADER_REGION_START=0x6D000
endif
Expand Down
2 changes: 1 addition & 1 deletion linker/nrf52840_debug.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MEMORY
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
*/
/* due to lack of flash for debug, we will use reserved app to extend bootloader size */
FLASH (rx) : ORIGIN = 0xF4000-28K, LENGTH = 0xFE000-0xF4000 - 2K + 28K /* 38 KB */
FLASH (rx) : ORIGIN = 0xF4000 - 40K, LENGTH = 0xFE000-0xF4000 - 2K + 40K /* 38 KB */

BOOTLOADER_CONFIG (r): ORIGIN = 0xFE000 - 2K, LENGTH = 2K

Expand Down
Loading

0 comments on commit 64d8e34

Please sign in to comment.