From e3b778d4da5aa43cd4c74a3785a966b344275717 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Sat, 5 Mar 2022 16:02:23 +0200 Subject: [PATCH] Generate partitions path based on ESP32 model To be able to support the ESP32-C3, a different partitioning scheme is needed. Add a helper function to generate the URL to download the binary partition table from, and use it when the user did not pass the partitions argument. Signed-off-by: Stijn Tintel --- esphomeflasher/common.py | 13 ++++++++++++- esphomeflasher/const.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/esphomeflasher/common.py b/esphomeflasher/common.py index 5078a30..6f4e284 100644 --- a/esphomeflasher/common.py +++ b/esphomeflasher/common.py @@ -3,7 +3,10 @@ import struct import esptool -from esphomeflasher.const import HTTP_REGEX +from esphomeflasher.const import ( + ESP32_DEFAULT_PARTITIONS, + HTTP_REGEX, +) from esphomeflasher.helpers import prevent_print @@ -186,6 +189,10 @@ def format_bootloader_path(path, model, flash_mode, flash_freq): return path.replace("$MODEL$", model).replace("$FLASH_MODE$", flash_mode).replace("$FLASH_FREQ$", flash_freq) +def format_partitions_path(path, model): + return path.replace("$MODEL$", model) + + def configure_write_flash_args( info, firmware_path, flash_size, bootloader_path, partitions_path, otadata_path ): @@ -206,6 +213,10 @@ def configure_write_flash_args( bootloader = open_downloadable_binary( format_bootloader_path(bootloader_path, model, flash_mode, flash_freq) ) + + if not partitions_path: + partitions_path = format_partitions_path(ESP32_DEFAULT_PARTITIONS, model) + partitions = open_downloadable_binary(partitions_path) otadata = open_downloadable_binary(otadata_path) diff --git a/esphomeflasher/const.py b/esphomeflasher/const.py index 7950e05..2656fab 100644 --- a/esphomeflasher/const.py +++ b/esphomeflasher/const.py @@ -8,7 +8,7 @@ ESP32_DEFAULT_BOOTLOADER_FORMAT = ( "2.0.2/tools/sdk/$MODEL$/bin/bootloader_$FLASH_MODE$_$FLASH_FREQ$.bin" ) ESP32_DEFAULT_PARTITIONS = ( - "https://raw.githubusercontent.com/esphome/esphomeflasher/main/partitions.esp32.bin" + "https://raw.githubusercontent.com/esphome/esphomeflasher/main/partitions.$MODEL$.bin" ) # https://stackoverflow.com/a/3809435/8924614