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
);
61 int n
= ipod_scan(&ipod
);
63 emit
logItem(tr("No Ipod detected\n"
64 "Permission for disc access denied!"),
70 emit
logItem(tr("No Ipod detected!"), LOGERROR
);
76 emit
logItem(tr("Warning: This is a MacPod, Rockbox only runs on WinPods.\n"
77 "See http://www.rockbox.org/wiki/IpodConversionToFAT32"), LOGERROR
);
81 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
83 downloadBlStart(m_blurl
);
84 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
89 void BootloaderInstallIpod::installStage2(void)
93 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
94 QCoreApplication::processEvents();
95 if(!ipodInitialize(&ipod
)) {
100 read_directory(&ipod
);
102 if(ipod
.nimages
<= 0) {
103 emit
logItem(tr("Failed to read firmware directory"), LOGERROR
);
107 if(getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0) {
108 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
109 ipod
.ipod_directory
[0].vers
), LOGERROR
);
115 emit
logItem(tr("Warning: This is a MacPod, Rockbox only runs on WinPods.\n"
116 "See http://www.rockbox.org/wiki/IpodConversionToFAT32"), LOGERROR
);
121 if(ipod_reopen_rw(&ipod
) < 0) {
122 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
128 QString blfile
= m_tempfile
.fileName();
130 if(add_bootloader(&ipod
, blfile
.toLatin1().data(), FILETYPE_DOT_IPOD
) == 0) {
131 emit
logItem(tr("Successfull added bootloader"), LOGOK
);
138 emit
logItem(tr("Failed to add bootloader"), LOGERROR
);
143 qDebug() << "[BootloaderInstallIpod] version installed:" << m_blversion
.toString(Qt::ISODate
);
147 bool BootloaderInstallIpod::uninstall(void)
150 emit
logItem(tr("Uninstalling bootloader"), LOGINFO
);
151 QCoreApplication::processEvents();
153 if(!ipodInitialize(&ipod
)) {
158 read_directory(&ipod
);
160 if (ipod
.nimages
<= 0) {
161 emit
logItem(tr("Failed to read firmware directory"),LOGERROR
);
165 if (getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0) {
166 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
167 ipod
.ipod_directory
[0].vers
), LOGERROR
);
172 if (ipod_reopen_rw(&ipod
) < 0) {
173 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
178 if (ipod
.ipod_directory
[0].entryOffset
== 0) {
179 emit
logItem(tr("No bootloader detected."), LOGERROR
);
184 if (delete_bootloader(&ipod
)==0) {
185 emit
logItem(tr("Successfully removed bootloader"), LOGOK
);
186 logInstall(LogRemove
);
192 emit
logItem(tr("Removing bootloader failed."), LOGERROR
);
200 BootloaderInstallBase::BootloaderType
BootloaderInstallIpod::installed(void)
203 BootloaderInstallBase::BootloaderType result
= BootloaderRockbox
;
205 if(!ipodInitialize(&ipod
)) {
206 qDebug() << "[BootloaderInstallIpod] installed: BootloaderUnknown";
207 result
= BootloaderUnknown
;
210 read_directory(&ipod
);
211 if(ipod
.ipod_directory
[0].entryOffset
== 0) {
212 qDebug() << "[BootloaderInstallIpod] installed: BootloaderOther";
213 result
= BootloaderOther
;
216 qDebug() << "[BootloaderInstallIpod] installed: BootloaderRockbox";
225 BootloaderInstallBase::Capabilities
BootloaderInstallIpod::capabilities(void)
227 return (Install
| Uninstall
| IsRaw
);
231 bool BootloaderInstallIpod::ipodInitialize(struct ipod_t
*ipod
)
233 if(!m_blfile
.isEmpty()) {
234 #if defined(Q_OS_WIN32)
235 sprintf(ipod
->diskname
, "\\\\.\\PhysicalDrive%i",
236 Autodetection::resolveDevicename(m_blfile
).toInt());
237 #elif defined(Q_OS_MACX)
238 sprintf(ipod
->diskname
,
239 qPrintable(Autodetection::resolveDevicename(m_blfile
)
240 .remove(QRegExp("s[0-9]+$"))));
242 sprintf(ipod
->diskname
,
243 qPrintable(Autodetection::resolveDevicename(m_blfile
)
244 .remove(QRegExp("[0-9]+$"))));
246 qDebug() << "[BootloaderInstallIpod] ipodpatcher: overriding scan, using"
252 if(ipod_open(ipod
, 0) < 0) {
253 emit
logItem(tr("Could not open Ipod"), LOGERROR
);
257 if(read_partinfo(ipod
, 0) < 0) {
258 emit
logItem(tr("Error reading partition table - possibly not an Ipod"), LOGERROR
);
263 if(ipod
->pinfo
[0].start
== 0) {
264 emit
logItem(tr("No firmware partition on disk"), LOGERROR
);