tlv-eeprom: adapt for integration with hvtlv
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Wed, 5 Nov 2025 05:14:05 +0000 (00:14 -0500)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:36:11 +0000 (10:36 -0500)
Replace calls to i2c_eeprom_read/write and call eeprom_block_read/write
from main.c.

Use zlib crc32 function.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
src/tlv_eeprom.c
src/tlv_eeprom.h

index 904c6bb..4b2dfb4 100644 (file)
@@ -9,17 +9,16 @@
  * Copyright (C) 2014,2016 david_yang <david_yang@accton.com>
  */
 
-#include <command.h>
-#include <dm.h>
-#include <i2c.h>
-#include <i2c_eeprom.h>
-#include <env.h>
-#include <init.h>
-#include <net.h>
-#include <asm/global_data.h>
-#include <linux/ctype.h>
-#include <u-boot/crc.h>
-
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <zlib.h> /* For crc32 routine */
+
+#include "linux-compat.h"
 #include "tlv_eeprom.h"
 
 /* File scope function prototypes */
@@ -744,16 +743,8 @@ static int set_bytes(char *buf, const char *string, int *converted_accum)
  */
 int read_tlv_eeprom(void *eeprom, int offset, int len, int dev_num)
 {
-       struct udevice *dev;
-
-       if (dev_num >= MAX_TLV_DEVICES)
-               return -EINVAL;
-
-       dev = find_tlv_device_by_index(dev_num);
-       if (!dev)
-               return -ENODEV;
-
-       return i2c_eeprom_read(dev, offset, eeprom, len);
+       (void) dev_num;
+       return eeprom_block_read(offset, eeprom, len);
 }
 
 /**
@@ -761,12 +752,8 @@ int read_tlv_eeprom(void *eeprom, int offset, int len, int dev_num)
  */
 int write_tlv_eeprom(void *eeprom, int len, int dev)
 {
-       if (!(gd->flags & GD_FLG_RELOC))
-               return -ENODEV;
-       if (!tlv_devices[dev])
-               return -ENODEV;
-
-       return i2c_eeprom_write(tlv_devices[dev], 0, eeprom, len);
+       (void) dev;
+       return eeprom_block_write(0, eeprom, len);
 }
 
 int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
index 8e0516a..10c479a 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <linux/errno.h>
 
+#include "linux-compat.h"
+
 /*
  *  The Definition of the TlvInfo EEPROM format can be found at onie.org or
  *  github.com/onie
@@ -137,4 +139,8 @@ int prog_eeprom(int devnum, u8 *eeprom);
 int read_eeprom(int devnum, u8 *eeprom);
 void show_tlv_code_list(void);
 
+/* Callbacks in main.c */
+int eeprom_block_read(int offset, uint8_t *buf, int size);
+int eeprom_block_write(int offset, const uint8_t *buf, int size);
+
 #endif /* __TLV_EEPROM_H_ */