📄 sysnvram.c
字号:
/* sysNvRam.c - x86 nvram api for block devices *//* * Copyright 1984-2005 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. *//*modification history--------------------01e,11aug05,pcm corrected NVRAMFILE pathname01d,29jul05,pcm changed INCLUDE_DOSFS to INCLUDE_DOSFS_MAIN01c,15jun05,pcm dosFs is now removable01b,18jul02,rhe Remove possible compile time warning message. SPR 7985701a,20jun02,dmh created. now even without eeprom peecees have storage for the bootline*//*DESCRIPTION:This file implements the nvram api using standard io system callsfor non-volatile media such as flash ram, floppy disks and hard diskdrives. It is primarily intended for saving and modifying boot parametersbut could in theory be used for general purpose information. A file ofNV_RAM_SIZE size is used for storing the "nvram" data.*//* includes */#include <vxWorks.h>#include <logLib.h>#include <string.h>#include "config.h"#define NVRAMFILE "/nvram.txt"#define NVRAMPATH BOOTROM_DIR "" NVRAMFILE/********************************************************************************* sysNvRam_mount - make file system accessible** This routine is called from sysNvRamSet and sysNvRamGet and handles* the storage media specific details.** RETURNS: N/A** NOMANUAL*/static void sysNvRam_mount() { int ctrl = 0; u_char * pVolDesc;#if defined(INCLUDE_ATA) && (SYS_WARM_TYPE == SYS_WARM_ATA) IMPORT ATA_RESOURCE ataResources[]; ATA_RESOURCE *pAtaResource = &ataResources[ctrl];#endif ctrl = 0;#if !defined(INCLUDE_DOSFS_MAIN) && !defined(INCLUDE_DOSFS) /* * For the moment, assume that DosFS is required to access the simulated * non-volatile ram. As DosFS is not included, do not initialize the * floppy, ATA, nor TFFS. The subsequent call to open() by the parent * will fail. */ return;#else /* INCLUDE_DOSFS_MAIN || INCLUDE_DOSFS */ /* if BOOTROM_DIR has already been mounted do not try remounting it */ if (dosFsVolDescGet (BOOTROM_DIR, &pVolDesc) != NULL) return;#if defined(INCLUDE_FD) && (SYS_WARM_TYPE == SYS_WARM_FD) if (fdDrv (FD_INT_VEC, FD_INT_LVL) != OK) return; if(usrFdConfig (ctrl, 0, BOOTROM_DIR) != OK) { logMsg("%s: usrFdConfig failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); return; }#endif#if defined(INCLUDE_ATA) && (SYS_WARM_TYPE == SYS_WARM_ATA) if (ataDrv (ctrl, pAtaResource->drives, pAtaResource->intVector, pAtaResource->intLevel, pAtaResource->configType, pAtaResource->semTimeout, pAtaResource->wdgTimeout) == ERROR) { return; } if (usrAtaConfig (ctrl, 0, BOOTROM_DIR) != OK) { logMsg ("%s: usrAtaConfig failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); return; }#endif#if defined(INCLUDE_TFFS) && (SYS_WARM_TYPE == SYS_WARM_TFFS) if (tffsDrv () != OK) return; if (usrTffsConfig (ctrl, 0, BOOTROM_DIR) != OK) { logMsg ("%s: usrTffsConfig failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); return; }#endif #endif /* INCLUDE_DOSFS_MAIN, INCLUDE_DOSFS */ }/******************************************************************************** sysNvRamGet - get the contents of non-volatile RAM** This routine copies the contents of non-volatile memory into a specified* string. The string is terminated with an EOS.** RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.** SEE ALSO: sysNvRamSet()*/STATUS sysNvRamGet ( char *string, /* where to copy non-volatile RAM */ int strLen, /* maximum number of bytes to copy */ int offset /* byte offset into non-volatile RAM */ ) { int fd, bytes; if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE)) return (ERROR); sysNvRam_mount (); fd = open (NVRAMPATH, O_RDWR, 0); if (fd == ERROR) { logMsg ("%s: open failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); return (ERROR); } bytes = read (fd, string, strLen); if (bytes == ERROR) { logMsg ("%s: read failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); close (fd); return (ERROR); } else { string[bytes] = EOS; close (fd); return (OK); } }/********************************************************************************* sysNvRamSet - write to non-volatile RAM** This routine copies a specified string into non-volatile RAM.** 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; if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE)) return (ERROR); sysNvRam_mount (); fd = open (NVRAMPATH, O_RDWR | O_CREAT, 2); if (fd == ERROR) { logMsg ("%s: open failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); return (ERROR); } if (write (fd, string, strLen) != strLen) { logMsg ("%s: write failed\n", (int)__FUNCTION__, 0, 0, 0, 0, 0); close (fd); return (ERROR); } else { close (fd); return (OK); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -