Flashing the ESP32
This guide explains how to flash the ESP32 module on the Nagami module. The ESP32 provides Wi-Fi and Bluetooth using ESP-Hosted-NG firmware from Espressif.
⚠️ The ESP32 is connected via SDIO, and its strapping pins are controlled by both the MMC host and the mmc-pwrseq driver. You must fully release both before flashing.
Prerequisites
Ensure the following are available on the Nagami module:
esptool.py,espefuse.py,espsecure.py- A valid ESP-Hosted-NG firmware build (see build section below)
Step-by-Step Instructions
Step 1: Disable ESP32 Control (MMC + PWRSEQ)
Since the driver is now managed by udev, there is no service to stop. Instead, manually release control:
# Unbind MMC host
echo "4021000.mmc" > /sys/bus/platform/drivers/sunxi-mmc/unbind
# Unbind power sequence (IMPORTANT - releases reset GPIO)
echo "wifi-pwrseq" > /sys/bus/platform/drivers/pwrseq_simple/unbind
👉 Both steps are required. Unbinding MMC alone is not sufficient.
Step 2: Enter ESP32 Bootloader Mode
Set the strapping pins and reset the ESP32:
gpioset -t0 ESP_nBOOT=0
gpioset -t0 ESP_D0=0
# Reset pulse
gpioset -t0 ESP_nRST=0
gpioset -t0 ESP_nRST=1
The ESP32 is now in UART bootloader mode.
Step 3: (Optional) Set Flash Voltage
If using a new or replaced ESP32, set flash voltage to 3.3V:
espefuse.py -p /dev/ttyS1 -b 115200 --chip esp32 set_flash_voltage 3.3V
⚠️ This is one-time and irreversible. Type BURN when prompted.
Step 4: Flash Firmware
Run:
esptool.py -p /dev/ttyS1 -b 115200 --chip esp32 write_flash \
--flash_mode dio --flash_size detect --flash_freq 40m \
0x1000 bootloader.bin \
0x8000 partition-table.bin \
0xd000 ota_data_initial.bin \
0x10000 network_adapter.bin
Step 5: Reboot System
After flashing:
reboot
✅ On boot, udev will automatically:
- Rebind MMC
- Reattach
mmc-pwrseq - Load ESP-Hosted driver
You should see WiFi come up (“✨ look at the stars”).
Building ESP-Hosted-NG Firmware
If you need to build firmware manually:
git clone https://github.com/espressif/esp-hosted.git
cd esp-hosted
# Checkout version matching kernel module
git checkout release/ng-1.0.5.0.3
Build
cd esp_hosted_ng/esp/esp_driver
./setup.sh
. ./esp-idf/export.sh
idf.py set-target esp32
idf.py build
Output Files
After building, use:
build/bootloader/bootloader.bin
build/partition_table/partition-table.bin
build/ota_data_initial.bin
build/network_adapter.bin
Copy them to the Nagami module (e.g. via scp) and flash using the steps above.