^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ===========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) Cramfs - cram a filesystem onto a small ROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ===========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) cramfs is designed to be simple and small, and to compress things well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) It uses the zlib routines to compress a file one page at a time, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) allows random page access. The meta-data is not compressed, but is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) expressed in a very terse representation to make it use much less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) diskspace than traditional filesystems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) You can't write to a cramfs filesystem (making it compressible and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) compact also makes it _very_ hard to update on-the-fly), so you have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) create the disk image with the "mkcramfs" utility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) Usage Notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) File sizes are limited to less than 16MB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Maximum filesystem size is a little over 256MB. (The last file on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) filesystem is allowed to extend past 256MB.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) Only the low 8 bits of gid are stored. The current version of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) mkcramfs simply truncates to 8 bits, which is a potential security
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) issue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Hard links are supported, but hard linked files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) will still have a link count of 1 in the cramfs image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Cramfs directories have no ``.`` or ``..`` entries. Directories (like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) every other file on cramfs) always have a link count of 1. (There's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) no need to use -noleaf in ``find``, btw.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) No timestamps are stored in a cramfs, so these default to the epoch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (1970 GMT). Recently-accessed files may have updated timestamps, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) the update lasts only as long as the inode is cached in memory, after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) which the timestamp reverts to 1970, i.e. moves backwards in time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Currently, cramfs must be written and read with architectures of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) same endianness, and can be read only by kernels with PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) == 4096. At least the latter of these is a bug, but it hasn't been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) decided what the best fix is. For the moment if you have larger pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) you can just change the #define in mkcramfs.c, so long as you don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mind the filesystem becoming unreadable to future kernels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) Memory Mapped cramfs image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) --------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) The CRAMFS_MTD Kconfig option adds support for loading data directly from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) a physical linear memory range (usually non volatile memory like Flash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) instead of going through the block device layer. This saves some memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) since no intermediate buffering is necessary to hold the data before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) decompressing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) And when data blocks are kept uncompressed and properly aligned, they will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) automatically be mapped directly into user space whenever possible providing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) eXecute-In-Place (XIP) from ROM of read-only segments. Data segments mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) read-write (hence they have to be copied to RAM) may still be compressed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) the cramfs image in the same file along with non compressed read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) segments. Both MMU and no-MMU systems are supported. This is particularly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) handy for tiny embedded systems with very tight memory constraints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) The location of the cramfs image in memory is system dependent. You must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) know the proper physical address where the cramfs image is located and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) configure an MTD device for it. Also, that MTD device must be supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) by a map driver that implements the "point" method. Examples of such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) MTD drivers are cfi_cmdset_0001 (Intel/Sharp CFI flash) or physmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) (Flash device in physical memory map). MTD partitions based on such devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) are fine too. Then that device should be specified with the "mtd:" prefix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) as the mount device argument. For example, to mount the MTD device named
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "fs_partition" on the /mnt directory::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) $ mount -t cramfs mtd:fs_partition /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) To boot a kernel with this as root filesystem, suffice to specify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) something like "root=mtd:fs_partition" on the kernel command line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) Tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) -----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) A version of mkcramfs that can take advantage of the latest capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) described above can be found here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) https://github.com/npitre/cramfs-tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) For /usr/share/magic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ===== ======================= =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) 0 ulelong 0x28cd3d45 Linux cramfs offset 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) >4 ulelong x size %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) >8 ulelong x flags 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) >12 ulelong x future 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) >16 string >\0 signature "%.16s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) >32 ulelong x fsid.crc 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) >36 ulelong x fsid.edition %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) >40 ulelong x fsid.blocks %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) >44 ulelong x fsid.files %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) >48 string >\0 name "%.16s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 512 ulelong 0x28cd3d45 Linux cramfs offset 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) >516 ulelong x size %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) >520 ulelong x flags 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) >524 ulelong x future 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) >528 string >\0 signature "%.16s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) >544 ulelong x fsid.crc 0x%x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) >548 ulelong x fsid.edition %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) >552 ulelong x fsid.blocks %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) >556 ulelong x fsid.files %d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) >560 string >\0 name "%.16s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ===== ======================= =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) Hacker Notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) See fs/cramfs/README for filesystem layout and implementation notes.