[PATCH 1/3] filetype: add zstd support

Marco Felsch m.felsch at pengutronix.de
Wed Jan 24 05:47:36 PST 2024


Add support to detect ZSTD compressed files.

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 common/filetype.c  | 4 ++++
 include/filetype.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 14948db4469f..7f1ce20d0094 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -17,6 +17,7 @@
 #include <disks.h>
 #include <image-sparse.h>
 #include <elf.h>
+#include <linux/zstd.h>
 
 #include <mach/imx/imx-header.h>
 
@@ -78,6 +79,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_mxs_sd_image] = { "i.MX23/28 SD card image", "mxs-sd-image" },
 	[filetype_rockchip_rkns_image] = { "Rockchip boot image", "rk-image" },
 	[filetype_fip] = { "TF-A Firmware Image Package", "fip" },
+	[filetype_zstd_compressed] = { "ZSTD compressed", "zstd" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -320,6 +322,8 @@ 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 e5aa050ebc27..a1f98f2a983a 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -60,6 +60,7 @@ enum filetype {
 	filetype_fip,
 	filetype_qemu_fw_cfg,
 	filetype_nxp_fspi_image,
+	filetype_zstd_compressed,
 	filetype_max,
 };
 
@@ -84,6 +85,7 @@ static inline bool file_is_compressed_file(enum filetype ft)
 	case filetype_gzip:
 	case filetype_bzip2:
 	case filetype_xz_compressed:
+	case filetype_zstd_compressed:
 		return true;
 	default:
 		return false;
-- 
2.39.2




More information about the barebox mailing list