Skip to content
Snippets Groups Projects
Commit c5c8ef55 authored by Federico Vaga's avatar Federico Vaga
Browse files

lib|tools: dump EEPROM content to stdout


Signed-off-by: default avatarFederico Vaga <federico.vaga@cern.ch>
parent 6fddf58a
Branches
Tags
No related merge requests found
......@@ -34,6 +34,8 @@ int fmc_slot_eeprom_type_get(struct fmc_tkn *tkn, unsigned int slot_n,
char *str, size_t max_len);
int fmc_slot_eeprom_type_set(struct fmc_tkn *tkn, unsigned int slot_n,
const char *str, size_t max_len);
int fmc_slot_eeprom_size(struct fmc_tkn *tkn, unsigned int slot_n,
unsigned int *size);
int fmc_slot_eeprom_read(struct fmc_tkn *tkn, unsigned int slot_n,
char *buf, size_t len, off_t offset);
int fmc_slot_eeprom_write(struct fmc_tkn *tkn, unsigned int slot_n,
......
......@@ -368,6 +368,24 @@ int fmc_slot_eeprom_type_set(struct fmc_tkn *tkn, unsigned int slot_n,
return err;
}
int fmc_slot_eeprom_size(struct fmc_tkn *tkn, unsigned int slot_n,
unsigned int *size)
{
struct fmc_carrier *carrier = (struct fmc_carrier *)tkn;
struct fmc_slot *slot = __fmc_slot_get(carrier, slot_n);
char len_c[8];
unsigned long len;
strncpy(len_c, slot->eeprom_type + 3, sizeof(len_c));
len = strtol(len_c, NULL, 10);
if (errno == ERANGE || errno == EINVAL)
return - 1;
*size = (len * 1024) / 8;
return 0;
}
int fmc_slot_eeprom_read(struct fmc_tkn *tkn, unsigned int slot_n,
char *buf, size_t len, off_t offset)
{
......
......@@ -23,7 +23,8 @@ static void help(void)
"\t-h print help\n"
"\t-c carrier number\n"
"\t-s slot number\n"
"\t-t EEPROM type to set\n",
"\t-t EEPROM type to set\n"
"\t-d dump EEPROM content\n",
name);
}
......@@ -33,6 +34,29 @@ static void print_version(void)
name, git_version, fmc_version_get());
}
static void print_dump(struct fmc_tkn *fmc, unsigned int slot_n,
const char *eeprom_type)
{
char *buf;
unsigned int len;
int ret;
ret = fmc_slot_eeprom_size(fmc, slot_n, &len);
if (ret < 0)
fputs("Failed to get EEPROM size\n", stderr);
buf = malloc(len);
if (!buf) {
fputs("Failed to allocate buffer\n", stderr);
return;
}
ret = fmc_slot_eeprom_read(fmc, slot_n, buf, len, 0);
if (ret > 0)
fwrite(buf, len, 1, stdout);
else
fputs("Failed to read EEPROM\n", stderr);
}
int main(int argc, char *argv[])
{
struct fmc_tkn *fmc;
......@@ -41,6 +65,7 @@ int main(int argc, char *argv[])
char *eeprom_type = NULL;
char eeprom_type_rb[16];
int err = 0;
int dump = 0;
char opt;
name = strndup(basename(argv[0]), 64);
......@@ -48,7 +73,7 @@ int main(int argc, char *argv[])
err = -1;
goto out_strdup;
}
while ((opt = getopt(argc, argv, "h?Vc:s:t:")) != -1) {
while ((opt = getopt(argc, argv, "h?Vc:s:t:d")) != -1) {
switch (opt) {
case 'h':
case '?':
......@@ -71,6 +96,9 @@ int main(int argc, char *argv[])
case 't':
eeprom_type = optarg;
break;
case 'd':
dump = 1;
break;
}
}
if (carr_n == FMC_ID_INVALID || slot_n == FMC_ID_INVALID) {
......@@ -90,8 +118,12 @@ int main(int argc, char *argv[])
}
fmc_slot_eeprom_type_get(fmc, slot_n,
eeprom_type_rb, sizeof(eeprom_type_rb));
fprintf(stdout, "fmc-slot.%u.%u EEPROM type %s\n",
carr_n, slot_n, eeprom_type_rb);
if (dump == 0)
fprintf(stdout, "fmc-slot.%u.%u EEPROM type %s\n",
carr_n, slot_n, eeprom_type_rb);
else
print_dump(fmc, slot_n, eeprom_type_rb);
fmc_carrier_close(fmc);
out_open:
out_invalid:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment