arch/arm64: Support FEAT_CCIDX
[coreboot2.git] / util / coreboot-configurator / src / application / NvramToolCli.cpp
blobda844a043bdad2fb63d78ae10552052d8ef2a98e
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <QProcess>
4 #include <QTextStream>
6 #include "NvramToolCli.h"
7 #include "Util.h"
9 static constexpr char s_sudoProg[] = "/usr/bin/pkexec";
10 static constexpr char s_nvramToolProg[] = "/usr/sbin/nvramtool";
12 #if MOCK
14 QMap<QString, QString> NvramToolCli::readParameters(QString *error) {
15 return QMap<QString,QString>({
16 {"boot_option","Normal"},
17 {"reboot_counter","0x0"},
18 {"debug_level","Spew"},
19 {"vtd","Enable"},
20 {"power_profile","Performance"},
21 {"wireless","Enable"},
22 {"webcam","Enable"},
23 {"microphone","Enable"},
24 {"legacy_8254_timer","Enable"},
25 {"usb_always_on","Disable"},
26 {"kbl_timeout","Never"},
27 {"fn_ctrl_swap","Enable"},
28 {"max_charge","100%"},
29 {"power_on_after_fail","Disable"},
30 {"fn_lock_state","0x2"},
31 {"trackpad_state","0x40"},
32 {"kbl_brightness","0xc4"},
33 {"kbl_state","0x22"}
34 });
37 QStringList NvramToolCli::readOptions(const QString &parameter, QString *error){
38 return (parameter=="power_profile")?
39 QStringList{
40 "Power Saver","Balanced","Performance"
41 } : QStringList{};
44 #else
46 QMap<QString, QString> NvramToolCli::readParameters(QString *error)
48 QProcess nvramtoolProcess;
49 nvramtoolProcess.start(s_sudoProg, {s_nvramToolProg, "-a"});
51 nvramtoolProcess.waitForFinished();
53 if(error) *error = nvramtoolProcess.readAllStandardError();
55 if(nvramtoolProcess.exitCode() != 0){
56 return {};
59 return Util::parseParameters(nvramtoolProcess);
62 QStringList NvramToolCli::readOptions(const QString &parameter, QString *error)
64 QStringList result;
66 QProcess nvramtoolProcess;
67 nvramtoolProcess.start(s_sudoProg, {s_nvramToolProg, "-e", parameter});
68 nvramtoolProcess.waitForFinished();
70 if(error) *error = nvramtoolProcess.readAllStandardError();
72 while (nvramtoolProcess.canReadLine()) {
73 result.append(nvramtoolProcess.readLine().trimmed());
76 return result;
78 #endif
80 bool NvramToolCli::writeParameters(const QMap<QString, QString> &parameters, QString *error)
83 #if MOCK
84 QTextStream outStream(stdout);
85 #else
86 QProcess nvramtoolProcess;
87 nvramtoolProcess.start(s_sudoProg, {s_nvramToolProg, "-i"});
88 nvramtoolProcess.waitForStarted();
89 QTextStream outStream(&nvramtoolProcess);
90 #endif
91 for(auto it = parameters.begin(); it != parameters.end(); ++it){
92 outStream << it.key() << " = " << it.value() << "\n";
95 outStream.flush();
96 #if MOCK
97 return true;
98 #else
99 nvramtoolProcess.closeWriteChannel();
100 nvramtoolProcess.waitForFinished();
102 if(error){
103 *error = nvramtoolProcess.readAllStandardError();
106 return nvramtoolProcess.exitCode()==0;
107 #endif
112 QString NvramToolCli::version()
114 QProcess nvramtoolProcess;
115 nvramtoolProcess.start(s_nvramToolProg, {"-v"});
117 nvramtoolProcess.waitForFinished();
119 return nvramtoolProcess.readAll();