Gregory N
2012-03-27 16:10:26 UTC
I'm also interested exploring how the NuttX ROMFS compares to a Linux root file system as far as adding executables.
Executables work great with NXFLAT and ROMFS. NXFLAT is described here: http://nuttx.sourceforge.net/NuttXNxFlat.html . ROMFS is a standard read-only file system described here: http://romfs.sourceforge.net/ . ROMFS supports XIP so that you do not have to copy the data to SRAM; rather you can eXecute-In-Place in the ROMFS file system. ROMFS is unique in that way. NXFLAT mmap's the file and ROMFS support XIP memory mapping.If you don't use ROMFS then you have to use the mmap() emulation. Without an MMU, you can't really support true mmap(), but NuttX has a mmap() emulation that will copy the whole file into SRAM where it can executed. This is kind of a pricey solution for most SRAM-limited MCUs.
The NuttX root file system is always a psuedo-filesystem. It is just the opposite from Linux. With Linux the root file system must always be some physical block device (if only an initrd ram disk). Then once you have mounted the physical root file system, you can mount other file systems -- including Linux psuedo-filesystems like /proc or /sys. With NuttX, the root file system is always a pseudo-filesystem that does not require any underlying block driver or physical device. Then you can mount real filesystem in the pseudo-filesystem.
This arrangement makes life much easier for the tiny embedded world (but also has a few limitations --- like where you can mount file systems).
So in this case here, ROMFS would not be the root file system. But could be mounted at any location under / in the psuedo-filesystem. If you want executables, you could mount a ROMFS file system at /bin for example.
I'm used to simply populating a /bin folder in an embedded root file system image with the programs I want to execute at run time.
If you are using, say, a FAT file system and a the copy-to-SRAM mmap() emulation. Then it could be just like this. However, that is not usually a good solution unless you have tons of RAM to copy images because FAT is not XIP.ROMFS has can reside in any random-access FLASH and XIP will work if that FLASH supports code execution. The ROMFS image can be built-into the main program on the MCU's internal FLASH using the nuttx/tools/mkromfsetc.sh script. Or the ROMFS image could be written to an external NOR FLASH using standard techniques.
In these cases, I think that the procedure is still more or less as you would have to do it in Linux. You have to create the file system image, run genromfs to create a ROMFS image of the file system, and then install the ROMFS image in FLASH. ROMFS is a read-only file-system so you would never be able to add anything to the bin/ folder, even with NuttX.
A bigger issue is symbol tables. That will probably cause you more problems. When external NXFLAT programs are loaded, they have to be dynamically linked with the base code. This requires two symbol tables: One in the NXFLAT module that enumerates all of the symbols needed by the NXFLAT module (imports). And another in the FLASH base code the enumerates all of the symbols available in the base code (exports).
There are examples of how to do this in apps/examples/nxflat and apps/examples/thttpd. The THTTPD example is particularly cool. There NXFLAT executables are used to implement true CGI, complete with I/O re-direction of standard I/O to the TCP connection.
Greg