zoukankan      html  css  js  c++  java
  • 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! ");
    }

    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 ",keylen);
    printf("enclen=%d ",enclen);
    printf("declen=%d ",declen);

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

    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     //重点参考

  • 相关阅读:
    有价值的终会被人发现和承认
    Sql中存在斜杠“/”怎么办?
    JSONObject和JSONArray(json-lib-2.4)的基本用法
    如何设定linux系统时间
    动态创建的文本框想要加上jQuery的datepicker功能变成日期选择控件该怎么办?
    如果$.ajax函数迟迟得不到响应,那么最有可能出错的地方是请求参数写错了
    Notepad2替代系统自带的记事本Notepad
    css属性与js中style对象的属性对应表
    day02_js学习笔记_01_js的简介、js的基本语法
    Eclipse/MyEclipse的快捷键以及文档注释、多行注释的快捷键
  • 原文地址:https://www.cnblogs.com/sanmubai/p/12504795.html
Copyright © 2011-2022 走看看