www.pudn.com > Demo C.rar > nvRamToAta.c
/* nvRamToAta.c - non-volatile RAM mapping to Ata 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 Ata disk for boot line storage only. This library is intended to PC-x86 targets, that are not accompany with NVRAM or flash memory and obtain bootrom image from Ata disk. */ #ifndef __NVRAM_TO_ATA__ #define __NVRAM_TO_ATA__ /* includes */ #include#include "drv/mem/memDev.h" #include "config.h" #include "dosFsLib.h" /* defines */ /* globals */ /* device names to search for */ char * nvBlDevNames[] = {"/ata0"/* default name */ , "c:"}; int nvBlDevNameInd = (-1); /****************************************************************************** * nvAtaDevInit - to init DOSFS on the Ata device. * * RETURNS OK. */ LOCAL STATUS nvAtaDevInit() { int fd; BLK_DEV *pBootDev; int ctrl = 0; ATA_RESOURCE *pAtaResource = &ataResources[ctrl]; if( nvBlDevNameInd != (-1) ) return OK; if (ataDrv (ctrl, pAtaResource->drives, pAtaResource->intVector, pAtaResource->intLevel, pAtaResource->configType, pAtaResource->semTimeout, pAtaResource->wdgTimeout) == ERROR) { printErr ("Could not initialize.\n"); return (ERROR); } printf ("Attaching to ATA disk device... "); dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ fd = usrAtaConfig (0,0,"/ata0"); printErr("Ata 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( nvAtaDevInit() == ERROR ) return ERROR; sprintf(name,"%s/bootline.dat", "/ata0" ); fd = creat( name, O_WRONLY ); if( fd == ERROR ) { printErr("Error create file to store boot line onto Ata disk\n"); return ERROR; } if( write(fd, string, strLen ) < strLen ) { printErr("Error store boot line onto Ata disk\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( nvAtaDevInit() == ERROR ) return ERROR; sprintf(name,"%s/bootline.dat", "/ata0" ); 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 Ata disk\n"); return ERROR; } string [strLen] = EOS; close( fd ); return OK; } #endif /* __NVRAM_TO_ATA__ */