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

add guide on how to emulate Olimex image #15

Merged
merged 1 commit into from Jun 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -64,6 +64,8 @@ As base to actually run opensesame you need:

- https://www.olimex.com/Products/OLinuXino/A20/A20-OLinuXino-LIME2/

If you want to try it out on your normal PC, we have provided an [emulation guide](doc/Emulating-Olimex.md).

Probably you also want for every device:

- https://www.olimex.com/Products/OLinuXino/A20/LIME2-SHIELD/
Expand Down
54 changes: 54 additions & 0 deletions doc/Emulating-Olimex.md
@@ -0,0 +1,54 @@
# Emulating the Olimex Board

This guide shows how to emulate the Olimex Linux image on your Intel based PC.
It is based [on this forum entry](https://www.olimex.com/forum/index.php?topic=2239.0).

Basically, we use the `qemu-user-static` emulator to emulate ARM binaries on our native kernel, and use `systemd-nspawn` to execute the image like a container.

## Prerequisites

On Debian systems, install the following tools:

```
apt install qemu-user-static systemd-container
```

On Fedora, use these:

```
dnf install qemu-user-static systemd-container
```

## Running the system

You need to have the [A20 Debian image](http://images.olimex.com/release/a20/) extracted somewhere in your filesystem.
This means you either extracted it from the image file, you mounted the image file, or you have already written it onto a microSD card and mounted that on your system.
As an example, we have extracted the whole image into `/tmp/olimex`.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you could include some basic information on, how to mount from an Image. For example, extracting the offset of the partition which should be mounted (``fdisk -l .img) and how to setup the loop-device (losetup -o -f .img).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well I can't because I don't know. But feel free to add suggestions via the comments on how you set up that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

First you need to get the offset of the olimex.img for that you need to execute fdisk -l olimex.img, now you need to get the starting sector of the image partition, you like to mount. Now you have to multiple the starting sector with the sector-size and this results in the offset. In the next step you have to setup the loop-device with losetup -o <offset> -f olimex.img. You can list all you loop-devices with losetup -l, to see on which loop-device your image is connected. The last step is to mount the loop-device with mount /dev/loop0 <mount-dir>.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fel115 probably easier if you directly write it.

Copy link
Collaborator Author

@atmaxinger atmaxinger Jun 7, 2023

Choose a reason for hiding this comment

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

@fel115 systemd-nspawn also has a way of directly working on the image with the --image parameter. Maybe this is easier? You can then use --overlay for persisting the changes and keeping the image read-only.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With my image it doesn't worked. I get this error message No suitable root partition found in image 'A20-OLinuXino-bullseye-minimal-20220928-143706.img'.. It think that's because the image doesn't contain a MBR- or GUID-table.

All that's left is to execute the following command as root:

```
systemd-nspawn --bind=/dev/ttyACM0 -b -D /tmp/olimex
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't bind the /dev/ttyACM0, because my system doesn't have such a device. Is it necessary to mount this device?

Copy link
Collaborator Author

@atmaxinger atmaxinger Jun 6, 2023

Choose a reason for hiding this comment

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

It's only necessary if you want to bind it. However, opensesame seems to be a bit useless without it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything except of the air-quality sensors works without it (the other devices/sensors use i2c).


Explanations of the parameters:
- `--bind=/dev/ttyACM0` exposes your host system serial device `/dev/ttyACM0` into the chrooted A20 environment.
This serial device is used in opensesame to read the sensor data.

- `-b` advices systemd to act like it's booting the image, so it will run the `init` exectuable of the chrooted environment.

- `-D` specifies the root directory of the A20 image.
Alternatively, you can use `-i` to specify the image directly, so you don't need to extract the contents of it.

Use the credentials of the image (default root/olimex) to login and work on the system.

If you need network connectivity, you need to configure DNS lookup with the following command:

```
echo 'nameserver 8.8.8.8' > /run/resolvconf/resolv.conf
```

You need to do this every time you start the container, as anything under `/run` does not get persisted.

If you want to connect into this container via SSH, you need to modify the port in `/etc/sshd/sshd_config` to another port, as port 22 is most likely already used by your host system.