summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-02-18 11:15:03 -0600
committerMike Fiore <mfiore@multitech.com>2014-02-18 11:15:03 -0600
commit29348251247d0385807752d0a9773e7167084b52 (patch)
treea63794b255eb0a30b5e16354599da47172051877
parent398cd3fec2c60ce8cb9f97be6a768a2ee7b7ff2a (diff)
parente92217e366678be4d556646038963c24bf51982f (diff)
downloadmts-id-eeprom-29348251247d0385807752d0a9773e7167084b52.tar.gz
mts-id-eeprom-29348251247d0385807752d0a9773e7167084b52.tar.bz2
mts-id-eeprom-29348251247d0385807752d0a9773e7167084b52.zip
Merge branch 'daughter-cards'0.2.0
-rw-r--r--src/eeprom_main.c222
1 files changed, 176 insertions, 46 deletions
diff --git a/src/eeprom_main.c b/src/eeprom_main.c
index 29cd45d..29c0f99 100644
--- a/src/eeprom_main.c
+++ b/src/eeprom_main.c
@@ -37,6 +37,11 @@
#include "log.h"
#include "eeprom.h"
+static int eeprom_size = 512;
+
+static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom);
+static void mts_dc_eeprom_inspect(struct mts_dc_eeprom_layout *dc_eeprom);
+
static int hwaddr_aton(const char *str, uint8_t *buf, size_t len)
{
size_t count = 0;
@@ -85,7 +90,7 @@ static int hwaddr_aton(const char *str, uint8_t *buf, size_t len)
return 1;
}
-static int yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom)
+static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom)
{
FILE *file;
@@ -149,7 +154,42 @@ static int yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom)
return 0;
}
-static int bin_out(const char *name, struct mts_id_eeprom_layout *id_eeprom)
+static int dc_yaml_out(const char *name, struct mts_dc_eeprom_layout *dc_eeprom)
+{
+ FILE *file;
+
+ if (!strcmp(name, "-")) {
+ file = stdout;
+ } else {
+ file = fopen(name, "w+");
+ if (!file) {
+ log_error("could not open %s: %m", name);
+ return -1;
+ }
+ }
+
+ fprintf(file, "---\n");
+ fprintf(file, "\n");
+
+ fprintf(file, "vendor-id: \"%.32s\"\n", dc_eeprom->vendor_id);
+ fprintf(file, "product-id: \"%.32s\"\n", dc_eeprom->product_id);
+ fprintf(file, "device-id: \"%.32s\"\n", dc_eeprom->device_id);
+ fprintf(file, "hw-version: \"%.32s\"\n", dc_eeprom->hw_version);
+ fprintf(file, "mac-addr: \"%02X:%02X:%02X:%02X:%02X:%02X\"\n",
+ dc_eeprom->mac_addr[0],
+ dc_eeprom->mac_addr[1],
+ dc_eeprom->mac_addr[2],
+ dc_eeprom->mac_addr[3],
+ dc_eeprom->mac_addr[4],
+ dc_eeprom->mac_addr[5]);
+ fprintf(file, "...\n");
+
+ fclose(file);
+
+ return 0;
+}
+
+static int bin_out(const char *name, char *eeprom)
{
int fd;
int tmp;
@@ -164,11 +204,11 @@ static int bin_out(const char *name, struct mts_id_eeprom_layout *id_eeprom)
}
}
- tmp = write(fd, (char *) id_eeprom, sizeof(*id_eeprom));
+ tmp = write(fd, eeprom, eeprom_size);
if (tmp < 0) {
log_error("writing %s failed: %m", name);
return fd;
- } else if (tmp != sizeof(*id_eeprom)) {
+ } else if (tmp != eeprom_size) {
log_error("only wrote %d bytes to %s", tmp, name);
return -1;
}
@@ -207,7 +247,7 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom)
id_eeprom->mac_bluetooth[3],
id_eeprom->mac_bluetooth[4],
id_eeprom->mac_bluetooth[5]);
- log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
+ log_info("mac-wifi: %02X:%02X:%02X:%02X:%02X:%02X",
id_eeprom->mac_wifi[0],
id_eeprom->mac_wifi[1],
id_eeprom->mac_wifi[2],
@@ -216,6 +256,22 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom)
id_eeprom->mac_wifi[5]);
}
+static void mts_dc_eeprom_inspect(struct mts_dc_eeprom_layout *dc_eeprom)
+{
+ log_info("sizeof: %lu", sizeof(struct mts_dc_eeprom_layout));
+ log_info("vendor-id: %.32s", dc_eeprom->vendor_id);
+ log_info("product-id: %.32s", dc_eeprom->product_id);
+ log_info("device-id: %.32s", dc_eeprom->device_id);
+ log_info("hw-version: %.32s", dc_eeprom->hw_version);
+ log_info("mac-addr: %02X:%02X:%02X:%02X:%02X:%02X",
+ dc_eeprom->mac_addr[0],
+ dc_eeprom->mac_addr[1],
+ dc_eeprom->mac_addr[2],
+ dc_eeprom->mac_addr[3],
+ dc_eeprom->mac_addr[4],
+ dc_eeprom->mac_addr[5]);
+}
+
static void print_version(const char *name) {
printf("%s (" PACKAGE ") " VERSION " (" __DATE__ " " __TIME__ ")\n", name);
printf("Copyright (C) 2010 by Multi-Tech Systems\n");
@@ -246,7 +302,8 @@ static void usage(FILE *out) {
fprintf(out, " --capa-bluetooth |\n");
fprintf(out, " --capa <capa> |\n");
fprintf(out, " --out-format { bin | yaml (default) } |\n");
- fprintf(out, " --update\n");
+ fprintf(out, " --update |\n");
+ fprintf(out, " --daughter-card\n");
fprintf(out, " }\n");
fprintf(out, "\n");
}
@@ -271,6 +328,7 @@ enum {
CMD_OPT_CAPA,
CMD_OPT_OUT_FORMAT,
CMD_OPT_UPDATE,
+ CMD_OPT_DAUGHTER_CARD,
CMD_OPT_VERSION,
CMD_OPT_HELP,
};
@@ -296,6 +354,7 @@ static struct option long_options[] = {
{"capa", 1, NULL, CMD_OPT_CAPA},
{"out-format", 1, NULL, CMD_OPT_OUT_FORMAT},
{"update", 0, NULL, CMD_OPT_UPDATE},
+ {"daughter-card", 0, NULL, CMD_OPT_DAUGHTER_CARD},
{"version", 0, NULL, CMD_OPT_VERSION},
{"help", 0, NULL, CMD_OPT_HELP},
{0, 0, 0, 0},
@@ -311,10 +370,19 @@ int main(int argc, char *argv[]) {
char *out_file = "-";
char *out_format = "yaml";
int update = 0;
+ int daughter_card = 0;
+
+ char *vendor_id = NULL;
+ char *product_id = NULL;
+ char *device_id = NULL;
+ char *hw_version = NULL;
+ char *mac_addr = NULL;
struct mts_id_eeprom_layout id_eeprom;
+ struct mts_dc_eeprom_layout dc_eeprom;
- memset(&id_eeprom, 0, sizeof(id_eeprom));
+ memset(&id_eeprom, 0, eeprom_size);
+ memset(&dc_eeprom, 0, eeprom_size);
#if 0
strncpy(id_eeprom.vendor_id, VENDOR_ID_MULTITECH, sizeof(id_eeprom.vendor_id) - 1);
@@ -343,58 +411,38 @@ int main(int argc, char *argv[]) {
case CMD_OPT_IN_FILE:
in_file = optarg;
- fd = open(in_file, O_RDONLY);
- if (fd < 0) {
- log_error("could not open in-file %s: %m", in_file);
- exit(1);
- }
-
- tmp = read(fd, (char *) &id_eeprom, sizeof(id_eeprom));
- if (tmp < 0) {
- log_error("reading %s failed: %m", in_file);
- exit(1);
- } else if (tmp != sizeof(id_eeprom)) {
- log_error("only read %d bytes from %s", tmp, in_file);
- exit(1);
- }
-
- close(fd);
+ break;
- log_info("loaded eeprom from %s successfully", in_file);
- mts_id_eeprom_inspect(&id_eeprom);
+ case CMD_OPT_UPDATE:
+ update = 1;
+ break;
+ case CMD_OPT_DAUGHTER_CARD:
+ daughter_card = 1;
break;
- case CMD_OPT_UPDATE:
- update = 1;
- break;
case CMD_OPT_OUT_FILE:
out_file = optarg;
break;
case CMD_OPT_VENDOR_ID:
- strncpy(id_eeprom.vendor_id, optarg, sizeof(id_eeprom.vendor_id) - 1);
+ vendor_id = optarg;
break;
case CMD_OPT_PRODUCT_ID:
- strncpy(id_eeprom.product_id, optarg, sizeof(id_eeprom.product_id) - 1);
+ product_id = optarg;
break;
case CMD_OPT_DEVICE_ID:
- strncpy(id_eeprom.device_id, optarg, sizeof(id_eeprom.device_id) - 1);
+ device_id = optarg;
break;
case CMD_OPT_HW_VERSION:
- strncpy(id_eeprom.hw_version, optarg, sizeof(id_eeprom.hw_version) - 1);
+ hw_version = optarg;
break;
case CMD_OPT_MAC_ADDR:
- tmp = hwaddr_aton(optarg, id_eeprom.mac_addr, sizeof(id_eeprom.mac_addr));
- if (!tmp) {
- log_error("invalid mac-addr %s", optarg);
- usage(stderr);
- exit(1);
- }
+ mac_addr = optarg;
break;
case CMD_OPT_MAC_BLUETOOTH:
@@ -435,13 +483,13 @@ int main(int argc, char *argv[]) {
DEVICE_CAPA_SET(id_eeprom.capa, CAPA_ADC);
break;
- case CMD_OPT_CAPA_WIFI:
- DEVICE_CAPA_SET(id_eeprom.capa, CAPA_WIFI);
- break;
+ case CMD_OPT_CAPA_WIFI:
+ DEVICE_CAPA_SET(id_eeprom.capa, CAPA_WIFI);
+ break;
- case CMD_OPT_CAPA_BLUETOOTH:
- DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BLUETOOTH);
- break;
+ case CMD_OPT_CAPA_BLUETOOTH:
+ DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BLUETOOTH);
+ break;
case CMD_OPT_CAPA:
log_error("capa option not implemented");
@@ -474,6 +522,80 @@ int main(int argc, char *argv[]) {
}
}
+ /* these fields can apply to the on board EEPROM or the daughter card EEPROM */
+ if (vendor_id) {
+ if (! daughter_card) {
+ strncpy(id_eeprom.vendor_id, vendor_id, sizeof(id_eeprom.vendor_id) - 1);
+ } else {
+ strncpy(dc_eeprom.vendor_id, vendor_id, sizeof(dc_eeprom.vendor_id) - 1);
+ }
+ }
+ if (product_id) {
+ if (! daughter_card) {
+ strncpy(id_eeprom.product_id, product_id, sizeof(id_eeprom.product_id) - 1);
+ } else {
+ strncpy(dc_eeprom.product_id, product_id, sizeof(dc_eeprom.product_id) - 1);
+ }
+ }
+ if (device_id) {
+ if (! daughter_card) {
+ strncpy(id_eeprom.device_id, device_id, sizeof(id_eeprom.device_id) - 1);
+ } else {
+ strncpy(dc_eeprom.device_id, device_id, sizeof(dc_eeprom.device_id) - 1);
+ }
+ }
+ if (hw_version) {
+ if (! daughter_card) {
+ strncpy(id_eeprom.hw_version, hw_version, sizeof(id_eeprom.hw_version) - 1);
+ } else {
+ strncpy(dc_eeprom.hw_version, hw_version, sizeof(dc_eeprom.hw_version) - 1);
+ }
+ }
+ if (mac_addr) {
+ if (! daughter_card) {
+ tmp = hwaddr_aton(mac_addr, id_eeprom.mac_addr, sizeof(id_eeprom.mac_addr));
+ } else {
+ tmp = hwaddr_aton(mac_addr, dc_eeprom.mac_addr, sizeof(dc_eeprom.mac_addr));
+ }
+ if (!tmp) {
+ log_error("invalid mac-addr %s", optarg);
+ usage(stderr);
+ exit(1);
+ }
+ }
+
+ if (in_file) {
+ fd = open(in_file, O_RDONLY);
+ if (fd < 0) {
+ log_error("could not open in-file %s: %m", in_file);
+ exit(1);
+ }
+
+ if (daughter_card) {
+ tmp = read(fd, (char *) &dc_eeprom, eeprom_size);
+ } else {
+ tmp = read(fd, (char *) &id_eeprom, eeprom_size);
+ }
+
+ if (tmp < 0) {
+ log_error("reading %s failed: %m", in_file);
+ exit(1);
+ } else if (tmp != eeprom_size) {
+ log_error("only read %d bytes from %s", tmp, in_file);
+ exit(1);
+ }
+
+ if (daughter_card) {
+ log_info("loaded dc eeprom from %s successfully", in_file);
+ mts_dc_eeprom_inspect(&dc_eeprom);
+ } else {
+ log_info("loaded id eeprom from %s successfully", in_file);
+ mts_id_eeprom_inspect(&id_eeprom);
+ }
+
+ close(fd);
+ }
+
// updating eeprom in place, force bin format
if (update) {
out_file = in_file;
@@ -482,9 +604,17 @@ int main(int argc, char *argv[]) {
if (out_file) {
if (!strcmp(out_format, "bin")) {
- bin_out(out_file, &id_eeprom);
+ if (! daughter_card) {
+ bin_out(out_file, (char*) &id_eeprom);
+ } else {
+ bin_out(out_file, (char*) &dc_eeprom);
+ }
} else if (!strcmp(out_format, "yaml")) {
- yaml_out(out_file, &id_eeprom);
+ if (! daughter_card) {
+ id_yaml_out(out_file, &id_eeprom);
+ } else {
+ dc_yaml_out(out_file, &dc_eeprom);
+ }
} else {
log_error("un-handled out-format");
exit(1);