modprobe g_ether on enable; skip reboot if overlay already active - #21
Open
XECDesign wants to merge 1 commit into
Open
modprobe g_ether on enable; skip reboot if overlay already active#21XECDesign wants to merge 1 commit into
XECDesign wants to merge 1 commit into
Conversation
…ay already active
Collaborator
|
Hi @XECDesign, sounds like a good addition. Thanks for the PR. |
paulober
requested changes
Aug 30, 2026
Comment on lines
+331
to
340
| if ! cfg_has_overlay; then | ||
| # ensure overlay present once | ||
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_FW" 2>/dev/null || true | ||
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_LEGACY" 2>/dev/null || true | ||
| printf '%s\n' "$OVERLAY_LINE" >> "$CFG_FW" 2>/dev/null || printf '%s\n' "$OVERLAY_LINE" >> "$CFG_LEGACY" | ||
| if ! overlay_active; then | ||
| NEED_REBOOT=true | ||
| fi | ||
| fi | ||
|
|
Collaborator
There was a problem hiding this comment.
Suggested change
| if ! cfg_has_overlay; then | |
| # ensure overlay present once | |
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_FW" 2>/dev/null || true | |
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_LEGACY" 2>/dev/null || true | |
| printf '%s\n' "$OVERLAY_LINE" >> "$CFG_FW" 2>/dev/null || printf '%s\n' "$OVERLAY_LINE" >> "$CFG_LEGACY" | |
| if ! overlay_active; then | |
| NEED_REBOOT=true | |
| fi | |
| fi | |
| if ! cfg_has_overlay; then | |
| # ensure overlay present once | |
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_FW" 2>/dev/null || true | |
| sed -i "\|^$OVERLAY_LINE\$|d" "$CFG_LEGACY" 2>/dev/null || true | |
| printf '%s\n' "$OVERLAY_LINE" >> "$CFG_FW" 2>/dev/null || printf '%s\n' "$OVERLAY_LINE" >> "$CFG_LEGACY" | |
| fi | |
| if ! overlay_active; then | |
| NEED_REBOOT=true | |
| fi |
If the module is already in the config but the Pi didn't restart yet the overlay_active will be false but since the check is in the conditional block NEED_REBOOT will not be set.
| have_systemctl() { command -v systemctl >/dev/null 2>&1; } | ||
|
|
||
| # /sys/class/udc is populated when a UDC driver (dwc2 in peripheral mode) is active | ||
| overlay_active() { [ -n "$(ls /sys/class/udc/ 2>/dev/null)" ]; } |
Collaborator
There was a problem hiding this comment.
Suggested change
| overlay_active() { [ -n "$(ls /sys/class/udc/ 2>/dev/null)" ]; } | |
| overlay_active() { [ "$(ls -A /sys/class/udc 2>/dev/null)" ]; } |
If I remember correctly this approach can be prone to shell special features and we might want to go more POSIX compliant here. What do you think?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since config.txt could be modified in advance before the device is started, the gadget could be enabled without requiring a reboot.
When used with rpi-power-hat this speeds things up a lot.