├── Dockerfile ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04.3 2 | 3 | MAINTAINER Bo-Yi Wu 4 | 5 | RUN apt-get update 6 | RUN apt-get -y install git g++ make libncurses5-dev subversion libssl-dev gawk libxml-parser-perl unzip wget python xz-utils 7 | RUN cd /root && git clone git://git.openwrt.org/15.05/openwrt.git 8 | 9 | WORKDIR /root/openwrt 10 | 11 | RUN cp feeds.conf.default feeds.conf 12 | RUN echo src-git linkit https://github.com/MediaTek-Labs/linkit-smart-7688-feed.git >> feeds.conf 13 | RUN ./scripts/feeds update 14 | RUN ./scripts/feeds install -a 15 | 16 | CMD /bin/bash 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Bo-Yi Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linkit-smart-7688-golang 2 | 3 | Build static binary using [golang](https://golang.org/) for linkit smart 7688. 4 | 5 | ## What's MT7688 6 | 7 | 802.11n 1T1R Wi-Fi AP SoC, Home Automation Bridge. Please refer to detail information abount [linkit smart 7688](http://www.mediatek.com/en/products/connectivity/wifi/home-network/wifi-ap/mt7688ka/). 8 | 9 | ## Installation 10 | 11 | Please follow the [linkit smart 7688 feed](https://github.com/MediaTek-Labs/linkit-smart-7688-feed) instructions or using the docker as below: 12 | 13 | ```bash 14 | $ git clone https://github.com/appleboy/linkit-smart-7688-golang.git 15 | $ cd linkit-smart-7688-golang && docker build -t mt7688 . 16 | ``` 17 | 18 | Start the `7688` terminal. 19 | 20 | ```bash 21 | $ docker run -ti --name 7688 mt7688 /bin/bash 22 | ``` 23 | 24 | ## Update Source Code 25 | 26 | open `package/libs/toolchain/Makefile` file 27 | 28 | find 29 | 30 | ```makefile 31 | define Package/ldd 32 | ``` 33 | 34 | insert before 35 | 36 | ```makefile 37 | define Package/libgo 38 | $(call Package/gcc/Default) 39 | TITLE:=Go support library 40 | DEPENDS+=@INSTALL_GCCGO 41 | DEPENDS+=@USE_EGLIBC 42 | endef 43 | 44 | define Package/libgo/config 45 | menu "Configuration" 46 | depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo 47 | 48 | config LIBGO_ROOT_DIR 49 | string 50 | prompt "libgo shared library base directory" 51 | depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo 52 | default TOOLCHAIN_ROOT if !NATIVE_TOOLCHAIN 53 | default "/" if NATIVE_TOOLCHAIN 54 | 55 | config LIBGO_FILE_SPEC 56 | string 57 | prompt "libgo shared library files (use wildcards)" 58 | depends EXTERNAL_TOOLCHAIN && PACKAGE_libgo 59 | default "./usr/lib/libgo.so.*" 60 | 61 | endmenu 62 | endef 63 | ``` 64 | 65 | find 66 | 67 | ```makefile 68 | define Package/libssp/install 69 | ``` 70 | 71 | insert before 72 | 73 | ```makefile 74 | define Package/libgo/install 75 | $(INSTALL_DIR) $(1)/usr/lib 76 | $(if $(CONFIG_TARGET_avr32)$(CONFIG_TARGET_coldfire),,$(CP) $(TOOLCHAIN_DIR)/lib/libgo.so.* $(1)/usr/lib/) 77 | endef 78 | ``` 79 | 80 | find 81 | 82 | ```makefile 83 | $(eval $(call BuildPackage,ldd)) 84 | ``` 85 | 86 | insert before 87 | 88 | ```makefile 89 | $(eval $(call BuildPackage,libgo)) 90 | ``` 91 | 92 | open `toolchain/gcc/Config.in` file. Insert the following code to bottom: 93 | 94 | ```makefile 95 | config INSTALL_GCCGO 96 | bool 97 | prompt "Build/install gccgo compiler?" if TOOLCHAINOPTS && !(GCC_VERSION_4_6 || GCC_VERSION_4_6_LINARO) 98 | default n 99 | help 100 | Build/install GNU gccgo compiler ? 101 | ``` 102 | 103 | open `toolchain/gcc/common.mk` file. 104 | 105 | find 106 | 107 | ```makefile 108 | TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)" 109 | ``` 110 | 111 | replace 112 | 113 | ```makefile 114 | TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)" 115 | ``` 116 | 117 | Prepare the kernel configuration to inform OpenWrt that we want to build an firmware for LinkIt Smart 7688: 118 | 119 | ```bash 120 | $ make menuconfig 121 | ``` 122 | 123 | Select the options as below: 124 | 125 | * Target System: Ralink RT288x/RT3xxx 126 | * Subtarget: MT7688 based boards 127 | * Target Profile: LinkIt7688 128 | 129 | Build [gccgo](https://golang.org/doc/install/gccgo): 130 | 131 | ``` 132 | -> Advanced configuration options 133 | -> Toolchain options 134 | -> Select Build/Install gccgo 135 | -> C library implementation 136 | -> Use eglibc 137 | ``` 138 | 139 | Start the compilation process: 140 | 141 | ```bash 142 | $ make V=s 143 | ``` 144 | 145 | ## Write your first golang program 146 | 147 | Add an alias with your toolchain path information. This keeps it easy to call gccgo. 148 | 149 | ```bash 150 | 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' 151 | ``` 152 | 153 | helloworld.go 154 | 155 | ```go 156 | package main 157 | 158 | import "fmt" 159 | 160 | func main() { 161 | fmt.Println("hello world") 162 | } 163 | ``` 164 | 165 | build your go program 166 | 167 | ```bash 168 | mips_gccgo -Wall -o helloworld_static_libgo helloworld.go -static-libgo 169 | ``` 170 | 171 | run your program on 7688 device 172 | 173 | ```bash 174 | root@mylinkit:/tmp/7688# ./helloworld_static_libgo 175 | hello world 176 | ``` 177 | --------------------------------------------------------------------------------