mirror of
https://github.com/stefanberger/libtpms
synced 2025-08-26 04:33:40 +00:00

Make sure that the NVRAM offsets and structure sizes are the same on all architectures so that we can fill up the NVRAM on one system and migrate the state to another architecture and it will fit into the NVRAM space there. We leave some space for the first few data structures in the NVRAM to grow. We do this by rounding up the NV_INDEX_RAM_DATA location to the next kb boundary. This moves it from offset 4356 to 5120 on x86_64 and from offset 4332 to 5120 on i386. This now leaves us with the same amount of space for user dynamic NVRAM, which starts beyond offset 5120. We also pad the OBJECT structure with 4 bytes so that it is the same size on 32 and 64 bit architectures. This is a data structure that is used in user dynamic NVRAM and should be the same size on all architectures so that a full NVRAM always fits. Also test the size of the NV_INDEX structure, which already has the same size on all tested architectures (x86_64, i386, arm32, ppc64). Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
59 lines
2.0 KiB
C
59 lines
2.0 KiB
C
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "Implementation.h"
|
|
#include "Tpm.h"
|
|
|
|
/* from Global.h */
|
|
extern BYTE s_indexOrderlyRam[RAM_INDEX_SPACE];
|
|
|
|
int main(void)
|
|
{
|
|
/* ensure that the NVRAM offset of NV_USER_DYNAMIC is at the expected
|
|
location so that there's enough memory for re-constructing NVRAM
|
|
indices etc. into the NVRAM */
|
|
#define NV_INDEX_RAM_DATA_EXP_OFFSET 5120
|
|
if (NV_INDEX_RAM_DATA != NV_INDEX_RAM_DATA_EXP_OFFSET) {
|
|
/* If this ever changes due to growth of the preceding data
|
|
* structure, we need to adjust the total NVRAM memory size
|
|
* for the architecture where this changed (or have all
|
|
* architectures use the same offset.
|
|
*/
|
|
fprintf(stderr,
|
|
"NV_INDEX_RAM_DATA not at expected offset %u but at %u\n",
|
|
NV_INDEX_RAM_DATA_EXP_OFFSET, (unsigned int)NV_INDEX_RAM_DATA);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
#define NV_USER_DYNAMIC_EXP_OFFSET (5120 + 512)
|
|
if (NV_USER_DYNAMIC != NV_USER_DYNAMIC_EXP_OFFSET) {
|
|
fprintf(stderr,
|
|
"NV_USER_DYNAMIC not at expected offset %u but at %u\n",
|
|
NV_USER_DYNAMIC_EXP_OFFSET, (unsigned int)NV_USER_DYNAMIC);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
/*
|
|
* OBJECTs are directly written into NVRAM. We have to make sure that the
|
|
* size of the OBJECT is the same on all architectures so that a full
|
|
* NVRAM fits on all architectures
|
|
*/
|
|
#define OBJECT_EXP_SIZE 1896
|
|
if (sizeof(OBJECT) != OBJECT_EXP_SIZE) {
|
|
fprintf(stderr, "sizeof(OBJECT) does not have expected size of %u bytes"
|
|
"but %zu bytes\n", OBJECT_EXP_SIZE, sizeof(OBJECT));
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
/* Same for NV_INDEX */
|
|
#define NV_INDEX_EXP_SIZE 148
|
|
if (sizeof(NV_INDEX) != NV_INDEX_EXP_SIZE) {
|
|
fprintf(stderr,
|
|
"sizeof(NV_INDEX) does not have expected size of %u bytes"
|
|
"but %zu bytes\n", NV_INDEX_EXP_SIZE, sizeof(NV_INDEX));
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|