Difference between revisions of "Flash script linux"

From Let's Control It
Jump to navigation Jump to search
(Created page with "To flash an ESP8266 on Linux, you need the esptool as it is shipped with Arduino IDE or as standalone tool, see github [source](https://github.com/igrr/esptool-ck) and [binary...")
 
m (→‎Thonshic's script: bug report from https://www.letscontrolit.com/forum/viewtopic.php?f=6&t=2105#p45507)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
To flash an ESP8266 on Linux, you need the esptool as it is shipped with Arduino IDE or as standalone tool, see github [source](https://github.com/igrr/esptool-ck) and [binary releases](https://github.com/igrr/esptool-ck/releases/).
+
= Flash script for linux =
 +
 
 +
To flash an ESP8266 on Linux, you need the esptool as it is shipped with Arduino IDE or as standalone tool, see github [https://github.com/igrr/esptool-ck source] and [https://github.com/igrr/esptool-ck/releases/ binary releases].
 +
 
 +
== Felix' script ==
 +
 
 +
Felix [http://www.letscontrolit.com/forum/viewtopic.php?t=2105 posted a script in the forum] that works like the windows flash.cmd script:
 +
 
 +
    #!/bin/bash
 +
    read -e -p "Serial Port                          :" -i "/dev/ttyUSB0" comport
 +
    read -e -p "Flash Size (example 512, 1024, 4096) :" -i "4096" fsize
 +
    read -e -p "Build (example 71, 72, ..)          :" -i "120" build
 +
 
 +
    size="${fsize}K"
 +
    if [ $fsize -gt 1000 ]; then
 +
            size=$(($fsize/1024))"M"
 +
    fi
 +
 
 +
    echo "Expected Flash Size: $size"
 +
    echo "Using com port: $comport"
 +
    if [ -f ESPEasy_R${build}_${fsize}.bin ]; then
 +
            echo "Using bin file: ESPEasy_R${build}_${fsize}.bin [FOUND]"
 +
            ./esptool -vv -cd nodemcu -cb 115200 -bz $size -cp $comport -ca 0x00000 -cf ESPEasy_R${build}_${fsize}.bin
 +
    else
 +
            echo "Expected bin file: ESPEasy_R${build}_${fsize}.bin [NOT FOUND!!!]"
 +
    fi
 +
 
 +
== Thonshic's script ==
  
 
The following script tries to find the esptool binary
 
The following script tries to find the esptool binary
Line 6: Line 33:
 
* the local directory (with the script and firmware files)
 
* the local directory (with the script and firmware files)
  
<code>
+
You get a choice of firmware files, either with dialog or by number.
#!/bin/bash
+
 
 +
    #!/bin/bash
 +
 
 +
    selectst=""
 +
    for i in ESPEasy*bin
 +
    do
 +
            selectst="$i $i off $selectst"
 +
    done
 +
 
 +
    # check for esptool
 +
    esptoolbin=$(which esptool)
 +
    if [ ! -x "$esptoolbin" ] ; then
 +
            if [ -x "./esptool" ] ; then
 +
                    esptoolbin="./esptool"
 +
            else
 +
                    eardu=$(find $HOME/.arduino*/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
 +
                    if [ -x "$eardu" ] ; then
 +
                            echo "found esptool: $eardu"
 +
                            esptoolbin="$eardu"
 +
                    fi
 +
            fi
 +
    fi
 +
    if [ ! -x "$esptoolbin" ] ; then
 +
            echo "esptool not found, you can link it here or put in \$PATH"
 +
            exit 2
 +
    else
 +
            echo "using esptool $esptoolbin"
 +
    fi
 +
 
 +
    read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
  
selectst=""
+
    if [ ! -r "$serdev" ] ; then
for i in ESPEasy*bin
+
            echo "device '$serdev' does not exist"
do
+
            exit 2
selectst="$i $i off $selectst"
+
    fi
done
 
  
# check for esptool
+
    if [ -n "$(which dialog)" ] ; then
esptoolbin=$(which esptool)
+
            cmd=(dialog --radiolist "Select firmware" 22 76 16)
if [ ! -x "$esptoolbin" ] ; then
+
            choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
if [ -x "./esptool" ] ; then
+
    else
esptoolbin="./esptool"
+
            # bash only, do it with an array
else
+
            fa=(ESP_Easy_*.bin)
eardu=$(find $HOME/.arduino15/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
+
            cnt=0
if [ -x "$eardu" ] ; then
+
            nfa=${#fa[*]}
echo "found esptool: $eardu"
+
            while [ $cnt -lt $nfa ]
esptoolbin="$eardu"
+
            do
fi
+
                    echo $cnt ${fa[$cnt]}
fi
+
                    ((cnt++))
fi
+
            done
if [ ! -x "$esptoolbin" ] ; then
+
            read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
echo "esptool not found, you can link it here or put in \$PATH"
+
            choice=${fa[$nsel]}
exit 2
+
            if [ ! -f "$choice" ] ; then  
else
+
                    echo "cannot find file \"$choice\", exiting"
echo "using esptool $esptoolbin"
+
                    exit 2
fi
+
            fi
 +
    fi
  
read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
+
    echo "----"
 +
    read -p "flash $choice? [Y/n]" yn
 +
    if [ "$yn" != "n" ] ; then
 +
        "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
 +
    fi
  
if [ ! -r "$serdev" ] ; then
+
=== Example output ===
echo "device '$serdev' does not exist"
 
exit 2
 
fi
 
  
if [ -n "$(which dialog)" ] ; then
 
cmd=(dialog --radiolist "Select firmware" 22 76 16)
 
choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
 
else
 
# bash only, do it with an array
 
fa=(ESPEasy_*.bin)
 
cnt=0
 
nfa=${#fa[*]}
 
while [ $cnt -lt $nfa ]
 
do
 
echo $cnt ${fa[$cnt]}
 
                ((cnt++))
 
done
 
read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
 
choice=${fa[$nsel]}
 
if [ ! -f "$choice" ] ; then
 
echo "cannot find file \"$choice\", exiting"
 
exit 2
 
fi
 
fi
 
  
echo "----"
+
using esptool ./esptool
read -p "flash $choice? [Y/n]" yn
+
serial device, (USB2serial devices: /dev/ttyUSB0):/dev/ttyUSB0
if [ "$yn" != "n" ] ; then
+
    ┌──────────────────────────────────────────────────────────────────────────┐
     "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
+
    │ Select firmware                                                          │ 
fi
+
    │ ┌──────────────────────────────────────────────────────────────────────┐ │ 
</code>
+
    │ │          (*) ESPEasy_R147_512.bin  ESPEasy_R147_512.bin            │ │ 
 +
    │ │          ( ) ESPEasy_R147_4096.bin  ESPEasy_R147_4096.bin          │ │ 
 +
    │ │          ( ) ESPEasy_R147_1024.bin  ESPEasy_R147_1024.bin          │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ │                                                                      │ │ 
 +
    │ └──────────────────────────────────────────────────────────────────────┘ │ 
 +
    ├──────────────────────────────────────────────────────────────────────────┤ 
 +
    │                  <  OK    >          <Abbrechen>                      │ 
 +
    └──────────────────────────────────────────────────────────────────────────┘ 
 +
    ----
 +
    flash ESPEasy_R147_512.bin? [Y/n]
 +
     esptool v0.4.9 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
 +
        setting board to nodemcu
 +
        setting baudrate from 115200 to 115200
 +
        setting port from /dev/ttyUSB0 to /dev/ttyUSB0
 +
        setting address from 0x00000000 to 0x00000000
 +
        espcomm_upload_file
 +
        espcomm_upload_mem
 +
    opening port /dev/ttyUSB0 at 115200
 +
        tcgetattr
 +
        tcsetattr
 +
        serial open
 +
    opening bootloader
 +
    resetting board
 +
    trying to connect
 +
        espcomm_send_command: sending command header
 +
        espcomm_send_command: sending command payload
 +
    trying to connect
 +
        espcomm_send_command: sending command header
 +
        espcomm_send_command: sending command payload
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        espcomm_send_command: receiving 2 bytes of data
 +
    Uploading 431376 bytes from ESPEasy_R147_512.bin to flash at 0x00000000
 +
        erasing flash
 +
        size: 069510 address: 000000
 +
        first_sector_index: 0
 +
        total_sector_count: 106
 +
        head_sector_count: 16
 +
        adjusted_sector_count: 90
 +
        erase_size: 05a000
 +
        espcomm_send_command: sending command header
 +
        espcomm_send_command: sending command payload
 +
        setting timeout 15000
 +
        setting timeout 100
 +
        espcomm_send_command: receiving 2 bytes of data
 +
        writing flash
 +
    ................................................................................ [ 18% ]
 +
    ................................................................................ [ 37% ]
 +
    ................................................................................ [ 56% ]
 +
    ................................................................................ [ 75% ]
 +
    ................................................................................ [ 94% ]
 +
    ......................                                                          [ 100% ]
 +
    starting app without reboot
 +
        espcomm_send_command: sending command header
 +
        espcomm_send_command: sending command payload
 +
        espcomm_send_command: receiving 2 bytes of data
 +
    closing bootloader

Latest revision as of 20:55, 22 July 2020

Flash script for linux

To flash an ESP8266 on Linux, you need the esptool as it is shipped with Arduino IDE or as standalone tool, see github source and binary releases.

Felix' script

Felix posted a script in the forum that works like the windows flash.cmd script:

   #!/bin/bash
   read -e -p "Serial Port                          :" -i "/dev/ttyUSB0" comport
   read -e -p "Flash Size (example 512, 1024, 4096) :" -i "4096" fsize
   read -e -p "Build (example 71, 72, ..)           :" -i "120" build
   size="${fsize}K"
   if [ $fsize -gt 1000 ]; then
           size=$(($fsize/1024))"M"
   fi
   echo "Expected Flash Size: $size"
   echo "Using com port: $comport"
   if [ -f ESPEasy_R${build}_${fsize}.bin ]; then
           echo "Using bin file: ESPEasy_R${build}_${fsize}.bin [FOUND]"
           ./esptool -vv -cd nodemcu -cb 115200 -bz $size -cp $comport -ca 0x00000 -cf ESPEasy_R${build}_${fsize}.bin
   else
           echo "Expected bin file: ESPEasy_R${build}_${fsize}.bin [NOT FOUND!!!]"
   fi

Thonshic's script

The following script tries to find the esptool binary

  • in Arduino IDE install paths
  • in a dir of the PATH variable
  • the local directory (with the script and firmware files)

You get a choice of firmware files, either with dialog or by number.

   #!/bin/bash
   selectst=""
   for i in ESPEasy*bin
   do
           selectst="$i $i off $selectst"
   done
   # check for esptool
   esptoolbin=$(which esptool)
   if [ ! -x "$esptoolbin" ] ; then
           if [ -x "./esptool" ] ; then
                   esptoolbin="./esptool"
           else
                   eardu=$(find $HOME/.arduino*/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
                   if [ -x "$eardu" ] ; then
                           echo "found esptool: $eardu"
                           esptoolbin="$eardu"
                   fi
           fi
   fi
   if [ ! -x "$esptoolbin" ] ; then
           echo "esptool not found, you can link it here or put in \$PATH"
           exit 2
   else
           echo "using esptool $esptoolbin"
   fi
   read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
   if [ ! -r "$serdev" ] ; then
           echo "device '$serdev' does not exist"
           exit 2
   fi
   if [ -n "$(which dialog)" ] ; then
           cmd=(dialog --radiolist "Select firmware" 22 76 16)
           choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
   else
           # bash only, do it with an array
           fa=(ESP_Easy_*.bin)
           cnt=0
           nfa=${#fa[*]}
           while [ $cnt -lt $nfa ]
           do
                   echo $cnt ${fa[$cnt]}
                   ((cnt++))
           done
           read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
           choice=${fa[$nsel]}
           if [ ! -f "$choice" ] ; then 
                   echo "cannot find file \"$choice\", exiting"
                   exit 2
           fi
   fi
   echo "----"
   read -p "flash $choice? [Y/n]" yn
   if [ "$yn" != "n" ] ; then
       "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
   fi

Example output

using esptool ./esptool
serial device, (USB2serial devices: /dev/ttyUSB0):/dev/ttyUSB0
   ┌──────────────────────────────────────────────────────────────────────────┐
   │ Select firmware                                                          │  
   │ ┌──────────────────────────────────────────────────────────────────────┐ │  
   │ │           (*) ESPEasy_R147_512.bin   ESPEasy_R147_512.bin            │ │  
   │ │           ( ) ESPEasy_R147_4096.bin  ESPEasy_R147_4096.bin           │ │  
   │ │           ( ) ESPEasy_R147_1024.bin  ESPEasy_R147_1024.bin           │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ │                                                                      │ │  
   │ └──────────────────────────────────────────────────────────────────────┘ │  
   ├──────────────────────────────────────────────────────────────────────────┤  
   │                   <   OK    >          <Abbrechen>                       │  
   └──────────────────────────────────────────────────────────────────────────┘  
   ----
   flash ESPEasy_R147_512.bin? [Y/n]
   esptool v0.4.9 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
       setting board to nodemcu
       setting baudrate from 115200 to 115200
       setting port from /dev/ttyUSB0 to /dev/ttyUSB0
       setting address from 0x00000000 to 0x00000000
       espcomm_upload_file
       espcomm_upload_mem
   opening port /dev/ttyUSB0 at 115200
       tcgetattr
       tcsetattr
       serial open
   opening bootloader
   resetting board
   trying to connect
       espcomm_send_command: sending command header
       espcomm_send_command: sending command payload
   trying to connect
       espcomm_send_command: sending command header
       espcomm_send_command: sending command payload
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
       espcomm_send_command: receiving 2 bytes of data
   Uploading 431376 bytes from ESPEasy_R147_512.bin to flash at 0x00000000
       erasing flash
       size: 069510 address: 000000
       first_sector_index: 0
       total_sector_count: 106
       head_sector_count: 16
       adjusted_sector_count: 90
       erase_size: 05a000
       espcomm_send_command: sending command header
       espcomm_send_command: sending command payload
       setting timeout 15000
       setting timeout 100
       espcomm_send_command: receiving 2 bytes of data
       writing flash
   ................................................................................ [ 18% ]
   ................................................................................ [ 37% ]
   ................................................................................ [ 56% ]
   ................................................................................ [ 75% ]
   ................................................................................ [ 94% ]
   ......................                                                           [ 100% ]
   starting app without reboot
       espcomm_send_command: sending command header
       espcomm_send_command: sending command payload
       espcomm_send_command: receiving 2 bytes of data
   closing bootloader