The Go Programming Language on the Raspberry Pi


31 posts   Page 1 of 2   1, 2
by ajstarks » Tue Jul 10, 2012 1:28 am
Here are screenshots of using the Go Programming Language (see http://golang.org) on the Raspberry Pi:

1) Running the Go Tour, an in-browser, interactive teaching tool: http://www.flickr.com/photos/ajstarks/7539336658/in/photostream

2) SVGo, a Go language library for generating SVG:
http://www.flickr.com/photos/ajstarks/7451061716/ (running the in-browser "sketching" environment) and http://www.flickr.com/photos/ajstarks/7471726452/in/photostream (running SVGo clients for twitter and Flickr)

The "it's just a Linux" box adage holds true -- once built, the Go toolchain and associated tools work as expected. For example to install the and run the go tour:

$ go get get code.google.com/p/go-tour/gotour
$ gotour

I endorse the idea stated by Andrew Gerrand, Google developer advocate, that "Go would be a fantastic teaching language"
[url](http://www.youtube.com/watch?v=sln-gJaU ... ed#t=3407s)[/url]

I encourage you to watch the entire video to get a sense of the team (for example Rob Pike and Ken Thompson on the same stage) and ideas behind the language.

The Go implementation on the Pi still has a few rough spots, but I'm confident these will be worked out, and I welcome Go to the Raspberry Pi.
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by RadioactiveMouse » Tue Jul 10, 2012 8:04 am
I saw from the Go Wiki that you have installed Go on Debian (wheezy?). Have you tried any other distros?

I've been meaning to try get it going on Arch but lack of building from source experience is making me a tad cautious ;) I've changed the ARM memory split in preparation though.

Could you provide a quick overview for compiling including any command line flags/(+tips)? Also if there are any patches that should be applied maybe a list of those? :D

Really interested in how Go runs on the system and memory usage.

Cheers
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by ajstarks » Wed Jul 11, 2012 4:29 am
I installed on wheezy, have not tried any other distro.

Recipe for building Go on the Raspberry Pi:

Adjust your environment to include:
GOARM=5
GOOS=linux
GOARCH=arm
GOPATH=<root for packages>

$ sudo apt-get install mercurial # get mercurial
$ sudo apt-get install git # for go get ...
$ hg clone -u tip https://code.google.com/p/go # fetch the repo (tip)
$ cd go/src
$ ./all.bash

See: http://golang.org/doc/install/source
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by RadioactiveMouse » Wed Jul 11, 2012 7:55 am
Cheers. I will try it over the weekend and hopefully have a build of Go running on Arch to tinker with :D
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by RadioactiveMouse » Thu Jul 12, 2012 8:13 am
Got it all compiled last night :D

For anyone else wishing to compile via Arch:

Code: Select all
pacman -Syu # makes sure you have the most up to date system to start
pacman -S mercurial # to grab the source
pacman -S git # for go get
pacman -S gcc # for compiling the source

Beware that you should modify your "start.elf" to give the ARM the most amount of RAM possible. ;)
The do exactly what is recommended by @ajstarks for adjusting the environment. *This is crucial!*

Notes:

Dragging the repo down it took a very long time so set yourself aside some or drag it down before you need it.

It took around an hour for me to compile and for the automated tests to run. (1 failed due to out of memory) But despite a failure everything seems to work fine.

Then follow the instructions from the Go Wiki regarding the "hello world" example to ensure your compilation is correctly installed.

I also had to do the following to make it work:

Modify the $PATH to include "/go/bin/"
Redefine the GOARM=5 environment variable to make the example build. (this is for if you get an illegal instruction error)

If I have to recompile it again I may experiment with overclocking slightly to see if I can drag the build time down a bit. My SD card is also only Class 4 so that may be a bottle neck also....
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by ajstarks » Thu Jul 12, 2012 12:00 pm
Yes, my build took 51 minutes.

Note that the ARM fixes are under review now: http://codereview.appspot.com/6344078/
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by MaStr » Thu Jul 19, 2012 7:30 pm
Hi,
ok, everybody building his own go package is one solution. But there is already a dev/golang package in the package tree... This seems not functional.

pi@raspberrypi ~/go/src $ go
SIGILL: illegal instruction
PC=0x7d394

math.init·1()
/usr/lib/go/src/pkg/math/pow10.go:34 +0x28
math.init()
/usr/lib/go/src/pkg/math/unsafe.go:21 +0x70
strconv.init()
/usr/lib/go/src/pkg/strconv/quote.go:441 +0x70
go/parser.init()
/usr/lib/go/src/pkg/go/parser/parser.go:2349 +0x78
main.init()
/usr/lib/go/src/cmd/go/vet.go:37 +0x78

goroutine 2 [runnable]:
created by runtime.main
/build/golang-4n61xa/golang-1.0.2/src/pkg/runtime/proc.c:221

trap 0x6
error 0x0
oldmask 0x0
r0 0x86c5b0
r1 0x0
r2 0x0
r3 0x0
r4 0x0
r5 0x0
r6 0x0
r7 0x0
r8 0x0
r9 0x45e29c
r10 0x10953000
fp 0x86c172
ip 0xcafebabe
sp 0x401d9e4c
lr 0x7d928
pc 0x7d394
cpsr 0x20000010
fault 0x0


Let's repair that instead of everybody doing it on their own.

Does anybody know why the package dumps?
Who or How can we fix this package?

Matthias
Posts: 3
Joined: Thu Jul 19, 2012 7:27 pm
by tburke » Fri Jul 20, 2012 2:25 am
Matthias,

I'm not familiar with the Debian packaging system, but that looks like a floating point issue. I ran into the same thing after I installed on Raspbian. Wheezy, with software floating point, worked fine.

There is a discussion on the golang-nuts forum about the problem, go assumes there is support for a floating point instruction on ARM processors with hardware floating point. The RaspberryPi ARM chip does not implement that instruction. One workaround is to build go with GOARM=5.

https://groups.google.com/d/msg/golang- ... vrM0WmYfsJ
Posts: 1
Joined: Fri Jul 20, 2012 2:15 am
by RadioactiveMouse » Fri Jul 20, 2012 8:07 am
@Matthias

If you're getting the illegal instruction try setting GOARM=5 again in your environment variables and it should clear the issue as mentioned above. ;)
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by ajstarks » Sat Jul 21, 2012 3:27 pm
If you apply the patches here: https://gist.github.com/3116118 you will not need to set GOARM=5.
I have tested this build on the latest hardware-float Raspbian based wheezy distribution:

pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l GNU/Linux
pi@raspberrypi ~ $ go version
go version weekly.2012-03-27 +d2213960ade2
pi@raspberrypi ~ $ cat hello.go
package main
import "fmt"

func main() {
fmt.Println("hello, Raspberry Pi")
}
pi@raspberrypi ~ $ go run hello.go
hello, Raspberry Pi
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by jonskeet » Sat Jul 21, 2012 10:26 pm
RadioactiveMouse wrote:@Matthias

If you're getting the illegal instruction try setting GOARM=5 again in your environment variables and it should clear the issue as mentioned above. ;)


I'm having the same problem - and that didn't fix it :(

Code: Select all
[jon@fruity ~]$ export
declare -x GOARCH="arm"
declare -x GOARM="5"
declare -x GOOS="linux"
declare -x GOPATH="/home/jon/go"
But...
Code: Select all
[jon@fruity ~]$ go run hello.go
SIGILL: illegal instruction
PC=0x7bd10
I'm running Arch on my Pi, and I just installed the package with pacman:
Code: Select all
community/go 2:1.0.1-6 [installed]
    Google Go compiler and tools (release version)

Any more suggestions, or do I basically have a choice between waiting for a package update, or building from source myself? (The latter would be okay, but I'd prefer to just stick to packages...)
Posts: 2
Joined: Thu Jul 19, 2012 5:42 am
by ajstarks » Sat Jul 21, 2012 10:47 pm
As of now, the best option is to build from source.
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by MaStr » Sat Jul 21, 2012 11:00 pm
Hi,
I posted a support thread @ Raspian-Subforum. Should be fixed in normal package tree to not confuse somebody new. :)

kind regards
Matthias
Posts: 3
Joined: Thu Jul 19, 2012 7:27 pm
by RadioactiveMouse » Mon Jul 23, 2012 9:39 am
jonskeet wrote:
RadioactiveMouse wrote:@Matthias

If you're getting the illegal instruction try setting GOARM=5 again in your environment variables and it should clear the issue as mentioned above. ;)


I'm having the same problem - and that didn't fix it :(

Code: Select all
[jon@fruity ~]$ export
declare -x GOARCH="arm"
declare -x GOARM="5"
declare -x GOOS="linux"
declare -x GOPATH="/home/jon/go"
But...
Code: Select all
[jon@fruity ~]$ go run hello.go
SIGILL: illegal instruction
PC=0x7bd10
I'm running Arch on my Pi, and I just installed the package with pacman:
Code: Select all
community/go 2:1.0.1-6 [installed]
    Google Go compiler and tools (release version)

Any more suggestions, or do I basically have a choice between waiting for a package update, or building from source myself? (The latter would be okay, but I'd prefer to just stick to packages...)


Mmmm that's strange. I compiled from source rather than using Pacman so maybe it's an issue with the package?

Mine is fine apart from the aforementioned issue having to explicitly set the environment variable. Haven't had time to really experiment so following @ajstarks advice is probably the way to go ;)

Hopefully the patch will make the mainstream package allowing people to get started on Go on the Pi easier :D

EDIT: Just clicked through to the link and realised it is a problem with the package :o
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by djhuk » Sun Jul 29, 2012 9:30 am
jonskeet wrote:
RadioactiveMouse wrote:@Matthias

If you're getting the illegal instruction try setting GOARM=5 again in your environment variables and it should clear the issue as mentioned above. ;)


I'm having the same problem - and that didn't fix it :(

Code: Select all
[jon@fruity ~]$ export
declare -x GOARCH="arm"
declare -x GOARM="5"
declare -x GOOS="linux"
declare -x GOPATH="/home/jon/go"
But...
Code: Select all
[jon@fruity ~]$ go run hello.go
SIGILL: illegal instruction
PC=0x7bd10
I'm running Arch on my Pi, and I just installed the package with pacman:
Code: Select all
community/go 2:1.0.1-6 [installed]
    Google Go compiler and tools (release version)

Any more suggestions, or do I basically have a choice between waiting for a package update, or building from source myself? (The latter would be okay, but I'd prefer to just stick to packages...)


I think your GOPATH might be wrong, when I tried doing the following I got this warning

Code: Select all
pi@raspberrypi ~ $ export GOPATH=/home/pi/go
pi@raspberrypi ~ $ go run test.go
warning: GOPATH set to GOROOT (/home/pi/go) has no effect
Hello, 世界


Changing it to the bin folder removed that warning and made it work....

Code: Select all
pi@raspberrypi ~ $ export GOPATH=/home/pi/go/bin
pi@raspberrypi ~ $ go run test.go
Hello, 世界
pi@raspberrypi ~ $ go build test.go
pi@raspberrypi ~ $ ./test
Hello, 世界
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by liamgh » Thu Sep 06, 2012 10:04 am
Hi everyone,

Managed to get the Raspbian packages for Go to work by rebuilding them with the modified GOARM setting. Have written it all up on my blog: http://www.greenhughes.com/content/how-get-go-going-raspberry-pi Hope this is useful!
Posts: 1
Joined: Thu Sep 06, 2012 9:11 am
by BrandonAGr » Thu Sep 06, 2012 3:58 pm
Has anyone gotten GPIO or I2C access working in Go?

If not could anyone recommend a good place to start implementing support? Would porting some GPIO C code into Go work? I'm new to Go but would like to try it out for implementing the software for the project I'm working on.
Posts: 6
Joined: Sat Sep 01, 2012 7:42 pm
by robodonut » Mon Sep 10, 2012 10:50 pm
For all the Arch users, I made a package with the patch (posted above) already applied:
http://archlinuxarm.org/forum/viewtopic.php?f=31&t=3679
Posts: 2
Joined: Mon Sep 10, 2012 10:48 pm
by ajstarks » Mon Sep 10, 2012 11:21 pm
Another Go ARM fix under review: http://codereview.appspot.com/6501099/
This update provides better runtime support.
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by robodonut » Tue Sep 11, 2012 5:35 pm
BrandonAGr wrote:Has anyone gotten GPIO or I2C access working in Go?

If not could anyone recommend a good place to start implementing support? Would porting some GPIO C code into Go work? I'm new to Go but would like to try it out for implementing the software for the project I'm working on.

Have you looked into "cgo"? It's part of the go toolchain.
Posts: 2
Joined: Mon Sep 10, 2012 10:48 pm
by softboyled » Tue Sep 18, 2012 10:54 pm
I am running Raspbian and followed Liam's (?) instructions here:

http://www.greenhughes.com/content/how- ... spberry-pi

I got the SIGILL when I was done, but properly setting the GOROOT and GOPATH env variables seems to have fixed it.

Take particular care that GOROOT points to the parent of the directory where all.bash is found.

Mine looks like this, for better or worse:

declare -x GOROOT="/usr/src/golang/golang-1.0.2"

My thanks to Liam, BTW.

Cheers,
Greg
Posts: 1
Joined: Tue Sep 18, 2012 10:38 pm
by ajstarks » Tue Sep 25, 2012 11:50 pm
Dave Cheney has posted a nice review on installing Go on your Raspberry Pi. The posting covers initial setup as well as building from source (no need to set the GOARM variable now)

http://dave.cheney.net/2012/09/25/insta ... spberry-pi
User avatar
Posts: 81
Joined: Fri Jun 22, 2012 2:14 am
by RadioactiveMouse » Thu Oct 04, 2012 11:51 am
Yes Dave Cheny's post looks 100x better than the hoops that were required initially to install Go.

Hopefully more people will get this installed now ;)
Posts: 21
Joined: Wed Nov 16, 2011 10:48 am
by eix » Sun Jan 27, 2013 10:12 am
As of today, still same behavior with golang package on raspbian:

Code: Select all
SIGILL: illegal instruction
PC=0x7d394

math.init��()
        /usr/lib/go/src/pkg/math/pow10.go:34 +0x28
math.init()
        /usr/lib/go/src/pkg/math/unsafe.go:21 +0x70
strconv.init()
        /usr/lib/go/src/pkg/strconv/quote.go:441 +0x70
go/parser.init()
        /usr/lib/go/src/pkg/go/parser/parser.go:2349 +0x78
main.init()
        /usr/lib/go/src/cmd/go/vet.go:37 +0x78

goroutine 2 [runnable]:
created by runtime.main
        /build/golang-FunV5r/golang-1.0.2/src/pkg/runtime/proc.c:221

trap    0x6
error   0x0
oldmask 0x0
r0      0x86c5b0
r1      0x0
r2      0x0
r3      0x0
r4      0x0
r5      0x0
r6      0x0
r7      0x0
r8      0x0
r9      0x45e29c
r10     0x10953000
fp      0x86c172
ip      0xcafebabe
sp      0x400efe4c
lr      0x7d928
pc      0x7d394
cpsr    0x20000010
fault   0x0


I will use Dave Cheney's tutorial
User avatar
Posts: 82
Joined: Sat Sep 15, 2012 8:09 am
by eix » Sun Jan 27, 2013 11:06 am
By the way, this patch is no more applicable, does somebody know if it's still needed?
User avatar
Posts: 82
Joined: Sat Sep 15, 2012 8:09 am