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 ****************************************************************************/
21 #include "bootloaderinstallbase.h"
22 #include "bootloaderinstallipod.h"
24 #include "../ipodpatcher/ipodpatcher.h"
25 #include "autodetection.h"
28 BootloaderInstallIpod::BootloaderInstallIpod(QObject
*parent
)
29 : BootloaderInstallBase(parent
)
32 // initialize sector buffer. ipod_sectorbuf is defined in ipodpatcher.
33 // The buffer itself is only present once, so make sure to not allocate
34 // it if it was already allocated. The application needs to take care
35 // no concurrent (i.e. multiple objects of this class running) requests
37 if(ipod_sectorbuf
== NULL
)
38 ipod_alloc_buffer(&ipod_sectorbuf
, BUFFER_SIZE
);
42 BootloaderInstallIpod::~BootloaderInstallIpod()
46 ipod_sectorbuf
= NULL
;
51 bool BootloaderInstallIpod::install(void)
53 if(ipod_sectorbuf
== NULL
) {
54 emit
logItem(tr("Error: can't allocate buffer memory!"), LOGERROR
);
58 memset(&ipod
, 0, sizeof(struct ipod_t
));
60 if(!ipodInitialize(&ipod
)) {
65 if(ipod
.nimages
<= 0) {
66 emit
logItem(tr("Failed to read firmware directory"), LOGERROR
);
70 if(getmodel(&ipod
,(ipod
.ipod_directory
[ipod
.ososimage
].vers
>>8)) < 0) {
71 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
72 ipod
.ipod_directory
[0].vers
), LOGERROR
);
77 emit
logItem(tr("Warning: This is a MacPod, Rockbox only runs on WinPods. \n"
78 "See http://www.rockbox.org/wiki/IpodConversionToFAT32"), LOGERROR
);
82 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
84 downloadBlStart(m_blurl
);
85 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
90 void BootloaderInstallIpod::installStage2(void)
92 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
93 QCoreApplication::processEvents();
95 if(ipod_reopen_rw(&ipod
) < 0) {
96 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
100 QCoreApplication::processEvents();
103 QString blfile
= m_tempfile
.fileName();
105 if(add_bootloader(&ipod
, blfile
.toLatin1().data(), FILETYPE_DOT_IPOD
) == 0) {
106 emit
logItem(tr("Successfull added bootloader"), LOGOK
);
108 #if defined(Q_OS_MACX)
109 m_remountDevice
= ipod
.diskname
;
110 connect(this, SIGNAL(remounted(bool)), this, SLOT(installStage3(bool)));
117 emit
logItem(tr("Failed to add bootloader"), LOGERROR
);
125 void BootloaderInstallIpod::installStage3(bool mounted
)
129 emit
logItem(tr("Bootloader Installation complete."), LOGINFO
);
134 emit
logItem(tr("Writing log aborted"), LOGERROR
);
137 qDebug() << "[BootloaderInstallIpod] version installed:" << m_blversion
.toString(Qt::ISODate
);
141 bool BootloaderInstallIpod::uninstall(void)
144 emit
logItem(tr("Uninstalling bootloader"), LOGINFO
);
145 QCoreApplication::processEvents();
147 if(!ipodInitialize(&ipod
)) {
152 if (ipod
.nimages
<= 0) {
153 emit
logItem(tr("Failed to read firmware directory"),LOGERROR
);
157 if (getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0) {
158 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
159 ipod
.ipod_directory
[0].vers
), LOGERROR
);
164 if (ipod_reopen_rw(&ipod
) < 0) {
165 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
170 if (ipod
.ipod_directory
[0].entryOffset
== 0) {
171 emit
logItem(tr("No bootloader detected."), LOGERROR
);
176 if (delete_bootloader(&ipod
)==0) {
177 emit
logItem(tr("Successfully removed bootloader"), LOGOK
);
178 logInstall(LogRemove
);
184 emit
logItem(tr("Removing bootloader failed."), LOGERROR
);
192 BootloaderInstallBase::BootloaderType
BootloaderInstallIpod::installed(void)
195 BootloaderInstallBase::BootloaderType result
= BootloaderRockbox
;
197 if(!ipodInitialize(&ipod
)) {
198 qDebug() << "[BootloaderInstallIpod] installed: BootloaderUnknown";
199 result
= BootloaderUnknown
;
202 read_directory(&ipod
);
203 if(ipod
.ipod_directory
[0].entryOffset
== 0 || ipod
.macpod
) {
204 qDebug() << "[BootloaderInstallIpod] installed: BootloaderOther";
205 result
= BootloaderOther
;
208 qDebug() << "[BootloaderInstallIpod] installed: BootloaderRockbox";
217 BootloaderInstallBase::Capabilities
BootloaderInstallIpod::capabilities(void)
219 return (Install
| Uninstall
| IsRaw
);
223 /** @initialize Ipod by opening its file handle and checking if its an ipod.
224 * Note: the caller has to make sure the file handle gets closed!
226 bool BootloaderInstallIpod::ipodInitialize(struct ipod_t
*ipod
)
228 if(!m_blfile
.isEmpty()) {
229 QString devicename
= Autodetection::resolveDevicename(m_blfile
);
230 if(devicename
.isEmpty()) {
231 emit
logItem(tr("Error: could not retrieve device name"), LOGERROR
);
234 #if defined(Q_OS_WIN32)
235 sprintf(ipod
->diskname
, "\\\\.\\PhysicalDrive%i", devicename
.toInt());
236 #elif defined(Q_OS_MACX)
237 sprintf(ipod
->diskname
, "%s",
238 qPrintable(devicename
.remove(QRegExp("s[0-9]+$"))));
240 sprintf(ipod
->diskname
, "%s",
241 qPrintable(devicename
.remove(QRegExp("[0-9]+$"))));
243 qDebug() << "[BootloaderInstallIpod] ipodpatcher: overriding scan, using"
247 emit
logItem(tr("Error: no mountpoint specified!"), LOGERROR
);
248 qDebug() << "[BootloaderInstallIpod] no mountpoint specified!";
250 int result
= ipod_open(ipod
, 1);
252 emit
logItem(tr("Could not open Ipod: permission denied"), LOGERROR
);
255 else if(result
< 0) {
256 emit
logItem(tr("Could not open Ipod"), LOGERROR
);
260 if(read_partinfo(ipod
, 1) < 0) {
261 emit
logItem(tr("Error reading partition table - possibly not an Ipod"), LOGERROR
);
266 if(ipod
->pinfo
[0].start
== 0) {
267 emit
logItem(tr("No firmware partition on disk"), LOGERROR
);
271 read_directory(ipod
);