openwrt 遍译php,OpenWrt的编写和编译程序

I have a embedded device with MIPS arch working under OpenWRT

system type: MediaTek MT7628AN ver:1 eco:2

machine: WRTnode2P

processor: 0

cpu model: MIPS 24KEc V5.5

I want to compile compile a small program in C through my computer (ubuntu)

#include

int main(void){

printf("HelloWorld");

return 0;

}

To compile it I use mips-linux-gnu-gcc command

mips-linux-gnu-gcc -march=24kec -mabi=32 hello.c -o hello

I send hello program to my device and make a chmod 755

chmod 755 hello

When I try to execute it I have an error

root@openWrt:/www# ./hello

./hello: line 1: syntax error: unexpected word (expecting ")")

I don't understand what's going on, I tried some others command to compile it like with argument: -EB or -EL or not, -static or not, -mabi=32 and not, but I have same problem.

Anyone to help me?

Thanks

[UPDATE]

I send a file command to existing file and this is result

fw3: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, stripped

so I compile my program with this command

mipsel-linux-gnu-gcc -march=24kec -mips32r2 -mips16 hello.c -o hello

now I have this file command result

hello: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, BuildID[sha1]=cd12319441c530606d52d96478719b06a7b215a7, not stripped

Now I read ELF of my remote program

ELF Header:

Magic: 7f 45 4c 46 01 01 01 00 01 00 00 00 00 00 00 00

Class: ELF32

Data: 2's complement, little endian

Version: 1 (current)

OS/ABI: UNIX - System V

ABI Version: 1

Type: EXEC (Executable file)

Machine: MIPS R3000

Version: 0x1

Entry point address: 0x402c40

Start of program headers: 52 (bytes into file)

Start of section headers: 78592 (bytes into file)

Flags: 0x74001005, noreorder, cpic, o32, mips16, mips32r2

Size of this header: 52 (bytes)

Size of program headers: 32 (bytes)

Number of program headers: 10

Size of section headers: 40 (bytes)

Number of section headers: 31

Section header string table index: 30

and this my hello program readelf command

ELF Header:

Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Class: ELF32

Data: 2's complement, little endian

Version: 1 (current)

OS/ABI: UNIX - System V

ABI Version: 0

Type: EXEC (Executable file)

Machine: MIPS R3000

Version: 0x1

Entry point address: 0x4005c0

Start of program headers: 52 (bytes into file)

Start of section headers: 6700 (bytes into file)

Flags: 0x74001007, noreorder, pic, cpic, o32, mips16, mips32r2

Size of this header: 52 (bytes)

Size of program headers: 32 (bytes)

Number of program headers: 11

Size of section headers: 40 (bytes)

Number of section headers: 33

Section header string table index: 30

There is two difference ABI version and in flags there is pic

If I try to launch my hello program I have this error

hello: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

I try to add -static argument but I have this error when I launch my hello program

Illegal instruction

I'm always stuck with this problem.

解决方案

I have a similar issue and fixed it by setting architect to mipsle. I'm using Go to build binary for linux/mips on this device,

system type : MediaTek MT7620A ver:2 eco:6

cpu model : MIPS 24KEc V5.0

isa : mips1 mips2 mips32r1 mips32r2

ASEs implemented : mips16 dsp

It fails on the first time,

macbook:# cat main.go

package main

import (

"fmt"

)

func main() {

fmt.Println("hello, mips")

}

############# Setting GOARCH=mips ============

macbook:# GOOS=linux GOARCH=mips GOMIPS=softfloat go build -o hello-mips

openwrt:# ./hello-mips

./hello-mips: line 1: syntax error: unexpected "("

Then I realized the CPU arch is Little-Endian, not the default Big-Endian. So I changed the build parameter and it successes now.

############# Setting GOARCH=mipsle ============

macbook:# GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -o hello

openwrt:# ./hello

hello, mips

Your CPU model is same as mine and only differs in the revision MIPS 24KEc V5.5, it must also be mipsle (mipsel). Hope it helps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值