Index: rbutil/rbutilqt/rbutil.ini =================================================================== --- rbutil/rbutilqt/rbutil.ini (revision 22067) +++ rbutil/rbutilqt/rbutil.ini (working copy) @@ -43,6 +43,7 @@ platform32=iaudiox5v platform33=iaudiom3 platform40=gigabeatf +platform44=ondavx747 platform50=sansae200 platform51=sansac200 platform60=mrobe100 @@ -452,6 +453,20 @@ targetid=33 encoder=rbspeex +[ondavx747] +name=VX747 +buildserver_modelname=ondavx747 +bootloadermethod=chinachip +bootloadername=/onda/vx747/ccpmp.bin +bootloaderfile=/SG301.HXF +resolution=240x400x16 +manualname= +brand=Onda +usbid=0x07c4a4a5 +configure_modelname=ondavx747 +targetid=44 +encoder=rbspeex + [languages] lang1=afrikaans lang2=bulgarian Index: rbutil/rbutilqt/rbutilqt.cpp =================================================================== --- rbutil/rbutilqt/rbutilqt.cpp (revision 22067) +++ rbutil/rbutilqt/rbutilqt.cpp (working copy) @@ -44,6 +44,7 @@ #include "bootloaderinstallipod.h" #include "bootloaderinstallsansa.h" #include "bootloaderinstallfile.h" +#include "bootloaderinstallchinachip.h" #if defined(Q_OS_LINUX) #include @@ -652,6 +653,9 @@ else if(type == "file") { bl = new BootloaderInstallFile(this); } + else if(type == "chinachip") { + bl = new BootloaderInstallChinaChip(this); + } else { logger->addItem(tr("No install method known."), LOGERROR); logger->setFinished(); Index: rbutil/rbutilqt/rbutilqt.pro =================================================================== --- rbutil/rbutilqt/rbutilqt.pro (revision 22067) +++ rbutil/rbutilqt/rbutilqt.pro (working copy) @@ -1,12 +1,13 @@ -unix:!mac { +unix:!mac { CCACHE = $$system(which ccache) - !isEmpty(CCACHE) { + !isEmpty(CCACHE) { message("using ccache") - QMAKE_CXX = ccache g++ - QMAKE_CC = ccache gcc + QMAKE_CXX = ccache \ + g++ + QMAKE_CC = ccache \ + gcc } } - OBJECTS_DIR = build/o UI_DIR = build/ui MOC_DIR = build/moc @@ -14,236 +15,252 @@ # check version of Qt installation VER = $$find(QT_VERSION, ^4\.[3-9]+.*) -isEmpty(VER) { +isEmpty(VER) { !isEmpty(QT_VERSION) error("Qt found:" $$[QT_VERSION]) error("Qt >= 4.3 required!") } message("Qt version used:" $$VER) # add a custom rule for pre-building librbspeex -!mac { -rbspeex.commands = @$(MAKE) -C ../../tools/rbspeex librbspeex.a -} -mac { -rbspeex.commands = @$(MAKE) -C ../../tools/rbspeex librbspeex-universal -} +!mac:rbspeex.commands = @$(MAKE) \ + -C \ + ../../tools/rbspeex \ + librbspeex.a +mac:rbspeex.commands = @$(MAKE) \ + -C \ + ../../tools/rbspeex \ + librbspeex-universal QMAKE_EXTRA_TARGETS += rbspeex PRE_TARGETDEPS += rbspeex # rule for creating ctags file -tags.commands = ctags -R --c++-kinds=+p --fields=+iaS --extra=+q $(SOURCES) +tags.commands = ctags \ + -R \ + --c++-kinds=+p \ + --fields=+iaS \ + --extra=+q \ + $(SOURCES) tags.depends = $(SOURCES) QMAKE_EXTRA_TARGETS += tags # add a custom rule for making the translations -lrelease.commands = $$[QT_INSTALL_BINS]/lrelease -silent rbutilqt.pro +lrelease.commands = $$[QT_INSTALL_BINS]/lrelease \ + -silent \ + rbutilqt.pro QMAKE_EXTRA_TARGETS += lrelease -!dbg { - PRE_TARGETDEPS += lrelease -} - - +!dbg:PRE_TARGETDEPS += lrelease SOURCES += rbutilqt.cpp \ - main.cpp \ - install.cpp \ - base/httpget.cpp \ - configure.cpp \ - zip/zip.cpp \ - zip/unzip.cpp \ - base/zipinstaller.cpp \ - progressloggergui.cpp \ - installtalkwindow.cpp \ - base/talkfile.cpp \ - base/talkgenerator.cpp \ - base/autodetection.cpp \ - ../ipodpatcher/ipodpatcher.c \ - ../sansapatcher/sansapatcher.c \ - browsedirtree.cpp \ - themesinstallwindow.cpp \ - base/uninstall.cpp \ - uninstallwindow.cpp \ - base/utils.cpp \ - preview.cpp \ - base/encoders.cpp \ - encttscfggui.cpp \ - base/encttssettings.cpp \ - base/tts.cpp \ - ../../tools/wavtrim.c \ - ../../tools/voicefont.c \ - base/voicefile.cpp \ - createvoicewindow.cpp \ - base/rbsettings.cpp \ - base/rbunzip.cpp \ - base/rbzip.cpp \ - base/detect.cpp \ - sysinfo.cpp \ - base/bootloaderinstallbase.cpp \ - base/bootloaderinstallmi4.cpp \ - base/bootloaderinstallhex.cpp \ - base/bootloaderinstallipod.cpp \ - base/bootloaderinstallsansa.cpp \ - base/bootloaderinstallfile.cpp \ - ../../tools/mkboot.c \ - ../../tools/iriver.c - + main.cpp \ + install.cpp \ + base/httpget.cpp \ + configure.cpp \ + zip/zip.cpp \ + zip/unzip.cpp \ + base/zipinstaller.cpp \ + progressloggergui.cpp \ + installtalkwindow.cpp \ + base/talkfile.cpp \ + base/talkgenerator.cpp \ + base/autodetection.cpp \ + ../ipodpatcher/ipodpatcher.c \ + ../sansapatcher/sansapatcher.c \ + ../chinachippatcher/chinachip.c \ + browsedirtree.cpp \ + themesinstallwindow.cpp \ + base/uninstall.cpp \ + uninstallwindow.cpp \ + base/utils.cpp \ + preview.cpp \ + base/encoders.cpp \ + encttscfggui.cpp \ + base/encttssettings.cpp \ + base/tts.cpp \ + ../../tools/wavtrim.c \ + ../../tools/voicefont.c \ + base/voicefile.cpp \ + createvoicewindow.cpp \ + base/rbsettings.cpp \ + base/rbunzip.cpp \ + base/rbzip.cpp \ + base/detect.cpp \ + sysinfo.cpp \ + base/bootloaderinstallbase.cpp \ + base/bootloaderinstallmi4.cpp \ + base/bootloaderinstallhex.cpp \ + base/bootloaderinstallipod.cpp \ + base/bootloaderinstallsansa.cpp \ + base/bootloaderinstallfile.cpp \ + base/bootloaderinstallchinachip.cpp \ + ../../tools/mkboot.c \ + ../../tools/iriver.c HEADERS += rbutilqt.h \ - install.h \ - base/httpget.h \ - configure.h \ - zip/zip.h \ - zip/unzip.h \ - zip/zipentry_p.h \ - zip/unzip_p.h \ - zip/zip_p.h \ - version.h \ - base/zipinstaller.h \ - installtalkwindow.h \ - base/talkfile.h \ - base/talkgenerator.h \ - base/autodetection.h \ - base/progressloggerinterface.h \ - progressloggergui.h \ - ../ipodpatcher/ipodpatcher.h \ - ../ipodpatcher/ipodio.h \ - ../ipodpatcher/parttypes.h \ - ../sansapatcher/sansapatcher.h \ - ../sansapatcher/sansaio.h \ - irivertools/h100sums.h \ - irivertools/h120sums.h \ - irivertools/h300sums.h \ - browsedirtree.h \ - themesinstallwindow.h \ - base/uninstall.h \ - uninstallwindow.h \ - base/utils.h \ - preview.h \ - base/encoders.h \ - encttscfggui.h \ - base/encttssettings.h \ - base/tts.h \ - ../../tools/wavtrim.h \ - ../../tools/voicefont.h \ - base/voicefile.h \ - createvoicewindow.h \ - base/rbsettings.h \ - base/rbunzip.h \ - base/rbzip.h \ - sysinfo.h \ - base/detect.h \ - base/bootloaderinstallbase.h \ - base/bootloaderinstallmi4.h \ - base/bootloaderinstallhex.h \ - base/bootloaderinstallipod.h \ - base/bootloaderinstallsansa.h \ - base/bootloaderinstallfile.h \ - ../../tools/mkboot.h \ - ../../tools/iriver.h + install.h \ + base/httpget.h \ + configure.h \ + zip/zip.h \ + zip/unzip.h \ + zip/zipentry_p.h \ + zip/unzip_p.h \ + zip/zip_p.h \ + version.h \ + base/zipinstaller.h \ + installtalkwindow.h \ + base/talkfile.h \ + base/talkgenerator.h \ + base/autodetection.h \ + base/progressloggerinterface.h \ + progressloggergui.h \ + ../ipodpatcher/ipodpatcher.h \ + ../ipodpatcher/ipodio.h \ + ../ipodpatcher/parttypes.h \ + ../sansapatcher/sansapatcher.h \ + ../sansapatcher/sansaio.h \ + ../chinachippatcher/chinachip.h \ + irivertools/h100sums.h \ + irivertools/h120sums.h \ + irivertools/h300sums.h \ + browsedirtree.h \ + themesinstallwindow.h \ + base/uninstall.h \ + uninstallwindow.h \ + base/utils.h \ + preview.h \ + base/encoders.h \ + encttscfggui.h \ + base/encttssettings.h \ + base/tts.h \ + ../../tools/wavtrim.h \ + ../../tools/voicefont.h \ + base/voicefile.h \ + createvoicewindow.h \ + base/rbsettings.h \ + base/rbunzip.h \ + base/rbzip.h \ + sysinfo.h \ + base/detect.h \ + base/bootloaderinstallbase.h \ + base/bootloaderinstallmi4.h \ + base/bootloaderinstallhex.h \ + base/bootloaderinstallipod.h \ + base/bootloaderinstallsansa.h \ + base/bootloaderinstallfile.h \ + base/bootloaderinstallchinachip.h \ + ../../tools/mkboot.h \ + ../../tools/iriver.h # Needed by QT on Win -INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools +INCLUDEPATH = . \ + irivertools \ + zip \ + zlib \ + ../ipodpatcher \ + ../sansapatcher \ + ../chinachippatcher \ + ../../tools/rbspeex \ + ../../tools INCLUDEPATH += base - -LIBS += -L../../tools/rbspeex -lrbspeex - +LIBS += -L../../tools/rbspeex \ + -lrbspeex TEMPLATE = app -dbg { - CONFIG += debug thread qt warn_on +dbg { + CONFIG += debug \ + thread \ + qt \ + warn_on DEFINES -= QT_NO_DEBUG_OUTPUT message("debug") } -!dbg { - CONFIG += release thread qt +!dbg { + CONFIG += release \ + thread \ + qt DEFINES += QT_NO_DEBUG_OUTPUT message("release") } - TARGET = rbutilqt - FORMS += rbutilqtfrm.ui \ - aboutbox.ui \ - installfrm.ui \ - progressloggerfrm.ui \ - configurefrm.ui \ - browsedirtreefrm.ui \ - installtalkfrm.ui \ - themesinstallfrm.ui \ - uninstallfrm.ui \ - previewfrm.ui \ - createvoicefrm.ui \ - sysinfofrm.ui - + aboutbox.ui \ + installfrm.ui \ + progressloggerfrm.ui \ + configurefrm.ui \ + browsedirtreefrm.ui \ + installtalkfrm.ui \ + themesinstallfrm.ui \ + uninstallfrm.ui \ + previewfrm.ui \ + createvoicefrm.ui \ + sysinfofrm.ui RESOURCES += rbutilqt.qrc -win32 { - RESOURCES += rbutilqt-win.qrc -} -!dbg { - RESOURCES += rbutilqt-lang.qrc -} - +win32:RESOURCES += rbutilqt-win.qrc +!dbg:RESOURCES += rbutilqt-lang.qrc TRANSLATIONS += lang/rbutil_de.ts \ - lang/rbutil_fi.ts \ - lang/rbutil_fr.ts \ - lang/rbutil_gr.ts \ - lang/rbutil_he.ts \ - lang/rbutil_ja.ts \ - lang/rbutil_nl.ts \ - lang/rbutil_pt.ts \ - lang/rbutil_pt_BR.ts \ - lang/rbutil_tr.ts \ - lang/rbutil_zh_CN.ts \ - lang/rbutil_zh_TW.ts \ - - + lang/rbutil_fi.ts \ + lang/rbutil_fr.ts \ + lang/rbutil_gr.ts \ + lang/rbutil_he.ts \ + lang/rbutil_ja.ts \ + lang/rbutil_nl.ts \ + lang/rbutil_pt.ts \ + lang/rbutil_pt_BR.ts \ + lang/rbutil_tr.ts \ + lang/rbutil_zh_CN.ts \ + lang/rbutil_zh_TW.ts QT += network -DEFINES += RBUTIL _LARGEFILE64_SOURCE - -win32 { - SOURCES += ../ipodpatcher/ipodio-win32.c - SOURCES += ../sansapatcher/sansaio-win32.c +DEFINES += RBUTIL \ + _LARGEFILE64_SOURCE +win32 { + SOURCES += ../ipodpatcher/ipodio-win32.c + SOURCES += ../sansapatcher/sansaio-win32.c RC_FILE = rbutilqt.rc - LIBS += -lsetupapi -lnetapi32 + LIBS += -lsetupapi \ + -lnetapi32 } - -unix { - SOURCES += ../ipodpatcher/ipodio-posix.c - SOURCES += ../sansapatcher/sansaio-posix.c +unix { + SOURCES += ../ipodpatcher/ipodio-posix.c + SOURCES += ../sansapatcher/sansaio-posix.c } -unix:!static { - LIBS += -lusb -} -unix:static { - # force statically linking of libusb. Libraries that are appended - # later will get linked dynamically again. - LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic -} +unix:!static:LIBS += -lusb +unix:static:# force statically linking of libusb. Libraries that are appended -macx { - QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk - QMAKE_LFLAGS_PPC=-mmacosx-version-min=10.4 -arch ppc - QMAKE_LFLAGS_X86=-mmacosx-version-min=10.4 -arch i386 - CONFIG+=x86 ppc - LIBS += -L/usr/local/lib -framework IOKit +# later will get linked dynamically again. +LIBS += -Wl,-Bstatic \ + -lusb \ + -Wl,-Bdynamic +macx { + QMAKE_MAC_SDK = /Developer/SDKs/MacOSX10.4u.sdk + QMAKE_LFLAGS_PPC = -mmacosx-version-min=10.4 \ + -arch \ + ppc + QMAKE_LFLAGS_X86 = -mmacosx-version-min=10.4 \ + -arch \ + i386 + CONFIG += x86 \ + ppc + LIBS += -L/usr/local/lib \ + -framework \ + IOKit INCLUDEPATH += /usr/local/include QMAKE_INFO_PLIST = Info.plist RC_FILE = icons/rbutilqt.icns # rule for creating a dmg file - dmg.commands = hdiutil create -ov -srcfolder rbutilqt.app/ rbutil.dmg + dmg.commands = hdiutil \ + create \ + -ov \ + -srcfolder \ + rbutilqt.app/ \ + rbutil.dmg QMAKE_EXTRA_TARGETS += dmg } - -static { +static { QTPLUGIN += qtaccessiblewidgets - LIBS += -L$$(QT_BUILD_TREE)/plugins/accessible -lqtaccessiblewidgets + LIBS += -L$$(QT_BUILD_TREE)/plugins/accessible \ + -lqtaccessiblewidgets LIBS += -L. DEFINES += STATIC message("using static plugin") } - -unix { +unix { target.path = /usr/local/bin INSTALLS += target } - - - Index: rbutil/rbutilqt/base/bootloaderinstallbase.cpp =================================================================== --- rbutil/rbutilqt/base/bootloaderinstallbase.cpp (revision 22067) +++ rbutil/rbutilqt/base/bootloaderinstallbase.cpp (working copy) @@ -153,7 +153,8 @@ msg += "
    "; msg += tr("
  1. Safely remove your player.
  2. "); - if(model == "h100" || model == "h120" || model == "h300") { + if(model == "h100" || model == "h120" || model == "h300" || + model == "ondavx747") { hint = true; msg += tr("
  3. Reboot your player into the original firmware.
  4. " "
  5. Perform a firmware upgrade using the update functionality " Index: rbutil/rbutilqt/base/bootloaderinstallchinachip.h =================================================================== --- rbutil/rbutilqt/base/bootloaderinstallchinachip.h (revision 0) +++ rbutil/rbutilqt/base/bootloaderinstallchinachip.h (revision 0) @@ -0,0 +1,43 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2009 by Maurus Cuelenaere + * $Id$ + * + * 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. + * + ****************************************************************************/ + +#ifndef BOOTLOADERINSTALLCCPMP_H +#define BOOTLOADERINSTALLCCPMP_H + +#include +#include "bootloaderinstallbase.h" + +class BootloaderInstallChinaChip : public BootloaderInstallBase +{ + Q_OBJECT + + public: + BootloaderInstallChinaChip(QObject *parent = 0); + bool install(void); + bool uninstall(void); + BootloaderInstallBase::BootloaderType installed(void); + Capabilities capabilities(void); + QString ofHint(); + void logString(char* buffer, va_list args, int type); + + private slots: + void installStage2(void); +}; + +#endif // BOOTLOADERINSTALLCCPMP_H Property changes on: rbutil/rbutilqt/base/bootloaderinstallchinachip.h ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Index: rbutil/rbutilqt/base/bootloaderinstallchinachip.cpp =================================================================== --- rbutil/rbutilqt/base/bootloaderinstallchinachip.cpp (revision 0) +++ rbutil/rbutilqt/base/bootloaderinstallchinachip.cpp (revision 0) @@ -0,0 +1,117 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2009 by Maurus Cuelenaere + * $Id$ + * + * 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 "bootloaderinstallchinachip.h" + +#include "../chinachippatcher/chinachip.h" + +BootloaderInstallChinaChip::BootloaderInstallChinaChip(QObject *parent) + : BootloaderInstallBase(parent) +{ + (void)parent; +} + +QString BootloaderInstallChinaChip::ofHint() +{ + return tr("Bootloader installation requires you to provide " + "a firmware file of the original firmware (HXF file). " + "You need to download this file yourself due to legal " + "reasons. Please refer to the " + "manual and the " + "OndaVX747 wiki page on " + "how to obtain this file.
    " + "Press Ok to continue and browse your computer for the firmware " + "file."); +} + +void BootloaderInstallChinaChip::logString(char* format, va_list args, int type) +{ + QString buffer; + + emit logItem(buffer.vsprintf(format, args), type); + QCoreApplication::processEvents(); +} + +static void info(void* userdata, char* format, ...) +{ + BootloaderInstallChinaChip* pThis = (BootloaderInstallChinaChip*) userdata; + va_list args; + + va_start(args, format); + pThis->logString(format, args, LOGINFO); + va_end(args); +} + +static void err(void* userdata, char* format, ...) +{ + BootloaderInstallChinaChip* pThis = (BootloaderInstallChinaChip*) userdata; + va_list args; + + va_start(args, format); + pThis->logString(format, args, LOGERROR); + va_end(args); +} + +bool BootloaderInstallChinaChip::install() +{ + if(m_offile.isEmpty()) + return false; + + emit logItem(tr("Downloading bootloader file"), LOGINFO); + + connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2())); + downloadBlStart(m_blurl); + + return true; +} + +void BootloaderInstallChinaChip::installStage2() +{ + m_tempfile.open(); + QString blfile = m_tempfile.fileName(); + m_tempfile.close(); + + QString backupfile = QFileInfo(m_blfile).absoluteDir().absoluteFilePath("ccpmp.bin"); + + int ret = chinachip_patch(m_offile.toLocal8Bit(), blfile.toLocal8Bit(), m_blfile.toLocal8Bit(), + backupfile.toLocal8Bit(), &info, &err, (void*)this); + qDebug() << "chinachip_patch" << ret; + + emit done(ret); +} + +bool BootloaderInstallChinaChip::uninstall() +{ + /* TODO: only way is to restore the OF */ + return false; +} + +BootloaderInstallBase::BootloaderType BootloaderInstallChinaChip::installed() +{ + /* TODO: find a way to figure this out */ + return BootloaderUnknown; +} + +BootloaderInstallBase::Capabilities BootloaderInstallChinaChip::capabilities() +{ + return (Install | IsFile | NeedsOf); +} Property changes on: rbutil/rbutilqt/base/bootloaderinstallchinachip.cpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Property changes on: rbutil/chinachippatcher ___________________________________________________________________ Added: svn:ignore + chinachip Index: rbutil/chinachippatcher/chinachip.c =================================================================== --- rbutil/chinachippatcher/chinachip.c (revision 0) +++ rbutil/chinachippatcher/chinachip.c (revision 0) @@ -0,0 +1,310 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Maurus Cuelenaere + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include "chinachip.h" + +/* From http://www.rockbox.org/wiki/ChinaChip */ +struct header +{ + uint32_t signature; /* WADF */ + uint32_t unk; + int8_t timestamp[12]; /* 200805081100 */ + uint32_t size; + uint32_t checksum; + uint32_t unk2; + int8_t identifier[32]; /* Chinachip PMP firmware V1.0 */ +} __attribute__ ((packed)); + +static inline void int2le(unsigned char* addr, unsigned int val) +{ + addr[0] = val & 0xff; + addr[1] = (val >> 8) & 0xff; + addr[2] = (val >> 16) & 0xff; + addr[3] = (val >> 24) & 0xff; +} + +static inline unsigned int le2int(unsigned char* buf) +{ + return (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; +} + +static long int filesize(FILE* fd) +{ + long int len; + fseek(fd, 0, SEEK_END); + len = ftell(fd); + fseek(fd, 0, SEEK_SET); + return len; +} + +#ifdef STANDALONE +#define ERR(fmt, ...) err(userdata, "[ERR] "fmt"\n", ##__VA_ARGS__) +#define INFO(fmt, ...) info(userdata, "[INFO] "fmt"\n", ##__VA_ARGS__) +#define tr(x) x +#else +#define ERR(fmt, ...) err(userdata, fmt, ##__VA_ARGS__) +#define INFO(fmt, ...) info(userdata, fmt, ##__VA_ARGS__) +#endif +#define FCLOSE(fd) fclose(fd); fd = NULL; +#define CCPMPBIN_HEADER_SIZE (sizeof(uint32_t)*2 + sizeof(uint8_t) + 9) +#define TOTAL_SIZE (fsize + CCPMPBIN_HEADER_SIZE + bsize) +int chinachip_patch(const char* firmware, const char* bootloader, + const char* output, const char* ccpmp_backup, + void (*info)(void*, char*, ...), + void (*err)(void*, char*, ...), + void* userdata) +{ + char header_time[13]; + time_t cur_time; + struct tm* time_info; + unsigned char* buf = NULL; + FILE *fd = NULL, *bd = NULL, *od = NULL; + unsigned int ccpmp_size = 0, i, fsize, bsize; + signed int checksum = 0, ccpmp_pos; + + fd = fopen(firmware, "rb"); + if(!fd) + { + ERR("Can't open file %s!", firmware); + goto err; + } + bd = fopen(bootloader, "rb"); + if(!bd) + { + ERR("Can't open file %s!", bootloader); + goto err; + } + + bsize = filesize(bd); + INFO("Bootloader size is %d bytes", bsize); + FCLOSE(bd); + + fsize = filesize(fd); + INFO("Firmware size is %d bytes", fsize); + + buf = malloc(TOTAL_SIZE); + if(buf == NULL) + { + ERR("Can't allocate %d bytes!", fsize); + goto err; + } + memset(buf, 0, TOTAL_SIZE); + + INFO("Reading %s into memory...", firmware); + if(fread(buf, fsize, 1, fd) != 1) + { + ERR("Can't read file %s to memory!", firmware); + goto err; + } + FCLOSE(fd); + + if(memcmp(buf, "WADF", 4)) + { + ERR("File %s isn't a valid ChinaChip firmware!", firmware); + goto err; + } + + ccpmp_pos = -1, i = 0x40; + do + { + int filenamesize = le2int(&buf[i]); + i += sizeof(uint32_t); + + if(!strncmp((char*) &buf[i], "ccpmp.bin", 9)) + { + ccpmp_pos = i; + ccpmp_size = le2int(&buf[i + sizeof(uint8_t) + filenamesize]); + } + else + i += filenamesize + le2int(&buf[i + sizeof(uint8_t) + filenamesize]) + + sizeof(uint32_t) + sizeof(uint8_t); + } while(ccpmp_pos < 0 && i < fsize); + + if(i >= fsize) + { + ERR("Couldn't find ccpmp.bin in %s!", firmware); + goto err; + } + INFO("Found ccpmp.bin at %d bytes", ccpmp_pos); + + if(ccpmp_backup) + { + bd = fopen(ccpmp_backup, "wb"); + if(!bd) + { + ERR("Can't open file %s!", ccpmp_backup); + goto err; + } + + INFO("Writing %d bytes to %s...", ccpmp_size, ccpmp_backup); + if(fwrite(&buf[ccpmp_pos], ccpmp_size, 1, bd) != 1) + { + ERR("Can't write to file %s!", ccpmp_backup); + goto err; + } + FCLOSE(bd); + } + + INFO("Renaming it to ccpmp.old..."); + buf[ccpmp_pos + 6] = 'o'; + buf[ccpmp_pos + 7] = 'l'; + buf[ccpmp_pos + 8] = 'd'; + + bd = fopen(bootloader, "rb"); + if(!bd) + { + ERR("Can't open file %s!", bootloader); + goto err; + } + + /* Also include path size */ + ccpmp_pos -= sizeof(uint32_t); + + INFO("Making place for ccpmp.bin..."); + memmove(&buf[ccpmp_pos + bsize + CCPMPBIN_HEADER_SIZE], + &buf[ccpmp_pos], fsize - ccpmp_pos); + + INFO("Reading %s into memory...", bootloader); + if(fread(&buf[ccpmp_pos + CCPMPBIN_HEADER_SIZE], + bsize, 1, bd) != 1) + { + ERR("Can't read file %s to memory!", bootloader); + goto err; + } + FCLOSE(bd); + + INFO("Adding header to %s...", bootloader); + int2le(&buf[ccpmp_pos ], 9); /* Pathname Size */ + memcpy(&buf[ccpmp_pos + 4 ], "ccpmp.bin", 9); /* Pathname */ + memset(&buf[ccpmp_pos + 4 + 9 ], 0x20, sizeof(uint8_t)); /* File Type */ + int2le(&buf[ccpmp_pos + 4 + 9 + 1], bsize); /* File Size */ + + time(&cur_time); + time_info = localtime(&cur_time); + if(time_info == NULL) + { + ERR("Can't obtain current time!"); + goto err; + } + + snprintf(header_time, 13, "%04d%02d%02d%02d%02d", time_info->tm_year + 1900, + time_info->tm_mon, + time_info->tm_mday, + time_info->tm_hour, + time_info->tm_min); + + INFO("Computing checksum..."); + for(i = sizeof(struct header); i < TOTAL_SIZE; i+=4) + checksum += le2int(&buf[i]); + + INFO("Updating main header..."); + memcpy(&buf[offsetof(struct header, timestamp)], header_time, 12); + int2le(&buf[offsetof(struct header, size) ], TOTAL_SIZE); + int2le(&buf[offsetof(struct header, checksum) ], checksum); + + od = fopen(output, "wb"); + if(!od) + { + ERR("Can't open file %s!", output); + goto err; + } + + INFO("Writing output to %s...", output); + if(fwrite(buf, TOTAL_SIZE, 1, od) != 1) + { + ERR("Can't write to file %s!", output); + goto err; + } + fclose(od); + free(buf); + + return 0; + +err: + if(buf) + free(buf); + if(fd) + fclose(fd); + if(bd) + fclose(bd); + if(od) + fclose(od); + + return -1; +} + + +#ifdef STANDALONE + +#define VERSION "0.1" +#define PRINT(fmt, ...) fprintf(stderr, fmt"\n", ##__VA_ARGS__) + +static void info(void* userdata, char* fmt, ...) +{ + (void)userdata; + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +static void err(void* userdata, char* fmt, ...) +{ + (void)userdata; + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +void usage(char* name) +{ + PRINT("Usage:"); + PRINT(" %s [backup]", name); + PRINT("\nExample:"); + PRINT(" %s VX747.HXF bootloader.bin output.HXF ccpmp.bak", name); + PRINT(" This will copy ccpmp.bin in VX747.HXF as ccpmp.old and replace it" + " with bootloader.bin, the output will get written to output.HXF." + " The old ccpmp.bin will get written to ccpmp.bak."); +} + +int main(int argc, char* argv[]) +{ + PRINT("ChinaChipPatcher v" VERSION " - (C) Maurus Cuelenaere 2009"); + PRINT("This is free software; see the source for copying conditions. There is NO"); + PRINT("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); + + if(argc < 4) + { + usage(argv[0]); + return 1; + } + + return chinachip_patch(argv[1], argv[2], argv[3], argc > 4 ? argv[4] : NULL, + &info, &err, NULL); +} +#endif Property changes on: rbutil/chinachippatcher/chinachip.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Index: rbutil/chinachippatcher/chinachip.h =================================================================== --- rbutil/chinachippatcher/chinachip.h (revision 0) +++ rbutil/chinachippatcher/chinachip.h (revision 0) @@ -0,0 +1,39 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Maurus Cuelenaere + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef __INCLUDE_CHINACHIP_H_ +#define __INCLUDE_CHINACHIP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int chinachip_patch(const char* firmware, const char* bootloader, + const char* output, const char* ccpmp_backup, + void (*info)(void*, char*, ...), + void (*err)(void*, char*, ...), + void* userdata); + +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_CHINACHIP_H_ */ Property changes on: rbutil/chinachippatcher/chinachip.h ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Index: rbutil/chinachippatcher/Makefile =================================================================== --- rbutil/chinachippatcher/Makefile (revision 0) +++ rbutil/chinachippatcher/Makefile (revision 0) @@ -0,0 +1,10 @@ +CFLAGS=-g -Wall -DSTANDALONE +CC=gcc + +all: chinachip + +chinachip: chinachip.c + $(CC) $(CFLAGS) -o $@ $^ + +clean: + rm -f chinachip Property changes on: rbutil/chinachippatcher/Makefile ___________________________________________________________________ Added: svn:eol-style + native