Bootlin contributes SquashFS support to U-Boot

SquashFS is a very popular read-only compressed root filesystem, widely used in embedded systems. It has been supported in the Linux kernel for many years, but so far the U-Boot bootloader did not have support for SquashFS, so it was not possible to load a kernel image or a Device Tree Blob from a SquashFS filesystem in U-Boot.

Between February 2020 and August 2020, João Marcos Costa from the ENSICAEN engineering school, has worked at Bootlin as an intern. João’s internship goal was specifically to implement and contribute to U-Boot the support for the SquashFS filesystem. We are happy to announce that João’s effort has now completed, as the support for SquashFS is now in upstream U-Boot. It can be found in fs/squashfs/ in the U-Boot source code.

More specifically, João’s contributions have been:

In addition to those contributions already merged, João has also submitted for inclusion the support for LZO and ZSTD decompression support.

Practically speaking, this SquashFS support works very much like the support for other filesystems. At build time, you need to enable the CONFIG_FS_SQUASHFS option for the SquashFS driver itself, and CONFIG_CMD_SQUASHFS for the SquashFS U-Boot commands. Once enabled, in U-Boot, you get:

=> sqfsls     
sqfsls - List files in directory. Default: root (/).
 
Usage:
sqfsls  [] [directory]
    - list files from 'dev' on 'interface' in 'directory'
 
=> sqfsload 
sqfsload - load binary file from a SquashFS filesystem
 
Usage:
sqfsload  [ [ [ [bytes [pos]]]]]
    - Load binary file 'filename' from 'dev' on 'interface'
      to address 'addr' from SquashFS filesystem.
      'pos' gives the file position to start loading from.
      If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.
      'bytes' gives the size to load. If 'bytes' is 0 or omitted,
      the load stops on end of file.
      If either 'pos' or 'bytes' are not aligned to
      ARCH_DMA_MINALIGN then a misaligned buffer warning will
      be printed and performance will suffer for the load.

sqfsls is obviously used to list files, here the list of files from a typical Linux root filesystem:

=> sqfsls mmc 0:1
            bin/
            boot/
            dev/
            etc/
            lib/
    <SYM>   lib32
    <SYM>   linuxrc
            media/
            mnt/
            opt/
            proc/
            root/
            run/
            sbin/
            sys/
            tmp/
            usr/
            var/
 
2 file(s), 16 dir(s)

And then you can use sqfsload to load files, which we illustrate here by loading a Linux kernel image and Device Tree blob, and booting this kernel:

=> sqfsload mmc 0:1 $kernel_addr_r /boot/zImage
6160384 bytes read in 433 ms (13.6 MiB/s)
=> sqfsload mmc 0:1 0x81000000 /boot/am335x-boneblack.dtb
40817 bytes read in 11 ms (3.5 MiB/s)
=> setenv bootargs console=ttyO0,115200n8
=> bootz $kernel_addr_r - 0x81000000
## Flattened Device Tree blob at 81000000
   Booting using the fdt blob at 0x81000000
   Loading Device Tree to 8fff3000, end 8fffff70 ... OK
 
Starting kernel ...
 
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.19.79 (joaomcosta@joaomcosta-Latitude-E7470) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05)) #1 SMP Fri May 29 18:26:39 CEST 2020
[    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d

Of course, the SquashFS driver is still fresh, and there is a chance that more extensive and widespread testing will uncover a few bugs or limitations, which we’re sure the broader U-Boot community will help address. Overall, we’re really happy to have contributed this new functionality to U-Boot, it will be useful for our projects, and we hope it will be useful to many others in the embedded Linux community!

Thomas Petazzoni

Author: Thomas Petazzoni

Thomas Petazzoni is Bootlin's co-owner and CEO. Thomas joined Bootlin in 2008 as a kernel and embedded Linux engineer, became CTO in 2013, and co-owner/CEO in 2021. More details...

5 thoughts on “Bootlin contributes SquashFS support to U-Boot”

  1. Gongrats Bootlin ! I guess this is on EU funding, well spend, if you ask me.
    I hope you do short post for the other 4 internships and then a final recap for all 5.
    Keep up the good work!

    1. This is not at all on EU funding. This is all funded on Bootlin’s own resources. If you know how to get EU funding for this kind of activity, we’re interested 🙂

      Also, we haven’t had 5 internships this summer, only 2 internships. One on SquashFS, the other one on MIPI CSI-2 support for the camera interface of some Allwinner platforms. We will post about this a bit later.

      1. Then more and bigger Congrats for you! There is definitely such E.U. program(s) I’ve seen such intership listings on IT jobs websites and earlier this year I heard a discussion about it on the radio. Try contacting the E.U office or the Labor department in your region. Good luck !

        I’m your fan,
        https://bootlin.com/blog/2020-internships/
        Here it says all positions filled. So after Allwinner MIPI-CSI and U-boot Squashfs I though the
        others are done too (especially the Allwinner video encoding).

  2. Hello,

    Is it possible to list files or load a file (for instance the kernel) from a squashfs image standing in an UBI volume ?

    I am a little bit confused about how to use the sqfsls or sqfsload command.

    I generate an UBI image with several volumes (uboot_config, userfs, rootfs, …) and write it in the UBI mtd partition:
    ——–
    device spi-nand0 , # parts = 4
    #: name size offset mask_flags
    0: fsbl 0x00200000 0x00000000 0
    1: ssbl1 0x00200000 0x00200000 0
    2: ssbl2 0x00200000 0x00400000 0
    3: UBI 0x0fa00000 0x00600000 0
    ——–

    The rootfs UBI volume contains the squashfs compressed with xz. I can read it with the command “ubi read 0xc2000000 rootfs 52441088” for instance. But I do not find the way to use sqfsls. If I issue the command “sqfsls ubi rootfs1”, I see this error: “”UBIFS not mounted, use ubifsmount to mount volume first!”. I looked into the uboot source code and indeed, there is a check with “!ubifs_is_mounted()” if the “ubi” interface is used.

    1. This would require something similar to ubiblock from Linux, but which hasn’t been ported to U-Boot. So I’d say additional development is probably needed to be able to access a SquashFS filesystem stored in a UBI volume in U-Boot.

Leave a Reply