1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include "bootloaderinstallbase.h"
26 #if defined(Q_OS_MACX)
27 #include <sys/param.h>
28 #include <sys/ucred.h>
29 #include <sys/mount.h>
32 BootloaderInstallBase::BootloaderType
BootloaderInstallBase::installed(void)
34 return BootloaderUnknown
;
38 BootloaderInstallBase::Capabilities
BootloaderInstallBase::capabilities(void)
44 void BootloaderInstallBase::downloadBlStart(QUrl source
)
46 m_http
.setFile(&m_tempfile
);
47 m_http
.setCache(true);
48 connect(&m_http
, SIGNAL(done(bool)), this, SLOT(downloadBlFinish(bool)));
49 // connect the http read signal to our logProgess *signal*
50 // to immediately emit it without any helper function.
51 connect(&m_http
, SIGNAL(dataReadProgress(int, int)),
52 this, SIGNAL(logProgress(int, int)));
53 m_http
.getFile(source
);
57 void BootloaderInstallBase::downloadReqFinished(int id
, bool error
)
59 qDebug() << "[BootloaderInstallBase] Download Request" << id
60 << "finished, error:" << m_http
.errorString();
62 downloadBlFinish(error
);
66 void BootloaderInstallBase::downloadBlFinish(bool error
)
68 qDebug() << "[BootloaderInstallBase] Downloading bootloader finished, error:"
71 // update progress bar
72 emit
logProgress(100, 100);
74 if(m_http
.httpResponse() != 200) {
75 emit
logItem(tr("Download error: received HTTP error %1.")
76 .arg(m_http
.errorString()), LOGERROR
);
81 emit
logItem(tr("Download error: %1")
82 .arg(m_http
.error()), LOGERROR
);
86 else if(m_http
.isCached())
87 emit
logItem(tr("Download finished (cache used)."), LOGOK
);
89 emit
logItem(tr("Download finished."), LOGOK
);
91 QCoreApplication::processEvents();
92 m_blversion
= m_http
.timestamp();
96 void BootloaderInstallBase::installBlfile(void)
98 qDebug() << "[BootloaderInstallBase]" << __func__
;
102 //! @brief backup OF file.
103 //! @param to folder to write backup file to. Folder will get created.
104 //! @return true on success, false on error.
106 bool BootloaderInstallBase::backup(QString to
)
108 qDebug() << "[BootloaderInstallBase] Backing up bootloader file";
110 emit
logItem(tr("Creating backup of original firmware file."), LOGINFO
);
111 if(!targetDir
.mkpath(to
)) {
112 emit
logItem(tr("Creating backup folder failed"), LOGERROR
);
115 QString tofile
= to
+ "/" + QFileInfo(m_blfile
).fileName();
116 qDebug() << "[BootloaderInstallBase] trying to backup" << m_blfile
<< "to" << tofile
;
117 if(!QFile::copy(Utils::resolvePathCase(m_blfile
), tofile
)) {
118 emit
logItem(tr("Creating backup copy failed."), LOGERROR
);
121 emit
logItem(tr("Backup created."), LOGOK
);
126 //! @brief log installation to logfile.
127 //! @param mode action to perform. 0: add to log, 1: remove from log.
128 //! @return 0 on success
129 int BootloaderInstallBase::logInstall(LogMode mode
)
132 QString section
= m_blurl
.path().section('/', -1);
133 QSettings
s(m_logfile
, QSettings::IniFormat
, this);
134 emit
logItem(tr("Creating installation log"), LOGINFO
);
137 s
.setValue("Bootloader/" + section
, m_blversion
.toString(Qt::ISODate
));
138 qDebug() << "[BootloaderInstallBase] Writing log, version:"
139 << m_blversion
.toString(Qt::ISODate
);
142 s
.remove("Bootloader/" + section
);
146 emit
logItem(tr("Installation log created"), LOGOK
);
152 //! @brief Return post install hints string.
153 //! @param model model string
155 QString
BootloaderInstallBase::postinstallHints(QString model
)
158 QString msg
= tr("Bootloader installation is almost complete. "
159 "Installation <b>requires</b> you to perform the "
160 "following steps manually:");
163 msg
+= tr("<li>Safely remove your player.</li>");
164 if(model
== "h100" || model
== "h120" || model
== "h300" ||
165 model
== "ondavx747") {
167 msg
+= tr("<li>Reboot your player into the original firmware.</li>"
168 "<li>Perform a firmware upgrade using the update functionality "
169 "of the original firmware. Please refer to your player's manual "
171 "<li>After the firmware has been updated reboot your player.</li>");
173 if(model
== "iaudiox5" || model
== "iaudiom5"
174 || model
== "iaudiox5v" || model
== "iaudiom3") {
176 msg
+= tr("<li>Turn the player off</li>"
177 "<li>Insert the charger</li>");
179 if(model
== "gigabeatf") {
181 msg
+= tr("<li>Unplug USB and power adaptors</li>"
182 "<li>Hold <i>Power</i> to turn the player off</li>"
183 "<li>Toggle the battery switch on the player</li>"
184 "<li>Hold <i>Power</i> to boot into Rockbox</li>");
188 msg
+= tr("<p><b>Note:</b> You can safely install other parts first, but "
189 "the above steps are <b>required</b> to finish the installation!</p>");
198 #if defined(Q_OS_MACX)
199 void BootloaderInstallBase::waitRemount()
201 m_remountTries
= 600;
202 emit
logItem(tr("Waiting for system to remount player"), LOGINFO
);
204 QTimer::singleShot(100, this, SLOT(checkRemount()));
209 void BootloaderInstallBase::checkRemount()
211 #if defined(Q_OS_MACX)
212 if(m_remountTries
--) {
214 // check if device has been remounted
215 QCoreApplication::processEvents();
217 struct statfs
*mntinf
;
219 num
= getmntinfo(&mntinf
, MNT_WAIT
);
221 if(QString(mntinf
->f_mntfromname
).startsWith(m_remountDevice
)
222 && QString(mntinf
->f_fstypename
).contains("msdos", Qt::CaseInsensitive
))
227 // still not remounted, restart timer.
228 QTimer::singleShot(500, this, SLOT(checkRemount()));
229 qDebug() << "[BootloaderInstallBase] Player not remounted yet" << m_remountDevice
;
232 emit
logItem(tr("Player remounted"), LOGINFO
);
233 emit
remounted(true);
237 emit
logItem(tr("Timeout on remount"), LOGERROR
);
238 emit
remounted(false);
244 //! @brief set list of possible bootloader files and pick the existing one.
245 //! @param sl list of possible bootloader files.
246 void BootloaderInstallBase::setBlFile(QStringList sl
)
248 // figue which of the possible bootloader filenames is correct.
249 for(int a
= 0; a
< sl
.size(); a
++) {
250 if(!Utils::resolvePathCase(sl
.at(a
)).isEmpty()) {
254 if(m_blfile
.isEmpty()) {