The QNX Software Development Platform (SDP) can be very fragile to configure natively, whether you're using the command line or the Eclipse based Momentics IDE (if you enjoy extra suffering).
This guide will run through setting up the SDP on its recommended Linux distro (Ubuntu) inside a QEMU VM, so by the end you have a standard x86 image of the QNX RTOS with SSH enabled. That way you can get to the fun part, compiling & running code for it.
We will not be using any GUI tools, only the CLI; therefore it is assumed you know your way around CLI tools for your host & VM (Ubuntu) environment. There will be a header above code blocks to help understand which environment a command is expected to be run from to be explicit.
If you feel confident your host machine will run the SDP CLI without issue,
you can skip the VM portion and move straight to
Setting Up the QNX Software Center,
since this guide also covers the qnxsoftwarecenter_clt
commands required to get your first RTOS image running. Disregard the environment
headers on code blocks if you choose this approach; everything will be ran on
your host.
Note: Originally written for CST8244 at Algonquin College as a guide for non x86 hosts (macOS M-chips & Windows/Linux on ARM).
Why a Clean Environment?
Before we download the SDP from the software center, setting up the environment QNX suggests is the best way to not run into any issues. Although the SDP supports Windows on paper, its tooling fundamentally relies on GNU/POSIX tools, which are not native to Windows.
To bridge the gap, the SDP uses msys2 as an emulation layer to execute its shell scripts in Windows environments. This can cause odd errors that you don't want to debug, and so I (as many others) recommend running the SDP environment in Linux where it's fully compliant.
This ensures you get a completely clean environment where you'll run into the least friction possible. It also means your computer architecture does not matter to this guide, since you won't be doing any QNX development inside your host machine.
Installing QEMU
To emulate the SDP's preferred environment, we will be using QEMU because it's lightweight, open source, and highly customizable for specific hardware specifications which will be useful to run our RTOS later.
Windows
On Host Environmentwinget install -e --id SoftwareFreedomConservancy.QEMU
macOS
On Host Environmentbrew install qemu
Linux (Ubuntu/Debian)
On Host Environmentapt-get install qemu-system
This guide uses the qemu-system-x86_64 tool (the QEMU package
has quite a few tools). You can do a quick integrity check with
--version which will return the version you've downloaded.
See the QEMU download page for more details.
Download Ubuntu Image
After QEMU is installed, you need to grab the preferred linux image for your QNX version. You can check the SDP 7.1 and SDP 8.0 release notes if your curious, or just follow the download link I've provided:
SDP 7+
Ubuntu 18.04 Server (release page)
SDP 8+
Create QEMU Virtual Disk
Lets create an SDP directory to keep our work safe and contained, then create a virtual disk for the VM:
On Host Environmentqemu-img create -f qcow2 sdpdisk.qcow2 60G
This provisions a 60GB (60G) virtual disk with the
QEMU Copy On Write format
(-f qcow2). While the format is slightly slower
than a raw format due to metadata overhead, it supports snapshots,
compression, and (importantly for us) dynamic allocation. Dynamic
allocation means the virtual disk file only takes what was
written in the VM, so storage for the SDP environment stays as
lean as possible. In this case 60GB acts as the upper limit
rather than an upfront allocation, no worries.
More information about qemu-img and its flags is available in the
QEMU disk image documentation.
Mount Ubuntu Image
Move your Ubuntu .iso to the SDP directory you created and start
your VM:
On Host Environmentqemu-system-x86_64 -machine q35 -cpu max -smp 8 -m 6G -accel tcg,thread=multi -drive file=sdpdisk.qcow2,if=virtio -cdrom ubuntu-*-live-server-amd64.iso -nic user,hostfwd=tcp::2222-:22
There are a lot of flags here I won't go in depth with but these are the ones to pay attention to:
-smp 8: The VM can use 8 cores. Leave some for your
host OS.
-m 6G: The VM can use 6GB of RAM. Leave some for
your host OS.
-accel tcg: If you are on an x86 machine,
you will have faster performance using
kvm
on Linux,
whpx
on Windows, and
hvf
on Apple. These are all hypervisors, so they require hardware virtualization.
Ensure that's enabled on your system. Leaving this as tcg is the
safe route, but will be slower.
More information about qemu-system-x86_64 and its flags is available in the
QEMU system emulator documentation.
Installing Ubuntu
After running the command above, QEMU should have opened a window as so:
Let it finish, this is systemd.
After it's finished, you should be greeted by the friendly Ubuntu install TUI.
For any page I don't specify moving forward, the answer is to leave it as-is
and select Done.
If Ubuntu prompts you for an installer update, continue without updating:
Set whatever you want for your login. Keep in mind you will have to use these credentials for SSH later, so if you'd like to just follow along with the guide you can copy mine:
Extra points if you can figure out my password.
Ubuntu will prompt you to install OpenSSH. We need this, otherwise we will interact to the OS through the QEMU window which is not ideal. Our terminal will be much nicer.
If you see this screen:
Congrats! You have installed Ubuntu. You can close the QEMU window now,
no need to Cancel update and reboot, since we will be using
SSH to get into the SDP environment from this point on.
Starting Up The SDP Environment
From now on, starting the SDP environment will take the command we used earlier
(with any adjustments you made from mine) but without the -cdrom option
since Ubuntu is now installed, and -display none so QEMU
doesn't open a window for the OS. If you've been following the guide exactly, you
can try this:
On Host Environmentqemu-system-x86_64 -machine q35 -cpu max -smp 8 -m 6G -accel tcg,thread=multi -drive file=sdpdisk.qcow2,if=virtio -nic user,hostfwd=tcp::2222-:22 -display none
With -display none QEMU will not notify you when Ubuntu has
booted. Trust your gut when you think it's up, and run:
On Host Environmentssh -p 2222 qnx@localhost
If everything is setup correctly, you should get a response like this:
On Host EnvironmentThe authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.
ED25519 key fingerprint is SHA256:p9jnaEwyRpEfeZOhzlqz+3wktx/vPQzXIBeM0y8RkVs.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes, input your Ubuntu password, and congratulations! You are now
connected to your SDP environment.
Setting Up SSH Keys
When ssh'ing into your SDP environment, you will have
been prompted with the password you setup. To make life easier,
we can setup keys that will automatically verify your identity between
both the SDP and your host machine.
Generate a key on your SDP environment as so:
On SDP Environmentssh-keygen
And accept all the defaults. Your new public key will live
at your home directory under .ssh/id_ed25519.pub (assuming
at the time of reading the OpenSSH default algorithm is still
ed25519).
Make sure to run the same command on your host machine if
you do not already have a public key created there.
You can check the .ssh/ directory for your
generated keys.
Then give your SDP environment your host key as follows:
Windows
On Host Environmenttype %USERPROFILE%\.ssh\id_ed25519.pub | ssh -p 2222 qnx@localhost "cat >> ~/.ssh/authorized_keys"
Linux & macOS
On Host Environmentssh-copy-id -p 2222 qnx@localhost
Now if you have not setup a password on your key, you should be
able to ssh into your SDP environment without a
password.
More information about ssh is available in the
SSH Wikipedia article for technical details,
or
Cloudflare's SSH guide for a general overview.
Setting Up QNX Software Center
Head over to the QNX Software Center and download the build for your environment. If you've followed the VM steps, download the Linux hosts build:
After it's downloaded, send it over to the SDP environment with scp and
ssh in:
On Host Environmentscp -P 2222 qnx-setup-*.run qnx@localhost:~
ssh -p 2222 qnx@localhost
Now make the installer executable and run it:
On SDP Environmentchmod +x qnx-setup-*.run
./qnx-setup-*.run
Go through the license agreement and set your installation path. You should now have the software center installed in a directory of your choosing (or the default one). We can now install the SDP.
Head over to that directory, and add your license key to the software center tool:
On SDP Environment./qnxsoftwarecenter_clt -addLicenseKey "YOUR-KEY" -myqnx.user="YOUR-USER" -myqnx.password="YOUR-PASS"
Then mirror the repository details for your QNX version (7.1 in this example):
On SDP Environment./qnxsoftwarecenter_clt -mirrorBaseline qnx710 -myqnx.user="YOUR-USER" -myqnx.password="YOUR-PASS"
Finally install it into a directory of your choosing (qnx710 in this example):
On SDP Environment./qnxsoftwarecenter_clt -cleanInstall -destination "qnx710" -installBaseline com.qnx.qnx710 -myqnx.user="YOUR-USER" -myqnx.password="YOUR-PASS"
This step can take a while; be patient and let it complete. After it is completed, I
recommend auto-sourcing the qnxsdp-env.sh file from the SDP directory
into your .bashrc, so you don't have to source it every time
you open a terminal session and want to run SDP commands:
On SDP Environmentecho 'source ~/qnx710/qnxsdp-env.sh' >> ~/.bashrc
Now every new terminal session will automatically add all SDP commands to your
$PATH. You can update your current terminal by source'ing
your .bashrc file again:
On SDP Environmentsource ~/.bashrc
More information about qnxsoftwarecenter_clt and its flags is available in the
QNX Software Center CLI documentation.
Creating The RTOS Image
After sourcing the qnxsdp-env.sh file with my recommended
advice above or your own way, you should be able to use the
mkqnximage command now. This command is the golden goose
we've been working towards that will allow us to build the RTOS image.
Create a directory for the image (for this guide it will be
~/image) and run this command:
On SDP Environmentmkqnximage --type=qemu --ssh-ident="$HOME/.ssh/id_ed25519.pub" --clean --build
The --ssh-ident flag will auto-embed our SDP key into the RTOS
.ssh/authorized_keys file in the RTOS system, given we give it
a proper location. The $HOME/.ssh/id_ed25519.pub path assumes that
your SDP public key lives at the default ssh-keygen location,
given you followed it's defaults as we did in the guide earlier.
The command should build a assembled RTOS disk into an output
directory. We need to transfer your built image from the SDP to your
host machine now. Create a new directory for this disk to reside in
or use the SDP directory, and copy it over:
On Host Environmentscp -P 2222 qnx@localhost:~/image/output/disk-qemu .
More information about mkqnximage and its flags is available in the
QNX mkqnximage documentation.
Running The RTOS Image
Given all prior steps, you should be able to now run the RTOS:
On Host Environmentqemu-system-x86_64 -m 1G -drive file=disk-qemu,format=raw,if=ide -netdev user,id=net0,hostfwd=tcp::3333-:22 -device e1000,netdev=net0 -display none -serial mon:stdio
It should boot up and present you with another command line interface, except this one is special because it's the one you followed the guide to see. Enjoy it!
With -serial mon:stdio, QEMU should pipe the output of the machine
to your current terminals stdout and your input to stdin.
When your done with the RTOS, you can terminate the QEMU process with
Ctrl+A and X.
This is the early end to the guide; from here I cover ssh'ing into
the RTOS machine and discuss some more setup that can help the development
experience. But if your satisfied, you can end here.
'sshd-session is not found'
To ssh into the RTOS, you need sshd-session.
But I've noticed whilst running the 7.1 SDP that the RTOS image cannot
find sshd-session.
This is because an
OpenSSH update split the sshd server into multiple binaries,
and whilst QNX updated the target packages, it did not update mkqnximage
to build with this change in mind. QNX's release notes about the
QNX SDP OpenSSH update
mentions this.
Here's my fix for SDP 7+:
Head to the directory you created your RTOS image in with mkqnximage.
If you haven't created it yet, create it so you have the build files.
Open the local/snippets/system_files.custom file and append
these lines so the missing binaries are thrown onto the RTOS disk with
execute permissions:
On SDP Environment[perms=0755] xbin/sshd-session=${QNX_TARGET}/x86_64/usr/libexec/sshd-session
[perms=0755] xbin/sshd-auth=${QNX_TARGET}/x86_64/usr/libexec/sshd-auth
Open the local/snippets/ifs_start.custom file and append this
symlink command so the ssh daemon can find the binaries:
On SDP Environmentln -sP /system/xbin /usr/libexec
Rebuild just as before, and the boot screen should not show any
sshd errors.
SSH Into The RTOS!
Now you should be able to ssh into the RTOS from your
SDP environment:
On SDP Environmentssh -p 3333 root@10.0.2.2
We use 10.0.2.2 on the SDP environment instead of
localhost as it's the host loopback IP for QEMU.
As a final step, we want to allow the host machine to ssh
in as well, so we'll add the host machines key whilst we're connected:
On RTOS Environmentecho "YOUR HOST ED25519 PUB KEY" >> .ssh/authorized_keys
Setting Up SSH Aliases
By now I'm sure you're tired of manually entering in the port, user, and IP of the SDP & RTOS machine. Creating an alias will make the experience much simpler.
Create a config file in your .ssh directory,
and write aliases for your SDP and RTOS environments as such:
On Host EnvironmentHost qnxSDP
HostName localhost
Port 2222
User qnx
Host qnxOS
HostName localhost
Port 3333
User root
The format is simple, so if your QEMU ports or SDP username differ from this example based on the values of the guide, I'm sure you can figure it out.
There's a beauty in the old(er) days of software before every config
file had to be in json or toml format, and
software just wrote it's own parser instead of importing one from
a library.
More information about ssh aliases and config is available at the
OpenBSD SSH config documentation.