Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add USB Ethernet Gadget toggle #933

Open
wants to merge 12 commits into
base: qml
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ if (WIN32)
add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} ${DEPENDENCIES}
extraFiles.qrc)
else()
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${DEPENDENCIES})
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${DEPENDENCIES}
extraFiles.qrc)
endif()

set_property(TARGET ${PROJECT_NAME} PROPERTY AUTOMOC ON)
Expand Down
45 changes: 19 additions & 26 deletions src/OptionsPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Window {
property string cloudinitrun
property string cloudinitwrite
property string cloudinitnetwork
property bool deviceUsbOtgSupport
property bool enableEtherGadget

signal saveSettingsSignal(var settings)
Expand Down Expand Up @@ -359,6 +360,7 @@ Window {
ImCheckBox {
id: chkUSBEther
text: qsTr("Enable USB Ethernet Gadget")
enabled: deviceUsbOtgSupport
}

ImCheckBox {
Expand Down Expand Up @@ -635,6 +637,18 @@ Window {
}
}

var hwFilterList = imageWriter.getHWFilterList()
var hwFilterIsModelZero = imageWriter.getHWFilterIsModelZero()

if (hwFilterList) {
var targetTags = ["pi5-64bit", "pi4-64bit", "pi5-32bit", "pi4-32bit"]
paulober marked this conversation as resolved.
Show resolved Hide resolved
deviceUsbOtgSupport = targetTags.some(tag => hwFilterList.includes(tag)) || hwFilterIsModelZero
if (!deviceUsbOtgSupport) {
// make sure it isn't disabled and selected
chkUSBEther = false;
}
}

//open()
show()
raise()
Expand Down Expand Up @@ -834,35 +848,14 @@ Window {
}
if (chkUSBEther.checked) {
addConfig("dtoverlay=dwc2,dr_mode=peripheral")
// only required if no conf is used to load modules
// g_ether must not be loaded when using manual config
// with sh script
addCmdline("modules-load=dwc2,g_ether")
// TODO: generate mac addresses if there are issues with DHCP
//addCmdline("g_ether.dev_addr=8A:89:6a:8d:14:22")
//addCmdline("g_ether.host_addr=6A:89:6a:8d:14:22")
addCmdline("g_ether.idVendor=0x04b3")
addCmdline("g_ether.idProduct=0x4010")
addCmdline("g_ether.iManufacturer=\"Raspberry Pi\"")
addCmdline("g_ether.bcdDevice=0x0100")
addCmdline("g_ether.iProduct=\"USB Ethernet Gadget\"")
// TODO: maybe set device serial
//addCmdline("g_ether.iSerialNumber=8c1aceb07269b131")

enableEtherGadget = true;

// manual config with this script requires not to load g_ether
//addFirstRun("mv /boot/firmware/etherSet.sh /usr/sbin/configure-usb-ether-gadget-once")
//addFirstRun("chmod +x /usr/sbin/configure-usb-ether-gadget-once")
//addFirstRun("mv /boot/firmware/sysdEth.srv /etc/systemd/system/usb-ether-gadget-once.service")
//addFirstRun("mkdir -p /etc/systemd/system/usb-gadget.target.wants")
//addFirstRun("ln -s /etc/systemd/system/usb-ether-gadget-once.service /etc/systemd/system/usb-gadget.target.wants/usb-ether-gadget-once.service")
addFirstRun("mv /boot/firmware/10usb.net /etc/systemd/network/10-usb.network\n")
// enable stuff
//addFirstRun("systemctl daemon-reload")
//addFirstRun("systemctl enable usb-ether-gadget-once.service")
//addFirstRun("systemctl start usb-ether-gadget-once.service\n")
// enable networkd as I don't have NetworkManager config
addFirstRun("\nmv /boot/firmware/10usb.net /etc/systemd/network/10-usb.network")
addFirstRun("mv /boot/firmware/geth.cnf /etc/modprobe.d/g_ether.conf")
addFirstRun("mv /boot/firmware/gemod.cnf /etc/modules-load.d/usb-ether-gadget.conf\n")
addFirstRun("SERIAL=$(grep Serial /proc/cpuinfo | awk '{print $3}')")
addFirstRun("sed -i \"s/<serial>/$SERIAL/g\" /etc/modprobe.d/g_ether.conf")
addFirstRun("systemctl enable systemd-networkd\n")
}

Expand Down
18 changes: 9 additions & 9 deletions src/downloadthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,19 +979,19 @@ bool DownloadThread::_customizeImage()
// load files from disk and write
QByteArray networkConfig = _fileGetContentsTrimmed("://extraFiles/10-usb.network");
fat->writeFile("10usb.net", networkConfig);
// little optimization for memory constraint systems - add if more files are loaded in this scope
//networkConfig.clear();
// little optimization for memory constraint systems
paulober marked this conversation as resolved.
Show resolved Hide resolved
networkConfig.clear();

// only needed for manual config without g_ether
paulober marked this conversation as resolved.
Show resolved Hide resolved
//QByteArray script = _fileGetContentsTrimmed("://extraFiles/configure-usb-ether-gadget-once.sh");
//fat->writeFile("etherSet.sh", script);
// little optimization for memory constraint systems - add if more files are loaded in this scope
//script.clear();
QByteArray modprobeConf = _fileGetContentsTrimmed("://extraFiles/g_ether.conf");
fat->writeFile("geth.cnf", modprobeConf);
// little optimization for memory constraint systems
modprobeConf.clear();

//QByteArray serviceFile = _fileGetContentsTrimmed("://extraFiles/usb-ether-gadget-once.service");
//fat->writeFile("sysdEth.srv", serviceFile);
QByteArray modulesConf = _fileGetContentsTrimmed("://extraFiles/usb-ether-gadget.conf");
fat->writeFile("gemod.cnf", modulesConf);
// not needed anymore, because auto cleanup after out of scope
//serviceFile.clear();
//modulesConf.clear();
}

if (!_cloudinit.isEmpty() && _initFormat == "cloudinit")
Expand Down
4 changes: 2 additions & 2 deletions src/extraFiles.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<RCC>
<qresource prefix="/">
<file>extraFiles/10-usb.network</file>
<file>extraFiles/configure-usb-ether-gadget-once.sh</file>
<file>extraFiles/usb-ether-gadget-once.service</file>
<file>extraFiles/g_ether.conf</file>
<file>extraFiles/usb-ether-gadget.conf</file>
</qresource>
</RCC>
115 changes: 0 additions & 115 deletions src/extraFiles/configure-usb-ether-gadget-once.sh
paulober marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

1 change: 1 addition & 0 deletions src/extraFiles/g_ether.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
options g_ether idVendor=0x04b3 idProduct=0x4010 iManufacturer="Raspberry Pi" bcdDevice=0x0100 iProduct="USB Ethernet Gadget" iSerialNumber=<serial>
paulober marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 0 additions & 17 deletions src/extraFiles/usb-ether-gadget-once.service

This file was deleted.

2 changes: 2 additions & 0 deletions src/extraFiles/usb-ether-gadget.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dwc2
g_ether
15 changes: 14 additions & 1 deletion src/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,23 @@ namespace {
} // namespace anonymous


void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive) {
void ImageWriter::setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero) {
QJsonDocument json_document = QJsonDocument::fromJson(json);
_deviceFilter = json_document.array();
_deviceFilterIsInclusive = inclusive;
_isModelZero = isModelZero;
}

QJsonArray ImageWriter::getHWFilterList() {
return _deviceFilter;
}

bool ImageWriter::getHWFilterListInclusive() {
return _deviceFilterIsInclusive;
}

bool ImageWriter::getHWFilterIsModelZero() {
return _isModelZero;
}

void ImageWriter::handleNetworkRequestFinished(QNetworkReply *data) {
Expand Down
17 changes: 14 additions & 3 deletions src/imagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ class ImageWriter : public QObject
Q_INVOKABLE void beginOSListFetch();

/** Set the HW filter, for a filtered view of the OS list */
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive);
Q_INVOKABLE void setHWFilterList(const QByteArray &json, const bool &inclusive, const bool &isModelZero);

/* Get the HW filter list */
Q_INVOKABLE QJsonArray getHWFilterList();

/* Get if the HW filter is in inclusive mode */
Q_INVOKABLE bool getHWFilterListInclusive();

/* Get if HW filter tags are from a Pi Zero model */
Q_INVOKABLE bool getHWFilterIsModelZero();

/* Set custom cache file */
void setCustomCacheFile(const QString &cacheFile, const QByteArray &sha256);
Expand Down Expand Up @@ -122,8 +131,8 @@ class ImageWriter : public QObject
Q_INVOKABLE QString getPSK();

Q_INVOKABLE bool getBoolSetting(const QString &key);
Q_INVOKABLE void setSetting(const QString &key, const QVariant &value);//, const QVariantList
Q_INVOKABLE void setImageCustomization(const QByteArray &config, const QByteArray &cmdline, const QByteArray &firstrun, const QByteArray &cloudinit, const QByteArray &cloudinitNetwork, const bool enableEtherGadget);
Q_INVOKABLE void setSetting(const QString &key, const QVariant &value);
Q_INVOKABLE void setImageCustomization(const QByteArray &config, const QByteArray &cmdline, const QByteArray &firstrun, const QByteArray &cloudinit, const QByteArray &cloudinitNetwork, const bool enableEtherGadget);
Q_INVOKABLE void setSavedCustomizationSettings(const QVariantMap &map);
Q_INVOKABLE QVariantMap getSavedCustomizationSettings();
Q_INVOKABLE void clearSavedCustomizationSettings();
Expand Down Expand Up @@ -186,6 +195,8 @@ protected slots:
QJsonDocument _completeOsList;
QJsonArray _deviceFilter;
bool _deviceFilterIsInclusive;
/* As there is no distinction between normal pi models and zeros (in the tags), this flag can be used to differenciate */
paulober marked this conversation as resolved.
Show resolved Hide resolved
bool _isModelZero;

protected:
QUrl _src, _repo;
Expand Down
2 changes: 1 addition & 1 deletion src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ ApplicationWindow {
}
}

imageWriter.setHWFilterList(hwmodel.tags, inclusive)
imageWriter.setHWFilterList(hwmodel.tags, inclusive, hwmodel.name.toLowerCase().includes("zero"))
paulober marked this conversation as resolved.
Show resolved Hide resolved

/* Reload list */
var oslist_json = imageWriter.getFilteredOSlist();
Expand Down