開源龍芯loongson智龍主板V2.0程序putty登陸、交叉編譯、Series鏈接、telnet鏈接使用、DNS開啓ping通

交叉編譯:在x86 CPU環境下編譯適用於MIPS CPU架構的二進制程序html

所需環境:x86(32位)linux系統【注意,必定得是32位的,否則沒法使用提供的32位mips交叉編譯程序。並且,智龍上的芯片也是32位的。以前安裝64位的結果編譯出來的程序也是64的,形成運行失敗】linux

 

編譯好的程序經過USB線鏈接,經過putty使用Series模式登陸到龍芯智龍的linux操做系統:c++

設置上注意Flow Control和通信Speed爲115200git

 

這裏給出一個benchmark程序:shell

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>


int main(){
    int t, len1, len2;
    len1 = 181000000;
    len2 = 81000000;
    struct timeval start, end;
    gettimeofday( &start, NULL );
    for(t=0;t<len1;t++);
    gettimeofday( &end, NULL );printf("%d times Empty loop need: %d us (%.3f ms)\n", len1, (int) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec), (float) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec) / 1000.0);

    long a=0;
    gettimeofday( &start, NULL );
    for(t=0;t<len2;t++){
       a = a + 1;
    };
    gettimeofday( &end, NULL );printf("%d times + need: %d us (%.3f ms)\n", len2, (int) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec), (float) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec) / 1000.0);


    double b=39.2;
    gettimeofday( &start, NULL );
    for(t=0;t<len2;t++){
       b = b + 1.0;
       b = b * 0.99;
    };
    gettimeofday( &end, NULL );printf("%d times +* need: %d us (%.3f ms)\n", len2, (int) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec), (float) (1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec) / 1000.0);
    return 0;
}

編譯命令爲:ubuntu

編譯爲x86程序:
gcc benchmark.c -o benchmark_x86

編譯爲MIPS程序:
mipsel-linux-gcc benchmark.c -o benchmark_mips

注意:putty剛鏈接上智龍開發板的時候,是一片漆黑的,這時候會誤覺得還在鏈接中,一直等着。其實按一下回車就進入到shell界面了……真是囧死vim

 

 

出現bus error和segment fault是同理的,mips上是bus error

開啓網絡bash

ifconfig eth0 up

設置靜態IP網絡

ifconfig eth0 192.168.3.2

【注意】這裏不能直接經過設置靜態IP來啓動網卡,必須先eth up再eth ip地址,不然ping不通,找不到網絡。架構

跟電腦端網線直連(不經過路由器),電腦端只須要設置
IP地址
192.168.3.1
子網掩碼
255.255.255.0


這兩個便可

設置完後,經過putty連接,連接方式選擇telnet便可
登陸帳戶爲root,若是沒改過是不須要密碼的

【設置動態獲取DNS】

此時雖然設置了靜態ip,咱們會發覺咱們ping內網ping得通,外網徹底不行,dns也所有失效沒法解析www.baidu.com等域名。這就須要開啓動態dhc客戶端,自動更新ip地址以及dns:

修改以下文件:

# 若是是debian系統,則應該修改這個文件:
vi /etc/network/interfaces
# 若是是ubuntu系統,則應該修改這個文件:
vim /etc/sysconfig/network-scripts/ifcfg-eth1

添加以下代碼:

# 啓動系統激活設備.
# Loop迴環地址.
auto lo
iface lo inet loopback

# 啓動系統激活設備.
# 網卡eth0設置爲DHCP類型.
auto eth0
iface eth0 inet dhcp

添加後須要重啓網絡服務:

/etc/init.d/networking restart
若是發覺重啓networking後不起做用,能夠嘗試執行如下語句:

dhclient eth1

若是還不行,嘗試以下配置再重啓:

# DNS地址設置
vi /etc/resolv.conf

# 必須設置.不然沒法訪問任何URL
nameserver x.x.x.x
nameserver x.x.x.x

 

 

 

編譯大型帶configure的項目的時候,須要注意工具鏈等一系列問題,例如編譯openssh,參考編譯代碼以下:

./configure --with-zlib=/home/liangzulin/Downloads/zlib-1.2.11/ --host=mipsel-linux --with-cflags=-I/home/liangzulin/Downloads/openssl/include --with-ldflags=-L/home/liangzulin/Downloads/openssl/final_mips_openssl
make CC="mipsel-linux-gcc" AR="mipsel-linux-ar rc" RANLIB="mipsel-linux-ranlib"

一鍵拷貝全部生成的可執行文件:

for i in scp ssh ssh-keyscan sshd sftp ssh-add ssh-keysign sftp-server ssh-keygen ssh-pkcs11-helper; do cp $i mipsel_file_2/; done;

小插曲:使用的kylin ubuntu系統缺少vim,而後apt源也比較舊了

 

 

 

【傳輸文件的問題】

因爲沒有SSH,傳輸文件暫時比較麻煩。咱們能夠交叉編譯一個小工具,使用xshell來解決:

lrzsz is a portable and fast implementation of the X/Y/Zmodem protocols.

Linux上安裝rz和sz命令

 

 

老版本的debian系統可能不含gcc,可是含有cpp、cc一、as、ld等編譯工具鏈,能夠採用以下方式編譯:

mipsel-linux-cpp hello_mips_test.c -o hello_mips_test.i
mipsel-linux-c++ hello_mips_test.i -o hello_mips_test.s
mipsel-linux-as hello_mips_test.s -o hello_mips_test.o
mipsel-linux-ld hello_mips_test.o -o hello_mips_test.out

四個步驟的說明:

Gcc的編譯流程分爲了四個步驟

龍芯社區開源項目源碼庫

相關文章
相關標籤/搜索