1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
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 ****************************************************************************/
20 #include "installbootloader.h"
21 #include "irivertools/checksums.h"
23 BootloaderInstaller::BootloaderInstaller(QObject
* parent
): QObject(parent
)
28 void BootloaderInstaller::install(ProgressloggerInterface
* dp
)
32 m_dp
->addItem(tr("Starting bootloader installation"),LOGINFO
);
33 connect(this, SIGNAL(done(bool)), this, SLOT(installEnded(bool)));
35 if(m_bootloadermethod
== "gigabeatf")
37 // connect internal signal
38 connect(this,SIGNAL(prepare()),this,SLOT(gigabeatPrepare()));
39 connect(this,SIGNAL(finish()),this,SLOT(gigabeatFinish()));
41 else if(m_bootloadermethod
== "iaudio")
43 // connect internal signal
44 connect(this,SIGNAL(prepare()),this,SLOT(iaudioPrepare()));
45 connect(this,SIGNAL(finish()),this,SLOT(iaudioFinish()));
47 else if(m_bootloadermethod
== "h10")
49 // connect internal signal
50 connect(this,SIGNAL(prepare()),this,SLOT(h10Prepare()));
51 connect(this,SIGNAL(finish()),this,SLOT(h10Finish()));
53 else if(m_bootloadermethod
== "ipodpatcher")
55 // connect internal signal
56 connect(this,SIGNAL(prepare()),this,SLOT(ipodPrepare()));
57 connect(this,SIGNAL(finish()),this,SLOT(ipodFinish()));
59 else if(m_bootloadermethod
== "sansapatcher")
61 // connect internal signal
62 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare()));
63 connect(this,SIGNAL(finish()),this,SLOT(sansaFinish()));
65 else if(m_bootloadermethod
== "fwpatcher")
67 // connect internal signal
68 connect(this,SIGNAL(prepare()),this,SLOT(iriverPrepare()));
69 connect(this,SIGNAL(finish()),this,SLOT(iriverFinish()));
71 else if(m_bootloadermethod
== "mrobe100")
73 // connect internal signal
74 connect(this,SIGNAL(prepare()),this,SLOT(mrobe100Prepare()));
75 connect(this,SIGNAL(finish()),this,SLOT(mrobe100Finish()));
79 m_dp
->addItem(tr("unsupported install Method"),LOGERROR
);
87 void BootloaderInstaller::uninstall(ProgressloggerInterface
* dp
)
91 m_dp
->addItem(tr("Starting bootloader uninstallation"),LOGINFO
);
92 connect(this, SIGNAL(done(bool)), this, SLOT(installEnded(bool)));
94 if(m_bootloadermethod
== "gigabeatf")
96 // connect internal signal
97 connect(this,SIGNAL(prepare()),this,SLOT(gigabeatPrepare()));
99 else if(m_bootloadermethod
== "iaudio")
101 m_dp
->addItem(tr("No uninstallation possible"),LOGWARNING
);
105 else if(m_bootloadermethod
== "iaudio")
107 // connect internal signal
108 connect(this,SIGNAL(prepare()),this,SLOT(h10Prepare()));
110 else if(m_bootloadermethod
== "ipodpatcher")
112 // connect internal signal
113 connect(this,SIGNAL(prepare()),this,SLOT(ipodPrepare()));
115 else if(m_bootloadermethod
== "sansapatcher")
117 // connect internal signal
118 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare()));
120 else if(m_bootloadermethod
== "h10")
122 // connect internal signal
123 connect(this,SIGNAL(prepare()),this,SLOT(h10Prepare()));
125 else if(m_bootloadermethod
== "mrobe100")
127 // connect internal signal
128 connect(this,SIGNAL(prepare()),this,SLOT(mrobe100Prepare()));
130 else if(m_bootloadermethod
== "fwpatcher")
132 m_dp
->addItem(tr("No uninstallation possible"),LOGWARNING
);
138 m_dp
->addItem(tr("unsupported install Method"),LOGERROR
);
146 void BootloaderInstaller::downloadRequestFinished(int id
, bool error
)
148 qDebug() << "BootloaderInstall::downloadRequestFinished" << id
<< error
;
149 qDebug() << "error:" << getter
->errorString();
154 void BootloaderInstaller::downloadDone(bool error
)
156 qDebug() << "Install::downloadDone, error:" << error
;
158 // update progress bar
160 int max
= m_dp
->getProgressMax();
163 m_dp
->setProgressMax(max
);
165 m_dp
->setProgressValue(max
);
166 if(getter
->httpResponse() != 200) {
167 m_dp
->addItem(tr("Download error: received HTTP error %1.").arg(getter
->httpResponse()),LOGERROR
);
173 m_dp
->addItem(tr("Download error: %1").arg(getter
->errorString()),LOGERROR
);
178 else m_dp
->addItem(tr("Download finished."),LOGOK
);
184 void BootloaderInstaller::updateDataReadProgress(int read
, int total
)
186 m_dp
->setProgressMax(total
);
187 m_dp
->setProgressValue(read
);
188 qDebug() << "progress:" << read
<< "/" << total
;
192 void BootloaderInstaller::installEnded(bool error
)
198 bool BootloaderInstaller::downloadInfo()
200 // try to get the current build information
201 infodownloader
= new HttpGet(this);
203 connect(infodownloader
, SIGNAL(done(bool)), this, SLOT(infoDownloadDone(bool)));
204 connect(infodownloader
, SIGNAL(requestFinished(int, bool)), this, SLOT(infoRequestFinished(int, bool)));
206 qDebug() << "downloading bootloader info";
207 infodownloader
->setFile(&bootloaderInfo
);
208 infodownloader
->getFile(QUrl(m_bootloaderinfoUrl
));
210 // block until its downloaded
211 qDebug() << "Waiting for Download finished";
212 infoDownloaded
=false;
214 while(!infoDownloaded
)
215 QCoreApplication::processEvents();
219 void BootloaderInstaller::infoDownloadDone(bool error
)
223 qDebug() << "network error:" << infodownloader
->error();
226 qDebug() << "network status:" << infodownloader
->error();
228 infoDownloaded
= true;
231 void BootloaderInstaller::infoRequestFinished(int id
, bool error
)
237 errorString
= tr("Network error: %1. Please check your network and proxy settings.")
238 .arg(infodownloader
->errorString());
240 if(error
) QMessageBox::about(NULL
, "Network Error", errorString
);
242 qDebug() << "downloadDone:" << id
<< error
;
245 infoDownloaded
= true;
247 qDebug() << "infoRequestFinished:" << id
<< error
;
251 void BootloaderInstaller::createInstallLog()
253 m_dp
->addItem(tr("Creating installation log"),LOGINFO
);
254 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
256 bootloaderInfo
.open();
257 QSettings
info(bootloaderInfo
.fileName(), QSettings::IniFormat
, this);
258 bootloaderInfo
.close();
259 info
.beginGroup(m_device
);
261 installlog
.beginGroup("Bootloader");
262 installlog
.setValue("md5sum",info
.value("md5sum").toString());
263 installlog
.endGroup();
267 void BootloaderInstaller::removeInstallLog()
269 m_dp
->addItem(tr("Editing installation log"),LOGINFO
);
270 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
271 installlog
.beginGroup("Bootloader");
272 installlog
.remove("md5sum");
273 installlog
.endGroup();
278 bool BootloaderInstaller::uptodate()
280 QString installedMd5
;
283 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
284 installlog
.beginGroup("Bootloader");
285 installedMd5
= installlog
.value("md5sum").toString();
286 installlog
.endGroup();
288 if(installedMd5
.isEmpty())
290 bootloaderInfo
.open();
291 QSettings
info(bootloaderInfo
.fileName(), QSettings::IniFormat
, this);
292 bootloaderInfo
.close();
293 info
.beginGroup(m_device
);
294 serverMd5
= info
.value("md5sum").toString();
297 if(installedMd5
!= serverMd5
)
303 /**************************************************
304 *** gigabeat secific code
305 ***************************************************/
307 void BootloaderInstaller::gigabeatPrepare()
309 if(m_install
) // Installation
311 QString url
= m_bootloaderUrlBase
+ "/gigabeat/" + m_bootloadername
;
313 m_dp
->addItem(tr("Downloading file %1.%2")
314 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
316 // temporary file needs to be opened to get the filename
318 m_tempfilename
= downloadFile
.fileName();
319 downloadFile
.close();
320 // get the real file.
321 getter
= new HttpGet(this);
322 getter
->setFile(&downloadFile
);
323 // connect signals from HttpGet
324 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
325 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
326 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
328 getter
->getFile(QUrl(url
));
330 else //UnInstallation
332 QString firmware
= m_mountpoint
+ "/GBSYSTEM/FWIMG/FWIMG01.DAT";
333 QString firmwareOrig
= firmware
.append(".ORIG");
335 QFileInfo
firmwareOrigFI(firmwareOrig
);
337 // check if original firmware exists
338 if(!firmwareOrigFI
.exists())
340 m_dp
->addItem(tr("Could not find the Original Firmware at: %1")
341 .arg(firmwareOrig
),LOGERROR
);
346 QFile
firmwareFile(firmware
);
347 QFile
firmwareOrigFile(firmwareOrig
);
349 //remove modified firmware
350 if(!firmwareFile
.remove())
352 m_dp
->addItem(tr("Could not remove the Firmware at: %1")
353 .arg(firmware
),LOGERROR
);
358 //copy original firmware
359 if(!firmwareOrigFile
.copy(firmware
))
361 m_dp
->addItem(tr("Could not copy the Firmware from: %1 to %2")
362 .arg(firmwareOrig
,firmware
),LOGERROR
);
369 emit
done(false); //success
374 void BootloaderInstaller::gigabeatFinish()
376 // this step is only need for installation, so no code for uninstall here
378 m_dp
->addItem(tr("Finishing bootloader install"),LOGINFO
);
380 QString firmware
= m_mountpoint
+ "/GBSYSTEM/FWIMG/" + m_bootloadername
;
382 QFileInfo
firmwareFI(firmware
);
384 // check if firmware exists
385 if(!firmwareFI
.exists())
387 m_dp
->addItem(tr("Could not find the Firmware at: %1")
388 .arg(firmware
),LOGERROR
);
393 QString firmwareOrig
= firmware
;
394 firmwareOrig
.append(".ORIG");
395 QFileInfo
firmwareOrigFI(firmwareOrig
);
397 // rename and backup the firmware, if there is no original firmware there
398 if(!firmwareOrigFI
.exists())
400 QFile
firmwareFile(firmware
);
402 QDir::home().mkdir("Gigabeat Original Firmware Backup");
403 firmwareFile
.copy(QDir::toNativeSeparators(QDir::homePath()) + QDir::toNativeSeparators("/Gigabeat Original Firmware Backup/") + m_bootloadername
);
406 if(!firmwareFile
.rename(firmwareOrig
))
408 m_dp
->addItem(tr("Could not rename: %1 to %2")
409 .arg(firmware
,firmwareOrig
),LOGERROR
);
414 else // or remove the normal firmware, if the original is there
416 QFile
firmwareFile(firmware
);
417 firmwareFile
.remove();
421 if(!downloadFile
.copy(firmware
))
423 m_dp
->addItem(tr("Could not copy: %1 to %2")
424 .arg(m_tempfilename
,firmware
),LOGERROR
);
429 downloadFile
.remove();
433 m_dp
->addItem(tr("Bootloader install finished successfully."),LOGOK
);
434 m_dp
->addItem(tr("To finish the Bootloader installation, follow the steps below."),LOGINFO
);
435 m_dp
->addItem(tr("1. Eject/Unmount your Device."),LOGINFO
);
436 m_dp
->addItem(tr("2. Unplug USB and any Power adapters."),LOGINFO
);
437 m_dp
->addItem(tr("3. Hold POWER to turn the Device off."),LOGINFO
);
438 m_dp
->addItem(tr("4. Toggle the Battery switch on the Device."),LOGINFO
);
439 m_dp
->addItem(tr("5. Hold POWER to boot the Rockbox bootloader."),LOGINFO
);
444 emit
done(false); // success
448 /**************************************************
449 *** iaudio secific code
450 ***************************************************/
451 void BootloaderInstaller::iaudioPrepare()
454 QString url
= m_bootloaderUrlBase
+ "/iaudio/" + m_bootloadername
;
456 m_dp
->addItem(tr("Downloading file %1.%2")
457 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
459 // temporary file needs to be opened to get the filename
461 m_tempfilename
= downloadFile
.fileName();
462 downloadFile
.close();
463 // get the real file.
464 getter
= new HttpGet(this);
465 getter
->setFile(&downloadFile
);
466 getter
->getFile(QUrl(url
));
467 // connect signals from HttpGet
468 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
469 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
470 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
473 void BootloaderInstaller::iaudioFinish()
475 QString firmware
= m_mountpoint
+ "/FIRMWARE/" + m_bootloadername
;
478 if(!downloadFile
.copy(firmware
))
480 m_dp
->addItem(tr("Could not copy: %1 to %2")
481 .arg(m_tempfilename
,firmware
),LOGERROR
);
486 downloadFile
.remove();
490 m_dp
->addItem(tr("Bootloader install finished successfully."),LOGOK
);
491 m_dp
->addItem(tr("To finish the Bootloader installation, follow the steps below."),LOGINFO
);
492 m_dp
->addItem(tr("1. Eject/Unmount your Device."),LOGINFO
);
493 m_dp
->addItem(tr("2. Turn you Device OFF."),LOGINFO
);
494 m_dp
->addItem(tr("3. Insert Charger."),LOGINFO
);
498 emit
done(false); // success
503 /**************************************************
505 ***************************************************/
506 void BootloaderInstaller::h10Prepare()
508 if(m_install
) // Installation
510 QString url
= m_bootloaderUrlBase
+ "/iriver/" + m_bootloadername
;
512 m_dp
->addItem(tr("Downloading file %1.%2")
513 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
515 // temporary file needs to be opened to get the filename
517 m_tempfilename
= downloadFile
.fileName();
518 downloadFile
.close();
519 // get the real file.
520 getter
= new HttpGet(this);
521 getter
->setFile(&downloadFile
);
522 // connect signals from HttpGet
523 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
524 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
525 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
527 getter
->getFile(QUrl(url
));
529 else // Uninstallation
532 QString firmwarename
= m_bootloadername
.section('/', -1);
534 QString firmware
= m_mountpoint
+ "/SYSTEM/" + firmwarename
;
535 QString firmwareOrig
= m_mountpoint
+ "/SYSTEM/OF.mi4";
537 QFileInfo
firmwareFI(firmware
);
538 if(!firmwareFI
.exists()) //Firmware dosent exists on player
540 firmware
= m_mountpoint
+ "/SYSTEM/H10EMP.mi4"; //attempt other firmwarename
541 firmwareFI
.setFile(firmware
);
542 if(!firmwareFI
.exists()) //Firmware dosent exists on player
544 m_dp
->addItem(tr("Firmware does not exist: %1")
545 .arg(firmware
),LOGERROR
);
551 QFileInfo
firmwareOrigFI(firmwareOrig
);
552 if(!firmwareOrigFI
.exists()) //Original Firmware dosent exists on player
554 m_dp
->addItem(tr("Original Firmware does not exist: %1")
555 .arg(firmwareOrig
),LOGERROR
);
560 QFile
firmwareFile(firmware
);
561 QFile
firmwareOrigFile(firmwareOrig
);
563 //remove modified firmware
564 if(!firmwareFile
.remove())
566 m_dp
->addItem(tr("Could not remove the Firmware at: %1")
567 .arg(firmware
),LOGERROR
);
572 //copy original firmware
573 if(!firmwareOrigFile
.copy(firmware
))
575 m_dp
->addItem(tr("Could not copy the Firmware from: %1 to %2")
576 .arg(firmwareOrig
,firmware
),LOGERROR
);
583 emit
done(false); //success
588 void BootloaderInstaller::h10Finish()
590 QString firmwarename
= m_bootloadername
.section('/', -1);
592 QString firmware
= m_mountpoint
+ "/SYSTEM/" + firmwarename
;
593 QString firmwareOrig
= m_mountpoint
+ "/SYSTEM/OF.mi4";
595 QFileInfo
firmwareFI(firmware
);
597 if(!firmwareFI
.exists()) //Firmware dosent exists on player
599 firmware
= m_mountpoint
+ "/SYSTEM/H10EMP.mi4"; //attempt other firmwarename
600 firmwareFI
.setFile(firmware
);
601 if(!firmwareFI
.exists()) //Firmware dosent exists on player
603 m_dp
->addItem(tr("Firmware does not exist: %1")
604 .arg(firmware
),LOGERROR
);
610 QFileInfo
firmwareOrigFI(firmwareOrig
);
612 if(!firmwareOrigFI
.exists())
614 QFile
firmwareFile(firmware
);
617 QDir::home().mkdir("Iriver H10 Original Firmware Backup");
618 firmwareFile
.copy(QDir::toNativeSeparators(QDir::homePath()) + QDir::toNativeSeparators("/Iriver H10 Original Firmware Backup/") + m_bootloadername
);
621 if(!firmwareFile
.rename(firmwareOrig
)) //rename Firmware to Original
623 m_dp
->addItem(tr("Could not rename: %1 to %2")
624 .arg(firmware
,firmwareOrig
),LOGERROR
);
629 else //there is already a original firmware
631 QFile
firmwareFile(firmware
);
632 firmwareFile
.remove();
635 if(!downloadFile
.copy(firmware
))
637 m_dp
->addItem(tr("Could not copy: %1 to %2")
638 .arg(m_tempfilename
,firmware
),LOGERROR
);
643 downloadFile
.remove();
647 m_dp
->addItem(tr("Bootloader install finished successfully."),LOGOK
);
650 emit
done(false); // success
656 /**************************************************
657 *** mrobe100 secific code
658 ***************************************************/
659 void BootloaderInstaller::mrobe100Prepare()
661 if(m_install
) // Installation
663 QString url
= m_bootloaderUrlBase
+ "/olympus/mrobe100/" + m_bootloadername
;
665 m_dp
->addItem(tr("Downloading file %1.%2")
666 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
668 // temporary file needs to be opened to get the filename
670 m_tempfilename
= downloadFile
.fileName();
671 downloadFile
.close();
672 // get the real file.
673 getter
= new HttpGet(this);
674 getter
->setFile(&downloadFile
);
676 // connect signals from HttpGet
677 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
678 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
679 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
681 getter
->getFile(QUrl(url
));
683 else // Uninstallation
686 QString firmwarename
= m_bootloadername
;
688 QString firmware
= m_mountpoint
+ "/SYSTEM/" + firmwarename
;
689 QString firmwareOrig
= m_mountpoint
+ "/SYSTEM/OF.mi4";
691 QFileInfo
firmwareFI(firmware
);
692 if(!firmwareFI
.exists()) //Firmware dosent exists on player
694 m_dp
->addItem(tr("Firmware does not exist: %1")
695 .arg(firmware
),LOGERROR
);
700 QFileInfo
firmwareOrigFI(firmwareOrig
);
701 if(!firmwareOrigFI
.exists()) //Original Firmware dosent exists on player
703 m_dp
->addItem(tr("Original Firmware does not exist: %1")
704 .arg(firmwareOrig
),LOGERROR
);
709 QFile
firmwareFile(firmware
);
710 QFile
firmwareOrigFile(firmwareOrig
);
712 //remove modified firmware
713 if(!firmwareFile
.remove())
715 m_dp
->addItem(tr("Could not remove the Firmware at: %1")
716 .arg(firmware
),LOGERROR
);
721 //copy original firmware
722 if(!firmwareOrigFile
.copy(firmware
))
724 m_dp
->addItem(tr("Could not copy the Firmware from: %1 to %2")
725 .arg(firmwareOrig
,firmware
),LOGERROR
);
732 emit
done(false); //success
737 void BootloaderInstaller::mrobe100Finish()
739 QString firmwarename
= m_bootloadername
;
741 QString firmware
= m_mountpoint
+ "/SYSTEM/" + firmwarename
;
742 QString firmwareOrig
= m_mountpoint
+ "/SYSTEM/OF.mi4";
744 QFileInfo
firmwareFI(firmware
);
746 if(!firmwareFI
.exists()) //Firmware dosent exists on player
748 m_dp
->addItem(tr("Firmware does not exist: %1")
749 .arg(firmware
),LOGERROR
);
754 QFileInfo
firmwareOrigFI(firmwareOrig
);
756 if(!firmwareOrigFI
.exists())
758 QFile
firmwareFile(firmware
);
761 QDir::home().mkdir("Olympus mrobe100 Original Firmware Backup");
762 firmwareFile
.copy(QDir::toNativeSeparators(QDir::homePath()) + QDir::toNativeSeparators("/Olympus mrobe100 Original Firmware Backup/") + m_bootloadername
);
765 if(!firmwareFile
.rename(firmwareOrig
)) //rename Firmware to Original
767 m_dp
->addItem(tr("Could not rename: %1 to %2")
768 .arg(firmware
,firmwareOrig
),LOGERROR
);
773 else //there is already a original firmware
775 QFile
firmwareFile(firmware
);
776 firmwareFile
.remove();
779 if(!downloadFile
.copy(firmware
))
781 m_dp
->addItem(tr("Could not copy: %1 to %2")
782 .arg(m_tempfilename
,firmware
),LOGERROR
);
787 downloadFile
.remove();
791 m_dp
->addItem(tr("Bootloader install finished successfully."),LOGOK
);
794 emit
done(false); // success
798 /**************************************************
799 *** ipod secific code
800 ***************************************************/
802 // reserves memory for ipodpatcher
803 bool initIpodpatcher()
805 if (ipod_alloc_buffer(§orbuf
,BUFFER_SIZE
) < 0) return true;
809 void BootloaderInstaller::ipodPrepare()
811 m_dp
->addItem(tr("Searching for ipods"),LOGINFO
);
814 int n
= ipod_scan(&ipod
);
817 m_dp
->addItem(tr("No Ipods found"),LOGERROR
);
823 m_dp
->addItem(tr("Too many Ipods found"),LOGERROR
);
827 if(m_install
) // Installation
830 QString url
= m_bootloaderUrlBase
+ "/ipod/bootloader-" + m_bootloadername
+ ".ipod";
832 m_dp
->addItem(tr("Downloading file %1.%2")
833 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
835 // temporary file needs to be opened to get the filename
837 m_tempfilename
= downloadFile
.fileName();
838 downloadFile
.close();
839 // get the real file.
840 getter
= new HttpGet(this);
841 getter
->setFile(&downloadFile
);
843 // connect signals from HttpGet
844 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
845 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
846 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
848 getter
->getFile(QUrl(url
));
850 else // Uninstallation
852 if (ipod_open(&ipod
, 0) < 0)
854 m_dp
->addItem(tr("could not open ipod"),LOGERROR
);
859 if (read_partinfo(&ipod
,0) < 0)
861 m_dp
->addItem(tr("could not read partitiontable"),LOGERROR
);
866 if (ipod
.pinfo
[0].start
==0)
868 m_dp
->addItem(tr("No partition 0 on disk"),LOGERROR
);
871 double sectors_per_MB
= (1024.0*1024.0)/ipod
.sector_size
;
872 m_dp
->addItem(tr("[INFO] Part Start Sector End Sector Size (MB) Type\n"),LOGINFO
);
873 for ( i
= 0; i
< 4; i
++ )
875 if (ipod
.pinfo
[i
].start
!= 0)
877 m_dp
->addItem(tr("[INFO] %1 %2 %3 %4 %5 (%6)").arg(
879 ipod
.pinfo
[i
].start
).arg(
880 ipod
.pinfo
[i
].start
+ipod
.pinfo
[i
].size
-1).arg(
881 ipod
.pinfo
[i
].size
/sectors_per_MB
).arg(
882 get_parttype(ipod
.pinfo
[i
].type
)).arg(
883 ipod
.pinfo
[i
].type
),LOGINFO
);
890 read_directory(&ipod
);
892 if (ipod
.nimages
<= 0)
894 m_dp
->addItem(tr("Failed to read firmware directory"),LOGERROR
);
898 if (getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0)
900 m_dp
->addItem(tr("Unknown version number in firmware (%1)").arg(
901 ipod
.ipod_directory
[0].vers
),LOGERROR
);
908 m_dp
->addItem(tr("Warning this is a MacPod, Rockbox doesnt work on "
909 "this. Convert it to WinPod\n"
910 "See http://www.rockbox.org/wiki/IpodConversionToFAT32"),
916 if (ipod_reopen_rw(&ipod
) < 0)
918 m_dp
->addItem(tr("Could not open Ipod in RW mode"),LOGERROR
);
923 if (ipod
.ipod_directory
[0].entryOffset
==0) {
924 m_dp
->addItem(tr("No bootloader detected."),LOGERROR
);
929 if (delete_bootloader(&ipod
)==0)
931 m_dp
->addItem(tr("Successfully removed Bootloader"),LOGOK
);
939 m_dp
->addItem(tr("--delete-bootloader failed."),LOGERROR
);
947 void BootloaderInstaller::ipodFinish()
952 if (ipod_open(&ipod
, 0) < 0)
954 m_dp
->addItem(tr("could not open ipod"),LOGERROR
);
959 if (read_partinfo(&ipod
,0) < 0)
961 m_dp
->addItem(tr("could not read partitiontable"),LOGERROR
);
966 if (ipod
.pinfo
[0].start
==0)
968 m_dp
->addItem(tr("No partition 0 on disk"),LOGERROR
);
971 double sectors_per_MB
= (1024.0*1024.0)/ipod
.sector_size
;
973 m_dp
->addItem(tr("[INFO] Part Start Sector End Sector Size (MB) Type\n"),LOGINFO
);
975 for ( i
= 0; i
< 4; i
++ )
977 if (ipod
.pinfo
[i
].start
!= 0)
979 m_dp
->addItem(tr("[INFO] %1 %2 %3 %4 %5 (%6)").arg(
981 ipod
.pinfo
[i
].start
).arg(
982 ipod
.pinfo
[i
].start
+ipod
.pinfo
[i
].size
-1).arg(
983 ipod
.pinfo
[i
].size
/sectors_per_MB
).arg(
984 get_parttype(ipod
.pinfo
[i
].type
)).arg(
985 ipod
.pinfo
[i
].type
),LOGWARNING
);
992 read_directory(&ipod
);
994 if (ipod
.nimages
<= 0)
996 m_dp
->addItem(tr("Failed to read firmware directory"),LOGERROR
);
1000 if (getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0)
1002 m_dp
->addItem(tr("Unknown version number in firmware (%1)").arg(
1003 ipod
.ipod_directory
[0].vers
),LOGERROR
);
1010 m_dp
->addItem(tr("Warning this is a MacPod, Rockbox doesnt work on "
1011 "this. Convert it to WinPod\n"
1012 "See http://www.rockbox.org/wiki/IpodConversionToFAT32"),
1018 if (ipod_reopen_rw(&ipod
) < 0)
1020 m_dp
->addItem(tr("Could not open Ipod in RW mode"),LOGERROR
);
1025 if (add_bootloader(&ipod
, m_tempfilename
.toLatin1().data(), FILETYPE_DOT_IPOD
)==0)
1027 m_dp
->addItem(tr("Successfully added Bootloader"),LOGOK
);
1035 m_dp
->addItem(tr("failed to add Bootloader"),LOGERROR
);
1042 /**************************************************
1043 *** sansa secific code
1044 ***************************************************/
1045 // reserves memory for sansapatcher
1046 bool initSansapatcher()
1048 if (sansa_alloc_buffer(§orbuf
,BUFFER_SIZE
) < 0) return true;
1053 void BootloaderInstaller::sansaPrepare()
1055 m_dp
->addItem(tr("Searching for sansas"),LOGINFO
);
1056 struct sansa_t sansa
;
1058 int n
= sansa_scan(&sansa
);
1061 m_dp
->addItem(tr("No Sansa found"),LOGERROR
);
1067 m_dp
->addItem(tr("Too many Sansas found"),LOGERROR
);
1071 if(m_install
) // Installation
1073 QString url
= m_bootloaderUrlBase
+ "/sandisk-sansa/"
1074 + QString(sansa
.targetname
) + "/" + m_bootloadername
;
1076 m_dp
->addItem(tr("Downloading file %1.%2")
1077 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
1079 // temporary file needs to be opened to get the filename
1080 downloadFile
.open();
1081 m_tempfilename
= downloadFile
.fileName();
1082 downloadFile
.close();
1083 // get the real file.
1084 getter
= new HttpGet(this);
1085 getter
->setFile(&downloadFile
);
1087 // connect signals from HttpGet
1088 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
1089 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
1090 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
1092 getter
->getFile(QUrl(url
));
1094 else // Uninstallation
1097 if (sansa_open(&sansa
, 0) < 0)
1099 m_dp
->addItem(tr("could not open Sansa"),LOGERROR
);
1104 if (sansa_read_partinfo(&sansa
,0) < 0)
1106 m_dp
->addItem(tr("could not read partitiontable"),LOGERROR
);
1111 int i
= is_sansa(&sansa
);
1113 m_dp
->addItem(tr("Disk is not a Sansa (%1), aborting.").arg(i
),LOGERROR
);
1118 if (sansa
.hasoldbootloader
)
1120 m_dp
->addItem(tr("********************************************\n"
1121 "OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n"
1122 "You must reinstall the original Sansa firmware before running\n"
1123 "sansapatcher for the first time.\n"
1124 "See http://www.rockbox.org/twiki/bin/view/Main/SansaE200Install\n"
1125 "*********************************************\n"),LOGERROR
);
1131 if (sansa_reopen_rw(&sansa
) < 0)
1133 m_dp
->addItem(tr("Could not open Sansa in RW mode"),LOGERROR
);
1138 if (sansa_delete_bootloader(&sansa
)==0)
1140 m_dp
->addItem(tr("Successfully removed Bootloader"),LOGOK
);
1143 sansa_close(&sansa
);
1148 m_dp
->addItem(tr("--delete-bootloader failed."),LOGERROR
);
1150 sansa_close(&sansa
);
1156 void BootloaderInstaller::sansaFinish()
1158 struct sansa_t sansa
;
1161 if (sansa_open(&sansa
, 0) < 0)
1163 m_dp
->addItem(tr("could not open Sansa"),LOGERROR
);
1168 if (sansa_read_partinfo(&sansa
,0) < 0)
1170 m_dp
->addItem(tr("could not read partitiontable"),LOGERROR
);
1176 int i
= is_sansa(&sansa
);
1179 m_dp
->addItem(tr("Disk is not a Sansa (%1), aborting.").arg(i
),LOGERROR
);
1184 if (sansa
.hasoldbootloader
)
1186 m_dp
->addItem(tr("********************************************\n"
1187 "OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n"
1188 "You must reinstall the original Sansa firmware before running\n"
1189 "sansapatcher for the first time.\n"
1190 "See http://www.rockbox.org/twiki/bin/view/Main/SansaE200Install\n"
1191 "*********************************************\n"),LOGERROR
);
1196 if (sansa_reopen_rw(&sansa
) < 0)
1198 m_dp
->addItem(tr("Could not open Sansa in RW mode"),LOGERROR
);
1203 if (sansa_add_bootloader(&sansa
, m_tempfilename
.toLatin1().data(), FILETYPE_MI4
)==0)
1205 m_dp
->addItem(tr("Successfully added Bootloader"),LOGOK
);
1208 sansa_close(&sansa
);
1213 m_dp
->addItem(tr("failed to add Bootloader"),LOGERROR
);
1214 sansa_close(&sansa
);
1221 /**************************************************
1222 *** iriver /fwpatcher secific code
1223 ***************************************************/
1225 void BootloaderInstaller::iriverPrepare()
1227 char md5sum_str
[32];
1228 if (!FileMD5(m_origfirmware
, md5sum_str
)) {
1229 m_dp
->addItem(tr("Could not MD5Sum original firmware"),LOGERROR
);
1234 /* Check firmware against md5sums in h120sums and h100sums */
1236 table_entry
= intable(md5sum_str
, &h120pairs
[0],
1237 sizeof(h120pairs
)/sizeof(struct sumpairs
));
1238 if (table_entry
>= 0) {
1243 table_entry
= intable(md5sum_str
, &h100pairs
[0],
1244 sizeof(h100pairs
)/sizeof(struct sumpairs
));
1245 if (table_entry
>= 0)
1251 table_entry
= intable(md5sum_str
, &h300pairs
[0],
1252 sizeof(h300pairs
)/sizeof(struct sumpairs
));
1253 if (table_entry
>= 0)
1259 m_dp
->addItem(tr("Could not detect firmware type"),LOGERROR
);
1264 QString url
= m_bootloaderUrlBase
+ "/iriver/" + m_bootloadername
;
1266 m_dp
->addItem(tr("Downloading file %1.%2")
1267 .arg(QFileInfo(url
).baseName(), QFileInfo(url
).completeSuffix()),LOGINFO
);
1269 // temporary file needs to be opened to get the filename
1270 downloadFile
.open();
1271 m_tempfilename
= downloadFile
.fileName();
1272 downloadFile
.close();
1273 // get the real file.
1274 getter
= new HttpGet(this);
1275 getter
->setFile(&downloadFile
);
1277 // connect signals from HttpGet
1278 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
1279 connect(getter
, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
1280 connect(m_dp
, SIGNAL(aborted()), getter
, SLOT(abort()));
1282 getter
->getFile(QUrl(url
));
1285 void BootloaderInstaller::iriverFinish()
1288 char md5sum_str
[32];
1289 struct sumpairs
*sums
= 0;
1292 /* get pointer to the correct bootloader.bin */
1295 sums
= &h100pairs
[0];
1299 sums
= &h120pairs
[0];
1303 sums
= &h300pairs
[0];
1308 // temporary files needs to be opened to get the filename
1309 QTemporaryFile firmwareBin
, newBin
, newHex
;
1313 QString firmwareBinName
= firmwareBin
.fileName();
1314 QString newBinName
= newBin
.fileName();
1315 QString newHexName
= newHex
.fileName();
1316 firmwareBin
.close();
1321 if (iriver_decode(m_origfirmware
, firmwareBinName
, FALSE
, STRIP_NONE
,m_dp
) == -1)
1323 m_dp
->addItem(tr("Error in descramble"),LOGERROR
);
1324 firmwareBin
.remove();
1331 if (!mkboot(firmwareBinName
, newBinName
, m_tempfilename
, origin
,m_dp
))
1333 m_dp
->addItem(tr("Error in patching"),LOGERROR
);
1334 firmwareBin
.remove();
1341 if (iriver_encode(newBinName
, newHexName
, FALSE
,m_dp
) == -1)
1343 m_dp
->addItem(tr("Error in scramble"),LOGERROR
);
1344 firmwareBin
.remove();
1352 if (!FileMD5(newHexName
, md5sum_str
))
1354 m_dp
->addItem(tr("Error in checksumming"),LOGERROR
);
1355 firmwareBin
.remove();
1361 if (strncmp(sums
[table_entry
].patched
, md5sum_str
, 32) == 0) {
1362 /* delete temp files */
1363 firmwareBin
.remove();
1367 // Load patched Firmware to player
1370 dest
= m_mountpoint
+ "/ihp_100.hex";
1371 else if(series
== 120)
1372 dest
= m_mountpoint
+ "/ihp_120.hex";
1373 else if(series
== 300)
1374 dest
= m_mountpoint
+ "/H300.hex";
1377 QFile
destfile(dest
);
1378 if(destfile
.exists()) destfile
.remove();
1379 if(!newHex
.copy(dest
))
1381 m_dp
->addItem(tr("Could not copy: %1 to %2")
1382 .arg(newHexName
,dest
),LOGERROR
);
1387 downloadFile
.remove();
1392 m_dp
->addItem(tr("Bootloader install finished successfully."),LOGOK
);
1393 m_dp
->addItem(tr("To finish the Bootloader installation, follow the steps below."),LOGINFO
);
1394 m_dp
->addItem(tr("1. Eject/Unmount your Device."),LOGINFO
);
1395 m_dp
->addItem(tr("2. Boot into the original Firmware."),LOGINFO
);
1396 m_dp
->addItem(tr("3. Use the Firmware flash option in the Original Firmware."),LOGINFO
);
1397 m_dp
->addItem(tr("4. Reboot."),LOGINFO
);
1400 emit
done(false); // success