摘要:Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。
本文分享自华为云社区《嵌入式Linux下移植samba服务--<基于北斗和4G cat1模块的智慧物流>开发实战》,作者: 小小小橘。

Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。
嵌入式开发过程中,往往需要将文件传输至开发板,移植samba服务之后,将开发板接入局域网之后,客直接通过访问开发板IP地址直接访问开发板samba共享文件夹,在开发板和局域网内传输文件方便快捷。此次主要介绍移植samba以及开发中可能遇到的问题。
此次感谢华为云IoT课程《基于北斗和4G cat1模块的智慧物流》提供的STM32MP1开发板,可关注华为云公众号、华为云IoT物联网论坛获取更多活动内容。

  开发环境

系统:Ubuntu 18.04 64位
开发板:STM32MP157
samba版本:3.2.15

  准备工作
samba下载链接:https://download.samba.org/pub/samba/
选择samba-3.2.15.tar.gz下载。

  编译
下载完成之后,在文件夹下使用tar命令进行解压,解压完成之后cd进入samba-3.2.15/source文件夹下进行配置。
  
tar -vxf samba-3.2.15.tar.gz
  • 复制代码

    v2-fac9c5d1bc4e79cf0c33d1d33e62ee33_720w.jpg
    进入文件夹下后
    修改configure文件,修改内容见
    编辑修改configure文件内容,修改内容如下,全文共7处需修改。
    原文内容:
      
    echo "$as_me: error: cannot run test program while cross compiling
  • See \`config.log' for more details." >&2;}
  •    { (exit 1); exit 1; }; }
  • 复制代码

    改为
      
    $as_echo "$as_me: error: cannot run test program while cross compiling
  • See \`config.log' for more details." >&2;}
  • #   { (exit 1); exit 1; };
  •      }; }
  • 复制代码

    修改后见下图
    v2-015fa7087c86e143b3e210bbf52d7527_720w.jpg
    执行如下命令
    echo SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=>arm-linux.cache
  • ./configure CC=arm-none-linux-gnueabihf-gcc LD=arm-none-linux-gnueabihf-ld AR=arm-none-linux-gnueabihf-ar --target=arm-none-linux --host=arm-none-linux-gnueabihf samba_cv_CC_NEGATIVE_ENUM_VALUES=yes --cache-file=arm-linux.cache
  • 复制代码
    v2-f9d6dbb802474620a428c36450dc66f7_720w.jpg
    至此,配置完成。
    配置完成之后执行make命令进行编译,编译完成如下图
    v2-dc4fe7dbf2f75340329201490cefaa9c_720w.jpg
    编译完成之后执行make install命令安装,安装的路径默认为/usr/local/samba。
    v2-504fbc7cfc56fc84c865c0e792c7d3f5_720w.jpg
    安装完成之后将/usr/local/samba文件夹打包拷贝,打包命令
      
    tar -vcf samba.tar.gz samba/
  • 复制代码

    打包完成之后将samba.tar.gz文件拷贝至开发板/usr/local文件夹下。此处使用scp命令拷贝至开发板(前提开发板已接入局域网内,并可Ubuntu系统可相互ping通,本次开发板IP:192.168.124.11),命令如下
      
    scp samba-3.2.15.tar.gz root@192.168.124.11:/usr/local
    复制代码

    发送完成之后可在开发板/usr/local文件下查看到压缩包,使用如下命令进行解压。
      
    tar -vxf samba.tar.gz
    复制代码

    解压后进入/usr/local/samba/lib文件夹下,添加smb.conf文件,此配置文件可根据需求进行配置。
    添加内容如下
      
    [global]
  • workgroup = WORKGROUP
  • server string = samba sever
  • netbios name =myarm
  • guest account=root
  • security =share
  • interfaces = eth0
  • [share]
  • component = share dir
  • path = /opt/
  • guest ok=yes
  • browseable=yes
  • public = yes
  • directory mask = 0777
  • create mask = 0777
  • available = yes
  • 复制代码

    增加可smb.conf文件之后,可进入samba/bin文件进行测试,执行./findsmb文件。可搜索局域网内的samba服务端。
    v2-212ea8b754e13ac2376b56e28e5f323a_720w.jpg
    进入samba/sbin文件夹下执行命令启动samba服务。
      
    ./smbd -D
  • ./nmbd -D
  • 复制代码

    v2-2ef341136f10f53f5eb058ad0e15ede4_720w.jpg
    至此,samba服务移植完成,可在windows下快捷键win+r打开“运行”,输入开发板开发板ip进行访问开发板共享文件夹,妈妈再也不用担心传文件问题了!
    v2-d9173bbfbe25c60e2cbe9481e1dc4a85_720w.jpg

      编译过程中出现的错误
      1、checking that the C compiler understands negative enum values... configure: error
    checking whether arm-none-linux-gnueabihf-gcc and cc understand -c and -o together... yes
  • checking that the C compiler understands -Werror... cross
  • checking that the C compiler understands -w2... cross
  • checking that the C compiler understands -errwarn... cross
  • checking that the C compiler understands volatile... yes
  • checking that the C compiler understands negative enum values... configure: error: in `/home/fan/Downloads/samba-3.2.15/source':
  • configure: error: cannot run test program while cross compiling
  • See `config.log' for more details.
  • 复制代码
    v2-4e24387ed9c70803314ad90ea88dd4be_720w.jpg
    解决办法:
    命令行执行如下命令,并在执行./configure命令时加参数 --cache-file=arm-linux.cache
      
    echo SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=>arm-linux.cache
    复制代码

      2、configure: error: cannot run test program while cross compiling
    checking for __open64... yes
  • checking for creat64... yes
  • checking for prctl... yes
  • configure: error: in `/home/fan/Downloads/samba-3.2.15/source':
  • configure: error: cannot run test program while cross compiling
  • See `config.log' for more details.
  • 复制代码
    v2-4a57a90453802e22287595ab1383f34c_720w.jpg
    解决办法:
    编辑修改configure文件内容,修改内容如下,全文共7处需修改。
    原文内容:
      
    echo "$as_me: error: cannot run test program while cross compiling
  • See \`config.log' for more details." >&2;}
  •    { (exit 1); exit 1; }; }
  • 复制代码

    改为
      
    $as_echo "$as_me: error: cannot run test program while cross compiling
  • See \`config.log' for more details." >&2;}
  • #   { (exit 1); exit 1; };
  •      }; }
  • 复制代码

    更改后如下图
    v2-015fa7087c86e143b3e210bbf52d7527_720w.jpg