summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstalltcc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstalltcc.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstalltcc.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstalltcc.cpp b/utils/rbutilqt/base/bootloaderinstalltcc.cpp
new file mode 100644
index 0000000000..ffc8555733
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstalltcc.cpp
@@ -0,0 +1,165 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2009 by Tomer Shalev
10 *
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.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 * This file is a modified version of the AMS installer by Dominik Wenger
18 *
19 ****************************************************************************/
20
21#include <QtCore>
22#include "bootloaderinstallbase.h"
23#include "bootloaderinstalltcc.h"
24#include "../mktccboot/mktccboot.h"
25
26BootloaderInstallTcc::BootloaderInstallTcc(QObject *parent)
27 : BootloaderInstallBase(parent)
28{
29}
30
31QString BootloaderInstallTcc::ofHint()
32{
33 return tr("Bootloader installation requires you to provide "
34 "a firmware file of the original firmware (bin file). "
35 "You need to download this file yourself due to legal "
36 "reasons. Please refer to the "
37 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and the "
38 "<a href='http://www.rockbox.org/wiki/CowonD2Info'>CowonD2Info</a> "
39 "wiki page on how to obtain the file.<br/>"
40 "Press Ok to continue and browse your computer for the firmware "
41 "file.");
42}
43
44bool BootloaderInstallTcc::install(void)
45{
46 if(m_offile.isEmpty())
47 return false;
48
49 // Download firmware from server
50 emit logItem(tr("Downloading bootloader file"), LOGINFO);
51
52 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallTcc::installStage2);
53 downloadBlStart(m_blurl);
54
55 return true;
56}
57
58void BootloaderInstallTcc::installStage2(void)
59{
60 unsigned char *of_buf, *boot_buf = nullptr, *patched_buf = nullptr;
61 int n, of_size, boot_size, patched_size;
62 char errstr[200];
63 bool ret = false;
64
65 m_tempfile.open();
66 QString bootfile = m_tempfile.fileName();
67 m_tempfile.close();
68
69 /* Construct path for write out.
70 * Combine path of m_blfile with filename from OF */
71 QString outfilename = QFileInfo(m_blfile).absolutePath() + "/" +
72 QFileInfo(m_offile).fileName();
73
74 /* Write out file */
75 QFile out(outfilename);
76
77 /* Load original firmware file */
78 of_buf = file_read(m_offile.toLocal8Bit().data(), &of_size);
79 if (of_buf == nullptr)
80 {
81 emit logItem(errstr, LOGERROR);
82 emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
83 goto exit;
84 }
85
86 /* A CRC test in order to reject non OF file */
87 if (test_firmware_tcc(of_buf, of_size))
88 {
89 emit logItem(errstr, LOGERROR);
90 emit logItem(tr("Unknown OF file used: %1").arg(m_offile), LOGERROR);
91 goto exit;
92 }
93
94 /* Load bootloader file */
95 boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size);
96 if (boot_buf == nullptr)
97 {
98 emit logItem(errstr, LOGERROR);
99 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
100 goto exit;
101 }
102
103 /* Patch the firmware */
104 emit logItem(tr("Patching Firmware..."), LOGINFO);
105
106 patched_buf = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size,
107 &patched_size);
108 if (patched_buf == nullptr)
109 {
110 emit logItem(errstr, LOGERROR);
111 emit logItem(tr("Could not patch firmware"), LOGERROR);
112 goto exit;
113 }
114
115 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
116 {
117 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),
118 LOGERROR);
119 goto exit;
120 }
121
122 n = out.write((char*)patched_buf, patched_size);
123 out.close();
124 if (n != patched_size)
125 {
126 emit logItem(tr("Could not write firmware file"), LOGERROR);
127 goto exit;
128 }
129
130 /* End of install */
131 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
132 logInstall(LogAdd);
133
134 ret = true;
135
136exit:
137 if (of_buf)
138 free(of_buf);
139
140 if (boot_buf)
141 free(boot_buf);
142
143 if (patched_buf)
144 free(patched_buf);
145
146 emit done(ret);
147}
148
149bool BootloaderInstallTcc::uninstall(void)
150{
151 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified original firmware"), LOGINFO);
152 logInstall(LogRemove);
153 emit done(true);
154 return false;
155}
156
157BootloaderInstallBase::BootloaderType BootloaderInstallTcc::installed(void)
158{
159 return BootloaderUnknown;
160}
161
162BootloaderInstallBase::Capabilities BootloaderInstallTcc::capabilities(void)
163{
164 return (Install | NeedsOf);
165}