playdate: `run` command with `--device` flag gets stuck

As discussed in https://github.com/boozook/playdate/issues/314#issuecomment-2065686756

When I attempt to use cargo playdate run --device I can’t get past the device showing “sharing DATA segment as USB drive” and “Eject disk to reboot”.

My terminal says Running hello-world on a device and eventually exits but the device stays the same.

If I inspect the Games directory on the device while it’s still mounted, the game isn’t there. If I manually eject the device and then look for the game on it, it isn’t there either.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 46 (42 by maintainers)

Commits related to this issue

Most upvoted comments

Ah, yes I should have mentioned that. I have a bunch of USB devices/hubs connected to my machine, and previously the Playdate was connected two hubs deep.

Trying the new build, I see the expected behavior and trace/debug output for pdtool mount --wait and pdtool unmount --wait. I confirmed this new build works with the PD connected directly, 1, 2, and 3 hubs deep. Thanks very much for getting this figured out and fixed so quickly!

I’m sure the last issue I posted about here was due to the wrong/old build of cargo-playdate hanging around in my Nix dev shell.

It happened again when I was working on the Lua API PR and had pulled in some changes from the main branch. I’m not yet sure why it happens when I do that but I was able to identify it and make sure I was using the correct build.

All of that to say, this issue remains fixed for me at the moment.

Thanks guys, appreciate the prompt and thorough responses.

» cargo-playdate --version
cargo 0.4.10

When running pdtool mount --wait, the connected Playdate enters data disk mode very quickly. My shell sits waiting for a minute or so, eventually timing out with [ERROR pdtool] Awaiting device timeout `PDU1-YMYSERIAL(S)`.. The Playdate is visible in Finder as expected during/after.

Works great here. Not sure what happened. Thanks again.

I tried main at 5f03a23ea8904799c7b26d1d371d74443ec38195 and this issue appears to be fixed. Thanks!

I ran CARGO_PLAYDATE_LOG=trace cargo playdate run --device and looked at the code that calls system_profiler so have a better understanding of what that’s trying to do now.

...
[DEBUG playdate_device::mount::methods] retries: 500 * 100ms ≈ 50s.
[TRACE polling] Poller::notify()
[TRACE polling::kqueue] notify: kqueue_fd=10
[TRACE polling::kqueue] new events: kqueue_fd=10, res=1
[TRACE async_io::reactor] process_timers: 0 ready wakers
[TRACE async_io::reactor] react: 0 ready wakers
[TRACE async_io::driver] main_loop: waiting on I/O
[TRACE async_io::reactor] process_timers: 0 ready wakers
[TRACE polling] Poller::wait(_, Some(99.978791ms))
[TRACE polling::kqueue] wait: kqueue_fd=10, timeout=Some(99.978791ms)
[TRACE polling::kqueue] new events: kqueue_fd=10, res=0
[TRACE async_io::reactor] process_timers: 1 ready wakers
[TRACE async_io::reactor] react: 1 ready wakers
[TRACE async_io::driver] main_loop: waiting on I/O
[TRACE async_io::reactor] process_timers: 0 ready wakers
[TRACE polling] Poller::wait(_, None)
[TRACE polling::kqueue] wait: kqueue_fd=10, timeout=None
[TRACE playdate_device::mount::methods] waiting mount point availability: XXXX-XXXXXXX, current: S, try: 1/500
[DEBUG playdate_device::mount::methods] ERROR: missing field `serial_num` at line 31 column 9
[DEBUG playdate_device::mount::methods] mount point still not found, waiting...
...

I think ERROR: missing field `serial_num` at line 31 column 9 must be the issue but it’s there in the JSON and appears in the output after waiting mount point availability

Okay, now I know that you’re on no latest macOS, probably on 12.x.x, because somewhere between 12 and 14 was “little improvement” in the output of system_profiler, so now it always returns SN if possible. Okay, if I right and that is it, I’ll fix it.

I’ve been putting off upgrading just because I didn’t want to deal with any churn that might come with it 😄

I’m on 12.2.1

Could you try please following things from nix environment for debug purposes?

Will do, thanks!

Thank you. Done, merged, published.

» RUST_LOG=trace CARGO_PLAYDATE_LOG=trace system_profiler -json SPUSBDataType

A bunch of output removed for brevity/privacy:

{
  "SPUSBDataType" : [
    {
      "_items" : [
        {
          "_items" : [
            {
              "_name" : "Playdate",
              "bcd_device" : "2.00",
              "bus_power" : "500",
              "bus_power_used" : "100",
              "device_speed" : "full_speed",
              "extra_current_used" : "0",
              "location_id" : "0x05310000 / 24",
              "manufacturer" : "Panic Inc",
              "Media" : [
                {
                  "_name" : "Playdate",
                  "bsd_name" : "disk24",
                  "Logical Unit" : 0,
                  "partition_map_type" : "master_boot_record_partition_map_type",
                  "removable_media" : "yes",
                  "size" : "3.66 GB",
                  "size_in_bytes" : 3662675968,
                  "smart_status" : "Verified",
                  "USB Interface" : 0,
                  "volumes" : [
                    {
                      "_name" : "PLAYDATE",
                      "bsd_name" : "disk24s1",
                      "file_system" : "MS-DOS FAT32",
                      "free_space" : "2.13 GB",
                      "free_space_in_bytes" : 2133676032,
                      "iocontent" : "Windows_FAT_32",
                      "mount_point" : "/Volumes/PLAYDATE",
                      "size" : "3.66 GB",
                      "size_in_bytes" : 3662675456,
                      "volume_uuid" : "83B4406D-",
                      "writable" : "yes"
                    }
                  ]
                }
              ],
              "product_id" : "0x5741",
              "serial_num" : "PDU1-Y0xxxxx",
              "vendor_id" : "0x1331"
            }
          ],
          "_name" : "4-Port USB 2.0 Hub",
          "bcd_device" : "1.36",
          "bus_power" : "500",
          "bus_power_used" : "0",
          "device_speed" : "high_speed",
          "extra_current_used" : "0",
          "location_id" : "0x05300000 / 3",
          "manufacturer" : "Generic",
          "product_id" : "0x5411",
          "vendor_id" : "0x0bda  (Realtek Semiconductor Corp.)"
        },
      ],
      "_name" : "USB31Bus",
      "host_controller" : "AppleASMediaUSBXHCI",
      "pci_device" : "0x1242 ",
      "pci_revision" : "0x0000 ",
      "pci_vendor" : "0x1b21 "
    },
  ]
}%

Running the second command errors with jq: error (at <stdin>:313): Cannot iterate over null (null). This adjusted command gives the expected UUID: system_profiler -json SPUSBDataType | jq '.SPUSBDataType[] | ._items[]? | ._items[]?.Media[]?.volumes[]? | select(._name=="PLAYDATE") | .volume_uuid' -r

@paulstraw I suppose its about changed format of system_profiler.

To get exactly what’s wrong I recommend do two steps.

But first of all set RUST_LOG and CARGO_PLAYDATE_LOG env vars to "trace.

Well, first step is to mount device somehow (use pdutil, pdtool or by hand) and then run following command and show me the output (I need just structure with names of fields and to know that value is empty or not)

system_profiler -json SPUSBDataType

Second is similar, but imitate used fallback method to determine mount-point:

# requires jq
export PD_VOLUME_UUID=$(system_profiler -json SPUSBDataType | jq '.SPUSBDataType.[] | select(._items) | ._items.[].Media.[].volumes.[] | select(._name=="PLAYDATE") | .volume_uuid' -r) && \
diskutil info -plist $PD_VOLUME_UUID

(same as above)

This way we can understand whether the problem is in the output format or not.

I’m also hitting the issue originally described here. My env:

  • macOS 14.4.1, Apple Silicon
  • playdate 0.2.0 specified in Cargo.lock
  • rustc 1.80.0-nightly (faefc618c 2024-05-07)

I tried again from main and it works as expected. I’ll try dev/debug-326 just to be sure.

Reopening due to https://github.com/boozook/playdate/pull/327#issuecomment-2087818912

Strange, I’m running into #326 on this branch despite having pulled in the fixes for that issue.

I traced the value passed to Volume::from here and got a different result this time:

[TRACE playdate_device::mount::volume] existing, by name: /Volumes/PLAYDATE
[TRACE playdate_device::mount::volume] *************** "/Volumes/PLAYDATE"
[DEBUG playdate_device::mount::methods] XXXX-XXXXXXX mounted, volume found: '/Volumes/PLAYDATE'

https://github.com/boozook/playdate/blob/de8d14cf9b1e689bfed610d9dff60cf0bc452e74/support/device/src/mount/mac.rs#L101

The game installed and ran on my device. I reverted the change and it still works. I’m not sure what happened before that when I got volume found ''

I omitted a lot of fields for brevity and changed the names of things between angle brackets for privacy and security. I also redacted the serial number.

{
  "SPUSBDataType" : [
    {
      "_items" : [
        {
          "_items" : [
            {
              "_name" : "USB3.1 Hub             "
            }
          ],
          "_name" : "USB3.0 Hub"
        },
        {
          "_items" : [
            {
              "_name" : "<kvm hub>"
            },
            {
              "_items" : [
                {
                  "_name" : "<keyboard 1>"
                },
                {
                  "_name" : "<keyboard 2>"
                },
                {
                  "_name" : "<trackpad>"
                }
              ],
              "_name" : "USB2.0 Hub             "
            }
          ],
          "_name" : "USB2.0 Hub"
        }
      ],
      "_name" : "USB31Bus"
    },
    {
      "_name" : "USB31Bus"
    },
    {
      "_name" : "USB31Bus"
    },
    {
      "_items" : [
        {
          "_items" : [
            {
              "_name" : "<webcam>"
            }
          ],
          "_name" : "hub_device"
        },
        {
          "_name" : "Playdate",
          "bcd_device" : "2.00",
          "bus_power" : "500",
          "bus_power_used" : "100",
          "device_speed" : "full_speed",
          "extra_current_used" : "0",
          "location_id" : "0x03200000 / 6",
          "manufacturer" : "Panic Inc",
          "product_id" : "0x5740",
          "serial_num" : "XXXX-XXXXXXX",
          "vendor_id" : "0x1331"
        },
        {
          "_items" : [
            {
              "_name" : "USB Controls"
            }
          ],
          "_name" : "hub_device"
        }
      ],
      "_name" : "USB31Bus"
    }
  ]
}

If you see seven, I suppose that last digit is 1 and it’s a number of port (USB telmodem device can have multiple ports)

That appears to be the case, sorry for the confusion.

I’m not sure how works isolation in nix. Is it containerisation?

It’s not, at least not in this case, and I’m using Nix on macOS FWIW.

In this instance I’m using it as a convenient way to set up a developer shell environment, which basically just puts various things on the PATH

Or maybe OS didn’t mounted your device as drive, so that is bigger problem then 1.

The device is definitely mounted as a drive; I can explore it and need to eject the disk.