Skip to content

Commit 558d3de

Browse files
Copilotsofthack007
andcommitted
Improve partition file handling and add comprehensive debugging
Critical improvements for partition "spiffs" not found errors: - Update prepare-firmware.sh with robust bootloader detection: - Check standard location: BUILD_DIR/bootloader.bin - Check alternative location: BUILD_DIR/bootloader/bootloader.bin - ESP-IDF v4+ may use subdirectory structure - Add comprehensive error checking: - Fail build if bootloader.bin or partitions.bin are missing - Display detailed error messages with file locations - Show build directory contents to aid debugging - Display partition table hex dump for verification - Add partition file verification in CI workflow: - Verify bootloader.bin exists before boot check - Verify partitions.bin exists before boot check - Display hexdump of partitions.bin (shows table structure) - Fail fast if required files are missing - Update README with comprehensive troubleshooting: - New section: "Filesystem/partition errors" - Step-by-step diagnosis for "partition not found" errors - Commands to verify partition files and configuration - Explanation of why bootloader and partitions are critical - Instructions for rebuilding if files are missing These changes ensure that missing partition files are detected early with clear error messages, rather than causing runtime filesystem errors in the simulator. Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com>
1 parent 397f901 commit 558d3de

3 files changed

Lines changed: 125 additions & 5 deletions

File tree

.github/workflows/wokwi-test.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,37 @@ jobs:
105105
echo "⚠️ firmware.elf not found (optional for simulation)"
106106
fi
107107
108+
# Verify bootloader and partitions exist (required for filesystem)
109+
if [ -f "bootloader.bin" ]; then
110+
echo "✅ bootloader.bin found ($(du -h bootloader.bin | cut -f1))"
111+
else
112+
echo "❌ ERROR: bootloader.bin not found - filesystem will not work!"
113+
echo "Available files:"
114+
ls -la
115+
exit 1
116+
fi
117+
118+
if [ -f "partitions.bin" ]; then
119+
echo "✅ partitions.bin found ($(du -h partitions.bin | cut -f1))"
120+
else
121+
echo "❌ ERROR: partitions.bin not found - filesystem will not work!"
122+
echo "Available files:"
123+
ls -la
124+
exit 1
125+
fi
126+
108127
# Verify firmware can be read and has valid ESP32 header
109128
echo ""
110129
echo "Firmware file details:"
111-
ls -lh firmware.bin firmware.elf 2>/dev/null || true
130+
ls -lh firmware.bin firmware.elf bootloader.bin partitions.bin 2>/dev/null || true
112131
echo ""
113132
echo "Firmware.bin first 64 bytes (hex):"
114133
hexdump -C firmware.bin | head -4 || echo "Cannot read firmware.bin"
115134
echo "Note: ESP32 firmware should start with magic byte 0xe9"
135+
echo ""
136+
echo "Partitions.bin first 64 bytes (hex):"
137+
hexdump -C partitions.bin | head -4 || echo "Cannot read partitions.bin"
138+
echo "Note: Partition table defines flash layout including SPIFFS filesystem"
116139
117140
echo ""
118141
echo "Running quick boot check scenario (15 seconds)..."

test/wokwi/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,56 @@ To add more tests:
218218
- Ensure firmware was copied: `ls -lh test/wokwi/firmware.bin`
219219
- Check firmware build logs for errors
220220

221+
### Filesystem/partition errors
222+
**Error:** `partition "spiffs" could not be found`
223+
224+
**Cause:** Missing or incorrect partition table configuration
225+
226+
**Solutions:**
227+
1. Verify bootloader.bin and partitions.bin are present:
228+
```bash
229+
ls -lh test/wokwi/bootloader.bin test/wokwi/partitions.bin
230+
```
231+
232+
2. Check that prepare-firmware.sh copied all files:
233+
```bash
234+
./test/wokwi/prepare-firmware.sh esp32_V4_wokwi_debug
235+
```
236+
237+
3. Verify partitions.bin content:
238+
```bash
239+
hexdump -C test/wokwi/partitions.bin | head -4
240+
```
241+
242+
4. Check the partition table source CSV file:
243+
```bash
244+
# The esp32_V4_wokwi_debug build uses:
245+
cat tools/WLED_ESP32_4MB_256KB_FS.csv
246+
# Should include a line with: spiffs, data, spiffs, ...
247+
```
248+
249+
5. Rebuild firmware to regenerate partition files:
250+
```bash
251+
pio run -e esp32_V4_wokwi_debug --target clean
252+
pio run -e esp32_V4_wokwi_debug
253+
```
254+
255+
6. Check wokwi.toml flash configuration:
256+
```toml
257+
[wokwi]
258+
partitions = "partitions.bin"
259+
260+
[[wokwi.flashFiles]]
261+
offset = 0x1000
262+
file = "bootloader.bin"
263+
264+
[[wokwi.flashFiles]]
265+
offset = 0x8000
266+
file = "partitions.bin"
267+
```
268+
269+
**Note:** The bootloader and partition table are essential for filesystem support. Without them, SPIFFS cannot mount and the firmware will show "partition not found" errors.
270+
221271
### Web server not accessible
222272
- Wait 30-60 seconds for the ESP32 to boot and start WiFi
223273
- Check that port 9080 is not already in use

test/wokwi/prepare-firmware.sh

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ ENV_NAME=$1
1919
BUILD_DIR="$PROJECT_ROOT/.pio/build/$ENV_NAME"
2020
FIRMWARE_BIN="$BUILD_DIR/firmware.bin"
2121
FIRMWARE_ELF="$BUILD_DIR/firmware.elf"
22+
23+
# PlatformIO stores bootloader and partitions in the build directory
24+
# but they might be in subdirectories depending on the platform version
2225
BOOTLOADER_BIN="$BUILD_DIR/bootloader.bin"
2326
PARTITIONS_BIN="$BUILD_DIR/partitions.bin"
2427

28+
# Alternative locations for bootloader (ESP-IDF v4+ might use different paths)
29+
if [ ! -f "$BOOTLOADER_BIN" ]; then
30+
ALT_BOOTLOADER="$BUILD_DIR/bootloader/bootloader.bin"
31+
if [ -f "$ALT_BOOTLOADER" ]; then
32+
BOOTLOADER_BIN="$ALT_BOOTLOADER"
33+
fi
34+
fi
35+
2536
# Check if firmware exists
2637
if [ ! -f "$FIRMWARE_BIN" ]; then
2738
echo "Error: Firmware binary not found at $FIRMWARE_BIN"
@@ -42,21 +53,57 @@ else
4253
fi
4354

4455
# Copy bootloader and partitions (required for filesystem support)
56+
MISSING_FILES=""
57+
4558
if [ -f "$BOOTLOADER_BIN" ]; then
4659
cp "$BOOTLOADER_BIN" "$WOKWI_DIR/bootloader.bin"
47-
echo "✓ Copied bootloader.bin"
60+
echo "✓ Copied bootloader.bin from $(basename $(dirname "$BOOTLOADER_BIN"))/$(basename "$BOOTLOADER_BIN")"
4861
else
49-
echo "⚠ Warning: bootloader.bin not found at $BOOTLOADER_BIN"
62+
echo "❌ ERROR: bootloader.bin not found!"
63+
echo " Checked: $BOOTLOADER_BIN"
64+
echo " Also checked: $BUILD_DIR/bootloader/bootloader.bin"
65+
MISSING_FILES="${MISSING_FILES}bootloader.bin "
66+
# List build directory contents to help debug
67+
echo " Build directory contents:"
68+
ls -la "$BUILD_DIR" | head -20
5069
fi
5170

5271
if [ -f "$PARTITIONS_BIN" ]; then
5372
cp "$PARTITIONS_BIN" "$WOKWI_DIR/partitions.bin"
5473
echo "✓ Copied partitions.bin"
74+
# Display partition table contents for verification
75+
echo " Partition table contents:"
76+
python3 -c "
77+
import sys
78+
try:
79+
with open('$WOKWI_DIR/partitions.bin', 'rb') as f:
80+
data = f.read()
81+
print(f' Size: {len(data)} bytes')
82+
print(f' First 32 bytes (hex): {data[:32].hex()}')
83+
except Exception as e:
84+
print(f' Could not read: {e}')
85+
" || true
5586
else
56-
echo "⚠ Warning: partitions.bin not found at $PARTITIONS_BIN"
87+
echo "❌ ERROR: partitions.bin not found at $PARTITIONS_BIN"
88+
MISSING_FILES="${MISSING_FILES}partitions.bin "
89+
# List build directory contents to help debug
90+
echo " Build directory contents:"
91+
ls -la "$BUILD_DIR" | head -20
92+
fi
93+
94+
if [ -n "$MISSING_FILES" ]; then
95+
echo ""
96+
echo "❌ ERROR: Missing required files: $MISSING_FILES"
97+
echo ""
98+
echo "These files are generated by PlatformIO/ESP-IDF during the build process."
99+
echo "To fix this issue:"
100+
echo "1. Ensure the build completed successfully"
101+
echo "2. Check that 'pio run -e $ENV_NAME' completed without errors"
102+
echo "3. Verify the partition table is correctly specified in platformio.ini"
103+
exit 1
57104
fi
58105

59106
echo ""
60-
echo "Firmware prepared successfully!"
107+
echo "Firmware prepared successfully!"
61108
echo "Files in $WOKWI_DIR:"
62109
ls -lh "$WOKWI_DIR"/*.bin "$WOKWI_DIR"/*.elf 2>/dev/null || true

0 commit comments

Comments
 (0)