Random posts about coding

Mostly blogging about dart.

Build and Deploy Dart to Beaglebone Black

| Comments

I was looking into using dart on Beaglebone Black and decided it would be useful to share with others what I found.

After a some build hacks and patches I found a minimal working solution for Beaglebone Black with Debian ARMhf. A few important notes before going down the road of building dart for ARM. The dart-sdk is not fully supported and pub currently might not work. The dartanalyzer might not work. The only supported ARM architectures are the ones that have ARMv7 with VFP. Don’t spin your wheels trying to target any architecutre that is not ARMv7 with VFP (minimum at the moment ARMv7-A) unless you plan on implementing the routines needed in the runtime arm assembler. If you do plan on implementing them, well thats just pure awesome!

assembler_arm.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void CPUFeatures::InitOnce() {
#if defined(USING_SIMULATOR)
  integer_division_supported_ = true;
  neon_supported_ = true;
#else
  ASSERT(CPUInfoContainsString("ARMv7"));  // Implements ARMv7.
  ASSERT(CPUInfoContainsString("vfp"));  // Has floating point unit.
  // Has integer division.
  if (CPUInfoContainsString("QCT APQ8064")) {
    // Special case for Qualcomm Krait CPUs in Nexus 4 and 7.
    integer_division_supported_ = true;
  } else {
    integer_division_supported_ = CPUInfoContainsString("idiva");
  }
  neon_supported_ = CPUInfoContainsString("neon");
#endif  // defined(USING_SIMULATOR)
#if defined(DEBUG)
  initialized_ = true;
#endif
}

Download Ubuntu 12.04.3 LTS

Download the desktop iso to install on VirtualBox.

Install on VirtualBox

I work mostly on mac so Ubuntu installed on VirtualBox was needed to help with cross compiling and flashing of uSD cards.

Update the packages

Just to be safe update any Ubuntu packages before installing the development software.

Install basic packages

I typically use the git overlay on subversion when working with the dart repo. The java jre/jdk is required for building the dart_analyzer which does not work in the sdk.

shell
1
2
# Install subversion 
sudo apt-get install subversion git git-svn openssh-server vim default-jre default-jdk

Install the chrome build and arm dependencies

Checkout the latest build tools scripts. The following scripts prep your system with any packages needed for building dart.

shell
1
2
3
4
5
6
7
# checkout build scripts
svn co http://src.chromium.org/chrome/trunk/src/build; cd build

# install dependencies
chmod u+x install-build-deps.sh
./install-build-deps.sh --no-chromeos-fonts
./install-build-deps.sh --no-chromeos-fonts --arm

Install addtional libraries

The following libraries are needed for building dart but might not be included from the chrome build tool scripts.

shell
1
2
# Install addtional libs
sudo apt-get install libc6-dev-i386 g++-multilib

Install depot-tools

depot-tools is required for hacking out the dart source code.

shell
1
2
3
# depot tools
svn co http://src.chromium.org/svn/trunk/tools/depot_tools
export PATH=$PATH:`pwd`//depot_tools

Checkout the dart code base

You dont need to include --username <YOUR USERNAME> unless you plan on creating a CL for review.

shell
1
2
3
4
5
6
7
mkdir dart_bleeding
cd dart_bleeding
svn ls https://dart.googlecode.com/svn/branches/bleeding_edge/ --username <YOUR USERNAME>
gclient config https://dart.googlecode.com/svn/branches/bleeding_edge/deps/all.deps
git svn clone -rHEAD https://dart.googlecode.com/svn/branches/bleeding_edge/dart dart
gclient sync
gclient runhooks

Patch the gyp and version files

A git patch can be found here 7725354, that patches the build scripts to support building the dart-sdk for ARM. Patching the VERSION file was done in an attempt to get pub working. At the moment its not required. If not done then an old version number is baked into the dartvm. This patch also modifies which dartvm creates the snapshots for pub, dart2js and a wrapper util. Patch creates the requirement of having to build the dartvm for x64 before building the dart-sdk for ARM. The dart build scripts have a funky dependency of wanting to use the dartvm target to create the snapshot files. Which in this case wont work since our dartvm is an ARM target being built on x64.

arm.build.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
diff --git a/tools/VERSION b/tools/VERSION
index d1ab212..0d6101d 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -1,5 +1,5 @@
 CHANNEL be
-MAJOR 0
-MINOR 1
-BUILD 2
-PATCH 0
+MAJOR 1
+MINOR 0
+BUILD 0
+PATCH 7
diff --git a/utils/compiler/compiler.gyp b/utils/compiler/compiler.gyp
index 294c7e9..5f3754a 100644
--- a/utils/compiler/compiler.gyp
+++ b/utils/compiler/compiler.gyp
@@ -18,7 +18,7 @@
         {
           'action_name': 'generate_snapshots',
           'inputs': [
-            '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
+            '<(PRODUCT_DIR)/../DebugX64/dart',
             '../../sdk/lib/_internal/libraries.dart',
             '<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../sdk/lib/_internal/compiler", "../../runtime/lib", "../../sdk/lib/_internal/dartdoc"])',
             'create_snapshot.dart',
@@ -30,7 +30,7 @@
             '<(SHARED_INTERMEDIATE_DIR)/dart2js.dart.snapshot',
           ],
           'action': [
-            '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
+            '<(PRODUCT_DIR)/../DebugX64/dart',
             'create_snapshot.dart',
             '--output_dir=<(SHARED_INTERMEDIATE_DIR)',
             '--dart2js_main=sdk/lib/_internal/compiler/implementation/dart2js.dart',
diff --git a/utils/pub/pub.gyp b/utils/pub/pub.gyp
index fd5e147..ab2e243 100644
--- a/utils/pub/pub.gyp
+++ b/utils/pub/pub.gyp
@@ -25,7 +25,7 @@
             '<(SHARED_INTERMEDIATE_DIR)/pub.dart.snapshot',
           ],
           'action': [
-            '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
+            '<(PRODUCT_DIR)/../DebugX64/dart',
             '--package-root=<(PRODUCT_DIR)/packages/',
             '--snapshot=<(SHARED_INTERMEDIATE_DIR)/pub.dart.snapshot',
             '../../sdk/lib/_internal/pub/bin/pub.dart',

Build the dart-sdk

Building of the dart-sdk for ARM target is a two stop process. First build x64 so we can use that dartvm to generate the snapshot files. Then the second step is running the create_sdk build for ARM. When the build is finished the out/ReleaseARM/dart-sdk should contain a full dart-sdk build. Keep in mind this does build the dartanalyzer but it may not work on ARM.

shell
1
2
3
4
5
# build a target for your native system to create the snapshot files. 
./tools/build.py -m debug -v -a x64 -j 8

# build the arm target
./tools/build.py -m release -v -a arm -j 8 create_sdk

Tarball the sdk

Package up the dart-sdk as a tarball to distribute.

shell
1
2
cd ./out/ReleaseARM/
tar -czvf dart-sdk.tar.gz dart-sdk

Install Debian Wheezy 7.2 Hard Float Minimal Image on Beaglebone Black

In virtualbox with a uSD card at /dev/sdX the following will download an image and write to the uSD card. Updated images can be found at armhf

shell
1
2
wget http://s3.armhf.com/debian/wheezy/bone/debian-wheezy-7.2-armhf-3.8.13-bone30.img.xz
xz -cd debian-wheezy-7.2-armhf-3.8.13-bone30.img.xz > /dev/sdX

Then insert the uSD card into the Beaglebone Black and boot the image by holding down the boot switch and powering on.

Write the booted image to the eMMC.

shell
1
xz -cd debian-wheezy-7.2-armhf-3.8.13-bone30.img.xz > /dev/mmcblk1

Power down and remove the uSD card.

Update glibc on the BeagleBone Black

Updating glibc is required cause the version of glibc installed from the chromium build scripts is greater then the one shipped with Wheezy 7.2. The following commands update glibc.

shell
1
2
3
4
5
6
7
8
# Add an addtional source for the latest glibc
sudo sed -i '1i deb http://ftp.us.debian.org/debian/ jessie main' /etc/apt/sources.list

# Update sources 
sudo apt-get update

# Download latest glibc
sudo DEBIAN_FRONTEND=noninteractive apt-get -t jessie install -y libc6 libc6-dev libc6-dbg git screen

Copy over dart-sdk

From virtual box copy over the tarball to Beaglebone Black running debian.

shell
1
scp dart-sdk.tar.gz debian@192.168.2.2:~/

After the tarball is copied, uncompress and add to your PATH.

shell
1
2
3
4
tar -zxvf dart-sdk.tar.gz
export PATH=~/dart-sdk:$PATH
dart --version
Dart VM version: 1.0.0.7_r30634_adam (Fri Nov 29 01:14:42 2013) on "linux_arm"

Known issues at the moment

Pub does not work, issue could be followed at 15383. I was testing this out while staying at a hotel so some proxy settings might of been blocking or tripping up pub.

Feedback

If you have a better way of running dart on Beagleblone Black I would love to hear it! Please contact me on g+ and lets discuss.

Update on dartanalyzer

dartanalyzer will work after installing the default-jre on Beaglebone Black.

shell
1
sudo apt-get install default-jre

Addtional resources

Comments