FPGA----petalinux的Ubuntu文件系统移植
1、之前的文章提到我们的系统启动时可设置包含两个分区一个是FAT32包含系统启动的引导分区、一个是EXT4的文件分区。我们基于Alinx的提供debain8制作了定制化的文件系统。那么是否可以用ubuntu来制作文件系统呢当然是可以的本次移植Ubuntu 16.04https://blog.csdn.net/qq_37912811/article/details/147782010https://blog.csdn.net/qq_37912811/article/details/1477820102、ubuntu-base获取Ubuntu的移植非常简单不需要我们编译任何东西因为Ubuntu官方已经将根文件系统制作了我们只需要简单配置一下Ubuntu官方提供的base根文件系统使其在我们的开发板上跑起来即可。因此我们首先需要下载Ubuntu-base根文件系统。下面是下载地址http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.4/release/http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.4/release/注意Ubuntu针对不同的CPU架构提供相应的ubuntu base根文件系统有amd64(64位X86)、armhf、i386(32位X86)、powerpc、ppc64el等系统的。ZYNQ的PS端是两个Cortex-A9核的CPU并且有硬件浮点运算单元因此选择armhf版本。3、解压缩ubuntu base根文件系统在ubuntu系统中解压该文件到/home/yangzheng/Downloads/ubuntu_rootfs文件夹下mkdir ubuntu_rootfs sudo tar -xzf ubuntu-base-16.04.6-base-armhf.tar.gz -C ubuntu_rootfs/4、在Ubuntu下安装qemu模拟器我们可以在PC的Ubuntu系统上使用这个工具运行待移植的Ubuntu-basesudo apt-get install qemu-user-static将刚刚安装的qemu-user-static拷贝到我们解压出来的ubuntu base根文件系统中也就是ubuntu_rootfs/usr/bin目录下命令如下cd ubuntu_rootfs sudo cp /usr/bin/qemu-arm-static ./usr/bin/5、指定ubuntu base根文件系统的软件源在设置软件源之前先将Ubuntu主机下的DNS配置文件/etc/resolv.conf拷贝到根文件系统中命令如下sudo cp /etc/resolv.conf ./etc/resolv.conf打开ubuntu-base根文件系统的ubuntu_rootfs/etc/apt/sources.list文件使用vim打开。首先将此文件中已有的内容全部删除然后再添加在新的软件源譬如国内常用的清华源、中科大源等等这些软件源可以直接在网上查找。sudo vim sources.listdeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-proposed main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main restricted universe multiverse6、Ubuntu上挂在Ubuntu base接下来将上面制作的根文件系统挂载的主机上需要挂载proc、sys、dev、dev/pts等文件系统最后使用chroot将主机的根文件系统切换到我们前面制作的根文件系统中。这里我们通过两个脚本文件来完成挂载和卸载操作首先是挂载脚本mount.sh回到/home/yangzheng/Downloads目录在该目录下创建一个名为mount.sh的shell脚本touch mount.sh然后在里面输入如下所示内容sudo mount -t proc /proc /home/yangzheng/Downloads/ubuntu_rootfs/proc sudo mount -t sysfs /sys /home/yangzheng/Downloads/ubuntu_rootfs/sys sudo mount -o bind /dev /home/yangzheng/Downloads/ubuntu_rootfs/dev sudo mount -o bind /dev/pts /home/yangzheng/Downloads/ubuntu_rootfs/dev/pts sudo chroot /home/yangzheng/Downloads/ubuntu_rootfs命令当中使用到的路径信息大家根据自己的实际情况进行配置即可mount.sh脚本编写完成之后再创建一个名为unmount.sh的卸载脚本文件touch unmount.sh在里面输入如下所示内容sudo umount /home/yangzheng/Downloads/ubuntu_rootfs/dev/pts sudo umount /home/yangzheng/Downloads/ubuntu_rootfs/dev sudo umount /home/yangzheng/Downloads/ubuntu_rootfs/sys sudo umount /home/yangzheng/Downloads/ubuntu_rootfs/proc最后给予mount.sh和unmount.sh这两个shell脚本可执行权限命令如下chmod ax mount.sh unmount.sh7、在主机上挂载Ubuntu base将制作的根文件系统挂载到主机下输入如下命令./mount.sh挂载成功如下所示1安装常用的命令和软件apt install sudo sudo apt update sudo apt install sudo vim net-tools ethtool ifupdown wireless-tools rsyslog htop iputils-ping udhcpc wget make screen -y # 安装 SSH 服务 多次尝试不然可能会失败 sudo apt-get update sudo apt-get -f install sudo apt-get install openssh-server # 忽略网络服务 sudo systemctl mask networking.service # 安装perl sudo apt-get update sudo apt-get install perl libperl-dev build-essential必须配置网络服务否则启动时自检非常慢2设置开机启动SSH服务、TCF服务手动在/etc/rc.local中添加启动命令编辑/etc/rc.local如果不存在就创建sudo vim /etc/rc.local写入内容#!/bin/sh -e # start SSH /etc/init.d/ssh start exit 0添加权限sudo chmod x /etc/rc.local安装TCF服务https://blog.csdn.net/qq_37912811/article/details/147782010https://blog.csdn.net/qq_37912811/article/details/1477820103必须添加一个用户Ubuntu-base根文件系统默认只有一个root用户后面我们移植到开发板启动的时候直接登录root用户是登录不上去的我也不知道为什么。所以这里我们需要添加一个普通用户执行下面这条命令添加一个名为zynq的普通用户adduser zynq用户添加完成之后需要设置zynq用户可以使用sudo命令也就是该用户可以使用root用户的身份执行相应的命令我们需要修改/etc/sudoers文件首先打开该文件。vim /etc/sudoers找到“root ALL(ALL:ALL) ALL”这一行在该行下面添加“zynq ALL(ALL:ALL) ALL”如下所示4设置本机名称和IP地址echo ALIENTEK-ZYNQ /etc/hostname echo 127.0.0.1 localhost /etc/hosts echo 127.0.1.1 ALIENTEK-ZYNQ /etc/hosts5配置串口终端和网络dhcpubuntu根文件系统在开发板上启动以后我们通常也希望串口终端正常工作。首先确定自己所使用的串口设备文件假设的USB调试串口对应的设备文件为ttyPS0我们需要添加一个名为gettyttyPS0.service的链接链接到getty.service服务上输入如下命令ln -s /lib/systemd/system/getty.service /etc/systemd/system/getty.target.wants/gettyttyPS0.service设置好以后接下来我们需要配置开发板启动之后能够打开网络设备、启用网络功能使用网线将开发板网口连接到路由器开机启动实现自动分配ip地址打开/etc/network/interfaces配置文件注释掉“source-directory /etc/network/interfaces.d”行并添加如下内容auto eth0 # 动态IP iface eth0 inet dhcp8、整个ubuntu-base根文件系统到这里就构建、配置完成了退出ubuntu-base根文件系统了输入如下命令退出exit ./unmount.sh9、将ubuntu_rootfs目录下所有文件拷贝到SD卡的ext4分区sudo rm -rfd /media/yangzheng/rootfs/* //首先删除SD启动卡根文件系统分区原有的内容 sudo cp -a ./ubuntu_rootfs/* /media/yangzheng/rootfs/ //拷贝ubuntu_rootfs目录下的所有文件到ext4分区 sync //同步10、制作boot.bin与image.ub1切记需要将PL侧的USB0打开不然没有串口。2build后将两个文件移动至SD卡的FAT分区下。11、启动系统1将SD卡插入最小系统板2等待系统自检3输入用户名zynq4输入密码root5由于关闭了网络服务因此在开机时需要输入网络命令才可以上网# 192.168.137.68是你开发板的IP sudo ifconfig eth0 192.168.137.68 netmask 255.255.255.0 up # 192.168.137.1是你的一个可以上网的IP sudo ip route add default via 192.168.137.1 # 验证网络 ping 8.8.8.812、设置串口与SSH可以root登录# 修改root密码 sudo passwd root # 设置密码为root # 设置可以直接root登录 echo ttyPS0 | sudo tee -a /etc/securetty # 配置ssh服务 sudo vi /etc/ssh/sshd_config # 找到或添加 PermitRootLogin yes # 重启ssh服务 sudo systemctl restart sshd重启系统以后可以直接用root登录13、进入系统安装epics7.0.5https://blog.csdn.net/qq_37912811/article/details/147769028https://blog.csdn.net/qq_37912811/article/details/147769028下载7.0.5版本epics#下载epics cd /. mkdir epics cd /epics/ wget https://epics.anl.gov/download/base/base-7.0.5.tar.gz#解压并重命名 tar vxfz base-7.0.5.tar.gz mv base-7.0.5 base需要注意的就是时间和权限问题其余过程一样。cd base # 设置统一时间 sudo find . -type f -exec touch {} # 再次编译 make # 为zynq用户加入文件夹修改权限 sudo chown -R zynq:zynq /epics/base14、文件系统我已经给大家移植好了欢迎下载# 挂载ext4分区 sudo mount /dev/sdb2 /mnt/debian_root # 压缩 sudo tar -czf /home/yangzheng/Downloads/debian10/debian10_V2.tar.gz -C /mnt/debian_root .https://github.com/qwer872336019/zynq_rootfs_epics_tcf/https://github.com/qwer872336019/zynq_rootfs_epics_tcf/15、如果不用root用户那么如何进入root权限1每条命令前加入sudo2进入root模式su root # 输入密码 root