From 61f999a16e601aa0cf61a342654b5574a626f7c7 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Wed, 4 Jan 2012 19:19:02 +0000 Subject: [PATCH] Rockbox Utility: add support for mkimxboot bootloader. Reworked version of FS#12402 by Jean-Louis Biasini. Since the mkimxboot process takes quite a while which blocks the UI it has been adjusted to perform the actual firmware patching in a separate process. Various other small changes have been made to make it fit better into Rockbox Utility's dialogs / messages and update the code to latest changes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31580 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/bootloaderinstallbase.cpp | 18 +++ rbutil/rbutilqt/base/bootloaderinstallimx.cpp | 189 +++++++++++++++++++++++++ rbutil/rbutilqt/base/bootloaderinstallimx.h | 47 ++++++ rbutil/rbutilqt/rbutil.ini | 3 +- rbutil/rbutilqt/rbutilqt.pri | 2 + rbutil/rbutilqt/rbutilqt.pro | 8 +- 6 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 rbutil/rbutilqt/base/bootloaderinstallimx.cpp create mode 100644 rbutil/rbutilqt/base/bootloaderinstallimx.h diff --git a/rbutil/rbutilqt/base/bootloaderinstallbase.cpp b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp index 0492525c05..750e33bef8 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallbase.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallbase.cpp @@ -29,6 +29,7 @@ #include "bootloaderinstallams.h" #include "bootloaderinstalltcc.h" #include "bootloaderinstallmpio.h" +#include "bootloaderinstallimx.h" #include "utils.h" #if defined(Q_OS_MACX) @@ -67,6 +68,9 @@ BootloaderInstallBase* BootloaderInstallBase::createBootloaderInstaller(QObject* else if(type == "mpio") { return new BootloaderInstallMpio(parent); } + else if(type == "imx") { + return new BootloaderInstallImx(parent); + } else { return NULL; } @@ -205,6 +209,10 @@ QString BootloaderInstallBase::postinstallHints(QString model) msg += "
    "; msg += tr("
  1. Safely remove your player.
  2. "); + if(model == "sansafuzeplus") { + msg += tr("
  3. Remove any previously inserted microSD card
  4. "); + hint = true; + } if(model == "h100" || model == "h120" || model == "h300" || model == "ondavx747") { hint = true; @@ -217,6 +225,16 @@ QString BootloaderInstallBase::postinstallHints(QString model) "process." "
  5. After the firmware has been updated reboot your player.
  6. "); } + if(model == "sansafuzeplus") { + hint = true; + msg += tr("
  7. Disconnect your player. The player will reboot and " + "perform an update of the original firmware. " + "Please refer to your players manual on details.
    " + "Important: updating the firmware is a " + "critical process that must not be interrupted. Make sure the " + "player is charged before disconnecting the player.
  8. " + "
  9. After the firmware has been updated reboot your player.
  10. "); + } if(model == "iaudiox5" || model == "iaudiom5" || model == "iaudiox5v" || model == "iaudiom3" || model == "mpioh200") { hint = true; diff --git a/rbutil/rbutilqt/base/bootloaderinstallimx.cpp b/rbutil/rbutilqt/base/bootloaderinstallimx.cpp new file mode 100644 index 0000000000..e25244f80a --- /dev/null +++ b/rbutil/rbutilqt/base/bootloaderinstallimx.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2011 by Jean-Louis Biasini + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include "bootloaderinstallbase.h" +#include "bootloaderinstallimx.h" +#include "../mkimxboot/mkimxboot.h" + +// class for running mkimxboot() in a separate thread to keep the UI responsive. +class BootloaderThreadImx : public QThread +{ + public: + void run(void); + void setInputFile(QString f) + { m_inputfile = f; } + void setOutputFile(QString f) + { m_outputfile = f; } + void setBootloaderFile(QString f) + { m_bootfile = f; } + enum imx_error_t error(void) + { return m_error; } + private: + QString m_inputfile; + QString m_bootfile; + QString m_outputfile; + enum imx_error_t m_error; +}; + + +void BootloaderThreadImx::run(void) +{ + qDebug() << "[BootloaderThreadImx] Thread started."; + struct imx_option_t opt; + opt.debug = false; + opt.output = IMX_DUALBOOT; + + m_error = mkimxboot(m_inputfile.toLocal8Bit().constData(), + m_bootfile.toLocal8Bit().constData(), + m_outputfile.toLocal8Bit().constData(), opt); + qDebug() << "[BootloaderThreadImx] Thread finished, result:" << m_error; +} + + +BootloaderInstallImx::BootloaderInstallImx(QObject *parent) + : BootloaderInstallBase(parent) +{ + m_thread = NULL; +} + + +QString BootloaderInstallImx::ofHint() +{ + return tr("Bootloader installation requires you to provide " + "a copy of the original Sandisk firmware (firmware.sb file). " + "This file will be patched with the Rockbox bootloader and " + "installed to your player. You need to download this file " + "yourself due to legal reasons. Please browse the " + "Sansa Forums " + "or refer to the " + "SansaFuzePlus " + "wiki page on how to obtain this file.
    " + "Press Ok to continue and browse your computer for the firmware " + "file."); +} + + +/** Start bootloader installation. + */ +bool BootloaderInstallImx::install(void) +{ + if(!QFileInfo(m_offile).isReadable()) + { + qDebug() << "[BootloaderInstallImx] could not read original firmware file" + << m_offile; + emit logItem(tr("Could not read original firmware file"), LOGERROR); + return false; + } + + qDebug() << "[BootloaderInstallImx] downloading bootloader"; + // download bootloader from server + emit logItem(tr("Downloading bootloader file"), LOGINFO); + connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2())); + downloadBlStart(m_blurl); + return true; +} + + +void BootloaderInstallImx::installStage2(void) +{ + qDebug() << "[BootloaderInstallImx] patching file..."; + emit logItem(tr("Patching file..."), LOGINFO); + m_tempfile.open(); + + // we have not detailed progress on the patching so just show a busy + // indicator instead. + emit logProgress(0, 0); + m_patchedFile.open(); + m_thread = new BootloaderThreadImx(); + m_thread->setInputFile(m_offile); + m_thread->setBootloaderFile(m_tempfile.fileName()); + m_thread->setOutputFile(m_patchedFile.fileName()); + m_tempfile.close(); + m_patchedFile.close(); + connect(m_thread, SIGNAL(finished()), this, SLOT(installStage3())); + connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3())); + m_thread->start(); +} + + +void BootloaderInstallImx::installStage3(void) +{ + enum imx_error_t err = m_thread->error(); + emit logProgress(1, 1); + // if the patch failed + if (err != IMX_SUCCESS) + { + qDebug() << "[BootloaderInstallImx] Could not patch the original firmware file"; + emit logItem(tr("Patching the original firmware failed"), LOGERROR); + emit done(true); + return; + } + + qDebug() << "[BootloaderInstallImx] Original Firmware succesfully patched"; + emit logItem(tr("Succesfully patched firmware file"), LOGINFO); + + // if a bootloader is already present delete it. + QString fwfile(m_blfile); + if(QFileInfo(fwfile).isFile()) + { + qDebug() << "[BootloaderInstallImx] deleting old target file"; + QFile::remove(fwfile); + } + + // place (new) bootloader. Copy, since the temporary file will be removed + // automatically. + qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile; + if(m_patchedFile.copy(fwfile)) + { + emit logItem(tr("Bootloader successful installed"), LOGOK); + logInstall(LogAdd); + emit done(false); + } + else + { + emit logItem(tr("Patched bootloader could not be installed"), LOGERROR); + emit done(true); + } + // clean up thread object. + delete m_thread; + return; +} + + +bool BootloaderInstallImx::uninstall(void) +{ + emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified " + "original firmware."), LOGINFO); + logInstall(LogRemove); + return false; +} + + +BootloaderInstallBase::BootloaderType BootloaderInstallImx::installed(void) +{ + return BootloaderUnknown; +} + + +BootloaderInstallBase::Capabilities BootloaderInstallImx::capabilities(void) +{ + return (Install | NeedsOf); +} + diff --git a/rbutil/rbutilqt/base/bootloaderinstallimx.h b/rbutil/rbutilqt/base/bootloaderinstallimx.h new file mode 100644 index 0000000000..1d780998ef --- /dev/null +++ b/rbutil/rbutilqt/base/bootloaderinstallimx.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2011 by Jean-Louis Biasini + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef BOOTLOADERINSTALLIMX_H +#define BOOTLOADERINSTALLIMX_H + +#include +#include "bootloaderinstallbase.h" + +class BootloaderThreadImx; + +//! bootloader installation class for devices handled by mkimxboot. +class BootloaderInstallImx : public BootloaderInstallBase +{ + Q_OBJECT + public: + BootloaderInstallImx(QObject *parent); + bool install(void); + bool uninstall(void); + BootloaderInstallBase::BootloaderType installed(void); + Capabilities capabilities(void); + QString ofHint(); + + private slots: + void installStage2(void); + void installStage3(void); + + private: + BootloaderThreadImx *m_thread; + QTemporaryFile m_patchedFile; +}; + +#endif diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini index fdd8ff2ee6..e59b4e3e49 100644 --- a/rbutil/rbutilqt/rbutil.ini +++ b/rbutil/rbutilqt/rbutil.ini @@ -501,7 +501,7 @@ encoder=rbspeex [sansafuzeplus] name="Sansa Fuze+" buildserver_modelname=sansafuzeplus -bootloadermethod=none ; no bootloader for now +bootloadermethod=imx bootloadername=/sandisk-sansa/fuzeplus/bootloader-fuzeplus.sansa bootloaderfile=/firmware.sb manualname= @@ -510,7 +510,6 @@ usbid=0x078174e1 usberror= configure_modelname=sansafuzeplus encoder=rbspeex -status=disabled [sansam200v4] name="Sansa m200v4" diff --git a/rbutil/rbutilqt/rbutilqt.pri b/rbutil/rbutilqt/rbutilqt.pri index 66bcbcbf7c..c8d3f58546 100644 --- a/rbutil/rbutilqt/rbutilqt.pri +++ b/rbutil/rbutilqt/rbutilqt.pri @@ -60,6 +60,7 @@ SOURCES += \ base/bootloaderinstallams.cpp \ base/bootloaderinstalltcc.cpp \ base/bootloaderinstallmpio.cpp \ + base/bootloaderinstallimx.cpp \ base/rockboxinfo.cpp \ ../../tools/mkboot.c \ ../../tools/iriver.c \ @@ -121,6 +122,7 @@ HEADERS += \ base/bootloaderinstallams.h \ base/bootloaderinstalltcc.h \ base/bootloaderinstallmpio.h \ + base/bootloaderinstallimx.h \ base/rockboxinfo.h \ ../../tools/mkboot.h \ ../../tools/iriver.h \ diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 6ff1831e6a..270e47b1f7 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -125,10 +125,16 @@ libchinachippatcher.commands = $$ADDENV \ APPVERSION=\"rbutil\" \ CC=\"$$QMAKE_CC\" CFLAGS=\"$$MACHINEFLAGS\" AR=\"$$MYAR\" \ $(MAKE) -C $$RBBASE_DIR/rbutil/chinachippatcher libchinachippatcher$$RBLIBPOSTFIX +libmkimxboot.commands = $$ADDENV \ + BUILD_DIR=$$MYLIBBUILDDIR/mkimxboot/ \ + TARGET_DIR=$$MYLIBBUILDDIR \ + APPVERSION=\"rbutil\" \ + CC=\"$$QMAKE_CC\" CFLAGS=\"$$MACHINEFLAGS\" AR=\"$$MYAR\" \ + $(MAKE) -C $$RBBASE_DIR/rbutil/mkimxboot libmkimxboot$$RBLIBPOSTFIX # Note: order is important for RBLIBS! The libs are appended to the linker # flags in this order, put libucl at the end. RBLIBS = librbspeex libipodpatcher libsansapatcher libmkamsboot libmktccboot \ - libmkmpioboot libchinachippatcher libucl + libmkmpioboot libchinachippatcher libmkimxboot libucl QMAKE_EXTRA_TARGETS += $$RBLIBS PRE_TARGETDEPS += $$RBLIBS -- 2.11.4.GIT