Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

fopen - Memory Mapped Files

Altera_Forum
Honored Contributor II
1,210 Views

Is there a way to have fopen read a file whose contents reside in flash/ram (i.e. not from stdin/stdout rs232/jtag)? 

 

Using the nios-ide, I flashed a file into Flash where I have plenty of space, but at runtime I need to perform FILE type operations on it. If I just pass the (flash) memory address as the handle and cast it as FILE, it doesn't work, the typedef FILE has a host of elements, but the memory address contains just the data.  

 

How is this generally done? Is there a way to mount a pointer that points to data such that fopen/fgetc/etc work? Since I'm low on ram, I'd hate to have to copy the same data just to serialize it! type=memory, memmapfile / MMFIO
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
463 Views

If your file resides in CFI flash then would it work to just cast it as a char array? You'd have nice access for reads, but you'd have to manage the sector-at-a-time issues of flash when writing (erasing/programming). 

 

If not, then if it's read-only access you're after, rozip_fs might be enough. Otherwise, you're looking at more work to emulate filesystem-like behavior and/or porting an existing filesystem to Nios II HAL. 

 

Of course, none of this applies if you're using uClinux/Linux running on Nios II. 

 

Cheers, 

 

- slacker
0 Kudos
Reply