1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2009 by Tomer Shalev
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 * This file is a modified version of the AMS installer by Dominik Wenger
20 ****************************************************************************/
23 #include "bootloaderinstallbase.h"
24 #include "bootloaderinstalltcc.h"
25 #include "../mktccboot/mktccboot.h"
27 BootloaderInstallTcc::BootloaderInstallTcc(QObject
*parent
)
28 : BootloaderInstallBase(parent
)
32 QString
BootloaderInstallTcc::ofHint()
34 return tr("Bootloader installation requires you to provide "
35 "a firmware file of the original firmware (bin file). "
36 "You need to download this file yourself due to legal "
37 "reasons. Please refer to the "
38 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and the "
39 "<a href='http://www.rockbox.org/wiki/CowonD2Info'>CowonD2Info</a> "
40 "wiki page on how to obtain the file.<br/>"
41 "Press Ok to continue and browse your computer for the firmware "
45 bool BootloaderInstallTcc::install(void)
47 if(m_offile
.isEmpty())
50 // Download firmware from server
51 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
53 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
54 downloadBlStart(m_blurl
);
59 void BootloaderInstallTcc::installStage2(void)
61 unsigned char *of_buf
, *boot_buf
= NULL
, *patched_buf
= NULL
;
62 int n
, of_size
, boot_size
, patched_size
;
67 QString bootfile
= m_tempfile
.fileName();
70 /* Construct path for write out.
71 * Combine path of m_blfile with filename from OF */
72 QString outfilename
= QFileInfo(m_blfile
).absolutePath() + "/" +
73 QFileInfo(m_offile
).fileName();
76 QFile
out(outfilename
);
78 /* Load original firmware file */
79 of_buf
= file_read(m_offile
.toLocal8Bit().data(), &of_size
);
82 emit
logItem(errstr
, LOGERROR
);
83 emit
logItem(tr("Could not load %1").arg(m_offile
), LOGERROR
);
87 /* A CRC test in order to reject non OF file */
88 if (test_firmware_tcc(of_buf
, of_size
))
90 emit
logItem(errstr
, LOGERROR
);
91 emit
logItem(tr("Unknown OF file used: %1").arg(m_offile
), LOGERROR
);
95 /* Load bootloader file */
96 boot_buf
= file_read(bootfile
.toLocal8Bit().data(), &boot_size
);
99 emit
logItem(errstr
, LOGERROR
);
100 emit
logItem(tr("Could not load %1").arg(bootfile
), LOGERROR
);
104 /* Patch the firmware */
105 emit
logItem(tr("Patching Firmware..."), LOGINFO
);
107 patched_buf
= patch_firmware_tcc(of_buf
, of_size
, boot_buf
, boot_size
,
109 if (patched_buf
== NULL
)
111 emit
logItem(errstr
, LOGERROR
);
112 emit
logItem(tr("Could not patch firmware"), LOGERROR
);
116 if(!out
.open(QIODevice::WriteOnly
| QIODevice::Truncate
))
118 emit
logItem(tr("Could not open %1 for writing").arg(m_blfile
),
123 n
= out
.write((char*)patched_buf
, patched_size
);
125 if (n
!= patched_size
)
127 emit
logItem(tr("Could not write firmware file"), LOGERROR
);
132 emit
logItem(tr("Success: modified firmware file created"), LOGINFO
);
150 bool BootloaderInstallTcc::uninstall(void)
152 emit
logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO
);
153 logInstall(LogRemove
);
157 BootloaderInstallBase::BootloaderType
BootloaderInstallTcc::installed(void)
159 return BootloaderUnknown
;
162 BootloaderInstallBase::Capabilities
BootloaderInstallTcc::capabilities(void)
164 return (Install
| NeedsOf
);