MediaTek MT762 官方发布的不能用,因为他CPU是小端的.刚折腾了下,自己编译. 记录一下.
git clone https://github.com/v2fly/’V2′-core.git cd ‘V2’-core git branch -a git checkout remotes/origin/dev-v4main 使用分支 确定编译参数 我们可以通过查看/proc/cpuinfo来确定cpu的基本信息 [email protected]:~# cat /proc/cpuinfo system type : MediaTek MT7621 ver:1 eco:3 machine : MikroTik RouterBOARD M33G processor : 0 cpu model : MIPS 1004Kc V2.15 BogoMIPS : 586.13 wait instruction : yes microsecond timers : yes tlb_entries : 32 extra interrupt vector : yes hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb] isa : mips1 mips2 mips32r1 mips32r2 ASEs implemented : mips16 dsp mt Options implemented : tlb 4kex 4k_cache prefetch mcheck ejtag llsc pindexed_dcache userlocal vint perf_cntr_intr_bit cdmm perf shadow register sets : 1 kscratch registers : 0 package : 0 core : 0 VPE : 0 VCED exceptions : not available VCEI exceptions : not available
然后我们可以通过file命令来查看一个路由器上可执行文件的文件类型,比如/bin/sh
Fi : ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, corrupted section header size
这里我们可以看到这个可执行文件是LSB,也就是小端序的,MIPS架构的CPU分为大端序和小端序两种,一定要注意区分清楚。所以我们可以确定我们的编译参数为
export GOOS=linux export GOARCH=mipsle
但是这时编译出来的程序很有可能执行的时候出现错误 Illegal instruction
在编译参数中加上 export GOMIPS=softfloat
执行: export GOOS=linux export GOARCH=mipsle export GOMIPS=softfloat go mod tidy go build -o bin/’V2′ -trimpath -ldflags "-s -w -buildid=" ./main go build -o bin/v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main X86 export GOOS=linux export GOARCH=amd64 go build -o bin/’V2′ -trimpath -ldflags "-s -w -buildid=" ./main go build -o bin/v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main
|