User guide

Nios II IDE Help System
Host-Based File System
The host-based file system enables programs executing on a target board to read and write
files stored on the host computer. The Nios II IDE transmits file data over the Altera download
cable. Your program accesses the host based file system using the ANSI C standard library I/O
functions, such as fopen() and fread(). The host-based file system is a software component
which you add to your system library.
The following features and restrictions apply to the host based file system:
The host-based file system makes the Nios II C/C++ application project directory and
its subdirectories available to the hardware abstraction layer (HAL) file system on the
target hardware.
The target processor can access any file in the project directory. Be careful not to
corrupt project source files.
The host-based file system only operates while debugging a project. It cannot be used
for run sessions.
Host file data travels between host and target serially through the Altera download
cable, and therefore file access time is relatively slow. It takes approximately 10 ms
per call to the host. For higher performance, use buffered I/O (fread(), fwrite(),
etc.), and increase the buffer size for large files.
You configure the host-based file system using the Software Components
dialog box. The
host-based file system has the following setting:
Mount-point—Specifies the mount point within the HAL file system. For example, if
you name the mount point /mnt/host and the project directory on you host
computer is /software/project1, the code fopen("/mnt/host/foo.dat", "r"); in
a HAL-based program opens the file /software/project1/foo.dat.
Example Programs
The Host File System project template in the New Project wizard contains one example of
using the host-based file system.
The following code is another example program that uses the host-based file system to read
and display its own source code.
/*
* "hello_hostfs.c" example.
*
* This example reads the file "hello_hostfs.c" (ie this file) from the
* project directory on the host and writes it to the STDOUT stream.
* It runs on any design which includes a hostfs software component,
* with any RTOS (or no RTOS) and requires a STDOUT device in your
* system's hardware.
*
*/
#include <stdio.h>
int main()
{
FILE * hostfile = fopen("/mnt/host/hello_hostfs.c", "r");
char buffer[1024];
while (fgets(buffer, sizeof(buffer), hostfile) != NULL)
84