aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/tools/tlv_eeprom/eeprom-id.c
diff options
context:
space:
mode:
authorMichael Auchter <michael.auchter@ni.com>2019-09-09 16:46:14 -0500
committerMartin Braun <martin@gnuradio.org>2021-05-31 05:28:47 -0700
commit530cb0a8aaaac906fe124086e780d6651241b0ad (patch)
tree8a5301163392b3d0c1642da0cb9ba2a9ea176401 /mpm/tools/tlv_eeprom/eeprom-id.c
parentfa997d52cc62c3c39f5b7560890e31d41e4eb9e9 (diff)
downloaduhd-530cb0a8aaaac906fe124086e780d6651241b0ad.tar.gz
uhd-530cb0a8aaaac906fe124086e780d6651241b0ad.tar.bz2
uhd-530cb0a8aaaac906fe124086e780d6651241b0ad.zip
mpm: add tlv_eeprom
Add support for parsing an eeprom that uses tag-length-value to store contents. Co-authored-by: Michael Auchter <michael.auchter@ni.com> Co-authored-by: Virendra Kakade <virendra.kakade@ni.com> Co-authored-by: Cristina Fuentes <cristina.fuentes@ni.com>
Diffstat (limited to 'mpm/tools/tlv_eeprom/eeprom-id.c')
-rw-r--r--mpm/tools/tlv_eeprom/eeprom-id.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/mpm/tools/tlv_eeprom/eeprom-id.c b/mpm/tools/tlv_eeprom/eeprom-id.c
new file mode 100644
index 000000000..e00732f0a
--- /dev/null
+++ b/mpm/tools/tlv_eeprom/eeprom-id.c
@@ -0,0 +1,66 @@
+//
+// Copyright 2021 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tlv_eeprom.h"
+#include "tlv_eeprom_io.h"
+#include "usrp_eeprom.h"
+#include "eeprom-pids.h"
+
+int main(int argc, char **argv)
+{
+ struct tlv_eeprom *eeprom;
+ const struct usrp_eeprom_module_info *module_info;
+ const struct usrp_eeprom_board_info *board_info;
+ const struct pid_info *pid_info;
+ unsigned int pid, rev;
+ const char *serial;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <eeprom>\n", argv[0]);
+ return 1;
+ }
+
+ eeprom = tlv_eeprom_read_from_file(argv[1]);
+ if (tlv_eeprom_validate(eeprom, USRP_EEPROM_MAGIC)) {
+ fprintf(stderr, "failed to validate eeprom\n");
+ return 1;
+ }
+
+ module_info = tlv_lookup(eeprom->tlv, eeprom->size,
+ USRP_EEPROM_MODULE_INFO_TAG);
+ board_info = tlv_lookup(eeprom->tlv, eeprom->size,
+ USRP_EEPROM_BOARD_INFO_TAG);
+
+ if (module_info) {
+ serial = module_info->serial;
+ pid = module_info->pid;
+ rev = module_info->rev;
+ } else if (board_info) {
+ serial = board_info->serial;
+ pid = board_info->pid;
+ rev = board_info->rev;
+ } else {
+ fprintf(stderr, "couldn't find module_info or board_info\n");
+ return 1;
+ }
+
+ pid_info = get_info_from_pid(pid);
+
+ if (pid_info && pid_info->name) {
+ printf("product=ni-%s-rev%u\n", pid_info->name, rev + pid_info->rev_offset);
+ } else if (pid_info && pid_info->description) {
+ printf("product=ni-(%s)-rev%u\n", pid_info->description, rev + pid_info->rev_offset);
+ } else {
+ printf("product=unknown-(%04x)\n", pid);
+ }
+ printf("serial=%s\n", serial);
+
+ free(eeprom);
+ return 0;
+}