def LoadFirmwareImage(chip, filename):
 with open(filename, 'rb') as f:
  if (chip == 'esp32'):
   return ESP32FirmwareImage(f)
  else:
   magic = ord(f.read(1))
   f.seek(0)
   if (magic == ESPLoader.ESP_IMAGE_MAGIC):
    return ESPFirmwareImage(f)
   elif (magic == ESPBOOTLOADER.IMAGE_V2_MAGIC):
    return OTAFirmwareImage(f)
   else:
    raise FatalError(('Invalid image magic number: %d' % magic))

def LoadFirmwareImage ( chip , filename ) : with open ( filename , 'rb' ) as f : if ( chip == 'esp32' ) : return ESP32FirmwareImage ( f ) else : magic = ord ( f . read ( 1 ) ) f . seek ( 0 ) if ( magic == ESPLoader . ESP_IMAGE_MAGIC ) : return ESPFirmwareImage ( f ) elif ( magic == ESPBOOTLOADER . IMAGE_V2_MAGIC ) : return OTAFirmwareImage ( f ) else : raise FatalError ( ( 'Invalid image magic number: %d' % magic ) )
load a firmware image .