基于I.xm6q,移植lsof工具

近日,在I.xm6q上处理录像文件。而已移植的系统缺少lsof命令,难以准确知道系统当前打开的录像有哪些。若未关闭录像文件,对卸载与格式化SD卡有一定影响。

经查阅资料,在不重新制作busybox的情况下,直接下载源码,交叉编译,移植lsof命令。步骤如下:

  1. 下载源码路径:http://www.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/
  2. 下载源码包:lsof_4.91.tar.gz
  3. 将下载好的lsof_4.91.tar.gz,移植到Linux开发系统中,并解压源包:tar -xvf lsof_4.91.tar.gz
  4. 进入解压目录,检测源码包lsof_4.91_src.tar是否完好无损
    • 解压目录内有"README.lsof_4.91"文件,文件内容有MD5码,用于检验文件是否完好无损。
    • 开发环境中,对下载的lsof_4.91_src.tar进行MD5校验.
    • 若两个MD5一样,则可以交叉编译,移植。否则,建议重新下载

5.解压lsof_4.91_src.tar: tar -xvf lsof_4.91_src.tar

6.进入解压后的lsof_4.91_src目录

7.交叉编译前,参数配置:LINUX_KERNEL=/opt/fsl-imx/4.1.15-2.1.0/linux-imx ./Configure linux

    • 其中:/opt/fsl-imx/4.1.15-2.1.0/linux-imx是Ixm6q系统Kernel源码路径

8.修改Makefile文件

  • 修改CC交叉编译链即可,修改内容如下:
  • ARCH = arm                                
    CC = /opt/fsl-imx/4.1.15-2.1.0/fb_back/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9  --sysroot=/opt/fsl-imx/4.1.15-2.1.0/fb/sysroots/cortexa9hf-neon-poky-linux-gnueabi    

     

9.编译源码,生成lsof命令:make

10.移植:将交叉编译好的lsof命令移植到I.xm6q开发板上。

11.移植测试:lsof --help

  • root@imx6qsabreauto:~# lsof --help
    lsof: illegal option character: -
    lsof 4.91
     latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
     latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
     latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
     usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
     [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
     [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
    Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
      -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
      -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
      -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
      -i select IPv[46] files  -K [i] list|(i)gn tasKs    -l list UID numbers
      -n no host names         -N select NFS files        -o list file offset
      -O no overhead *RISKY*   -P no port names           -R list paRent PID
      -s list file size        -t terse listing           -T disable TCP/TPI info
      -U select Unix socket    -v list version info       -V verbose search
      +|-w  Warnings (-)       -X skip TCP&UDP* files     -- end option scan
      -E display endpoint info              +E display endpoint info and files
      +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
      -F [f] select fields; -F? for help  
      +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                            +m [m] use|create mount supplement
      +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
      -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
      -T qs TCP/TPI Q,St (s) info
      -g [s] exclude(^)|select and print process group IDs
      -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
      +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
           An optional suffix to t is m<fmt>; m must separate t from <fmt> and
          <fmt> is an strftime(3) format for the marker line.
      -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
      -u s   exclude(^)|select login|UID set s
      -x [fl] cross over +d|+D File systems or symbolic Links
      names  select named files or files on named file systems
    Only root can list all files, but anyone can list socket files.
    /dev warnings disabled; kernel ID check enabled.
  • 有相关内容,则表示移植成功

12.使用教程:参考菜鸟教程https://www.runoob.com/w3cnote/linux-check-port-usage.html

posted @ 2020-04-26 15:43  ~Newbie  阅读(715)  评论(0编辑  收藏  举报