summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2026-03-26 11:04:41 -0600
committerTom Rini <[email protected]>2026-03-26 11:04:41 -0600
commit80a4c49a4ab2ad06fa84a8b7bdf6e33b3b5101bf (patch)
tree94041e641b12a66eef8c35d991d83fb05409d698 /fs
parent5673d25fd82a00eb5a2bf5761b3aa92de0e9e4e1 (diff)
parent868233099d873cc8e2f8b99f609bdbaed421eab7 (diff)
Merge patch series "Introduce SQUASHFS support in SPL"
Richard Genoud <[email protected]> says: SquashFS has support in U-Boot, but not in SPL. This series adds the possibility for the SPL to load files from SquashFS partitions. This is useful, for instance, when there's a SquashFS rootfs containing U-Boot binary. NB: falcon mode is not supported yet. Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'fs')
-rw-r--r--fs/squashfs/sqfs.c12
-rw-r--r--fs/squashfs/sqfs_decompressor.c71
2 files changed, 28 insertions, 55 deletions
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 9cb8b4afcdd..543db8c7e9e 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -1490,13 +1490,11 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
goto out;
}
- /* If the user specifies a length, check its sanity */
- if (len) {
- if (len > finfo.size) {
- ret = -EINVAL;
- goto out;
- }
-
+ /*
+ * For FIT loading, the len is ALIGN, so it may exceed the actual size.
+ * Let's just read the max.
+ */
+ if (len && len < finfo.size) {
finfo.size = len;
} else {
len = finfo.size;
diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c
index cfd1153fd74..a156cfe6f65 100644
--- a/fs/squashfs/sqfs_decompressor.c
+++ b/fs/squashfs/sqfs_decompressor.c
@@ -10,19 +10,19 @@
#include <stdio.h>
#include <stdlib.h>
-#if IS_ENABLED(CONFIG_LZO)
+#if CONFIG_IS_ENABLED(LZO)
#include <linux/lzo.h>
#endif
-#if IS_ENABLED(CONFIG_ZLIB)
+#if CONFIG_IS_ENABLED(ZLIB)
#include <u-boot/zlib.h>
#endif
-#if IS_ENABLED(CONFIG_LZ4)
+#if CONFIG_IS_ENABLED(LZ4)
#include <u-boot/lz4.h>
#endif
-#if IS_ENABLED(CONFIG_ZSTD)
+#if CONFIG_IS_ENABLED(ZSTD)
#include <linux/zstd.h>
#endif
@@ -33,60 +33,35 @@ int sqfs_decompressor_init(struct squashfs_ctxt *ctxt)
{
u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression);
- switch (comp_type) {
-#if IS_ENABLED(CONFIG_LZO)
- case SQFS_COMP_LZO:
- break;
-#endif
-#if IS_ENABLED(CONFIG_ZLIB)
- case SQFS_COMP_ZLIB:
- break;
-#endif
-#if IS_ENABLED(CONFIG_LZ4)
- case SQFS_COMP_LZ4:
- break;
-#endif
-#if IS_ENABLED(CONFIG_ZSTD)
- case SQFS_COMP_ZSTD:
+ if (((CONFIG_IS_ENABLED(LZO) && comp_type == SQFS_COMP_LZO)) ||
+ ((CONFIG_IS_ENABLED(ZLIB) && comp_type == SQFS_COMP_ZLIB)) ||
+ ((CONFIG_IS_ENABLED(LZ4) && comp_type == SQFS_COMP_LZ4)))
+ return 0;
+
+#if CONFIG_IS_ENABLED(ZSTD)
+ if (comp_type == SQFS_COMP_ZSTD) {
ctxt->zstd_workspace = malloc(zstd_dctx_workspace_bound());
if (!ctxt->zstd_workspace)
return -ENOMEM;
- break;
-#endif
- default:
- printf("Error: unknown compression type.\n");
- return -EINVAL;
+ return 0;
}
+#endif
- return 0;
+ printf("Error: unknown compression type.\n");
+ return -EINVAL;
}
void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt)
{
+#if CONFIG_IS_ENABLED(ZSTD)
u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression);
- switch (comp_type) {
-#if IS_ENABLED(CONFIG_LZO)
- case SQFS_COMP_LZO:
- break;
-#endif
-#if IS_ENABLED(CONFIG_ZLIB)
- case SQFS_COMP_ZLIB:
- break;
-#endif
-#if IS_ENABLED(CONFIG_LZ4)
- case SQFS_COMP_LZ4:
- break;
-#endif
-#if IS_ENABLED(CONFIG_ZSTD)
- case SQFS_COMP_ZSTD:
+ if (comp_type == SQFS_COMP_ZSTD)
free(ctxt->zstd_workspace);
- break;
#endif
- }
}
-#if IS_ENABLED(CONFIG_ZLIB)
+#if CONFIG_IS_ENABLED(ZLIB)
static void zlib_decompression_status(int ret)
{
switch (ret) {
@@ -103,7 +78,7 @@ static void zlib_decompression_status(int ret)
}
#endif
-#if IS_ENABLED(CONFIG_ZSTD)
+#if CONFIG_IS_ENABLED(ZSTD)
static int sqfs_zstd_decompress(struct squashfs_ctxt *ctxt, void *dest,
unsigned long dest_len, void *source, u32 src_len)
{
@@ -129,7 +104,7 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
int ret = 0;
switch (comp_type) {
-#if IS_ENABLED(CONFIG_LZO)
+#if CONFIG_IS_ENABLED(LZO)
case SQFS_COMP_LZO: {
size_t lzo_dest_len = *dest_len;
ret = lzo1x_decompress_safe(source, src_len, dest, &lzo_dest_len);
@@ -141,7 +116,7 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
break;
}
#endif
-#if IS_ENABLED(CONFIG_ZLIB)
+#if CONFIG_IS_ENABLED(ZLIB)
case SQFS_COMP_ZLIB:
ret = uncompress(dest, dest_len, source, src_len);
if (ret) {
@@ -151,7 +126,7 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
break;
#endif
-#if IS_ENABLED(CONFIG_LZ4)
+#if CONFIG_IS_ENABLED(LZ4)
case SQFS_COMP_LZ4:
ret = LZ4_decompress_safe(source, dest, src_len, *dest_len);
if (ret < 0) {
@@ -162,7 +137,7 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
ret = 0;
break;
#endif
-#if IS_ENABLED(CONFIG_ZSTD)
+#if CONFIG_IS_ENABLED(ZSTD)
case SQFS_COMP_ZSTD:
ret = sqfs_zstd_decompress(ctxt, dest, *dest_len, source, src_len);
if (ret) {