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

Freeze qemu-pebble on pebble-sdk-4.2.1-mac, QEMU waiting for connection on: disconnected:tcp::54035,server #45

Open
iSevenDays opened this issue May 27, 2016 · 8 comments

Comments

@iSevenDays
Copy link

iSevenDays commented May 27, 2016

I've enabled debug logging

sevens:watchface seven$ sudo pebble install --emulator aplite
Password:
INFO:pebble_tool.sdk.emulator:Spawning QEMU.
INFO:pebble_tool.sdk.emulator:Qemu command: qemu-pebble -rtc base=localtime -serial null -serial tcp::54034,server,nowait -serial tcp::54035,server -pflash "/Users/seven/Library/Application Support/Pebble SDK/SDKs/3.12/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin" -gdb tcp::54036,server,nowait -machine pebble-bb2 -cpu cortex-m3 -mtdblock "/Users/seven/Library/Application Support/Pebble SDK/3.12/aplite/qemu_spi_flash.bin"
INFO:pebble_tool.sdk.emulator:Waiting for the firmware to boot.
WARNING: Image format was not specified for '/Users/seven/Library/Application Support/Pebble SDK/SDKs/3.12/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for '/Users/seven/Library/Application Support/Pebble SDK/3.12/aplite/qemu_spi_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
QEMU waiting for connection on: disconnected:tcp::54035,server
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
DEBUG:pebble_tool.sdk.emulator:QEMU not ready yet.
Emulator launch timed out.

Then I found the root of the problem

sevens:~ seven$ qemu-pebble -rtc base=localtime -serial null -serial tcp::54034,server,nowait -pflash "/Users/seven/Library/Application Support/Pebble SDK/SDKs/3.12/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin" -gdb tcp::54036,server,nowait -machine pebble-bb2 -cpu cortex-m3 -mtdblock "/Users/seven/Library/Application Support/Pebble SDK/3.12/aplite/qemu_spi_flash.bin"
WARNING: Image format was not specified for '/Users/seven/Library/Application Support/Pebble SDK/SDKs/3.12/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for '/Users/seven/Library/Application Support/Pebble SDK/3.12/aplite/qemu_spi_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

I removed the line -serial tcp::54035,server

And then I saw "Pebble", "Install an app to continue...etc"

Tested on Mac OS El Capitan 10.11.5

@chesterbr
Copy link

Same thing happening to me, on Mac OS 10.11.16, after I upgraded the SDK.

My output upon the crash was:

$ qemu-pebble -rtc base=localtime -serial null -serial tcp::64061,server,nowait -serial tcp::64062,server -pflash "/Users/chester/Library/Application Support/Pebble SDK/SDKs/4.0.1/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin" -gdb tcp::64063,server,nowait -machine pebble-bb2 -cpu cortex-m3 -mtdblock "/Users/chester/Library/Application Support/Pebble SDK/4.0.1/aplite/qemu_spi_flash.bin"
WARNING: Image format was not specified for '/Users/chester/Library/Application Support/Pebble SDK/SDKs/4.0.1/sdk-core/pebble/aplite/qemu/qemu_micro_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for '/Users/chester/Library/Application Support/Pebble SDK/4.0.1/aplite/qemu_spi_flash.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
QEMU waiting for connection on: disconnected:tcp::64062,server

and I removed the -serial tcp::64062,server to work., getting to the "Install an app" just like @iSevenDays. But can't really do anything from that point (maybe pebble install requires that port to be listening?)

Is there any fix for this? Thank you!

@chesterbr
Copy link

@iSevenDays Found the issue and how to fix it! Hope it is your case as well.

TL;DR: Add this line to/etc/hosts/:

127.0.0.1       localhost

Details:

A while ago, @Katharine kindly explained me on the Pebble slack that the client tool indeed starts qemu with that parameter (which will map a TCP port to an emulated serial one and wait for a connection), then waits until it can connect to such port in order to continue - or, in our case, fails to connect and gives up.

So I tried to manually connect to the port with telnet localhost 64062 (using the port chosen by that invocation instead of 64062), hitting the same wall as the tool. But that made me notice an interesting thing: telnet was not trying 127.0.0.1:

$ telnet localhost 50822
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 159.203.57.211...
telnet: connect to address 159.203.57.211: Connection refused
telnet: Unable to connect to remote host
$

So I tried telnet 127.0.0.1 64062 and bam: I got output and the emulator booted fine (just like it did when you removed the -serial altogether or added ,nowait to it), which led to the real problem: my /etc/hosts was missing the entry that translates localhost to 127.0.0.1.

Once you add it, the likes of pebble install --emulator aplite work just fine.

@Katharine
Copy link
Contributor

Indeed, the actual sequence of events here is that everything waits on everything else to avoid an assortment of race conditions:

  1. The pebble tool spawns QEMU with two "serial"-over-TCP ports — one for Pebble QEMU Protocol (you can read more here) and one for the serial port that exists on physical Pebble bigboards.
  2. The pebble tool blocks until it can connect to the second serial port.
  3. QEMU blocks until something connects on the second serial port. This prevents the ready message being sent before anything is waiting.
  4. The pebble tool connects to the second serial port and blocks until it receives a "ready" message over that port. This ensures we don't send messages to the firmware before it is ready.
  5. Upon receiving the message, the pebble tool connects to the Pebble QEMU Protocol port.
  6. Whatever action was actually requested (e.g. installing an app) is performed.

I am somewhat surprised that localhost not doing anything useful on IPv4 doesn't break more. I wonder if we should change all references to localhost to instead be 127.0.0.1 to avoid this, though.

@chesterbr
Copy link

I see, thanks for the details! I am also surprised that nothing else (on the surface) broke on my system. Despite all that, I'd consider that:

  • Using 127.0.0.1 could make IPv6 support harder in the future (or even cause likewise issues for IPv6-exclusive users - once that becomes a thing)
  • I'd think most devs would rather fix such a problem than live with an unknown configuration failure. I'm surprised that things like nginx or MySQL didn't (ostensibly) break (the later is quite picky on the localhost x 127.0.0.1 distinction)
  • This issue is the first thing that pops out on a search for "frozen Emulator launch timed out pebble sdk".

This all would make me leave it as is. Whatever you decide, thank you and the Pebble team once again for the great level of dev support (in particular for such an edge case)!

@xcsrz
Copy link

xcsrz commented Nov 10, 2016

I encountered the same issue, or at least the same symptoms. However the /etc/hosts solution was not a cure me. I'm not sure, but I did realize that the issue arose for me after attempting to use the gdb option.

In any case, if anyone else stumbles in here with a similar issue:

After a lot of google and poking around I found the issue (at least the one I encountered) can be solved by either of the following:

cd ~/Library/Application\ Support && mv Pebble\ SDK Pebble\ SDK.bak

or

pebble wipe

After the first, executing pebble install --emulator basalt will

  • trigger another round of agreeing to TOS
  • redownloading the basalt image

Either should result in a properly (again) working emulator.

@bjorndm
Copy link

bjorndm commented Dec 5, 2016

I am also experiencing the same problem. Neither the /etc/host nor re-downloading the image work for me. I am working on Ubuntu 14.04LTS with tools version 4.5 and sdk 4.3. I can connect to the qemu ports manually but no joys trough the pebble command. Perhaps my python set up is a bit screwy? Any information I can provide to help debug this?
EDIT: it's the aplite emulator that apparently doesn't work for me, the basalt one is fine.

@gamepad-coder
Copy link

gamepad-coder commented Mar 14, 2021

Solution

Solved:
By complete removal of ~/pebble-dev/pebble-sdk-4.5-linux64/ AND ~/.pebble-sdk/. Then a manual reinstall of pebble-sdk-4.5-linux64.tar.bz2 (with the tweaked step of using a Python virtual environment to ensure Python2.7 is used when running the command pebble install --emulator basalt; if you're unfamiliar with how to do this, I've included detailed step-by-step instructions below).

Hopefully this helps someone running into the same problem. I wasn't able to find this solution anywhere online, so I decided to post it here.

System Environment:

  • Using Windows 10, 64-bit.
  • Using Bash on Debian inside WSL2
  • Manually installing Pebble SDK using this recipe on rebble.io
    https://developer.rebble.io/developer.pebble.com/sdk/install/linux/index.html
    (full steps+ minor tweaks below)
  • Not using Brew.
  • Note regarding scope:
    This is potentially out of context for this repository, since I did not install the Pebble SDK using brew. However, as of March 2021, this is the only website URL listed when you search Google for the phrase:
    "pebble" "QEMU waiting for connection on: disconnected:tcp"

Half a year ago, my pebble development environment was working fine, but I've since rewired my Python variables. Other than that I'm unsure what caused the Pebble Qemu emulator to start malfunctioning, but now I know what steps will make it work again on my setup (your mileage may vary, but fingers crossed).

 

Failed Troubleshooting:

I tried multiple reinstalls (with minor steps changed), but had totally forgotten that ~/.pebble-sdk/ existed. Leaving this directory unaltered was the root of my problem.

I began by trying solutions mentioned above in this issue, but:

  • My localhost was already properly configured in /etc/hosts/.
  • None of the emulators would load for me.
    Any attempt to run a successfully built pebble project in an emulator resulted in the same error messages as the opening post for this issue (regardless of emulator chosen).
    Commands examples:
  • I tried going into ~/pebble-dev/pebble-sdk-4.5-linux64/pebble- tool/pebble_tool/sdk/emulator.py and commenting out the line in function
    def _spawn_qemu(self):
        [line 195] "-serial", "tcp:: {},server".format(self.qemu_serial_port),
    but this did not make the emulator launch.
  • I ran the emulator command pebble wipe to reset the emulator. Calls to pebble install --emulator basalt still resulted in a hang/freeze and no emulator window appeared.
  • I tried using this alternative install method, but the emulator still failed to launch:
    https://gist.github.com/zeevro/ce20d0d74a869d73119e9d1522b7caa7

None of these changes were needed for the solution which worked for me (except possibly localhost's config in /etc/hosts). The above list is just additional info/trivia for those troubleshooting.

 

Successful Troubleshooting:

The emulator immediately worked when I manually reinstalled the Pebble SDK, but removed ~/.pebble-sdk/ first before going through the recipe here: https://developer.rebble.io/developer.pebble.com/sdk/install/linux/index.html (with minor tweaks, full steps next section).

 

How to Reinstall Pebble SDK on Linux

This is a modified combination of the following recipes:

Steps:

  1. Back up or remove existing pebble dev files:
    1. Rename or remove ~/.pebble-sdk/
    2. Rename or remove ~/pebble-dev/pebble-sdk-4.5-linux64/
  2. Download the Pebble SDK here:
    https://developer.rebble.io/developer.pebble.com/sdk/install/linux/index.html
  3. Place pebble-sdk-4.5-linux64.tar.bz2 in the directory ~/pebble-dev/
  4. Run the commands:
    1. cd ~/pebble-dev/
    2. tar -xf pebble-sdk-4.5-linux64.tar.bz2 and wait for it to be extracted
  5. If you have not already done so, add the pebble executable commands to your PATH environment variable with:
    1. echo 'export PATH=~/pebble-dev/pebble-sdk-4.5-linux64/bin:$PATH' >> ~/.bash_profile
      This will make the pebble commands available in future bash terminal sessions.
    2. . ~/.bash_profile
      This will immediately make the pebble commands available in your current bash terminal session.
  6. Install Python2.7 Dependencies:
    1. Install Python2.7 and Python2.7-pip with:
      sudo apt-get install python2.7 python2.7-dev python2.7-pip
    2. Install Python's Virtual Environment with:
      sudo -H python2.7 -m pip install -U pip setuptools wheel virtualenv
      (note: Be sure to run using python2.7 -m pip instead of just pip. This will ensure you're using Python2.7's version of pip instead of Python3.)
  7. Install Emulator Dependencies:
    1. sudo apt-get install libsdl1.2debian libfdt1 libpixman-1-0
  8. Install Node.js and npm:
    1. sudo apt install -y libssl1.0-dev nodejs-dev npm
      (Unsure if this is necessary, but the popular install method from the above Reddit link recommends it)
  9. Install the latest version of pebble-tool/ to ~/pebble-dev/pebble-sdk-4.5-linux64/pebble-tool/
    1. cd ~/pebble-dev/pebble-sdk-4.5-linux64/
    2. Copy paste the following into bash, then hit enter.
      # Replace pebble-tool
      if [ "$(grep 'sdk.getpebble.com' pebble-tool/pebble_tool/sdk/manager.py)" ]; then
      mv pebble-tool pebble-tool.OLD
      git clone https://github.com/pebble-dev/pebble-tool.git
      fi
    3. What does that do?
      The default ~/pebble-dev/.../pebble-tool/sdk/manager.py is version 4.5.0, but the latest available from GitHub is 4.6.0. This if statement checks to see if manager.py is still trying to download from the (nonexistent) "https://sdk.getpebble.com". If so, then the default pebble-tool is moved to a backup directory as pebble-tool.OLD, and the latest version is downloaded (and manager.py will now use DOWNLOAD_SERVER = "https://sdk.rebble.io")
  10. (Optional?) Use pypkjs-1.1.1 instead of pypkjs-1.0.6 by adding it to the requirements.txt file:**
    1. cd ~/pebble-dev/pebble-sdk-4.5-linux64/
    2. echo 'git+https://github.com/pebble/pypkjs.git' >> requirements.txt
  11. Create a Python2.7 virtual environment:
    1. cd ~/pebble-dev/pebble-sdk-4.5-linux64/
    2. virtualenv --python=/usr/bin/python2.7 .env
      (note: rebble.io's recipe calls for using the --no-site-packages flag here, but this is no longer necessary, as it does this by default now.)
      (note: rebble.io omits the --python=/usr/bin/python2.7 flag, which will lead to problems if you forget it! If the command python --version displays any modern 3.x+, then you absolutely need this flag here.)
    3. Why?

    Python version: the Pebble SDK requires Python 2.7. At this time, the Pebble SDK is not compatible with Python 3." Installing the virtual environment and configuring the Pebble SDK within it will ensure that all the setup commands use Python2.7.
     
    (from the top of: https://developer.rebble.io/developer.pebble.com/sdk/install/linux/index.html)

  12. Enter the Python virtual environment with:
    1. cd ~/pebble-dev/pebble-sdk-4.5-linux64/
    2. source .env/bin/activate
    3. You will now see (.env) at the beginning of your bash line.
      (Use the command deactivate at any time to exit.)
    4. python --version
      If the output for this command is anything other than Python 2.7 or Python 2.7.*, return to step 11. and repeat it with the --python=/usr/bin/python2.7 flag.
    5. pip --version
      If the output for this command doesn't end with (python 2.7) replace pip with pip2 in step 13.
  13. Now that we're using the correct version of Python in our virtual environment, we can install the list of requirements for pebble and pebble-tool:
    1. pip install -r requirements.txt
    2. pip install -r pebble-tool/requirements.txt
  14. Exit the python virtual environment with the command:
    1. deactivate
  15. Install the Pebble SDK to ~/.pebble-sdk/ with the command:
    1. pebble sdk install latest

 

Running pebble commands inside the Python virtual environment:

Building Pebble Projects + Running them:

Now that we have reinstalled Pebble, we need to enter the Python virtual environment we created in step 11. whenever we run pebble commands like pebble build or pebble install --emulator basalt. This will ensure Python2.7 is used. Without this, if your system uses Python3 by default when commands like python --version are called, then pebble commands won't work and you'll get a variety of error messages.

For an example, let's say we have a project in ~/pebble-dev/projects/hello_world/

  1. cd ~/pebble-dev/projects/hello_world/
  2. source ~/pebble-dev/pebble-sdk-4.5-linux64/.env/bin/activate
  3. pebble build
  4. pebble install --emulator basalt
  5. When you're done, exit the Python virtual environment with:
    deactivate

Since entering the virtual environment is a command I will now often use, I've added an alias vpebble to quickly activate it. To add this to your bash profile, use the commands:

  1. echo "alias vpebble='source /home/philosopher0fpeace/pebble-dev/pebble-sdk-4.5-linux64/.env/bin/activate'" >> ~/.bash_profile
  2. . ~/.bash_profile

With this alias, the previous process becomes:

  1. cd ~/pebble-dev/projects/hello_world/
  2. vpebble
  3. pebble build
  4. pebble install --emulator basalt
  5. Use the emulator
  6. deactivate

Concluding Remarks

This works for me, but if I've missed any typos or if different steps are needed, feel free to mention them.

Without first using the virtual environment, then trying to run pebble build you'll get an error like:

Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fbd8686f740 (most recent call first):
'python' doesn't mean anything on this system.

This happens on my setup when I do not first activate the Python virtual environment inside ~/pebble-dev/pebble-sdk-4.5-linux64/.env/.

A year ago, I was able to run pebble build on this machine without a Python virtual environment. But I've changed a lot with Python since I initially used pebble tools. I'm just glad I finally got it working again.

Fun note, now when I enter the virtual environment using my vpebble alias then run pebble install --emulator basalt -vv, part of the output still includes:
QEMU waiting for connection on: disconnected:tcp::34839,server. But the emulator now works successfully.

Anyway, hope this helps save someone from the hours and hours of Googling that I went through yesterday.

Have a great day.

@ProgrammingParadox
Copy link

@gamepad-coder Thanks for your solution! However, I'm still having the same problem of everything just freezing, even after restarting and following your steps twice.

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

No branches or pull requests

7 participants