Fix wpsbuild to properly generate "-" for theme related settings (to get the default...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstalltcc.cpp
blob350aa04edffa2c15738bfa696d941a36436960d2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2009 by Tomer Shalev
10 * $Id$
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 ****************************************************************************/
22 #include <QtCore>
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 "
42 "file.");
45 bool BootloaderInstallTcc::install(void)
47 if(m_offile.isEmpty())
48 return false;
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);
56 return true;
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;
63 char errstr[200];
64 bool ret = false;
66 m_tempfile.open();
67 QString bootfile = m_tempfile.fileName();
68 m_tempfile.close();
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();
75 /* Write out file */
76 QFile out(outfilename);
78 /* Load original firmware file */
79 of_buf = file_read(m_offile.toLocal8Bit().data(), &of_size);
80 if (of_buf == NULL)
82 emit logItem(errstr, LOGERROR);
83 emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
84 goto exit;
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);
92 goto exit;
95 /* Load bootloader file */
96 boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size);
97 if (boot_buf == NULL)
99 emit logItem(errstr, LOGERROR);
100 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
101 goto exit;
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,
108 &patched_size);
109 if (patched_buf == NULL)
111 emit logItem(errstr, LOGERROR);
112 emit logItem(tr("Could not patch firmware"), LOGERROR);
113 goto exit;
116 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
118 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),
119 LOGERROR);
120 goto exit;
123 n = out.write((char*)patched_buf, patched_size);
124 out.close();
125 if (n != patched_size)
127 emit logItem(tr("Could not write firmware file"), LOGERROR);
128 goto exit;
131 /* End of install */
132 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
133 logInstall(LogAdd);
135 ret = true;
137 exit:
138 if (of_buf)
139 free(of_buf);
141 if (boot_buf)
142 free(boot_buf);
144 if (patched_buf)
145 free(patched_buf);
147 emit done(ret);
150 bool BootloaderInstallTcc::uninstall(void)
152 emit logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO);
153 logInstall(LogRemove);
154 return false;
157 BootloaderInstallBase::BootloaderType BootloaderInstallTcc::installed(void)
159 return BootloaderUnknown;
162 BootloaderInstallBase::Capabilities BootloaderInstallTcc::capabilities(void)
164 return (Install | NeedsOf);