From: Simon Glass <simon.glass@canonical.com>
The ext4 code contains many detailed error messages that consume about
20K of rodata. These messages are helpful for debugging mount failures
but not essential for normal operation.
Use CONFIG_EXT4L_DEBUG directly in ext4.h so that when debug is
disabled, the message macros (ext4_msg, ext4_error, ext4_warning, etc.)
use generic empty strings instead of detailed format strings. This
allows the compiler to eliminate the string literals from rodata.
Add a separate CONFIG_EXT4L_PRINT option to control whether messages
are printed to the console. Messages are always recorded internally
for programmatic access; this option only affects console output.
Mount failures are still reported, but without specific details about
what went wrong.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
fs/ext4l/Kconfig | 18 +++++++++++++++++-
fs/ext4l/ext4.h | 6 +++++-
fs/ext4l/ext4_uboot.h | 10 ----------
fs/ext4l/super.c | 4 ++--
4 files changed, 24 insertions(+), 14 deletions(-)
@@ -29,8 +29,24 @@ config EXT4_JOURNAL
config EXT4L_DEBUG
bool "Enable ext4l debug messages"
depends on FS_EXT4L
+ default y if SANDBOX
help
Enable debug and informational messages from the ext4l filesystem.
- This includes mount messages and other ext4_msg() output.
+ This includes mount messages, error details, and other ext4_msg()
+ output with full format strings.
+
+ Disabling this option replaces detailed error messages with generic
+ strings, saving about 20K of rodata. Mount failures will still be
+ reported but without specific details about what went wrong.
+
+ If unsure, say N.
+
+config EXT4L_PRINT
+ bool "Print ext4l messages to console"
+ depends on EXT4L_DEBUG
+ help
+ Print ext4l messages to the console in addition to recording them.
+ Messages are always recorded and can be retrieved programmatically;
+ this option controls whether they are also printed.
If unsure, say N.
@@ -3266,7 +3266,11 @@ void __ext4_grp_locked_error(const char *, unsigned int,
#define ext4_abort(sb, err, fmt, a...) \
__ext4_error((sb), __func__, __LINE__, true, (err), 0, (fmt), ## a)
-#ifdef EXT4L_PRINTF
+/*
+ * When CONFIG_EXT4L_DEBUG is enabled, pass full messages through the error
+ * macros. When disabled, use empty strings to save rodata space.
+ */
+#ifdef CONFIG_EXT4L_DEBUG
#define ext4_error_inode(inode, func, line, block, fmt, ...) \
__ext4_error_inode(inode, func, line, block, 0, fmt, ##__VA_ARGS__)
@@ -40,16 +40,6 @@
#include <linux/rbtree.h> /* Real rbtree implementation */
#include <u-boot/crc.h> /* For crc32() used by crc32_be */
-/*
- * Enable ext4_msg() and other diagnostic macros to pass full messages.
- * This is required for message recording to work. Without this, the
- * ext4_msg macro passes empty strings to __ext4_msg().
- *
- * Use EXT4L_PRINTF instead of CONFIG_PRINTK since U-Boot requires CONFIG_
- * options to be defined in Kconfig.
- */
-#define EXT4L_PRINTF 1
-
/*
* __CHAR_UNSIGNED__ - directory hash algorithm selection
*
@@ -971,8 +971,8 @@ void __ext4_msg(struct super_block *sb,
/* Record in message buffer */
ext4l_record_msg(buf, len);
- /* Also print if debug is enabled */
- if (IS_ENABLED(CONFIG_EXT4L_DEBUG))
+ /* Also print if requested */
+ if (IS_ENABLED(CONFIG_EXT4L_PRINT))
printf("%s", buf);
}