Ejemplo n.º 1
0
/* On USB root drives we create a dummy recovery and settings partition.
 * Just in case the user wants to start booting from HDD later */
bool InitDriveThread::formatUsbDrive()
{
    zeroMbr();
    partitionDrive();
    setDiskId();
    formatBootPartition();
    formatSettingsPartition();

    return true;
}
Ejemplo n.º 2
0
bool InitDriveThread::method_reformatDrive()
{
    emit statusUpdate(tr("Saving boot files to memory"));
    if (!saveBootFiles() )
    {
        emit error(tr("Error saving boot files to memory. SD card may be damaged."));
        return false;
    }
    if (!umountSystemPartition())
    {
        emit error(tr("Error unmounting system partition."));
        return false;
    }

    emit statusUpdate(tr("Zeroing partition table"));
    if (!zeroMbr())
    {
        emit error(tr("Error zero'ing MBR/GPT. SD card may be broken or advertising wrong capacity."));
        return false;
    }

    emit statusUpdate(tr("Creating partitions"));

    if (!partitionDrive())
    {
        emit error(tr("Error partitioning"));
        return false;
    }

    emit statusUpdate(tr("Formatting boot partition (fat)"));
    if (!formatBootPartition())
    {
       emit error(tr("Error formatting boot partition (fat)"));
       return false;
    }

    emit statusUpdate(tr("Copying boot files to storage"));
    mountSystemPartition();
    restoreBootFiles();
    umountSystemPartition();

    return true;
}
Ejemplo n.º 3
0
void DriveFormatThread::run()
{
    if (_reformatBoot)
    {
        emit statusUpdate(tr("Saving boot files to memory"));

        if (!_i->saveBootFiles() )
        {
            emit error(tr("Error saving boot files to memory. Not enough memory to save all files currently on SD card?"));
            return;
        }
        _i->umountSystemPartition();
    }

    emit statusUpdate(tr("Zeroing partition table"));
    if (!zeroMbr())
    {
        emit error(tr("Error zero'ing MBR"));
        return;
    }

    emit statusUpdate(tr("Creating partitions"));

    if (!partitionDrive())
    {
        emit error(tr("Error partitioning"));
        return;
    }

    if (_reformatBoot)
    {
        /* A10 devices need to have u-boot written to the spare space before the first partition */
        if (QFile::exists("/tmp/boot/u-boot.bin") && QFile::exists("/tmp/boot/sunxi-spl.bin"))
        {
            emit statusUpdate(tr("Installing u-boot SPL"));
            if (!installUbootSPL())
            {
                emit error(tr("Error writing u-boot to disk"));
                return;
            }
        }

        emit statusUpdate(tr("Formatting boot partition (fat)"));
        if (!formatBootPartition())
        {
            emit error(tr("Error formatting boot partition (vfat)"));
            return;
        }

        emit statusUpdate(tr("Copying boot files to storage"));
        _i->mountSystemPartition();
        _i->restoreBootFiles();

        emit statusUpdate(tr("Finish writing boot files to disk (sync)"));
        sync();
    }

    emit statusUpdate(tr("Formatting data partition (%1)").arg(_fs));
    if (!formatDataPartition())
    {
        emit error(tr("Error Formatting data partition (%1)").arg(_fs));
        return;
    }

    emit statusUpdate(tr("Mounting and initializing data partition"));
    _i->initializeDataPartition(_datadev);

    emit statusUpdate(tr("Editing cmdline.txt"));

    /* Data dev setting */
    QFile f("/boot/cmdline.txt");
    f.open(QIODevice::ReadWrite);
    QByteArray line = f.readAll().trimmed();
    if (_fs == "btrfs")
        line += " fstype=btrfs";
    if (_iscsi)
        line += " datadev=iscsi";
    else
        line += " datadev="+_datadev;
    f.seek(0);
    f.write(line.trimmed());
    f.close();

    /* Data dev setting in uEnv.txt (for A10 devices) */
    f.setFileName("/boot/uEnv.txt");
    f.open(QIODevice::ReadWrite);
    line = f.readAll().trimmed();
    if (_fs == "btrfs")
        line += " fstype=btrfs";
    if (_iscsi)
        line += " datadev=iscsi";
    else
        line += " datadev="+_datadev;
    f.seek(0);
    f.write(line.trimmed());
    f.close();

    /* Overscan setting */
    bool configchanged = false;
    f.setFileName("/boot/config.txt");
    f.open(QIODevice::ReadOnly);
    QByteArray configdata = f.readAll();
    f.close();
    bool overscanCurrentlyDisabled = configdata.contains("disable_overscan=1");

    if (_i->disableOverscan() && !overscanCurrentlyDisabled)
    {
        configdata += "\ndisable_overscan=1";
        configchanged = true;
    }
    else if (!_i->disableOverscan() && overscanCurrentlyDisabled)
    {
        configdata.replace("disable_overscan=1", "");
        configchanged = true;
    }
    if (configchanged)
    {
        f.open(QIODevice::WriteOnly);
        f.write(configdata.trimmed());
        f.close();
    }

    /* Finished */
    emit statusUpdate(tr("Unmounting boot partition"));
    _i->umountSystemPartition();

    emit statusUpdate(tr("Finish writing to disk (sync)"));
    sync();

    emit completed();
}