tlv_eeprom: remove U-Boot specific code
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Tue, 4 Nov 2025 17:15:40 +0000 (12:15 -0500)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:36:11 +0000 (10:36 -0500)
src/tlv_eeprom.c
src/tlv_eeprom.h

index 491b77a..9481084 100644 (file)
 
 #include "tlv_eeprom.h"
 
-DECLARE_GLOBAL_DATA_PTR;
-
-#define MAX_TLV_DEVICES        2
-
 /* File scope function prototypes */
 static bool is_checksum_valid(u8 *eeprom);
 static int read_eeprom(int devnum, u8 *eeprom);
@@ -39,12 +35,6 @@ static bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval);
 static int set_mac(char *buf, const char *string);
 static int set_date(char *buf, const char *string);
 static int set_bytes(char *buf, const char *string, int *converted_accum);
-static void show_tlv_devices(int current_dev);
-
-/* The EEPROM contents after being read into memory */
-static u8 eeprom[TLV_INFO_MAX_LEN];
-
-static struct udevice *tlv_devices[MAX_TLV_DEVICES];
 
 #define to_header(p) ((struct tlvinfo_header *)p)
 #define to_entry(p) ((struct tlvinfo_tlv *)p)
@@ -145,10 +135,6 @@ static int read_eeprom(int devnum, u8 *eeprom)
                update_crc(eeprom);
        }
 
-#ifdef DEBUG
-       show_eeprom(devnum, eeprom);
-#endif
-
        return ret;
 }
 
@@ -416,147 +402,6 @@ void show_tlv_code_list(void)
        }
 }
 
-/**
- *  do_tlv_eeprom
- *
- *  This function implements the tlv_eeprom command.
- */
-int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-       char cmd;
-       struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
-       static unsigned int current_dev;
-       /* Set to 1 if we've read EEPROM into memory */
-       static int has_been_read;
-       int ret;
-
-       // If no arguments, read the EEPROM and display its contents
-       if (argc == 1) {
-               if (!has_been_read) {
-                       ret = read_eeprom(current_dev, eeprom);
-                       if (ret) {
-                               printf("Failed to read EEPROM data from device.\n");
-                               return 0;
-                       }
-
-                       has_been_read = 1;
-               }
-               show_eeprom(current_dev, eeprom);
-               return 0;
-       }
-
-       // We only look at the first character to the command, so "read" and
-       // "reset" will both be treated as "read".
-       cmd = argv[1][0];
-
-       // select device
-       if (cmd == 'd') {
-                /* 'dev' command */
-               unsigned int devnum;
-
-               devnum = simple_strtoul(argv[2], NULL, 0);
-               if (devnum >= MAX_TLV_DEVICES) {
-                       printf("Invalid device number\n");
-                       return 0;
-               }
-               current_dev = devnum;
-               has_been_read = 0;
-
-               return 0;
-       }
-
-       // Read the EEPROM contents
-       if (cmd == 'r') {
-               has_been_read = 0;
-               ret = read_eeprom(current_dev, eeprom);
-               if (ret) {
-                       printf("Failed to read EEPROM data from device.\n");
-                       return 0;
-               }
-
-               printf("EEPROM data loaded from device to memory.\n");
-               has_been_read = 1;
-               return 0;
-       }
-
-       // Subsequent commands require that the EEPROM has already been read.
-       if (!has_been_read) {
-               printf("Please read the EEPROM data first, using the 'tlv_eeprom read' command.\n");
-               return 0;
-       }
-
-       // Handle the commands that don't take parameters
-       if (argc == 2) {
-               switch (cmd) {
-               case 'w':   /* write */
-                       prog_eeprom(current_dev, eeprom);
-                       break;
-               case 'e':   /* erase */
-                       strcpy(eeprom_hdr->signature, TLV_INFO_ID_STRING);
-                       eeprom_hdr->version = TLV_INFO_VERSION;
-                       eeprom_hdr->totallen = cpu_to_be16(0);
-                       update_crc(eeprom);
-                       printf("EEPROM data in memory reset.\n");
-                       break;
-               case 'l':   /* list */
-                       show_tlv_code_list();
-                       break;
-               case 'd':   /* dev */
-                       show_tlv_devices(current_dev);
-                       break;
-               default:
-                       return CMD_RET_USAGE;
-               }
-               return 0;
-       }
-
-       // The set command takes one or two args.
-       if (argc > 4)
-               return CMD_RET_USAGE;
-
-       // Set command. If the TLV exists in the EEPROM, delete it. Then if
-       // data was supplied for this TLV add the TLV with the new contents at
-       // the end.
-       if (cmd == 's') {
-               int tcode;
-
-               tcode = simple_strtoul(argv[2], NULL, 0);
-               tlvinfo_delete_tlv(eeprom, tcode);
-               if (argc == 4)
-                       tlvinfo_add_tlv(eeprom, tcode, argv[3]);
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-/**
- *  This macro defines the tlv_eeprom command line command.
- */
-U_BOOT_CMD(tlv_eeprom, 4, 1,  do_tlv_eeprom,
-          "Display and program the system EEPROM data block.",
-          "[read|write|set <type_code> <string_value>|erase|list]\n"
-          "tlv_eeprom\n"
-          "    - With no arguments display the current contents.\n"
-          "tlv_eeprom dev [dev]\n"
-          "    - List devices or set current EEPROM device.\n"
-          "tlv_eeprom read\n"
-          "    - Load EEPROM data from device to memory.\n"
-          "tlv_eeprom write\n"
-          "    - Write the EEPROM data to persistent storage.\n"
-          "tlv_eeprom set <type_code> <string_value>\n"
-          "    - Set a field to a value.\n"
-          "    - If no string_value, field is deleted.\n"
-          "    - Use 'tlv_eeprom write' to make changes permanent.\n"
-          "tlv_eeprom erase\n"
-          "    - Reset the in memory EEPROM data.\n"
-          "    - Use 'tlv_eeprom read' to refresh the in memory EEPROM data.\n"
-          "    - Use 'tlv_eeprom write' to make changes permanent.\n"
-          "tlv_eeprom list\n"
-          "    - List the understood TLV codes and names.\n"
-       );
-
 /**
  *  tlvinfo_find_tlv
  *
@@ -899,56 +744,6 @@ static int set_bytes(char *buf, const char *string, int *converted_accum)
        return 0;
 }
 
-static void show_tlv_devices(int current_dev)
-{
-       unsigned int dev;
-
-       for (dev = 0; dev < MAX_TLV_DEVICES; dev++)
-               if (tlv_devices[dev])
-                       printf("TLV: %u%s\n", dev,
-                              (dev == current_dev) ? " (*)" : "");
-}
-
-static int find_tlv_devices(struct udevice **tlv_devices_p)
-{
-       int ret;
-       int count_dev = 0;
-       struct udevice *dev;
-
-       for (ret = uclass_first_device_check(UCLASS_I2C_EEPROM, &dev);
-                       dev;
-                       ret = uclass_next_device_check(&dev)) {
-               if (ret == 0)
-                       tlv_devices_p[count_dev++] = dev;
-               if (count_dev >= MAX_TLV_DEVICES)
-                       break;
-       }
-
-       return (count_dev == 0) ? -ENODEV : 0;
-}
-
-static struct udevice *find_tlv_device_by_index(int dev_num)
-{
-       struct udevice *local_tlv_devices[MAX_TLV_DEVICES] = {};
-       struct udevice **tlv_devices_p;
-       int ret;
-
-       if (gd->flags & (GD_FLG_RELOC | GD_FLG_SPL_INIT)) {
-               /* Assume BSS is initialized; use static data */
-               if (tlv_devices[dev_num])
-                       return tlv_devices[dev_num];
-               tlv_devices_p = tlv_devices;
-       } else {
-               tlv_devices_p = local_tlv_devices;
-       }
-
-       ret = find_tlv_devices(tlv_devices_p);
-       if (ret == 0 && tlv_devices_p[dev_num])
-               return tlv_devices_p[dev_num];
-
-       return NULL;
-}
-
 /**
  * read_tlv_eeprom - read the hwinfo from i2c EEPROM
  */
@@ -1009,103 +804,3 @@ int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
 
        return 0;
 }
-
-/**
- *  mac_read_from_eeprom
- *
- *  Read the MAC addresses from EEPROM
- *
- *  This function reads the MAC addresses from EEPROM and sets the
- *  appropriate environment variables for each one read.
- *
- *  The environment variables are only set if they haven't been set already.
- *  This ensures that any user-saved variables are never overwritten.
- *
- *  This function must be called after relocation.
- */
-int mac_read_from_eeprom(void)
-{
-       unsigned int i;
-       int eeprom_index;
-       struct tlvinfo_tlv *eeprom_tlv;
-       int maccount;
-       u8 macbase[6];
-       struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
-       int devnum = 0; // TODO: support multiple EEPROMs
-
-       if (read_eeprom(devnum, eeprom)) {
-               log_err("EEPROM: read failed\n");
-               return -1;
-       }
-
-       maccount = 1;
-       if (tlvinfo_find_tlv(eeprom, TLV_CODE_MAC_SIZE, &eeprom_index)) {
-               eeprom_tlv = to_entry(&eeprom[eeprom_index]);
-               maccount = (eeprom_tlv->value[0] << 8) | eeprom_tlv->value[1];
-       }
-
-       memcpy(macbase, "\0\0\0\0\0\0", 6);
-       if (tlvinfo_find_tlv(eeprom, TLV_CODE_MAC_BASE, &eeprom_index)) {
-               eeprom_tlv = to_entry(&eeprom[eeprom_index]);
-               memcpy(macbase, eeprom_tlv->value, 6);
-       }
-
-       for (i = 0; i < maccount; i++) {
-               if (is_valid_ethaddr(macbase)) {
-                       char ethaddr[18];
-                       char enetvar[11];
-
-                       sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
-                               macbase[0], macbase[1], macbase[2],
-                               macbase[3], macbase[4], macbase[5]);
-                       sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
-                       /* Only initialize environment variables that are blank
-                        * (i.e. have not yet been set)
-                        */
-                       if (!env_get(enetvar))
-                               env_set(enetvar, ethaddr);
-
-                       macbase[5]++;
-                       if (macbase[5] == 0) {
-                               macbase[4]++;
-                               if (macbase[4] == 0) {
-                                       macbase[3]++;
-                                       if (macbase[3] == 0) {
-                                               macbase[0] = 0;
-                                               macbase[1] = 0;
-                                               macbase[2] = 0;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       log_debug("EEPROM: %s v%u len=%u\n", eeprom_hdr->signature, eeprom_hdr->version,
-                 be16_to_cpu(eeprom_hdr->totallen));
-
-       return 0;
-}
-
-int serial_read_from_eeprom(int devnum)
-{
-       char serialstr[257];
-       int eeprom_index;
-       struct tlvinfo_tlv *eeprom_tlv;
-
-       if (env_get("serial#"))
-               return 0;
-
-       if (read_eeprom(devnum, eeprom)) {
-               printf("Read failed.\n");
-               return -1;
-       }
-
-       if (tlvinfo_find_tlv(eeprom, TLV_CODE_SERIAL_NUMBER, &eeprom_index)) {
-               eeprom_tlv = to_entry(&eeprom[eeprom_index]);
-               memcpy(serialstr, eeprom_tlv->value, eeprom_tlv->length);
-               serialstr[eeprom_tlv->length] = 0;
-               env_set("serial#", serialstr);
-       }
-
-       return 0;
-}
index 2b1e19b..0f66ab1 100644 (file)
@@ -67,8 +67,6 @@ struct __attribute__ ((__packed__)) tlvinfo_tlv {
 #define TLV_CODE_VENDOR_EXT     0xFD
 #define TLV_CODE_CRC_32         0xFE
 
-#if CONFIG_IS_ENABLED(CMD_TLV_EEPROM)
-
 /**
  * read_tlv_eeprom - Read the EEPROM binary data from the hardware
  * @eeprom: Pointer to buffer to hold the binary data
@@ -113,27 +111,6 @@ int write_tlv_eeprom(void *eeprom, int len, int dev);
 int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
                            struct tlvinfo_tlv **first_entry, int dev);
 
-#else /* !CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
-
-static inline int read_tlv_eeprom(void *eeprom, int offset, int len, int dev)
-{
-       return -ENOSYS;
-}
-
-static inline int write_tlv_eeprom(void *eeprom, int len)
-{
-       return -ENOSYS;
-}
-
-static inline int
-read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
-                       struct tlvinfo_tlv **first_entry, int dev)
-{
-       return -ENOSYS;
-}
-
-#endif /* CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
-
 /**
  *  is_valid_tlvinfo_header
  *