Skip to content
Snippets Groups Projects
Commit 6b8adb75 authored by Tobias Kahlki's avatar Tobias Kahlki Committed by Jonas Höppner
Browse files

[LIB][EEPROM] Add public function to format/init the EEPROM structure

parent 8cab7095
No related branches found
No related tags found
No related merge requests found
...@@ -252,6 +252,68 @@ int seco_eeprom_init(u8 i2c_bus_number, u8 i2c_addr) ...@@ -252,6 +252,68 @@ int seco_eeprom_init(u8 i2c_bus_number, u8 i2c_addr)
return 0; return 0;
} }
int seco_eeprom_format(u8 i2c_bus_number, u8 i2c_addr)
{
struct udevice *i2c_bus;
struct udevice *i2c_device;
u8 buffer[EEPROM_SIZE];
u32 crc = 0;
int i = 0, ret = 0;
/* Setup bus and probe EEPROM */
uclass_get_device_by_seq(UCLASS_I2C, i2c_bus_number, &i2c_bus);
ret = dm_i2c_probe(i2c_bus, i2c_addr, 0, &i2c_device);
if (ret)
{
printf("Error: Unable to probe EEPROM (Bus: 0x%02x / Device: 0x%02x)\n",
i2c_bus_number, i2c_addr);
return ret;
}
/*
* Prepare buffer, set version, calculate
* CRC and write buffer to EEPROM
*/
memset(buffer, 0xFF, sizeof(buffer));
buffer[EEPROM_OFFSET_VERSION] = VERSION_MAJOR;
buffer[EEPROM_OFFSET_VERSION+1] = VERSION_MINOR;
crc = 0xFF * (EEPROM_SIZE - EEPROM_OFFSET_DATA - 1);
crc += VERSION_MAJOR + VERSION_MINOR;
printf("CRC (calc.): %d / CRC (define): %d\n", crc, EEPROM_RESET_CRC);
memcpy(buffer+EEPROM_OFFSET_CRC, &crc, sizeof(crc));
/* Dump buffer before writing */
for (i = 0; i < EEPROM_SIZE; ++i)
{
if (i % 16 == 0)
printf("\n");
printf("0x%02X ", buffer[i]);
}
printf("\n");
ret = dm_i2c_write(i2c_device, 0, buffer, EEPROM_SIZE);
if (ret)
{
printf("Error: Unable to init EEPROM data-structure (Error: %d / Bus: 0x%02x / Device: 0x%02x)\n",
ret, i2c_bus_number, i2c_addr);
return ret;
}
return 0;
}
int seco_eeprom_get_macaddr(u8 *mac_addr) int seco_eeprom_get_macaddr(u8 *mac_addr)
{ {
if (g_eeprom_initialized == false) if (g_eeprom_initialized == false)
......
...@@ -23,6 +23,8 @@ Author: shirin raeisi <shirin.raeisi@seco.com> ...@@ -23,6 +23,8 @@ Author: shirin raeisi <shirin.raeisi@seco.com>
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define EEPROM_RESET_CRC ((0xFF*((EEPROM_SIZE) - (EEPROM_OFFSET_DATA) - 1)) + (VERSION_MAJOR) + (VERSION_MINOR))
enum enum
{ {
UID_BOARD_SERIAL_NUMBER = 0x00, UID_BOARD_SERIAL_NUMBER = 0x00,
...@@ -65,6 +67,7 @@ extern void populate_custom_uid(struct eeprom_ssect subsection); ...@@ -65,6 +67,7 @@ extern void populate_custom_uid(struct eeprom_ssect subsection);
// Exported functions // Exported functions
// --------------------- // ---------------------
int seco_eeprom_init(u8 i2c_bus_number, u8 i2c_addr); int seco_eeprom_init(u8 i2c_bus_number, u8 i2c_addr);
int seco_eeprom_format(u8 i2c_bus_number, u8 i2c_addr);
int seco_eeprom_get_macaddr(u8 *mac_addr); int seco_eeprom_get_macaddr(u8 *mac_addr);
int seco_eeprom_get_panel_id(u8 *panel); int seco_eeprom_get_panel_id(u8 *panel);
int seco_eeprom_get_bsn(char* bsn); int seco_eeprom_get_bsn(char* bsn);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment