1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
20 #include "bootloaderinstallbase.h"
21 #include "bootloaderinstallipod.h"
23 #include "../ipodpatcher/ipodpatcher.h"
27 BootloaderInstallIpod::BootloaderInstallIpod(QObject
*parent
)
28 : BootloaderInstallBase(parent
)
31 // initialize sector buffer. ipod_sectorbuf is defined in ipodpatcher.
32 // The buffer itself is only present once, so make sure to not allocate
33 // it if it was already allocated. The application needs to take care
34 // no concurrent (i.e. multiple objects of this class running) requests
36 if(ipod_sectorbuf
== NULL
)
37 ipod_alloc_buffer(&ipod_sectorbuf
, BUFFER_SIZE
);
41 BootloaderInstallIpod::~BootloaderInstallIpod()
45 ipod_sectorbuf
= NULL
;
50 bool BootloaderInstallIpod::install(void)
52 if(ipod_sectorbuf
== NULL
) {
53 emit
logItem(tr("Error: can't allocate buffer memory!"), LOGERROR
);
57 memset(&ipod
, 0, sizeof(struct ipod_t
));
59 if(!ipodInitialize(&ipod
)) {
64 if(ipod
.nimages
<= 0) {
65 emit
logItem(tr("Failed to read firmware directory"), LOGERROR
);
69 if(getmodel(&ipod
,(ipod
.ipod_directory
[ipod
.ososimage
].vers
>>8)) < 0) {
70 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
71 ipod
.ipod_directory
[0].vers
), 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)
91 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
92 QCoreApplication::processEvents();
94 if(ipod_reopen_rw(&ipod
) < 0) {
95 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
99 QCoreApplication::processEvents();
102 QString blfile
= m_tempfile
.fileName();
104 if(add_bootloader(&ipod
, blfile
.toLatin1().data(), FILETYPE_DOT_IPOD
) == 0) {
105 emit
logItem(tr("Successfull added bootloader"), LOGOK
);
107 #if defined(Q_OS_MACX)
108 m_remountDevice
= ipod
.diskname
;
109 connect(this, SIGNAL(remounted(bool)), this, SLOT(installStage3(bool)));
116 emit
logItem(tr("Failed to add bootloader"), LOGERROR
);
124 void BootloaderInstallIpod::installStage3(bool mounted
)
128 emit
logItem(tr("Bootloader Installation complete."), LOGINFO
);
133 emit
logItem(tr("Writing log aborted"), LOGERROR
);
136 qDebug() << "[BootloaderInstallIpod] version installed:" << m_blversion
.toString(Qt::ISODate
);
140 bool BootloaderInstallIpod::uninstall(void)
143 emit
logItem(tr("Uninstalling bootloader"), LOGINFO
);
144 QCoreApplication::processEvents();
146 if(!ipodInitialize(&ipod
)) {
151 if (ipod
.nimages
<= 0) {
152 emit
logItem(tr("Failed to read firmware directory"),LOGERROR
);
156 if (getmodel(&ipod
,(ipod
.ipod_directory
[0].vers
>>8)) < 0) {
157 emit
logItem(tr("Unknown version number in firmware (%1)").arg(
158 ipod
.ipod_directory
[0].vers
), LOGERROR
);
163 if (ipod_reopen_rw(&ipod
) < 0) {
164 emit
logItem(tr("Could not open Ipod in R/W mode"), LOGERROR
);
169 if (ipod
.ipod_directory
[0].entryOffset
== 0) {
170 emit
logItem(tr("No bootloader detected."), LOGERROR
);
175 if (delete_bootloader(&ipod
)==0) {
176 emit
logItem(tr("Successfully removed bootloader"), LOGOK
);
177 logInstall(LogRemove
);
183 emit
logItem(tr("Removing bootloader failed."), LOGERROR
);
191 BootloaderInstallBase::BootloaderType
BootloaderInstallIpod::installed(void)
194 BootloaderInstallBase::BootloaderType result
= BootloaderRockbox
;
196 if(!ipodInitialize(&ipod
)) {
197 qDebug() << "[BootloaderInstallIpod] installed: BootloaderUnknown";
198 result
= BootloaderUnknown
;
201 read_directory(&ipod
);
202 if(ipod
.ipod_directory
[0].entryOffset
== 0 || ipod
.macpod
) {
203 qDebug() << "[BootloaderInstallIpod] installed: BootloaderOther";
204 result
= BootloaderOther
;
207 qDebug() << "[BootloaderInstallIpod] installed: BootloaderRockbox";
216 BootloaderInstallBase::Capabilities
BootloaderInstallIpod::capabilities(void)
218 return (Install
| Uninstall
| IsRaw
);
222 /** @initialize Ipod by opening its file handle and checking if its an ipod.
223 * Note: the caller has to make sure the file handle gets closed!
225 bool BootloaderInstallIpod::ipodInitialize(struct ipod_t
*ipod
)
227 if(!m_blfile
.isEmpty()) {
228 QString devicename
= Utils::resolveDevicename(m_blfile
);
229 if(devicename
.isEmpty()) {
230 emit
logItem(tr("Error: could not retrieve device name"), LOGERROR
);
233 #if defined(Q_OS_WIN32)
234 sprintf(ipod
->diskname
, "\\\\.\\PhysicalDrive%i", devicename
.toInt());
235 #elif defined(Q_OS_MACX)
236 sprintf(ipod
->diskname
, "%s",
237 qPrintable(devicename
.remove(QRegExp("s[0-9]+$"))));
239 sprintf(ipod
->diskname
, "%s",
240 qPrintable(devicename
.remove(QRegExp("[0-9]+$"))));
242 qDebug() << "[BootloaderInstallIpod] ipodpatcher: overriding scan, using"
246 emit
logItem(tr("Error: no mountpoint specified!"), LOGERROR
);
247 qDebug() << "[BootloaderInstallIpod] no mountpoint specified!";
249 int result
= ipod_open(ipod
, 1);
251 emit
logItem(tr("Could not open Ipod: permission denied"), LOGERROR
);
254 else if(result
< 0) {
255 emit
logItem(tr("Could not open Ipod"), LOGERROR
);
259 if(read_partinfo(ipod
, 1) < 0) {
260 emit
logItem(tr("Error reading partition table - possibly not an Ipod"), LOGERROR
);
265 if(ipod
->pinfo
[0].start
== 0) {
266 emit
logItem(tr("No firmware partition on disk"), LOGERROR
);
270 read_directory(ipod
);