Hello world inside a window

(or writing my second app)

As a non-programmer, I had to start from scratch. Sure, I can write C programs for embedded systems and I even know some VHDL. But that's all peanuts compared to setting up a development environment for GNOME (or KDE for that matter). The tools and documentation are there, but if you, like me, never made a program for a PC or a smartphone, it is all a mystery to you. On most sites they just say: install your favorite development tools and start programming. Well, that information is of no use when you do not know which tools are available and how to use them. After a couple of evenings browsing through forums, websites and video's I stumbled across a good tutorial: https://developer.puri.sm/Librem5/Apps/index.html. I still have to read it thoroughly, as it is very comprehensive. It is written for developing applications for the Librem 5 phone, but that phone is build around the same processor as the PinePhone. So it should (and it did) work.

The technical stuff

This is a summary of what I did to get my application running on the PinePhone. I strongly suggest to read the tutorial on https://developer.puri.sm/Librem5/Apps/index.html for a better understanding of the process.

It is all based around flatpak, so I had to install that:

sudo apt-get install flatpak flatpak-builder

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

flatpak install flathub org.gnome.Platform//3.34

For the cross compilation you need qemu:

apt-get -y install qemu-user-static

Because all the examples on the Purism site are made with GNOME, I choose to stick with that and installed GNOME builder:

flatpak install flathub org.gnome.Builder

Later, I can start GNOME builder by typing:

flatpak run org.gnome.Builder

Now some technical stuff I did not fully understand, but did anyway. You have to be root; sudo does not suffice:

echo -1 > /proc/sys/fs/binfmt_misc/qemu-arm

echo ":qemu-arm:M:0:\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:F" > /proc/sys/fs/binfmt_misc/register

echo -1 > /proc/sys/fs/binfmt_misc/qemu-aarch64

echo ":qemu-aarch64:M:0:\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:F" > /proc/sys/fs/binfmt_misc/register

Hello World

Now everthing should be ready to try to compile my first GUI program for the PinePhone. I followed this tutorial: https://developer.puri.sm/Librem5/Apps/Tutorials/First_Application/index.html

In order to cross compile the application, I had to install the aarch64 version of the runtime and SDK:

flatpak --user install flathub org.gnome.Platform/aarch64/3.34 org.gnome.Sdk/aarch64/3.34

Now I can build the example program from the above tutorial and make it into a flatpak:

flatpak-builder --arch=aarch64 --repo=myrepo _flatpak com.example.first_application.json

flatpak build-bundle --arch=aarch64 myrepo app.flatpak com.example.first_application

The file app.flatpak contains the aarch64 build and has to be copied to the PinePhone.

Now, on the PinePhone, register the flatpak remote and install the applicition:

flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

flatpak --user install app.flatpak

Now I can finally run the application on the PinePhone:

flatpak run com.example.first_application

That's it. Now I can write programs with a GUI for the Pinephone. Well, I first have to read a lot of documentation before I really understand what is going on. But I know that, in theory at least, I can write programs for the PinePhone.

I also tried to install the development environment on my openSUSE Leap workstation, but that did not work. openSUSE Leap is not made for developers. Thumbleweed is probably better. But I need a stable workstation for editing video, designing pcbs and documenting projects. As much as I like fiddling with computers, I also need at least one machine that just works all the time. I tried to run GNOME builder via remote X11 from Debian to my openSUSE workstation, but it seems that the flatpak software does not allow X11 forwarding. So I have to make do with the old Core2Duo Debian station with the mushy keyboard for developing applications for the PinePhone.

Next: writing in C