[PATCH v3 2/4] cmd: tlv_eeprom: Add support for do_mac() command
Artur Rojek
artur at conclusive.pl
Mon Oct 2 14:42:15 CEST 2023
The existing mac_read_from_eeprom() is supposed to be used in
conjunction with CONFIG_ID_EEPROM=y. However, when this config option is
enabled, it also expects the do_mac() command to be implemented.
Provide tlv_eeprom's implementation of the do_mac() command. At this
point only the "read" option is supported.
Signed-off-by: Artur Rojek <artur at conclusive.pl>
---
v3: new patch
cmd/tlv_eeprom.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c
index 9aa9b070473e..3e9972e506b6 100644
--- a/cmd/tlv_eeprom.c
+++ b/cmd/tlv_eeprom.c
@@ -1088,6 +1088,57 @@ int mac_read_from_eeprom(void)
return 0;
}
+#if defined(CONFIG_ID_EEPROM)
+int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct tlvinfo_tlv *eeprom_tlv;
+ int i, eeprom_index, maccount, devnum = 0;
+ u8 macbase[6], *octet_p;
+
+ /* Only the "read" command supported for now. */
+ if (argc > 1 && strcmp(argv[1], "read")) {
+ printf("\"%s\" command not supported\n", argv[1]);
+ return 0;
+ }
+
+ if (read_eeprom(devnum, eeprom))
+ return 0;
+
+ 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);
+ }
+
+ if (!is_valid_ethaddr(macbase))
+ return 0;
+
+ for (i = 0; i < maccount; i++) {
+ printf("EEPROM MAC Address #%d: %02X:%02X:%02X:%02X:%02X:%02X\n",
+ i, macbase[0], macbase[1], macbase[2], macbase[3],
+ macbase[4], macbase[5]);
+
+ /* Increment next MAC address. */
+ for (octet_p = &macbase[5]; ++*octet_p == 0; octet_p--) {
+ if (octet_p == &macbase[3]) {
+ macbase[2] = 0;
+ macbase[1] = 0;
+ macbase[0] = 0;
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+#endif
+
static int populate_serial_number(int devnum)
{
char serialstr[257];
--
2.42.0
More information about the U-Boot
mailing list