Ext4l: Bringing Full Write Support to the Linux-Ported Filesystem

The effort to modernise U-Boot’s filesystem support continues with a major update to ext4l—the new ext4 driver ported directly from Linux. A recent series series of 30 patches that brings full write capabilities to the driver.
So far ext4l has only supported reading. With this series, the driver now supports the full lifecycle of file management, including file creation, modification, and deletion, all while using the journal for crash-safety.
What’s New?
The new series adds support for the following operations:
- File Write: You can now write files using the journal for data integrity.
- Deletion: Support for
unlinkto remove files. - Directories: Implementation of
mkdirto create new directories. - Symbolic Links: Support for
lnto create symlinks. - Renaming: Full support for renaming and moving files and directories.
Additionally, unlike the legacy ext4 driver, ext4l supports metadata_csum checksums, allowing U-Boot to interact with modern ext4 partitions without disabling features.
Adapting Linux Code for a Bootloader
Porting filesystem code from Linux to U-Boot presents unique challenges regarding resource management.
In the Linux kernel, the filesystem driver doesn’t need to meticulously free every single resource the moment a filesystem is unmounted; it can rely on the kernel’s broader memory management to clean up caches or reuse structures later.
U-Boot, however, operates differently. The bootloader might mount and unmount filesystems multiple times during a single session—for example, when running an extensive test suite or loading kernels and device trees from different partitions. If resources aren’t freed explicitly, memory leaks accumulate, eventually causing allocation failures.
To address this, this series includes significant infrastructure improvements that go beyond the Linux upstream code:
- Aggressive Cleanup: We implemented thorough cleanup of journal references and buffer heads upon unmount to prevent memory leaks.
- Safety Guards: Added safeguards to handle
probecalls without explicitclosecalls from previous sessions. - Use-After-Free Prevention: Logic was added to prevent freeing buffer heads that still have active journal heads attached.
Testing and Next Steps
This series enables ext4l for sandbox testing, allowing us to validate these features rapidly without hardware. It also includes tweaks to the video console (a new --quiet_vidconsole flag) to speed up verbose test outputs.
While ext4l is now functional and usable for read/write operations, there is still work to be done before it could perhaps replace the existing ‘ext4’ driver: enabling the driver for ARM and x86 targets, fine-tuning Kconfig options to optimise code size, and expanding the documentation.
But for now, this is a significant step toward having a robust, modern, and maintainable ext4 implementation in U-Boot!
Note: This work was brought to you with the assistance of Claude and the city of Wuhan, China.