| 1 |
/* Microsoft Reference Implementation for TPM 2.0 |
| 2 |
* |
| 3 |
* The copyright in this software is being made available under the BSD |
| 4 |
* License, included below. This software may be subject to other third party |
| 5 |
* and contributor rights, including patent rights, and no such rights are |
| 6 |
* granted under this license. |
| 7 |
* |
| 8 |
* Copyright (c) Microsoft Corporation |
| 9 |
* |
| 10 |
* All rights reserved. |
| 11 |
* |
| 12 |
* BSD License |
| 13 |
* |
| 14 |
* Redistribution and use in source and binary forms, with or without |
| 15 |
* modification, are permitted provided that the following conditions are met: |
| 16 |
* |
| 17 |
* Redistributions of source code must retain the above copyright notice, this |
| 18 |
* list of conditions and the following disclaimer. |
| 19 |
* |
| 20 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 21 |
* this list of conditions and the following disclaimer in the documentation |
| 22 |
* and/or other materials provided with the distribution. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS |
| 25 |
* IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 26 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 28 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 31 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 32 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 33 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 34 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 |
*/ |
| 36 |
//** Description |
| 37 |
// |
| 38 |
// This file contains the NV read and write access methods. This |
| 39 |
// implementation uses RAM/file and does not manage the RAM/file as NV |
| 40 |
// blocks. The implementation may become more sophisticated over time. |
| 41 |
// |
| 42 |
|
| 43 |
#include <assert.h> |
| 44 |
#include <string.h> |
| 45 |
|
| 46 |
#include "PlatformData.h" |
| 47 |
#include "Platform_fp.h" |
| 48 |
|
| 49 |
unsigned char s_NV[NV_MEMORY_SIZE]; |
| 50 |
|
| 51 |
void _plat__NvMemoryRead(unsigned int start, unsigned int size, void *data) { |
| 52 |
assert(start + size <= NV_MEMORY_SIZE); |
| 53 |
memcpy(data, &s_NV[start], size); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
int _plat__NvIsDifferent(unsigned int start, unsigned int size, void *data) { |
| 58 |
return (memcmp(&s_NV[start], data, size) != 0); |
| 59 |
} |
| 60 |
|
| 61 |
bool _plat__NvMemoryWrite(unsigned int start, unsigned int size, void *data) { |
| 62 |
if (start + size <= NV_MEMORY_SIZE) { |
| 63 |
memcpy(&s_NV[start], data, size); |
| 64 |
return true; |
| 65 |
} |
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
void _plat__NvMemoryClear(unsigned int start, unsigned int size) { |
| 70 |
assert(start + size <= NV_MEMORY_SIZE); |
| 71 |
// In this implementation, assume that the erase value for NV is all 1s |
| 72 |
memset(&s_NV[start], 0xff, size); |
| 73 |
} |
| 74 |
|
| 75 |
void _plat__NvMemoryMove(unsigned int sourceOffset, unsigned int destOffset, |
| 76 |
unsigned int size) { |
| 77 |
assert(sourceOffset + size <= NV_MEMORY_SIZE); |
| 78 |
assert(destOffset + size <= NV_MEMORY_SIZE); |
| 79 |
memmove(&s_NV[destOffset], &s_NV[sourceOffset], size); |
| 80 |
return; |
| 81 |
} |