Skip to content

Commit

Permalink
Fixes for esp32 flashing_script (#8358)
Browse files Browse the repository at this point in the history
* Draft changes to esp32 flash_script

* Fix board type

* Fix pigweed.

* Address review comments

Also adding a missed piece to the build-all-clusters-app.sh script.

* Update readme files.

* Remove warning on ESPPORT not set.

caveat emptor.

(cherry picked from commit 354fc86)
  • Loading branch information
cecille authored and mspang committed Jul 27, 2021
1 parent 5e05c11 commit c00bdec
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 151 deletions.
36 changes: 2 additions & 34 deletions examples/all-clusters-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)

set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
Expand All @@ -36,37 +37,4 @@ project(chip-all-clusters-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
flashing_script()
1 change: 0 additions & 1 deletion examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ commissioning and cluster control.

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
Expand Down
77 changes: 77 additions & 0 deletions examples/common/cmake/idf_flashing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2021 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Common cmake code for creating flash scripts.
# Must include the IDF project.cmake file before this file.
# Usage:
#
# flashing_script([DEPENDS <dep1> <dep2>])
#
# where DEPENDS and its args are optional and list additional dependencies.
# (use full path).

function(get_additional_flashing_depends)
set(options)
set(oneValueArgs)
set(multiValueArgs DEPENDS)
cmake_parse_arguments(MYARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(additional_flashing_depends "${MYARGS_DEPENDS}" PARENT_SCOPE)
endfunction(get_additional_flashing_depends)

macro(flashing_script)
idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

if (${IDF_TARGET} MATCHES "esp32*")
set(board_type "esp32")
else()
message(FATAL_ERROR "Unknown board type ${IDF_TARGET}")
endif()

set(flashing_utils_dir "${project_path}/third_party/connectedhomeip/scripts/flashing/")
set(board_firmware_utils "${board_type}_firmware_utils.py")
configure_file("${flashing_utils_dir}/${board_firmware_utils}" "${build_dir}/${board_firmware_utils}" COPYONLY)
configure_file("${flashing_utils_dir}/firmware_utils.py" "${build_dir}/firmware_utils.py" COPYONLY)

get_additional_flashing_depends(${ARGN})
foreach(dep IN LISTS additional_flashing_depends)
get_filename_component(filename ${dep} NAME)
configure_file("${dep}" "${build_dir}/${filename}" COPYONLY)
list(APPEND build_dir_depends "${build_dir}/${filename}")
endforeach(dep)

add_custom_target(flashing_script
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" ${board_type}
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud 460800
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
DEPENDS "${build_dir}/${board_firmware_utils}"
"${build_dir}/firmware_utils.py"
"${build_dir_deps}"
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)
endmacro(flashing_script)
36 changes: 2 additions & 34 deletions examples/persistent-storage/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)

set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
Expand All @@ -26,37 +27,4 @@ project(chip-persistent-storage)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
flashing_script()
1 change: 0 additions & 1 deletion examples/persistent-storage/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ make sure the IDF_PATH has been exported(See the manual setup steps above).

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
Expand Down
46 changes: 3 additions & 43 deletions examples/pigweed-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)


set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
Expand All @@ -27,47 +29,5 @@ project(chip-pigweed-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/echo_test.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/../mobly_tests/echo_test.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/echo_test_config.yml"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/echo_test_config.yml" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py" "${build_dir}/echo_test.py" "${build_dir}/echo_test_config.yml")
flashing_script(DEPENDS "${project_path}/echo_test_config.yml" "${project_path}/../mobly_tests/echo_test.py")
1 change: 0 additions & 1 deletion examples/pigweed-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ To download and install packages.

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
Expand Down
37 changes: 3 additions & 34 deletions examples/temperature-measurement-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if(NOT is_debug)
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)


set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
Expand All @@ -37,37 +39,4 @@ project(chip-temperature-measurement-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_path PROJECT_DIR)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(idf_path IDF_PATH)

add_custom_command(OUTPUT "${build_dir}/firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/esp32_firmware_utils.py"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${project_path}/third_party/connectedhomeip/scripts/flashing/esp32_firmware_utils.py" "${build_dir}/"
WORKING_DIRECTORY ${build_dir}
VERBATIM)

add_custom_command(OUTPUT "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${project_path}/../../../scripts/flashing/gen_flashing_script.py" esp32
--output "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py"
--port "$ENV{ESPPORT}"
--baud "$ENV{ESPBAUD}"
--before ${CONFIG_ESPTOOLPY_BEFORE}
--after ${CONFIG_ESPTOOLPY_AFTER}
--application "${CMAKE_PROJECT_NAME}.bin"
--bootloader "bootloader/bootloader.bin"
--partition "partition_table/partition-table.bin"
--use-partition-file "${build_dir}/partition_table/partition-table.bin"
--use-parttool ${idf_path}/components/partition_table/parttool.py
--use-sdkconfig ${project_path}/sdkconfig
WORKING_DIRECTORY ${build_dir}
COMMENT "To flash ${build_dir}/${CMAKE_PROJECT_NAME}.bin run ./build/${CMAKE_PROJECT_NAME}.flash.py"
VERBATIM)

add_custom_target(flashing_script DEPENDS "${build_dir}/${CMAKE_PROJECT_NAME}.bin" "${build_dir}/${CMAKE_PROJECT_NAME}.flash.py" "${build_dir}/esp32_firmware_utils.py" "${build_dir}/firmware_utils.py")
flashing_script()
1 change: 0 additions & 1 deletion examples/temperature-measurement-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ commissioning and cluster control.

```
$ export ESPPORT=/dev/tty.SLAB_USBtoUART
$ export ESPBAUD=${baud_value}
$ idf.py build
$ idf.py flashing_script
$ python ${app_name}.flash.py
Expand Down
11 changes: 10 additions & 1 deletion scripts/examples/build-all-clusters-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
self.run_cmd = os.path.join(self.chip_root, "scripts", "run_in_build_env.sh")
logging.info("Executing via: %s" % self.run_cmd)


def execute(self, command):
os.chdir(self.chip_root)
subprocess.call([self.run_cmd, 'source "%s/export.sh"; cd %s; idf.py %s' % (idf_path, ROOT, command)])
Expand All @@ -43,6 +43,11 @@ def main():
default=None,
choices=['m5stack', 'devkit'],
)
parser.add_argument(
'--generate-flash-script',
action='store_true',
)

args = parser.parse_args()

# Ensures somewhat pretty logging of what is going on
Expand All @@ -67,8 +72,12 @@ def main():


logging.info('Compiling')

e.execute('build')

logging.info('Generating flash script')
if args.generate_flash_script:
e.execute('flashing_script')

if __name__ == '__main__':
# execute only if run as a script
Expand Down
2 changes: 1 addition & 1 deletion scripts/flashing/esp32_firmware_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
},
'bootloader_offset': {
'help': 'Bootloader offset',
'default': None,
'default': '0x1000',
'argparse': {
'metavar': 'OFFSET'
},
Expand Down

0 comments on commit c00bdec

Please sign in to comment.