This is a creation in Article, where the information may have evolved or changed.
Online to see a lot of information found are very outdated, basic is compiled with https://github.com/gomini/go-mips32 .
But go1.9 long-time support MIPS, set the compilation parameters, start build, at this time in the go/pkg will appear linux_mips directory, is the compilation environment, the other same.
- GOOS is the operating system where your application will run the platform
- Goarch is the processor architecture in which your application will run the platform.
The valid $GOOS and $GOARCH combined are as follows:
$GOOS $GOARCH Android Arm Darwin386Darwin AMD64 Darwin Arm Darwin arm64 Dragonfly AMD64 FreeBSD386FreeBSD amd64 FreeBSD arm Linux386Linux amd64 linux arm linux arm64 linux PPC64 linux ppc64le Linux MIPS Linux mipsle linux mips64 linux mips64le NetBSD386NetBSD amd64 NetBSD arm OpenBSD386OpenBSD amd64 OpenBSD arm plan9386plan9 amd64 Solaris amd64 Windows386Windows AMD64
1. First connect to the router via putty, look at the Router CPU architecture, I connect wr720n-v3 here, such as, visible that the router CPU is MIPS architecture
Cat/proc/cpuinfo
2.go can set the running schema and system of the compiled program through Goarch and GOOS, so the environment is set at compile time as follows:
I was in window7 under Liteide compile, directly add an environment file (LITEIDE32.1\SHARE\LITEIDE\LITEENV\LINUX32-MIPS.ENV):
Goarch=Mipsgoos=linux
3.golang write the following code, direct build, do not run:
Package Mainimport ("FMT" " Time") Func main () { for{fmt. Println ("1111") time. Sleep (1*Time . Second) for{time. Sleep (1*Time . Second) fmt. Println ("2222") Break } }}
4. Use WINSCP to put the program file "Openwrttest" into the openwrt system, where it is placed in/TMP, set the file permissions:
777 -r/tmp/openwrttest
5. Run the file and get it done. If you have already entered the TMP directory, use the./openwrttest
/tmp/openwrttest