From 6494e823b46ced400764b6203d7480c9e3badc20 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Fri, 13 Mar 2026 11:42:26 +0100 Subject: spl: add squashfs support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement spl_load_image_sqfs() in spl code. This will be used in MMC to read a file from a squashfs partition. Also, loosen squashfs read checks on file size by not failing when a bigger size than the actual file size is requested. (Just read the file) This is needed for FIT loading, because the length is ALIGNed. Signed-off-by: Richard Genoud Reviewed-by: Miquel Raynal Reviewed-by: João Marcos Costa --- common/spl/Makefile | 1 + common/spl/spl_squashfs.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 common/spl/spl_squashfs.c (limited to 'common') diff --git a/common/spl/Makefile b/common/spl/Makefile index 4c9482bd309..53cc45fc5b9 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_$(PHASE_)OPENSBI) += spl_opensbi.o obj-$(CONFIG_$(PHASE_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(PHASE_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(PHASE_)FS_EXT4) += spl_ext.o +obj-$(CONFIG_$(PHASE_)FS_SQUASHFS) += spl_squashfs.o obj-$(CONFIG_$(PHASE_)LOAD_IMX_CONTAINER) += spl_imx_container.o obj-$(CONFIG_$(PHASE_)SATA) += spl_sata.o obj-$(CONFIG_$(PHASE_)NVME) += spl_nvme.o diff --git a/common/spl/spl_squashfs.c b/common/spl/spl_squashfs.c new file mode 100644 index 00000000000..d3b1c70bfc4 --- /dev/null +++ b/common/spl/spl_squashfs.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Paratronic + * Copyright (C) 2026 Bootlin + * + * Author: Richard Genoud + * + */ + +#include +#include +#include +#include +#include +#include +#include + +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, + ulong size, void *buf) +{ + struct legacy_img_hdr *header; + char *filename = load->priv; + loff_t actread; + int ret; + + ret = sqfs_read(filename, buf, file_offset, size, &actread); + if (ret) + return ret; + + if (CONFIG_IS_ENABLED(OS_BOOT)) { + header = (struct legacy_img_hdr *)buf; + if (image_get_magic(header) != FDT_MAGIC) + return size; + } + + return actread; +} + +int spl_load_image_sqfs(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev, + struct blk_desc *block_dev, int partition, + const char *filename) +{ + int err; + loff_t size = 0; + struct spl_load_info load; + struct disk_partition part_info = {}; + + err = part_get_info(block_dev, partition, &part_info); + if (err) { + printf("spl: no partition table found\n"); + goto end; + } + + err = sqfs_probe(block_dev, &part_info); + if (err) { + printf("spl: sqfs probe err part_name:%s type=%s err=%d\n", + part_info.name, part_info.type, err); + goto end; + } + + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) { + err = sqfs_size(filename, &size); + if (err) + goto end; + } + + spl_load_init(&load, spl_fit_read, (void *)filename, 1); + + err = spl_load(spl_image, bootdev, &load, size, 0); + +end: + if (err < 0) + printf("%s: error reading image %s, err - %d\n", + __func__, filename, err); + + return err; +} -- cgit v1.2.3 From fb0df3552892ff150edaf7579989fd4750ee85ee Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Fri, 13 Mar 2026 11:42:27 +0100 Subject: spl: mmc: support squashfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit spl_mmc_do_fs_boot supports now loading an image from squashfs. Also, convert #if defined(CONFIG_SPL_xx) to if (CONFIG_IS_ENABLED(xx)) Signed-off-by: Richard Genoud Reviewed-by: Miquel Raynal Reviewed-by: João Marcos Costa --- common/spl/spl_mmc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 47cfe4aef58..cc16709dc9b 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -226,6 +226,11 @@ static int __maybe_unused spl_mmc_fs_load(struct spl_image_info *spl_image, if (!err) return 0; } + if (CONFIG_IS_ENABLED(FS_SQUASHFS)) { + err = spl_load_image_sqfs(spl_image, bootdev, blk_dev, part, file); + if (!err) + return 0; + } return err; } @@ -284,13 +289,15 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, u32 __weak spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) { -#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) - return MMCSD_MODE_FS; -#elif defined(CONFIG_SUPPORT_EMMC_BOOT) - return MMCSD_MODE_EMMCBOOT; -#else + if (CONFIG_IS_ENABLED(FS_FAT) || + CONFIG_IS_ENABLED(FS_EXT4) || + CONFIG_IS_ENABLED(FS_SQUASHFS)) + return MMCSD_MODE_FS; + + if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) + return MMCSD_MODE_EMMCBOOT; + return MMCSD_MODE_RAW; -#endif } #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION -- cgit v1.2.3