summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2022-03-16 12:35:57 -0500
committerJohn Klug <john.klug@multitech.com>2022-03-16 16:36:00 -0500
commit4b5fcfa39cd840418d2316209a7f67f239d3aa28 (patch)
treefc1c3ba6845f984717319aed8516a9e90ed6a4b0
parent17e3209a015e2f23b655b860917a1d2dffcd6040 (diff)
downloadmts-io-sysfs-4b5fcfa39cd840418d2316209a7f67f239d3aa28.tar.gz
mts-io-sysfs-4b5fcfa39cd840418d2316209a7f67f239d3aa28.tar.bz2
mts-io-sysfs-4b5fcfa39cd840418d2316209a7f67f239d3aa28.zip
Fixed fpga loader
-rw-r--r--include/Fpga/Fpga.h1
-rw-r--r--include/General.h4
-rw-r--r--include/Utility/Utility.h2
-rw-r--r--src/AccessoryCards/LoraCard15.cpp6
-rw-r--r--src/AccessoryCards/Mtac15Fpga.cpp81
-rw-r--r--src/Device/Device.cpp86
-rw-r--r--src/MtsIoSysfs.cpp39
7 files changed, 143 insertions, 76 deletions
diff --git a/include/Fpga/Fpga.h b/include/Fpga/Fpga.h
index 986a269..3ed672a 100644
--- a/include/Fpga/Fpga.h
+++ b/include/Fpga/Fpga.h
@@ -68,6 +68,7 @@ class Mtac15Fpga {
Mtac15Fpga(std::string path);
int getFpgaVersion();
int FpgaVersion();
+ void printFpgaVersion();
int upgradeFpga();
};
diff --git a/include/General.h b/include/General.h
index e45f06a..861ec62 100644
--- a/include/General.h
+++ b/include/General.h
@@ -58,6 +58,10 @@ typedef unsigned int uint; // 32 bit - even on 64 bit machines
#define FIRMWARE_FILE "/etc/issue"
#define CRESET "/creset"
+#define LORA_1_5_MTCAP_SPI "/dev/spidev0.0"
+#define LORA_1_5_MTCDT_SPI_AP_1 "/dev/spidev0.2"
+#define LORA_1_5_MTCDT_SPI_AP_2 "/dev/spidev1.2"
+
#define LORA_2_1_FPGA_VERSION \
"mts-fpga-loader -g | grep version | awk '{printf $4}'"
#define LORA_2_1_EXT_FPGA_VERSION \
diff --git a/include/Utility/Utility.h b/include/Utility/Utility.h
index caf5661..a04d826 100644
--- a/include/Utility/Utility.h
+++ b/include/Utility/Utility.h
@@ -44,7 +44,7 @@ inline std::string toCamelCase(const char *d_name) {
inline void exitHandler(int code) {
if (code != 0) {
- std::cout << "exiting with " << std::to_string(code);
+ std::cout << "exiting with " << std::to_string(code) <<std::endl;
}
exit(code);
}
diff --git a/src/AccessoryCards/LoraCard15.cpp b/src/AccessoryCards/LoraCard15.cpp
index 3ed0f31..f71bff3 100644
--- a/src/AccessoryCards/LoraCard15.cpp
+++ b/src/AccessoryCards/LoraCard15.cpp
@@ -27,11 +27,11 @@ void Device::Lora15Card::AddToDeviceInfo(const std::string Port,
LoraCard::AddToDeviceInfo(Port, ProductID);
if (ProductID.rfind("MTCAP", 0) == 0) {
- spiPath = "/dev/spidev0.0";
+ spiPath = LORA_1_5_MTCAP_SPI;
} else if (Port.back() == '2') {
- spiPath = "/dev/spidev1.2";
+ spiPath = LORA_1_5_MTCDT_SPI_AP_2;
} else {
- spiPath = "/dev/spidev0.2";
+ spiPath = LORA_1_5_MTCDT_SPI_AP_1;
}
Mtac15Fpga mtac15Fpga(spiPath);
diff --git a/src/AccessoryCards/Mtac15Fpga.cpp b/src/AccessoryCards/Mtac15Fpga.cpp
index 151ff77..fda3737 100644
--- a/src/AccessoryCards/Mtac15Fpga.cpp
+++ b/src/AccessoryCards/Mtac15Fpga.cpp
@@ -316,7 +316,7 @@ int Mtac15Fpga::cresetWrite(char num) {
std::string cresetPath = SYSFS_PLATFORM + port + CRESET;
int fd = open(cresetPath.c_str(), O_WRONLY);
if (fd < 0) {
- printError("Unable to lock file, are you root?");
+ printError("Unable to lock creset file: %d %s", fd, cresetPath.c_str());
return -1;
}
write(fd, &num, 1);
@@ -669,6 +669,10 @@ int Mtac15Fpga::busContention() {
Mtac15Fpga::Mtac15Fpga(std::string inputFile, std::string forcedPath) {
FILE *fp = fopen(DEVICE_INFO_FILE, "r");
char buf[0XFFFF];
+ if (fp== NULL) {
+ perror("Unable to open device info file");
+ exitHandler(errno);
+ }
rapidjson::FileReadStream input(fp, buf, sizeof(buf));
deviceInfo.ParseStream(input);
fclose(fp);
@@ -676,17 +680,20 @@ Mtac15Fpga::Mtac15Fpga(std::string inputFile, std::string forcedPath) {
if (!deviceInfo.HasMember("hardwareVersion")) {
printError("%s does not have hardware version info, exiting",
DEVICE_INFO_FILE);
- return;
+ exitHandler(99);
}
std::string hwVersion = deviceInfo["hardwareVersion"].GetString();
if (deviceInfo.HasMember("accessoryCards") &&
deviceInfo["accessoryCards"].IsArray() &&
deviceInfo["accessoryCards"].Size() > 0) {
+ rapidjson::SizeType acCardCount = deviceInfo["accessoryCards"].Size();
if (hwVersion.find("MTCDT3") != std::string::npos) {
hardwareType = HARDWARE_MTCDT3;
} else if (hwVersion.find("MTCDT") != std::string::npos) {
hardwareType = HARDWARE_MTCDT;
+ } else if (hwVersion.find("MTCAP") != std::string::npos) {
+ hardwareType = HARDWARE_MTCAP;
} else {
return;
}
@@ -695,14 +702,53 @@ Mtac15Fpga::Mtac15Fpga(std::string inputFile, std::string forcedPath) {
} else {
input_file = inputFile;
}
- port = deviceInfo["accessoryCards"][0]["port"].GetString();
- if (port.back() == '2') {
- spiPath = "/dev/spidev1.2";
+ if(forcedPath.empty()) {
+ port = deviceInfo["accessoryCards"][0]["port"].GetString();
+ if (port.back() == '2') {
+ spiPath = LORA_1_5_MTCDT_SPI_AP_2;
+ } else {
+ spiPath = LORA_1_5_MTCDT_SPI_AP_1;
+ }
} else {
- spiPath = "/dev/spidev0.2";
+ if (forcedPath.compare("1") == 0) {
+ spiPath = LORA_1_5_MTCDT_SPI_AP_1;
+ port = "ap1";
+ } else if (forcedPath.compare("2") == 0) {
+ port = "ap2";
+ spiPath = LORA_1_5_MTCDT_SPI_AP_2;
+ } else {
+ spiPath = forcedPath;
+ rapidjson::SizeType i;
+ bool found = false;
+ for (i = 0; i < acCardCount; i++) {
+ if (spiPath.compare(deviceInfo["accessoryCards"][i]["spiPath"].GetString()) == 0) {
+ port = deviceInfo["accessoryCards"][i]["port"].GetString();
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ printError("Invalid spi path: %s", spiPath.c_str());
+ exitHandler(99);
+ }
+ }
+ }
+ /* Sanity check config options with device info.json */
+ bool valid_config = false;
+ rapidjson::SizeType j;
+ for (j = 0; j < acCardCount; j++) {
+ if (spiPath.compare(deviceInfo["accessoryCards"][j]["spiPath"].GetString()) == 0
+ && port.compare(deviceInfo["accessoryCards"][j]["port"].GetString()) == 0) {
+ valid_config = true;
+ break;
+ }
+ }
+ if (!valid_config) {
+ printError("Path %s with port %s does not in exist in %s. Please set a valid config", spiPath.c_str(), port.c_str(), DEVICE_INFO_FILE);
+ exitHandler(99);
}
+
getFpgaVersion();
- printInfo("Current FPGA version: %d", fpgaVersion);
} else if (hwVersion.find("MTCAP") != std::string::npos) {
hardwareType = HARDWARE_MTCAP;
if (inputFile.empty()) {
@@ -712,7 +758,19 @@ Mtac15Fpga::Mtac15Fpga(std::string inputFile, std::string forcedPath) {
}
spiPath = "/dev/spidev0.0";
getFpgaVersion();
- printInfo("Current FPGA version: %d", fpgaVersion);
+ } else {
+ printError("No accessory cards installed/invalid hardware");
+ exitHandler(99);
+ }
+}
+
+void Mtac15Fpga::printFpgaVersion() {
+ if(fpgaVersion == 255 || fpgaVersion == 0) {
+ printError("Found invalid FPGA Version %d on spi path %s", fpgaVersion, spiPath.c_str());
+ exitHandler(errno);
+ } else {
+ printInfo("Found FPGA Version %d on spi path %s", fpgaVersion, spiPath.c_str());
+ exit(0);
}
}
@@ -740,11 +798,6 @@ int Mtac15Fpga::getFpgaVersion() {
/* setup and upgrade the mtac card with the file specified */
int Mtac15Fpga::upgradeFpga() {
- if (hardwareType == HARDWARE_INVALID) {
- printError("Invalid hardware");
- return -1;
- }
-
int ret;
if (input_file.empty()) {
@@ -756,8 +809,6 @@ int Mtac15Fpga::upgradeFpga() {
if (ret != 0) {
return ret;
}
- /* check MTAC Hardware Compatibility */
- printInfo("Checking hardware compatibility");
/* check input file checksum */
ret = sha256_file(input_file.c_str());
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index 04dbfef..e4ec02a 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -402,7 +402,7 @@ void Device::printJson() {
void Device::printVersion(std::string name) {
printInfo(
- "%s %s\nCopyright (C) 2021 by Multi-Tech Systems\nThis program is free "
+ "%s %s\nCopyright (C) 2022 by Multi-Tech Systems\nThis program is free "
"software; you may redistribute it under the terms of\nthe GNU General "
"Public License version 2 or (at your option) any later version.\nThis "
"program has absolutely no warranty.",
@@ -412,41 +412,43 @@ void Device::printVersion(std::string name) {
void Device::printUsage(std::string program) {
std::vector<std::string> showResults;
- printf("Usage: %s [ OPTIONS ] OBJECT [--] [ ARGUMENTS ]\n",
- program.c_str());
- printf("where OBJECT := {\n");
- printf(" init |\n");
- printf(" show SHOW-NAME |\n");
- printf(" store STORE-NAME |\n");
- printf(" json |\n");
- printf(" load-fpga FPGA-OPTIONS |\n");
- printf(" }\n");
+ printf("Usage: %s [ OPTIONS ] OBJECT [--] [ ARGUMENTS ]\n", program.c_str());
+ printf("Legacy OBJECT options:\n");
+ printf(" init : init & make device info json\n");
+ printf(" json : init & make device info json\n");
+ printf(" show : show data for file\n");
+ printf(" show-trigger : show trigger data for file\n");
+ printf(" store : store data for file\n");
+ printf(" store-trigger : store trigger data for file\n");
+ printf(" load-fpga : load fpga version\n");
+ printf("Updated OBJECT options:\n");
+ printf(" -I, --init : init & make device info json\n");
+ printf(" -j, --json : output device info json\n");
+ printf(" -s, --show : show data for file\n");
+ printf(" -S, --show-trigger : show trigger data for file\n");
+ printf(" -t, --store : store data for file\n");
+ printf(" -T, --store-trigger : store trigger data for file\n");
+ printf(" -l, --load-fpga : update fpga version\n");
+ printf(" -c, --check : check fpga version\n");
+ printf(" -v, --version : show version\n");
+ printf(" -h, --help : show help\n");
printf("\n");
- printf(" FPGA-OPTIONS := {\n");
- printf(" -c Check FPGA Version\n");
- printf(" -i Specify input file. Default is "
- "mtcdt-fpga-v31.hex for a MultiConnect Conduit\n");
- printf(" and mtcap-fpga-v31.hex for MultiConnect Access "
- "Point\n");
- printf(" -p Specify port 1 or 2 (MultiConnect Conduit "
- "Only)\n");
- printf(
- " -s Print FPGA versions supported by the utility\n");
- printf(" Examples :=\n");
- printf(" %s load-fpga -c Check existing "
- "FPGA version\n",
- program.c_str());
- printf(" %s load-fpga -i <upgrade file> Upgrade the FPGA "
- "on the default port using the file specified\n",
- program.c_str());
- printf(" %s load-fpga -p 2 -i <upgrade file> Upgrade the FPGA "
- "on ap2 using the file specified\n",
- program.c_str());
- printf(" %s Upgrade the FPGA "
- "on the default port and upgrade file\n",
- program.c_str());
- printf(" }\n");
- printf(" SHOW-NAME := {\n");
+ printf("Options\n");
+ printf(" -V, --verbose : show additional debug output\n");
+ printf("FPGA\n");
+ printf("Arguments:\n");
+ printf(" -p, --path : path for card\n");
+ printf(" : options: 1 for ap1, 2 for ap2 everything else\n");
+ printf(" : is an expected full path. i.e. /dev/spidevX.X\n");
+ printf(" -i, --input : input file for upgrade\n");
+ printf(" : files are stored in /usr/lib/mts-flash-binaries\n");
+ printf("Usage:\n");
+ printf(" Load : mts-io-sysfs -l -p <path> -i <file>\n");
+ printf(" Check : mts-io-sysfs -c -p <path>\n");
+ printf("\n");
+ printf("show-name:\n");
+ printf("Usage:\n");
+ printf("--show-name <name>\n");
printDir("", showResults);
sort(showResults.begin(),
showResults.end()); // Unix file tree is not sorted
@@ -455,9 +457,10 @@ void Device::printUsage(std::string program) {
if (!regex_match(showResult, showFilters))
printf(" %s\n", showResult.c_str());
}
- printf(" }\n");
printf("\n");
- printf(" STORE-NAME := {\n");
+ printf("store-name:\n");
+ printf("Usage:\n");
+ printf("--store-name <name> <value>\n");
for (std::string showResult : showResults) {
if (showResult == "radio-reset") {
printf(" %s { 0 }\n", showResult.c_str());
@@ -476,15 +479,8 @@ void Device::printUsage(std::string program) {
printf(" %s BOOLEAN\n", showResult.c_str());
}
}
- printf(" OPTIONS := {\n");
- printf(" --verbose\n");
- printf(" }\n");
- printf("\n");
- printf(" BOOLEAN := { OFF | ON }\n");
- printf(" OFF := 0\n");
- printf(" ON := 1\n");
printf("\n");
- exitHandler(1);
+ exitHandler(0);
}
void Device::show(std::string name) {
diff --git a/src/MtsIoSysfs.cpp b/src/MtsIoSysfs.cpp
index c7e892a..8bde1fb 100644
--- a/src/MtsIoSysfs.cpp
+++ b/src/MtsIoSysfs.cpp
@@ -33,6 +33,7 @@ enum action_code {
ACTION_INIT,
ACTION_JSON,
ACTION_LOAD_FPGA,
+ ACTION_CHECK_FPGA,
ACTION_SHOW,
ACTION_SHOW_TRIGGER,
ACTION_STORE,
@@ -56,11 +57,12 @@ int main(int argc, char **argv) {
int c;
static struct option long_options[] = {
{"help", no_argument, nullptr, 'h'},
+ {"check", no_argument, nullptr, 'c'},
{"data", required_argument, nullptr, 'd'},
{"input", required_argument, nullptr, 'i'},
{"init", no_argument, nullptr, 'I'},
{"json", no_argument, nullptr, 'j'},
- {"load-fpga", optional_argument, nullptr, 'l'},
+ {"load-fpga", no_argument, nullptr, 'l'},
{"path", required_argument, nullptr, 'p'},
{"show", required_argument, nullptr, 's'},
{"show-trigger", required_argument, nullptr, 'S'},
@@ -73,7 +75,7 @@ int main(int argc, char **argv) {
for (;;) {
int option_index = 0;
- c = getopt_long(argc, argv, "d:hi:Ijl:p:s:St:T:vV", long_options,
+ c = getopt_long(argc, argv, "cd:hi:Ijlp:s:St:T:vV", long_options,
&option_index);
if (c == -1)
break;
@@ -87,6 +89,10 @@ int main(int argc, char **argv) {
true);
break;
}
+ case 'c': {
+ action = ACTION_CHECK_FPGA;
+ break;
+ }
case 'd': {
data = optarg;
break;
@@ -96,7 +102,7 @@ int main(int argc, char **argv) {
break;
}
case 'p': {
- forcedAP = optarg;
+ forcedAP = std::string(optarg);
break;
}
case 'I': {
@@ -107,6 +113,10 @@ int main(int argc, char **argv) {
action = ACTION_JSON;
break;
}
+ case 'l': {
+ action = ACTION_LOAD_FPGA;
+ break;
+ }
case 's': {
action = ACTION_SHOW;
name = optarg;
@@ -127,18 +137,17 @@ int main(int argc, char **argv) {
name = optarg;
break;
}
- case 'L': {
- action = ACTION_LOAD_FPGA;
- break;
+ case ':': {
+ printf("Missing arg for %c\n", optopt);
+ exit(-1);
}
- case '?': {
- printError("%s option requires arguement", optopt);
- break;
+ case 'h': {
+ m.printUsage(argv[0]);
+ exit(0);
}
- case 'h':
default:
m.printUsage(argv[0]);
- exit(0);
+ exit(-1);
}
}
@@ -184,7 +193,9 @@ int main(int argc, char **argv) {
action = ACTION_NONE;
}
} else if (strcmp(argv[index], COMMMAND_LOAD_FPGA) == 0) {
- action = ACTION_LOAD_FPGA;
+ if (action != ACTION_CHECK_FPGA) {
+ action = ACTION_LOAD_FPGA;
+ }
} else if (strcmp(argv[index], COMMMAND_VERSION) == 0) {
action = ACTION_VERSION;
} else if (strcmp(argv[index], COMMMAND_EXTRA) == 0) {
@@ -216,6 +227,10 @@ int main(int argc, char **argv) {
case ACTION_JSON: {
m.json();
}
+ case ACTION_CHECK_FPGA: {
+ Mtac15Fpga mtac15Fpga(fpgaFilePath, forcedAP);
+ mtac15Fpga.printFpgaVersion();
+ }
case ACTION_LOAD_FPGA: {
Mtac15Fpga mtac15Fpga(fpgaFilePath, forcedAP);
return mtac15Fpga.upgradeFpga();