Exemplo n.º 1
0
BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
        : BootloaderInstallBase(parent)
{
    (void)parent;
    // initialize sector buffer. sansa_sectorbuf is instantiated by
    // sansapatcher.
    // The buffer itself is only present once, so make sure to not allocate
    // it if it was already allocated. The application needs to take care
    // no concurrent (i.e. multiple objects of this class running) requests
    // are done.
    if(sansa_sectorbuf == NULL)
        sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
}
Exemplo n.º 2
0
bool Autodetection::detect()
{
    m_device = "";
    m_mountpoint = "";
    m_errdev = "";

    detectUsb();

    // Try detection via rockbox.info / rbutil.log
    QStringList mounts = mountpoints();

    for(int i=0; i< mounts.size();i++)
    {
        // do the file checking
        QDir dir(mounts.at(i));
        qDebug() << "[Autodetect] paths to check:" << mounts;
        if(dir.exists())
        {
            // check logfile first.
            if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) {
                QSettings log(mounts.at(i) + "/.rockbox/rbutil.log",
                              QSettings::IniFormat, this);
                if(!log.value("platform").toString().isEmpty()) {
                    if(m_device.isEmpty())
                        m_device = log.value("platform").toString();
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect] rbutil.log detected:" << m_device << m_mountpoint;
                    return true;
                }
            }

            // check rockbox-info.txt afterwards.
            RockboxInfo info(mounts.at(i));
            if(info.success())
            {
                if(m_device.isEmpty())
                {
                    m_device = info.target();
                    // special case for video64mb. This is a workaround, and
                    // should get replaced when autodetection is reworked.
                    if(m_device == "ipodvideo" && info.ram() == 64)
                    {
                        m_device = "ipodvideo64mb";
                    }
                }
                m_mountpoint = mounts.at(i);
                qDebug() << "[Autodetect] rockbox-info.txt detected:"
                         << m_device << m_mountpoint;
                return true;
            }

            // check for some specific files in root folder
            QDir root(mounts.at(i));
            QStringList rootentries = root.entryList(QDir::Files);
            if(rootentries.contains("archos.mod", Qt::CaseInsensitive))
            {
                // archos.mod in root folder -> Archos Player
                m_device = "player";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive))
            {
                // ONDIOST.BIN in root -> Ondio FM
                m_device = "ondiofm";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive))
            {
                // ONDIOSP.BIN in root -> Ondio SP
                m_device = "ondiosp";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive))
            {
                qDebug() << "[Autodetect] ajbrec.ajz found. Trying detectAjbrec()";
                if(detectAjbrec(mounts.at(i))) {
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect]" << m_device;
                    return true;
                }
            }
            // detection based on player specific folders
            QStringList rootfolders = root.entryList(QDir::Dirs
                    | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
            if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive))
            {
                // GBSYSTEM folder -> Gigabeat
                m_device = "gigabeatf";
                m_mountpoint = mounts.at(i);
                return true;
            }
#if defined(Q_OS_WIN32)
            // on windows, try to detect the drive letter of an Ipod
            if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive))
            {
                // iPod_Control folder -> Ipod found
                // detecting of the Ipod type is done below using ipodpatcher
                m_mountpoint = mounts.at(i);
            }
#endif
        }

    }

    int n;
    // try ipodpatcher
    // initialize sector buffer. Needed.
    ipod_sectorbuf = NULL;
    ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
    struct ipod_t ipod;
    n = ipod_scan(&ipod);
    if(n == 1) {
        qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
        // if the found ipod is a macpod also notice it as device with problem.
        if(ipod.macpod)
            m_errdev = ipod.targetname;
        m_device = ipod.targetname;
        // since resolveMountPoint is doing exact matches we need to select
        // the correct partition.
        QString mp(ipod.diskname);
#ifdef Q_OS_LINUX
        mp.append("2");
#endif
#ifdef Q_OS_MACX
        mp.append("s2");
#endif
        m_mountpoint = resolveMountPoint(mp);
        return true;
    }
    else {
        qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
    }
    free(ipod_sectorbuf);
    ipod_sectorbuf = NULL;

    // try sansapatcher
    // initialize sector buffer. Needed.
    sansa_sectorbuf = NULL;
    sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
    struct sansa_t sansa;
    n = sansa_scan(&sansa);
    if(n == 1) {
        qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname;
        m_device = QString("sansa%1").arg(sansa.targetname);
        QString mp(sansa.diskname);
#ifdef Q_OS_LINUX
        mp.append("1");
#endif
#ifdef Q_OS_MACX
        mp.append("s1");
#endif
        m_mountpoint = resolveMountPoint(mp);
        return true;
    }
    else {
        qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n;
    }
    free(sansa_sectorbuf);
    sansa_sectorbuf = NULL;

    if(m_mountpoint.isEmpty() && m_device.isEmpty()
            && m_errdev.isEmpty() && m_incompat.isEmpty())
        return false;
    return true;
}
Exemplo n.º 3
0
void Autodetection::mergePatcher(void)
{
    int n;
    // try ipodpatcher
    // initialize sector buffer. Needed.
    struct ipod_t ipod;
    ipod.sectorbuf = NULL;
    ipod_alloc_buffer(&ipod, BUFFER_SIZE);
    n = ipod_scan(&ipod);
    // FIXME: handle more than one Ipod connected in ipodpatcher.
    if(n == 1) {
        LOG_INFO() << "Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
        // since resolveMountPoint is doing exact matches we need to select
        // the correct partition.
        QString mp(ipod.diskname);
#ifdef Q_OS_LINUX
        mp.append("2");
#endif
#ifdef Q_OS_MACX
        mp.append("s2");
#endif
        struct Detected d;
        d.device = ipod.targetname;
        d.mountpoint = Utils::resolveMountPoint(mp);
        // if the found ipod is a macpod also notice it as device with problem.
        if(ipod.macpod)
            d.status = PlayerWrongFilesystem;
        else
            d.status = PlayerOk;
        updateDetectedDevice(d);
    }
    else {
        LOG_INFO() << "ipodpatcher: no Ipod found." << n;
    }
    ipod_dealloc_buffer(&ipod);

    // try sansapatcher
    // initialize sector buffer. Needed.
    struct sansa_t sansa;
    sansa_alloc_buffer(&sansa, BUFFER_SIZE);
    n = sansa_scan(&sansa);
    if(n == 1) {
        LOG_INFO() << "Sansa found:"
                   << sansa.targetname << "at" << sansa.diskname;
        QString mp(sansa.diskname);
#ifdef Q_OS_LINUX
        mp.append("1");
#endif
#ifdef Q_OS_MACX
        mp.append("s1");
#endif
        struct Detected d;
        d.device = QString("sansa%1").arg(sansa.targetname);
        d.mountpoint = Utils::resolveMountPoint(mp);
        d.status = PlayerOk;
        updateDetectedDevice(d);
    }
    else {
        LOG_INFO() << "sansapatcher: no Sansa found." << n;
    }
    sansa_dealloc_buffer(&sansa);
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
    char yesno[4];
    int i;
    int n;
    char* filename;
    int action = SHOW_INFO;
    int type;
    struct sansa_t sansa;
    int res = 0;

    fprintf(stderr,"sansapatcher v" VERSION " - (C) Dave Chapman 2006-2007\n");
    fprintf(stderr,"This is free software; see the source for copying conditions.  There is NO\n");
    fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");

    if ((argc > 1) && ((strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0))) {
        print_usage();
        return 1;
    }

    if (sansa_alloc_buffer(&sansa_sectorbuf,BUFFER_SIZE) < 0) {
        fprintf(stderr,"Failed to allocate memory buffer\n");
    }

    if ((argc > 1) && (strcmp(argv[1],"--scan")==0)) {
        if (sansa_scan(&sansa) == 0)
            fprintf(stderr,"[ERR]  No E200s or C200s found.\n");
        return 0;
    }

    /* If the first parameter doesn't start with -, then we interpret it as a device */
    if ((argc > 1) && (argv[1][0] != '-')) {
        sansa.diskname[0]=0;
#ifdef __WIN32__
        snprintf(sansa.diskname,sizeof(sansa.diskname),"\\\\.\\PhysicalDrive%s",argv[1]);
#else
        strncpy(sansa.diskname,argv[1],sizeof(sansa.diskname));
#endif
        i = 2;
    } else {
        /* Autoscan for C200/E200s */
        n = sansa_scan(&sansa);
        if (n==0) {
            fprintf(stderr,"[ERR]  No E200s or C200s found, aborting\n");
            fprintf(stderr,"[ERR]  Please connect your sansa and ensure it is in UMS mode\n");
#if defined(__APPLE__) && defined(__MACH__)
            fprintf(stderr,"[ERR]  Also ensure that your Sansa's main partition is not mounted.\n");
#elif !defined(__WIN32__)
            if (geteuid()!=0) {
                fprintf(stderr,"[ERR]  You may also need to run sansapatcher as root.\n");
            }
#endif
            fprintf(stderr,"[ERR]  Please refer to the Rockbox manual if you continue to have problems.\n");
        } else if (n > 1) {
            fprintf(stderr,"[ERR]  %d Sansas found, aborting\n",n);
            fprintf(stderr,"[ERR]  Please connect only one Sansa and re-run sansapatcher.\n");
        }

        if (n != 1) {
            if (argc==1) {
                printf("\nPress ENTER to exit sansapatcher :");
                fgets(yesno,4,stdin);
            }
            return 0;
        }

        i = 1;
    }

    action = INTERACTIVE;

    while (i < argc) {
        if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) {
            action = LIST_IMAGES;
            i++;
        } else if (strcmp(argv[i],"--install")==0) {
            action = INSTALL;
            i++;
        } else if ((strcmp(argv[i],"-d")==0) || 
                   (strcmp(argv[i],"--delete-bootloader")==0)) {
            action = DELETE_BOOTLOADER;
            i++;
        } else if ((strcmp(argv[i],"-a")==0) || 
                   (strcmp(argv[i],"--add-bootloader")==0)) {
            action = ADD_BOOTLOADER;
            type = FILETYPE_MI4;
            i++;
            if (i == argc) { print_usage(); return 1; }
            filename=argv[i];
            i++;
        } else if ((strcmp(argv[i],"-of")==0) || 
                   (strcmp(argv[i],"--update-original-firmware")==0)) {
            action = UPDATE_OF;
            i++;
            if (i == argc) { print_usage(); return 1; }
            filename=argv[i];
            i++;
        } else if ((strcmp(argv[i],"-bl")==0) || 
                   (strcmp(argv[i],"--update-ppbl")==0)) {
            action = UPDATE_PPBL;
            i++;
            if (i == argc) { print_usage(); return 1; }
            filename=argv[i];
            i++;
        } else if ((strcmp(argv[i],"-rf")==0) || 
                   (strcmp(argv[i],"--read-firmware")==0)) {
            action = READ_FIRMWARE;
            i++;
            if (i == argc) { print_usage(); return 1; }
            filename=argv[i];
            i++;
        }
    }

    if (sansa.diskname[0]==0) {
        print_usage();
        return 1;
    }

    if (sansa_open(&sansa, 0) < 0) {
        return 1;
    }

    fprintf(stderr,"[INFO] Reading partition table from %s\n",sansa.diskname);
    fprintf(stderr,"[INFO] Sector size is %d bytes\n",sansa.sector_size);

    if (sansa_read_partinfo(&sansa,0) < 0) {
        return 2;
    }

    display_partinfo(&sansa);

    i = is_sansa(&sansa);
    if (i < 0) {
        fprintf(stderr,"[ERR]  Disk is not an E200 or C200 (%d), aborting.\n",i);
        return 3;
    }

    if (sansa.hasoldbootloader) {
        printf("[ERR]  ************************************************************************\n");
        printf("[ERR]  *** OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n");
        printf("[ERR]  *** You must reinstall the original Sansa firmware before running\n");
        printf("[ERR]  *** sansapatcher for the first time.\n");
        printf("[ERR]  *** See http://www.rockbox.org/twiki/bin/view/Main/SansaE200Install\n");
        printf("[ERR]  ************************************************************************\n");
        res = 4;
    } else {
        if (action==LIST_IMAGES) {
            sansa_list_images(&sansa);
        } else if (action==INTERACTIVE) {

            printf("Enter i to install the Rockbox bootloader, u to uninstall\n or c to cancel and do nothing (i/u/c) :");

            if (fgets(yesno,4,stdin)) {
                if (yesno[0]=='i') {
                    if (sansa_reopen_rw(&sansa) < 0) {
                        res = 5;
                    }

                    if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) {
                        fprintf(stderr,"[INFO] Bootloader installed successfully.\n");
                    } else {
                        fprintf(stderr,"[ERR]  --install failed.\n");
                        res = 6;
                    }
                } else if (yesno[0]=='u') {
                    if (sansa_reopen_rw(&sansa) < 0) {
                        res = 5;
                    }

                    if (sansa_delete_bootloader(&sansa)==0) {
                        fprintf(stderr,"[INFO] Bootloader removed.\n");
                    } else {
                        fprintf(stderr,"[ERR]  Bootloader removal failed.\n");
                        res = 7;
                    }
                }
            }
        } else if (action==READ_FIRMWARE) {
            if (sansa_read_firmware(&sansa, filename)==0) {
                fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename);
            } else {
                fprintf(stderr,"[ERR]  --read-firmware failed.\n");
            }
        } else if (action==INSTALL) {
            if (sansa_reopen_rw(&sansa) < 0) {
                return 5;
            }

            if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) {
                fprintf(stderr,"[INFO] Bootloader installed successfully.\n");
            } else {
                fprintf(stderr,"[ERR]  --install failed.\n");
            }
        } else if (action==ADD_BOOTLOADER) {
            if (sansa_reopen_rw(&sansa) < 0) {
                return 5;
            }

            if (sansa_add_bootloader(&sansa, filename, type)==0) {
                fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename);
            } else {
                fprintf(stderr,"[ERR]  --add-bootloader failed.\n");
            }
        } else if (action==DELETE_BOOTLOADER) {
            if (sansa_reopen_rw(&sansa) < 0) {
                return 5;
            }

            if (sansa_delete_bootloader(&sansa)==0) {
                fprintf(stderr,"[INFO] Bootloader removed successfully.\n");
            } else {
                fprintf(stderr,"[ERR]  --delete-bootloader failed.\n");
            }
        } else if (action==UPDATE_OF) {
            if (sansa_reopen_rw(&sansa) < 0) {
                return 5;
            }

            if (sansa_update_of(&sansa, filename)==0) {
                fprintf(stderr,"[INFO] OF updated successfully.\n");
            } else {
                fprintf(stderr,"[ERR]  --update-original-firmware failed.\n");
            }
        } else if (action==UPDATE_PPBL) {
            printf("[WARN] PPBL installation will overwrite your bootloader. This will lead to a\n");
            printf("       Sansa that won't boot if the bootloader file is invalid. Only continue if\n");
            printf("       you're sure you know what you're doing.\n");
            printf("       Continue (y/n)? ");

            if (fgets(yesno,4,stdin)) {
                if (yesno[0]=='y') {
                    if (sansa_reopen_rw(&sansa) < 0) {
                        return 5;
                    }
        
                    if (sansa_update_ppbl(&sansa, filename)==0) {
                        fprintf(stderr,"[INFO] PPBL updated successfully.\n");
                    } else {
                        fprintf(stderr,"[ERR]  --update-ppbl failed.\n");
                    }
                }
            }
        }
    }

    sansa_close(&sansa);

    if (action==INTERACTIVE) {
        printf("Press ENTER to exit sansapatcher :");
        fgets(yesno,4,stdin);
    }

    return res;
}