toverainc / willow

Open source, local, and self-hosted Amazon Echo/Google Home competitive Voice Assistant alternative
https://heywillow.io/
Apache License 2.0
2.57k stars 96 forks source link

Flashing Willow with esptool #360

Closed RazZziel closed 8 months ago

RazZziel commented 8 months ago

How can we flash Willow with bare esptool?

Willow Web Flash (https://flash.heywillow.io/) doesn't work for me, for some reason. I'm trying it on Chrome 120.0.6099.109 on Linux with a ESP-S3-BOX, and I always get the same error:

Fetching your Willow release. Please wait...
Successfully injected Willow settings in image!
Error: Cannot read properties of undefined (reading 'BOOTLOADER_FLASH_OFFSET')

Flashing with bare esptool works fine:

pip install esptool
python3 -m esptool --port /dev/serial/by-id/pci-Espressif_USB_JTAG_serial_debug_unit_F4\:12\:FA\:FD\:15\:C8-if00 write_flash 0x0 ~/Downloads/willow-dist-ESP32-S3-BOX.bin

However the ESP-S3-BOX doesn't get past the "Starting up" screen, because I can't configure the WiFi and WAS parameters.

How can I configure the WiFi and WAS parameters when flashing Willow with bare esptool?

stintel commented 8 months ago

Welcome to Willow. I'm in Sunday mode, so this answer might be incomplete. If this is not enough, I'll try to provide more help tomorrow.

There's a function in utils.sh that generates the NVS partition, and there's a hint in the commit message of 36ee1f70bf1d23d2cf654afbd2a95db448e73699 that tells you how to flash that partition.

RazZziel commented 8 months ago

Thanks!

I tried generating a NVS partition with https://www.linux-ipv6.be/esp-nvs/, and flashing it along Willow with these commands:

python3 -m esptool --port /dev/ttyACM0 write_flash 0x0 ~/Downloads/willow-dist-ESP32-S3-BOX.bin
python3 -m esptool --port /dev/ttyACM0 write_flash 0x9000 ~/Downloads/nvs.bin

I think https://www.linux-ipv6.be/esp-nvs/ doesn't work right, because if I run strings on the generated nvs.bin, my SSID is nowhere to be found, and Willow boot gets stuck trying to connect to the wifi:

I (15:12:46.139) WILLOW/NETWORK: disconnected from AP, retrying
I (15:12:48.543) WILLOW/NETWORK: disconnected from AP, retrying
I (15:12:50.947) WILLOW/NETWORK: disconnected from AP, retrying
I (15:12:53.350) WILLOW/NETWORK: disconnected from AP, retrying
I (15:12:55.754) WILLOW/NETWORK: disconnected from AP, retrying

I tried running https://www.linux-ipv6.be/esp-nvs/ again but switching the "SSID" and the "WAS URL" fields. Oddly, that seems to work better, now Willow connects to the network, but not to my WAS, and the ESP-S3-BOX screen shows "Fatal error! Failed to read NVS partition", and the boot log shows this:

I (15:15:08.239) WILLOW/NETWORK: disconnected from AP, retrying
I (15:15:08.280) WILLOW/NETWORK: unhandled network event ev_id='4'
I (15:15:09.780) WILLOW/NETWORK: received IP: 192.168.1.224
I (15:15:09.780) WILLOW/NETWORK: Using configured SNTP server 'pool.ntp.org'
E (15:15:09.783) WILLOW/MAIN: failed to open NVS namespace WAS: ESP_ERR_NVS_NOT_FOUND
I (15:15:15.013) WILLOW/NETWORK: SNTP client synchronized time to 1705266915 from server pool.ntp.org

In the commit message you linked they mention an alternative to https://www.linux-ipv6.be/esp-nvs/ in NOTES.md, and there's indeed a "Generate NVS partition" section, but it uses /opt/esp/idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py and I don't know yet where to find that tool, I guess it's from ESPs toolkit?

RazZziel commented 8 months ago

I did it!

touch nvs.bin
docker run -v$PWD/nvs.csv:/nvs.csv -v$PWD/nvs.bin:/nvs.bin espressif/idf /opt/esp/idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py generate --version 2 nvs.csv nvs.bin 0x24000
python3 -m esptool --port /dev/ttyACM0 write_flash 0x9000 nvs.bin

I had previously generated the nvs.csv using a template I got from utils.sh, because the one in NOTES.md is wrong (lacks the WAS URL):

key,type,encoding,value
WAS,namespace,,
URL,data,string,$WAS_URL
WIFI,namespace,,
PSK,data,string,$PASSWORD
SSID,data,string,$SSID