Skip to content

Commit

Permalink
openmv: Alif bootloader loads firmware in under a minute.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Nov 18, 2024
1 parent 3079df0 commit 2df2a55
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 36 deletions.
4 changes: 4 additions & 0 deletions share/qtcreator/firmware/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@
"Interface": "isp",
"Jtag-adapter": "J-Link"
}
},
"dfuBootloaderProgramCommand" : {
"images": "../build/images/bootloader.bin 0x80000000 ../build/AppTocPackage.bin 0x8057f060",
"bootloaderVidPid": "37C5:96E3"
}
}
},
Expand Down
29 changes: 19 additions & 10 deletions src/plugins/openmv/bootloaders/openmvpluginalifbootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,25 @@ void OpenMVPlugin::openmvAlifBootloader(const QString &forceFirmwarePath,
{
if(alifDownloadFirmware(selectedDfuDevice.split(QStringLiteral(",")).last(), originalFirmwareFolder, outObj))
{
if((m_autoUpdate.isEmpty()) && (!m_autoErase)) QMessageBox::information(Core::ICore::dialogParent(),
Tr::tr("Connect"),
Tr::tr("Firmware update complete!\n\n") +
Tr::tr("If you are forcing SBL mode, disconnect your OpenMV Cam from your computer and reset the SBL switch. "
"Then reconnect your OpenMV Cam to your computer.\n\n") +
Tr::tr("Click the Ok button after your OpenMV Cam has enumerated and finished running its built-in self test (blue led blinking - this takes a while).") +
Tr::tr("\n\nIf you overwrote main.py on your OpenMV Cam and did not erase the disk then your OpenMV Cam will just run that main.py."
"\n\nIn this case click OK when you see your OpenMV Cam's internal flash drive mount (a window may or may not pop open)."));

RECONNECT_WAIT_END();
QJsonObject dfuBootloaderProgramCommand = outObj.value(QStringLiteral("dfuBootloaderProgramCommand")).toObject();

if (!dfuBootloaderProgramCommand.isEmpty())
{
openmvDFUBootloader(forceFlashFSErase, justEraseFlashFs, QString(), dfuBootloaderProgramCommand.value(QStringLiteral("bootloaderVidPid")).toString() + QStringLiteral(",NULL"));
}
else
{
if((m_autoUpdate.isEmpty()) && (!m_autoErase)) QMessageBox::information(Core::ICore::dialogParent(),
Tr::tr("Connect"),
Tr::tr("Firmware update complete!\n\n") +
Tr::tr("If you are forcing SBL mode, disconnect your OpenMV Cam from your computer and reset the SBL switch. "
"Then reconnect your OpenMV Cam to your computer.\n\n") +
Tr::tr("Click the Ok button after your OpenMV Cam has enumerated and finished running its built-in self test (blue led blinking - this takes a while).") +
Tr::tr("\n\nIf you overwrote main.py on your OpenMV Cam and did not erase the disk then your OpenMV Cam will just run that main.py."
"\n\nIn this case click OK when you see your OpenMV Cam's internal flash drive mount (a window may or may not pop open)."));

RECONNECT_WAIT_END();
}
}
else
{
Expand Down
95 changes: 69 additions & 26 deletions src/plugins/openmv/tools/alif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ bool alifDownloadFirmware(const QString &port, const QString &originalFirmwareFo
{
QMutexLocker locker(&alif_tools_working);

QJsonObject dfuBootloaderProgramCommand = obj.value(QStringLiteral("dfuBootloaderProgramCommand")).toObject();

bool result = true;
Utils::Process process;

Expand Down Expand Up @@ -544,38 +546,79 @@ bool alifDownloadFirmware(const QString &port, const QString &originalFirmwareFo
}
}

// App Write Mram
if (!dfuBootloaderProgramCommand.isEmpty())
{
QStringList args = QStringList();

QString command = QString(QStringLiteral("%1 %2")).arg(appWriteMramBinary.toString()).arg(args.join(QLatin1Char(' ')));
dialog->appendColoredText(command);
// Write Bootloader
{
QStringList args = QStringList() << QStringLiteral("-i") <<
dfuBootloaderProgramCommand.value(QStringLiteral("images")).toString();

std::chrono::seconds timeout(300); // 5 minutes...
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine);
process.setProcessMode(Utils::ProcessMode::Writer);
process.setWorkingDirectory(appWriteMramBinary.parentDir());
process.setCommand(Utils::CommandLine(appWriteMramBinary, args));
process.runBlocking(timeout, Utils::EventLoopMode::On, QEventLoop::AllEvents);
QString command = QString(QStringLiteral("%1 %2")).arg(appWriteMramBinary.toString()).arg(args.join(QLatin1Char(' ')));
dialog->appendColoredText(command);

if((process.result() != Utils::ProcessResult::FinishedWithSuccess) && (process.result() != Utils::ProcessResult::TerminatedAbnormally))
{
QMessageBox box(QMessageBox::Critical, Tr::tr("Alif Tools"), Tr::tr("Timeout Error!"), QMessageBox::Ok, Core::ICore::dialogParent(),
Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
(Utils::HostOsInfo::isMacHost() ? Qt::WindowType(0) : Qt::WindowCloseButtonHint));
box.setDetailedText(command + QStringLiteral("\n\n") + process.stdOut() + QStringLiteral("\n") + process.stdErr());
box.setDefaultButton(QMessageBox::Ok);
box.setEscapeButton(QMessageBox::Cancel);
box.exec();
std::chrono::seconds timeout(300); // 5 minutes...
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine);
process.setProcessMode(Utils::ProcessMode::Writer);
process.setWorkingDirectory(appWriteMramBinary.parentDir());
process.setCommand(Utils::CommandLine(appWriteMramBinary, args));
process.runBlocking(timeout, Utils::EventLoopMode::On, QEventLoop::AllEvents);

result = false;
goto cleanup;
if((process.result() != Utils::ProcessResult::FinishedWithSuccess) && (process.result() != Utils::ProcessResult::TerminatedAbnormally))
{
QMessageBox box(QMessageBox::Critical, Tr::tr("Alif Tools"), Tr::tr("Timeout Error!"), QMessageBox::Ok, Core::ICore::dialogParent(),
Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
(Utils::HostOsInfo::isMacHost() ? Qt::WindowType(0) : Qt::WindowCloseButtonHint));
box.setDetailedText(command + QStringLiteral("\n\n") + process.stdOut() + QStringLiteral("\n") + process.stdErr());
box.setDefaultButton(QMessageBox::Ok);
box.setEscapeButton(QMessageBox::Cancel);
box.exec();

result = false;
goto cleanup;
}
else if(process.result() == Utils::ProcessResult::TerminatedAbnormally)
{
result = false;
goto cleanup;
}
}
else if(process.result() == Utils::ProcessResult::TerminatedAbnormally)
}
else
{
// App Write Mram
{
result = false;
goto cleanup;
QStringList args = QStringList();

QString command = QString(QStringLiteral("%1 %2")).arg(appWriteMramBinary.toString()).arg(args.join(QLatin1Char(' ')));
dialog->appendColoredText(command);

std::chrono::seconds timeout(300); // 5 minutes...
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine);
process.setProcessMode(Utils::ProcessMode::Writer);
process.setWorkingDirectory(appWriteMramBinary.parentDir());
process.setCommand(Utils::CommandLine(appWriteMramBinary, args));
process.runBlocking(timeout, Utils::EventLoopMode::On, QEventLoop::AllEvents);

if((process.result() != Utils::ProcessResult::FinishedWithSuccess) && (process.result() != Utils::ProcessResult::TerminatedAbnormally))
{
QMessageBox box(QMessageBox::Critical, Tr::tr("Alif Tools"), Tr::tr("Timeout Error!"), QMessageBox::Ok, Core::ICore::dialogParent(),
Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
(Utils::HostOsInfo::isMacHost() ? Qt::WindowType(0) : Qt::WindowCloseButtonHint));
box.setDetailedText(command + QStringLiteral("\n\n") + process.stdOut() + QStringLiteral("\n") + process.stdErr());
box.setDefaultButton(QMessageBox::Ok);
box.setEscapeButton(QMessageBox::Cancel);
box.exec();

result = false;
goto cleanup;
}
else if(process.result() == Utils::ProcessResult::TerminatedAbnormally)
{
result = false;
goto cleanup;
}
}
}

Expand Down

0 comments on commit 2df2a55

Please sign in to comment.