Skip to content

Commit 69ccc68

Browse files
committed
feat(zephyr): generate flash.bin in native_sim build
Generate flash.bin like we do with merged.hex Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 3097870 commit 69ccc68

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

zephyr/storage_partition.cmake

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,44 @@ add_custom_command(OUTPUT user_data.bin
1515
VERBATIM
1616
)
1717

18-
add_custom_command(OUTPUT user_data.hex
19-
COMMAND bin2hex.py
20-
--offset ${CONFIG_OCRE_STORAGE_PARTITION_ADDR}
21-
user_data.bin user_data.hex
22-
DEPENDS user_data.bin
23-
COMMENT "Generating user_data.hex"
24-
VERBATIM
25-
)
18+
if (CONFIG_OCRE_MERGE_HEX)
19+
add_custom_command(OUTPUT user_data.hex
20+
COMMAND bin2hex.py
21+
--offset ${CONFIG_OCRE_STORAGE_PARTITION_ADDR}
22+
user_data.bin user_data.hex
23+
DEPENDS user_data.bin
24+
VERBATIM
25+
)
2626

27-
add_custom_target(user_data_partition ALL
28-
DEPENDS user_data.hex
29-
COMMENT "Generating user data partition"
30-
VERBATIM
31-
)
27+
add_custom_target(user_data_partition ALL
28+
DEPENDS user_data.hex
29+
COMMENT "Generating user data partition (user_data.hex)"
30+
VERBATIM
31+
)
3232

33-
if (CONFIG_OCRE_MERGE_HEX)
3433
set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE "${CMAKE_CURRENT_BINARY_DIR}/user_data.hex")
3534
set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE "zephyr.hex")
3635
endif()
36+
37+
if (CONFIG_BOARD_NATIVE_SIM)
38+
# get the total flash size
39+
math(EXPR total_flash_size "${CONFIG_OCRE_STORAGE_PARTITION_ADDR} + ${CONFIG_OCRE_STORAGE_PARTITION_SIZE}")
40+
41+
# convert to decimal if necessary
42+
math(EXPR flash_offset "${CONFIG_OCRE_STORAGE_PARTITION_ADDR}")
43+
44+
# first we fill the total flash size with 0xff
45+
# then we rewrite the storage_partition
46+
add_custom_command(OUTPUT flash.bin
47+
COMMAND dd if=/dev/zero bs=${total_flash_size} count=1 | tr '\\0' '\\377' | dd of=${PROJECT_BINARY_DIR}/../flash.bin
48+
COMMAND dd if=user_data.bin of=${PROJECT_BINARY_DIR}/../flash.bin seek=1 bs=${flash_offset} conv=notrunc
49+
DEPENDS user_data.bin
50+
VERBATIM
51+
)
52+
53+
add_custom_target(user_data_partition_native ALL
54+
DEPENDS flash.bin
55+
COMMENT "Generating user data partition (flash.bin)"
56+
VERBATIM
57+
)
58+
endif()

0 commit comments

Comments
 (0)