avatartwo / avatar2-examples

Examples demonstrating the usage of avatar²
27 stars 14 forks source link

Qemu U-Boot not working with Docker #7

Closed peterrakolcza closed 2 years ago

peterrakolcza commented 2 years ago

Hey!

I have been trying to tinker with the above mentioned example. However, I got the following error message when I try to run the python file using the installer method of avatar2:

(avatar2-local) parallels@parallels-Parallels-Virtual-Platform:~/avatar2-compose/files$ python test2.py 
2022-05-17 17:15:45,936 | avatar.INFO | Initialized Avatar. Output directory is /tmp/myavatar
Traceback (most recent call last):
  File "test2.py", line 111, in <module>
    main()
  File "test2.py", line 34, in main
    target_runner = TargetLauncher([avatar.arch.get_qemu_executable(),
  File "/home/parallels/.virtualenvs/avatar2-local/lib/python3.8/site-packages/avatar2/archs/architecture.py", line 38, in <lambda>
    return staticmethod(lambda : Architecture._resolve_executable(exec_name))
  File "/home/parallels/.virtualenvs/avatar2-local/lib/python3.8/site-packages/avatar2/archs/architecture.py", line 25, in _resolve_executable
    raise Exception(("Couldn't find executable for %s\n"
Exception: Couldn't find executable for avatar-qemu
Have you tried running the avatar2-installer (python -m avatar2.installer) or setting the AVATAR2_QEMU_EXECUTABLE environment variable?

When I try to run with docker, I get the following output: docker command: docker-compose run --rm -e AVATAR2_QEMU_EXECUTABLE=qemu-system-arm avatar2 python3 /tmp/test2.py

2022-05-17 15:17:10,668 | avatar.INFO | Initialized Avatar. Output directory is /tmp/myavatar
TargetLauncher is starting process "/usr/local/bin/qemu-system-arm" "-M" "versatilepb" "-m" "20M" "-gdb" "tcp:127.0.0.1:1234" "-serial" "tcp:127.0.0.1:2000,server,nowait" "-kernel" "u-boot" "-S" "-nographic" "-monitor" "telnet:127.0.0.1:2001,server,nowait"
qemu-system-arm: could not load kernel 'u-boot'
2022-05-17 15:17:15,780 | avatar.targets.GDBTarget0.GDBProtocol.CRITICAL | GDBProtocol was unable to connect to remote target
Traceback (most recent call last):
  File "/tmp/test2.py", line 111, in <module>
    main()
  File "/tmp/test2.py", line 85, in main
    avatar.init_targets()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 233, in init_targets
    t[1].init()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/gdb_target.py", line 60, in init
    if gdb.remote_connect(ip=self.gdb_ip, port=self.gdb_port):
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/protocols/gdb.py", line 399, in remote_connect
    return self._remote_connect_common('%s:%d' % (ip, int(port)))
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/protocols/gdb.py", line 384, in _remote_connect_common
    raise Exception("GDBProtocol was unable to connect")
Exception: GDBProtocol was unable to connect

Any help is appreciated!

rawsample commented 2 years ago

Hi Peter,

For the first error, you should either try to set the environment variable AVATAR2_QEMU_EXECUTABLE or execute python -m avatar2.installer which let you save it under ~/.avatar2/settings.cfg.

For you second issue, could you give us a bit more context about your environment and the script you run? My understanding is that you want to run the Qemu U-Boot example within the avatar2 container. Did you check the u-boot binaries are in the container? IIRC it's not the case by default.

peterrakolcza commented 2 years ago

Hi, thanks for your input!

After setting the variables in the setting.cfg file, I still get the same error.

[DIST]
has_apt = True
default_install_path = /home/parallels/.avatar2/

[TARGETS]
openocd = /home/parallels/.avatar2/openocd/src/openocd
avatar-qemu = qemu-system-arm
panda = None
gdb (x86) = gdb
gdb (multiarch) = gdb-multiarch

For my second issue: I am running a docker-compose

version: "3"

services:
  avatar2:
    image: avatar2:latest
    privileged: true
    volumes:
      - ./files:/tmp

Under ./files, I have the following files:

image

test2.py contains the example which I want to run, see the docker-compose run command above.

rawsample commented 2 years ago

For settings.cfg, try with the absolute path.

rawsample commented 2 years ago

For the second issue, the script expects u-boot to be in the current working directory (i.e., /). Something like this should work in your setup: docker-compose run --rm -e AVATAR2_QEMU_EXECUTABLE=qemu-system-arm avatar2 sh -c 'cd /tmp && python3 test2.py

You can replace qemu with panda-system-arm to avoid the #6