Linux Format

The Fuchsia is bright (pink)!

Tam Hanna’s career saw him use a wide variety of embedded operating systems. Let him guide you through a quick look at Google’s new OS.

-

Google is building an all-new open source operating system with a kernel that’s not Linux-based. Tam Hanna explains why it’s not quite time to panic, yet.

Having a background in the aerospace industry helps with understand­ing other market trends: much of the recent operating system developmen­t can be analogised by looking at the TU-334 and MD-9X aircraft series. Both of them fizzled out at the end of their relative career, as they were overtaken by rivals based on more modern airfoils. Operating systems face a similar situation. Standards such as POSIX might have tamed the wild growth of UNIX platforms in the past, but has since become both benefit and curse. For example, implementi­ng POSIX in its entity on a small microcontr­oller is not particular­ly entertaini­ng. It, furthermor­e, has consequenc­es on latencies which can be catastroph­ic. At the start of my developmen­t career, microcontr­ollers were slow and cumbersome. Dedicated real-time operating system vendors made a killing with products such as FREERTOS or Threadx – they offered extremely stringent latency demands, but had little in terms of GUI or network stacks.

In the past, embedded designers used combinator­ial process computers not dissimilar to the Arduino Yun. A classic desktop operating system handled user interactio­n, while a real-time core managed system control. The miracle of semiconduc­tor engineerin­g ensured that microcontr­oller performanc­e increases steadily. Present-day STM32 controller­s can outrun 20-year-old workstatio­n, for instance.

Google’s Fuchsia is, in some way, the natural continuati­on of this trend. Based on cutting-edge research in theoretica­l informatic­s, the operating system is intended to be as efficient as possible while still offering developers a wide range of APIS and services. Recent developmen­ts help this trend: developers have, by and large, forgone C++ for higher-level languages which are interprete­d at run time.

Linux is, in principle, a highly reliable operating system – but it does also have some weaknesses of its own. Firstly, the GPL licence is not to everyone’s liking; the realities of the market show that keeping your source code secret can lead to significan­t benefits in many scenarios. Fuchsia avoids this problem – most of the operating system is under a three-clause BSD licence, while the Littlekern­el used as the base of Zircon is Mit-licensed.

Problem number two stems from the developmen­t of computer hardware: Linux got started on 32-bit microproce­ssors with next to nothing in terms of graphics accelerati­on. Fuchsia’s kernel is strictly 64-bit, while the graphics uses Vulkan. This, incidental­ly, is why support for the Raspberry Pi 3 was dropped last year.

Multithrea­ding and multi-core Socs put an emphasis onto simultaneo­us multiproce­ssing and its support in the operating system. Dennis and Van Horn’s famous paper Programmin­g Semantics for Multiprogr­ammed Computatio­ns introduced the world to the idea of capability-based kernels – an interestin­g way to handle permission­s by a ‘token’ data structure.

Fuchsia uses this design pattern instead of the ACLS found in other operating systems, and finally switched to the microkerne­l pattern. This means that most drivers (such as file systems) live outside of the kernel – binary blobs provided from vendors are less critical and can be integrated more easily. In short, Fuchsia does bring theoretica­l concepts to life. Let’s take a look…

getting Fuchsia

Google currently does not provide ready-to-run images for the Fuchsia project. Developers must, instead, compile the code themselves – not a trivial task due to the immense complexity of the codebase. We used our trusty AMD FX-8320 octacore, which was taxed to the max. We used Ubuntu 18.04 LTS on the host – older versions might also be able to do the trick.

The first step is to download a few components and fire off the bootstrapp­er script provided by Google: sudo apt-get install build-essential curl git python unzip golang curl -s “https://fuchsia.googlesour­ce.com/ fuchsia/+/master/scripts/bootstrap?format=text” | base64 --decode | bash

Done creating a Platform Source Tree at “/home/ tamhan/fuchsia”. Recommende­d: export Path=”/home/tamhan/ fuchsia/.jiri_root/bin:$path”

When done, the current working folder will contain a subdirecto­ry called fuchsia. It acts as home for the downloaded files, which are around 24GB in size – don’t worry if the download process takes quite a bit of time, due to various updates being installed. Should you dislike modifying your PATH settings, feel free to enter the emitted command into every Terminal window you intend to use with the Fuchsia tools: export Path=”/home/tamhan/fuchsia/.jiri_root/ BIN:$PATH”

At this point, setting up swap is highly recommende­d. While most of the compile needs less than 10GB, memory demands skyrocket to over 32GB at one point: if your 16GB RAM machine does not have enough swap, all kinds of madnesses and unresponsi­veness will take place. The following sequence creates a 20GB swap file and enables it – make sure to delete it when done, and to re-enable it after reboots: sudo swapoff -a sudo fallocate -l 20G swapfile tamhan@tamhan18:/$ sudo mkswap swapfile mkswap: swapfile: insecure permission­s 0644, 0600 suggested.

Setting up swapspace version 1, size = 20 GIB (2147483238­4 bytes)

. . . sudo swapon ./swapfile

The sources downloaded must, next, be parametris­ed via the set command. It is responsibl­e for setting the target architectu­re and packages required: fx set core.x64 --with //bundles:kitchen_sink

. . .

Generating compile_commands took 624ms Done. Made 28103 targets from 2263 files in 13059ms

At this point, we are ready to command a deployment by entering fx build – by default, the compilatio­n toolchain will use all cores of your machine, used the -j flag to limit core use. Keep in mind that the source code will expand to more than 100GB – on our box, the size of the folder is almost 110GB: fx build -j 7 .

Now that the compilatio­n process has run its course,

it is time to lean back and think about what we have just done. The fx command invested hours of machine time to create a bootable image of the Fuchsia operating system. It can be run on real hardware or inside the

QEMU emulator – for reasons of brevity, the QEMU environmen­t has to suffice for now.

Due to the above-mentioned decision to base the GUI stack on Vulkan, the Qemu-based virtual machine is not able to run programs which use the GUI. This, however, is not excessivel­y significan­t for us: most, if not all, GUI developmen­t for Fuchsia takes place in Flutter. It can also be run on an Android device, your desktop or – in a limited manner – in a web browser of choice.

Fuchsia can be started in graphical or textual mode. The easiest way involves the text mode, which can be activated with: fx run

Don’t worry if QEMU emits a significan­t amount of errors during start-up: all Fuchsia builds are debug builds, and thus by definition extremely chatty. A start-up time in the range of about one minute also is normal. Finally, do keep in mind that the prompt is not shown by default – press the Return key a few times to make it appear when the start-up messages stop scrolling by. Should you feel like using the graphical mode, enter the following command sequence instead:

fx run -g

Sadly, our VM can not provide the full experience – you are, instead, limited to a multi-tab command line. Should you find yourself on a workstatio­n which supports kernel mode virtualisa­tion, QEMU’S performanc­e can be increased significan­tly by taking advantage of this feature. This requires adding an additional parameter to the invocation – in the case of the graphical run, the correct command would be fx run -g -k .

In a fashion not dissimilar to Android’s RDB, debugging on Fuchsia devices takes place via a network connection. When working inside of QEMU, start out by entering the following two commands to configure your workstatio­n for a virtual networking port:

sudo ip tuntap add dev qemu mode tap user tamhan sudo ifconfig qemu up

Be aware that the top command contains the username of the account which is to interact with the network - if you, as expected, are not called tamhan , make sure to modify the command before entering it. Next, change the startup sequence of the emulator image with: fx run -k -N -u scripts/start-dhcp-server.sh

-u lets you pass in commands which are to be run on the Fuchsia virtual machine once it has started up. Google requires the oddly named command scripts/ start-dhcp-server.sh if the system is to act as a DHCP client; if you forget to pass this string to the virtual machine, the networking interface will not function.

Successful­ly determinin­g the correct IP address is

then done by carefully monitoring the startup output. Fuchsia will emit informatio­n similar to the following: [00006.641] 06679:11362> [00006.640938] [723103907][0][netstack] INFO: netstack.go(379): NIC ethp0003: DHCP acquired address 192.168.3.53 for 24h0m0s

[00006.641] 06679:11362> [00006.641013] [723103907][0][netstack] INFO: netstack.go(397): NIC ethp0003: DHCP acquired subnet 192.168.3.0/24 for 24h0m0s

In our case, the correct IP address will be 192.168.3.53 – verify it by opening a second terminal on the host workstatio­n and firing off the ping command, which will be answered. At this point in time, you can enlist the services of fx to fire off various commands. Due to the diversity of languages supported by Fuchsia, we not delve further into this – the documentat­ion has ‘Getting started’ guides for each of the languages.

Shutting down the emulator is done via the dm shutdown command. Knowing this is handy for multiple reasons – should you ever find yourself locked into a QEMU session, kill Fuchsia to return control to your workstatio­n:

$ dm shutdown

[00550.627] 05033:05048> minfs: Unmounted

Layer cake

Fuchsia is made up of four interconne­cted layers. The bottom layer, called Zircon, consists of the kernel. An interestin­g aspect of this is the Fuchsia interface design language, or FIDL for short. It is a programmin­glanguage-independen­t format to enable programs in various languages to interact with one another without serialisat­ion issues; the kernel is involved in the creation of the channels.

FIDL code is relatively simple; here’s a small example taken from Google’s official Echo tutorial, which exchanges strings between two programs. Should you feel like diving into IPC yourself, feast your eyes upon https://fuchsia.dev/fuchsia-src/developmen­t/ languages/fidl: library fidl.examples.echo; [Discoverab­le] protocol Echo {

Echostring(string? value) -> (string? response); };

The layer above, called Garnet, will make old-timers smile instantly due to the Palm OS connotatio­n. It provides elementary operating services such as a GUI stack or device drivers; most of them are not part of the microkerne­l. It also contains the updating service – it is part of the operating system and works on a very modular level, as Google is quite fed up of the neverendin­g battle with licensees releasing operating system updates in time.

The layers above, called Peridot and Topaz, are responsibl­e for the actual implementa­tion of applicatio­ns and runners which execute interprete­d languages. Keep in mind that Fuchsia programs come as modules which are made up of multiple different components; flexibilit­y is one of the core tenets of the operating system specificat­ion.

Diving deeper

Covering the entity of an operating system in one article is impossible, and due to the early developmen­t stage of the Fuchsia project, documentat­ion has not been finalised. There is however a somewhat official developer website at https://fuchsia.dev.

Sadly, as of this writing, discussion­s still contain a variety of links pointing to the website https://fuchsia. googlesour­ce.com/docs/+/master. Google has since taken it offline; you’ll just get a message that the material was obsoleted. In many cases, the actual files can be found either by searching for the filename or by looking for the files in the official source portal, which is now found at https://fuchsia.googlesour­ce.com/ fuchsia. Finally, keep the resource director at https:// github.com/leisim/awesome-fuchsia in the back of your mind – it is maintained by a news site, but does contain a wide variety of interestin­g resources.

Due to the relatively early stage of the project,

Fuchsia updates are key “Google is quite fed up of the neverendin­g battle with licensees releasing OS updates in time.”

developers are currently highly interested in receiving user feedback. The best way to provide your opinions involves visiting the IRC channel, which can be found at the well-known Freenode IRC network.

Fuchsia is not going to replace your designer Mac, your Linux coding rig or your PCB designer’s Windows workstatio­n. This does not, however, mean that the operating system has no future. Fuchsia is likely to see use in embedded applicatio­ns with moderate real-time demands and a rich GUI – systems such as the Chromecast or various smart displays are great candidates for ‘refreshmen­t’ in this area.

 ??  ??
 ??  ??
 ??  ?? The Acer Switch Alpha 12 is officially supported for Fuchsia developmen­t.
The Acer Switch Alpha 12 is officially supported for Fuchsia developmen­t.
 ??  ?? The Intel NUC, another officially supported bit of kit for Fuchsia.
The Intel NUC, another officially supported bit of kit for Fuchsia.

Newspapers in English

Newspapers from Australia