From 580cfeaaaec17649f54fd5b77b7dcf3f87caf76e Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 24 May 2018 16:05:31 +1000 Subject: [PATCH] idf.py: Print flashing steps at the end of each build --- components/esptool_py/CMakeLists.txt | 2 +- components/esptool_py/flash_app_args.in | 3 - .../esptool_py/flash_partition_table_args.in | 3 - components/esptool_py/flasher_args.json.in | 8 ++- docs/en/get-started/index.rst | 23 ++++++++ tools/idf.py | 57 +++++++++++++++++-- 6 files changed, 84 insertions(+), 12 deletions(-) diff --git a/components/esptool_py/CMakeLists.txt b/components/esptool_py/CMakeLists.txt index 0d62557c8..690763934 100644 --- a/components/esptool_py/CMakeLists.txt +++ b/components/esptool_py/CMakeLists.txt @@ -1,7 +1,7 @@ register_config_only_component() # Generate pre-canned flasher args files suitable for passing to esptool.py -foreach(part project app bootloader) +foreach(part project app bootloader partition_table) configure_file( "${CMAKE_CURRENT_LIST_DIR}/flash_${part}_args.in" "${CMAKE_BINARY_DIR}/flash_${part}_args" diff --git a/components/esptool_py/flash_app_args.in b/components/esptool_py/flash_app_args.in index 7cc24a638..1e2fa31c2 100644 --- a/components/esptool_py/flash_app_args.in +++ b/components/esptool_py/flash_app_args.in @@ -1,4 +1 @@ ---flash_mode ${ESPFLASHMODE} ---flash_size ${ESPFLASHSIZE} ---flash_freq ${ESPFLASHFREQ} ${CONFIG_APP_OFFSET} ${PROJECT_NAME}.bin diff --git a/components/esptool_py/flash_partition_table_args.in b/components/esptool_py/flash_partition_table_args.in index f5bbe084c..0983e11c4 100644 --- a/components/esptool_py/flash_partition_table_args.in +++ b/components/esptool_py/flash_partition_table_args.in @@ -1,4 +1 @@ ---flash_mode ${ESPFLASHMODE} ---flash_size ${ESPFLASHSIZE} ---flash_freq ${ESPFLASHFREQ} 0x8000 partition_table/partition-table.bin diff --git a/components/esptool_py/flasher_args.json.in b/components/esptool_py/flasher_args.json.in index 0266316ea..55e3a93a5 100644 --- a/components/esptool_py/flasher_args.json.in +++ b/components/esptool_py/flasher_args.json.in @@ -7,5 +7,11 @@ "0x8000" : "partition_table/partition-table.bin", "${CONFIG_APP_OFFSET}" : "${PROJECT_NAME}.bin", "${PHY_PARTITION_OFFSET}" : "${PHY_PARTITION_BIN_FILE}" - } + }, + "bootloader" : { "offset" : "0x1000", + "file" : "bootloader/bootloader.bin" }, + "app" : { "offset" : "${CONFIG_APP_OFFSET}", + "file" : "${PROJECT_NAME}.bin" }, + "partition_table" : { "offset" : "0x8000", + "file" : "partition_table/partition-table.bin" } } diff --git a/docs/en/get-started/index.rst b/docs/en/get-started/index.rst index 79ada7188..8542bd37a 100644 --- a/docs/en/get-started/index.rst +++ b/docs/en/get-started/index.rst @@ -258,6 +258,29 @@ Now you can build the project. Run:: This command will compile the application and all the ESP-IDF components, generate bootloader, partition table, and application binaries. +.. highlight: none + +:: + $ idf.py build + Running cmake in directory /path/to/hello_world/build + Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"... + Warn about uninitialized values. + -- Found Git: /usr/bin/git (found version "2.17.0") + -- Building empty aws_iot component due to configuration + -- Component names: ... + -- Component paths: ... + + ... (more lines of build system output) + + [527/527] Generating hello-world.bin + esptool.py v2.3.1 + + Project build complete. To flash, run this command: + ../../../components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x10000 build/hello-world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin + or run 'idf.py flash' + +If there are no errors, the build will finish by generating the firmware binary .bin file. + Flash To A Device ================= diff --git a/tools/idf.py b/tools/idf.py index bd7b9fe23..8b2c058fb 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -309,6 +309,54 @@ def fullclean(action, args): else: os.remove(f) +def print_closing_message(args): + # print a closing message of some kind + # + + if "flash" in str(args.actions): + print("Done") + return + + # Otherwise, if we built any binaries print a message about + # how to flash them + def print_flashing_message(title, key): + print("\n%s build complete. To flash, run this command:" % title) + + with open(os.path.join(args.build_dir, "flasher_args.json")) as f: + flasher_args = json.load(f) + + def flasher_path(f): + return os.path.relpath(os.path.join(args.build_dir, f)) + + if key != "project": + cmd = "" + if key == "bootloader": + cmd = " ".join(flasher_args["write_flash_args"]) + " " + + cmd += flasher_args[key]["offset"] + " " + cmd += flasher_path(flasher_args[key]["file"]) + else: + cmd = " ".join(flasher_args["write_flash_args"]) + " " + for o,f in flasher_args["flash_files"].items(): + cmd += o + " " + flasher_path(f) + " " + + print("%s -p %s -b %s write_flash %s" % ( + os.path.relpath("%s/components/esptool_py/esptool/esptool.py" % os.environ["IDF_PATH"]), + args.port or "(PORT)", + args.baud, + cmd.strip())) + print("or run 'idf.py %s'" % (key + "-flash" if key != "project" else "flash",)) + + if "all" in args.actions or "build" in args.actions: + print_flashing_message("Project", "project") + else: + if "app" in args.actions: + print_flashing_message("App", "app") + if "partition_table" in args.actions: + print_flashing_message("Partition Table", "partition_table") + if "bootloader" in args.actions: + print_flashing_message("Bootloader", "bootloader") + ACTIONS = { # action name : ( function (or alias), dependencies, order-only dependencies ) "all" : ( build_target, [], [ "reconfigure", "menuconfig", "clean", "fullclean" ] ), @@ -343,7 +391,6 @@ def get_commandline_options(): result.append(a) return result - def main(): if sys.version_info[0] != 2 or sys.version_info[1] != 7: raise FatalError("ESP-IDF currently only supports Python 2.7, and this is Python %d.%d.%d. Search for 'Setting the Python Interpreter' in the ESP-IDF docs for some tips to handle this." % sys.version_info[:3]) @@ -394,10 +441,12 @@ def main(): completed_actions.add(action) - while len(args.actions) > 0: - execute_action(args.actions[0], args.actions[1:]) - args.actions.pop(0) + actions = list(args.actions) + while len(actions) > 0: + execute_action(actions[0], actions[1:]) + actions.pop(0) + print_closing_message(args) if __name__ == "__main__": try: