summaryrefslogtreecommitdiff
path: root/src/eeprom_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eeprom_main.c')
-rw-r--r--src/eeprom_main.c110
1 files changed, 61 insertions, 49 deletions
diff --git a/src/eeprom_main.c b/src/eeprom_main.c
index c7956e8..29c0f99 100644
--- a/src/eeprom_main.c
+++ b/src/eeprom_main.c
@@ -171,9 +171,10 @@ static int dc_yaml_out(const char *name, struct mts_dc_eeprom_layout *dc_eeprom)
fprintf(file, "---\n");
fprintf(file, "\n");
- fprintf(file, "serial: \"%.32s\"\n", dc_eeprom->serial);
- fprintf(file, "hw-rev: \"%.32s\"\n", dc_eeprom->hw_rev);
+ 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],
@@ -258,9 +259,10 @@ 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)
{
log_info("sizeof: %lu", sizeof(struct mts_dc_eeprom_layout));
- log_info("serial: %.32s", dc_eeprom->serial);
- log_info("hw-rev: %.32s", dc_eeprom->hw_rev);
+ 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],
@@ -299,13 +301,9 @@ static void usage(FILE *out) {
fprintf(out, " --capa-wifi |\n");
fprintf(out, " --capa-bluetooth |\n");
fprintf(out, " --capa <capa> |\n");
- fprintf(out, " --dc-serial <daughter-card-serial> |\n");
- fprintf(out, " --dc-hw-rev <daughter-card-hardware-revision> |\n");
- fprintf(out, " --dc-product-id <daughter-card-product-id> |\n");
- fprintf(out, " --dc-mac-addr <daughter-card-mac-addr> |\n");
fprintf(out, " --out-format { bin | yaml (default) } |\n");
- fprintf(out, " --update\n");
- fprintf(out, " --daughter-card |\n");
+ fprintf(out, " --update |\n");
+ fprintf(out, " --daughter-card\n");
fprintf(out, " }\n");
fprintf(out, "\n");
}
@@ -328,10 +326,6 @@ enum {
CMD_OPT_CAPA_WIFI,
CMD_OPT_CAPA_BLUETOOTH,
CMD_OPT_CAPA,
- CMD_OPT_DAUGHTER_CARD_SERIAL,
- CMD_OPT_DAUGHTER_CARD_HW_REVISION,
- CMD_OPT_DAUGHTER_CARD_PRODUCT_ID,
- CMD_OPT_DAUGHTER_CARD_MAC_ADDR,
CMD_OPT_OUT_FORMAT,
CMD_OPT_UPDATE,
CMD_OPT_DAUGHTER_CARD,
@@ -358,10 +352,6 @@ static struct option long_options[] = {
{"capa-wifi", 0, NULL, CMD_OPT_CAPA_WIFI},
{"capa-bluetooth", 0, NULL, CMD_OPT_CAPA_BLUETOOTH},
{"capa", 1, NULL, CMD_OPT_CAPA},
- {"dc-serial", 1, NULL, CMD_OPT_DAUGHTER_CARD_SERIAL},
- {"dc-hw-rev", 1, NULL, CMD_OPT_DAUGHTER_CARD_HW_REVISION},
- {"dc-product-id", 1, NULL, CMD_OPT_DAUGHTER_CARD_PRODUCT_ID},
- {"dc-mac-addr", 1, NULL, CMD_OPT_DAUGHTER_CARD_MAC_ADDR},
{"out-format", 1, NULL, CMD_OPT_OUT_FORMAT},
{"update", 0, NULL, CMD_OPT_UPDATE},
{"daughter-card", 0, NULL, CMD_OPT_DAUGHTER_CARD},
@@ -382,6 +372,12 @@ int main(int argc, char *argv[]) {
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;
@@ -430,28 +426,23 @@ int main(int argc, char *argv[]) {
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:
@@ -505,27 +496,6 @@ int main(int argc, char *argv[]) {
exit(1);
break;
- case CMD_OPT_DAUGHTER_CARD_SERIAL:
- strncpy(dc_eeprom.serial, optarg, sizeof(dc_eeprom.serial) - 1);
- break;
-
- case CMD_OPT_DAUGHTER_CARD_HW_REVISION:
- strncpy(dc_eeprom.hw_rev, optarg, sizeof(dc_eeprom.hw_rev) - 1);
- break;
-
- case CMD_OPT_DAUGHTER_CARD_PRODUCT_ID:
- strncpy(dc_eeprom.product_id, optarg, sizeof(dc_eeprom.product_id) - 1);
- break;
-
- case CMD_OPT_DAUGHTER_CARD_MAC_ADDR:
- tmp = hwaddr_aton(optarg, dc_eeprom.mac_addr, sizeof(dc_eeprom.mac_addr));
- if (!tmp) {
- log_error("invalid daughter card mac-addr %s", optarg);
- usage(stderr);
- exit(1);
- }
- break;
-
case CMD_OPT_OUT_FORMAT:
if (strcmp(optarg, "bin") && strcmp(optarg, "yaml")) {
log_error("invalid out-format %s", optarg);
@@ -552,6 +522,48 @@ 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) {