From 0728f5d0e27ed1d1274f1c82b2bdc0ffd31d2aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Thu, 9 Jan 2025 09:32:11 +0100 Subject: [PATCH] scripts: west_commands: runners: esp32: add flash encryption option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an argument `--esp-encrypt` to flash an ESP32 series chip with encrypted flash. The content of the binary is encrypted on the fly by the chip. It is not required to know the encryption key. However, the fuses that disable encrypted flash download must be kept enabled for this to work. Signed-off-by: Martin Jäger --- scripts/west_commands/runners/esp32.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/west_commands/runners/esp32.py b/scripts/west_commands/runners/esp32.py index faaa2b047eb..619c16460e8 100644 --- a/scripts/west_commands/runners/esp32.py +++ b/scripts/west_commands/runners/esp32.py @@ -19,7 +19,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): app_address, erase=False, reset=False, baud=921600, flash_size='detect', flash_freq='40m', flash_mode='dio', espidf='espidf', bootloader_bin=None, partition_table_bin=None, - no_stub=False): + encrypt=False, no_stub=False): super().__init__(cfg) self.elf = cfg.elf_file self.app_bin = cfg.bin_file @@ -36,6 +36,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): self.espidf = espidf self.bootloader_bin = bootloader_bin self.partition_table_bin = partition_table_bin + self.encrypt = encrypt self.no_stub = no_stub @classmethod @@ -78,6 +79,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): help='Bootloader image to flash') parser.add_argument('--esp-flash-partition_table', help='Partition table to flash') + parser.add_argument('--esp-encrypt', default=False, action='store_true', + help='Encrypt firmware while flashing (correct efuses required)') parser.add_argument('--esp-no-stub', default=False, action='store_true', help='Disable launching the flasher stub, only talk to ROM bootloader') @@ -99,7 +102,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): flash_freq=args.esp_flash_freq, flash_mode=args.esp_flash_mode, espidf=espidf, bootloader_bin=args.esp_flash_bootloader, partition_table_bin=args.esp_flash_partition_table, - no_stub=args.esp_no_stub) + encrypt=args.esp_encrypt, no_stub=args.esp_no_stub) def do_run(self, command, **kwargs): self.require(self.espidf) @@ -124,6 +127,9 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): cmd_flash.extend(['--flash_freq', self.flash_freq]) cmd_flash.extend(['--flash_size', self.flash_size]) + if self.encrypt: + cmd_flash.extend(['--encrypt']) + if self.bootloader_bin: cmd_flash.extend([self.boot_address, self.bootloader_bin]) if self.partition_table_bin: