Skip to content

Commit 334c170

Browse files
s07641069austina-csa
authored andcommitted
[Telink] Add merge_n22 post build step (project-chip#34815)
1 parent 9e2af25 commit 334c170

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

config/telink/chip-module/CMakeLists.txt

+48-27
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ if (CONFIG_CHIP_ROTATING_DEVICE_ID)
125125
matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE)
126126
endif()
127127

128-
if(CONFIG_WIFI_W91)
128+
if (CONFIG_WIFI_W91)
129129
matter_add_gn_arg_string("chip_mdns" "minimal")
130130
elseif (CONFIG_NET_L2_OPENTHREAD)
131131
matter_add_gn_arg_string("chip_mdns" "platform")
@@ -160,12 +160,11 @@ include(${TELINK_COMMON}/common.cmake)
160160

161161
set(BLOCK_SIZE "1024")
162162

163-
# get code-partition mcuboot_partition size
164-
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
165-
dt_reg_size(mcuboot_size PATH ${dts_partition_path})
166-
math(EXPR boot_blocks "${mcuboot_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL)
167-
168163
if (CONFIG_BOOTLOADER_MCUBOOT)
164+
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
165+
dt_reg_size(mcuboot_size PATH ${dts_partition_path})
166+
math(EXPR boot_blocks "${mcuboot_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL)
167+
169168
add_custom_target(build_mcuboot ALL
170169
COMMAND
171170
west build -b ${BASE_BOARD} -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr
@@ -183,31 +182,30 @@ if (CONFIG_BOOTLOADER_MCUBOOT)
183182

184183
add_dependencies(merge_mcuboot ${ZEPHYR_FINAL_EXECUTABLE})
185184

186-
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
187-
chip_ota_image(chip-ota-image
188-
INPUT_FILES ${PROJECT_BINARY_DIR}/zephyr.signed.bin
189-
OUTPUT_FILE ${PROJECT_BINARY_DIR}/zephyr-ota.bin
190-
)
185+
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
186+
chip_ota_image(chip-ota-image
187+
INPUT_FILES ${PROJECT_BINARY_DIR}/zephyr.signed.bin
188+
OUTPUT_FILE ${PROJECT_BINARY_DIR}/zephyr-ota.bin
189+
)
191190

192-
add_dependencies(chip-ota-image ${ZEPHYR_FINAL_EXECUTABLE})
193-
endif()
191+
add_dependencies(chip-ota-image ${ZEPHYR_FINAL_EXECUTABLE})
192+
endif()
194193
endif()
195194

196-
# get code-partition factory_partition address
197-
dt_nodelabel(dts_partition_path NODELABEL "factory_partition")
198-
dt_reg_addr(factory_size PATH ${dts_partition_path})
199-
math(EXPR factory_blocks "${factory_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL)
200-
201195
if (CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE)
202-
add_custom_target(merge_factory_data ALL
203-
COMMAND
204-
dd if=${PROJECT_BINARY_DIR}/factory/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=${BLOCK_SIZE} seek=${factory_blocks}
205-
)
206-
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
207-
add_dependencies(merge_factory_data merge_mcuboot)
208-
else()
209-
add_dependencies(merge_factory_data ${ZEPHYR_FINAL_EXECUTABLE})
210-
endif()
196+
dt_nodelabel(dts_partition_path NODELABEL "factory_partition")
197+
dt_reg_addr(factory_size PATH ${dts_partition_path})
198+
math(EXPR factory_blocks "${factory_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL)
199+
200+
add_custom_target(merge_factory_data ALL
201+
COMMAND
202+
dd if=${PROJECT_BINARY_DIR}/factory/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=${BLOCK_SIZE} seek=${factory_blocks}
203+
)
204+
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
205+
add_dependencies(merge_factory_data merge_mcuboot)
206+
else()
207+
add_dependencies(merge_factory_data ${ZEPHYR_FINAL_EXECUTABLE})
208+
endif()
211209
endif()
212210

213211
# ==============================================================================
@@ -218,4 +216,27 @@ if (CONFIG_CHIP_FACTORY_DATA_BUILD)
218216
telink_generate_factory_data()
219217
endif()
220218

219+
if (CONFIG_SOC_SERIES_RISCV_TELINK_W91 AND CONFIG_TELINK_W91_FETCH_N22_BIN)
220+
dt_nodelabel(flash_path NODELABEL "flash")
221+
dt_reg_size(flash_size PATH ${flash_path})
222+
math(EXPR flash_blocks "${flash_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL)
223+
224+
add_custom_target(merge_n22 ALL
225+
COMMAND
226+
[ -f ${PROJECT_BINARY_DIR}/n22.bin ] && (
227+
dd if=/dev/zero bs=${BLOCK_SIZE} count=${flash_blocks} | tr '\\000' '\\377' > ${PROJECT_BINARY_DIR}/merged.bin &&
228+
dd if=${PROJECT_BINARY_DIR}/zephyr.bin of=${PROJECT_BINARY_DIR}/merged.bin conv=notrunc &&
229+
dd if=${PROJECT_BINARY_DIR}/n22.bin of=${PROJECT_BINARY_DIR}/merged.bin bs=${BLOCK_SIZE} seek=${flash_blocks} conv=notrunc
230+
) || true
231+
)
232+
233+
if (CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE)
234+
add_dependencies(merge_n22 merge_factory_data)
235+
elseif (CONFIG_CHIP_OTA_IMAGE_BUILD)
236+
add_dependencies(merge_n22 merge_mcuboot)
237+
else()
238+
add_dependencies(merge_n22 ${ZEPHYR_FINAL_EXECUTABLE})
239+
endif()
240+
endif()
241+
221242
endif() # CONFIG_CHIP

0 commit comments

Comments
 (0)