rust 小米R3G官方rom(openwrt) openssl


小米R3G openwrt交叉編譯

整體流程:

1.去openwrt官網下載對應的交叉編譯sdk,用c語言測試ok

2.設置rust 為nightly版本,並用xargo代替cargo構建項目(因為rust正式版的target不支持mipsel-unknown-linux-uclibc)

3.有的rust項目需要openssl依賴,所以交叉編譯 openssl

host: ubuntu18.04
target: openwrt 15.05.1

https://openwrt.org/toh/hwdata/xiaomi/xiaomi_miwifi_3g_v2                //小米r3g硬件信息
http://downloads.openwrt.org/
https://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/        //交叉編譯sdk下載頁面

ssh登陸到小米R3G
uname -a //查看架構信息
cat /etc/openwrt_release //小米自帶的openwrt信息是假的

ubuntu上的操作
1.下載交叉編譯sdk,並配置環境變量

cd ~/tmp
wget https://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
解壓下載的文件
tar xjvf OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
設置環境變量
vi ~/.zshrc
export PATH=$PATH:~/tmp/openwrt/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/
export STAGING_DIR=~/tmp/openwrt/staging_dir/

自建hello.c 測試c語言交叉編譯

#include<stdio.h>

main() {
printf("Hello, World!\n");
}

mipsel-openwrt-linux-gcc hello.c -o hello

2.設置rust 為nightly版本,並用xargo代替cargo

 

rustup install nightly
rustup default nightly
rustup component add rust-src
rustc -Vv
cargo install xargo

新建 rust測試項目hello
cargo new hello --bin

vi Cargo.toml //添加

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

vi Xargo.toml //添加

[target.mipsel-unknown-linux-uclibc.dependencies.std]
features = []

vi ~/.cargo/config //添加

[target.mipsel-unknown-linux-uclibc]
linker = "mipsel-openwrt-linux-gcc"

交叉編譯openssl時需要,參考第三條

export OPENSSL_LIB_DIR=/home/ubuntu/MipsOpenssl/lib                 
export OPENSSL_INCLUDE_DIR=/home/ubuntu/MipsOpenssl/include

構建項目
xargo build --release --target mipsel-unknown-linux-uclibc --verbose

3.交叉編譯openssl

 

https://www.openssl.org/source/                     //openssl 官網

 

wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar xzf openssl-1.1.1d.tar.gz

 

setarch i386 ./config --prefix=/home/ubuntu/MipsOpenssl CC=mipsel-openwrt-linux-gcc CXX=mipsel-openwrt-linux-g++ AR=mipsel-openwrt-linux-ar RANLIB=mipsel-openwrt-linux-ranlib shared no-asm no-async

 

vi Makefile
去除 -m32

 

vi rsademo.c

 

// rsademo.c
//ref. http://amitmason.blogspot.com/2016/05/linux-mint-openssl-library.html
#include <stdio.h>
#include <openssl/rsa.h>
#include <string.h>
main(){
int keylen, enclen, declen,i;
char enc[256],dec[256];
char *b="1234";
RSA *key=NULL;
key=RSA_generate_key(2048,RSA_F4,NULL,NULL);

 

enclen=RSA_public_encrypt(strlen(b),b,enc,key,RSA_PKCS1_PADDING);
declen=RSA_private_decrypt(enclen,enc,dec,key,RSA_PKCS1_PADDING);
keylen=RSA_size(key);

 

printf("keylen=%d\n",keylen);
printf("enclen=%d\n",enclen);
printf("declen=%d\n",declen);

 

for(i=0;i<declen;i++) printf("%c",dec[i]);
printf("\n");

 

RSA_free(key);
}

 


mipsel-openwrt-linux-gcc rsademo.c ~/MipsOpenssl/lib/libcrypto.a ~/MipsOpenssl/lib/libssl.a -o rsademo -I /home/ubuntu/MipsOpenssl/include -pthread -ldl

 

參考鏈接

 

https://github.com/japaric/rust-cross                                                  //rust 交叉編譯文檔
https://github.com/japaric/xargo
https://users.rust-lang.org/t/openwrt-mips-cross-compile-error/7285
https://nitschinger.at/Rust-on-the-Wifi-Pineapple-and-OpenWRT/        //詳細介紹配置過程 仔細閱讀

 

https://www.dazhuanlan.com/2019/12/26/5e043c553fc1a/?__cf_chl_jschl_tk__=3a32e05b873db5c4cefed9207b4a2dc879c8aa28-1584347106-0-AVEJlXYnaY88_QUj0n132ZRBYcYJafmB_rP-I4jpPhszwmZ-GV-0wbJdTfo8LcWfLoma_1KSAMf1vv-eo4CCJgXmNCweBYJjhXzav2Lyj5m8NLUp_CYdpweEfkJ95fG014W6dlB4hyWbXSvowCddowdu2hlzOaIwRfMg5fz9oK3yF-jujDU-LqrDwGzHBg0KIsUEAAlhvZoZHZ5I8Hzt0z5VxpQKu-gx73O-8EnZbokDAF0AkKzf7XJp8tMz3MYnx9oErXL2QeNyzX3VD0FZONMjZW_uByGlTlDRgllrcTdkwg8FN9SFmZIQ6fpGkUxNJg

 

openssl
https://stackoverflow.com/questions/37375712/cross-compile-rust-openssl-for-raspberry-pi-2
https://www.reddit.com/r/rust/comments/axaq9b/opensslsys_error_when_crosscompiling_for/

https://medium.com/@pipi9baby/cross-compiler-openssl%E5%9C%A8mips-32%E4%BD%8D%E5%85%83%E7%9A%84%E6%9D%BF%E5%AD%90%E4%B8%8A-3cbfd1f17aa7     //重點參考

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM