VPD ECC support
Added methods/interfaces to create ECC and verify the data using ECC
Tested: tested some of the EEPROMS on Rainier simics
root@rainier:/tmp# ./ipz-read-vpd --file /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0050/8-00500/nvmem
PASSED
root@rainier:/tmp# ./ipz-read-vpd --file /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a400.i2c-bus/i2c-7/7-0050/7-00500/nvmem
PASSED
root@rainier:/tmp# ./ipz-read-vpd --file /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem
PASSED
root@rainier:/tmp# ./ipz-read-vpd --file /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a400.i2c-bus/i2c-7/7-0051/7-00510/nvmem
PASSED
root@rainier:/tmp# ./ipz-read-vpd --file /sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a080.i2c-bus/i2c-0/0-0051/0-00510/nvmem
PASSED
Signed-off-by: Alpana Kumari <alpankum@in.ibm.com>
Change-Id: I863327f504c2dfa468d5ceadce10250292a968b7
diff --git a/vpdecc/vpdecc.c b/vpdecc/vpdecc.c
new file mode 100644
index 0000000..f7cf7eb
--- /dev/null
+++ b/vpdecc/vpdecc.c
@@ -0,0 +1,21 @@
+#include "vpdecc.h"
+
+#include <string.h>
+
+int vpdecc_create_ecc(const unsigned char* data, size_t data_length,
+ unsigned char* ecc, size_t* ecc_buffersize)
+{
+ int i, vRet = 0;
+
+ memset(ecc, 0, *ecc_buffersize);
+
+ return vRet;
+}
+
+int vpdecc_check_data(unsigned char* data, size_t data_length,
+ const unsigned char* ecc, size_t ecc_length)
+{
+ int vRet = 0;
+
+ return vRet;
+}
diff --git a/vpdecc/vpdecc.h b/vpdecc/vpdecc.h
new file mode 100644
index 0000000..6e7605f
--- /dev/null
+++ b/vpdecc/vpdecc.h
@@ -0,0 +1,87 @@
+/******************************************************************************
+ *
+ * IBM Confidential
+ *
+ * Licensed Internal Code Source Materials
+ *
+ * IBM Flexible Support Processor Licensed Internal Code
+ *
+ * (c) Copyright IBM Corp. 2004
+ *
+ * The source code is for this program is not published or otherwise divested
+ * of its trade secrets, irrespective of what has been deposited with the
+ * U.S. Copyright Office.
+ *
+ *****************************************************************************/
+
+#ifndef _VPDECC_H_
+#define _VPDECC_H_
+
+#include <stdlib.h>
+
+#define VPD_ECC_OK 0
+#define VPD_ECC_NOT_ENOUGH_BUFFER 1
+#define VPD_ECC_WRONG_ECC_SIZE 2
+#define VPD_ECC_WRONG_BUFFER_SIZE 9
+#define VPD_ECC_UNCORRECTABLE_DATA 90
+#define VPD_ECC_CORRECTABLE_DATA 91
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* TODO doxygen !!!!!!!! */
+
+/******************************************************************************/
+/* vpdecc_create_ecc */
+/* */
+/* For a given data block (together with the length of the data block */
+/* this function creates the ECC */
+/* */
+/* @param pData In-Buffer containing the raw VPD data */
+/* (wont't be changed) */
+/* */
+/* @param vDataLength In should contain the length of the Data */
+/* in the buffer given to vData */
+/* */
+/* @param pEcc Out-Buffer after execution this will be the */
+/* buffer for the calculated Ecc */
+/* */
+/* @param pEccLenght In/Out In : size of buffer */
+/* Out: contains the length of the Ecc */
+/* */
+/* @return Error returncode */
+/******************************************************************************/
+int vpdecc_create_ecc(const unsigned char* data, size_t datalength,
+ unsigned char* ecc, size_t* ecc_buffersize);
+
+/******************************************************************************/
+/* vpdecc_check_data */
+/* */
+/* For a given data block (together with the ecc) */
+/* this function checks the data for validness */
+/* */
+/* @param pData In-Buffer containing the raw VPD data */
+/* Out-Buffer containing the raw VPD data */
+/* No error : data unchanged */
+/* Correctable error : data corrected */
+/* Uncorrectable error: data unchanged */
+/* */
+/* @param vDataLength In should contain the length of the Data */
+/* in the buffer given to vData */
+/* */
+/* @param pEcc In-Buffer should contain the Ecc for the data */
+/* */
+/* */
+/* @param vEccLenght In should contain the length of the Ecc */
+/* */
+/* @return Error returncode */
+/******************************************************************************/
+int vpdecc_check_data(unsigned char* data, size_t data_length,
+ const unsigned char* ecc, size_t ecc_length);
+
+#ifdef __cplusplus
+} /* end extern "C" */
+#endif
+
+#endif /* endif _VPDECC_H_ */
diff --git a/vpdecc/vpdecc_support.c b/vpdecc/vpdecc_support.c
new file mode 100644
index 0000000..674f236
--- /dev/null
+++ b/vpdecc/vpdecc_support.c
@@ -0,0 +1,75 @@
+
+#include "vpdecc_support.h"
+
+#include <string.h>
+
+/******************************************************************************/
+/* seepromGetEcc */
+/* */
+/* Calculates the 7 bit ECC code of a 32 bit data word and returns it */
+/* */
+/******************************************************************************/
+inline unsigned char seepromGetEcc(const unsigned char* data)
+{
+ unsigned char vResult = 0x00;
+ return vResult;
+}
+
+/******************************************************************************/
+/* */
+/******************************************************************************/
+int seepromScramble(const int bitOffset, const unsigned char* cleanData,
+ size_t cleanSize, unsigned char* scrambledData,
+ size_t scrambledSize)
+{
+ int vRet = 0;
+ return vRet;
+}
+
+/******************************************************************************/
+/* */
+/******************************************************************************/
+int seepromUnscramble(const int bitOffset, const unsigned char* scrambledData,
+ size_t scrambledSize, unsigned char* cleanData,
+ size_t cleanSize)
+{
+ int vRet = 0;
+ return vRet;
+}
+
+/******************************************************************************/
+/* seepromGenCsDecode */
+/* */
+/* */
+/******************************************************************************/
+void seepromGenCsDecode(const unsigned char numBits,
+ const unsigned char syndrom,
+ const unsigned char* csdSyndroms,
+ unsigned char* vResult)
+{
+}
+
+/******************************************************************************/
+/* seepromGenerateCheckSyndromDecode */
+/* */
+/* */
+/******************************************************************************/
+void seepromGenerateCheckSyndromDecode(const unsigned char checkSyndrom,
+ unsigned char* csdData,
+ unsigned char* csdEcc)
+{
+}
+
+/******************************************************************************/
+/* seepromEccCheck */
+/* */
+/* Checks the data integrety and correct it if possible */
+/* */
+/******************************************************************************/
+
+int seepromEccCheck(unsigned char* vData, unsigned char* vEcc,
+ size_t numOfWords)
+{
+ int vRet = 0;
+ return vRet;
+}
diff --git a/vpdecc/vpdecc_support.h b/vpdecc/vpdecc_support.h
new file mode 100644
index 0000000..6f71c03
--- /dev/null
+++ b/vpdecc/vpdecc_support.h
@@ -0,0 +1,45 @@
+#include "vpdecc.h"
+
+/******************************************************************************/
+unsigned char seepromGetEcc(const unsigned char* data);
+
+/******************************************************************************/
+/* seepromScramble */
+/******************************************************************************/
+
+int seepromScramble(const int bitOffset, const unsigned char* cleanData,
+ size_t cleanSize, unsigned char* scrambledData,
+ size_t scrambledSize);
+
+/******************************************************************************/
+/******************************************************************************/
+int seepromUnscramble(const int bitOffset, const unsigned char* scrambledData,
+ size_t scrambledSize, unsigned char* cleanData,
+ size_t cleanSize);
+
+/******************************************************************************/
+/******************************************************************************/
+void seepromGenCsDecode(const unsigned char numBits,
+ const unsigned char syndrom,
+ const unsigned char* csdSyndroms,
+ unsigned char* vResult);
+
+/******************************************************************************/
+/* seepromGenerateCheckSyndromDecode */
+/******************************************************************************/
+void seepromGenerateCheckSyndromDecode(const unsigned char checkSyndrom,
+ unsigned char* csdData,
+ unsigned char* csdEcc);
+
+/******************************************************************************/
+/******************************************************************************/
+int seepromEccCheck(unsigned char* vData, unsigned char* vEcc,
+ size_t numOfDataBytes);
+
+/******************************************************************************/
+/******************************************************************************/
+/*int seepromCheckData(unsigned char* seepromData);*/
+
+/******************************************************************************/
+/******************************************************************************/
+/*int seepromCreateEcc(unsigned char* seepromData);*/