From c876d3bbefe0dc00c27ca0c12d29da5874946962 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Wed, 15 Dec 2021 21:04:28 +0100 Subject: rbutil: Merge rbutil with utils folder. rbutil uses several components from the utils folder, and can be considered part of utils too. Having it in a separate folder is an arbitrary split that doesn't help anymore these days, so merge them. This also allows other utils to easily use libtools.make without the need to navigate to a different folder. Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21 --- utils/rbutilqt/base/bootloaderinstallams.cpp | 201 +++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 utils/rbutilqt/base/bootloaderinstallams.cpp (limited to 'utils/rbutilqt/base/bootloaderinstallams.cpp') diff --git a/utils/rbutilqt/base/bootloaderinstallams.cpp b/utils/rbutilqt/base/bootloaderinstallams.cpp new file mode 100644 index 0000000000..be43ed52db --- /dev/null +++ b/utils/rbutilqt/base/bootloaderinstallams.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2008 by Dominik Wenger + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include "bootloaderinstallbase.h" +#include "bootloaderinstallams.h" +#include "Logger.h" + +#include "../mkamsboot/mkamsboot.h" + +BootloaderInstallAms::BootloaderInstallAms(QObject *parent) + : BootloaderInstallBase(parent) +{ +} + +QString BootloaderInstallAms::ofHint() +{ + return tr("Bootloader installation requires you to provide " + "a copy of the original Sandisk firmware (bin file). " + "This firmware file will be patched and then installed to your " + "player along with the rockbox bootloader. " + "You need to download this file yourself due to legal " + "reasons. Please browse the " + "Sansa Forums " + "or refer to the " + "manual and " + "the SansaAMS " + "wiki page on how to obtain this file.
" + "Note: This file is not present on your player and will " + "disappear automatically after installing it.

" + "Press Ok to continue and browse your computer for the firmware " + "file."); +} + +bool BootloaderInstallAms::install(void) +{ + if(m_offile.isEmpty()) + return false; + + LOG_INFO() << "installing bootloader"; + + // download firmware from server + emit logItem(tr("Downloading bootloader file"), LOGINFO); + + connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallAms::installStage2); + downloadBlStart(m_blurl); + + return true; +} + +void BootloaderInstallAms::installStage2(void) +{ + LOG_INFO() << "installStage2"; + + unsigned char* buf; + unsigned char* of_packed; + int of_packedsize; + unsigned char* rb_packed; + int rb_packedsize; + off_t len; + struct md5sums sum; + char md5sum[33]; /* 32 hex digits, plus terminating zero */ + int n; + int model; + int firmware_size; + int bootloader_size; + int patchable; + int totalsize; + char errstr[200]; + + sum.md5 = md5sum; + + m_tempfile.open(); + QString bootfile = m_tempfile.fileName(); + m_tempfile.close(); + + /* Load bootloader file */ + rb_packed = load_rockbox_file(bootfile.toLocal8Bit().data(), &model, + &bootloader_size,&rb_packedsize, + errstr,sizeof(errstr)); + if (rb_packed == nullptr) + { + LOG_ERROR() << "could not load bootloader: " << bootfile; + emit logItem(errstr, LOGERROR); + emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR); + emit done(true); + return; + } + + /* Load original firmware file */ + buf = load_of_file(m_offile.toLocal8Bit().data(), model, &len, &sum, + &firmware_size, &of_packed ,&of_packedsize, + errstr, sizeof(errstr)); + if (buf == nullptr) + { + LOG_ERROR() << "could not load OF: " << m_offile; + emit logItem(errstr, LOGERROR); + emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR); + free(rb_packed); + emit done(true); + return; + } + + /* check total size */ + patchable = check_sizes(sum.model, rb_packedsize, bootloader_size, + of_packedsize, firmware_size, &totalsize, errstr, sizeof(errstr)); + + if (!patchable) + { + LOG_ERROR() << "No room to insert bootloader"; + emit logItem(errstr, LOGERROR); + emit logItem(tr("No room to insert bootloader, try another firmware version"), + LOGERROR); + free(buf); + free(of_packed); + free(rb_packed); + emit done(true); + return; + } + + /* patch the firmware */ + emit logItem(tr("Patching Firmware..."), LOGINFO); + + patch_firmware(sum.model,firmware_revision(sum.model),firmware_size,buf, + len,of_packed,of_packedsize,rb_packed,rb_packedsize); + + /* write out file */ + QFile out(m_blfile); + + if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + LOG_ERROR() << "Could not open" << m_blfile << "for writing"; + emit logItem(tr("Could not open %1 for writing").arg(m_blfile),LOGERROR); + free(buf); + free(of_packed); + free(rb_packed); + emit done(true); + return; + } + + n = out.write((char*)buf, len); + + if (n != len) + { + LOG_ERROR() << "Could not write firmware file"; + emit logItem(tr("Could not write firmware file"),LOGERROR); + free(buf); + free(of_packed); + free(rb_packed); + emit done(true); + return; + } + + out.close(); + + free(buf); + free(of_packed); + free(rb_packed); + + //end of install + LOG_INFO() << "install successfull"; + emit logItem(tr("Success: modified firmware file created"), LOGINFO); + logInstall(LogAdd); + emit done(false); + return; +} + +bool BootloaderInstallAms::uninstall(void) +{ + emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified " + "original firmware"), LOGINFO); + logInstall(LogRemove); + emit done(true); + return false; +} + +BootloaderInstallBase::BootloaderType BootloaderInstallAms::installed(void) +{ + return BootloaderUnknown; +} + +BootloaderInstallBase::Capabilities BootloaderInstallAms::capabilities(void) +{ + return (Install | NeedsOf); +} + -- cgit v1.2.3