8000 Say which boards can be a USB device when none is found by adeelahmad · Pull Request #34 · adeelahmad/gadgetcast · GitHub
[go: up one dir, main page]

Skip to content
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
8000
6 changes: 4 additions & 2 deletions internal/gadget/gadget.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ func Down(x Executor, root string, s Spec) error {

// FindUDC returns the first USB device controller in dir (normally
// /sys/class/udc). It is empty when the Pi's USB port is not in peripheral
// mode, which means dtoverlay=dwc2,dr_mode=peripheral is missing.
// mode: dtoverlay=dwc2,dr_mode=peripheral is missing, or the board has no
// device-capable port (Pi 1 B, 2 B, 3 B, 3 B+).
func FindUDC(dir string) (string, error) {
entries, err := os.ReadDir(dir)
if err != nil && !errors.Is(err, os.ErrNotExist) {
Expand All @@ -286,7 +287,8 @@ func FindUDC(dir string) (string, error) {
}
sort.Strings(names)
if len(names) == 0 {
return "", errors.New("gadget: no USB device controller found; enable dtoverlay=dwc2,dr_mode=peripheral and reboot")
return "", errors.New("gadget: no USB device controller found. Check that config.txt has dtoverlay=dwc2,dr_mode=peripheral under [all] and reboot. " +
"Only some boards can be a USB device: Pi Zero, Zero W and Zero 2 W (the USB data port, not PWR), Pi 4 and 5 (the USB-C port), and Pi A+/3 A+; Pi 1 B, 2 B, 3 B and 3 B+ cannot")
}
return names[0], nil
}
4 changes: 3 additions & 1 deletion internal/gadget/gadget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ func TestOSSymlinkWritesAbsoluteTarget(t *testing.T) {

func TestFindUDC(t *testing.T) {
dir := t.TempDir()
if _, err := FindUDC(dir); err == nil || !strings.Contains(err.Error(), "dr_mode=peripheral") {
// The overlay alone is not enough: Pi 1 B, 2 B, 3 B and 3 B+ have no
// device-capable port, so the message must name the boards that do.
if _, err := FindUDC(dir); err == nil || !strings.Contains(err.Error(), "dr_mode=peripheral") || !strings.Contains(err.Error(), "Zero") {
t.Fat 5209 alf("empty dir: err = %v", err)
}
if _, err := FindUDC(filepath.Join(dir, "missing")); err == nil {
Expand Down
Loading
0