diff options
-rw-r--r-- | src/b2qt-flashing-wizard/commit_page.cpp | 119 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/device_page.cpp | 7 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/mainwindow.cpp | 7 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/platform_page.cpp | 150 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/platform_page.h | 5 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/platforminfo.h | 39 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/scriptwriter.cpp | 20 | ||||
-rw-r--r-- | src/b2qt-flashing-wizard/scriptwriter.h | 2 |
8 files changed, 151 insertions, 198 deletions
diff --git a/src/b2qt-flashing-wizard/commit_page.cpp b/src/b2qt-flashing-wizard/commit_page.cpp index 1013640..62d9965 100644 --- a/src/b2qt-flashing-wizard/commit_page.cpp +++ b/src/b2qt-flashing-wizard/commit_page.cpp @@ -21,16 +21,13 @@ #include "scriptwriter.h" #include "progress_page.h" #include "mainwindow.h" +#include "platforminfo.h" #include <QDebug> #include <QVBoxLayout> #include <QLabel> -extern QString G_platform; -extern QString G_version; -extern QString G_os; +extern PlatformInfo G_platforminfo; extern QString G_device; -extern QString G_board; -extern QString G_SDKDIR; extern QString G_mode; QLabel *createErrorLabel(QWidget *parent); @@ -73,102 +70,32 @@ bool CommitPage::isComplete() const void CommitPage::initializePage() { - qDebug() << "platform:" << G_platform << "version:" << G_version << "os:" << G_os - << "device:" << G_device << "board:" << G_board << "mode:" << G_mode; + qDebug() << "platform:" << G_platforminfo.platform << "version:" << G_platforminfo.version + << "os:" << G_platforminfo.os << "board:" << G_platforminfo.board + << "deploycommand:" << G_platforminfo.deployCommand << "deployarguments:" << G_platforminfo.deployArguments + << "device:" << G_device << "mode:" << G_mode; + QString text(tr("Write %1-%2 (%3) to device %4.")); - mText->setText(text.arg(G_platform, G_os, G_version, G_device)); + mText->setText(text.arg(G_platforminfo.platform, G_platforminfo.os, G_platforminfo.version, G_device)); mComplete = true; - qDebug() << "os:" << G_os << "platform:" << G_platform << "device:" << G_device; + ScriptWriter *i = new ScriptWriter(this); + i->setScriptFile(G_platforminfo.deployCommand); + i->setRootFlag(G_platforminfo.asroot); - if (G_platform == "generic-4.2" && G_os == "eAndroid" && G_board == "iMX6") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "iMX6" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "beaglebone" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "beaglebone") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "nexus7v2") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh"); - QStringList args("-y"); - if (G_mode == "fastboot") - args << "-fastboot"; - i->setAdditionalArgs(args); - mActor = i; - } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "nexus7") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh"); - QStringList args("-y"); - if (G_mode == "fastboot") - args << "-fastboot"; - i->setAdditionalArgs(args); - mActor = i; - } else if (G_platform == "generic-4.2" && G_os == "eAndroid" && G_board == "nexus7") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh"); - QStringList args("-y"); - if (G_mode == "fastboot") - args << "-fastboot"; - i->setAdditionalArgs(args); - mActor = i; - } else if (G_platform == "raspberrypi" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" << G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "imx6qsabresd" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "imx6dsabresd" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/imx6qsabresd-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose" << "--uboot" << "u-boot-imx6dlsabresd.imx"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "apalis-imx6" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "tibidabo" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else if (G_platform == "colibri-vf" && G_os == "eLinux") { - ScriptWriter *i = new ScriptWriter(this); - i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh"); - i->setAdditionalArgs(QStringList() << "-y" <<G_device << "--verbose"); - i->setEnvironment("VERBOSE","1"); - mActor = i; - } else { - mError->setText(tr("Unsupported platform combination")); - mComplete = false; + QStringList args; + foreach (QString a, G_platforminfo.deployArguments) { + if (a == "@DEVICE@") + a = G_device; + args << a; } + + if (G_platforminfo.board.startsWith("nexus7") && G_mode == "fastboot") + args << "-fastboot"; + + i->setAdditionalArgs(args); + i->setEnvironment("VERBOSE","1"); + mActor = i; } bool CommitPage::validatePage() diff --git a/src/b2qt-flashing-wizard/device_page.cpp b/src/b2qt-flashing-wizard/device_page.cpp index f6c146a..97a6def 100644 --- a/src/b2qt-flashing-wizard/device_page.cpp +++ b/src/b2qt-flashing-wizard/device_page.cpp @@ -20,6 +20,7 @@ #include "device_page.h" #include "common.h" #include "mainwindow.h" // for Page_ enum +#include "platforminfo.h" #include <QDebug> #include <QDir> #include <QLabel> @@ -32,7 +33,7 @@ extern QString G_SDKDIR; extern QString G_device; -extern QString G_board; +extern PlatformInfo G_platforminfo; extern QString G_mode; QLabel *createErrorLabel(QWidget *parent); @@ -259,13 +260,13 @@ bool DevicePage::validatePage() return false; } - if (deviceInfo.name.toLower() != G_board.toLower()) { + if (deviceInfo.name.toLower() != G_platforminfo.board.toLower()) { QMessageBox::critical(this, tr("Wrong device type"), tr("The selected device is not compatible for this platform.")); return false; } G_device = deviceInfo.serial; - G_board = deviceInfo.name.toLower(); + G_platforminfo.board = deviceInfo.name.toLower(); G_mode = deviceInfo.mode; return true; } diff --git a/src/b2qt-flashing-wizard/mainwindow.cpp b/src/b2qt-flashing-wizard/mainwindow.cpp index 17114c1..8693eab 100644 --- a/src/b2qt-flashing-wizard/mainwindow.cpp +++ b/src/b2qt-flashing-wizard/mainwindow.cpp @@ -29,13 +29,10 @@ #include <QDir> #include <QCoreApplication> -QString G_platform; // generic-4.4 / iMX6 -QString G_version; // Boot2Qt version -QString G_os; // eAndroid / eLinux -QString G_device; // serial number or SD Card -QString G_board; // nexus7v2,nexus7, etc... +PlatformInfo G_platforminfo; QString G_SDKDIR; // install directory QString G_mode; // adb or fastboot +QString G_device; MainWindow::MainWindow() : QWizard() diff --git a/src/b2qt-flashing-wizard/platform_page.cpp b/src/b2qt-flashing-wizard/platform_page.cpp index 31ee880..609a5aa 100644 --- a/src/b2qt-flashing-wizard/platform_page.cpp +++ b/src/b2qt-flashing-wizard/platform_page.cpp @@ -24,14 +24,12 @@ #include <QDir> #include <QLabel> #include <QSpacerItem> +#include <QSettings> #include "mainwindow.h" // Page_ enum -extern QString G_platform; -extern QString G_version; -extern QString G_os; -extern QString G_device; -extern QString G_board; +static QList<PlatformInfo> platforms; extern QString G_SDKDIR; +extern PlatformInfo G_platforminfo; QLabel *createErrorLabel(QWidget *parent) { @@ -68,20 +66,7 @@ PlatformPage::~PlatformPage() bool PlatformPage::isComplete() const { - QStringList data = buttonData(); - if (data.isEmpty()) - return false; - - if (data[0] == "nexus7") { - mError->setText(tr("The selected platform is not supported.")); - return false; - } - if (data[0] == "iMX6" && data[1] == "eAndroid") { - mError->setText(tr("The selected platform is not supported.")); - return false; - } - - return !data.isEmpty(); + return true; } void PlatformPage::itemSelected() @@ -90,13 +75,53 @@ void PlatformPage::itemSelected() emit completeChanged(); } +static void loadDeployConfig(const QString &filename, const QString &version) +{ + qDebug() << "Trying to load config" << filename; + if (!QFile::exists(filename)) + return; + + QFileInfo fi(filename); + + QSettings settings(filename, QSettings::IniFormat); + + foreach (const QString &group, settings.childGroups()) { + PlatformInfo pi; + + settings.beginGroup(group); + pi.name = group; + pi.platform = settings.value("platform").toString(); + pi.os = settings.value("os").toString(); + pi.androidversion = settings.value("androidversion").toString(); + pi.board = settings.value("board").toString(); + pi.deployCommand = settings.value("deploycommand").toString(); + pi.deployCommand = QDir::cleanPath(fi.canonicalPath() + "/" + pi.deployCommand); + pi.deployArguments = settings.value("deployarguments").toStringList(); + pi.asroot = settings.value("asroot").toBool(); + pi.version = version; + settings.endGroup(); + + if (pi.platform.isEmpty() || pi.os.isEmpty() || pi.deployCommand.isEmpty()) { + qWarning() << "Invalid data"; + continue; + } + + if (pi.os == "eAndroid" && pi.androidversion.isEmpty()) { + qWarning() << "Invalid data"; + continue; + } + + qDebug() << "Adding platform" << group; + platforms.append(pi); + } +} + void PlatformPage::initializePage() { mError->clear(); qDeleteAll(mButtons); mButtons.clear(); - mButtonData.clear(); QDir dir(G_SDKDIR); foreach (const QString i, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { @@ -111,91 +136,52 @@ void PlatformPage::initializePage() QString os = token.takeLast(); QString name = token.join("-"); - if (os == "eAndroid" && name.startsWith("generic-")) { - QString version = token[1]; - QDir dir3(dir2.absoluteFilePath(j) + "/images"); - foreach (const QString k, dir3.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { - if (k == "common") - continue; - - if (!QFile::exists(dir3.absoluteFilePath(k) + "/deploy.sh")) - continue; - - QRadioButton *button = new QRadioButton; - button->setText(k + "-" + version + "-" + os + " (" + i + ")"); - mLayout->insertWidget(0, button); - connect(button, &QRadioButton::toggled, this, &PlatformPage::itemSelected); - mButtons.append(button); - mButtonData.insert(button, QStringList() << name << os << i << k); - } - - } else if (os == "eAndroid" || os == "eLinux") { - // Will be fixed with http://qt-gerrit.it.local/#change,7842 - if (name == "imx6qsabresd") { - { - QRadioButton *button = new QRadioButton; - button->setText(j + " (" + i + ")"); - mLayout->insertWidget(0, button); - connect(button, &QRadioButton::toggled, this, &PlatformPage::itemSelected); - mButtons.append(button); - mButtonData.insert(button, QStringList() << name << os << i << name); - } - { - QRadioButton *button = new QRadioButton; - button->setText("imx6dsabresd-eLinux (" + i + ")"); - mLayout->insertWidget(0, button); - connect(button, &QRadioButton::toggled, this, &PlatformPage::itemSelected); - mButtons.append(button); - mButtonData.insert(button, QStringList() << "imx6dsabresd" << os << i << name); - } - } else { - QRadioButton *button = new QRadioButton; - button->setText(j + " (" + i + ")"); - mLayout->insertWidget(0, button); - connect(button, &QRadioButton::toggled, this, &PlatformPage::itemSelected); - mButtons.append(button); - mButtonData.insert(button, QStringList() << name << os << i << name); - } - } + loadDeployConfig(dir2.absoluteFilePath(j) + "/images/deploy.conf", i); } } - if (mButtons.isEmpty()) { + if (platforms.isEmpty()) { mError->setText(tr("No suitable platform found in '%1'.\nMake sure you have" "installed at least one hardware platform.").arg(G_SDKDIR)); } + + for (int i = 0; i < platforms.count(); ++i) { + const PlatformInfo &pi = platforms[i]; + QRadioButton *button = new QRadioButton; + if (pi.os == "eAndroid") + button->setText(pi.name + " | " + pi.os + " " + pi.androidversion + " (" + pi.version + ")"); + else + button->setText(pi.name + " | " + pi.os + " (" + pi.version + ")"); + mLayout->insertWidget(0, button); + connect(button, &QRadioButton::toggled, this, &PlatformPage::itemSelected); + button->setProperty("b2qt-platform-name", i); + mButtons.append(button); + } } -QStringList PlatformPage::buttonData() const +PlatformInfo PlatformPage::buttonData() const { - QStringList data; - foreach (QRadioButton *button, mButtons) { if (button->isChecked()) { - data = mButtonData[button]; - break; + int id = button->property("b2qt-platform-name").toInt(); + return platforms[id]; } } - return data; + return PlatformInfo(); } bool PlatformPage::validatePage() { - QStringList data = buttonData(); - - G_platform = data[0]; - G_os = data[1]; - G_version = data[2]; - G_board = data[3]; - - qDebug() << "Selected:" << G_platform << G_os << G_version << G_board; + G_platforminfo = buttonData(); + qDebug() << "Selected:" << G_platforminfo.name; return true; } int PlatformPage::nextId() const { - if (G_board.startsWith("nexus7")) + if (G_platforminfo.board.startsWith("nexus7")) return MainWindow::Page_Device; else return MainWindow::Page_Disk; } + diff --git a/src/b2qt-flashing-wizard/platform_page.h b/src/b2qt-flashing-wizard/platform_page.h index 215023a..f14f207 100644 --- a/src/b2qt-flashing-wizard/platform_page.h +++ b/src/b2qt-flashing-wizard/platform_page.h @@ -20,8 +20,8 @@ #ifndef PLATFORM_PAGE_H #define PLATFORM_PAGE_H +#include "platforminfo.h" #include <QWizardPage> -#include <QMap> class QRadioButton; class QLabel; class QVBoxLayout; @@ -41,10 +41,9 @@ private slots: void itemSelected(); private: - QStringList buttonData() const; + PlatformInfo buttonData() const; QList<QRadioButton*> mButtons; - QMap<QRadioButton*, QStringList> mButtonData; QLabel *mError; QVBoxLayout *mLayout; }; diff --git a/src/b2qt-flashing-wizard/platforminfo.h b/src/b2qt-flashing-wizard/platforminfo.h new file mode 100644 index 0000000..5108aec --- /dev/null +++ b/src/b2qt-flashing-wizard/platforminfo.h @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use the contact form at +** http://qt.digia.com/ +** +** This file is part of Qt Enterprise Embedded. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** the contact form at http://qt.digia.com/ +** +****************************************************************************/ + +#ifndef PLATFORMINFO_H +#define PLATFORMINFO_H + +#include <QStringList> + +class PlatformInfo { +public: + PlatformInfo() : asroot(false) { } + QString name; // Display name + QString platform; // generic-4.4 / iMX6 + QString os; // eAndroid / eLinux + QString board; // nexus7v2,nexus7, etc... + QString deployCommand; // script + QStringList deployArguments; + QString androidversion; + QString version; // Boot2Qt version + bool asroot; // script needs root privileges +}; + +#endif // PLATFORMINFO_H diff --git a/src/b2qt-flashing-wizard/scriptwriter.cpp b/src/b2qt-flashing-wizard/scriptwriter.cpp index 9b85c24..594aecc 100644 --- a/src/b2qt-flashing-wizard/scriptwriter.cpp +++ b/src/b2qt-flashing-wizard/scriptwriter.cpp @@ -32,6 +32,7 @@ ScriptWriter::ScriptWriter(QObject *parent) : Actor(parent) , mDebug(false) + , mRoot(false) { mProcess.setProcessChannelMode(QProcess::MergedChannels); mDebug = qEnvironmentVariableIsSet("DEBUG"); @@ -84,17 +85,13 @@ void ScriptWriter::start() connect(&mProcess, (void (QProcess::*)(QProcess::ProcessError))&QProcess::error, this, &ScriptWriter::processError); connect(&mProcess, (void (QProcess::*)(int, QProcess::ExitStatus))&QProcess::finished, this, &ScriptWriter::processFinished); - // Due to some random convenience output in the deploy scripts "set -x" has to be used to synchronize - QStringList args = elevate() << "/bin/sh" << "-x" << mScriptName << mAdditionalArgs; + QStringList args; + + if (mRoot) + args << elevate(); + args << "/bin/sh" << "-x" << mScriptName << mAdditionalArgs; qDebug() << "Executing" << args; -/* QProcessEnvironment pe ; - QString var = qgetenv("XDG_SESSION_COOKIE"); - pe.insert("XDG_SESSION_COOKIE", var); - var = qgetenv("HOME"); - pe.insert("HOME", var); - mProcess.setProcessEnvironment(pe); - */ mProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); mProcess.start(args.takeFirst(), args); @@ -140,3 +137,8 @@ void ScriptWriter::setAdditionalArgs(const QStringList &args) { mAdditionalArgs = args; } + +void ScriptWriter::setRootFlag(bool value) +{ + mRoot = value; +} diff --git a/src/b2qt-flashing-wizard/scriptwriter.h b/src/b2qt-flashing-wizard/scriptwriter.h index a1ed7a3..68a7684 100644 --- a/src/b2qt-flashing-wizard/scriptwriter.h +++ b/src/b2qt-flashing-wizard/scriptwriter.h @@ -36,6 +36,7 @@ public: void start(); void setEnvironment(const QString &key, const QString &value); void setAdditionalArgs(const QStringList &); + void setRootFlag(bool); private slots: void readOutput(); @@ -47,6 +48,7 @@ private: QProcess mProcess; QStringList mAdditionalArgs; bool mDebug; + bool mRoot; }; #endif // SCRIPTWRITER_H |