diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 685898a..ab6af66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,7 @@ jobs: - name: Build id: make run: | - cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target=z03mmc.ota + cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target=z03mmc.zigbee echo "status=success" >> $GITHUB_OUTPUT - name: Build additional firmware with Heiman model @@ -51,5 +51,5 @@ jobs: # A file, directory or wildcard pattern that describes what to upload path: | ${{ env.ARTIFACT_DIR }}/*.bin - ${{ env.ARTIFACT_DIR }}/*.ota + ${{ env.ARTIFACT_DIR }}/*.zigbee diff --git a/README.md b/README.md index 53de19d..d131782 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,11 @@ it compatible with Zigbee networks. 3. Configure and build: ```sh cmake -DSDK_PREFIX=$(pwd)/../tl_zigbee_sdk -DTOOLCHAIN_PREFIX=$(pwd)/../tc32 -B build . - cmake --build build --target z03mmc.bin + cmake --build build --target z03mmc.zigbee ``` Firmware binary is located at `build/src/z03mmc.bin` + The binary with OTA header is at the same folder, ending with `z03mmc.zigbee` ## Flashing firmware with USB to UART diff --git a/cmake/TelinkSDK.cmake b/cmake/TelinkSDK.cmake index 9c57c51..fdae28b 100644 --- a/cmake/TelinkSDK.cmake +++ b/cmake/TelinkSDK.cmake @@ -45,9 +45,9 @@ FUNCTION(ADD_OTA_TARGET TARGET TOOLS_PATH) ELSE() SET(FILENAME "${TARGET}") ENDIF() - ADD_CUSTOM_TARGET("${TARGET}.ota" + ADD_CUSTOM_TARGET("${TARGET}.zigbee" DEPENDS ${TARGET}.bin - COMMAND python3 ${TOOLS_PATH}/make_ota.py ${FILENAME}.bin -o ${FILENAME}.ota + COMMAND python3 ${TOOLS_PATH}/make_ota.py ${FILENAME}.bin ) ENDFUNCTION() diff --git a/tools/make_ota.py b/tools/make_ota.py index 912795b..ec556cd 100644 --- a/tools/make_ota.py +++ b/tools/make_ota.py @@ -2,6 +2,7 @@ import argparse import binascii +import os import struct OTA_MAGIC = b'\x5d\x02' @@ -10,7 +11,7 @@ def main(args): assert args.input_file != args.output - with open(args.input_file, 'rb') as bin_file: + with (open(args.input_file, 'rb') as bin_file): bin_file.seek(0, 0) firmware = bytearray(bin_file.read(-1)) if firmware[6:8] != OTA_MAGIC: @@ -30,30 +31,49 @@ def main(args): header_size = 56 firmware_len = len(firmware) total_image_size = firmware_len + header_size + 6 + manufacturer_code = int.from_bytes(firmware[18:20], byteorder='little') + image_type = int.from_bytes(firmware[20:22], byteorder='little') + file_version = args.set_version or int.from_bytes(firmware[2:6], byteorder='little') ota_hdr = ota_hdr_s.pack( 0xbeef11e, 0x100, # header version is 0x0100 header_size, 0, # ota_ext_hdr_value if ota_ext_hdr else 0, - int.from_bytes(firmware[18:20], byteorder='little'), # args.manufacturer, - int.from_bytes(firmware[20:22], byteorder='little'), # args.image_type, - args.set_version or int.from_bytes(firmware[2:6], byteorder='little'), # 0x10023001 # options.File_Version + manufacturer_code, # args.manufacturer, + image_type, # args.image_type, + file_version, # options.File_Version args.ota_version, # options.stack_version, b'\x00' * 32, # OTA_Header_String.encode(), total_image_size, ) + # add chunk header: 0 - firmware type ota_hdr += struct.pack('