firmware icon indicating copy to clipboard operation
firmware copied to clipboard

LittleFS is full on bruce 1.16.1 MAJOUR ISSUE

Open Lucky-Mucky opened this issue 3 months ago • 3 comments

Describe the bug:

When LittleFS becomes completely full, the device gets stuck on the ERR: LittleFS is Full screen and becomes inaccessible. The device does not respond to buttons, WebUI, or serial commands.

This appears to be related to the issue described in #2298. The issue states that the fix was released in Bruce 1.16, but I am experiencing the same behavior on Bruce 1.16.1.

Steps To Reproduce:

  • Device used: M5StickC Plus SE (ESP32-PICO-D4 / hardware revision 1.1)
  • Firmware: Bruce 1.16.1
  • Upload a theme through the Bruce WebUI to LittleFS/themes/ that is large enough to fill the LittleFS partition.
  • Allow the upload to complete/fill the filesystem.
  • Reboot the device.
  • The device boots and displays ERR: LittleFS is Full.
  • Connect the device over USB and open the serial port at 115200 baud.
  • Attempt to use the serial command handler by entering help.

Expected behavior:

When LittleFS is full, Bruce should start the serial command handler before displaying the error, as described in issue #2298, allowing the user to connect over USB and delete files from LittleFS.

I would expect to be able to use the serial commands to remove the oversized theme and recover the device without reinstalling the firmware.

Actual behavior:

The device displays:

ERR: LittleFS is Full

and becomes effectively unusable.

The USB serial port is still detected by Windows as COM3, and boot logs are available at 115200 baud, but the serial command handler does not appear to start.

Entering:

help

produces no response.

The WebUI cannot be accessed because Bruce never reaches the normal interface.

The device therefore appears to require a firmware reinstall/full flash erase to recover, despite the fix described in #2298 being marked as released in Bruce 1.16.

Additional context / logs:

The issue was triggered after uploading an oversized theme to LittleFS/themes/ through the Bruce WebUI.

Serial output:

(SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:E (1109) esp_core_dump_flas`�~ No core dump partition found!
E (1109) esp_core_dump_flash: No core dump partition found!
[PSRAM] init=0 found=0 total=0 free=0 | internal free=150160 largest=110580
SDCard in a different Bus, sdcardSPI failed to mount
SDCard in a different Bus, using sdcardSPI instance
SDCARD NOT mounted, check wiring and format
Pins: SCK=0, MISO=36, MOSI=26, CS=14
ERR: LittleFS is Full

The device remains connected over USB as COM3.

Related issue: #2298 — "I found solution "LittleFS is full", fix function in code"

That issue states that the fix was released in Bruce 1.16. and yet its still here.

Lucky-Mucky avatar Aug 31 '26 15:08 Lucky-Mucky

Okay, thankfully I managed to fix it with Python.

All it does is:

  • Back up the LittleFS partition
  • Show all files and folders currently on the filesystem
  • Let you choose which files/folders you want to delete
  • Delete the selected files/folders
  • Verify that they were actually removed
  • Write only the modified LittleFS partition back to the ESP32
  • Keep the original filesystem backup untouched

It does not reflash Bruce or erase the entire device.

Libraries you need

py -m pip install esptool littlefs-python

Script

Click to expand
import os
import sys
import subprocess
from littlefs import LittleFS

PORT = "COM3"

# M5StickC Plus SE / Bruce partition layout
FILESYSTEM_OFFSET = 0x3D0000
FILESYSTEM_SIZE = 0x30000
BLOCK_SIZE = 4096

BACKUP_IMAGE = "filesystem-backup.bin"
MODIFIED_IMAGE = "filesystem-modified.bin"
PARTITION_BACKUP = "partition-table.bin"


def run_command(command):
    print()
    print("> " + " ".join(command))
    print()

    result = subprocess.run(command)

    if result.returncode != 0:
        print()
        print("Command failed.")
        sys.exit(result.returncode)

    return result


def is_directory(fs, path):
    try:
        fs.listdir(path)
        return True
    except Exception:
        return False


def file_size(fs, path):
    try:
        stat = fs.stat(path)

        # littlefs-python exposes the file size as st_size
        if hasattr(stat, "st_size"):
            return stat.st_size

        # Some versions may return a tuple-like object
        if hasattr(stat, "size"):
            return stat.size

    except Exception:
        pass

    return 0


def directory_size(fs, path):
    total = 0

    try:
        for name in fs.listdir(path):
            full_path = path.rstrip("/") + "/" + name

            if is_directory(fs, full_path):
                total += directory_size(fs, full_path)
            else:
                total += file_size(fs, full_path)

    except Exception:
        pass

    return total


def format_size(size):
    if size < 1024:
        return f"{size} B"

    if size < 1024 * 1024:
        return f"{size / 1024:.2f} KB"

    return f"{size / (1024 * 1024):.2f} MB"


def collect_entries(fs, path="/"):
    entries = []

    try:
        children = fs.listdir(path)
    except Exception:
        return entries

    for name in children:

        if path == "/":
            full_path = "/" + name
        else:
            full_path = path.rstrip("/") + "/" + name

        directory = is_directory(fs, full_path)

        if directory:
            size = directory_size(fs, full_path)
        else:
            size = file_size(fs, full_path)

        entries.append(
            (full_path, directory, size)
        )

        if directory:
            entries.extend(
                collect_entries(fs, full_path)
            )

    return entries


def delete_directory(fs, path):

    for name in fs.listdir(path):

        full_path = path.rstrip("/") + "/" + name

        if is_directory(fs, full_path):

            delete_directory(fs, full_path)
            fs.rmdir(full_path)

        else:

            fs.remove(full_path)


def delete_path(fs, path):

    if is_directory(fs, path):

        delete_directory(fs, path)
        fs.rmdir(path)

    else:

        fs.remove(path)


def mount_image(image):

    fs = LittleFS(
        block_size=BLOCK_SIZE,
        block_count=len(image) // BLOCK_SIZE,
        mount=False
    )

    fs.context.buffer = image

    result = fs.mount()

    if result != 0:
        raise RuntimeError(
            f"LittleFS mount failed with error {result}"
        )

    return fs


print("=" * 70)
print("Bruce LittleFS Recovery Tool")
print("=" * 70)
print()

print("This tool backs up the LittleFS partition and lets you")
print("delete files or folders from it without reflashing Bruce.")
print()

print(f"Port:              {PORT}")
print(f"Filesystem offset: 0x{FILESYSTEM_OFFSET:06X}")
print(f"Filesystem size:   {FILESYSTEM_SIZE // 1024} KiB")
print()

print("Bruce firmware will NOT be erased.")
print()


# ------------------------------------------------------------
# Check esptool
# ------------------------------------------------------------

try:

    result = subprocess.run(
        [
            sys.executable,
            "-m",
            "esptool",
            "version"
        ],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL
    )

    if result.returncode != 0:
        raise RuntimeError

except Exception:

    print("esptool is not installed.")
    print()
    print("Install it with:")
    print()
    print("    py -m pip install esptool")
    print()

    sys.exit(1)


# ------------------------------------------------------------
# Back up partition table
# ------------------------------------------------------------

print("=" * 70)
print("Backing up partition table")
print("=" * 70)

run_command([
    sys.executable,
    "-m",
    "esptool",
    "--chip",
    "esp32",
    "--port",
    PORT,
    "read-flash",
    "0x8000",
    "0x1000",
    PARTITION_BACKUP
])


# ------------------------------------------------------------
# Back up filesystem
# ------------------------------------------------------------

print()
print("=" * 70)
print("Backing up LittleFS")
print("=" * 70)

run_command([
    sys.executable,
    "-m",
    "esptool",
    "--chip",
    "esp32",
    "--port",
    PORT,
    "read-flash",
    hex(FILESYSTEM_OFFSET),
    hex(FILESYSTEM_SIZE),
    BACKUP_IMAGE
])


if not os.path.isfile(BACKUP_IMAGE):

    print("Filesystem backup was not created.")
    sys.exit(1)


backup_size = os.path.getsize(
    BACKUP_IMAGE
)

if backup_size != FILESYSTEM_SIZE:

    print("Filesystem backup has the wrong size.")
    print(f"Expected: {FILESYSTEM_SIZE}")
    print(f"Got:      {backup_size}")

    sys.exit(1)


print()
print(f"Backup created: {BACKUP_IMAGE}")
print(f"Backup size:    {format_size(backup_size)}")


# ------------------------------------------------------------
# Load filesystem
# ------------------------------------------------------------

print()
print("=" * 70)
print("Mounting LittleFS")
print("=" * 70)

with open(BACKUP_IMAGE, "rb") as f:

    original_image = bytearray(
        f.read()
    )


modified_image = bytearray(
    original_image
)


try:

    fs = mount_image(
        modified_image
    )

except Exception as e:

    print()
    print("Could not mount the LittleFS backup.")
    print()
    print(e)
    print()
    print("Nothing has been written to the ESP32.")

    sys.exit(1)


print()
print("LittleFS mounted successfully.")


# ------------------------------------------------------------
# Show files
# ------------------------------------------------------------

entries = collect_entries(fs)

if not entries:

    print()
    print("The filesystem is empty.")

    fs.unmount()

    sys.exit(0)


print()
print("=" * 70)
print("Filesystem contents")
print("=" * 70)
print()

print(
    f"{'#':>3}  {'Type':<6} {'Size':>12}  Path"
)

print("-" * 70)


for index, (path, directory, size) in enumerate(
    entries,
    start=1
):

    if directory:
        item_type = "DIR"
    else:
        item_type = "FILE"

    print(
        f"{index:3}  "
        f"{item_type:<6} "
        f"{format_size(size):>12}  "
        f"{path}"
    )


# ------------------------------------------------------------
# Select files
# ------------------------------------------------------------

print()
print("=" * 70)
print("Select items to delete")
print("=" * 70)
print()

print("Enter the numbers you want to delete.")
print("Multiple numbers can be separated with spaces or commas.")
print()
print("Examples:")
print("  5")
print("  2 5 9")
print("  2,5,9")
print()
print("Enter 0 to cancel.")
print()

selection = input(
    "Selection: "
).strip()


if selection == "0" or not selection:

    print()
    print("Cancelled.")

    fs.unmount()

    sys.exit(0)


selection = selection.replace(
    ",",
    " "
)

selected_indices = []


for value in selection.split():

    try:

        number = int(value)

    except ValueError:

        print()
        print(
            f"Invalid selection: {value}"
        )

        fs.unmount()

        sys.exit(1)


    if number < 1 or number > len(entries):

        print()
        print(
            f"Invalid selection: {number}"
        )

        fs.unmount()

        sys.exit(1)


    if number not in selected_indices:

        selected_indices.append(number)


selected_paths = [
    entries[number - 1]
    for number in selected_indices
]


# ------------------------------------------------------------
# Show selected items
# ------------------------------------------------------------

print()
print("=" * 70)
print("Selected for deletion")
print("=" * 70)
print()

total_selected_size = 0


for path, directory, size in selected_paths:

    if directory:

        print(
            f"[DIR]  {format_size(size):>12}  {path}"
        )

    else:

        print(
            f"[FILE] {format_size(size):>12}  {path}"
        )

    total_selected_size += size


print()
print(
    f"Total selected size: {format_size(total_selected_size)}"
)

print()
print(
    "Deleting a directory also deletes everything inside it."
)

print()


confirm = input(
    "Continue? [y/N]: "
).strip().lower()


if confirm != "y":

    print()
    print("Cancelled.")

    fs.unmount()

    sys.exit(0)


# ------------------------------------------------------------
# Delete selected items
# ------------------------------------------------------------

print()
print("=" * 70)
print("Deleting")
print("=" * 70)
print()


# Delete deeper paths first in case the user selected
# both a directory and something inside it.

selected_paths.sort(
    key=lambda item: item[0].count("/"),
    reverse=True
)


deleted = set()


for path, directory, size in selected_paths:

    already_deleted = False


    for deleted_path in deleted:

        if (
            path == deleted_path
            or path.startswith(
                deleted_path.rstrip("/") + "/"
            )
        ):

            already_deleted = True
            break


    if already_deleted:

        continue


    try:

        delete_path(
            fs,
            path
        )

        deleted.add(path)

        print(
            f"Deleted: {path} "
            f"({format_size(size)})"
        )

    except Exception as e:

        print()
        print(
            f"Failed to delete {path}: {e}"
        )

        fs.unmount()

        sys.exit(1)


# ------------------------------------------------------------
# Verify deletion
# ------------------------------------------------------------

print()
print("Verifying deletions...")
print()


for path, directory, size in selected_paths:

    try:

        if is_directory(
            fs,
            path
        ):

            print(
                f"ERROR: {path} still exists."
            )

            fs.unmount()

            sys.exit(1)


        fs.stat(path)

        print(
            f"ERROR: {path} still exists."
        )

        fs.unmount()

        sys.exit(1)


    except Exception:

        print(
            f"OK: {path} removed"
        )


# ------------------------------------------------------------
# Show remaining filesystem
# ------------------------------------------------------------

print()
print("=" * 70)
print("Remaining files")
print("=" * 70)
print()

remaining_entries = collect_entries(fs)


print(
    f"{'Type':<6} {'Size':>12}  Path"
)

print("-" * 70)


for path, directory, size in remaining_entries:

    if directory:
        item_type = "DIR"
    else:
        item_type = "FILE"

    print(
        f"{item_type:<6} "
        f"{format_size(size):>12}  "
        f"{path}"
    )


# ------------------------------------------------------------
# Unmount
# ------------------------------------------------------------

print()
print("Unmounting filesystem...")

try:

    fs.unmount()

except Exception as e:

    print()
    print("Failed to unmount filesystem.")
    print(e)

    sys.exit(1)


print("Unmount successful.")


# ------------------------------------------------------------
# Save modified image
# ------------------------------------------------------------

print()
print("=" * 70)
print("Creating modified filesystem image")
print("=" * 70)

with open(
    MODIFIED_IMAGE,
    "wb"
) as f:

    f.write(
        modified_image
    )


modified_size = os.path.getsize(
    MODIFIED_IMAGE
)


if modified_size != FILESYSTEM_SIZE:

    print()
    print("Modified filesystem has the wrong size.")

    sys.exit(1)


print()
print(
    f"Created: {MODIFIED_IMAGE}"
)

print(
    f"Size:    {format_size(modified_size)}"
)


# ------------------------------------------------------------
# Final verification
# ------------------------------------------------------------

print()
print("=" * 70)
print("Testing modified filesystem")
print("=" * 70)

with open(
    MODIFIED_IMAGE,
    "rb"
) as f:

    verification_image = bytearray(
        f.read()
    )


try:

    verify_fs = mount_image(
        verification_image
    )

except Exception as e:

    print()
    print(
        "Modified filesystem could not be mounted."
    )

    print(e)

    print()
    print(
        "Nothing has been written to the ESP32."
    )

    sys.exit(1)


for path, directory, size in selected_paths:

    try:

        if is_directory(
            verify_fs,
            path
        ):

            raise RuntimeError


        verify_fs.stat(path)

        print()
        print(
            f"ERROR: {path} still exists."
        )

        verify_fs.unmount()

        sys.exit(1)

    except Exception:

        pass


verify_fs.unmount()


print()
print("Modified filesystem looks good.")


# ------------------------------------------------------------
# Final confirmation
# ------------------------------------------------------------

print()
print("=" * 70)
print("READY TO WRITE TO ESP32")
print("=" * 70)
print()

print(
    f"Filesystem: 0x{FILESYSTEM_OFFSET:06X}"
)

print(
    f"Size:       {FILESYSTEM_SIZE // 1024} KiB"
)

print()

print(
    "Only the LittleFS partition will be written."
)

print(
    "Bruce firmware will NOT be reflashed."
)

print()

print("Original backup:")
print(
    f"  {os.path.abspath(BACKUP_IMAGE)}"
)

print()

print("Modified filesystem:")
print(
    f"  {os.path.abspath(MODIFIED_IMAGE)}"
)

print()

print("Files/directories being removed:")

for path, directory, size in selected_paths:

    print(
        f"  {format_size(size):>12}  {path}"
    )

print()

confirm = input(
    "Write the modified filesystem to the ESP32? [y/N]: "
).strip().lower()


if confirm != "y":

    print()
    print("Cancelled.")
    print()
    print("Nothing was written to the ESP32.")

    sys.exit(0)


# ------------------------------------------------------------
# Write ONLY filesystem partition
# ------------------------------------------------------------

print()
print("=" * 70)
print("Writing LittleFS partition")
print("=" * 70)
print()

print("DO NOT disconnect the device.")
print()

run_command([
    sys.executable,
    "-m",
    "esptool",
    "--chip",
    "esp32",
    "--port",
    PORT,
    "write-flash",
    hex(FILESYSTEM_OFFSET),
    MODIFIED_IMAGE
])


# ------------------------------------------------------------
# Done
# ------------------------------------------------------------

print()
print("=" * 70)
print("RECOVERY COMPLETE")
print("=" * 70)
print()

print("Selected files/folders have been removed.")
print()
print("Only the LittleFS partition was modified.")
print("Bruce firmware was NOT reflashed.")
print()
print(
    "Original backup:"
)
print(
    f"  {os.path.abspath(BACKUP_IMAGE)}"
)
print()
print("The device should now boot normally.")

Lucky-Mucky avatar Aug 31 '26 16:08 Lucky-Mucky

This issue has been automatically marked as stale due to inactivity. It will be closed in 5 days unless there is further activity.

github-actions[bot] avatar Sep 11 '26 03:09 github-actions[bot]

Closing due to prolonged inactivity. If this is still relevant, please comment or open a new issue with updated details.

github-actions[bot] avatar Sep 16 '26 03:09 github-actions[bot]