summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base
diff options
context:
space:
mode:
authorTomer Shalev <shalev.tomer@gmail.com>2009-10-29 21:31:50 +0000
committerTomer Shalev <shalev.tomer@gmail.com>2009-10-29 21:31:50 +0000
commitad785518111eabe4518dca485421e533186f63a5 (patch)
tree1933da66814ac5bb19b7b7f87bc2ab56ea27ed1d /rbutil/rbutilqt/base
parent0f90f0b423674494a648a0bb8fd2cfe31f29b68b (diff)
downloadrockbox-ad785518111eabe4518dca485421e533186f63a5.tar.gz
rockbox-ad785518111eabe4518dca485421e533186f63a5.zip
FS#10728 - Cowon D2: Add support for D2 in rbutil
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23410 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstalltcc.cpp154
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstalltcc.h45
2 files changed, 199 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp b/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp
new file mode 100644
index 0000000000..1d0a9e606e
--- /dev/null
+++ b/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp
@@ -0,0 +1,154 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2009 by Tomer Shalev
10 * $Id$
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 * This file is a modified version of the AMS installer by Dominik Wenger
19 *
20 ****************************************************************************/
21
22#include <QtCore>
23#include "bootloaderinstallbase.h"
24#include "bootloaderinstalltcc.h"
25#include "../mktccboot/mktccboot.h"
26
27BootloaderInstallTcc::BootloaderInstallTcc(QObject *parent)
28 : BootloaderInstallBase(parent)
29{
30}
31
32QString BootloaderInstallTcc::ofHint()
33{
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."
38 "Press Ok to continue and browse your computer for the firmware "
39 "file.");
40}
41
42bool BootloaderInstallTcc::install(void)
43{
44 if(m_offile.isEmpty())
45 return false;
46
47 // Download firmware from server
48 emit logItem(tr("Downloading bootloader file"), LOGINFO);
49
50 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
51 downloadBlStart(m_blurl);
52
53 return true;
54}
55
56void BootloaderInstallTcc::installStage2(void)
57{
58 unsigned char *of_buf, *boot_buf = NULL, *patched_buf = NULL;
59 int n, of_size, boot_size, patched_size;
60 char errstr[200];
61 bool ret = false;
62
63 m_tempfile.open();
64 QString bootfile = m_tempfile.fileName();
65 m_tempfile.close();
66
67 /* Construct path for write out.
68 * Combine path of m_blfile with filename from OF */
69 QString outfilename = QFileInfo(m_blfile).absolutePath() + "/" +
70 QFileInfo(m_offile).fileName();
71
72 /* Write out file */
73 QFile out(outfilename);
74
75 /* Load original firmware file */
76 of_buf = file_read(m_offile.toLocal8Bit().data(), &of_size);
77 if (of_buf == NULL)
78 {
79 emit logItem(errstr, LOGERROR);
80 emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
81 goto exit;
82 }
83
84 /* Load bootloader file */
85 boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size);
86 if (boot_buf == NULL)
87 {
88 emit logItem(errstr, LOGERROR);
89 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
90 goto exit;
91 }
92
93 /* Patch the firmware */
94 emit logItem(tr("Patching Firmware..."), LOGINFO);
95
96 patched_buf = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size,
97 &patched_size);
98 if (patched_buf == NULL)
99 {
100 emit logItem(errstr, LOGERROR);
101 emit logItem(tr("Could patch firmware"), LOGERROR);
102 goto exit;
103 }
104
105 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
106 {
107 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),
108 LOGERROR);
109 goto exit;
110 }
111
112 n = out.write((char*)patched_buf, patched_size);
113 out.close();
114 if (n != patched_size)
115 {
116 emit logItem(tr("Could not write firmware file"), LOGERROR);
117 goto exit;
118 }
119
120 /* End of install */
121 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
122 logInstall(LogAdd);
123
124 ret = true;
125
126exit:
127 if (of_buf)
128 free(of_buf);
129
130 if (boot_buf)
131 free(boot_buf);
132
133 if (patched_buf)
134 free(patched_buf);
135
136 emit done(ret);
137}
138
139bool BootloaderInstallTcc::uninstall(void)
140{
141 emit logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO);
142 logInstall(LogRemove);
143 return false;
144}
145
146BootloaderInstallBase::BootloaderType BootloaderInstallTcc::installed(void)
147{
148 return BootloaderUnknown;
149}
150
151BootloaderInstallBase::Capabilities BootloaderInstallTcc::capabilities(void)
152{
153 return (Install | NeedsOf);
154}
diff --git a/rbutil/rbutilqt/base/bootloaderinstalltcc.h b/rbutil/rbutilqt/base/bootloaderinstalltcc.h
new file mode 100644
index 0000000000..b91970034e
--- /dev/null
+++ b/rbutil/rbutilqt/base/bootloaderinstalltcc.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2009 by Tomer Shalev
10 * $Id$
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 * This file is a modified version of the AMS installer by Dominik Wenger
19 *
20 ****************************************************************************/
21#ifndef BOOTLOADERINSTALLTCC_H
22#define BOOTLOADERINSTALLTCC_H
23
24#include <QtCore>
25#include "bootloaderinstallbase.h"
26
27//! bootloader installation derivate based on mktccboot
28class BootloaderInstallTcc : public BootloaderInstallBase
29{
30 Q_OBJECT
31 public:
32 BootloaderInstallTcc(QObject *parent);
33 bool install(void);
34 bool uninstall(void);
35 BootloaderInstallBase::BootloaderType installed(void);
36 Capabilities capabilities(void);
37 QString ofHint();
38
39 private:
40
41 private slots:
42 void installStage2(void);
43};
44
45#endif