RISCV RTOS PROXYFS USER GUIDE

1. OVERVIEW

ProxyFs is used to enable RISCV RTOS to access the file system on the Linux side under DualOs. The basis for this function is inter-core communication through rpmsg. In addition, ProxyFs uses CamFs interface encapsulation to implement related functions in a similar way to operating files under Linux. In this way, CamFs related interfaces can be used to operate files under Linux on RISCV RTOS in the same way as on Linux.

2. RTOS USAGE INTRODUCTION

2.1. CONFIG Configuration

To enable RISCV RTOS ProxyFs, you need to enable the CONFIG_PROXYFS_SUPPORT configuration in the config file of mak/options_chipname_riscv_isw.mak.

# Description = [SYS] Proxyfs Support
# Option_Selection = N/A
CONFIG_PROXYFS_SUPPORT = TRUE

2.2. ProxyFs Software Interface Description

The header file for ProxyFs related software interfaces and definitions is located at kernel/rtk/proj/hdrs/pcupid_riscv_isw/cam_fs_wrapper.h.

2.2.1 CamFsMount

  • Function

    Mount the file system.

  • Syntax

    CamFsRet_e CamFsMount(CamFsFmt_e fmt, const char *szPartName, const char *szMntPath)

  • Parameter

    Parameter name Description
    fmt File system type, use ProxyFs to pass in CAM_FS_FMT_PROXYFS
    szPartName Partition name, ProxyFs passes in NULL
    szMntPath Mount path
  • Return value

    Return value Description
    CAM_FS_OK Success
    CAM_FS_FAIL Failure

2.2.2 CamFsUnmount

  • Function

    Unmount the file system.

  • Syntax

    CamFsRet_e CamFsUnmount(const char *szMntPath)

  • Parameter

    Parameter name Description
    szMntPath Mount path
  • Return value

    Return value Description
    CAM_FS_OK Success
    CAM_FS_FAIL Failure

2.2.3 CamFsShowMount

  • Function

    Display the current mount path.

  • Syntax

    void CamFsShowMount(void)

  • Parameter

    None.

  • Return value

    None.

2.2.4 CamFsOpen

  • Function

    Open the file.

  • Syntax

    CamFsRet_e CamFsOpen(CamFsFd *ptFd, const char *szPath, u32 nFlag, u32 nMode)

  • Parameter

    Parameter name Description
    ptFd File Description symbol
    szPath File path
    nFlag File status flag
    nMode File mode
  • Return value

    Return value Description
    CAM_FS_OK Success
    CAM_FS_FAIL Failure

2.2.5 CamFsClose

  • Function

    Close the file.

  • Syntax

    CamFsRet_e CamFsClose(CamFsFd tFd)

  • Parameter

    Parameter name Description
    tFd File Description symbol
  • Return value

    Return value Description
    CAM_FS_OK Success
    CAM_FS_FAIL Failure

2.2.6 CamFsRead

  • Function

    Read the file data.

  • Syntax

    s32 CamFsRead(CamFsFd tFd, void *pBuf, u32 nCount)

  • Parameter

    Parameter name Description
    tFd File Description symbol
    pBuf Buffer for storing read data
    nCount Maximum number of bytes to read
  • Return value

    Return value Description
    Greater than zero Actual number of data bytes read
    -1 Failure

2.2.7 CamFsWrite

  • Function

    Write in the file.

  • Syntax

    s32 CamFsWrite(CamFsFd tFd, const void *pBuf, u32 nCount);

  • Parameter

    Parameter name Description
    tFd File Description symbol
    pBuf Buffer for storing written data
    nCount Number of bytes of written data
  • Return value

    Return value Description
    Greater than zero Actual number of data bytes written
    -1 Failure

2.2.8 CamFsSeek

  • Function

    Locate the file.

  • Syntax

    s32 CamFsSeek(CamFsFd tFd, u32 nOffset, u32 nWhence)

  • Parameter

    Parameter name Description
    tFd File Description symbol
    nOffset Offset value relative to file location whence
    nWhence Specify the file location
  • Return value

    Return value Description
    Greater than zero The current offset relative to the beginning of the file
    -1 Failure

3. PROXYFS DEMO USAGE INTRODUCTION

3.1. Config Configuration

The demo source code is located in kernel/rtk/proj/sc/application/fs_app/fs_app.c and will be compiled into a CLI CMD named fs_test. To enable demo compilation, enable CONFIG_FS_APP_SUPPORT in the config file mak/options_chipname_riscv_isw.mak.

# Feature_Name = [APPLICATION] Support FS Demo App
# Description = Support FS Demo App
# Option_Selection = TRUE, FALSE
CONFIG_FS_APP_SUPPORT = TRUE

3.2. Demo Use Description

The basic usage of the fs_test CLI command is as follows:

fs_test [command] [parameter1] [parameter2] [parameter3]...

The command options are: open, close, read, write, seek;

The number and meaning of parameter options vary depending on the command options.

3.2.1 fs_test Mounts File Directories

Before performing any file operations, you must first mount the file directory. The command to mount the file directory using fs_test is as follows:

fs_test mount [path]

Path: the path of the mounted file directory, such as /proc;

If the operation is successful, there will be an output similar to the following:

SS-RTOS # fs_test mount /proc
fs_cli_mount: success!

3.2.2 fs_test Opens Files

The command to open files using fs_test is as follows:

fs_test open [file_path] [flags] [mode]

file_path: path to open the file, such as /proc/version;

flags: file status flags, the supported flags are defined in the header file mentioned above:

#define CAM_FS_O_RDONLY 0x00010001
#define CAM_FS_O_WRONLY 0x00020002
#define CAM_FS_O_RDWR   0x00040004
#define CAM_FS_O_CREAT  0x00080008
#define CAM_FS_O_TRUNC  0x02000200
#define CAM_FS_O_APPEND 0x04000400

mode: file modes, which affects the subsequent behavior of reading and writing files, for example, 0 (text mode, reading and writing files will be operated in character form), 1 (hexadecimal mode, reading and writing files will be converted into hexadecimal numbers);

If the operation is successful, there will be an output similar to the following:

SS-RTOS # fs_test mount /proc
fs_cli_mount: success!
SS-RTOS # fs_test open /proc/version 0x00040004 0
fs_cli_open: success!

3.2.3 fs_test Closes Files

The command to open files using fs_test is as follows:

fs_test close

The close command has no parameters, and the last opened file will be closed after execution.

3.2.4 fs_test Reads Files

The command to read a file using fs_test is as follows:

fs_test read [size]

size: the size of the data read;

If the operation is successful, the size bytes of data read will be output:

SS-RTOS # fs_test mount /proc
fs_cli_mount: success!
SS-RTOS # fs_test open /proc/version 0x00040004 0
fs_cli_open: success!
SS-RTOS # fs_test read 50
fs_cli_read[text][50]: Linux version 5.10.117 (payne.chen@xml3bc12803) (a!

It should be noted that before reading a file, you must first use the open command to open the file and execute the read mode. Here, the reading is in character type. If the mode of opening the file before is hexadecimal mode, the output is as follows:

SS-RTOS # fs_test open /proc/version 0x00040004 1
fs_cli_open: success!
SS-RTOS # fs_test read 50
fs_cli_read[hex][50]: 4C 69 6E 75 78 20 76 65 72 73 69 6F 6E 20 35 2E 31 30 2E 31 31 37 20 28 70 61 79 6E 65 2E 63 68 65 6E 40 78 6D 6C 33 62 63 31 32 38 30 33 29 20 28 61

3.2.5 fs_test Writes to Files

The command to write to files using fs_test is as follows:

fs_test write [data]

data: the data to be written. If the file was opened in hexadecimal format, the data size entered here must be an integer multiple of 2.

If the operation is successful, data will be written to the file:

SS-RTOS # fs_test mount /dev
fs_cli_mount: success!
SS-RTOS # fs_test open /dev/null 0x00040004 0
fs_cli_open: success!
SS-RTOS # fs_test write abcdef
fs_cli_write[text][6]: abcdef

It should be noted that before reading a file, you must first use the open command to open the file and execute the read mode. Here, the writing is in character type. If the mode of opening the file before is hexadecimal mode, the corresponding hexadecimal number will be written:

SS-RTOS # fs_test open /dev/null 0x00040004 1
fs_cli_open: success!
SS-RTOS # fs_test write abcdef
fs_cli_write[hex]: 3

3.2.6 fs_test Locates Files

The command to locate files using fs_test is as follows:

fs_test seek [offset] [whence]

offset: offset value relative to the file location whence;

whence: specifies the file location, and several values that support being written and their meanings as follows:

#define CAM_FS_SEEK_SET 0xFF000000 /* seek relative to beginning of file */
#define CAM_FS_SEEK_CUR 0xFF000001 /* seek relative to current file position */
#define CAM_FS_SEEK_END 0xFF000002 /* seek relative to end of file */

The following example repositions the file to the beginning so that previous data can be read repeatedly:

SS-RTOS # fs_test open /proc/version 0x00040004 0
fs_cli_open: success!
SS-RTOS # fs_test read 10
fs_cli_read[text][10]: Linux vers!
SS-RTOS # fs_test read 10
fs_cli_read[text][10]: ion 5.10.1!
SS-RTOS # fs_test seek 0 0xFF000000
fs_cli_seek: 0
SS-RTOS # fs_test read 10
fs_cli_read[text][10]: Linux vers!