www.pudn.com > Demo C.rar > nvRamToFloppy.c
/* nvRamToFloppy.c - non-volatile RAM mapping to floppy for boot line storage */ /* Copyright 1996 RST Software Industries, Ltd, Israel */ /* modification history -------------------- 01a,25dec96,vlad@rst created. */ /* DESCRIPTION This library simulates NVRAM on a floppy disk for boot line storage only. This library is intended for PC-x86 targets, that are not accompany with NVRAM or flash memory and obtain bootrom image from floppy disk. */ #ifndef __NVRAM_TO_FLOPPY__ #define __NVRAM_TO_FLOPPY__ /* includes */ #include#include "drv/mem/memDev.h" /* defines */ /* globals */ /* device names to search for */ char * nvBlDevNames[] = {"/fd0"/* default name */ , "A:"}; int nvBlDevNameInd = (-1); /****************************************************************************** * nvFloppyDevInit - to init DOSFS on the floppy device. * * RETURNS OK. */ LOCAL STATUS nvFloppyDevInit() { int fd; BLK_DEV *pBootDev; if( nvBlDevNameInd != (-1) ) return OK; for( nvBlDevNameInd = 0; nvBlDevNameInd < NELEMENTS( nvBlDevNames ); nvBlDevNameInd ++ ) { fd = open( nvBlDevNames[ nvBlDevNameInd ], O_RDONLY, 0 ); if( fd != ERROR ) goto ret; } nvBlDevNameInd = (-1); /* create floppy device */ fdDrv (FD_INT_VEC, FD_INT_LVL); /* initialize floppy disk driver */ if ((pBootDev = fdDevCreate (0, 0, 0, 0)) == NULL) { printErr ("fdDevCreate failed.\n"); return (ERROR); } dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ if (dosFsDevInit ( nvBlDevNames[ 0 ], pBootDev, NULL) == NULL) { printErr ("dosFsDevInit failed.\n"); return (ERROR); } fd = open( nvBlDevNames[ 0 ], O_RDONLY, 0 ); if( fd == ERROR ) { printErr ("floppy device %s create error\n", nvBlDevNames[ 0 ] ); return (ERROR); } printErr("Floppy device %s created\n", nvBlDevNames[ 0 ] ); nvBlDevNameInd = 0; ret: close( fd ); return OK; } /******************************************************************************* * * sysNvRamSet - write boot linre onto floppy disk * * This routine copies a specified string into bootline file on the floppy * 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("Storing boot line to file. Please wait...\n"); if( nvFloppyDevInit() == ERROR ) return ERROR; sprintf(name,"%s/bootline.dat", nvBlDevNames[ nvBlDevNameInd ] ); fd = creat( name, O_WRONLY ); if( fd == ERROR ) { printErr("Error creating file to store boot line on floppy disk\n"); return ERROR; } if( write(fd, string, strLen ) < strLen ) { printErr("Error storing boot line on floppy disk\n"); return ERROR; } close( fd ); return OK; } /******************************************************************************* * sysNvRamGet - get boot line from floppy 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("Reading boot line\n"); if( nvFloppyDevInit() == ERROR ) return ERROR; sprintf(name,"%s/bootline.dat", nvBlDevNames[ nvBlDevNameInd ] ); 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 reading boot line from floppy disk\n"); return ERROR; } string [strLen] = EOS; close( fd ); return OK; } #endif /* __NVRAM_TO_FLOPPY__ */