summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstallmpio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallmpio.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstallmpio.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallmpio.cpp b/utils/rbutilqt/base/bootloaderinstallmpio.cpp
new file mode 100644
index 0000000000..863418e591
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstallmpio.cpp
@@ -0,0 +1,143 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2008 by Dominik Wenger
10 * $Id: bootloaderinstallams.cpp 24778 2010-02-19 23:45:29Z funman $
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 ****************************************************************************/
19
20#include <QtCore>
21#include "bootloaderinstallbase.h"
22#include "bootloaderinstallmpio.h"
23#include "Logger.h"
24
25#include "../mkmpioboot/mkmpioboot.h"
26
27BootloaderInstallMpio::BootloaderInstallMpio(QObject *parent)
28 : BootloaderInstallBase(parent)
29{
30}
31
32QString BootloaderInstallMpio::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. Please refer to the "
38 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and "
39 "the <a href='http://www.rockbox.org/wiki/MPIOHD200Port'>MPIOHD200Port</a> "
40 "wiki page on how to obtain this file.<br/>"
41 "Press Ok to continue and browse your computer for the firmware "
42 "file.");
43}
44
45bool BootloaderInstallMpio::install(void)
46{
47 if(m_offile.isEmpty())
48 return false;
49
50 LOG_INFO() << "installing bootloader";
51
52 // download firmware from server
53 emit logItem(tr("Downloading bootloader file"), LOGINFO);
54
55 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallMpio::installStage2);
56 downloadBlStart(m_blurl);
57
58 return true;
59}
60
61void BootloaderInstallMpio::installStage2(void)
62{
63 LOG_INFO() << "installStage2";
64
65 int origin = 0xe0000; /* MPIO HD200 bootloader address */
66
67 m_tempfile.open();
68 QString bootfile = m_tempfile.fileName();
69 m_tempfile.close();
70
71 int ret = mkmpioboot(m_offile.toLocal8Bit().data(),
72 bootfile.toLocal8Bit().data(), m_blfile.toLocal8Bit().data(), origin);
73
74 if(ret != 0)
75 {
76 QString error;
77 switch(ret)
78 {
79 case -1:
80 error = tr("Could not open the original firmware.");
81 break;
82 case -2:
83 error = tr("Could not read the original firmware.");
84 break;
85 case -3:
86 error = tr("Loaded firmware file does not look like MPIO original firmware file.");
87 break;
88 case -4:
89 error = tr("Could not open downloaded bootloader.");
90 break;
91 case -5:
92 error = tr("Place for bootloader in OF file not empty.");
93 break;
94 case -6:
95 error = tr("Could not read the downloaded bootloader.");
96 break;
97 case -7:
98 error = tr("Bootloader checksum error.");
99 break;
100 case -8:
101 error = tr("Could not open output file.");
102 break;
103 case -9:
104 error = tr("Could not write output file.");
105 break;
106 default:
107 error = tr("Unknown error number: %1").arg(ret);
108 break;
109 }
110
111 LOG_ERROR() << "Patching original firmware failed:" << error;
112 emit logItem(tr("Patching original firmware failed: %1").arg(error), LOGERROR);
113 emit done(true);
114 return;
115 }
116
117 //end of install
118 LOG_INFO() << "install successful";
119 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
120 logInstall(LogAdd);
121 emit done(false);
122 return;
123}
124
125bool BootloaderInstallMpio::uninstall(void)
126{
127 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
128 "original firmware"), LOGINFO);
129 logInstall(LogRemove);
130 emit done(true);
131 return false;
132}
133
134BootloaderInstallBase::BootloaderType BootloaderInstallMpio::installed(void)
135{
136 return BootloaderUnknown;
137}
138
139BootloaderInstallBase::Capabilities BootloaderInstallMpio::capabilities(void)
140{
141 return (Install | NeedsOf);
142}
143