
    ;)di=                     `   g d Z dZddlZddlZddlZddlZddlZddlZddl	Z
ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3 dd	l4m5Z5m6Z6m7Z7m8Z8 dd
l9m:Z:m;Z;m<Z< ddl=Z=ddl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZL dej        _M        dej        _N        dddgddddgdgdg ddgdej        _O        ddg dddg ddgiej        _P        d ZQ	 dd eRd!eRd"eRd#e
jS        fd$ZTd%e,d&eUd'eUd#dfd(ZV ejW        e@d eXd)d*gd+,          d-e d./           ejY        d0d1 eCd2ge2z             ejZ        [                    d3d2          d45           ejY        d6d7 ej\                    ejZ        [                    d8d          d95           ejY        d:d; eD            ejZ        [                    d<e,j]                  d=5           ejY        d>de^eEd?@           ejY        dA eGg dB          ejZ        [                    dCdD          dE5           ejY        dFdG eGg dH          ejZ        [                    dIdJ          dK5           ejY        dLddMN           ejY        dOejZ        [                    dPdQ           ej_        dQdRg          dS           ejY        dTdUddVN           ejY        dWdXddYN           ejY        dZd[dd\N           ejY        d] ej_        e3j`                  d^_           ejY        d`eUejZ        [                    dae)          dbe) dc5          eja        dd                                                                                                                                                                                     Zbde Zcebd                    df           eje        dg eI            h          eja        dgefegeUdz  e
jh        ei         f                  fdi                                    Zjebd                    dj           eje        d& eD            h           eje        d' e?dk          h           eje        dl ej\                    h          eja        dm                                                             Zkebd                    dn           eje        d& eD            h          eja        do                                     Zlebd                    dp           eje        d& eD            h           eje        dq eD            h           eje        dr eD            dst          eja        du                                                             Zmebd                    dvw           eje        dxdydeAz           ejY        d{d|dd}N           ejY        d~d7ddN           ejY        dddN           ejY        d eJ            eEd           ejY        dddN           ejY        dddN           ejY        dddddgeF           ejY        ddddddgeF           eTdd          eQeja        d                                                                                                                                                             Znebd                    d          eja        d                         Zoebd                    d           eje        dg eI            h          eja        dgefegeUdz  e
jh        ei         f                  fd                                    Zpebd                    d           eje        dg ej\        d          h           ejY        dde^d_           ejY        dd| ej_        g d          dQd5           ejY        dd ejq        dd          dd           ejY        d ejq        dd          dd5           ejY        d ejq        dd          dd5           ejY        dddN           ejY        dddN           ejY        d eD            dd5           ejY        dddd           ejY        dddN           ejY        d ej_        g d          d_           ejY        de^dd5           ejY        dddN           eTdd          eja        d                                                                                                                                                                                                             Zrebd                    d          eja        d                         Zsebd                    d          eja        d                         Ztebd                    d          eQeja        d                                     Zuebd                    dæ           ejY        d ej_        g d          dRdŬ5          eQeja        dƄ                                                 Zvebd                    dǦ           ejY        dddɬN           ejY        d ej_        g d          dRdʬ5           eje        dq eD            h          eQeja        d˄                                                                         Zwebd                    d̦           eje        d& eD            h           eje        d' e?            h           eje        dl ej\                    h           ejY        d~d7ddN           eTdddͦ          eQeja        d΄                                                                                                 Zxebd                    dϦ           eje        dxdydeAz           ejY        ddddҬN           eTdd          eQeja        dӄ                                                                         Zyebd                    dԦ           ejY        dddլN          eQeja        dք                                                 Zzebd                    dצ           ejY        dddجN           eje        d& eD            h           eje        d' e?            h          eQeja        dل                                                                         Z{ebd                    dڦ           eje        d& eD            h           eje        d eD            h           eTdd          eQeja        d܄                                                                         Z|ebd                    dݦ           eje        dxdydeAz           ejY        dde^ddެߦ           ejY        dd ej_        g d          dd5           ejY        d eB            d_           ejY        dddN           ejY        ddU eD            dd5           ejY        d ej_        g d          d_           eTdd          eja        d                                                                                                                         Z}ebd                    d          eja        d                         Z~ebd                    d          d             Zddefe^         dz  d%e,dz  fdZg g g g fdefe^         defe^         defe^         defe^         d#efe^         f
dZdefe^         d#efe^         fdZ	 	 dde^deUde^deUdeRde^fdZ	 	 	 ddefe^         de^deUdeUde^deRde^fd Zd Zedk    r e             dS dS (  )chip_iddetect_chipdump_mem	elf2imageerase_flasherase_regionflash_idattach_flashget_security_info
image_infoload_ram	merge_bin
read_flashread_flash_statusread_flash_sfdpread_macread_mem
reset_chiprunrun_stubverify_flashversionwrite_flashwrite_flash_status	write_memz5.1.0    N)r   r   detect_flash_sizer   r   r   r   r	   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )load_config_file)DEFAULT_CONNECT_ATTEMPTSDEFAULT_OPEN_PORT_ATTEMPTSStubFlasher	ESPLoader
list_ports)log)	CHIP_DEFS	CHIP_LISTESP32ROM)
FatalErrorNotImplementedInROMErrorcheck_deprecated_py_suffixflash_size_bytes)chaincyclerepeat)AutoSizeTypeGroupAddrFilenameArgAutoChunkSizeTypeChipType
AnyIntTypeOptionEatAllMutuallyExclusiveOptionResetModeTypeSpiConnectionTypeAutoHex2BinTypeAddrFilenamePairTypeparse_port_filtersparse_size_argT)      zUF2 optionsz--chunk-sizez--md5-disable)nameoptionszRAW optionsz--target-offsetz--pad-to-sizezFlash options)--flash-freq--flash-mode--flash-size--spi-connection)z* merge-bin*rD   zBasic commands)
write-flash
read-flasherase-flasherase-regionread-macflash-idr   
image-info	merge-binr   )r>   commandszAdvanced commands)verify-flashload-ramdump-memread-mem	write-memread-flash-statuswrite-flash-statusread-flash-sfdpget-security-infochip-idr   c                 `     t          j        dddt                                |           } | S )NrC   z-sczOverride default SPI flash memory connection. Value can be SPI, HSPI or a comma-separated list of 5 I/O numbers to use for SPI flash (CLK,Q,D,HD,CS). Not supported with ESP8266.)helptype)clickoptionr7   )functions    W/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/esptool/__init__.pyadd_spi_connection_argr_      sI    u|L       H O    F
allow_keepauto_detect	size_onlyreturnc                       rdgng g |r                     d            r                     d            fd}|S )z4Add common parser arguments for SPI flash propertieskeepdetectc                 .   s t          j        dddt          j        g dz             t          j                            drdnd                     |           }  t          j        dd	d
t          j        g dz             t          j                            drdnd                    |           }  t          j        dddt          j        g dz             t          j                            drdnd                    |           } | S )Nr@   z-ffzSPI flash memory frequency.)80m60m48m40m30m26m24m20m16m15m12m
ESPTOOL_FFrf   )rY   rZ   defaultrA   z-fmzSPI flash memory mode.)qioqoutdiodout
ESPTOOL_FMrv   rB   z-fszHSPI flash memory size. ESP8266-only sizes: 256KB, 512KB, 2MB-c1, 4MB-c1.)256KB512KB1MB2MBz2MB-c14MBz4MB-c18MB16MB32MB64MB128MB
ESPTOOL_FSr}   )r[   r\   Choiceosenvironget)r]   ra   extra_keep_argsflash_sizesrc   s    r^   wrapperz&add_spi_flash_options.<locals>.wrapper   sh    	u|2\#     
|z5SVVtTT)  * + H,u|-\/4R4R4R"RSS
|z5TVVuUU    H
5<@   " JNN<:1P5QQ-
 
 
. / 0 r`   )append)ra   rb   rc   r   r   r   s   ` ` @@r^   add_spi_flash_optionsr      s    
 #-4vhh"OK %8$$$ #6"""8 8 8 8 8 8 8 8t Nr`   espaddresssizec                 .   | j         r	| j        dv s+||z   dk    r"t          d|dd|dd||z   dz
  dd          | j        sPt	          |           }|sd S t          |          }||z   |k    r't          d	|dd|dd
| d||z   |z
  dd	          d S d S )N)zESP32-S3zESP32-P4zESP32-C5i   z6Can't access flash regions larger than 16MB (set size z#xz from address z#010xz goes past 16MB by z bytes).zECan't access flash regions larger than detected flash size (set size z goes past z by )IS_STUB	CHIP_NAMEr'   secure_download_moder   r*   )r   r   r   detected_size_strdetected_sizes        r^   check_flash_sizer     sC    [
 ].RRRdNY&&:O: :07O: :D.9,9: : :
 
 	
 # 
-c22  	F():;;T>M))V!NV V4;NV V$V V*1D.=*HUV V V  
 

 *)r`   z-hz--helpx   )help_option_namesmax_content_width	esptool vzR - serial utility for flashing, provisioning, and interacting with Espressif SoCs.)clsno_args_is_helpcontext_settingsrY   z--chipz-cautoESPTOOL_CHIPzTarget chip type.)rZ   ru   rY   z--portz-pESPTOOL_PORTzSerial port device.z--baudz-bESPTOOL_BAUDz1Serial port baud rate used when flashing/reading.z--port-filterz[Serial port device filter, can be vid=NUMBER, pid=NUMBER, name=SUBSTRING, serial=SUBSTRING.)multiplerZ   r   rY   z--before)default-resetz	usb-resetno-resetno-reset-no-syncESPTOOL_BEFOREr   z5Which reset to perform before connecting to the chip.z--afterz-a)
hard-resetz
soft-resetr   zno-reset-stubzwatchdog-resetESPTOOL_AFTERr   z3Which reset to perform after operation is finished.z	--no-stubzeDisable launching the flasher stub, only talk to ROM bootloader. Some features will not be available.)is_flagrY   z--stub-versionESPTOOL_STUB_VERSION12)ru   rZ   hiddenz--tracez-tz2Enable trace-level output of esptool interactions.z	--verbosez-vz3Print all output, disable collapsing output stages.z--silentz-sz%Silence all output except for errors.z--override-vddsdiozBOverride ESP32 VDDSDIO internal voltage regulator (use with care).)rZ   rY   z--connect-attemptsESPTOOL_CONNECT_ATTEMPTSzDNumber of attempts to connect, negative or 0 for infinite. Default: .c                 @   |                      t                     | j                            |           | j        d         r| j        d         rt	          d          | j        d         r| j        d         rt	          d          | j        d         rt          j        d           n!| j        d         rt          j        d           | j        | j        d<   t          | dd           | j        d<   t          j	        dt                      t          d	
           d S )Nverbosesilentz@Cannot use both --verbose and --silent options at the same time.tracez>Cannot use both --trace and --silent options at the same time.invoked_subcommandr   r   T)r   )ensure_objectdictobjupdater'   r#   set_verbosityr   getattrprint__version__r   ctxkwargss     r^   clir   )  s/   J dGNN6
wy 
cgh/ 
N
 
 	
 ww 
CGH- 
L
 
 	
 wy $)$$$$		 $(###$'$:CG !S%..CGENI'+''(((T""""""r`   c           
      d	    t          j         j        d                     j        d         rdt          _        t          j                      j        d         dk    r&t          t          j         j        d                   }n j        d         } j        d         It           j        d	                   }t          | }t          j        d
t          |           d           n j        d         g}t          j                            dt                     }	 t#          |          }n# t$          $ r t'          d          w xY w j                            dd          du j        d<   |dk    ru j        d          j        d         dk    rt          j        d           nBp?t+           j        d         | j        d         | j        d          j        d                   pLt-          | j        d          j        d         | j        d          j        d          j        d                    t/          dt          |           d          t          j        d           t          j        dj         dj        j         d           j        r t          j        ddj         d           nt          j        dd                                            t          j        d dd!                                                                          t          j        d"d                                 d#                                            }|t          j        d$d|            tC                     t          j                     j        r- j        d%         d&vrt/          d' j        d%          d(           j        d)         stE                     j        d*         r #                     j        d*                     j        d         |k    rJ	 $                     j        d                    n(# tJ          $ r t          j        d+| d,           Y nw xY w j        d<   t          j                      j&         fd-            }dS ).z Prepare ESP object for operationstub_versionr   Fbeforer   baudportNport_filterzFound z serial ports...ESPTOOL_OPEN_PORT_ATTEMPTSz-Invalid value for ESPTOOL_OPEN_PORT_ATTEMPTS.r   external_espr<   chipr   zmThe ESPTOOL_OPEN_PORT_ATTEMPTS (open_port_attempts) option can only be used with --port and --chip arguments.connect_attempts)r   r   initial_baudr   r   r   z7Could not connect to an Espressif device on any of the z available serial ports.T)finishzConnected to z on :z
Chip type:z<20z in Secure Download Modez	Features:, zCrystal frequency:MHzz	USB mode:r   )rV   rE   rH   zThe 'z3' command is not available in Secure Download Mode.no_stuboverride_vddsdiozBROM doesn't support changing baud rate. Keeping initial baud rate r   c                  P   t          dg           D ]} |                                  t          j                     j        d         dk    rt          j        d           nt          j        d                    j        d         sj                                         dS dS )zFCommon teardown for all commands with chip - reset chip and close port_open_filesr   rO   zExiting immediately.afterr   N)r   closer#   r   r   r   _port)fr   r   s    r^   teardownz$prepare_esp_object.<locals>.teardown'  s    
 mR00 	 	AGGIIII 		7'(J66I,----sCGG,---
 w~& 	IOO	 	r`   )'r    set_stub_subdirr   r#   _smart_featuresstageminr!   ESP_ROM_BAUDr:   get_port_listr   lenr   r   r   r   int
ValueError
SystemExitwarningconnect_loopget_default_connected_devicer'   r   r   r   r   get_chip_descriptionjoinget_chip_featuresget_crystal_freqget_usb_moder   r   r   change_baudr(   call_on_close)r   r   filtersser_listopen_port_attemptsusb_moder   r   s   `      @r^   prepare_esp_objectr     s=    7888 ww $#IKKK
wx..."CGFO
 
 wv
wv$SW]%;<< '*	:3x==:::;;;;GFO$$&@ J !344 J J JHIIIJ '++eT
"
"C!oCGNQ76?"cgfo&?&?KE   
  " ! C  -WV_!34!WV_ggwx   C {E ]]E E E
 
 	

 ITIBcmBBBBBCCC
  		\NNs}NNNOOOO	\CCs'?'?'A'ACCDDD	[JJdii0E0E0G0G&H&HJJKKK	)JJs/C/C/E/EJJJKKK##%%I44(44555IKKK
  
CG,@$A J % %
 'CG01 ' ' '
 
 	
 79 smm
 w!" :SW%78999
wv%%	OOCGFO,,,,' 	 	 	K=-9= = =    	 CGENIKKK 	       s   D, ,E7 Q "Q=<Q=rO   filename)rZ   c                     t          |          dk    rt          d          t          |            t          | j        d         |d         d         j                   dS )z%Download an image to RAM and execute.r<   zVMerged binary image detected. Only one file can be specified for the load-ram command.r   r   N)r   r'   r   r   r   r>   )r   r   s     r^   load_ram_clir   C  sd    
 8}}qG
 
 	
 sSWU^Xa[^011111r`   rP   )	allow_alloutputc                 ^    t          |            t          | j        d         |||           dS )z Dump arbitrary memory to a file.r   N)r   r   r   )r   r   r   r   s       r^   dump_mem_clir   Q  s2     sSWU^WdF33333r`   rQ   c                 Z    t          |            t          | j        d         |           dS )zRead arbitrary memory location.r   N)r   r   r   )r   r   s     r^   read_mem_clir   \  s.    
 sSWU^W%%%%%r`   rR   valuemaskl    )rZ   ru   c                 ^    t          |            t          | j        d         |||           dS )z-Modify or write to arbitrary memory location.r   N)r   r   r   )r   r   r   r   s       r^   write_mem_clir   e  s2     scgengud33333r`   rE   r>   zaddr-filename)nargsrequiredr   z--erase-allz-ezEErase all regions of flash (not just write areas) before programming.z--no-progresszSuppress progress output.z	--encryptzKApply flash encryption when writing data (required correct eFuse settings).z--encrypt-fileszfFiles to be encrypted during flashing. The address is followed by binary filename, separated by space.)rZ   r   rY   z--ignore-flash-enc-efusez'Ignore flash encryption eFuse settings.z--forcezFForce write, skip security and compatibility checks. Use with caution!z
--compressz-zzFCompress data during transfer (default unless --no-stub is specified).zno-compress)r   rY   exclusive_withr   z--no-compressz-uzLDisable data compression during transfer (default if --no-stub is specified)compress)r   ru   rY   r  r   )ra   rb   c                     |d         r|d         t          d          t          |            t          | j        d         |                    dd                     t          | j        d         |fi | dS )zaWrite a binary blob to flash. The address is followed by binary filename,
    separated by space.encryptencrypt_filesNzMOptions --encrypt and --encrypt-files must not be specified at the same time.r   spi_connection)r'   r   r	   r   popr   r   addr_filenamer   s      r^   write_flash_clir  p  s    t i 
VO4@6
 
 	
 s,<d!C!CDDD8888888r`   r   c                     t          |            t          | j        d                    t          | j        d                    dS )z%Run application code loaded in flash.r   N)r   r	   r   r   r   s    r^   run_clir    s@     s   r`   rK   c                     | j         d         dk    rdn| j         d         }t          |          dk    r$t          |d         d         j        |           dS t          ||           dS )zEPrint information about a firmware image (bootloader or application).r   r   Nr<   r   )r   )r   r   r   r>   )r   r   r   s      r^   image_info_clir    sq    
 76?f,,44#'&/D
8}}8A;q>&T2222228$''''''r`   r   )existsz--outputz-oz:Output filename or filename prefix (for ESP8266 v1 image).z	--version)r   r   3zOutput image version.z	--min-revz-r   )rZ   ru   r   z--min-rev-fulli   z7Minimal chip revision (in format: major * 100 + minor).z--max-rev-fulli  z7Maximal chip revision (in format: major * 100 + minor).z--secure-padzXPad image so once signed it will end on a 64KB boundary. For Secure Boot v1 images only.z--secure-pad-v2zxPad image to 64KB, so once signed its signature sector will start at the next 64K block. For Secure Boot v2 images only.z--elf-sha256-offsetz^If set, insert SHA256 hash (32 bytes) of the input ELF file at specified offset in the binary.z--dont-append-digestz|Don't append a SHA256 digest of the entire image after the checksum. This argument is not supported and ignored for ESP8266.)r   ru   rY   z--use-segmentszPIf set, ELF segments will be used instead of ELF sections to generate the image.z--flash-mmu-page-size)64KB32KB16KB8KBzChange flash MMU page size.zjThe block size to pad the final binary image to. Value 0xFF is used for padding. Supports MB, KB suffixes.z--ram-only-headeraR  Order segments so IRAM and DRAM are placed at the beginning and force the main header segment number to RAM segments quantity. This will make the other segments invisible to the ROM loader. Use with care, the ROM loader will only load the RAM segments although the other segments being present in the output. Implies --dont-append-digest.c                    | j         d         dk    r+t          dd                    t                     d          |                    dd           }|                    dd	          }|dn|}t          || j         d         |fd
|i| d	S )z)Create an application image from ELF filer   r   )Specify the --chip argument (choose from r   ).dont_append_digestFr   Nappend_digest)r   r'   r   r%   r  r   )r   r   r   r  r   s        r^   elf2image_clir     s    z wv&  P		)8L8LPPP
 
 	
 

#7???MZZ$''F~VV6FhWW}WPVWWWWWr`   rI   c                 X    t          |            t          | j        d                    dS )zPrint the device MAC address.r   N)r   r   r   r  s    r^   read_mac_clir"  0  s,     sSWU^r`   rW   c                 X    t          |            t          | j        d                    dS )zPrint the device chip ID.r   N)r   r   r   r  s    r^   chip_id_clir$  8  s,     sCGENr`   rJ   c                     t          |            t          | j        d         |                    dd                     t	          | j        d                    dS )z6Print the SPI flash memory manufacturer and device ID.r   r
  N)r   r	   r   r  r   r   s     r^   flash_id_clir&  @  sQ    
 s,<d!C!CDDDSWU^r`   rS   z--bytesz%Number of status bytes to read (1-3).c                     t          |            t          | j        d         |                    dd                     t	          | j        d         t          |                     dS )z&Read SPI flash memory status register.r   r
  N)r   r	   r   r  r   r   )r   bytesr   s      r^   read_flash_status_clir)  J  sY     s,<d!C!CDDDcgenc%jj11111r`   rT   z--non-volatilez+Write non-volatile bits (use with caution).z&Number of status bytes to write (1-3).c                     t          |            t          | j        d         |                    dd                     t	          | j        d         |t          |          fi | dS )z'Write SPI flash memory status register.r   r
  N)r   r	   r   r  r   r   )r   r   r(  r   s       r^   write_flash_status_clir+  Z  sc    " s,<d!C!CDDDswu~uc%jjCCFCCCCCr`   rF   )ra   rb   rc   c                 &   t          |            t          | j        d         |                    dd                     t	          | j        d         |          }t          | j        d         ||           t          | j        d         |||fi | dS )zRead SPI flash memory content.r   r
  N)r   r	   r   r  r;   r   r   )r   r   r   r   r   s        r^   read_flash_clir-  p  s     s,<d!C!CDDD#'%.$//DSWU^Wd333swu~wf???????r`   rN   z--diffz-dzShow differences.c                     t          |            t          | j        d         |                    dd                     t	          | j        d         |fd|i| dS )z6Verify a binary blob against the flash memory content.r   r
  Ndiff)r   r	   r   r  r   )r   r  r/  r   s       r^   verify_flash_clir0    s`     s,<d!C!CDDDDDTDVDDDDDr`   rG   zDErase flash even if security features are enabled. Use with caution!c                     t          |            t          | j        d         |                    dd                     t	          | j        d         |           dS )zErase the SPI flash memory.r   r
  N)r   r	   r   r  r   )r   forcer   s      r^   erase_flash_clir3    sS     s,<d!C!CDDD&&&&&r`   rH   zEErase region even if security features are enabled. Use with caution!c                 *   t          |            t          | j        d         |                    dd                     t	          | j        d         |          }t          | j        d         ||           t          | j        d         |||           dS )z'Erase a region of the SPI flash memory.r   r
  N)r   r	   r   r  r;   r   r   )r   r   r   r2  r   s        r^   erase_region_clir5    s     s,<d!C!CDDD#'%.$//DSWU^Wd333$66666r`   rU   r(  c                     t          |            t          | j        d         |                    dd                     t	          | j        d         ||           dS )z;Read SPI flash SFDP (Serial Flash Discoverable Parameters).r   r
  N)r   r	   r   r  r   )r   r   r(  r   s       r^   read_flash_sfdp_clir7    sU     s,<d!C!CDDDCGENGU33333r`   rL   zOutput filename.)rZ   r  rY   z--formatz-f)rawuf2hexr8  zFormat of the output file.zSpecify the used data part of the 512 byte UF2 block. A common value is 256. By default the largest possible value will be used.z#Disable MD5 checksum in UF2 output.z4Target offset where the output file will be flashed.)
r{   r|   r}   r~   r   r   r   r   r   r   zSIf set, the final binary file will be padded with 0xFF bytes up to this flash size.c                     | j         d         dk    r+t          dd                    t                     d          t	          |fd| j         d         i| dS )z=Merge multiple raw binary files into a single flashable file.r   r   r  r   r  N)r   r'   r   r%   r   r  s      r^   merge_bin_clir<    sk    P wv&  P		)8L8LPPP
 
 	
 m<<#'&/<V<<<<<r`   rV   c                 X    t          |            t          | j        d                    dS )z"Print security information report.r   N)r   r
   r   r  s    r^   get_security_info_clir>    s,     scgen%%%%%r`   r   c                  "    t                       dS )zPrint esptool version.N)r    r`   r^   version_clirA    s     IIIIIr`   argvc                     t          | pt          j        dd                   }	 t          ||           dS # t          $ r}|j        dk    r Y d}~dS d}~ww xY w)a  
    Main function for esptool

    argv - Optional override for default arguments parsing (that uses sys.argv),
    can be a list of custom arguments as strings. Arguments and their values
    need to be added as individual items to the list
    e.g. "-b 115200" thus becomes ['-b', '115200'].

    esp - Optional override of the connected device previously
    returned by get_default_connected_device()
    r<   N)argsr   r   )expand_file_argumentssysrB  r   r   code)rB  r   rD  es       r^   mainrI    sz     !!5!""66D3   6Q;; ;;;;;s   8 
AAAvidspidsnamesserialsc                    t           t          d          g }t          j                    D ]t          j        dk    rj                            d          r-| rj        	j        | vr@|rj        	j        |vrS|r#j	        t          fd|D                       rx|r#j        t          fd|D                       r|                    j                   t          |          S )NzListing all serial ports is currently not available. Please try to specify the port when running esptool or update the pyserial package to the latest version.darwin)zBluetooth-Incoming-Portz
wlan-debugc              3   *   K   | ]}|j         vV  d S Nr  ).0r>   r   s     r^   	<genexpr>z get_port_list.<locals>.<genexpr>%  s*      $M$MtT%:$M$M$M$M$M$Mr`   c              3   *   K   | ]}|j         vV  d S rQ  )serial_number)rR  serialr   s     r^   rS  z get_port_list.<locals>.<genexpr>*  s+      JJ6!33JJJJJJr`   )r"   r'   comportsrF  platformdeviceendswithvidpidr>   allrU  r   sorted)rJ  rK  rL  rM  portsr   s        @r^   r   r     s<    :
 
 	

 E#%% " "<8##(<(<5)
 )
#  	TX%)=)= 	TX%)=)= 	I$M$M$M$Mu$M$M$M!M!M 	&JJJJ'JJJJJ ' T[!!!!%==r`   c                    g }d}| D ]}|                     d          rad}t          |dd                   5 }|                                D ]}|t          j        |          z  }	 ddd           n# 1 swxY w Y   x|                    |           |r,t          j        dd                    |                      |S | S )z
    Any argument starting with "@" gets replaced with all values read from a text file.
    Text file arguments can be split by newline or by space.
    Values are added "as-is", as if they were specified in this order
    on the command line.
    F@Tr<   Nzesptool  )	
startswithopen	readlinesshlexsplitr   r#   r   r   )rB  new_argsexpandedargr   lines         r^   rE  rE  1  s    HH ! !>># 	!Hc!""g 2!KKMM 2 2DD 1 11HH22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 OOC     	1SXXh//11222Ks   /A33A7	:A7	r   r   r   max_retriesr   r   c                    t           |         }d }t          j        d|  d           d}t          t	          t          dd          d                    }	t	          t          d|dz
            |rdnt          d                    }
t          |
|	          D ]\  }}	  || ||          }|st          j        d	           |                    |           |c S # t          t          j
        j        t          f$ r}|r |j        r|j                                         d }|r-t          j        |           t          j        d
d	d           d}|r||rt          j        dd	d           t          j        d           Y d }~d }~ww xY wd S )NSerial port r   TF	   )Tr<   )F zRetrying failed connection)endflushr   g?)r$   r#   r   r,   r+   r-   zipconnectr'   rV  
serialutilSerialExceptionOSErrorr   r   timesleep)r   r   r   rl  r   r   
chip_classr   first	ten_cycle
retry_looplastevery_tentherrs                 r^   r   r   H  s    4J
CI$T$$$%%%EeF5!,,g6677IukAo&&;(SE(OO J !Y77  k	*T<77C 	"KKJJJF-=wG 	 	 	 "sy "	!!!C 	#	6BdKKKK 	 3	#2T2222JsOOOOOOOO	 s   9C!F:BFFserial_listr   c                    d }t          |           D ]}t          j        d| d           	 |dk    rt          |||||          }n0t          |         }	 |	|||          }|                    ||            n^# t          t          f$ rJ}
| t          j        | d|
            |r |j	        r|j	        
                                 d }Y d }
~
d }
~
ww xY w|S )Nrn  r   r   z failed to connect: )reversedr#   r   r   r$   rt  r'   rw  errorr   r   )r  r   r   r   r   r   r   _esp	each_portrz  r  s              r^   r   r   r  s%    Dk**  		----...	v~~"|VU<L  't_
!z)\5AAV%5666EG$ 	 	 	I====>>> #
 #
  """DDDDDD	 Ks   A
A99C
A CCc                     t          t                     	 t                       d S # t          $ r6} t	          j        d|             t          j        d           Y d } ~ d S d } ~ wt          j	        j
        $ r^} t	          j        d|             t	          j        d           t	          j        d           t          j        d           Y d } ~ d S d } ~ wt          $ rQ t	          j        t          j                               t	          j        d           t          j        d           Y d S t          $ r, t	          j        d           t          j        d           Y d S w xY w)	Nz
A fatal error occurred:    z$
A serial exception error occurred: zNote: This error originates from pySerial. It is likely not a problem with esptool, but with the hardware connection or drivers.zkFor troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.htmlr<   z4A fatal error occurred: The chip stopped responding.z)KeyboardInterrupt: Run cancelled by user.)r)   __name__rI  r'   r#   r  rF  exitrV  ru  rv  StopIteration	traceback
format_excKeyboardInterrupt)rH  s    r^   _mainr    s}   x(((   	2q22333,   	=!==>>>	;	
 	
 	

 		Y	
 	
 	
 	   	)&(()))	HIII   	=>>>s.   & 
E#+A!!E#8ACAE#.1E#"E#__main__)FFF)NN)Fr   )r   Fr   )__all__r   r   rf  rF  rx  r  
rich_clickr[   typingtesptool.cmdsr   r   r   r   r   r   r   r	   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   esptool.configr   esptool.loaderr   r   r    r!   r"   esptool.loggerr#   esptool.targetsr$   r%   r&   esptool.utilr'   r(   r)   r*   	itertoolsr+   r,   r-   rV  esptool.cli_utilr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   SHOW_ARGUMENTS'STYLE_COMMANDS_TABLE_COLUMN_WIDTH_RATIOOPTION_GROUPSCOMMAND_GROUPSr_   boolCallabler   r   r   groupr   r\   r   r   Pathr   strr   OVERRIDE_VDDSDIO_CHOICESpass_contextr   r   commandargumentlisttupleIOr(  r   r   r   r   r  r  r  IntRanger   r"  r$  r&  r)  r+  r-  r0  r3  r5  r7  r<  r>  rA  rI  r   rE  r   r   r  r  r@  r`   r^   <module>r     sg    8  				  



                                                                    8 , + + + + +                    : : : : : : : : : :            + * * * * * * * * *                                $ #'  ;A  8 "	
 	
 "!	
 	
$ $  	
 	


#" "  < $  	
 	
  (  	
 	
! 
"#  N	 	 	 LQG GG+/GDHGZG G G GT) c      8 TT8,<PSTTT
+[ 
+ 
+ 
+	   	6(Y&	'	'JNN>622	   	JNN>400	   	JNN>9+ABB	<   	
   	UUU	V	VJNN+_==	@	   	SSS
 
 JNN?L99	>   
+   JNN1377	sCj	!	!   	=	   	>	   	0	   	h7	8	8	M  
 	JNN57OPP
,(
, 
, 
,	   # #               B#0[ [ [B Z
!2!23332U3:qtE{+B%C D 2 2 2  43 2 Z	

---\\E:::;;;zuz||,,,4 4  -, <; .- 
4 Z	

---& &  .- & [	

---jjll+++ZZ\\:>>>4 4  ?> ,+ .- 
4 -  rDoNNN	P	   otT8STTT	V  
 				
$	   	2  
 	Q  
 	Q!?   	W<   $D9999 9   :9       UT  ON ! f9" U    \
!2!2333($uS4Ze-D'E"F ( ( (  43 ( [
4!8!8!8999		E	   	ooo	&	&	     	3		   	5	!	!	B	   	5	!	!	B	   
   
6   	
	   
>	   
   	555	6	6	&  
 	
@	   
J   %U;;;	X 	X  <;              :9 v	X Z    Y    Z      !!	ooo	&	&	0	   2 2    "!2 !""	6  
 	ooo	&	&	1	   jjll+++D D   ,+   #"D \	

---\\^^,,,zuz||,,,otT8STTT$DDIII@ @   JI UT -, -, .- @ ^rDoNNNhd1DEEE$D999E E   :9 FE ON E ]	O  
 ' '    ' ^	P  
 	

---\\^^,,,7 7   -, .-  7 	

---jjll+++$D9994 4   :9 ,+ .-  4 [rDoNNNj$S4>PQQQ	+++	,	,	%   				
:   	.  
 		?   	WWW
 

   $E:::= =  ;:      RQ ON L=  !!& &  "!& Y  
 tCy4 Y-=    * 	   
s) 
s)  9  #Y	 
 
#Y       FS	 d3i    8 !' '
'' ' 	'
 ' ' ' ' '^ ! c
  	
      @  8 z	EGGGGG r`   