Compressing files

The file compression mechanism provided with our flash filesystem is a convenient way to cut flash memory costs for customers. The flash filesystem uses popular deflate/inflate algorithms for fast and efficient compression/decompression.

You can use the deflate utility to compress files in the flash filesystem, either from a shell or as the filter attribute to mkefs. The deflate algorithm provides excellent lossless compression of data and executable files.

The flash filesystem drivers use the inflator utility to transparently decompress files that have been compressed with deflate, which means that you can access compressed files in the flash filesystem without having to decompress them first.

Note: Compressing files can result in significant space savings. But there's a trade-off: it takes longer to access compressed files. Always consider the slowdown of compressed data access and increased CPU usage when designing a system. We've seen systems with restricted flash budget increase their boot time by large factors when using compression.

You can compress files:

The first method is the high-runner case. You can use the deflate utility as a filter for mkefs to compress the files that get built into the flash filesystem. For example, you could use this buildfile to create a 16-megabyte filesystem with compression:

[block_size=128K spare_blocks=1 min_size=16m filter=deflate]
/bin/

You can also precompress the files by using deflate directly. If mkefs detects a compression signature in a file that it's putting into the filesystem, it knows that the file is precompressed, and so it doesn't compress the file again. In either case, mkefs puts the data on the flash filesystem and sets a simple bit in the metadata that tells the flash filesystem that the file needs to be decompressed.

The second method is to use deflate to compress files and store them directly in the flash filesystem. For example, here's how to use deflate at the command line to compress the ls file from the image filesystem into a flash filesystem:

$ deflate /proc/boot/ls -o /fs0p0/ls