Add support for the SquashFS filesystem
Subsystems (2)
cover Add support for the SquashFS filesystem
Hello!
This series adds support for the SquashFS filesystem. For now, zlib is the only supported compression type. This is my first contribution to U-Boot as well as to a major Open Source project.
Best regards,
Joao Marcos Costa
Joao Marcos Costa (4):
fs/squashfs: new filesystem
fs/squashfs: add filesystem commands
fs/squashfs: add sources for zlib decompression
fs/squashfs: add support for zlib decompression
cmd/Kconfig | 6 + cmd/Makefile | 1 + cmd/sqfs.c | 43 + common/spl/Kconfig | 9 + fs/Kconfig | 2 + fs/Makefile | 2 + fs/fs.c | 15 + fs/squashfs/Kconfig | 10 + fs/squashfs/Makefile | 7 + fs/squashfs/sqfs.c | 1625 +++++++++++++++++++++++++++++++ fs/squashfs/sqfs_decompressor.c | 53 + fs/squashfs/sqfs_decompressor.h | 58 ++ fs/squashfs/sqfs_dir.c | 107 ++ fs/squashfs/sqfs_filesystem.h | 301 ++++++ fs/squashfs/sqfs_inode.c | 142 +++ fs/squashfs/sqfs_utils.h | 49 + include/fs.h | 13 + include/squashfs.h | 24 + include/u-boot/zlib.h | 32 + lib/zlib/uncompr.c | 93 ++ lib/zlib/zlib.c | 1 + 21 files changed, 2593 insertions(+) create mode 100644 cmd/sqfs.c create mode 100644 fs/squashfs/Kconfig create mode 100644 fs/squashfs/Makefile create mode 100644 fs/squashfs/sqfs.c create mode 100644 fs/squashfs/sqfs_decompressor.c create mode 100644 fs/squashfs/sqfs_decompressor.h create mode 100644 fs/squashfs/sqfs_dir.c create mode 100644 fs/squashfs/sqfs_filesystem.h create mode 100644 fs/squashfs/sqfs_inode.c create mode 100644 fs/squashfs/sqfs_utils.h create mode 100644 include/squashfs.h create mode 100644 lib/zlib/uncompr.c
--
2.17.1
PATCH 1/4 fs/squashfs: new filesystem
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit.
--- common/spl/Kconfig | 9 + fs/Kconfig | 2 + fs/Makefile | 2 + fs/fs.c | 15 + fs/squashfs/Kconfig | 10 + fs/squashfs/Makefile | 7 + fs/squashfs/sqfs.c | 1625 +++++++++++++++++++++++++++++++ fs/squashfs/sqfs_decompressor.c | 29 + fs/squashfs/sqfs_decompressor.h | 58 ++ fs/squashfs/sqfs_dir.c | 107 ++ fs/squashfs/sqfs_filesystem.h | 301 ++++++ fs/squashfs/sqfs_inode.c | 142 +++ fs/squashfs/sqfs_utils.h | 49 + include/fs.h | 13 + include/squashfs.h | 24 + 15 files changed, 2393 insertions(+) create mode 100644 fs/squashfs/Kconfig create mode 100644 fs/squashfs/Makefile create mode 100644 fs/squashfs/sqfs.c create mode 100644 fs/squashfs/sqfs_decompressor.c create mode 100644 fs/squashfs/sqfs_decompressor.h create mode 100644 fs/squashfs/sqfs_dir.c create mode 100644 fs/squashfs/sqfs_filesystem.h create mode 100644 fs/squashfs/sqfs_inode.c create mode 100644 fs/squashfs/sqfs_utils.h create mode 100644 include/squashfs.h
common/spl/Kconfig +9 -0
@@ -566,6 +566,15 @@ config SPL_FS_EXT4 filesystem from within SPL. Support for the underlying block device (e.g. MMC or USB) must be enabled separately. +config SPL_FS_SQUASHFS + bool "Support SquashFS filesystems" + select FS_SQUASHFS + help + Enable support for SquashFS filesystems with SPL. This permits + U-Boot (or Linux in Falcon mode) to be loaded from a SquashFS + filesystem from within SPL. Support for the underlying block + device (e.g. MMC or USB) must be enabled separately. + config SPL_FS_FAT bool "Support FAT filesystems" select FS_FAT
fs/Kconfig +2 -0
@@ -22,4 +22,6 @@ source "fs/cramfs/Kconfig" source "fs/yaffs2/Kconfig" +source "fs/squashfs/Kconfig" + endmenu
fs/Makefile +2 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/ obj-$(CONFIG_SPL_FS_CBFS) += cbfs/ +obj-$(CONFIG_SPL_FS_SQUASHFS) += squashfs/ else obj-y += fs.o
@@ -23,5 +24,6 @@ obj-$(CONFIG_SANDBOX) += sandbox/ obj-$(CONFIG_CMD_UBIFS) += ubifs/ obj-$(CONFIG_YAFFS2) += yaffs2/ obj-$(CONFIG_CMD_ZFS) += zfs/ +obj-$(CONFIG_FS_SQUASHFS) += squashfs/ endif obj-y += fs_internal.o
fs/fs.c +15 -0
@@ -19,6 +19,7 @@#include <div64.h> #include <linux/math64.h> #include <efi_loader.h> +#include <squashfs.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -273,6 +274,20 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, }, +#endif +#ifdef CONFIG_FS_SQUASHFS + { + .fstype = FS_TYPE_SQUASHFS, + .name = "squashfs", + .probe = sqfs_probe, + .opendir = sqfs_opendir, + .readdir = sqfs_readdir, + .ls = sqfs_ls, + .read = sqfs_read, + .size = sqfs_size, + .close = sqfs_close, + .closedir = sqfs_closedir, + }, #endif { .fstype = FS_TYPE_ANY,
fs/squashfs/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config FS_SQUASHFS + bool "Enable SquashFS filesystem support" + help + This provides support for reading images from SquashFS filesystem. + Squashfs is a compressed read-only filesystem for Linux. + It uses zlib, lz4, lzo, or xz compression to compress files, inodes + and directories. Squashfs is intended for general read-only + filesystem use, for archival use (i.e. in cases where a .tar.gz file + may be used), and in constrained block device/memory systems (e.g. + embedded systems) where low overhead is needed.
fs/squashfs/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_$(SPL_)FS_SQUASHFS) = sqfs.o \ + sqfs_inode.o \ + sqfs_dir.o \ + sqfs_decompressor.o
fs/squashfs/sqfs.c new file +1625 -0
1,625 lines not on this page · raw message
fs/squashfs/sqfs_decompressor.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020 Bootlin +* +* Author: Joao Marcos Costa <[email protected]> +*/ + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "sqfs_decompressor.h" +#include "sqfs_filesystem.h" +#include "sqfs_utils.h" + +int sqfs_decompress (u16 comp_type,void *dest,unsigned long *dest_len, +void *source,u32 lenp) +{ +int ret =0 ; + +switch (comp_type) { +default : +printf ("Error: unknown compression type.\n" ); +return -EINVAL ; + } + +return ret; +}
fs/squashfs/sqfs_decompressor.h new file +58 -0
58 lines not on this page · raw message
fs/squashfs/sqfs_dir.c new file +107 -0
107 lines not on this page · raw message
fs/squashfs/sqfs_filesystem.h new file +301 -0
301 lines not on this page · raw message
fs/squashfs/sqfs_inode.c new file +142 -0
142 lines not on this page · raw message
fs/squashfs/sqfs_utils.h new file +49 -0
49 lines not on this page · raw message
include/fs.h +13 -0
@@ -13,6 +13,7 @@#define FS_TYPE_SANDBOX 3#define FS_TYPE_UBIFS 4#define FS_TYPE_BTRFS 5 +#define FS_TYPE_SQUASHFS 6/** * do_fat_fsload - Run the fatload command
@@ -36,6 +37,18 @@ int do_fat_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);*/ int do_ext2load (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); + +/** +* do_sqfs_load - Run the sqfsload command +* +* @cmdtp: Command information for sqfsload +* @flag: Command flags (CMD_FLAG_...) +* @argc: Number of arguments +* @argv: List of arguments +* @return result (see enum command_ret_t) +*/ +int do_sqfs_load (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); +/* * Tell the fs layer which block device an partition to use for future * commands. This also internally identifies the filesystem that is present
include/squashfs.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020 Bootlin +* +* Author: Joao Marcos Costa <[email protected]> +* +* squashfs.h: SquashFS filesystem implementation. +*/ + +#ifndef _SQFS_H_ +#define _SQFS_H_ + +int sqfs_opendir (const char *filename,struct fs_dir_stream **dirsp); +int sqfs_ls (const char *filename); +int sqfs_readdir (struct fs_dir_stream *dirs,struct fs_dirent **dentp); +int sqfs_probe (struct blk_desc *fs_dev_desc, +disk_partition_t *fs_partition); +int sqfs_read (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actread); +int sqfs_size (const char *filename,loff_t *size); +void sqfs_close (void ); +void sqfs_closedir (struct fs_dir_stream *dirs); + +#endif /* SQFS_H */
--
2.17.1
PATCH 1/4 fs/squashfs: new filesystem
Quoted 2 lines · Joao Marcos Costa
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit.
Cool, thanks for proposing this. While I'm not really in a position to review these, just one comment below.
common/spl/Kconfig config SPL_FS_EXT4 · line 571
Quoted 4 lines
common/spl/Kconfig +3
-0+config SPL_FS_SQUASHFS + bool "Support SquashFS filesystems" + select FS_SQUASHFS
Is there any reason U-Boot proper must support squashfs if the SPL does? This isn't quite specific to this patch; I see a number of 'config SPL_FOO' that either depends on or selects FOO (e.g. SPL_FS_FAT), and I wonder why.
Rasmus
PATCH 1/4 fs/squashfs: new filesystem
Hello!
Quoted 18 lines · On Thu, 9 Jul 2020 21:50:03 +0200 Rasmus Villemoes…
Quoted 3 lines · Joao Marcos Costa
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit.
Cool, thanks for proposing this. While I'm not really in a position to review these, just one comment below.
common/spl/Kconfig config SPL_FS_EXT4 · line 571
Quoted 4 lines
common/spl/Kconfig +3
-0+config SPL_FS_SQUASHFS + bool "Support SquashFS filesystems" + select FS_SQUASHFSIs there any reason U-Boot proper must support squashfs if the SPL does? This isn't quite specific to this patch; I see a number of 'config
SPL_FOO' that either depends on or selects FOO (e.g.SPL_FS_FAT), and I wonder why.
Quoted 1 line
Rasmus
Well, I don't have enough experience to answer this question properly, but precisely as you mentioned, other filesystems do the same concerning SPL, and I simply decided to follow their example.
Best regards,
Joao Marcos
PATCH 1/4 fs/squashfs: new filesystem
In reply to Rasmus VillemoesHello Rasmus,
Quoted 8 lines · On Thu, 9 Jul 2020 21:50:03 +0200 Rasmus Villemoes…
common/spl/Kconfig config SPL_FS_EXT4 · line 571
Quoted 3 lines
common/spl/Kconfig +3
-0+config SPL_FS_SQUASHFS + bool "Support SquashFS filesystems" + select FS_SQUASHFSIs there any reason U-Boot proper must support squashfs if the SPL does? This isn't quite specific to this patch; I see a number of 'config
SPL_FOO' that either depends on or selects FOO (e.g.SPL_FS_FAT), and I wonder why.
Well, if your Linux kernel image and Device Tree are stored in a squashfs filesystem, then U-Boot proper needs SquashFS support, right ?
And that is completely independent of whether the SPL has SquashFS support to be able to load U-Boot proper (which potentially could be stored on SquashFS as well).
It's very much like the FAT filesystem case: if you have U-Boot proper and your Linux kernel image in a FAT filesystem, then the SPL needs FAT filesystem support to load U-Boot proper, and U-Boot proper needs FAT filesystem support to load the Linux kernel image.
Am I missing something here ?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/4 fs/squashfs: new filesystem
Quoted 14 lines · Thomas Petazzoni
Hello Rasmus,
Quoted 8 lines · On Thu, 9 Jul 2020 21:50:03 +0200 Rasmus Villemoes…
common/spl/Kconfig config SPL_FS_EXT4 · line 571
Quoted 3 lines
common/spl/Kconfig +3
-0+config SPL_FS_SQUASHFS + bool "Support SquashFS filesystems" + select FS_SQUASHFSIs there any reason U-Boot proper must support squashfs if the SPL does? This isn't quite specific to this patch; I see a number of 'config
SPL_FOO' that either depends on or selects FOO (e.g.SPL_FS_FAT), and I wonder why.
Quoted 2 lines
Well, if your Linux kernel image and Device Tree are stored in a squashfs filesystem, then U-Boot proper needs SquashFS support, right ?
Exactly.
Quoted 3 lines
And that is completely independent of whether the SPL has SquashFS support to be able to load U-Boot proper (which potentially could be stored on SquashFS as well).
Exactly.
Quoted 2 lines
It's very much like the FAT filesystem case: if you have U-Boot proper and your Linux kernel image in a FAT filesystem,
No, this is very much _not_ like the above. In this paragraph, you combine "U-Boot proper and your Linux kernel", imposing an implicit assumption that they are stored in the same way. Sure, _if_ both these items are stored in squashfs images (possibly the same, possibly distinct), then the thing that loads the respective images obviously needs squashfs (or FAT, or whatnot) support.
My point is that it's possible that, say, U-Boot proper is stored in a FAT file system, and the kernel is stored in a UBI volume. So SPL needs FAT support. Why should I be forced to compile FAT support into U-Boot proper if U-Boot proper never needs to access a FAT filesystem? And the same for squashfs. Or any of the drivers or DM_ frameworks that do that "depends on" or "select".
I can see why things like bloblist that are very much about passing info from one stage to the next only make sense if both sides have that configured in. But the drivers/filesystems that are needed in SPL need not have anything to do with that which is needed in U-Boot proper.
Rasmus
PATCH 1/4 fs/squashfs: new filesystem
Quoted 10 lines · On Fri, 10 Jul 2020 10:54:24 +0200 Rasmus Villemoes…
Quoted 2 lines
It's very much like the FAT filesystem case: if you have U-Boot proper and your Linux kernel image in a FAT filesystem,
No, this is very much _not_ like the above. In this paragraph, you combine "U-Boot proper and your Linux kernel", imposing an implicit assumption that they are stored in the same way. Sure, _if_ both these items are stored in squashfs images (possibly the same, possibly distinct), then the thing that loads the respective images obviously needs squashfs (or FAT, or whatnot) support.
Quoted 6 lines
My point is that it's possible that, say, U-Boot proper is stored in a FAT file system, and the kernel is stored in a UBI volume. So SPL needs FAT support. Why should I be forced to compile FAT support into U-Boot proper if U-Boot proper never needs to access a FAT filesystem? And the same for squashfs. Or any of the drivers or
DM_frameworks that do that "depends on" or "select".
Ah, I absolutely agree that it should be possible to have Squashfs in both SPL and U-Boot proper, or only in SPL or only in U-Boot proper.
It was not clear in your initial e-mail that this was the issue you were pointing.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/4 fs/squashfs: new filesystem
Quoted 20 lines · Thomas Petazzoni
Quoted 10 lines · On Fri, 10 Jul 2020 10:54:24 +0200 Rasmus Villemoes…
Quoted 2 lines
It's very much like the FAT filesystem case: if you have U-Boot proper and your Linux kernel image in a FAT filesystem,
No, this is very much _not_ like the above. In this paragraph, you combine "U-Boot proper and your Linux kernel", imposing an implicit assumption that they are stored in the same way. Sure, _if_ both these items are stored in squashfs images (possibly the same, possibly distinct), then the thing that loads the respective images obviously needs squashfs (or FAT, or whatnot) support.
Quoted 6 lines
My point is that it's possible that, say, U-Boot proper is stored in a FAT file system, and the kernel is stored in a UBI volume. So SPL needs FAT support. Why should I be forced to compile FAT support into U-Boot proper if U-Boot proper never needs to access a FAT filesystem? And the same for squashfs. Or any of the drivers or
DM_frameworks that do that "depends on" or "select".
Quoted 5 lines
Ah, I absolutely agree that it should be possible to have Squashfs in both SPL and U-Boot proper, or only in SPL or only in U-Boot proper.
It was not clear in your initial e-mail that this was the issue you were pointing.
Note that on this point the question is, do we have a use case for falcon mode and loading linux from squashfs? I assume the answer is yes, and that's why we would want to have squashfs be enabled in SPL.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200715/cac9a7a6/attachment.sig>
PATCH 1/4 fs/squashfs: new filesystem
In reply to Joao Marcos CostaQuoted 4 lines · Joao Marcos Costa
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit.
Signed-off-by Joao Marcos Costa <[email protected]>
Sorry for the delay. If you run this patch through checkpatch.pl it notes a few problems that need to be addressed. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200715/f3825680/attachment.sig>
PATCH 2/4 fs/squashfs: add filesystem commands
In reply to Joao Marcos CostaAdd 'ls' (sqfsls) and 'load' (sqfsload) commands.
--- cmd/Kconfig | 6 ++++++ cmd/Makefile | 1 + cmd/sqfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 cmd/sqfs.c
cmd/Kconfig +6 -0
@@ -1993,6 +1993,12 @@ config CMD_FAT help Support for the FAT fs +config CMD_SQUASHFS + bool "SquashFS command support" + select FS_SQUASHFS + help + Enables SquashFS filesystem commands (e.g. load, ls). + config CMD_FS_GENERIC bool "filesystem commands" help
cmd/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_CMD_EXT4) += ext4.o obj-$(CONFIG_CMD_EXT2) += ext2.o obj-$(CONFIG_CMD_FAT) += fat.o obj-$(CONFIG_CMD_FDT) += fdt.o +obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o obj-$(CONFIG_CMD_FITUPD) += fitupd.o obj-$(CONFIG_CMD_FLASH) += flash.o obj-$(CONFIG_CMD_FPGA) += fpga.o
cmd/sqfs.c new file +43 -0
43 lines not on this page · raw message
--
2.17.1
PATCH 3/4 fs/squashfs: add sources for zlib decompression
In reply to Joao Marcos CostaAdd zlib (v1.2.11) functions to U-Boot. SquashFS depends on those functions to decompress data from a raw disk image. The actual support for zlib into SquashFS sources will be added in a follow-up commit.
--- include/u-boot/zlib.h | 32 +++++++++++++++ lib/zlib/uncompr.c | 93 +++++++++++++++++++++++++++++++++++++++++++ lib/zlib/zlib.c | 1 + 3 files changed, 126 insertions(+) create mode 100644 lib/zlib/uncompr.c
include/u-boot/zlib.h +32 -0
@@ -110,6 +110,12 @@ extern "C" {# define voidp z_voidp#endif +#if defined(ZLIB_CONST ) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif +#if defined(__MSDOS__) && !defined(MSDOS )# define MSDOS #endif
@@ -710,6 +716,32 @@ ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len));if (crc != original_crc) error(); */ +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* +Decompresses the source buffer into the destination buffer. sourceLen is +the byte length of the source buffer. Upon entry, destLen is the total size +of the destination buffer, which must be large enough to hold the entire +uncompressed data. (The size of the uncompressed data must have been saved +previously by the compressor and transmitted to the decompressor by some +mechanism outside the scope of this compression library.) Upon exit, destLen +is the actual size of the uncompressed data. + +uncompress returns Z_OK if success, Z_MEM_ERROR if there was not +enough memory, Z_BUF_ERROR if there was not enough room in the output +buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In +the case where there is not enough room, uncompress() will fill the output +buffer with the uncompressed data up to that point. +*/ + +ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen)); +/* +Same as uncompress, except that sourceLen is a pointer, where the +length of the source is *sourceLen. On return, *sourceLen is the number of +source bytes consumed. +*/ + ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size));#define inflateInit (strm) \
lib/zlib/uncompr.c new file +93 -0
93 lines not on this page · raw message
lib/zlib/zlib.c +1 -0
@@ -30,3 +30,4 @@#include "inflate.c" #include "zutil.c" #include "adler32.c" +#include "uncompr.c"
--
2.17.1
PATCH 3/4 fs/squashfs: add sources for zlib decompression
Hello Joao,
Quoted 5 lines · On Thu, 9 Jul 2020 19:51:47 +0200 Joao Marcos Costa…
Add zlib (v1.2.11) functions to U-Boot. SquashFS depends on those functions to decompress data from a raw disk image. The actual support for zlib into SquashFS sources will be added in a follow-up commit.
Signed-off-by Joao Marcos Costa <[email protected]>
The header of the commit title is wrong, this commit is not touching fs/squashfs at all, but lib/zlib.
I think the rest of the commit title are also misleading: I believe zlib decompression was already supported in U-Boot.
But looking at the code, lib/gunzip.c already has a function called zunzip(), which seems to do pretty much the same thing: decompress from a memory buffer into another memory buffer.
Are you sure you cannot use this existing zunzip() function ? zunzip() is already used by UBIFS.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 4/4 fs/squashfs: add support for zlib decompression
In reply to Joao Marcos CostaAdd call to zlib's 'uncompress' function. Add function to display the right error message depending on the decompression's return value.
--- fs/squashfs/sqfs_decompressor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/squashfs/sqfs_decompressor.c +24 -0
@@ -9,17 +9,41 @@#include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <u-boot/zlib.h> #include "sqfs_decompressor.h" #include "sqfs_filesystem.h" #include "sqfs_utils.h" +static void zlib_decompression_status (int ret) +{ +switch (ret) { +case Z_BUF_ERROR : +printf ("Error: 'dest' buffer is not large enough.\n" ); +break ; +case Z_DATA_ERROR : +printf ("Error: corrupted compressed data.\n" ); +break ; +case Z_MEM_ERROR : +printf ("Error: insufficient memory.\n" ); +break ; + } +} +int sqfs_decompress (u16 comp_type,void *dest,unsigned long *dest_len,void *source,u32 lenp) {int ret =0 ;switch (comp_type) { +case SQFS_COMP_ZLIB : + ret =uncompress (dest, dest_len, source, lenp); +if (ret) { +zlib_decompression_status (ret); +return -EINVAL ; + } + +break ;default :printf ("Error: unknown compression type.\n" );return -EINVAL ;
--
2.17.1
cover squashfs fixes
In reply to Joao Marcos CostaHello Joao,
As I started reviewing your patch series, I encountered a number of build issues after applying your patches, and building on the latest master. The following patches address the build failures I have encountered. Could you squash them into your commits, so that those fixes are part of your v2 ? Of course, please do some testing, as I have only done build testing so far.
Also, even with those fixes in place, I do still get a worrying gcc warning (from gcc 10):
fs/squashfs/sqfs_inode.c: In function ?sqfs_find_inode?:fs/squashfs/sqfs_inode.c:72:34: warning: array subscript l is outside array bounds of ?struct squashfs_directory_index[0]? [-Warray-bounds]
72 | index_list_size += ldir.index[l].size + 1;
| ~~~~~~~~~~^~~In file included from fs/squashfs/sqfs_inode.c:16:fs/squashfs/sqfs_filesystem.h:207:34: note: while referencing ?index?
207 | struct squashfs_directory_index index[0];
| ^~~~~fs/squashfs/sqfs_inode.c:31:29: note: defined here ?ldir?
31 | struct squashfs_ldir_inode ldir;
| ^~~~
Could you investigate this ?
Thanks,
Thomas
Thomas Petazzoni (3):
cmd/sqfs.c, include/fs.h: fix build failures, don't expose do_sqfs_*()
functions globally
fs/squashfs: use "struct disk_partition" instead of "disk_partition_t" fs/squashfs: do not use CMD_RET_* defines in the filesystem code
cmd/sqfs.c | 5 ++-- fs/squashfs/sqfs.c | 66 ++++++++++++++++++++-------------------------- include/fs.h | 12 --------- include/squashfs.h | 4 ++- 4 files changed, 34 insertions(+), 53 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 cmd/sqfs.c, include/fs.h: fix build failures, don't expose do_sqfs_*() functions globally
The cmd_tbl_t type has been removed upstream since commit 09140113108 ("command: Remove the cmd_tbl_t typedef"), so we must use "struct cmd_tbl" instead.
The <command.h> include was missing in cmd/sqfs.c, without which U_BOOT_CMD() is not defined.
Finally, there is no reason to globally expose do_sqfs_ls() and do_sqfs_load(), they are only used within cmd/sqfs.c. This allows to drop the do_sqfs_load() prototype from include/fs.h.
--- cmd/sqfs.c | 5 +++-- include/fs.h | 12 ------------ 2 files changed, 3 insertions(+), 14 deletions(-)
cmd/sqfs.c +3 -2
@@ -7,10 +7,11 @@* squashfs.c: implements SquashFS related commands */ +#include <command.h> #include <fs.h> #include <squashfs.h> -int do_sqfs_ls (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +static int do_sqfs_ls (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {return do_ls (cmdtp, flag, argc, argv,FS_TYPE_SQUASHFS ); }
@@ -22,7 +23,7 @@ U_BOOT_CMD(" - list files from 'dev' on 'interface' in 'directory'\n" ); -int do_sqfs_load (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +static int do_sqfs_load (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {return do_load (cmdtp, flag, argc, argv,FS_TYPE_SQUASHFS ); }
include/fs.h +0 -12
@@ -42,18 +42,6 @@ int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc,*/ int do_ext2load (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]); - -/** -* do_sqfs_load - Run the sqfsload command -* -* @cmdtp: Command information for sqfsload -* @flag: Command flags (CMD_FLAG_...) -* @argc: Number of arguments -* @argv: List of arguments -* @return result (see enum command_ret_t) -*/ -int do_sqfs_load (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); -/* * Tell the fs layer which block device an partition to use for future * commands. This also internally identifies the filesystem that is present
Signature · 1 line
2.26.2
PATCH 2/3 fs/squashfs: use "struct disk_partition" instead of "disk_partition_t"
In reply to Thomas Petazzonidisk_partition_t was dropped in 0528979fa7ab ("part: Drop disk_partition_t typedef").
--- fs/squashfs/sqfs.c | 5 +++-- include/squashfs.h | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)
fs/squashfs/sqfs.c +3 -2
@@ -17,12 +17,13 @@#include <stdlib.h> #include <string.h> #include <squashfs.h> +#include <part.h> #include "sqfs_decompressor.h" #include "sqfs_filesystem.h" #include "sqfs_utils.h" -static disk_partition_t cur_part_info; +static struct disk_partition cur_part_info;static struct blk_desc *cur_dev;static int sqfs_disk_read (__u32 block,__u32 nr_blocks,void *buf)
@@ -1013,7 +1014,7 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp)return SQFS_CONTINUE_READDIR ; } -int sqfs_probe (struct blk_desc *fs_dev_desc,disk_partition_t *fs_partition) +int sqfs_probe (struct blk_desc *fs_dev_desc,struct disk_partition *fs_partition) {struct squashfs_super_block *sblk;
include/squashfs.h +3 -1
@@ -10,11 +10,13 @@#ifndef _SQFS_H_#define _SQFS_H_ +struct disk_partition ; +int sqfs_opendir (const char *filename,struct fs_dir_stream **dirsp);int sqfs_ls (const char *filename);int sqfs_readdir (struct fs_dir_stream *dirs,struct fs_dirent **dentp);int sqfs_probe (struct blk_desc *fs_dev_desc, -disk_partition_t *fs_partition); +struct disk_partition *fs_partition);int sqfs_read (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actread);int sqfs_size (const char *filename,loff_t *size);
Signature · 1 line
2.26.2
PATCH 3/3 fs/squashfs: do not use CMD_RET_* defines in the filesystem code
In reply to Thomas PetazzoniUsing CMD_RET_* defines in fs/squashfs/ breaks the build as they are not defined. These defines are really meant to be used as return values of commands, not internally in filesystem code. Instead, appropriate errno codes should be used.
This patch changes fs/squashfs to use proper errno code. In most places, it is straightforward. There are a few places where it is not:
- In sqfs_read(), the value of datablk_count was checked *after* it was used to do a memcpy(). So the memcpy() could have used a negative size. The check was moved prior to the memcpy(), right after calling sqfs_get_regfile_info() and sqfs_get_lregfile_info().
- The sqfs_size() function is modified to return "ret" at the end, so that the error code is properly propagated.
--- fs/squashfs/sqfs.c | 61 +++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 36 deletions(-)
fs/squashfs/sqfs.c +25 -36
@@ -1241,10 +1241,8 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,*/ sqfs_split_path (&file, &dir, filename); ret =sqfs_opendir (dir, &dirs.fs_dirs); -if (ret) { - ret =CMD_RET_FAILURE ; +if (ret) goto free_paths; - } dirsp = (struct fs_dir_stream *)&dirs; dirs.dentp = &dent;
@@ -1253,7 +1251,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,if (!strncmp (dent.name, file,strlen (dent.name))) { ret =sqfs_read_entry (&entry, dirs.entry);if (ret) { - ret =CMD_RET_FAILURE ;free (dirs.entry);sqfs_closedir (dirsp); goto free_paths;
@@ -1269,7 +1266,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,printf ("File not found.\n" ); *actread =0 ;sqfs_closedir (dirsp); - ret =CMD_RET_FAILURE ; + ret = -ENOENT ; goto free_paths; }
@@ -1283,6 +1280,10 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,memcpy (®, ipos,sizeof (reg)); datablk_count =sqfs_get_regfile_info (®, &finfo, &frag_entry, sblk->block_size); +if (datablk_count <0 ) { + ret = -EINVAL ; + goto free_entry; + }memcpy (finfo.blk_sizes, ipos +sizeof (reg), datablk_count *sizeof (u32));break ;
@@ -1291,6 +1292,10 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, datablk_count =sqfs_get_lregfile_info (&lreg, &finfo, &frag_entry, sblk->block_size); +if (datablk_count <0 ) { + ret = -EINVAL ; + goto free_entry; + }memcpy (finfo.blk_sizes, ipos +sizeof (lreg), datablk_count *sizeof (u32));break ;
@@ -1301,9 +1306,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,printf ("%s - > %s\n" , filename, resolved); ret =sqfs_read (resolved, buf, offset, len, actread);free (resolved); -if (ret) - ret =CMD_RET_FAILURE ; - ret =CMD_RET_SUCCESS ; goto free_entry;case SQFS_BLKDEV_TYPE :case SQFS_CHRDEV_TYPE :
@@ -1315,19 +1317,14 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,case SQFS_LSOCKET_TYPE :default :printf ("Unsupported entry type\n" ); - ret =CMD_RET_FAILURE ; - goto free_entry; - } - -if (datablk_count <0 ) { - ret =CMD_RET_FAILURE ; + ret = -EINVAL ; goto free_entry; }/* If the user specifies a length, check its sanity */ if (len) {if (len > finfo.size) { - ret =CMD_RET_FAILURE ; + ret = -EINVAL ; goto free_entry; }
@@ -1338,7 +1335,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, data_offset = finfo.start; datablock =malloc (sblk->block_size);if (!datablock) { - ret =CMD_RET_FAILURE ; + ret = -ENOMEM ; goto free_entry; } }
@@ -1353,18 +1350,18 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, data_buffer =malloc_cache_aligned (n_blks * cur_dev->blksz);if (!data_buffer) { - ret =CMD_RET_FAILURE ; + ret = -ENOMEM ; goto free_datablk; } -if (sqfs_disk_read (start, n_blks, data_buffer) <0 ) { + ret =sqfs_disk_read (start, n_blks, data_buffer); +if (ret <0 ) {/* * Tip: re-compile the SquashFS image with mksquashfs's * -b <block_size> option. */ printf ("Error: too many data blocks or too large" \"SquashFS block size.\n" ); - ret =CMD_RET_FAILURE ; goto free_buffer; }
@@ -1375,10 +1372,8 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, dest_len = sblk->block_size; ret =sqfs_decompress (comp_type, datablock, &dest_len, data, table_size); -if (ret) { - ret =CMD_RET_FAILURE ; +if (ret) goto free_buffer; - }memcpy (buf + offset + *actread, datablock, dest_len); *actread += dest_len;
@@ -1396,7 +1391,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,* There is no need to continue if the file is not fragmented. */ if (!finfo.frag) { - ret =CMD_RET_SUCCESS ; + ret =0 ; goto free_buffer; }
@@ -1408,21 +1403,20 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, fragment =malloc_cache_aligned (n_blks * cur_dev->blksz);if (!fragment) { - ret =CMD_RET_FAILURE ; + ret = -ENOMEM ; goto free_buffer; } -if (sqfs_disk_read (start, n_blks, fragment) <0 ) { - ret =CMD_RET_FAILURE ; + ret =sqfs_disk_read (start, n_blks, fragment); +if (ret <0 ) goto free_fragment; - }/* File compressed and fragmented */ if (finfo.frag && finfo.comp) { dest_len = sblk->block_size; fragment_block =malloc (sblk->block_size);if (!fragment_block) { - ret =CMD_RET_FAILURE ; + ret = -ENOMEM ; goto free_fragment; }
@@ -1431,7 +1425,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, frag_entry.size);if (ret) {free (fragment_block); - ret =CMD_RET_FAILURE ; goto free_fragment; }
@@ -1480,7 +1473,7 @@ int sqfs_ls(const char *filename) ret =sqfs_opendir (filename, &dirs.fs_dirs);if (ret) {sqfs_closedir (dirsp); -return CMD_RET_FAILURE ; +return ret; } dirs.dentp = &dent;
@@ -1542,7 +1535,6 @@ int sqfs_size(const char *filename, loff_t *size) ret =sqfs_opendir (dir, &dirs.fs_dirs);if (ret) {sqfs_closedir (dirsp); - ret =CMD_RET_FAILURE ; goto free_strings; }
@@ -1558,7 +1550,6 @@ int sqfs_size(const char *filename, loff_t *size)if (ret) {sqfs_closedir (dirsp); - ret =CMD_RET_FAILURE ; goto free_strings; }
@@ -1583,9 +1574,6 @@ int sqfs_size(const char *filename, loff_t *size) resolved =sqfs_resolve_symlink (&symlink, ipos, filename); ret =sqfs_size (resolved, size);free (resolved); -if (ret) - ret =CMD_RET_FAILURE ; - ret =CMD_RET_SUCCESS ;break ;case SQFS_BLKDEV_TYPE :case SQFS_CHRDEV_TYPE :
@@ -1598,6 +1586,7 @@ int sqfs_size(const char *filename, loff_t *size)default :printf ("Unable to recover entry's size.\n" ); *size =0 ; + ret = -EINVAL ;break ; }
@@ -1608,7 +1597,7 @@ free_strings:free (sblk);sqfs_closedir (dirsp); -return 0 ; +return ret; }void sqfs_close (void )
Signature · 1 line
2.26.2
cover squashfs fixes
In reply to Thomas PetazzoniHello, Thomas!
Quoted 8 lines · On Wed, 15 Jul 2020 22:11:40 +0200 Thomas Petazzoni…
Hello Joao,
As I started reviewing your patch series, I encountered a number of build issues after applying your patches, and building on the latest master. The following patches address the build failures I have encountered. Could you squash them into your commits, so that those fixes are part of your v2 ? Of course, please do some testing, as I have only done build testing so far.
Thank you for this series, I was actually working on the v2020.04 branch, and I think this explains why I was not seeing such errors.
Quoted 2 lines
Also, even with those fixes in place, I do still get a worrying gcc warning (from gcc 10):
I will update my gcc version, because currently I am using gcc 7.5.
Quoted 13 lines
fs/squashfs/sqfs_inode.c: In function ?sqfs_find_inode?:fs/squashfs/sqfs_inode.c:72:34: warning: array subscript l is outside array bounds of ?struct squashfs_directory_index[0]? [-Warray-bounds]
72 |index_list_size+= ldir.index[l].size + 1;
| ~~~~~~~~~~^~~ In file included fromfs/squashfs/sqfs_inode.c:16:fs/squashfs/sqfs_filesystem.h:207:34:
note: while referencing ?index? 207 | structsquashfs_directory_indexindex[0]; |
^~~~~fs/squashfs/sqfs_inode.c:31:29: note: defined here ?ldir?
31 | structsquashfs_ldir_inodeldir;
| ^~~~
Quoted 1 line
Could you investigate this ?
Surely I will, thanks!
Quoted 17 lines
Thanks,
Thomas
Thomas Petazzoni (3):
cmd/sqfs.c,include/fs.h: fix build failures, don't expose
do_sqfs_*() functions globally
fs/squashfs: use "structdisk_partition" instead of
"disk_partition_t" fs/squashfs: do not use CMD_RET_* defines in the filesystem codecmd/sqfs.c | 5 ++-- fs/squashfs/sqfs.c | 66 ++++++++++++++++++++-------------------------- include/fs.h | 12 --------- include/squashfs.h | 4 ++- 4 files changed, 34 insertions(+), 53 deletions(-)
cover squashfs fixes
Quoted 9 lines · On Thu, 16 Jul 2020 09:51:25 +0200 Joao Marcos Costa…
Quoted 6 lines
As I started reviewing your patch series, I encountered a number of build issues after applying your patches, and building on the latest master. The following patches address the build failures I have encountered. Could you squash them into your commits, so that those fixes are part of your v2 ? Of course, please do some testing, as I have only done build testing so far.
Thank you for this series, I was actually working on the v2020.04 branch, and I think this explains why I was not seeing such errors.
OK. When you're submitting patches to U-Boot, since the patches will very likely be applied on master, the patches you send should be based on master. Otherwise, the maintainer who will apply your patches will face the sort of problems that I did face.
Quoted 4 lines
Quoted 2 lines
Also, even with those fixes in place, I do still get a worrying gcc warning (from gcc 10):
I will update my gcc version, because currently I am using gcc 7.5.
You could also keep gcc 7.x on your system, but simply use a gcc 10.x toolchain when cross-compiling U-Boot for ARM for example, as I know you're also testing this on an ARM platform.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 fs/squashfs/sqfs.c: use sqfs_read_sblk() in sqfs_probe()
In reply to Joao Marcos Costasqfs_probe() currently duplicates what sqfs_read_sblk() is doing, so use the latter in the former to avoid some small code duplication.
--- fs/squashfs/sqfs.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
fs/squashfs/sqfs.c +4 -10
@@ -1017,20 +1017,14 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp)int sqfs_probe (struct blk_desc *fs_dev_desc,struct disk_partition *fs_partition) {struct squashfs_super_block *sblk; +int ret; cur_dev = fs_dev_desc; cur_part_info = *fs_partition; - sblk =malloc_cache_aligned (cur_dev->blksz); -if (!sblk) -return -ENOMEM ; - -/* Read SquashFS super block */ -if (sqfs_disk_read (0 ,1 , sblk) !=1 ) { -free (sblk); - cur_dev =NULL ; -return -EINVAL ; - } + ret =sqfs_read_sblk (&sblk); +if (ret) +return ret;/* Make sure it has a valid SquashFS magic number*/ if (sblk->s_magic !=SQFS_MAGIC_NUMBER ) {
Signature · 1 line
2.26.2