Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.__setattr__(key, value)
flash_args = FlashArgs({
'flash_size': self.app.flash_settings["flash_size"],
'flash_mode': self.app.flash_settings["flash_mode"],
'flash_freq': self.app.flash_settings["flash_freq"],
'addr_filename': flash_files,
'no_stub': False,
'compress': True,
'verify': False,
'encrypt': False,
'erase_all': False,
})
esp.change_baud(baud_rate)
esptool.detect_flash_size(esp, flash_args)
esptool.write_flash(esp, flash_args)
finally:
for (_, f) in flash_files:
f.close()
def write(self, offset, contents, compress=True, flash_size='detect', std_out=None, ui_label=None, file_name=None, updateList=True, progress_fs=None):
if progress_fs is not None:
self.__progress_fs = progress_fs
args = Args()
args.flash_size = self.__flash_size if flash_size == 'detect' else flash_size
args.flash_mode = FLASH_MODE
args.flash_freq = FLASH_FREQ
args.compress = compress
args.verify = False
args.no_stub = False
if args.flash_size == 'detect':
esptool.detect_flash_size(self.esp, args)
self.__flash_size = args.flash_size
self.set_baudrate(False)
fmap = cStringIO.StringIO(contents)
args.addr_filename = [[offset, fmap]]
if std_out is not None:
sys.stdout = std_out
first_exception = None
for x in range(0, 3):
try:
esptool.write_flash(self.esp, args, ui_label=ui_label, file_name=file_name, resultUpdateList=self.__resultUpdateList if updateList else None, partition=self.partition_name(offset), progress_fs=self.__progress_fs)
fmap.close()
return
except AttributeError as ae:
print_exc(ae)
raise RuntimeError('Content at offset 0x%x does not fit available flash size of %s' % (offset, args.flash_size))
def int_flash_size(self):
args = Args()
args.flash_size = self.__flash_size
args.flash_mode = FLASH_MODE
args.flash_freq = FLASH_FREQ
args.compress = True
args.verify = False
args.no_stub = False
if args.flash_size == 'detect':
esptool.detect_flash_size(self.esp, args)
self.__flash_size = args.flash_size
str_flash_size = args.flash_size
try:
int_flash_size = int(str_flash_size.replace('MB', '')) * 0x100000
except:
int_flash_size = (4 * 0x100000) if args.flash_size != '8MB' else (8 * 0x100000)
return int_flash_size
def flash_bin(self, dest_and_file_pairs, ui_label=None, file_name=None, progress_fs=None):
args = Args()
args.flash_size = self.__flash_size
args.flash_mode = FLASH_MODE
args.flash_freq = FLASH_FREQ
args.compress = True
args.verify = True
if args.flash_size == 'detect':
esptool.detect_flash_size(self.esp, args)
self.__flash_size = args.flash_size
dest_and_file = list(dest_and_file_pairs)
for i, el in enumerate(dest_and_file):
dest_and_file[i][1] = open(el[1], "rb")
args.addr_filename = dest_and_file
esptool.write_flash(self.esp, args, ui_label=ui_label, file_name=file_name, resultUpdateList=self.__resultUpdateList, progress_fs=progress_fs)
self.__setattr__(key, value)
flash_args = FlashArgs({
'flash_size': self.app.flash_settings["flash_size"],
'flash_mode': self.app.flash_settings["flash_mode"],
'flash_freq': self.app.flash_settings["flash_freq"],
'addr_filename': flash_files,
'no_stub': False,
'compress': True,
'verify': False,
'encrypt': self.app.flash_settings.get("encrypt", False),
'erase_all': False,
})
esp.change_baud(baud_rate)
esptool.detect_flash_size(esp, flash_args)
esptool.write_flash(esp, flash_args)
finally:
for (_, f) in flash_files:
f.close()
def detect_flash_size(self):
args = Args()
args.flash_size = 'detect'
args.flash_mode = FLASH_MODE
args.flash_freq = FLASH_FREQ
args.compress = True
args.verify = False
args.no_stub = False
esptool.detect_flash_size(self.esp, args)
return args.flash_size
self.write(offset, contents, ui_label=ui_label, file_name=file_name)
else:
if (len(contents) > size):
print_debug("Truncating this instruction by %s as it finishes outside specified partition size!" % hr_size(len(contents) - size), self.__debug)
contents = contents[:size]
args = Args()
args.flash_size = self.__flash_size
args.flash_mode = FLASH_MODE
args.flash_freq = FLASH_FREQ
args.compress = True
args.verify = False
args.no_stub = False
if args.flash_size == 'detect':
esptool.detect_flash_size(self.esp, args)
self.__flash_size = args.flash_size
finish_addr = offset + len(contents)
str_flash_size = args.flash_size
try:
int_flash_size = int(str_flash_size.replace('MB', '')) * 0x100000
except:
int_flash_size = (4 * 0x100000) if args.flash_size != '8MB' else (8 * 0x100000)
cb_start = int(PARTITIONS.get('config')[0], 16)
cb_len = int(PARTITIONS.get('config')[1], 16)
cb_end = cb_start + cb_len
if finish_addr > int_flash_size:
print_debug("Truncating this instruction by %s as it finishes outside available flash memory!" % ((hr_size(finish_addr - int_flash_size))), self.__debug)
contents = contents[:int_flash_size - offset]