18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=========================================== 48c2ecf20Sopenharmony_ciCramfs - cram a filesystem onto a small ROM 58c2ecf20Sopenharmony_ci=========================================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cicramfs is designed to be simple and small, and to compress things well. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciIt uses the zlib routines to compress a file one page at a time, and 108c2ecf20Sopenharmony_ciallows random page access. The meta-data is not compressed, but is 118c2ecf20Sopenharmony_ciexpressed in a very terse representation to make it use much less 128c2ecf20Sopenharmony_cidiskspace than traditional filesystems. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciYou can't write to a cramfs filesystem (making it compressible and 158c2ecf20Sopenharmony_cicompact also makes it _very_ hard to update on-the-fly), so you have to 168c2ecf20Sopenharmony_cicreate the disk image with the "mkcramfs" utility. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciUsage Notes 208c2ecf20Sopenharmony_ci----------- 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciFile sizes are limited to less than 16MB. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciMaximum filesystem size is a little over 256MB. (The last file on the 258c2ecf20Sopenharmony_cifilesystem is allowed to extend past 256MB.) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciOnly the low 8 bits of gid are stored. The current version of 288c2ecf20Sopenharmony_cimkcramfs simply truncates to 8 bits, which is a potential security 298c2ecf20Sopenharmony_ciissue. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciHard links are supported, but hard linked files 328c2ecf20Sopenharmony_ciwill still have a link count of 1 in the cramfs image. 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciCramfs directories have no ``.`` or ``..`` entries. Directories (like 358c2ecf20Sopenharmony_cievery other file on cramfs) always have a link count of 1. (There's 368c2ecf20Sopenharmony_cino need to use -noleaf in ``find``, btw.) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciNo timestamps are stored in a cramfs, so these default to the epoch 398c2ecf20Sopenharmony_ci(1970 GMT). Recently-accessed files may have updated timestamps, but 408c2ecf20Sopenharmony_cithe update lasts only as long as the inode is cached in memory, after 418c2ecf20Sopenharmony_ciwhich the timestamp reverts to 1970, i.e. moves backwards in time. 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciCurrently, cramfs must be written and read with architectures of the 448c2ecf20Sopenharmony_cisame endianness, and can be read only by kernels with PAGE_SIZE 458c2ecf20Sopenharmony_ci== 4096. At least the latter of these is a bug, but it hasn't been 468c2ecf20Sopenharmony_cidecided what the best fix is. For the moment if you have larger pages 478c2ecf20Sopenharmony_ciyou can just change the #define in mkcramfs.c, so long as you don't 488c2ecf20Sopenharmony_cimind the filesystem becoming unreadable to future kernels. 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciMemory Mapped cramfs image 528c2ecf20Sopenharmony_ci-------------------------- 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciThe CRAMFS_MTD Kconfig option adds support for loading data directly from 558c2ecf20Sopenharmony_cia physical linear memory range (usually non volatile memory like Flash) 568c2ecf20Sopenharmony_ciinstead of going through the block device layer. This saves some memory 578c2ecf20Sopenharmony_cisince no intermediate buffering is necessary to hold the data before 588c2ecf20Sopenharmony_cidecompressing. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciAnd when data blocks are kept uncompressed and properly aligned, they will 618c2ecf20Sopenharmony_ciautomatically be mapped directly into user space whenever possible providing 628c2ecf20Sopenharmony_cieXecute-In-Place (XIP) from ROM of read-only segments. Data segments mapped 638c2ecf20Sopenharmony_ciread-write (hence they have to be copied to RAM) may still be compressed in 648c2ecf20Sopenharmony_cithe cramfs image in the same file along with non compressed read-only 658c2ecf20Sopenharmony_cisegments. Both MMU and no-MMU systems are supported. This is particularly 668c2ecf20Sopenharmony_cihandy for tiny embedded systems with very tight memory constraints. 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciThe location of the cramfs image in memory is system dependent. You must 698c2ecf20Sopenharmony_ciknow the proper physical address where the cramfs image is located and 708c2ecf20Sopenharmony_ciconfigure an MTD device for it. Also, that MTD device must be supported 718c2ecf20Sopenharmony_ciby a map driver that implements the "point" method. Examples of such 728c2ecf20Sopenharmony_ciMTD drivers are cfi_cmdset_0001 (Intel/Sharp CFI flash) or physmap 738c2ecf20Sopenharmony_ci(Flash device in physical memory map). MTD partitions based on such devices 748c2ecf20Sopenharmony_ciare fine too. Then that device should be specified with the "mtd:" prefix 758c2ecf20Sopenharmony_cias the mount device argument. For example, to mount the MTD device named 768c2ecf20Sopenharmony_ci"fs_partition" on the /mnt directory:: 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci $ mount -t cramfs mtd:fs_partition /mnt 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciTo boot a kernel with this as root filesystem, suffice to specify 818c2ecf20Sopenharmony_cisomething like "root=mtd:fs_partition" on the kernel command line. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciTools 858c2ecf20Sopenharmony_ci----- 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciA version of mkcramfs that can take advantage of the latest capabilities 888c2ecf20Sopenharmony_cidescribed above can be found here: 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cihttps://github.com/npitre/cramfs-tools 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciFor /usr/share/magic 948c2ecf20Sopenharmony_ci-------------------- 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci===== ======================= ======================= 978c2ecf20Sopenharmony_ci0 ulelong 0x28cd3d45 Linux cramfs offset 0 988c2ecf20Sopenharmony_ci>4 ulelong x size %d 998c2ecf20Sopenharmony_ci>8 ulelong x flags 0x%x 1008c2ecf20Sopenharmony_ci>12 ulelong x future 0x%x 1018c2ecf20Sopenharmony_ci>16 string >\0 signature "%.16s" 1028c2ecf20Sopenharmony_ci>32 ulelong x fsid.crc 0x%x 1038c2ecf20Sopenharmony_ci>36 ulelong x fsid.edition %d 1048c2ecf20Sopenharmony_ci>40 ulelong x fsid.blocks %d 1058c2ecf20Sopenharmony_ci>44 ulelong x fsid.files %d 1068c2ecf20Sopenharmony_ci>48 string >\0 name "%.16s" 1078c2ecf20Sopenharmony_ci512 ulelong 0x28cd3d45 Linux cramfs offset 512 1088c2ecf20Sopenharmony_ci>516 ulelong x size %d 1098c2ecf20Sopenharmony_ci>520 ulelong x flags 0x%x 1108c2ecf20Sopenharmony_ci>524 ulelong x future 0x%x 1118c2ecf20Sopenharmony_ci>528 string >\0 signature "%.16s" 1128c2ecf20Sopenharmony_ci>544 ulelong x fsid.crc 0x%x 1138c2ecf20Sopenharmony_ci>548 ulelong x fsid.edition %d 1148c2ecf20Sopenharmony_ci>552 ulelong x fsid.blocks %d 1158c2ecf20Sopenharmony_ci>556 ulelong x fsid.files %d 1168c2ecf20Sopenharmony_ci>560 string >\0 name "%.16s" 1178c2ecf20Sopenharmony_ci===== ======================= ======================= 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ciHacker Notes 1218c2ecf20Sopenharmony_ci------------ 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciSee fs/cramfs/README for filesystem layout and implementation notes. 124