移植 mtd_util

1. 简介

在使用 flash_eraseall 命令时可能没有,如果你是用的busybox自己定制文件系统,只需要在配置busybox中时按自己需要将nandflash相关工具选择上,重新编译制作。

Miscellaneous Utilities --->

[*] nandwrite

[*] nanddump

[*] flash_eraseall

但还是有一些情况需要我们自己移植 flash 相关的操作命令,即 mtd_util

 

2. 正文

此次移植的版本是:2.0.0

本文的介绍顺序是记录的整个移植过程。

下载 mtd-utils-2.0.0,解压,进入目录,在目录下新建一个文件夹 install

然后回到mtd-utils的解压目录下

> ./configure --prefix=/home/zyl/wor_lip/porting/mtd-utils-2.0.0/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t"

出现错误

configure: error: lzo missing

安装 lzo,

先下载lzo:http://www.oberhumer.com/opensource/lzo/#download

解压文件,在文件夹下创建 install 文件夹

> mkdir install

> ./configure --prefix=/home/zyl/wor_lip/porting/lzo-2.10/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t"

> make

> make install

在install下就有有我们需要的库,文件结构如下

 

关键的数据大小

216K include/

664K lib/liblzo2.a

我们查找源码中有关lzo的变量,发现在configure中有如下的变量

./configure:1497: LZO_CFLAGS C compiler flags for lzo

./configure:1498: LZO_LIBS linker flags for lzo

 

则之前的配置命令变成:

./configure --prefix=/home/zyl/wor_lip/porting/mtd-utils-2.0.0/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t" LDFLAGS=-L/home/zyl/wor_lip/porting/lzo-2.10/install/lib CPPFLAGS=-I/home/zyl/wor_lip/porting/lzo-2.10/install/include/lzo

其中上面的 LDFLAGS 变量决定了 configure 脚本能不能找到lzo。

 

出现错误

ubifs-utils/mkfs.ubifs/mkfs.ubifs.h:46:23: fatal error: uuid/uuid.h: No such file or directory

#include <uuid/uuid.h>

 

搜索路径发现系统中文件在include下,因此改动这里变成

#include <uuid.h>

 

ubifs-utils/mkfs.ubifs/compr.c:28:23: fatal error: lzo/lzo1x.h: No such file or directory

#include <lzo/lzo1x.h>

我们知道lzo头文件搜索路径我们设置的是 CPPFLAGS=-I/home/zyl/wor_lip/porting/lzo-2.10/install/include/lzo,因此,我们重新配置下,将搜索路径变成lzo的上一层

> ./configure --prefix=/home/zyl/wor_lip/porting/mtd-utils-2.0.0/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t" LDFLAGS=-L/home/zyl/wor_lip/porting/lzo-2.10/install/lib CPPFLAGS=-I/home/zyl/wor_lip/porting/lzo-2.10/install/include

 

出现错误

ubifs-utils/mkfs.ubifs/compr.c:33:18: fatal error: zlib.h: No such file or directory

#include <zlib.h>

缺少 zlib,

下载zlib,

在解压出来的文件中创建文件夹 install

配置

> ./configure --prefix=/home/zyl/wor_lip/porting/zlib-1.2.11/install --shared

更改Makefile

CC=arm-none-linux-gnueabi-gcc -march=armv4t

LDSHARED=$(CC) -shared -Wl,-soname,libz.so.1,--version-script,zlib.map

CPP=$(CC) -E

AR=arm-none-linux-gnueabi-ar

RANLIB=arm-none-linux-gnueabi-ranlib

 

> make

> make install

 

回到mtd文件夹下

> ./configure --prefix=/home/zyl/wor_lip/porting/mtd-utils-2.0.0/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t" LDFLAGS="-L/home/zyl/wor_lip/porting/lzo-2.10/install/lib -L/home/zyl/wor_lip/porting/zlib-1.2.11/install/lib" CPPFLAGS="-I/home/zyl/wor_lip/porting/lzo-2.10/install/include -I/home/zyl/wor_lip/porting/zlib-1.2.11/install/include"

 

出现错误

/home/zyl/arm-2014.05/bin/../lib/gcc/arm-none-linux-gnueabi/4.8.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -luuid

 

看来是系统中没有uuid的库,下载移植

下载:https://sourceforge.net/projects/libuuid/files/latest/download

在解压的文件夹下创建 install 文件夹

> ./configure --prefix=/home/zyl/wor_lip/porting/libuuid-1.0.3/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t"

> make

> make install

 

重新回到mtd文件夹下,添加libuuid相关

> ./configure --prefix=/home/zyl/wor_lip/porting/mtd-utils-2.0.0/install --host=arm-linux CC="arm-none-linux-gnueabi-gcc -march=armv4t" LDFLAGS="-L/home/zyl/wor_lip/porting/lzo-2.10/install/lib -L/home/zyl/wor_lip/porting/zlib-1.2.11/install/lib -L/home/zyl/wor_lip/porting/lzo-2.10/install/lib -L/home/zyl/wor_lip/porting/libuuid-1.0.3/install/lib" CPPFLAGS="-I/home/zyl/wor_lip/porting/lzo-2.10/install/include -I/home/zyl/wor_lip/porting/zlib-1.2.11/install/include -I/home/zyl/wor_lip/porting/libuuid-1.0.3/install/include"

> make

hmmm,顺利通过,

> make install

将 install/sbin中的可执行程序拷贝到开发板中相应位置就能使用了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个使用 pthread 库的多线程程序,主要是创建一个线程并等待它的结束。下面是代码的详细解析: 1. `int main(int argc, char *argv[])`:程序的主函数。 2. `pthread_attr_t mtd_attr;`:定义线程属性对象 mtd_attr。 3. `pthread_attr_init(&mtd_attr);`:初始化线程属性对象 mtd_attr。 4. `pthread_attr_setinheritsched(&mtd_attr,PTHREAD_EXPLICIT_SCHED);`:设置线程属性对象 mtd_attr 的继承调度策略为 PTHREAD_EXPLICIT_SCHED。 5. `pthread_attr_setschedpolicy(&mtd_attr,SCHED_OTHER);`:设置线程属性对象 mtd_attr 的调度策略为 SCHED_OTHER。 6. `struct sched_param send_param; send_param.__sched_priority = 60;`:定义并设置调度参数对象 send_param 的优先级为 60。 7. `pthread_attr_setschedparam(&mtd_attr,&send_param);`:设置线程属性对象 mtd_attr 的调度参数为 send_param。 8. `pthread_attr_setscope(&mtd_attr,PTHREAD_SCOPE_SYSTEM);`:设置线程属性对象 mtd_attr 的作用域为 PTHREAD_SCOPE_SYSTEM。 9. `pthread_t mtd_thread;`:定义线程对象 mtd_thread。 10. `int mtd_task_id;`:定义线程 ID 变量 mtd_task_id。 11. `if((mtd_task_id=pthread_create((pthread_t *)(&mtd_thread),&mtd_attr,mtd_test,NULL))!=0)`:创建线程,并将其 ID 赋值给 mtd_task_id。其中,pthread_create() 函数的第一个参数是指向线程对象的指针,第二个参数是指向线程属性对象的指针,第三个参数是指向线程函数的指针,最后一个参数是线程函数的参数,这里设置为 NULL。 12. `printf("mtd_thread tid %d..\n",mtd_task_id);`:输出线程 ID。 13. `pthread_join(mtd_thread, NULL);`:等待线程结束,如果线程没有结束,主线程就会一直阻塞在这里。 14. `return 0;`:返回程序运行结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值