本文博客地址:http://blog.csdn.net/qq1084283172/article/details/68950682

为了能在我们熟悉的windows或者ubuntu下开发mips架构的程序,需要搭建mips程序的交叉编译环境。mips程序的交叉编译环境的构建需要用编译Buildroot,Buildroot在编译的过程中,会下载一些依赖包,所以在Buildroot的编译安装过程中必须确保网络畅通

(1) what is Buildroot ?

(2) Buildroot 源码工程下载和编译

Buildroot工程的官方下载地址:https://buildroot.org/download

Buildroot工程github下载地址:https://github.com/buildroot/buildroot

Buildroot各版本的源码下载地址:https://buildroot.org/downloads/

Buildroot工程的官方帮助指南:https://buildroot.org/docs.html

Buildroot工程的官方博客地址:http://free-electrons.com/blog/

Buildroot工程的详细介绍和使用说明的buildroot-labs:http://free-electrons.com/doc/training/buildroot/buildroot-labs.pdf

Buildroot工程的详细介绍和使用说明的buildroot-slides:http://free-electrons.com/doc/training/buildroot/buildroot-slides.pdf

Buildroot工程的详细介绍和使用说明的user manual:https://buildroot.org/downloads/manual/manual.pdf

Buildroot工程的详细介绍和使用说明的html版user manual:https://buildroot.org/downloads/manual/manual.html

Buildroot工程源码的下载,官方提供了两种方法。

1.通过github的方式获取:

Repository

The buildroot repository can be browsed online through cgit at http://git.buildroot.net/buildroot.
To grab a copy of the repository use

git clone git://git.buildroot.net/buildroot

Or if you're behind a firewall blocking git:

git clone https://git.buildroot.net/buildroot

Please use the native git protocol if at all possible, as it's a lot more efficient than HTTP.

If you are not already familiar with using Git, we recommend you visit the
Git website
.

Once you've checked out a copy of the source tree, you can update your source tree at any time so it is in sync with the latest and greatest by entering your buildroot directory and running
the command:

git pull

Because you've only been granted anonymous access to the tree, you won't be able to push your changes to the repo. Changes can instead be submitted for inclusion by posting them to the buildroot mailing list.

2.直接下载的方式

Tarballs
You can also obtain daily snapshots of the latest Buildroot source tree if you want to follow development, but cannot or do not wish to use Git.

Older versions can be downloaded from the
release archive
.

Buildroot工程源码的简单编译说明,参考Buildroot的github说明:https://github.com/shuixi2013/buildroot/blob/master/README

Buildroot工程源码的下载和编译配置:

1.github的方式

# 安装依赖库
$ sudo apt-get update
$ sudo apt-get install libncurses5-dev patch # 下载源码
$ git clone https://github.com/buildroot/buildroot.git # 进行编译的配置
$ cd buildroot
$ make clean
$ make menuconfig

2.直接下载解压

# 安装依赖库
$ sudo apt-get update
$ sudo apt-get install libncurses5-dev patch # 下载源码
$ wget https://buildroot.org/downloads/snapshots/buildroot-snapshot.tar.bz2
$ tar -jxvf buildroot-snapshot.tar.bz2 # 进行编译的配置
$ cd buildroot
$ make clean
$ make menuconfig

执行make menuconfig命令以后会出现Buildroot的编译配置界面,截图如下:

选择 Target options--->Target Architecture (MIPS (little endian)),配置 Target Architecture 为 MIPS (little endian),Target Architecture Variant 自动配置为 (Generic MIPS32)  ,不需要修改。其实,最后生成的编译器在编译程序的时,可以添加选项供用户进行大端或者小端的设置。

选择 “Toolchain”, 将 “kernel headers” 改成 机器环境的Kernel版本(即改为编译当前Buildroot的主机内核版本)。可以在主机上通过uname -r  或者cat  /proc/version  查看当前主机的内核版本。

上面操作完成以后,保存、退出Buildroot的编译配置界面。

执行 ./configure 命令根据设置的配置参数生成编译需要的Makefile文件。

$ ./configure

根据自己的具体需求配置好Buildroot的编译配置参数之后,执行make进行编译。在进行Buildroot编译的过程中一定要保持网络的畅通,因为在Buildroot的编译过程中,会下载一些依赖包参与编译。

$ make

经过一段时间的编译完成以后,在Buildroot的根目录下会增加一个output文件,其中包含已经编译好的文件。可以在 buildroot/output/host/usr/bin目录下找到生成的交叉编译工具,mips的编译器就是该目录下的mipsel-linux-gcc

通过如下的命令,查看一下 mipsel-linux-gcc的版本信息。

$ ./mipsel-linux-gcc --version

有关mipsel-linux-gcc的命令使用帮助:

fly2016@fly2016-vm:~/mywork/buildroot/output/host/usr/bin$ ./mipsel-linux-gcc --h
用法:mipsel-linux-gcc.br_real [选项] 文件...
选项:
-pass-exit-codes 在某一阶段退出时返回最高的错误码
--help 显示此帮助说明
--target-help 显示目标机器特定的命令行选项
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
显示特定类型的命令行选项
(使用‘-v --help’显示子进程的命令行参数)
--version 显示编译器版本信息
-dumpspecs 显示所有内建 spec 字符串
-dumpversion 显示编译器的版本号
-dumpmachine 显示编译器的目标处理器
-print-search-dirs 显示编译器的搜索路径
-print-libgcc-file-name 显示编译器伴随库的名称
-print-file-name=<库> 显示 <库> 的完整路径
-print-prog-name=<程序> 显示编译器组件 <程序> 的完整路径
-print-multiarch 显示目标的标准化 GNU 三元组(被用于库路径的一部分)
-print-multi-directory 显示不同版本 libgcc 的根目录
-print-multi-lib 显示命令行选项和多个版本库搜索路径间的映射
-print-multi-os-directory 显示操作系统库的相对路径
-print-sysroot 显示目标库目录
-print-sysroot-headers-suffix 显示用于寻找头文件的 sysroot 后缀
-Wa,<选项> 将逗号分隔的 <选项> 传递给汇编器
-Wp,<选项> 将逗号分隔的 <选项> 传递给预处理器
-Wl,<选项> 将逗号分隔的 <选项> 传递给链接器
-Xassembler <参数> 将 <参数> 传递给汇编器
-Xpreprocessor <参数> 将 <参数> 传递给预处理器
-Xlinker <参数> 将 <参数> 传递给链接器
-save-temps 不删除中间文件
-save-temps=<arg> 不删除中间文件
-no-canonical-prefixes 生成其他 gcc 组件的相对路径时不生成规范化的
前缀
-pipe 使用管道代替临时文件
-time 为每个子进程计时
-specs=<文件> 用 <文件> 的内容覆盖内建的 specs 文件
-std=<标准> 指定输入源文件遵循的标准
--sysroot=<目录> 将 <目录> 作为头文件和库文件的根目录
-B <目录> 将 <目录> 添加到编译器的搜索路径中
-v 显示编译器调用的程序
-### 与 -v 类似,但选项被引号括住,并且不执行命令
-E 仅作预处理,不进行编译、汇编和链接
-S 编译到汇编语言,不进行汇编和链接
-c 编译、汇编到目标代码,不进行链接
-o <文件> 输出到 <文件>
-pie 生成位置无关可执行文件
-shared 生成一个共享库
-x <语言> 指定其后输入文件的语言
允许的语言包括:c c++ assembler none
‘none’意味着恢复默认行为,即根据文件的扩展名猜测
源文件的语言 以 -g、-f、-m、-O、-W 或 --param 开头的选项将由 mipsel-linux-gcc.br_real 自动传递给其调用的
不同子进程。若要向这些进程传递其他选项,必须使用 -W<字母> 选项。 报告程序缺陷的步骤请参见:
<http://bugs.buildroot.net/>.

mipsel-linux-gcc其实是一个软连接,mipsel-linux-gcc真实连接到的是mipsel-buildroot-linux-uclibc-cc.br_real程序。使用mipsel-linux-gcc交叉编译工具进行mips程序的编译测试,下面是测试的代码 hello.c

#include <stdio.h>
#include <string.h> int vul(char *src)
{
char output[20] = {0};
strcpy(output, src);
printf("%s\n", output); return 0;
} int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("need more arguments\n"); return 1;
} vul(argv[1]); return 0;
}

运行编译命令,为了让生成的二进制程序 hello 不依赖动态库在编译选项中加入 "-static",示例如下:

# 静态-static 编译
$ ./mipsel-linux-gcc -o ./code/hello ./code/hello.c -static # 查看编译后生成的程序
$ ls -l ./code # 查看编译后生成的程序的格式
$ file ./code/hello

结果截图:

参考资料:

《解密家用路由器0day漏洞挖掘技术》小错误不少,感觉有些都是不该犯的低级错误。

(3) 直接下载MIPS程序的交叉编译工具链

其实MIPS程序的交叉编译工具gcc不必非得自己编译得到,网站https://uclibc.org/上已经有编译后的mips程序的交叉编译工具提供给我们下载,在ubuntu系统上,可以使用脚本 config.sh进行下载,脚本文件的内容如下:

#!/bin/bash
#this file aim to download xcompiler and install it
download_url="https://www.uclibc.org/downloads/binaries/0.9.30.1/cross-compiler-" function download_bins {
echo "ready to download: $1.tar.bz2"
wget "${download_url}$1.tar.bz2" "--no-check-certificate"
echo "ready to tar: $1.tar.bz2"
tar -jxf $install_path/cross-compiler-$1.tar.bz2
sed -i '$a\export PATH=$PATH:'$install_path'/cross-compiler-'$1'/bin' /etc/profile
} if [ $# == 0 ]
then
echo "Usage: $0 intall_path"
exit -1
elif [ $# == 1 ]
then
install_path=$1
fi cd $install_path
download_bins mips
download_bins mipsel
download_bins armv4l
download_bins i686
download_bins x86_64 source /etc/profile echo "Done"

结果截图:

脚本中交叉编译工具链的下载地址为:https://www.uclibc.org/downloads/binaries/0.9.30.1/

这个config.sh脚本来自于《IoT设备程序开发及编译环境搭建初体验》的作者scu-igroup的github上 IoT_bot工程 代码的脚本。config.sh脚本执行完成以后,各种平台的交叉编译链的工具都下载下来了,在 /cross-compiler-mips/tools/bin
目录和 /cross-compiler-mipsel/tools/bin目录下有mips程序的交叉编译工具链,直接拿来使用就可以。IoT_bot工程 的github下载地址为:https://github.com/scu-igroup/IoT_bot

路由器逆向分析------MIPS交叉编译环境的搭建(Buildroot)的更多相关文章

  1. 路由器逆向分析------MIPS系统网络的配置(QEMU)

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/69378333 MIPS系统网络的配置  使用QEMU 模拟正在运行的MIPS系统并 ...

  2. 路由器逆向分析------在QEMU MIPS虚拟机上运行MIPS程序(ssh方式)

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/69652258 在QEMU MIPS虚拟机上运行MIPS程序--SSH方式 有关在u ...

  3. 路由器逆向分析------Running Debian MIPS Linux in QEMU

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/70176583 下面的文章内容主要参考英文博客<Running Debian ...

  4. 【Linux学习】Ubuntu下嵌入式交叉编译环境arm-linux-gcc搭建

    (1)首先选择一个路径用来存放arm-linux-gcc.我选用的是/home/book,并在以下建立一个目录arm-linux-gcc. (2)利用cp EABI-4.3.3_Emdedsky_20 ...

  5. ubuntu12.10下arm-linux-gcc交叉编译环境的搭建

    交叉编译环境搭建的原因:通俗上讲,因为嵌入式系统可用资源比较少:几十M的ARM 二三百M的flash相对我们的pc机来说资源真的没法比.所以,为了解决这种局面就将PC机等作为主机,搭建开发环境,进行编 ...

  6. Ubuntu12.04嵌入式交叉编译环境arm-linu-gcc搭建过程,图解

    转载:王文松的博客Ubuntu12.04嵌入式交叉编译环境arm-linu-gcc搭建过程,图解 安装环境       Linux版本:Ubuntu 12.04    内核版本:Linux 3.5.0 ...

  7. Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程

    Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程Linux版本:Ubuntu 12.04 内核版本:Linux 3.5.0 交叉编译器版本:arm-linux-gcc-4. ...

  8. Ubuntu 上 hi3531 交叉编译环境 arm-hisiv100nptl-linux 搭建过程

    安装SDK 1.Hi3531 SDK包位置     在"Hi3531_V100R001***/01.software/board"目录下,您可以看到一个 Hi3531_SDK_Vx ...

  9. Hi3516开发笔记(三):Hi3516虚拟机基础环境搭建之交叉编译环境境搭建以及开机启动脚本分析

    前言   前面进行了可以传输,那么写一个简单的C程序来交叉编译并传入运行.   虚拟机   上一篇搭建的虚拟机环境,包含了sftp传递文件,网络能ping通,基于上一篇的虚拟机继续搭建.   海思交叉 ...

随机推荐

  1. js浅拷贝(地址引用)和深拷贝(克隆)

    浅拷贝和深拷贝相对于引用类型而言的. js有两大类型值类型(基本数据类型)和引用类型(object,function,array): 值类型保存在栈上,引用类型保存在堆上. 浅拷贝只是单纯的拷贝对象的 ...

  2. C#连接Excel读取与写入数据库SQL ( 下 )

    接上期 dataset简而言之可以理解为 虚拟的 数据库或是Excel文件.而dataset里的datatable 可以理解为数据库中的table活着Excel里的sheet(Excel里面不是可以新 ...

  3. jdk8的安装与环境搭建

    jdk8的安装与环境搭建 jdk8下载网址:https://www.oracle.com/cn/java/technologies/javase/javase-jdk8-downloads.html ...

  4. ASP.NET Core扩展库之日志

        上一篇我们对Xfrogcn.AspNetCore.Extensions扩展库功能进行了简单的介绍,从这一篇文章开始,我将逐步介绍扩展库中的核心功能.     日志作为非业务的通用领域基础功能, ...

  5. 写个锤子JS!它应该是你最后的选择

    本文翻译自:https://dev.to/olpeh/javascript-should-be-your-last-resort-5dje 在进行现代化Web前端开发时,使用着自己最爱的框架,有时候可 ...

  6. 「NOIP模拟赛」Round 3

    Tag 计数+LIS, 二分+ST表, 计数+记搜 A. 改造二叉树 Description 题面 Solution 如果目标序列非严格递增,或者说目标序列是不下降的,那么答案就是 \(n\) 减去最 ...

  7. Python读写配置文件模块--Configobj

    一.介绍 我们在项目的开发过程中应该会遇到这样的问题:我们的项目读取某个配置文件,然后才能按照配置的信息正常运行服务,当我们需要对修改服务的某些信息时,可以直接修改这个配置文件,重启服务即可,不用再去 ...

  8. SpringBoot中整合Redis、Ehcache使用配置切换 并且整合到Shiro中

    在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...

  9. Mybatis-plus 上

    Mybatis-plus 上 简介 1.什么是Mybatis-plus MyBatis-Plus(简称 MP)是一个 MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发 ...

  10. TCP的client和server的简单连接

    server: import socket as s import threading as t bind_ip = "0.0.0.0" bind_port = 80#配置服务器监 ...