Changed firmware update functionality

now it uses libsmu to flash firmware to devices instead of bossa
This commit is contained in:
Claudiu Pop committed 2017-11-23 12:15:09 +02:00
1 parent 8309a34237
commit 9d62870da5
6 files changed
+121 -234

No files matched your search

+33 -6
View File
@@ -1,8 +1,10 @@
#include <QStandardPaths>
#include <QDir>
#include "SMU.h"
#include "Plot/PhosphorRender.h"
#include "Plot/FloatBuffer.h"
#include "utils/fileio.h"
#include "utils/bossac_wrap.h"
#include "qdebug.h"
using namespace smu;
@@ -20,6 +22,16 @@ void registerTypes() {
qRegisterMetaType<uint64_t>("uint64_t");
}
QString SessionItem::getTmpPathForFirmware()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
path += "/pixelpulse2/m1k_firmware";
QDir dir(path);
if (!dir.exists())
dir.mkpath(".");
return dir.path();
}
SessionItem::SessionItem():
m_session(new Session),
m_active(false),
@@ -136,15 +148,13 @@ void SessionItem::onDetached(Device* device){
if (m_active) {
this->cancel();
}
m_session->remove(device, true);
for (auto dev: m_devices) {
if (dev->m_device == device) {
m_devices.removeOne(dev);
}
}
m_session->destroy(device);
devicesChanged();
qDebug() << "Device detached";
qDebug() << "Device detached";
}
void SessionItem::onSampleCountChanged(){
@@ -154,8 +164,7 @@ void SessionItem::onSampleCountChanged(){
void SessionItem::handleDownloadedFirmware()
{
FileIO f;
BossacWrapper bw;
f.writeRawByFilename(bw.getTmpPathForFirmware() + "/firmware.bin", m_firmware_fd->downloadedData());
f.writeRawByFilename(getTmpPathForFirmware() + "/firmware.bin", m_firmware_fd->downloadedData());
delete m_firmware_fd;
m_firmware_fd = NULL;
@@ -233,6 +242,7 @@ void SessionItem::updateAllMeasurements() {
void SessionItem::downloadFromUrl(QString url)
{
Q_UNUSED(url);
/*
* this causes Error in `/home/dan/work/git/build-pixelpulse2-Desktop_Qt_5_5_1_GCC_64bit3-Debug/pixelpulse2': corrupted double-linked list: 0x0000000001bf9140 ***
*
@@ -241,7 +251,18 @@ void SessionItem::downloadFromUrl(QString url)
connect(m_firmware_fd, SIGNAL (downloaded()), this, SLOT (handleDownloadedFirmware()));
*/
}
QString SessionItem::flash_firmware(QString url){
QString ret = "";
int flashed = 0;
try{
flashed = m_session->flash_firmware(url.toStdString());
}
catch(std::runtime_error &e){
ret = e.what();
}
return ret;
}
void SessionItem::getSamples()
{
if (!m_active)
@@ -314,6 +335,12 @@ void SessionItem::beginNewSweep()
}
}
int SessionItem::programmingModeDeviceExists(){
std::vector<libusb_device*> samba_devs;
return m_session->scan_samba_devs(samba_devs);
}
/// DeviceItem constructor
DeviceItem::DeviceItem(SessionItem* parent, Device* dev):
+4
View File
@@ -47,6 +47,10 @@ public:
Q_INVOKABLE void updateAllMeasurements();
Q_INVOKABLE void downloadFromUrl(QString url);
Q_INVOKABLE QString flash_firmware(QString url);
Q_INVOKABLE QString getTmpPathForFirmware();
Q_INVOKABLE int programmingModeDeviceExists();
bool isContinuous(){return m_continuous;}
bool getActive() { return m_active; }
QQmlListProperty<DeviceItem> getDevices() { return QQmlListProperty<DeviceItem>(this, m_devices); }
-3
View File
@@ -7,7 +7,6 @@
#include "SMU.h"
#include "utils/backtracing.h"
#include "utils/bossac_wrap.h"
#include "utils/fileio.h"
int main(int argc, char *argv[])
@@ -26,7 +25,6 @@ int main(int argc, char *argv[])
registerTypes();
FileIO fileIO;
BossacWrapper bossacWrapper;
SessionItem smu_session;
smu_session.openAllDevices();
engine.rootContext()->setContextProperty("session", &smu_session);
@@ -36,7 +34,6 @@ int main(int argc, char *argv[])
versions.insert("git_version", GIT_VERSION);
engine.rootContext()->setContextProperty("versions", versions);
engine.rootContext()->setContextProperty("fileio", &fileIO);
engine.rootContext()->setContextProperty("bossac", &bossacWrapper);
if (argc > 1) {
if (strcmp(argv[1], "-v") || strcmp(argv[1], "--version")) {
std::cout << GIT_VERSION << ": Built on " << BUILD_DATE << std::endl;
-1
View File
@@ -64,7 +64,6 @@ HEADERS += \
Plot/PhosphorRender.h \
Plot/FloatBuffer.h \
utils/fileio.h \
utils/bossac_wrap.h \
utils/filedownloader.h
win32:debug {
+84 -81
View File
@@ -9,6 +9,8 @@ ColumnLayout {
id: smpLayout
spacing: 12
property bool updateNeeded: false
property bool justUpdated: false
function addProgModeDeviceToList()
{
devicesModel.insert(devicesModel.count,
@@ -34,12 +36,9 @@ ColumnLayout {
function programmingModeDeviceExists()
{
var msg = bossac.deviceInformation();
var deviceExists = false;
if (msg.indexOf("Device found") > -1) {
deviceExists = true;
}
if(session.programmingModeDeviceExists() > 0)
deviceExists = true;
return deviceExists;
}
@@ -79,15 +78,30 @@ ColumnLayout {
}
devicesModel.clear();
}
console.log(programmingModeDeviceDetect()+" detected devices");
if(programmingModeDeviceDetect()){
if(!justUpdated){
updateNeeded = true;
}
justUpdated = false;
console.log("update needded: " + updateNeeded);
}
for (var i = 0; i < session.devices.length; i++) {
var device = session.devices[i];
var updt_needed = false;
if (device.FWVer.indexOf('.') === -1) // The firmware might be so old that won't provide the version in the 'major.minor' format
{
updt_needed = true;
else if (parseFloat(device.FWVer) < parseFloat(devListView.latestVersion.substring(1)))
updt_needed = true;
updateNeeded = true;
}
else if (parseFloat(device.FWVer) < parseFloat(devListView.latestVersion.substring(1))){
updt_needed = true;
updateNeeded = true;
}
console.log("Right before dev insert \n");
devicesModel.insert(devicesModel.count,
{"name": device.label,
"uid":device.UUID,
@@ -272,88 +286,16 @@ ColumnLayout {
height: parent.height
width: 115
radius: 4
color: 'grey'
color: 'black'
visible: fw_updt_needed === true
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 2
height: parent.height - 2
radius: 4
gradient: Gradient {
GradientStop { position: 0.0; color: '#565666' }
GradientStop { position: 0.15; color: '#6a6a7d' }
GradientStop { position: 0.5; color: '#5a5a6a' }
GradientStop { position: 1.0; color: '#585868' }
}
Text {
x: 5
text: "Update Firmware"
font.pointSize: 10
color: 'white'
color: 'steelblue'
anchors.verticalCenter: parent.verticalCenter
}
MouseArea {
property color lastColor: 'black'
visible: !updt_in_progress
hoverEnabled: true
anchors.fill: parent
onClicked: {
var ret;
var err;
var firmwareFilePath = bossac.getTmpPathForFirmware() + "/firmware.bin";
if (name === "[Device In Programming Mode]") {
// Devices in programming mode can be disconnected without us to know about it, so check if the device is still there.
if (!programmingModeDeviceExists()) {
clearProgModeDeviceFromList();
return;
}
ret = bossac.flashByFilename(firmwareFilePath);
if (ret.length === 0) {
devicesModel.setProperty(index, "firmware_version", devListView.latestVersion);
devicesModel.setProperty(index,"status", "ok");
} else {
devicesModel.setProperty(index,"status", "error");
logOutput.appendMessage(ret);
}
} else if (!programmingModeDeviceDetect()) {
devicesModel.setProperty(index, "updt_in_progress", true);
if (!bossac.checkFileExists(bossac.getBossacPath())) {
ret = "Could not find bossac.exe at:" + bossac.getBossacPath();
} else if (!bossac.checkFileExists(firmwareFilePath)) {
ret = "Could not find firmware at:" + firmwareFilePath;
} else {
session.devices[index].ctrl_transfer(0xBB, 0, 0);
ret = bossac.flashByFilename(firmwareFilePath);
}
if (ret.length === 0) {
devicesModel.setProperty(index, "firmware_version", devListView.latestVersion);
devicesModel.setProperty(index,"status", "ok");
} else {
devicesModel.setProperty(index,"status", "error");
logOutput.appendMessage(ret);
}
devicesModel.setProperty(index, "fw_updt_needed", false);
// TO DO: Now the user needs to unplug the device. App should monitor the COM port to check if the device has been disconnected
// and remove the item in the device list. The monitoring should be done in a separate thread.
} else {
logOutput.appendMessage("A device is already in programming mode and needs to be programmed first!");
}
}
onPressed: devUpdateBtn.color = 'black'
onReleased: devUpdateBtn.color = 'grey'
}
}
}
}
}
@@ -408,6 +350,67 @@ ColumnLayout {
}
}
}
Rectangle {
id: updateBtn
anchors { right: parent.right;
bottom: logCleanBtn.top;
bottomMargin: 5;
rightMargin: 5 }
height: 25
width: 145
radius: 4
color: 'grey'
visible: updateNeeded === true
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 2
height: parent.height - 2
radius: 4
gradient: Gradient {
GradientStop { position: 0.0; color: '#565666' }
GradientStop { position: 0.15; color: '#6a6a7d' }
GradientStop { position: 0.5; color: '#5a5a6a' }
GradientStop { position: 1.0; color: '#585868' }
}
Text {
x: 5
text: "Update Firmware"
font.pointSize: 10
color: 'white'
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
}
MouseArea {
hoverEnabled: true
anchors.fill: parent
onClicked: {
var firmwareFilePath = session.getTmpPathForFirmware() + "/firmware.bin";
var ret;
session.closeAllDevices();
devicesModel.clear();
justUpdated = true;
updateNeeded = false;
ret = session.flash_firmware(firmwareFilePath);
if (ret.length === 0) {
logOutput.appendMessage("All devices were succesfully updated. Disconnect devices");
} else {
logOutput.appendMessage(ret);
}
}
onPressed: updateBtn.color = 'black'
onReleased: updateBtn.color = 'grey'
}
}
}
Rectangle {
id: logCleanBtn
-143
View File
@@ -1,143 +0,0 @@
/// simple implementation of bossac flashing and verification
#ifndef BOSSAC_H
#define BOSSAC_H
#include <QProcess>
#include <QObject>
#include <QTextStream>
#include <QTimer>
#include <QFileInfo>
#include <QApplication>
#include <stdlib.h>
#include <QStandardPaths>
#include <QDir>
#if defined(Q_OS_MAC)
#include "CoreFoundation/CoreFoundation.h"
#endif
#include <QDebug>
class BossacWrapper: public QObject
{
Q_OBJECT
private:
QString getEnvVar(const QString varName)
{
return getenv(varName.toStdString().c_str());
}
public slots:
bool checkFileExists(const QString& filepath)
{
QFileInfo fInfo(filepath);
return fInfo.exists();
}
QString getTmpPathForFirmware()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
path += "/pixelpulse2/m1k_firmware";
QDir dir(path);
if (!dir.exists())
dir.mkpath(".");
return dir.path();
}
QString getBossacPath() {
QString current_path = QCoreApplication::applicationDirPath() + "/";
#ifdef Q_OS_LINUX
return (current_path + "bossac");
#elif defined(Q_OS_WIN32)
return (current_path + "bossac.exe");
#elif defined(Q_OS_MAC)
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[4096];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, 4096))
{
// error!
}
CFRelease(resourcesURL);
QString s((const char *)path);
s.append("/bossac");
return s;
#else
#error "We don't support this platform yet."
#endif
}
QString flashByFilename(const QString& image) {
QTimer timer;
bool devReadyToProg = false;
bool timeout = false;
QString ret = "";
if (!checkFileExists(image)) {
ret = "Cannot find " + image + " file.";
return ret;
}
// At this point device is set in programming mode. Make sure bossac sees it before
// attempting to flash it.
timer.setInterval(10000);
timer.start();
while (!devReadyToProg && !timeout) {
QString output = deviceInformation();
qDebug() << output;
if (output.contains("Device found", Qt::CaseInsensitive)) {
devReadyToProg = true;
} else {
if (timer.remainingTime() == 0) {
timeout = true;
ret = "The process of programming of the device has timeout!";
}
}
}
if (timeout)
return ret;
// Flash the device
QProcess bossacThread;
QString program = getBossacPath();
QStringList arguments;
arguments << "-e" /*erase*/ << "-w" /*write*/ << "-v" /*verify*/ << "-b" /*boot into flash*/ << image;
bossacThread.setProcessChannelMode(QProcess::MergedChannels);
if (devReadyToProg) {
bossacThread.start(program, arguments);
if (bossacThread.waitForFinished()) {
qDebug() << bossacThread.readAllStandardOutput();
} else {
ret = "Failed to run the bossac process.";
}
}
return ret;
}
QString deviceInformation()
{
QProcess bossacThread;
QString program = getBossacPath();
QStringList arguments;
arguments << "-i" /*info*/;
bossacThread.setProcessChannelMode(QProcess::MergedChannels);
bossacThread.start(program, arguments);
bossacThread.waitForFinished();
return bossacThread.readAllStandardOutput();
}
public:
BossacWrapper() {}
};
#endif // BOSSAC_H