summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJérémy Dufour2013-01-22 15:26:23 +0100
committerJérémy Dufour2013-01-30 10:45:43 +0100
commit3ddc712b01040b4f8e2a04da344a0c10cb8a603f (patch)
tree7537b87ca7c576709b495bb38541d53993c7f6dd /common
parenta77cb86a9175584181c15f6f0cac0fe4cb665420 (diff)
common/include/asm/arch: add a sanity check for NVRAM size, refs #3709
This commit add a sanity check which will be triggered if the sizeof of the NVRAM structure does not match the expected one: this can occur if the sizeof of some fields added to the structure changes depending on the architecture (pointers for example).
Diffstat (limited to 'common')
-rw-r--r--common/include/asm/arch/nvram.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/common/include/asm/arch/nvram.h b/common/include/asm/arch/nvram.h
index cefbf563b9..93abfa6457 100644
--- a/common/include/asm/arch/nvram.h
+++ b/common/include/asm/arch/nvram.h
@@ -136,6 +136,39 @@ typedef struct
#endif /* CONFIG_CHIP_FEATURE_EXTRA_NVRAM_FIELDS */
} spidcom_nvram_t; //Currently __attribute__((packed)) not needed
+/**
+ * Size, in bytes, of the NVRAM structure.
+ * This define will help tracking problem when structure of the NVRAM differs
+ * from the expected one (architecture 64 bits vs 32 bits for example).
+ */
+#ifdef CONFIG_CHIP_FEATURE_EXTRA_NVRAM_FIELDS
+# define SPIDCOM_NVRAM_SIZE 2320
+#else
+# define SPIDCOM_NVRAM_SIZE 1776
+#endif
+
+/**
+ * Create a negative define if size of NVRAM structure has changed.
+ * This define will be computed to a negative value if the size of the NVRAM
+ * structure differs from SPIDCOM_NVRAM_SIZE. Otherwise, if the size is the
+ * same, the define will be set to 1.
+ */
+#define error_size (1 - (2 * \
+ (sizeof (spidcom_nvram_t) != SPIDCOM_NVRAM_SIZE)))
+
+/**
+ * Report the error_size to the user during build process.
+ * This typedef will failed to compile if error_size is negative. If during
+ * build process you encounter an error (i.e.: array size is negative), you
+ * need to check modification done on spidcom_nvram_t structure (the size of
+ * the structure should be the same on different architecture) and/or you need
+ * to update the SPIDCOM_NVRAM_SIZE according to the change you made to the
+ * spidcom_nvram_t structure.
+ */
+typedef char spidcom_nvram_sizeof_does_not_match[error_size];
+
+#undef error_size
+
/* genNVRAM needs to know the sizes of the "sub-NVRAMs". But, as we only have
* one structure now, we can not use a sizeof anymore. */
#define SPC300_NVRAM_SIZE (SPC300_NVRAM_LAST_FIELD_OFFSET - SPC300_NVRAM_FIRST_FIELD_OFFSET)