runners: esp32.py: Support flashing for MCUboot and IDF bootloader

IDF bootloader requires partition table which is not a requirement for
MCUboot. Hence, esp32.py is updated to flash partition table only if it
exists.

Current implementation only allows flashing zephyr.bin. This commit adds
capability to flash binaries with other names as well
(e.g. - zephyr.signed.bin)

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
This commit is contained in:
Shubham Kulkarni 2021-08-30 17:21:40 +05:30 committed by Christopher Friedt
commit 5f11ac7c2a

View file

@ -18,7 +18,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
def __init__(self, cfg, device, boot_address, part_table_address,
app_address, baud=921600, flash_size='detect',
flash_freq='40m', flash_mode='dio', espidf='espidf',
bootloader_bin=None, partition_table_bin=None):
bootloader_bin=None, partition_table_bin=None, app_bin=None):
super().__init__(cfg)
self.elf = cfg.elf_file
self.device = device
@ -32,6 +32,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
self.espidf = espidf
self.bootloader_bin = bootloader_bin
self.partition_table_bin = partition_table_bin
self.app_bin = app_bin
@classmethod
def name(cls):
@ -71,6 +72,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-flash-app',
help='App to flash')
@classmethod
def do_create(cls, cfg, args):
@ -87,11 +90,15 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
flash_size=args.esp_flash_size, 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)
partition_table_bin=args.esp_flash_partition_table,
app_bin=args.esp_flash_app)
def do_run(self, command, **kwargs):
self.require(self.espidf)
bin_name = path.splitext(self.elf)[0] + path.extsep + 'bin'
if self.app_bin:
bin_name = self.app_bin
else:
bin_name = path.splitext(self.elf)[0] + path.extsep + 'bin'
cmd_flash = [self.espidf, '--chip', 'auto']
if self.device is not None:
@ -109,7 +116,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
if self.bootloader_bin:
cmd_flash.extend([self.boot_address, self.bootloader_bin])
cmd_flash.extend([self.part_table_address, self.partition_table_bin])
if self.partition_table_bin:
cmd_flash.extend([self.part_table_address, self.partition_table_bin])
cmd_flash.extend([self.app_address, bin_name])
else:
cmd_flash.extend([self.boot_address, bin_name])