mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] filetype: Some size reduction patches
@ 2025-03-18 14:41 Sascha Hauer
  2025-03-18 14:41 ` [PATCH 1/7] filetype: add file_detect_compression_type() Sascha Hauer
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

The am335x_mlo_defconfig is very size constrained and doesn't build
within these constraint anymore for some time. The filetype detection
code has become quite big and offers some opportunities for size
reduction. Specifically file_detect_type() is quite big, but many
callers are only interested in some specific file types like supported
file systems or supported compressed binary formats. This series
introduces some more specific smaller file detection functions so that
we can get rid of the big file_detect_type() in the binary.

Also included some patches for the myirtech-mid board to use a stripped
down device tree for the MLO. The same is already done for the other
boards supported in am335x_mlo_defconfig

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Sascha Hauer (7):
      filetype: add file_detect_compression_type()
      filetype: add file_detect_fs_type()
      filetype: add function pointer to file_name_detect_type_offset()
      filetype: let cdev_detect_type() only detect filesystems
      filetype: make file type strings optional
      ARM: am33xx: myirtech-myd: add MLO specific device tree
      ARM: am335x_mlo_defconfig: disable file type strings

 arch/arm/boards/myirtech-x335x/lowlevel.c |   6 +-
 arch/arm/configs/am335x_mlo_defconfig     |   1 +
 arch/arm/dts/Makefile                     |   2 +-
 arch/arm/dts/am335x-myirtech-myd-mlo.dts  |  10 +++
 common/Kconfig                            |   8 ++
 common/filetype.c                         | 132 +++++++++++++++++++++---------
 fs/fs.c                                   |   3 +-
 include/filetype.h                        |   5 +-
 lib/uncompress.c                          |   4 +-
 9 files changed, 125 insertions(+), 46 deletions(-)
---
base-commit: a0ba27e06535570e8e4653f5f92a607f8b99022e
change-id: 20250318-filetype-size-reduction-0cbf74281e2e

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/7] filetype: add file_detect_compression_type()
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:41 ` [PATCH 2/7] filetype: add file_detect_fs_type() Sascha Hauer
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

Add file_detect_compression_type() and use that in the uncompression
code which is only interested if the file is one of the supported
compression formats.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c  | 48 ++++++++++++++++++++++++++++++++----------------
 include/filetype.h |  1 +
 lib/uncompress.c   |  4 ++--
 3 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 73ea17e19b..9916b63b80 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -261,6 +261,34 @@ static bool is_dos_exe(const u8 *buf8)
 
 #define CH_TOC_section_name     0x14
 
+enum filetype file_detect_compression_type(const void *_buf, size_t bufsize)
+{
+	const u32 *buf = _buf;
+	const u8 *buf8 = _buf;
+
+	if (bufsize < 16)
+		return filetype_unknown;
+
+	if (buf8[0] == 0x89 && buf8[1] == 0x4c && buf8[2] == 0x5a &&
+			buf8[3] == 0x4f)
+		return filetype_lzo_compressed;
+	if (buf8[0] == 0x02 && buf8[1] == 0x21 && buf8[2] == 0x4c &&
+			buf8[3] == 0x18)
+		return filetype_lz4_compressed;
+	if (buf8[0] == 0x1f && buf8[1] == 0x8b && buf8[2] == 0x08)
+		return filetype_gzip;
+	if (buf8[0] == 'B' && buf8[1] == 'Z' && buf8[2] == 'h' &&
+			buf8[3] > '0' && buf8[3] <= '9')
+                return filetype_bzip2;
+	if (buf8[0] == 0xfd && buf8[1] == 0x37 && buf8[2] == 0x7a &&
+			buf8[3] == 0x58 && buf8[4] == 0x5a && buf8[5] == 0x00)
+		return filetype_xz_compressed;
+	if (le32_to_cpu(buf[0]) == le32_to_cpu(ZSTD_MAGICNUMBER))
+		return filetype_zstd_compressed;
+
+	return filetype_unknown;
+}
+
 enum filetype file_detect_type(const void *_buf, size_t bufsize)
 {
 	const u32 *buf = _buf;
@@ -278,17 +306,15 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (buf[0] == ENVFS_32(ENVFS_MAGIC))
 		return filetype_barebox_env;
 
+	type = file_detect_compression_type(_buf, bufsize);
+	if (type != filetype_unknown)
+		return type;
+
 	if (bufsize < 32)
 		return filetype_unknown;
 
 	if (strncmp(buf8, "BM", 2) == 0)
 		return filetype_bmp;
-	if (buf8[0] == 0x89 && buf8[1] == 0x4c && buf8[2] == 0x5a &&
-			buf8[3] == 0x4f)
-		return filetype_lzo_compressed;
-	if (buf8[0] == 0x02 && buf8[1] == 0x21 && buf8[2] == 0x4c &&
-			buf8[3] == 0x18)
-		return filetype_lz4_compressed;
 	if (buf[0] == be32_to_cpu(0x27051956))
 		return filetype_uimage;
 	if (buf[0] == 0x23494255)
@@ -297,14 +323,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_ubifs;
 	if (buf[0] == 0x20031985)
 		return filetype_jffs2;
-	if (buf8[0] == 0x1f && buf8[1] == 0x8b && buf8[2] == 0x08)
-		return filetype_gzip;
-	if (buf8[0] == 'B' && buf8[1] == 'Z' && buf8[2] == 'h' &&
-			buf8[3] > '0' && buf8[3] <= '9')
-                return filetype_bzip2;
-	if (buf8[0] == 0xfd && buf8[1] == 0x37 && buf8[2] == 0x7a &&
-			buf8[3] == 0x58 && buf8[4] == 0x5a && buf8[5] == 0x00)
-		return filetype_xz_compressed;
 	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
 			buf8[3] == 's')
 		return filetype_squashfs;
@@ -325,8 +343,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_rockchip_rkns_image;
 	if (le32_to_cpu(buf[0]) == le32_to_cpu(0xaa640001))
 		return filetype_fip;
-	if (le32_to_cpu(buf[0]) == le32_to_cpu(ZSTD_MAGICNUMBER))
-		return filetype_zstd_compressed;
 
 	if ((buf8[0] == 0x5a || buf8[0] == 0x69 || buf8[0] == 0x78 ||
 	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
diff --git a/include/filetype.h b/include/filetype.h
index c24d061e8f..b8c0105bf2 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -74,6 +74,7 @@ struct cdev;
 const char *file_type_to_string(enum filetype f);
 const char *file_type_to_short_string(enum filetype f);
 enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
+enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
 int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
diff --git a/lib/uncompress.c b/lib/uncompress.c
index 0aaeb066b6..c284bcc6ba 100644
--- a/lib/uncompress.c
+++ b/lib/uncompress.c
@@ -79,7 +79,7 @@ int uncompress(unsigned char *inbuf, long len,
 	char *err;
 
 	if (inbuf) {
-		ft = file_detect_type(inbuf, len);
+		ft = file_detect_compression_type(inbuf, len);
 		uncompress_buf = NULL;
 		uncompress_size = 0;
 	} else {
@@ -94,7 +94,7 @@ int uncompress(unsigned char *inbuf, long len,
 		if (ret < 0)
 			goto err;
 
-		ft = file_detect_type(uncompress_buf, 32);
+		ft = file_detect_compression_type(uncompress_buf, 32);
 	}
 
 	pr_debug("Filetype detected: %s\n", file_type_to_string(ft));

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/7] filetype: add file_detect_fs_type()
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
  2025-03-18 14:41 ` [PATCH 1/7] filetype: add file_detect_compression_type() Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:51   ` Ahmad Fatoum
  2025-03-18 14:41 ` [PATCH 3/7] filetype: add function pointer to file_name_detect_type_offset() Sascha Hauer
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

add file_detect_fs_type() which only tests if the buffer contains one of
the supported filesystems without testing for other binary formats.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c  | 59 ++++++++++++++++++++++++++++++++++++------------------
 include/filetype.h |  1 +
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 9916b63b80..2a55d5f4ea 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -198,29 +198,39 @@ int is_fat_boot_sector(const void *sect)
 	return 0;
 }
 
-enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
+static enum filetype file_detect_fs_fat(const void *_buf, size_t bufsize)
 {
-	/*
-	 * bootsec can be used to return index of the first sector in the
-	 * first partition
-	 */
-	if (bootsec)
-		*bootsec = 0;
+	const u8 *buf8 = _buf;
 
 	/*
 	 * Check record signature (always placed at offset 510 even if the
 	 * sector size is > 512)
 	 */
-	if (get_unaligned_le16(&sector[BS_55AA]) != 0xAA55)
+	if (get_unaligned_le16(&buf8[BS_55AA]) != 0xAA55)
 		return filetype_unknown;
 
 	/* Check "FAT" string */
-	if ((get_unaligned_le32(&sector[BS_FilSysType]) & 0xFFFFFF) == 0x544146)
+	if ((get_unaligned_le32(&buf8[BS_FilSysType]) & 0xFFFFFF) == 0x544146)
 		return filetype_fat;
 
-	if ((get_unaligned_le32(&sector[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
+	if ((get_unaligned_le32(&buf8[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
 		return filetype_fat;
 
+	return filetype_unknown;
+}
+
+enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
+{
+	/*
+	 * bootsec can be used to return index of the first sector in the
+	 * first partition
+	 */
+	if (bootsec)
+		*bootsec = 0;
+
+	if (file_detect_fs_fat(sector, 512) != filetype_fat)
+		return filetype_unknown;
+
 	if (bootsec)
 		/*
 		 * This must be an MBR, so return the starting sector of the
@@ -289,12 +299,31 @@ enum filetype file_detect_compression_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
+enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)
+{
+	const u32 *buf = _buf;
+	const u16 *buf16 = _buf;
+	const u8 *buf8 = _buf;
+
+	if (bufsize < 16)
+		return filetype_unknown;
+
+	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
+			buf8[3] == 's')
+		return filetype_squashfs;
+	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
+		return filetype_ext;
+	if (buf[0] == le32_to_cpu(0x06101831))
+		return filetype_ubifs;
+
+	return file_detect_fs_fat(_buf, bufsize);
+}
+
 enum filetype file_detect_type(const void *_buf, size_t bufsize)
 {
 	const u32 *buf = _buf;
 	const u64 *buf64 = _buf;
 	const u8 *buf8 = _buf;
-	const u16 *buf16 = _buf;
 	const struct imx_flash_header *imx_flash_header = _buf;
 	enum filetype type;
 
@@ -319,13 +348,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_uimage;
 	if (buf[0] == 0x23494255)
 		return filetype_ubi;
-	if (buf[0] == le32_to_cpu(0x06101831))
-		return filetype_ubifs;
 	if (buf[0] == 0x20031985)
 		return filetype_jffs2;
-	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
-			buf8[3] == 's')
-		return filetype_squashfs;
 	if (buf[0] == be32_to_cpu(0xd00dfeed))
 		return filetype_oftree;
 	if (strncmp(buf8, "ANDROID!", 8) == 0)
@@ -423,9 +447,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (type != filetype_unknown)
 		return type;
 
-	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
-		return filetype_ext;
-
 	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
 		return filetype_ch_image;
 
diff --git a/include/filetype.h b/include/filetype.h
index b8c0105bf2..329ebc9e8b 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -75,6 +75,7 @@ const char *file_type_to_string(enum filetype f);
 const char *file_type_to_short_string(enum filetype f);
 enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
 enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
+enum filetype file_detect_fs_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
 int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/7] filetype: add function pointer to file_name_detect_type_offset()
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
  2025-03-18 14:41 ` [PATCH 1/7] filetype: add file_detect_compression_type() Sascha Hauer
  2025-03-18 14:41 ` [PATCH 2/7] filetype: add file_detect_fs_type() Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:41 ` [PATCH 4/7] filetype: let cdev_detect_type() only detect filesystems Sascha Hauer
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

file_name_detect_type_offset() calls file_detect_type() which is quite
a big function. Add a function pointer argument so the caller can
decide which file detection function shall be called. This allows
callers to depend on a function with a smaller binary size impact.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c  | 8 +++++---
 fs/fs.c            | 3 ++-
 include/filetype.h | 3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 2a55d5f4ea..1e2d4ed0e3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -476,7 +476,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
-int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type)
+int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize))
 {
 	int fd, ret;
 	void *buf;
@@ -491,7 +492,7 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 	if (ret < 0)
 		goto err_out;
 
-	*type = file_detect_type(buf, ret);
+	*type = detect(buf, ret);
 
 	ret = 0;
 err_out:
@@ -503,7 +504,8 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 
 int file_name_detect_type(const char *filename, enum filetype *type)
 {
-	return file_name_detect_type_offset(filename, 0, type);
+	return file_name_detect_type_offset(filename, 0, type,
+					    file_detect_type);
 }
 
 int cdev_detect_type(struct cdev *cdev, enum filetype *type)
diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341e..9924709424 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -903,7 +903,8 @@ const char *fs_detect(const char *filename, const char *fsoptions)
 	parseopt_llu_suffix(fsoptions, "offset", &offset);
 
 	if (loop) {
-		ret = file_name_detect_type_offset(filename, offset, &type);
+		ret = file_name_detect_type_offset(filename, offset, &type,
+						   file_detect_fs_type);
 	} else {
 		struct cdev *cdev = cdev_open_by_name(filename, O_RDONLY);
 		if (cdev) {
diff --git a/include/filetype.h b/include/filetype.h
index 329ebc9e8b..03d1f1595d 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -78,7 +78,8 @@ enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_fs_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
-int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
+int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize));
 int cdev_detect_type(struct cdev *cdev, enum filetype *type);
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
 int is_fat_boot_sector(const void *_buf);

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/7] filetype: let cdev_detect_type() only detect filesystems
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2025-03-18 14:41 ` [PATCH 3/7] filetype: add function pointer to file_name_detect_type_offset() Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:41 ` [PATCH 5/7] filetype: make file type strings optional Sascha Hauer
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

cdev_detect_type() is only used by the fs code to determine the
filesystem type on a cdev, so it only needs to be able to detect
filesystems and no other types. Call file_detect_fs_type() instead
for smaller binary size.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/filetype.c b/common/filetype.c
index 1e2d4ed0e3..b8d65dfb9f 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -523,7 +523,7 @@ int cdev_detect_type(struct cdev *cdev, enum filetype *type)
 	if (ret < 0)
 		goto err_out;
 
-	*type = file_detect_type(buf, ret);
+	*type = file_detect_fs_type(buf, ret);
 	ret = 0;
 
 err_out:

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/7] filetype: make file type strings optional
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2025-03-18 14:41 ` [PATCH 4/7] filetype: let cdev_detect_type() only detect filesystems Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:41 ` [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree Sascha Hauer
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

This adds a new Kconfig option FILETYPE_STRING which makes
printing file types as strings optional. The filetype_str[]
array has become quite big and with this we can get rid of
it in size constraint barebox images. Make it default y to
keep the existing default.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig    |  8 ++++++++
 common/filetype.c | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index 12026b8232..c57669bb61 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1332,6 +1332,14 @@ config PBL_OPTEE
 	  Allows starting OP-TEE during lowlevel initialization of the PBL.
 	  Requires explicit support in the board's lowlevel file.
 
+config FILETYPE_STRING
+	bool "Print file types as strings"
+	default y
+	depends on FILETYPE
+	help
+	  Say yes here to include strings for filetypes in barebox. If disabled file
+	  types will be printed as numbers only.
+
 endmenu
 
 if FASTBOOT_BASE
diff --git a/common/filetype.c b/common/filetype.c
index b8d65dfb9f..ce868223d5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -85,8 +85,20 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_zstd_compressed] = { "ZSTD compressed", "zstd" },
 };
 
+static const char *file_type_to_nr_string(enum filetype f)
+{
+	static char str[sizeof("4294967295")];
+
+	sprintf(str, "%u", (unsigned int)f);
+
+	return str;
+}
+
 const char *file_type_to_string(enum filetype f)
 {
+	if (!IS_ENABLED(CONFIG_FILETYPE_STRINGS))
+		return file_type_to_nr_string(f);
+
 	if (f < ARRAY_SIZE(filetype_str))
 		return filetype_str[f].name;
 
@@ -95,6 +107,9 @@ const char *file_type_to_string(enum filetype f)
 
 const char *file_type_to_short_string(enum filetype f)
 {
+	if (!IS_ENABLED(CONFIG_FILETYPE_STRINGS))
+		return file_type_to_nr_string(f);
+
 	if (f < ARRAY_SIZE(filetype_str))
 		return filetype_str[f].shortname;
 

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2025-03-18 14:41 ` [PATCH 5/7] filetype: make file type strings optional Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 14:41 ` [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings Sascha Hauer
  2025-03-18 15:01 ` [PATCH 0/7] filetype: Some size reduction patches Alexander Shiyan
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

Use a stripped down device tree for the MLO to decrease the binary size.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/myirtech-x335x/lowlevel.c |  6 ++++--
 arch/arm/dts/Makefile                     |  2 +-
 arch/arm/dts/am335x-myirtech-myd-mlo.dts  | 10 ++++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/myirtech-x335x/lowlevel.c b/arch/arm/boards/myirtech-x335x/lowlevel.c
index c7b36b0173..05c858ad86 100644
--- a/arch/arm/boards/myirtech-x335x/lowlevel.c
+++ b/arch/arm/boards/myirtech-x335x/lowlevel.c
@@ -54,7 +54,7 @@ static struct am33xx_emif_regs ddr3_regs = {
 	.sdram_ref_ctrl		= 0xc30,
 };
 
-extern char __dtb_z_am335x_myirtech_myd_start[];
+extern char __dtb_z_am335x_myirtech_myd_mlo_start[];
 
 ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 {
@@ -68,7 +68,7 @@ ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	fdt = __dtb_z_am335x_myirtech_myd_start;
+	fdt = __dtb_z_am335x_myirtech_myd_mlo_start;
 
 	omap_watchdog_disable(IOMEM(AM33XX_WDT_BASE));
 
@@ -99,6 +99,8 @@ ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 	am335x_barebox_entry(fdt);
 }
 
+extern char __dtb_z_am335x_myirtech_myd_start[];
+
 ENTRY_FUNCTION(start_am33xx_myirtech_sdram, r0, r1, r2)
 {
 	void *fdt;
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d346285852..2d90738748 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -44,7 +44,7 @@ lwl-$(CONFIG_MACH_LENOVO_IX4_300D) += armada-xp-lenovo-ix4-300d-bb.dtb.o
 lwl-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP) += armada-xp-gp-bb.dtb.o
 lwl-$(CONFIG_MACH_MARVELL_ARMADA_XP_DB) += armada-xp-db-bb.dtb.o
 lwl-$(CONFIG_MACH_MX28EVK) += imx28-evk.dtb.o
-lwl-$(CONFIG_MACH_MYIRTECH_X335X) += am335x-myirtech-myd.dtb.o
+lwl-$(CONFIG_MACH_MYIRTECH_X335X) += am335x-myirtech-myd.dtb.o am335x-myirtech-myd-mlo.dtb.o
 lwl-$(CONFIG_MACH_NETGEAR_RN104) += armada-370-rn104-bb.dtb.o
 lwl-$(CONFIG_MACH_NETGEAR_RN2120) += armada-xp-rn2120-bb.dtb.o
 lwl-$(CONFIG_MACH_NITROGEN6) += imx6q-nitrogen6x.dtb.o imx6dl-nitrogen6x.dtb.o imx6qp-nitrogen6_max.dtb.o
diff --git a/arch/arm/dts/am335x-myirtech-myd-mlo.dts b/arch/arm/dts/am335x-myirtech-myd-mlo.dts
new file mode 100644
index 0000000000..20c3298073
--- /dev/null
+++ b/arch/arm/dts/am335x-myirtech-myd-mlo.dts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* SPDX-FileCopyrightText: Alexander Shiyan, <shc_work@mail.ru> */
+
+/dts-v1/;
+
+#include "am335x-myirtech-myd.dts"
+#include "am33xx-strip.dtsi"
+#include "am33xx-clocks-strip.dtsi"
+
+/delete-node/ &{/sound};

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2025-03-18 14:41 ` [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree Sascha Hauer
@ 2025-03-18 14:41 ` Sascha Hauer
  2025-03-18 15:01 ` [PATCH 0/7] filetype: Some size reduction patches Alexander Shiyan
  7 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 14:41 UTC (permalink / raw)
  To: open list:BAREBOX

The am335x_mlo_defconfig is very size constrained. Remove support for
printing file types as strings to reduce the binary size a bit.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/configs/am335x_mlo_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/am335x_mlo_defconfig b/arch/arm/configs/am335x_mlo_defconfig
index 91d0eb4a8d..4a9ce6cfb7 100644
--- a/arch/arm/configs/am335x_mlo_defconfig
+++ b/arch/arm/configs/am335x_mlo_defconfig
@@ -19,6 +19,7 @@ CONFIG_SHELL_NONE=y
 # CONFIG_TIMESTAMP is not set
 CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_OFDEVICE=y
+# CONFIG_FILETYPE_STRING is not set
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/7] filetype: add file_detect_fs_type()
  2025-03-18 14:41 ` [PATCH 2/7] filetype: add file_detect_fs_type() Sascha Hauer
@ 2025-03-18 14:51   ` Ahmad Fatoum
  2025-03-18 15:06     ` Sascha Hauer
  0 siblings, 1 reply; 11+ messages in thread
From: Ahmad Fatoum @ 2025-03-18 14:51 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX

Hi,

On 3/18/25 15:41, Sascha Hauer wrote:
> add file_detect_fs_type() which only tests if the buffer contains one of
> the supported filesystems without testing for other binary formats.


> +enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)

[snip]

>  enum filetype file_detect_type(const void *_buf, size_t bufsize)
> -	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
> -		return filetype_ext;
> -
>  	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
>  		return filetype_ch_image

Shouldn't file_detec_type() still call file_detect_fs_type()?

Thanks,
Ahmad



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] filetype: Some size reduction patches
  2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2025-03-18 14:41 ` [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings Sascha Hauer
@ 2025-03-18 15:01 ` Alexander Shiyan
  7 siblings, 0 replies; 11+ messages in thread
From: Alexander Shiyan @ 2025-03-18 15:01 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: open list:BAREBOX

Hello Sascha!

I've been using a separate config for this board for a long time :)
Maybe you can take something from my working configuration that
has been working for several years:
https://github.com/shcgit/barebox/blob/milas/arch/arm/configs/mm_am335x_mlo_defconfig

Thanks!

вт, 18 мар. 2025 г. в 17:46, Sascha Hauer <s.hauer@pengutronix.de>:
>
> The am335x_mlo_defconfig is very size constrained and doesn't build
> within these constraint anymore for some time. The filetype detection
> code has become quite big and offers some opportunities for size
> reduction. Specifically file_detect_type() is quite big, but many
> callers are only interested in some specific file types like supported
> file systems or supported compressed binary formats. This series
> introduces some more specific smaller file detection functions so that
> we can get rid of the big file_detect_type() in the binary.
>
> Also included some patches for the myirtech-mid board to use a stripped
> down device tree for the MLO. The same is already done for the other
> boards supported in am335x_mlo_defconfig
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> Sascha Hauer (7):
>       filetype: add file_detect_compression_type()
>       filetype: add file_detect_fs_type()
>       filetype: add function pointer to file_name_detect_type_offset()
>       filetype: let cdev_detect_type() only detect filesystems
>       filetype: make file type strings optional
>       ARM: am33xx: myirtech-myd: add MLO specific device tree
>       ARM: am335x_mlo_defconfig: disable file type strings
>
>  arch/arm/boards/myirtech-x335x/lowlevel.c |   6 +-
>  arch/arm/configs/am335x_mlo_defconfig     |   1 +
>  arch/arm/dts/Makefile                     |   2 +-
>  arch/arm/dts/am335x-myirtech-myd-mlo.dts  |  10 +++
>  common/Kconfig                            |   8 ++
>  common/filetype.c                         | 132 +++++++++++++++++++++---------
>  fs/fs.c                                   |   3 +-
>  include/filetype.h                        |   5 +-
>  lib/uncompress.c                          |   4 +-
>  9 files changed, 125 insertions(+), 46 deletions(-)
> ---
> base-commit: a0ba27e06535570e8e4653f5f92a607f8b99022e
> change-id: 20250318-filetype-size-reduction-0cbf74281e2e
>
> Best regards,
> --
> Sascha Hauer <s.hauer@pengutronix.de>
>
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/7] filetype: add file_detect_fs_type()
  2025-03-18 14:51   ` Ahmad Fatoum
@ 2025-03-18 15:06     ` Sascha Hauer
  0 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2025-03-18 15:06 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: open list:BAREBOX

On Tue, Mar 18, 2025 at 03:51:44PM +0100, Ahmad Fatoum wrote:
> Hi,
> 
> On 3/18/25 15:41, Sascha Hauer wrote:
> > add file_detect_fs_type() which only tests if the buffer contains one of
> > the supported filesystems without testing for other binary formats.
> 
> 
> > +enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)
> 
> [snip]
> 
> >  enum filetype file_detect_type(const void *_buf, size_t bufsize)
> > -	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
> > -		return filetype_ext;
> > -
> >  	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
> >  		return filetype_ch_image
> 
> Shouldn't file_detec_type() still call file_detect_fs_type()?

Sure, that was the intention at least.

Thanks for catching, fixed this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-03-18 15:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
2025-03-18 14:41 ` [PATCH 1/7] filetype: add file_detect_compression_type() Sascha Hauer
2025-03-18 14:41 ` [PATCH 2/7] filetype: add file_detect_fs_type() Sascha Hauer
2025-03-18 14:51   ` Ahmad Fatoum
2025-03-18 15:06     ` Sascha Hauer
2025-03-18 14:41 ` [PATCH 3/7] filetype: add function pointer to file_name_detect_type_offset() Sascha Hauer
2025-03-18 14:41 ` [PATCH 4/7] filetype: let cdev_detect_type() only detect filesystems Sascha Hauer
2025-03-18 14:41 ` [PATCH 5/7] filetype: make file type strings optional Sascha Hauer
2025-03-18 14:41 ` [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree Sascha Hauer
2025-03-18 14:41 ` [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings Sascha Hauer
2025-03-18 15:01 ` [PATCH 0/7] filetype: Some size reduction patches Alexander Shiyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox