Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions recovery/bootselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,33 @@ void BootSelectionDialog::accept()
QSettings settings("/settings/noobs.conf", QSettings::IniFormat, this);
QVariantMap m = item->data(Qt::UserRole).toMap();
QByteArray partition = m.value("partitions").toList().first().toByteArray();
QRegExp partnrRx("([0-9]+)$");
if (partnrRx.indexIn(partition) == -1)

int partitionNr;
QRegExp parttype("^PARTUUID");
if (parttype.indexIn(partition) == -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably use http://doc.qt.io/archives/qt-4.8/qstring.html#startsWith here instead?

{
QMessageBox::critical(this, "noobs.conf corrupt", "Not a valid partition: "+partition);
return;
// SD card style /dev/mmcblk0pDD
QRegExp partnrRx("([0-9]+)$");
if (partnrRx.indexIn(partition) == -1)
{
QMessageBox::critical(this, "installed_os.json corrupt", "Not a valid partition: "+partition);
return;
}
partitionNr = partnrRx.cap(1).toInt();
}
int partitionNr = partnrRx.cap(1).toInt();
else
{
// USB style PARTUUID=000dbedf-XX
QRegExp partnrRx("([0-9a-f][0-9a-f])$");
if (partnrRx.indexIn(partition) == -1)
{
QMessageBox::critical(this, "installed_os.json corrupt", "Not a valid partition: "+partition);
return;
}
bool ok;
partitionNr = partnrRx.cap(1).toInt(&ok, 16);
}

int oldpartitionNr = settings.value("default_partition_to_boot", 0).toInt();

if (partitionNr != oldpartitionNr)
Expand Down
65 changes: 7 additions & 58 deletions recovery/multiimagewritethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,13 @@ bool MultiImageWriteThread::processImage(OsInfo *image)
QVariantList vpartitions;
foreach (PartitionInfo *p, *partitions)
{
vpartitions.append(p->partitionDevice());
QString part = p->partitionDevice();
if (part.left(13) != "/dev/mmcblk0p")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, what happens if you remove this special-casing for /dev/mmcblk0 and instead always use the partuuid?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to have some Linux distributions that came with an initramfs that did not support partuuid parameters (e.g. OSMC).
Not sure if that's still the case in recent versions though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@procount I wonder if it'd be worth adding an extra param to the os.json / os_list.json files stipulating whether they support partuuid parameters, and then only using this partuuid code if they do?

Copy link
Contributor Author

@procount procount May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we piggy-back the supports_usb_root or support_usb_boot parameters for that? I think they serve a similar purpose...?

Copy link
Contributor Author

@procount procount May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, if an OS doesn't support partuuid, then it can't be installed to USB. If so, then the additional code won't be necessary. I'm sure @XECDesign or @maxnet explained the use of supports_usb_root and supports_usb_boot somewhere but I can't find the reference.

{
part = getPartUUID(part);
}
vpartitions.append(part);

}
QSettings settings("/settings/noobs.conf", QSettings::IniFormat);
int videomode = settings.value("display_mode", 0).toInt();
Expand Down Expand Up @@ -1009,31 +1015,6 @@ void MultiImageWriteThread::patchConfigTxt()

}

QByteArray MultiImageWriteThread::getLabel(const QString part)
{
QByteArray result;
QProcess p;
p.start("/sbin/blkid -s LABEL -o value "+part);
p.waitForFinished();

if (p.exitCode() == 0)
result = p.readAll().trimmed();

return result;
}

QByteArray MultiImageWriteThread::getUUID(const QString part)
{
QByteArray result;
QProcess p;
p.start("/sbin/blkid -s UUID -o value "+part);
p.waitForFinished();

if (p.exitCode() == 0)
result = p.readAll().trimmed();

return result;
}

QString MultiImageWriteThread::getDescription(const QString &folder, const QString &flavour)
{
Expand Down Expand Up @@ -1065,35 +1046,3 @@ bool MultiImageWriteThread::isURL(const QString &s)
return s.startsWith("http:") || s.startsWith("https:");
}

QByteArray MultiImageWriteThread::getDiskId(const QString &device)
{
mbr_table mbr;

QFile f(device);
f.open(f.ReadOnly);
f.read((char *) &mbr, sizeof(mbr));
f.close();

quint32 diskid = qFromLittleEndian<quint32>(mbr.diskid);
return QByteArray::number(diskid, 16).rightJustified(8, '0');;
}

QByteArray MultiImageWriteThread::getPartUUID(const QString &devpart)
{
QByteArray r;

QRegExp partnrRx("([0-9]+)$");
if (partnrRx.indexIn(devpart) != -1)
{
QString drive = devpart.left(partnrRx.pos());
if (drive.endsWith("p"))
drive.chop(1);

r = "PARTUUID="+getDiskId(drive);
int partnr = partnrRx.cap(1).toInt();
QByteArray partnrstr = QByteArray::number(partnr, 16).rightJustified(2, '0');
r += '-'+partnrstr;
}

return r;
}
4 changes: 0 additions & 4 deletions recovery/multiimagewritethread.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ class MultiImageWriteThread : public QThread
bool partclone_restore(const QString &imagePath, const QString &device);
bool untar(const QString &tarball);
bool isLabelAvailable(const QByteArray &label);
QByteArray getLabel(const QString part);
QByteArray getUUID(const QString part);
void patchConfigTxt();
QString getDescription(const QString &folder, const QString &flavour);
bool writePartitionTable(const QString &drive, const QMap<int, PartitionInfo *> &partitionMap);
bool isURL(const QString &s);
QByteArray getDiskId(const QString &device);
QByteArray getPartUUID(const QString &devpart);


/* key: folder, value: flavour */
Expand Down
61 changes: 61 additions & 0 deletions recovery/util.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "util.h"
#include "mbr.h"
#include <sys/ioctl.h>
#include <stdint.h>
#include <unistd.h>
Expand All @@ -10,6 +11,7 @@
#include <QProcess>
#include <QDebug>
#include <QList>
#include <QtEndian>

/*
* Convenience functions
Expand Down Expand Up @@ -173,3 +175,62 @@ QByteArray sysclassblock(const QString &drivedev, int partnr)

return "/sys/class/block/"+ b;
}

QByteArray getLabel(const QString part)
{
QByteArray result;
QProcess p;
p.start("/sbin/blkid -s LABEL -o value "+part);
p.waitForFinished();

if (p.exitCode() == 0)
result = p.readAll().trimmed();

return result;
}

QByteArray getUUID(const QString part)
{
QByteArray result;
QProcess p;
p.start("/sbin/blkid -s UUID -o value "+part);
p.waitForFinished();

if (p.exitCode() == 0)
result = p.readAll().trimmed();

return result;
}

QByteArray getDiskId(const QString &device)
{
mbr_table mbr;

QFile f(device);
f.open(f.ReadOnly);
f.read((char *) &mbr, sizeof(mbr));
f.close();

quint32 diskid = qFromLittleEndian<quint32>(mbr.diskid);
return QByteArray::number(diskid, 16).rightJustified(8, '0');;
}

QByteArray getPartUUID(const QString &devpart)
{
QByteArray r;

QRegExp partnrRx("([0-9]+)$");
if (partnrRx.indexIn(devpart) != -1)
{
QString drive = devpart.left(partnrRx.pos());
if (drive.endsWith("p"))
drive.chop(1);

r = "PARTUUID="+getDiskId(drive);
int partnr = partnrRx.cap(1).toInt();
QByteArray partnrstr = QByteArray::number(partnr, 16).rightJustified(2, '0');
r += '-'+partnrstr;
}

return r;
}
6 changes: 6 additions & 0 deletions recovery/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ bool canBootOs(const QString& name, const QVariantMap& values);
void setRebootPartition(QByteArray partition);
QByteArray partdev(const QString &drivedev, int nr);
QByteArray sysclassblock(const QString &drivedev, int partnr = -1);

QByteArray getLabel(const QString part);
QByteArray getUUID(const QString part);
QByteArray getDiskId(const QString &device);
QByteArray getPartUUID(const QString &devpart);

#endif // UTIL_H