Skip to content

Commit

Permalink
build: uf2: Flexible UF2 offset selection.
Browse files Browse the repository at this point in the history
UF2 offset configurable to be either flash base reg + offset,
or simply the flash bare reg if the offset is configured
to be ignored.

Signed-off-by: Peter Johanson <peter@peterjohanson.com>
  • Loading branch information
petejohanson authored and carlescufi committed Feb 2, 2022
1 parent 3266e82 commit 3f33207
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1454,12 +1454,27 @@ if(CONFIG_BUILD_OUTPUT_BIN)
endif()

if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2)
if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_BASE)
set(flash_addr "${CONFIG_FLASH_BASE_ADDRESS}")
else()
set(flash_addr "${CONFIG_FLASH_LOAD_OFFSET}")
endif()

if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_OFFSET)
# Note, the `+ 0` in formula below avoids errors in cases where a Kconfig
# variable is undefined and thus expands to nothing.
math(EXPR flash_addr
"${flash_addr} + ${CONFIG_FLASH_LOAD_OFFSET} + 0"
OUTPUT_FORMAT HEXADECIMAL
)
endif()

list(APPEND
post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/uf2conv.py
-c
-f ${CONFIG_BUILD_OUTPUT_UF2_FAMILY_ID}
-b ${CONFIG_FLASH_LOAD_OFFSET}
-b ${flash_addr}
-o ${KERNEL_UF2_NAME}
${KERNEL_BIN_NAME}
)
Expand Down
8 changes: 8 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ config BUILD_OUTPUT_UF2_FAMILY_ID
name string. If the SoC in use is known by UF2, the Family ID will
be pre-filled with the known value.

config BUILD_OUTPUT_UF2_USE_FLASH_BASE
bool
default n

config BUILD_OUTPUT_UF2_USE_FLASH_OFFSET
bool
default n

endif # BUILD_OUTPUT_UF2

config BUILD_OUTPUT_STRIPPED
Expand Down

0 comments on commit 3f33207

Please sign in to comment.