⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nvramtotffs.c

📁 Vxworks下的C例子程序
💻 C
字号:
/* nvRamToAta.c - non-volatile RAM mapping to Ata for boot line storage */

/* Copyright 1996 RST Software Industries, Ltd, Israel */

/*
modification history
--------------------
01b,10jun99,mpv       modified to support tffs
01a,25dec96,vlad@rst  created.
*/

/*
DESCRIPTION
This library simulates NVRAM on a Flash Device for boot line
storage only. This library is intended to support targets that
are not accompany with NVRAM and obtain bootrom
image from the Flash device.
*/

#ifndef __NVRAM_TO_TFFS__
#define __NVRAM_TO_TFFS__

/* includes */
 
#include <vxWorks.h>
#include "drv/mem/memDev.h"
#include "config.h"
#include "dosFsLib.h"

/* defines */

/* globals */
/* device names to search for */
char *	nvBlDevNames[] = {"/tffs0"/* default name */ , "c:"};
int	nvBlDevNameInd = (-1);

/******************************************************************************
* nvAtaDevInit - to init DOSFS on the Flash device.
*
* RETURNS OK.
*/

LOCAL STATUS nvTffsDevInit()
    {
    int	fd;
    
    if( nvBlDevNameInd != (-1) )
        return OK;

    if (tffsDrv() == ERROR)
	{
	printErr ("Could not initialize.\n");
	return (ERROR);
	}

    printf ("Attaching to Tffs device... ");

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */
    fd = usrTffsConfig (0,0,"/tffs0"); 

    printErr("Tffs device %s created\n", nvBlDevNames[ 0 ] );

    nvBlDevNameInd = 0;

    return OK;
    }

/*******************************************************************************
*
* sysNvRamSet - write boot linre onto Ata disk
*
* This routine copies a specified string into bootline file on the Ata
* disk.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamGet()
*/

STATUS sysNvRamSet
    (
    char *string,     /* string to be copied into non-volatile RAM */
    int strLen,       /* maximum number of bytes to copy           */
    int offset        /* byte offset into non-volatile RAM         */
    )
    {
    int fd;
    char	name[ 20 ] = {EOS};

    printErr("Store boot line to file. Please wait...\n");

    if( nvTffsDevInit() == ERROR )
    	return ERROR;

    sprintf(name,"%s/bootline.dat", "/tffs0" );
    fd = creat( name, O_WRONLY );
    if( fd == ERROR )
    	{
    	printErr("Error create file to store boot line onto Flash Device\n");
    	return ERROR;
    	}
    if( write(fd, string, strLen ) < strLen )
        {
        printErr("Error store boot line onto Flash Device\n");
        return ERROR;
        }
    close( fd ); 
    return OK;
    }

/*******************************************************************************
* sysNvRamGet - get boot line from Ata disk.
*
* This routine copies the contents of bootline file into a specified
* string.  The string will be terminated with an EOS.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamSet()
*/

STATUS sysNvRamGet
    (
    char *string,     /* string to be copied into non-volatile RAM */
    int strLen,       /* maximum number of bytes to copy           */
    int offset        /* byte offset into non-volatile RAM         */
    )
    {
    int fd;
    char        name[ 20 ] = {EOS};

    printErr("Try to read boot line\n");

    if( nvTffsDevInit() == ERROR )
        return ERROR;

    sprintf(name,"%s/bootline.dat", "/tffs0" );
    fd = open( name, O_RDONLY, 0 );
    if( fd == ERROR )
        {
        printErr("Error: boot line file %s not found\n", name );
        return ERROR;
        }
    if( read(fd, string, strLen ) == ERROR )
        {
        printErr("Error read boot line from Flash Device\n");
        return ERROR;
        }
    string [strLen] = EOS;
    close( fd );
    return OK;
    }

#endif /* __NVRAM_TO_TFFS__ */








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -