在 Linux 环境下进行嵌入式 Linux 开发的基本方法,然后对嵌入式开发用
到的软件进行介绍,包括如何安装和测试。这一章是进行嵌入式 Linux 开发必不可少的,是进行嵌入式 Linux 开发的基础,请务必仔细理解,并进行正确的设置。
- 嵌入式 Linux 开发模型
- 交叉编译
由于嵌入式系统资源匮乏,一般不能像 PC 一样安装本地编译器和调试器,不能在本地编写、编译和调试自身运行的程序,而需借助其它系统如 PC 来完成这些工作,这样的系统通常被称为宿主机。宿主机通常是 Linux 系统,并安装交叉编译器、调试器等工具;宿主机也可以是 Windows系统,安装嵌入式 Linux 集成开发环境。在宿主机上编写和编译代码,通过串口、网口或者硬件调试器将程序下载到目标系统里面运行.
- 安装交叉编译器
- 下载解压工具链压缩包
wget https://releases.linaro.org/components/toolchain/binaries/6.4-2018.05/arm-linux-gnueabi/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabi.tar.xz
tar -Jxvf gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabi.tar.xz -C /opt/toolchain/
- 设置环境变量
- 临时设置
export PATH=$PATH:/opt/toolchain/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabi/bin
- 修改用户配置文件
vim ~/.bashrc
export PATH=$PATH:/opt/toolchain/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabi/bin
source ~/.bashrc
- 修改全局配置文件
vim /etc/environment
:/opt/toolchain/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabi/bin
- SSH 服务器
sudo apt-get install openssh-server
先用 ping 命令测试 Windows 和 Linux 之间能否正常通信。
然后使用securecrt的SSH连接
- NFS 服务器
sudo apt-get install nfs-kernel-server #安装 NFS 服务器端
sudo apt-get install nfs-common #安装 NFS 客户端
sudo vi /etc/exports
/home/vmuser/tqimx6q/rootfs 192.168.1.0/24(sync,rw,no_root_squash) *(ro)
sudo /etc/init.d/nfs-kernel-server start #启动 NFS 服务
sudo /etc/init.d/nfs-kernel-server restart #重新启动 NFS 服务
showmount -e #显示共享出的目录
一些小问题:
旧版本: 重启portmap
sudo /etc/init.d/portmap restart
新版本:重启rpcbind 服务。nfs是一个RPC程序,使用它前,需要映射好端口,通过rpcbind 设定。
sudo /etc/init.d/rpcbind restart测试 NFS 服务器:
sudo mount -t nfs -o rw -o nolock -o tcp 192.168.1.188:/home/vmuser/tqimx6q/rootfs /mnt
如果指令运行没有出错,则 NFS 挂载成功,在/mnt 目录下应该可以看到/rootfs 目录下的内容
sudo umount /mnt
- TFTP 服务器
sudo apt-get install tftpd-hpa tftp-hpa
sudo mkdir /home/tftp -p
sudo chmod –R 777 /home/tftp
sudo chown –R nobody /home/tftp
sudo vi /etc/default/tftpd-hpa //被/etc/default/xinetd /etc/inetd.conf替代
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"
sudo service tftpd-hpa start #启动 tftp 服务
测试 tftp 服务器:
服务器端:
$ ls /home/tftp/
test_tftp.txt
在客户端:
tftp 192.168.1.188
tftp> get test_tftp.txt
tftp> q
ls test_tftp.txt
- Samba 服务器
sudo apt-get install samba samba-common smbclient
ps -ef | grep smb
vim /etc/samba/smb.conf
[homes]
comment = Home Directories
browseable = no
read only = no
create mask = 0775
directory mask = 0775
sudo /etc/init.d/smbd restart
sudo smbpasswd -e vmuser
测试 samba服务器:
whereis samba
whereis smbd
\192.168.1.188\vmuser
- FTP 服务器
sudo apt-get install vsftpd
sudo gedit /etc/vsftpd.conf