Skip to content

Commit 0e2d582

Browse files
committed
[roc-config] Implement firmware compatibility checker
1 parent 82ad0ef commit 0e2d582

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/CommandLineUtilities/ProgramConfig.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "CommandLineUtilities/Options.h"
1818
#include "CommandLineUtilities/Program.h"
1919
#include "Cru/CruBar.h"
20+
#include "FirmwareChecker.h"
2021
#include "ReadoutCard/CardConfigurator.h"
2122
#include "ReadoutCard/ChannelFactory.h"
2223
#include "ReadoutCard/Exception.h"
@@ -101,6 +102,7 @@ class ProgramConfig : public Program
101102
std::cout << " __== " << card.pciAddress.toString() << " ==__ " << std::endl;
102103
auto params = Parameters::makeParameters(card.pciAddress, 2);
103104
try {
105+
checkFirmwareCompatibility(params);
104106
CardConfigurator(card.pciAddress, mOptions.configFile, mOptions.forceConfig);
105107
} catch (const Exception& e) {
106108
std::cout << boost::diagnostic_information(e) << std::endl;
@@ -111,6 +113,12 @@ class ProgramConfig : public Program
111113

112114
// Configure specific card
113115
auto cardId = Options::getOptionCardId(map);
116+
try {
117+
checkFirmwareCompatibility(cardId);
118+
} catch (const Exception& e) {
119+
std::cout << boost::diagnostic_information(e) << std::endl;
120+
return;
121+
}
114122

115123
if (mOptions.configFile == "") {
116124
std::cout << "Configuring with command line arguments" << std::endl;

src/FirmwareChecker.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file FirmwareChecker.h
12+
/// \brief Helper functions to check a card's firmware compatibilty
13+
///
14+
/// \author Kostas Alexopoulos ([email protected])
15+
16+
#include "unordered_map"
17+
#include "ReadoutCard/ChannelFactory.h"
18+
#include "ReadoutCard/Parameters.h"
19+
20+
namespace AliceO2
21+
{
22+
namespace roc
23+
{
24+
25+
inline std::unordered_map<std::string, std::string> compatibleFirmwareList({ { "20190909-xxxxxx-3f5e11b3", "CRU v3.3.0" },
26+
{ "20190718-120712-4c8e6c48", "CRU v3.2.0" },
27+
{ "0.0:2000-0-0", "CRORC alpha" } });
28+
29+
inline std::string getFirmwareCompatibilityList()
30+
{
31+
std::string fwStrings;
32+
for (auto fwString : compatibleFirmwareList) {
33+
fwStrings += "\n" + fwString.second + " - " + fwString.first;
34+
}
35+
return fwStrings;
36+
}
37+
38+
inline void checkFirmwareCompatibilityWrapped(std::shared_ptr<BarInterface> bar2)
39+
{
40+
auto firmware = bar2->getFirmwareInfo().value_or("");
41+
auto serial = bar2->getSerial().value_or(-1);
42+
if (compatibleFirmwareList.find(firmware) == compatibleFirmwareList.end()) {
43+
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message(
44+
std::string("Firmware compatibility check failed.\n") +
45+
std::string("Serial: " + std::to_string(serial) + "\n") +
46+
std::string("Firmware: " + firmware + "\n") +
47+
std::string("\nCompatible firmwares:") +
48+
getFirmwareCompatibilityList()));
49+
}
50+
}
51+
52+
inline void checkFirmwareCompatibility(Parameters params)
53+
{
54+
auto bar2 = ChannelFactory().getBar(params);
55+
checkFirmwareCompatibilityWrapped(bar2);
56+
}
57+
58+
inline void checkFirmwareCompatibility(Parameters::CardIdType cardId)
59+
{
60+
auto params = Parameters::makeParameters(cardId, 2); // access bar2 to check the firmware release
61+
auto bar2 = ChannelFactory().getBar(params);
62+
checkFirmwareCompatibilityWrapped(bar2);
63+
}
64+
65+
} // namespace roc
66+
} // namespace AliceO2

0 commit comments

Comments
 (0)