Skip to content

modprobe g_ether on enable; skip reboot if overlay already active - #21

Open
XECDesign wants to merge 1 commit into
raspberrypi:pios/trixiefrom
XECDesign:noreboot
Open

modprobe g_ether on enable; skip reboot if overlay already active#21
XECDesign wants to merge 1 commit into
raspberrypi:pios/trixiefrom
XECDesign:noreboot

Conversation

@XECDesign

Copy link
Copy Markdown

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.

@paulober

Copy link
Copy Markdown
Collaborator

Hi @XECDesign, sounds like a good addition. Thanks for the PR.
I found minor issues.

Comment thread rpi-usb-gadget
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread rpi-usb-gadget
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)" ]; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants