Quantcast
Channel: 小惡魔 – 電腦技術 – 工作筆記 – AppleBOY
Viewing all articles
Browse latest Browse all 325

在 linkit smart 7688 寫 golang

$
0
0
7688_7688duo 很高興 Mediatek 在去年推出 linkit smart 7688 開發版,你可以把 7688 想成是一台迷你型 Router,如果不來拿開發,也可以當家用 Router 也是不錯的。7688 讓開發者可以在上面寫 Node.js, Python 及 Native C,光是聽到 Node.js 就很興奮,用 JavaScript 控制硬體。但是本篇要介紹如何在 7688 執行 Golang 程式,其實不難,只要把 OpenWrt 支援 gccgolibgo 即可。底下步驟同步於我的 Github Repo

用 Docker 安裝 7688 環境

我建立了一個 Dockerfile,讓開發者可以透過 Docker 快速在任何作業系統產生開發環境,安裝步驟如下:
$ git clone https://github.com/appleboy/linkit-smart-7688-golang.git 
$ cd linkit-smart-7688-golang && docker build -t mt7688 .
開啟 7688 terminal 環境
$ docker run -ti --name 7688 mt7688 /bin/bash

啟動 gccgo 和 libgo

底下步驟教您如何打開 gccgo 及 libgo 選單。打開 package/libs/toolchain/Makefile 找到
define Package/ldd
在前面插入
define Package/libgo
$(call Package/gcc/Default)
  TITLE:=Go support library
  DEPENDS+=@INSTALL_GCCGO
  DEPENDS+=@USE_EGLIBC
endef

define Package/libgo/config
       menu "Configuration"
               depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo

       config LIBGO_ROOT_DIR
               string
               prompt "libgo shared library base directory"
               depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo
               default TOOLCHAIN_ROOT  if !NATIVE_TOOLCHAIN
               default "/"  if NATIVE_TOOLCHAIN

       config LIBGO_FILE_SPEC
               string
               prompt "libgo shared library files (use wildcards)"
               depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo
               default "./usr/lib/libgo.so.*"

       endmenu
endef
找到
define Package/libssp/install
在前面插入
define Package/libgo/install
    $(INSTALL_DIR) $(1)/usr/lib
    $(if $(CONFIG_TARGET_avr32)$(CONFIG_TARGET_coldfire),,$(CP) $(TOOLCHAIN_DIR)/lib/libgo.so.* $(1)/usr/lib/)
endef
找到
$(eval $(call BuildPackage,ldd))
在前面插入
$(eval $(call BuildPackage,libgo))
打開 toolchain/gcc/Config.in 最後面插入
config INSTALL_GCCGO
    bool
    prompt "Build/install gccgo compiler?" if TOOLCHAINOPTS && !(GCC_VERSION_4_6 || GCC_VERSION_4_6_LINARO)
    default n
    help
        Build/install GNU gccgo compiler ?
打開 toolchain/gcc/common.mk 找到
TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)"
取代成
TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)"
打開 Kernel Configuration
$ make menuconfig
  • Target System: Ralink RT288x/RT3xxx
  • Subtarget: MT7688 based boards
  • Target Profile: LinkIt7688
啟動 gccgo
-> Advanced configuration options
-> Toolchain options
-> Select Build/Install gccgo
-> C library implementation
-> Use eglibc

撰寫 golang hello world

Go-brown-side.shalias 設定 mips gccgo 路徑
alias mips_gccgo='/root/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.19/bin/mipsel-openwrt-linux-gccgo -Wl,-R,/root/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.19/lib/gcc/mipsel-openwrt-linux-gnu/4.8.3 -L /root/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.19/lib'
hello world 程式
package main

import "fmt"

func main() {
  fmt.Println("hello world")
}
編譯執行檔
$ mips_gccgo -Wall -o helloworld_static_libgo helloworld.go -static-libgo
在 7688 裝置內執行 helloworld_static_libgo
root@mylinkit:/tmp/7688# ./helloworld_static_libgo 
hello world
以上步驟就可以完成 hello world 程式,詳細步驟都記錄在 linkit-smart-7688-golang

Viewing all articles
Browse latest Browse all 325

Trending Articles


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Tagalog Quotes To Move on and More Love Love Love Quotes


5 Tagalog Relationship Rules


Best Crush Tagalog Quotes And Sayings 2017


Re:Mutton Pies (lleechef)


FORECLOSURE OF REAL ESTATE MORTGAGE


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Patama Quotes : Tagalog Inspirational Quotes


Pamatay na Banat and Mga Patama Love Quotes


Tagalog Long Distance Relationship Love Quotes


BARKADA TAGALOG QUOTES


“BAHAY KUBO HUGOT”


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.