Skip to content

Commit ca46611

Browse files
authored
Merge pull request #11 from mozzwald/esp32s3
Add ESP32S3 support, Update build and bump version to 1.5
2 parents 0ae17f4 + afdf80e commit ca46611

File tree

8 files changed

+141
-95
lines changed

8 files changed

+141
-95
lines changed

.github/workflows/main.yml

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ jobs:
1717
run: |
1818
python --version
1919
pip --version
20-
- name: Install requirements
20+
- name: Update, Install & Build in virtual python environment
21+
shell: pwsh
2122
run: |
23+
python -m venv .venv
24+
.\.venv\Scripts\Activate.ps1
25+
python -m pip uninstall -y esptool
26+
python -m pip install "esptool>=4.7"
2227
pip install -r requirements_build.txt
2328
pip install -e .
2429
pip install --force-reinstall -v pyinstaller==4.10
2530
pip install --force-reinstall -v pyinstaller-hooks-contrib==2023.2
26-
- name: Run PyInstaller
27-
run: |
28-
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico esphomeflasher\__main__.py
31+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico `
32+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/1/*.json;esptool/targets/stub_flasher/1" `
33+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/2/*.json;esptool/targets/stub_flasher/2" `
34+
--collect-submodules esptool `
35+
esphomeflasher\__main__.py
2936
- uses: actions/upload-artifact@master
3037
with:
3138
name: FujiNet-Flasher_win-x64
@@ -45,15 +52,22 @@ jobs:
4552
run: |
4653
python --version
4754
pip --version
48-
- name: Install requirements
55+
- name: Update, Install & Build in virtual python environment
56+
shell: pwsh
4957
run: |
58+
python -m venv .venv
59+
.\.venv\Scripts\Activate.ps1
60+
python -m pip uninstall -y esptool
61+
python -m pip install "esptool>=4.7"
5062
pip install -r requirements_build.txt
5163
pip install -e .
5264
pip install --force-reinstall -v pyinstaller==4.10
5365
pip install --force-reinstall -v pyinstaller-hooks-contrib==2023.2
54-
- name: Run PyInstaller
55-
run: |
56-
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico esphomeflasher\__main__.py
66+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico `
67+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/1/*.json;esptool/targets/stub_flasher/1" `
68+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/2/*.json;esptool/targets/stub_flasher/2" `
69+
--collect-submodules esptool `
70+
esphomeflasher\__main__.py
5771
- name: See dist directory
5872
run: ls dist
5973
- name: Upload Artifact
@@ -82,7 +96,11 @@ jobs:
8296
pip install -e .
8397
- name: Run PyInstaller
8498
run: |
85-
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico esphomeflasher/__main__.py
99+
export STUBS_DIR="$(pip show esptool | grep "Location: " | cut -c 11- | tr -d '\n')/esptool/targets/stub_flasher/"
100+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico \
101+
--add-data="${STUBS_DIR}/1/*.json:esptool/targets/stub_flasher/1/" \
102+
--add-data="${STUBS_DIR}/2/*.json:esptool/targets/stub_flasher/2/" \
103+
esphomeflasher/__main__.py
86104
- name: See dist directory
87105
run: ls dist
88106
- name: Upload Artifact
@@ -104,13 +122,21 @@ jobs:
104122
run: |
105123
python --version
106124
pip --version
107-
- name: Install requirements
108-
run: |
109-
pip install -r requirements_build.txt
110-
pip install -e .
111-
- name: Run PyInstaller
112-
run: |
113-
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.icns esphomeflasher/__main__.py
125+
# Make sure we’re running in an isolated venv
126+
- name: Update, Install & Build in virtual python environment
127+
run: |
128+
python -m venv .venv
129+
source .venv/bin/activate
130+
python -m pip install --upgrade pip
131+
python -m pip uninstall -y esptool || true
132+
python -m pip install "esptool>=4.7"
133+
python -m pip install -r requirements_build.txt
134+
export STUBS_DIR="$(pip show esptool | grep "Location: " | cut -c 11- | tr -d '\n')/esptool/targets/stub_flasher/"
135+
ls -al ${STUBS_DIR}
136+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.icns \
137+
--add-data="${STUBS_DIR}/1/*.json:esptool/targets/stub_flasher/1/" \
138+
--add-data="${STUBS_DIR}/2/*.json:esptool/targets/stub_flasher/2/" \
139+
esphomeflasher/__main__.py
114140
- name: Remove Extra Binary
115141
run: rm dist/FujiNet-Flasher
116142
- name: Set binary permissions
@@ -149,13 +175,20 @@ jobs:
149175
run: |
150176
python3 --version
151177
pip3 --version
152-
- name: Install requirements
178+
- name: Update, Install & Build in virtual python environment
153179
run: |
180+
python3 -m venv .venv
181+
source .venv/bin/activate
182+
pip3 install --upgrade pip
183+
pip3 uninstall -y esptool || true
184+
pip3 install "esptool>=4.7"
154185
pip3 install -r requirements_build.txt
155-
pip3 install -e .
156-
- name: Run PyInstaller
157-
run: |
158-
python3 -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.icns esphomeflasher/__main__.py
186+
export STUBS_DIR="$(pip3 show esptool | grep "Location: " | cut -c 11- | tr -d '\n')/esptool/targets/stub_flasher/"
187+
ls -al ${STUBS_DIR}
188+
python3 -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.icns \
189+
--add-data="${STUBS_DIR}/1/*.json:esptool/targets/stub_flasher/1/" \
190+
--add-data="${STUBS_DIR}/2/*.json:esptool/targets/stub_flasher/2/" \
191+
esphomeflasher/__main__.py
159192
- name: Remove Extra Binary
160193
run: rm dist/FujiNet-Flasher
161194
- name: Set binary permissions

README.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
1-
# esphomeflasher (for FujiNet)
1+
# FujiNet Flasher
22

3-
esphomeflasher is a utility app for the [esphomelib](https://esphomelib.com/esphomeyaml/index.html)
4-
framework and is designed to make flashing ESPs with esphomelib as simple as possible by:
3+
FujiNet Flasher is a utility app for [FujiNet Hardware](https://fujinet.online)
4+
and is designed to make flashing as simple as possible by:
55

6-
* Having pre-built binaries for most operating systems.
6+
* Having pre-built binaries for most modern operating systems
77
* Hiding all non-essential options for flashing. All necessary options for flashing
88
(bootloader, flash mode) are automatically extracted from the binary.
99

1010
This project was originally intended to be a simple command-line tool,
11-
but then I decided that a GUI would be nice. As I don't like writing graphical
12-
front end code, the GUI largely is based on the
13-
[NodeMCU PyFlasher](https://github.com/marcelstoer/nodemcu-pyflasher)
14-
project.
11+
but then it was decided that a GUI would be nice. The GUI largely is based on the
12+
[NodeMCU PyFlasher](https://github.com/marcelstoer/nodemcu-pyflasher) and
13+
[esphomeflasher](https://github.com/esphome/esphome-flasher) projects.
1514

1615
The flashing process is done using the [esptool](https://github.com/espressif/esptool)
1716
library by espressif.
1817

1918
## Installation
2019

2120
It doesn't have to be installed, just double-click it and it'll start.
22-
Check the [releases section](https://github.com/OttoWinter/esphomeflasher/releases)
21+
Check the [releases section](https://github.com/FujiNetWiFi/fujinet-flasher/releases)
2322
for downloads for your platform.
2423

25-
## Installation Using `pip`
26-
27-
If you want to install this application from `pip`:
28-
29-
- Install Python 3.x
30-
- Install [wxPython 4.x](https://wxpython.org/) manually or run `pip3 install wxpython`
31-
- Install this project using `pip3 install esphomeflasher`
32-
- Start the GUI using `esphomeflasher`. Alternatively, you can use the command line interface (
33-
type `esphomeflasher -h` for info)
34-
3524
## Build it yourself
3625

37-
If you want to build this application yourself you need to:
26+
If you want to build this application yourself:
3827

3928
- Install Python 3.x
40-
- Install [wxPython 4.x](https://wxpython.org/) manually or run `pip3 install wxpython`
41-
- Download this project and run `pip3 install -e .` in the project's root.
42-
- Start the GUI using `esphomeflasher`. Alternatively, you can use the command line interface (
43-
type `esphomeflasher -h` for info)
29+
- See `build-instructions.md`
4430

4531
## License
4632

47-
[MIT](http://opensource.org/licenses/MIT) © Marcel Stör, Otto Winter
33+
[MIT](http://opensource.org/licenses/MIT) © Marcel Stör, Otto Winter, Joe Honold

build-instructions.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
# Linux / macOS
1+
# Linux / MacOS
22

3-
* `pip install -r requirements_build.txt`
4-
* `pyinstaller -F -w -n FujiNet-Flasher -i icon.icns esphomeflasher/__main__.py`
3+
```
4+
python -m venv .venv
5+
source .venv/bin/activate
6+
python -m pip install --upgrade pip
7+
python -m pip uninstall -y esptool || true
8+
pip install -r requirements_build.txt
9+
export STUBS_DIR="$(pip show esptool | grep "Location: " | cut -c 11- | tr -d '\n')/esptool/targets/stub_flasher/"
10+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.icns \
11+
--add-data="${STUBS_DIR}/1/*.json:esptool/targets/stub_flasher/1/" \
12+
--add-data="${STUBS_DIR}/2/*.json:esptool/targets/stub_flasher/2/" \
13+
esphomeflasher/__main__.py
14+
```
515

616
# Windows
717

8-
* `pip install pyinstaller`
9-
* `pip install -r requirements_build.txt`
10-
* `pip install -e.`
11-
* `python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico esphomeflasher\__main__.py`
18+
```
19+
python -m venv .venv
20+
.\.venv\Scripts\Activate.ps1
21+
python -m pip uninstall -y esptool
22+
python -m pip install "esptool>=4.7"
23+
pip install -r requirements_build.txt
24+
pip install -e .
25+
pip install --force-reinstall -v pyinstaller==4.10
26+
pip install --force-reinstall -v pyinstaller-hooks-contrib==2023.2
27+
python -m PyInstaller.__main__ -F -w -n FujiNet-Flasher -i icon.ico `
28+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/1/*.json;esptool/targets/stub_flasher/1" `
29+
--add-data "./.venv/lib/site-packages/esptool/targets/stub_flasher/2/*.json;esptool/targets/stub_flasher/2" `
30+
--collect-submodules esptool `
31+
esphomeflasher\__main__.py
32+
```

esphomeflasher/__main__.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
from esphomeflasher.common import fujinet_version_info, is_url
1313

1414
import esptool
15+
from esptool.cmds import detect_chip
1516
import serial
1617

1718
from esphomeflasher import const
1819
from esphomeflasher.common import ESP32ChipInfo, EsphomeflasherError, chip_run_stub, \
19-
configure_write_flash_args, detect_chip, detect_flash_size, read_chip_info, \
20+
configure_write_flash_args, detect_flash_size, read_chip_info, \
2021
read_firmware_info, check_flash_size, MockEsptoolArgs
2122
from esphomeflasher.const import ESP32_DEFAULT_BOOTLOADER_FORMAT, ESP32_DEFAULT_OTA_DATA, \
2223
ESP32_DEFAULT_PARTITIONS, ESP32_DEFAULT_FIRMWARE, ESP32_DEFAULT_SPIFFS, \
2324
FUJINET_VERSION_INFO, FUJINET_RELEASE_INFO
2425
from esphomeflasher.helpers import list_serial_ports
2526

26-
2727
# Set PYTHONUNBUFFERED environment variable to ensure unbuffered output
2828
os.environ["PYTHONUNBUFFERED"] = "1"
2929

@@ -159,27 +159,37 @@ def run_esphomeflasher_args(args):
159159
else:
160160
raise EsphomeflasherError("Invalid release info. Missing firmware file!")
161161

162-
chip = detect_chip(port, force_esp32=True)
162+
try:
163+
chip = detect_chip(
164+
port=port,
165+
baud="115200", # Detect at slow baud
166+
connect_mode="default-reset",
167+
trace_enabled=False,
168+
connect_attempts=7
169+
)
170+
except esptool.FatalError as err:
171+
raise EsphomeflasherError(f"Error Detecting ESP: {err}") from err
172+
173+
try:
174+
chip.connect('no_reset',7,False,False)
175+
except esptool.FatalError as err:
176+
raise EsphomeflasherError(f"Error connecting to ESP: {err}") from err
177+
178+
stub_chip = chip_run_stub(chip)
163179
info = read_chip_info(chip)
164180

165-
print()
166-
print("Chip Info:")
167-
print(" - Chip Family: {}".format(info.family))
168-
print(" - Chip Model: {}".format(info.model))
169181
if isinstance(info, ESP32ChipInfo):
170-
print(" - Number of Cores: {}".format(info.num_cores))
171-
print(" - Max CPU Frequency: {}".format(info.cpu_frequency))
172-
print(" - Has Bluetooth: {}".format('YES' if info.has_bluetooth else 'NO'))
173-
print(" - Has Embedded Flash: {}".format('YES' if info.has_embedded_flash else 'NO'))
174-
print(" - Has Factory-Calibrated ADC: {}".format(
175-
'YES' if info.has_factory_calibrated_adc else 'NO'))
182+
print("\nChip Info:")
183+
for attr, val in vars(info).items():
184+
# skip private/internal attrs
185+
if attr.startswith('_'):
186+
continue
187+
# pretty-up the field name
188+
name = attr.replace('_', ' ').title()
189+
print(f" - {name}: {val}")
176190
else:
177191
print(" - Chip ID: {:08X}".format(info.chip_id))
178192

179-
print(" - MAC Address: {}".format(info.mac))
180-
181-
stub_chip = chip_run_stub(chip)
182-
183193
if args.upload_baud_rate != 115200:
184194
try:
185195
stub_chip.change_baud(args.upload_baud_rate)
@@ -190,7 +200,7 @@ def run_esphomeflasher_args(args):
190200
if not flash_size:
191201
raise EsphomeflasherError("Firmware larger than chip flash, stopping!")
192202

193-
mock_args = MockEsptoolArgs(flash_size, addr_filename, flash_mode, flash_freq)
203+
mock_args = MockEsptoolArgs(flash_size, addr_filename, flash_mode, flash_freq, chip)
194204

195205
print(" - Flash Mode: {}".format(mock_args.flash_mode))
196206
print(" - Flash Frequency: {}Hz".format(mock_args.flash_freq.upper()))

esphomeflasher/common.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class EsphomeflasherError(Exception):
1818

1919

2020
class MockEsptoolArgs(object):
21-
def __init__(self, flash_size, addr_filename, flash_mode, flash_freq):
21+
def __init__(self, flash_size, addr_filename, flash_mode, flash_freq, chip):
22+
self.chip = chip
2223
self.compress = True
2324
self.no_compress = False
2425
self.flash_size = flash_size
@@ -29,7 +30,9 @@ def __init__(self, flash_size, addr_filename, flash_mode, flash_freq):
2930
self.verify = False
3031
self.erase_all = False
3132
self.encrypt = False
32-
33+
self.force = True
34+
self.encrypt = False
35+
self.encrypt_files = None
3336

3437
class ChipInfo(object):
3538
def __init__(self, family, model, mac):
@@ -101,6 +104,16 @@ def read_chip_info(chip):
101104
has_factory_calibrated_adc = 'VRef calibration in efuse' in features
102105
return ESP32ChipInfo(model, mac, num_cores, frequency, has_bluetooth,
103106
has_embedded_flash, has_factory_calibrated_adc)
107+
elif isinstance(chip, esptool.ESP32S3ROM):
108+
model = read_chip_property(chip.get_chip_description)
109+
features = read_chip_property(chip.get_chip_features)
110+
num_cores = 2 if 'Dual Core' in features else 1
111+
frequency = next((x for x in ('160MHz', '240MHz') if x in features), '80MHz')
112+
has_bluetooth = 'BT' in features
113+
has_embedded_flash = 'Embedded Flash' in features
114+
has_factory_calibrated_adc = 'VRef calibration in efuse' in features
115+
return ESP32ChipInfo(model, mac, num_cores, frequency, has_bluetooth,
116+
has_embedded_flash, has_factory_calibrated_adc)
104117
elif isinstance(chip, esptool.ESP8266ROM):
105118
model = read_chip_property(chip.get_chip_description)
106119
chip_id = read_chip_property(chip.chip_id)
@@ -202,20 +215,3 @@ def configure_write_flash_args(info, firmware_path, flash_size,
202215
bootloader_path, partitions_path,
203216
otadata_path, spiffs_path):
204217
return 0
205-
206-
def detect_chip(port, force_esp8266=False, force_esp32=False):
207-
if force_esp8266 or force_esp32:
208-
klass = esptool.ESP32ROM if force_esp32 else esptool.ESP8266ROM
209-
chip = klass(port)
210-
else:
211-
try:
212-
chip = esptool.ESPLoader.detect_chip(port)
213-
except esptool.FatalError as err:
214-
raise EsphomeflasherError("ESP Chip Auto-Detection failed: {}".format(err))
215-
216-
try:
217-
chip.connect()
218-
except esptool.FatalError as err:
219-
raise EsphomeflasherError("Error connecting to ESP: {}".format(err))
220-
221-
return chip

esphomeflasher/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22

3-
__version__ = "1.4.3"
3+
__version__ = "1.5.0"
44

55
FUJINET_FLASHER_VERSION_URL = "https://fujinet.online/firmware/flasher-current-ver.txt"
66

requirements_build.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
attrdict3
22
wheel
3-
wxpython==4.1.1
4-
esptool==3.0
3+
wxpython>=4.1.1
4+
esptool>=4.7
55
requests>=2.24.0,<3
6-
pyinstaller==4.10
6+
pyinstaller>=4.10
77
pyinstaller-hooks-contrib==2023.2
88
certifi
99
cryptography>=3.4.8

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
REQUIRES = [
2525
'wxpython>=4.0,<5.0',
26-
'esptool==2.8',
26+
'esptool>=4.7',
2727
'requests>=2.0,<3',
2828
]
2929

0 commit comments

Comments
 (0)