Skip to content

ESP8266/32 BIOS programmer for Winbond W25Qxx flash chips with automatic detection (2-32MB), embedded web interface

Notifications You must be signed in to change notification settings

AdaLoveLacer/ESP8266-BIOS-Programmer-h61-bios

Repository files navigation

ESP8266 W25Qxx BIOS Programmer

Leia-me em portuguΓͺs nos arquivos.

EPROM Programmer/Debugger for W25Qxx series (Winbond) BIOS chips using ESP8266, with automatic capacity detection and support from 2MB to 32MB.

✨ Main Features

  • πŸ” Automatic Chip Detection: Identifies W25Q16/32/64/128/256 via JEDEC ID
  • πŸ“¦ Multi-Capacity Support: 2MB, 4MB, 8MB, 16MB, 32MB
  • πŸ“€ Optimized Streaming Upload: 1KB chunks with automatic verify-retry
  • πŸ”’ Protection Management: Automatically removes block protections
  • ⚑ SPI Speed Control: 0.1-20 MHz adjustable at runtime (presets: 1/4/8/20 MHz)
  • βœ… Automatic Verification: Byte-by-byte checksum with detailed error report
  • 🌐 Responsive Web Interface: Embedded HTML/JS with real-time terminal
  • πŸ“Š Detailed Logs: Verbosity system (Quiet/Normal/Verbose/Debug)
  • πŸ”§ Robust Base64 Decoding: Critical transfer bug fixes

πŸ”§ Required Hardware

  • ESP8266 (NodeMCU, Wemos D1 Mini, etc.)
  • W25Qxx Series Chip:
    • βœ… W25Q16 (2MB) - JEDEC ID: EF4015
    • βœ… W25Q32 (4MB) - JEDEC ID: EF4016
    • βœ… W25Q64 (8MB) - JEDEC ID: EF4017 ← New support!
    • βœ… W25Q128 (16MB) - JEDEC ID: EF4018
    • βœ… W25Q256 (32MB) - JEDEC ID: EF4019
  • Connection jumpers (recommended: short cables 10-15cm)
  • Stable 3.3V power supply (ESP8266 already provides)

πŸ“Œ ESP8266 ↔ W25Qxx Series Pinout

ESP8266 Pin W25Qxx Description
D8 GPIO15 CS (Pin 1) Chip Select
D7 GPIO13 DI (Pin 5) Data Input (MOSI)
D6 GPIO12 DO (Pin 2) Data Output (MISO)
D5 GPIO14 CLK (Pin 6) Serial Clock
3.3V 3.3V VCC (Pin 8) Power Supply
3.3V 3.3V WP# (Pin 3) Write Protect - MUST be connected to VCC!
3.3V 3.3V HOLD# (Pin 7) Hold/Reset - MUST be connected to VCC!
GND GND GND (Pin 4) Ground

IMPORTANT:

  • W25Qxx operates ONLY at 3.3V. DO NOT use 5V!
  • ⚠️ CRITICAL: Pins 3 (WP#) and 7 (HOLD#) MUST be connected to 3.3V to allow writing!
  • If WP# is left at GND, the Status Register is locked and write protection cannot be removed!
  • Use short cables (10-15cm) to avoid signal integrity issues

πŸ” W25Qxx Pinout (SOIC-8)

     β”Œβ”€β”€β”€ 1 CS (Chip Select)
     β”‚ β”Œβ”€ 2 DO (MISO)
     β”‚ β”‚ β”Œ 3 WP# (Write Protect) β†’ ⚠️ Connect to VCC (3.3V)!
     β”‚ β”‚ β”‚β”Œ 4 GND
  β”Œβ”€β”€β–Όβ”€β–Όβ”€β–Όβ–Όβ”€β”
1──  ●      β”œβ”€8 VCC (3.3V)
2──         β”œβ”€7 HOLD# β†’ ⚠️ Connect to VCC (3.3V)!
3──  W25Qxxβ”œβ”€6 CLK
4──  Seriesβ”œβ”€5 DI (MOSI)
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚠️ WARNING - CRITICAL CONFIGURATION:

  • Pin 3 (WP#): MUST be connected to 3.3V (do not leave floating or at GND!)
  • Pin 7 (HOLD#): MUST be connected to 3.3V (do not leave floating or at GND!)
  • If WP# is at GND, the Status Register is protected and you WILL NOT BE ABLE to remove block protection!
  • If HOLD# is at GND, SPI communication will be permanently paused!

πŸ”Œ Complete Connection Diagram

ESP8266                      W25Qxx (SOIC-8)
                        
3.3V ────┬──────────────────► Pin 8 (VCC)
         β”‚
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί Pin 3 (WP#)   ⚠️ CRITICAL!
         β”‚
         └──────────────────► Pin 7 (HOLD#) ⚠️ CRITICAL!

GND ─────────────────────────► Pin 4 (GND)

D8 (GPIO15) ─────────────────► Pin 1 (CS)
D7 (GPIO13) ─────────────────► Pin 5 (DI/MOSI)
D6 (GPIO12) ─────────────────► Pin 2 (DO/MISO)
D5 (GPIO14) ─────────────────► Pin 6 (CLK)

Checklist before programming:

  • VCC connected to 3.3V (Pin 8)
  • GND connected (Pin 4)
  • WP# connected to 3.3V (Pin 3) ⚠️
  • HOLD# connected to 3.3V (Pin 7) ⚠️
  • CS connected to D8 (Pin 1)
  • MOSI connected to D7 (Pin 5)
  • MISO connected to D6 (Pin 2)
  • CLK connected to D5 (Pin 6)
  • Short cables (10-15cm maximum) πŸ“

πŸ› οΈ Arduino IDE Configuration

1. Install ESP8266 Core

  1. File β†’ Preferences
  2. In "Additional Board Manager URLs" add:
    http://arduino.esp8266.com/stable/package_esp8266com_index.json
    
  3. Tools β†’ Board β†’ Boards Manager
  4. Search for "ESP8266" and install

2. Configure Board

  • Board: "NodeMCU 1.0 (ESP-12E Module)" or your specific model
  • Upload Speed: 115200
  • CPU Frequency: 80 MHz
  • Flash Size: 4MB (FS:2MB OTA:~1019KB)
  • Port: Select the ESP8266 COM port

3. Configure WiFi

Edit the lines in esp8266_w25q32_programmer.ino file:

const char* ssid = "YourWiFi";        // Your network name
const char* password = "YourPassword";   // Your network password

4. Upload Firmware

  1. Connect ESP8266 via USB
  2. Open esp8266_w25q32_programmer.ino
  3. Click Upload (β†’)
  4. Wait for completion

⚑ Important: All-in-One Firmware

🎯 Just compile the .ino file - that's it!

  • βœ… The web interface (HTML/CSS/JS) is already embedded in the .ino file
  • βœ… No need to upload separate HTML files
  • βœ… No need to use filesystem (SPIFFS/LittleFS)
  • βœ… Everything works out of the box after compilation
  • πŸ“„ The index.html file is just for reference/preview - not required for operation

What happens:

  1. You compile esp8266_w25q32_programmer.ino in Arduino IDE
  2. Upload to ESP8266
  3. The web interface is already there, ready to use
  4. Just access the IP address in your browser

🌐 Using the Programmer

1. Connect to ESP8266

  1. Open Serial Monitor (115200 baud)
  2. Find the IP shown on WiFi connection
  3. Access http://YOUR_ESP8266_IP in browser

2. Web Interface

The interface allows:

πŸ“‹ Chip Information

  • Read JEDEC ID:
    • βœ… Automatically detects: W25Q16/32/64/128/256
    • βœ… Shows actual chip capacity (2MB-32MB)
    • βœ… Validates SPI communication
  • Status: Shows if busy or write-protected

βš™οΈ SPI Configuration

  • Adjustable Frequency: 0.1 MHz - 20 MHz (slider)
  • Quick Presets: 1/4/8/20 MHz buttons for quick testing
  • Chunk Size Verify: 4KB, 8KB, 16KB, 32KB, 64KB
  • Recommendation:
    • Use 1 MHz if you encounter corruption
    • Use 4 MHz for stability
    • Use 8-20 MHz for speed (short cables)

πŸ“– Reading

  • Read Data: Reads specific region (address + size)
  • Full Dump:
    • βœ… Automatically detects chip size
    • βœ… Downloads 2MB-32MB according to connected chip
    • βœ… File saved as bios_<timestamp>.bin

✏️ Writing

  • Accepts Formats: .bin, .rom, .bss ← New!
  • Maximum Size: Up to 8MB (adjusts according to detected chip)
  • Chunk-by-Chunk System:
    • Erases sector (4KB)
    • Writes 1KB
    • Verifies immediately
    • Automatic retry (up to 3x per chunk)
  • Automatic Verification:
    • Byte-by-byte checksum
    • Detailed error report
    • Locates first/last error
    • Counts affected regions
  • Progress Bar: Real-time updates

πŸ—‘οΈ Erasing

  • Erase Sector: Removes specific 4KB
  • Erase Chip: ⚠️ DANGER - Removes everything (makes board unusable)
  • Automatic Protection: Removes protections before erasing

πŸ”“ Chip Protection

  • Check Protection: Shows Status Register and BP0-BP2 bits
  • Remove Protection: Clears all block protection bits
  • Auto-Remove: System automatically removes protections before writing
  • IMPORTANT: Hardware protection (WP# pin) must be disabled (connected to VCC)

πŸ“Ÿ Log Terminal

  • Verbosity Levels: Quiet / Normal / Verbose / Debug
  • Auto-Scroll: Enable/disable automatic scrolling
  • Real-Time Logs: Updates every 1 second
  • Type Filtering: ERROR (red), WARNING (yellow), INFO (blue), DEBUG (gray)

πŸ” W25Q32BV Protection System

Hardware Protection (Pins)

The W25Q32BV has two levels of protection:

1. WP# Pin (Write Protect - Pin 3):

  • GND (LOW): Status Register LOCKED - does not accept modifications ❌
  • VCC (HIGH): Status Register UNLOCKED - accepts modifications βœ…
  • For writing: MANDATORY to connect to 3.3V!

2. HOLD# Pin (Pin 7):

  • GND (LOW): SPI Communication PAUSED ❌
  • VCC (HIGH): SPI Communication NORMAL βœ…
  • For writing: MANDATORY to connect to 3.3V!

Software Protection (Status Register)

BP0, BP1, BP2 bits in Status Register protect memory regions:

BP2 BP1 BP0 Protected Region Addresses
0 0 0 None (unlocked) βœ… -
0 0 1 Upper 256KB 0x3F0000-0x3FFFFF
0 1 0 Upper 512KB 0x3E0000-0x3FFFFF
0 1 1 Upper 1MB 0x3C0000-0x3FFFFF
1 0 0 Upper 2MB 0x380000-0x3FFFFF
1 0 1 Upper 3MB 0x300000-0x3FFFFF
1 1 0 Upper half 0x200000-0x3FFFFF
1 1 1 Entire chip πŸ”’ 0x000000-0x3FFFFF

How to use protection:

  1. Before writing: Click "πŸ” Check Protection"
  2. If protected: Click "πŸ”“ Remove Protection"
  3. Make sure WP# is at VCC (3.3V)!
  4. If WP# is at GND, protection removal WILL NOT WORK!

⚠️ CRITICAL WARNINGS

🚨 BACKUP FIRST!

ALWAYS make a backup of the original BIOS before any modification:

  1. Click "Full Dump (4MB)"
  2. Save the .bin file in a safe location
  3. Keep multiple copies

πŸ”΄ Writing Risks

  • Corrupted BIOS = Unusable motherboard
  • Only flash compatible BIOS for your H61 board
  • Never power off during writing
  • Verify file integrity before writing

⚑ Electrical Precautions

  • Completely power off the motherboard (power cable + battery)
  • Make sure there is no residual power
  • Use static wrist strap before touching components
  • Connect GND first, then other pins

πŸ”§ Troubleshooting

❌ Error: "4001 corrupted bytes" or partial corruption

Root cause: Critical bug in Base64 decoding (FIXED in v2.0!)

Solutions:

  1. Update to latest version (Base64 fix implemented)
  2. Reduce SPI speed:
    • Test 1 MHz first
    • If OK, gradually increase to 4 MHz β†’ 8 MHz
  3. Improve physical connections:
    • Use shorter cables (10-15cm)
    • Check for loose wires
    • Confirm common ground
  4. Check detailed logs:
    • Browser console (F12): size of sent chunks
    • Serial Monitor: received/decoded bytes

πŸ” ID not detected or incorrect JEDEC

  • Check SPI connections (pin order)
  • Confirm stable 3.3V power
  • Test jumper continuity
  • Check if chip is not soldered inverted
  • Use shorter cables (<15cm)

🚫 Write error / "Chip protected"

  • Chip write-protected:
    • Check if WP# (Pin 3) is connected to 3.3V (not GND!)
    • Click "πŸ” Check Protection" in interface
    • If protected, click "πŸ”“ Remove Protection"
    • If WP# is at GND, removal WILL NOT work!
  • Chip not responding:
    • Check if HOLD# (Pin 7) is connected to 3.3V (not GND!)
    • If HOLD# at GND, chip stays permanently paused
  • Insufficient voltage (use stable 3.3V supply)
  • Unstable connection during operation

πŸ“‘ ESP8266 not connecting to WiFi

  • Check SSID and password in code
  • 2.4GHz network (ESP8266 does not support 5GHz)
  • If it fails, ESP creates Access Point:
    • Name: ESP8266-BIOS-Programmer
    • Password: 12345678
    • IP: 192.168.4.1

πŸ’Ύ Motherboard not booting after flashing

  1. DO NOT PANIC
  2. Re-flash original backup
  3. If backup corrupted, look for official BIOS from manufacturer
  4. Use board BIOS recovery tool (if available)

πŸ“š W25Q32BV Technical Commands

Command Code Description
JEDEC ID 0x9F Read ID: EF4016
Read Data 0x03 Sequential read
Write Enable 0x06 Enable writing
Page Program 0x02 Write page (256B)
Read Status 0x05 Status register
Sector Erase 0x20 Erase sector (64KB)
Chip Erase 0xC7 Erase all

πŸ—οΈ Code Architecture

esp8266_w25q32_programmer.ino
β”œβ”€β”€ πŸ”§ Configuration
β”‚   β”œβ”€β”€ WiFi/AP dual mode
β”‚   β”œβ”€β”€ Configurable SPI (0.1-20 MHz)
β”‚   └── Automatic chip detection
β”œβ”€β”€ πŸ“‘ Low-level SPI functions
β”‚   β”œβ”€β”€ readJedecId() β†’ Read ID + detect capacity
β”‚   β”œβ”€β”€ detectFlashSize() β†’ Adjust FLASH_SIZE dynamically
β”‚   β”œβ”€β”€ readData() β†’ Sequential reading
β”‚   β”œβ”€β”€ programPage() β†’ Write 256 bytes
β”‚   β”œβ”€β”€ sectorErase() β†’ Erase 4KB
β”‚   └── chipErase() β†’ Erase all
β”œβ”€β”€ πŸ”’ Protection System
β”‚   β”œβ”€β”€ readStatus() / readStatus2()
β”‚   β”œβ”€β”€ writeStatusRegister()
β”‚   β”œβ”€β”€ disableAllProtection() β†’ Remove BP0-BP2
β”‚   └── isWriteProtected() β†’ Check protection
β”œβ”€β”€ πŸ“€ Streaming System (large files)
β”‚   β”œβ”€β”€ 1KB chunks for memory economy
β”‚   β”œβ”€β”€ Write-Verify-Retry per chunk (up to 3x)
β”‚   β”œβ”€β”€ Erase on-demand (erase sector when needed)
β”‚   └── Real-time progress tracking
β”œβ”€β”€ 🌐 HTTP Web Server
β”‚   β”œβ”€β”€ handleInterface() β†’ Embedded HTML/JS/CSS
β”‚   β”œβ”€β”€ handleReadId() β†’ /id (with chip detection)
β”‚   β”œβ”€β”€ handleRead() β†’ /read (dynamic reading)
β”‚   β”œβ”€β”€ handleWriteStream() β†’ /writeStream (init/finish)
β”‚   β”œβ”€β”€ handleWriteChunk() β†’ /writeChunk (ROBUST Base64)
β”‚   β”œβ”€β”€ handleSetSpiFrequency() β†’ /setSpiFrequency
β”‚   β”œβ”€β”€ handleCheckProtection() β†’ /checkProtection
β”‚   β”œβ”€β”€ handleRemoveProtection() β†’ /removeProtection
β”‚   └── handleSystem() β†’ /system (info + detected size)
β”œβ”€β”€ πŸ“Š Log System
β”‚   β”œβ”€β”€ 4 levels: Quiet/Normal/Verbose/Debug
β”‚   β”œβ”€β”€ Circular buffer (50 messages)
β”‚   └── /logs endpoint for web terminal
└── πŸ–₯️ HTML/JS Interface
    β”œβ”€β”€ SPI controls with presets
    β”œβ”€β”€ Streaming upload with progress
    β”œβ”€β”€ Byte-by-byte verification with report
    β”œβ”€β”€ Real-time terminal
    └── Console logs (F12) for debug

πŸ› Fixed Bugs (v2.0)

πŸ”΄ Critical Bug: Base64 Decoding (RESOLVED)

Symptom: 4001 corrupted bytes in large uploads

Cause: 3 bugs in manual Base64 decoding:

  1. ❌ Loop stopped before end (length() - 3)
  2. ❌ Premature break on padding
  3. ❌ Incorrect byte extraction logic

Solution: Base64 decoder rewritten from scratch:

  • βœ… Processes ALL characters
  • βœ… Accumulates bits gradually (not by blocks)
  • βœ… Handles padding correctly
  • βœ… Validates each byte
  • βœ… Debug logs (input/output size)

Result: 0% corruption in tests with 8MB files

πŸ“ˆ Changelog

v2.0 (2025-10-10)

  • βœ… Automatic detection of W25Q16/32/64/128/256 chips
  • βœ… Support for 8MB+ (up to 32MB)
  • βœ… .bss file acceptance
  • βœ… Critical Base64 decoding fix (eliminates corruption)
  • βœ… Base64 debug logs (client + server)
  • βœ… Dynamic dump (adjusts to chip size)
  • βœ… Interface shows chip name and capacity
  • βœ… /system endpoint returns detected size

v1.0 (Original)

  • W25Q32 support (4MB)
  • Streaming upload
  • Basic verification
  • SPI control

πŸ“„ License

This project is provided "as is" for educational purposes. Use at your own risk. The author is not responsible for damages caused by improper use.


⚠️ FINAL REMINDER: BIOS flashing is a high-risk operation. Always have a backup and adequate technical knowledge before proceeding.