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 "
38 "Press Ok to continue and browse your computer for the firmware "
42 bool BootloaderInstallTcc::install(void)
44 if(m_offile
.isEmpty())
47 // Download firmware from server
48 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
50 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
51 downloadBlStart(m_blurl
);
56 void BootloaderInstallTcc::installStage2(void)
58 unsigned char *of_buf
, *boot_buf
= NULL
, *patched_buf
= NULL
;
59 int n
, of_size
, boot_size
, patched_size
;
64 QString bootfile
= m_tempfile
.fileName();
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();
73 QFile
out(outfilename
);
75 /* Load original firmware file */
76 of_buf
= file_read(m_offile
.toLocal8Bit().data(), &of_size
);
79 emit
logItem(errstr
, LOGERROR
);
80 emit
logItem(tr("Could not load %1").arg(m_offile
), LOGERROR
);
84 /* A CRC test in order to reject non OF file */
85 if (test_firmware_tcc(of_buf
, of_size
))
87 emit
logItem(errstr
, LOGERROR
);
88 emit
logItem(tr("Unknown OF file used: %1").arg(m_offile
), LOGERROR
);
92 /* Load bootloader file */
93 boot_buf
= file_read(bootfile
.toLocal8Bit().data(), &boot_size
);
96 emit
logItem(errstr
, LOGERROR
);
97 emit
logItem(tr("Could not load %1").arg(bootfile
), LOGERROR
);
101 /* Patch the firmware */
102 emit
logItem(tr("Patching Firmware..."), LOGINFO
);
104 patched_buf
= patch_firmware_tcc(of_buf
, of_size
, boot_buf
, boot_size
,
106 if (patched_buf
== NULL
)
108 emit
logItem(errstr
, LOGERROR
);
109 emit
logItem(tr("Could patch firmware"), LOGERROR
);
113 if(!out
.open(QIODevice::WriteOnly
| QIODevice::Truncate
))
115 emit
logItem(tr("Could not open %1 for writing").arg(m_blfile
),
120 n
= out
.write((char*)patched_buf
, patched_size
);
122 if (n
!= patched_size
)
124 emit
logItem(tr("Could not write firmware file"), LOGERROR
);
129 emit
logItem(tr("Success: modified firmware file created"), LOGINFO
);
147 bool BootloaderInstallTcc::uninstall(void)
149 emit
logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO
);
150 logInstall(LogRemove
);
154 BootloaderInstallBase::BootloaderType
BootloaderInstallTcc::installed(void)
156 return BootloaderUnknown
;
159 BootloaderInstallBase::Capabilities
BootloaderInstallTcc::capabilities(void)
161 return (Install
| NeedsOf
);