Raspberry Pi: compile and run Magenta

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Magenta master branch, commit 0ad390c4d67102ede5ad8aeaa0f51d1f6401ab6c
  • Raspberry Pi 3 Model B

Magenta is a kernel developed by Google and used in Google’s coming soon brand new Fuchsia OS. Magenta is based on Little Kernel.

Download Magenta source code

Magenta source code can be downloaded as part of Fuchsia OS (see Fuchsia OS Getting Started) or separately (see Magenta Getting Started)

Build Magenta
# In Fuchsia repositories it's in the magenta folder
$ cd fuchsia/magenta
# Or, standalone Magenta repository
$ cd magenta
$ make magenta-rpi3-arm64
Prepare bootable SD card

To run Magenta on Raspberry Pi we need a single-partition bootable SD card with Master Boot Record (MBR) and FAT32 file system. Not all cards come in that state. See how to make one on Intel’s Make a bootable micro SD card page:

  • Run Unity Dash (desktop search utility).
  • Enter the command: disks.
  • Select the Disks app.
  • Insert the micro SD card into your computer.
  • In the left sidebar, select the micro SD card.
  • If you see multiple partitions, select a partition and click the icon to delete the partition.
  • Click the + icon to create a new partition.
  • From the Type drop-down list, select Compatible with all systems and devices (FAT). In the Name field, type magenta to make it easier to identify in the steps below.
Copy Magenta files to the SD card

See complete story on Github:

$ cd magenta
$ cp ./build-magenta-rpi3-arm64/magenta.bin /media/username/magenta/kernel8.img
$ cp ./kernel/target/rpi3/config.txt /media/username/magenta/config.txt
$ cp ./kernel/target/rpi3/cmdline.txt /media/username/magenta/
$ cp ./kernel/target/rpi3/bcm2710-rpi-3-b.dtb /media/username/magenta/
$ cp ./build-magenta-rpi3-arm64/bootcode.bin /media/username/magenta/
$ cp bootcode.bin /media/username/magenta/
$ cp start.elf /media/username/magenta/
$ ls -a /media/username/magenta/ | sort
  • Note that the ./build-magenta-rpi3-arm64/magenta.bin file is renamed to kernel8.img – this is how it is referred to in config.txt:
$ cat /media/username/config.txt
# Tells the Pi's bootloader which file contains the kernel.

The bootcode.bin and start.elf files are not part of the Magenta build process described above and can be found here and here.

Serial terminal setup

See the Raspberry Pi: serial terminal setup.

Run Magenta

Start screen/putty terminal and power up your Raspberry Pi:

...[00002.007] 01473.01497> LAN9514 - attempting to bind 
[00002.007] 01473.01497> lan9514 returned 3 endpoints 
[00002.021] 01473.02308> Initializing LAN9514... 
[00002.030] 01473.02308> LAN9514 MAC Address b8:27:eb:20:0a:4c 
[00002.045] 01473.02308> LAN9514 Initialized! bmcr=3000  bsr=7809 
[00002.052] 01041.01044> devcoord: drv='ethernet' bindable to dev='smsc-lan9514' 
[00002.062] 01227.01307> netifc: ? /dev/class/ethernet/000 
[00002.073] 01227.01307> netifc: create 128 eth buffers 
[00002.078] 01227.01307> macaddr: b8:27:eb:20:0a:4c 
[00002.078] 01227.01307> ip6addr: fe80::ba27:eb4d:fe20:a4c 
[00002.078] 01227.01307> snmaddr: ff02::1:ff20:a4c 
[00002.079] 01227.01307> netsvc: nodename='carol-grope-cozy-squat' 
[00002.079] 01227.01307> netsvc: start 
[00003.491] 01473.02308> lan9514: Link is up - 782d 
magenta$ ls -l 
d  7        0 . 
d  7        0 .. 
d  9        0 dev 
d  7        0 boot 
d  2        0 tmp 
d  2        0 data 
d  2        0 volume 
d  2        0 svc 

Raspberry Pi: turn on, off, blink the Green ACT LED

  • Ubuntu 16.04 LTS
  • Raspberry Pi 3 Model B
Turn on, off, blink the Green ACT LED
# We need root permissions
$ sudo -i
# Turn On
$ echo none > /sys/class/leds/led0/trigger
$ echo 1 > /sys/class/leds/led0/brightness
# Turn Off, echo none to trigger is not required
$ echo 0 > /sys/class/leds/led0/brightness
# Blink
$ echo timer > /sys/class/leds/led0/trigger


Raspberry Pi: key-based authentication

  • Ubuntu 16.04 LTS
  • Raspberry Pi 3 Model B

Key-based authentication is a nice alternative to username/password-based login. Below is a basic process describing how to generate an RSA key pair and install public key on Raspberry Pi.

For more info see How to configure ssh key-based authentication on a linux server, or Securing your Raspberry Pi.

Create RSA key pair
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):        
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:

The key will be created in the ~/.ssh folder by default.

Upload public key to Raspberry Pi
$ cat ~/.ssh/id_rsa.pub | ssh pi@192.168.0.xxx "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Alternatively, use ssh-copy-id:

$ ssh-copy-id pi@192.168.0.xxx
DISABLE PASSWORD authentication (optional)

If higher level of security is required – consider disabling password authentication. Edit the following lines in /etc/ssh/sshd_config as shown below:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
Key-based authentication

Start ssh session as usually, password will not be required:

$ ssh pi@192.168.0.xxx

IoT-DSA: install and run broker-dart

  • Ubuntu 16.04 LTS
  • Dart VM version: 1.23.0 (Fri Apr 21 10:05:24 2017)
Install Dart

Taken from Installing Dart on Linux.

# Enable HTTPS for apt.
$ sudo apt-get update
$ sudo apt-get install apt-transport-https
# Get the Google Linux package signing key.
$ sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
# Set up the location of the stable repository.
$ sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
$ sudo apt-get update
$ sudo apt-get install dart
Install and run broker-dart
$ sudo apth-get intsall https://github.com/IOT-DSA/broker-dart
$ cd broker-dart$ pub get
$ pub global run dsbroker:broker
[INFO][DSA] Listening on HTTP port 8080
[INFO][DSA] Listening on HTTP port 8443

Raspberry Pi: gdb debugging in Eclipse

If you want to do gdb debugging on command line – see Raspberry Pi: gdb debugging, command line.

In case you are interested how to debug Dart command line applications in IntelliJ – see Raspberry Pi: How to remote debug Dart command line applications in IntelliJ.

  • Ubuntu 16.04 LTS
  • Eclipse Neon.3 Release 4.6.3
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Raspberry Pi 3 Model B

Based on this and this GuruCoding pages.

ARM toolchain

See Raspberry Pi: cross-compiling blog.

Install Eclipse IDE for C/C++ developers

Download and install from here.

Create and compile an example project

See Raspberry Pi: cross-compiling in Eclipse blog.

Set up remote access in Eclipse
  • Window > Perspective > Open perspective > Other > Remote System Explorer
  • File > New > Other > Remote System Explorer > Connection
  • Select Remote System Type:
    • Linux
    • Next
  • Remote System Connection:
    • Host name: raspberry-pi
    • Connection name: raspberry-pi
    • Next
  • Files:
    • Configuration: ssh.files
    • Next
  • Processes
    • Configuration: processes-shell-linux
    • Next
  • Shells:
    • Configuration: ssh-shells
    • Next
  • Ssh Terminals:
    • Configuration: ssh.terminals
    • Finish
  • Right click created connection > Properties
    • Host > Default User Id: pi
Create project

In Eclipse:

  • File > New > C++ Project
  • C++ Project
    • Project name: helloworld
    • Project type: Hello World C++ Project
    • Toolchains: Cross GCC
    • Next
  • Basic Settings
    • Hello world greeting: Hello world!
    • Next
  • Select Configurations
    • Next
  • Cross GCC Command
    • Cross compiler prefix: arm-linux-gnueabihf-
    • Cross compiler path: /usr/sbin
    • Finish
  • Right-click project name > Properties > C/C++ Settings
    • Tool Settings > Cross Settings
      • Prefix: arm-linux-gnueabihf-
      • Path: /usr/sbin
  • Project > Build All

Raspberry Pi: how to solve the “version `GLIBCXX_6.0.21′ not found” problem

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Raspberry Pi 3 Model B
Upgrade libstdc++ to 6.0.21

If you use arm-linux-gnueabihf toolchain (see Raspberry Pi: C++ cross-compiling) to build your applications for Raspberry Pi then there is a chance that you’ll have to upgrade your Raspbbery Pi libstdc++ to the toolchain’s version 6.0.21 (or later).


$ scp /usr/arm-linux-gnueabihf/lib/libstdc++.so.6.0.21 pi@192.168.0.xxx:/home/pi

Raspberry Pi:

$ sudo mv libstdc++.so.6.0.21 /usr/lib/arm-linux-gnueabihf/
$ sudo ln -s /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.21 /usr/lib/arm-linux-gnueabihf/libstdc++.so.6

Raspberry Pi: install Dart VM, create and run helloword.dart

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Dart SDK, master 1.24.0-edge.eb1839b8fd453b6c0c93376346743fa96db48440
  • Raspberry Pi 3 Model B
Download and build Dart SDK

See Dart: build Dart SDK for x86 and ARM.

Important: though Raspberry Pi 3 has a 64-bit CPU the Raspbian OS does not support 64-bit builds at the moment of writing – we will build 32-bit Dart SDK for ARM.

Alternatively, you can download pre-built Dart SDK for ARM:

$ wget https://storage.googleapis.com/dart-archive/channels/stable/release/2.2.0/sdk/dartsdk-linux-arm-release.zip.sha256sum
Upgrade libstdc++ to 6.0.21

See Raspberry Pi: how to solve the “version `GLIBCXX_6.0.21′ not found” problem.

Copy Dart VM to Raspbbery Pi


$ cd dart-sdk/sdk
$ scp -r out/ReleaseXARM/dart-sdk/bin/dart pi@192.168.0.xxx:/home/pi

Raspberry Pi:

$ sudo mv dart /usr/local/bin

Restart Raspberry Pi ssh session, then check if Dart VM works:

$ dart --version
Dart VM version: 1.24.0-edge.eb1839b8fd453b6c0c93376346743fa96db48440 (Sun Apr 16 18:04:59 2017) on "linux_arm"
Hello World application

Create helloworld.dart file with the following content:

main() {
  print('Hello world!');

Run the application:

$ dart helloworld.dart 
Hello world!

Dart: build Dart SDK for x86 and ARM

Based on Building Dart, Building Dart SDK for ARM processors and Building Dart SDK for Raspberry Pi.

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Dart SDK, master f6a2fb0050eeaf24706da66bdd73c2f3c9770f96
x86 toolchain

Pre-installed in Ubuntu (16.04 LTS).

ARM 32-bit toolchain

See Raspberry Pi: C++ cross-compiling .

ARM 64-bit toolchain
$ sudo apt-get install g++-aarch64-linux-gnu
Other build tools
$ sudo apt-get install g++ git make python
$ sudo apt-get install g++-multilib
Install Chromium depot_toops
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH="$PATH:$PWD/depot_tools"
Get the source
$ mkdir dart-sdk
$ cd dart-sdk
$ gclient config https://github.com/dart-lang/sdk.git
### Checkout HEAD
$ gclient sync
### Checkout a tag, e.g. 1.9.3
$ gclient sync --revision=1.9.3
Create (if missing) symbolic links

create_sdk build will fail if the following symbolic links are missing:

$ sudo ln -s /usr/include/x86_64-linux-gnu/asm/ /usr/include/asm
$ sudo ln -s /usr/include/x86_64-linux-gnu/bits/ /usr/include/bits
Build 64-bit x86
$ cd dart-sdk/sdk
$ ./tools/build.py --mode release --arch x64 create_sdk
Build 32-bit x86
$ cd dart-sdk/sdk
$ ./tools/build.py --mode release --arch ia32 create_sdk
Build for 32-bit ARM
$ cd dart-sdk/sdk
$ ./tools/build.py --mode release --arch arm create_sdk

The build fails (master #eb1839b):

g++ -MMD -MF x86/obj/runtime/bin/gen_snapshot_dart_io/eventhandler_linux.o.d -DDART_IO_SECURE_SOCKET_DISABLED -D_FORTIFY_SOURCE=2 -DNDEBUG -DTARGET_OS_LINUX -DTARGET_ARCH_ARM -DNDEBUG -DDART_USE_TCMALLOC -DDART_PRECOMPILER -I../../runtime -I../../third_party -I../.. -Ix86/gen -I../../third_party/tcmalloc/gperftools/src -I../../third_party/zlib -m32 -msse2 -mfpmath=sse -fno-exceptions -pthread -Wall -Wextra -Werror -Wendif-labels -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-local-typedefs -O3 -fno-ident -fdata-sections -ffunction-sections -g3 -ggdb3 -Werror -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wvla -Wno-conversion-null -Woverloaded-virtual -g3 -ggdb3 -fno-rtti -fno-exceptions -O3 -fvisibility-inlines-hidden -fno-omit-frame-pointer -fno-rtti -fno-exceptions -c ../../runtime/bin/eventhandler_linux.cc -o x86/obj/runtime/bin/gen_snapshot_dart_io/eventhandler_linux.o
In file included from ../../runtime/vm/simulator_arm.h:19:0,
                 from ../../runtime/vm/simulator.h:15,
                 from ../../runtime/vm/atomic.h:11,
                 from ../../runtime/bin/reference_counting.h:8,
                 from ../../runtime/bin/socket.h:14,
                 from ../../runtime/bin/eventhandler_linux.cc:27:
../../runtime/vm/constants_arm.h:263:17: error: ‘dart::STMP’ defined but not used [-Werror=unused-variable]
 const SRegister STMP = EvenSRegisterOf(DTMP);
cc1plus: all warnings being treated as errors
ninja: build stopped: subcommand failed.

This can be fixed by changing the dart-sdk/sdk/runtime/vm/constants_arm.h file, lines 262-263 from:

const DRegister DTMP = EvenDRegisterOf(QTMP);  
const SRegister STMP = EvenSRegisterOf(DTMP);


const DRegister DTMP __attribute__((unused)) = EvenDRegisterOf(QTMP);  
const SRegister STMP __attribute__((unused)) = EvenSRegisterOf(DTMP);

Raspberry Pi note: This procedure will produce a useful Dart VM – the dart and pub utilities.

Pre-built 32-bit ARM Dart SDK image
$ wget http://share.geomodule.com/dart-sdk-f6a2fb0050eeaf24706da66bdd73c2f3c9770f96.tar.gz
Build for 64-bit ARM
$ cd dart-sdk/sdk
./tools/build.py --mode release --arch arm64 create_sd
Install Dart SDK on Raspberry Pi

Make sure you have correct version of the GLIBCXX library, see here:


# On your build host host
$ cd dart-sdk
$ scp -r sdk/out/ReleaseXARM/dart-sdk pi@192.168.0.xxx:~/dart-sdk
# On Raspberry Pi
# Add the following line at the end of .bashrc
# export PATH=${PATH}:/home/pi/dart-sdk/bin
$ dart --version
Dart VM version: 1.24.0-edge.eb1839b8fd453b6c0c93376346743fa96db48440 (Sun Apr 16 18:04:59 2017) on "linux_arm"
$ pub --version
Pub 1.25.0-edge.511963d71509de50ac577ac22f3bac8d33c17e34

Git: links, cheatsheets, tutorials, etc…

merge and rebase

Atlassian Merge vs Rebase tutorial.

Rename local and remote branch

Taken from here.

### Rename local branch
$ git branch -m new-name
### Rename local branch if you are on a different branch
$ git branch -m old-name new-name
# Remove old remote and push new local branch
$ git push origin :old-name new-name
### Reset upstream branch for thew name, switch to the new local
$ git push origin -u new-name
### Remote
$ git push --delete <remote_name> <branch_name>
### Or
$ git branch -rd <branch_name>
### Local
$ git branch -d <branch_name>
### Squash merge
$ git checkout develop
$ git merge --squash feature/branch
### Revert to a specific commit
$ git checkout -f COMMITID -- .
$ git commit -a

### Revert a specific commit
$ git revert --no-commit COMMITID
git flow

Nice git flow cheatsheet.

git stash

Good tutorial from Atlassian.

git submodules

Good tutorial from Jon Cairns.

Export existing git project to Github/Bitbucket

More details see on How can I export the project in Eclipse to a GitHub repository:

# github
$ git remote add origin git@github.com:<username>/<reponame>.git
# bitbucket
$ git remote add origin https://<username>@bitbucket.org/<username>/<reponame>.git
$ git push -u origin master
Find branch point

Taken from stackoverflow:

$ git log --pretty=oneline master > 1
$ git log --pretty=oneline branch_A > 2
$ git rev-parse `diff 1 2 | tail -1 | cut -c 3-42`^