ROMFS

From uGFX Wiki
Jump to: navigation, search

ROMFS is used to store files in the flash (or anywhere else) of your target system. The file system (the files and folders it contains) are listed in a file called romfs_files.h which you have to provide yourself. All files you want in your ROMFS must be converted into a C array which then is #include'd into romfs_files.h. This is done using the file2c program which is part of the µGFX repository. It can be found under /tools/file2c and it comes with precompiled binaries for Linux and Windows. However, note that we do not take any responsibility for the binaries, use them on your own risk!

Let's take a look at the usage of file2c:

file2c [-dbcs] [-n name] [-f file] [inputfile] [outputfile]
        -?      This help
        -h      This help
        -d      Add a directory entry for the ROM file system
        -b      Break the arrays for compilers that won't handle large arrays
        -c      Declare as const (useful to ensure they end up in Flash)
        -s      Declare as static
        -n name Use "name" as the name of the array
        -f file Use "file" as the filename in the ROM directory entry

Any binary can be converted to a C-Header file using the following command. In this example we convert a GIF image. Note that the file will not be image decoded, the binary information is just expressed as a C-Array so we can include it into our project.

./file2c -dcs image.gif image.h

A simple romfs_file.h looks like the following:

/**
 * This file contains the list of files for ROMFS.
 *
 * The files have been converted using...
 * 		file2c -dcs infile outfile
 */
#include "image1.h"
#include "image2.h"
#include "image3.h"

The ROMFS does not provide directory handling as this would bloat. However, you can create a directory hierarchy yourself by changing the file names. For example, instead of myFile.h you can name it dir1/dir2/myfile.h.