根文件系统的构建和移植

一、buildroot构建根文件系统

1. 配置buildroot

make menuconfig
Target options #配置项目参数
    -> Target Architecture = ARM (little endian)
    -> Target Binary Format = ELF
    -> Target Architecture Variant = cortex-A7
    -> Target ABI = EABIhf
    -> Floating point strategy = NEON/VFPv4
    -> ARM instruction set = ARM
    
Toolchain #配置交叉编译工具链
    -> Toolchain type = External toolchain
    -> Toolchain = Custom toolchain //用户自己的交叉编译器
    -> Toolchain origin = Pre-installed toolchain //预装的编译器
    -> Toolchain path //编译器路径 =/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
    -> Toolchain prefix = $(ARCH)-linux-gnueabihf //前缀
    -> External toolchain gcc version = 4.9.x
    -> External toolchain kernel headers series = 4.1.x
    -> External toolchain C library = glibc/eglibc
    -> [*] Toolchain has SSP support? (NEW) //选中
    -> [*] Toolchain has RPC support? (NEW) //选中
    -> [*] Toolchain has C++ support? //选中
    -> [*] Enable MMU support (NEW) //选中 
    
System configuration #系统配置
-> System hostname = alpha_imx6ull //平台名字,自行设置
-> System banner = Welcome to alpha i.mx6ull //欢迎语
-> Init system = BusyBox //使用 busybox
-> /dev management = Dynamic using devtmpfs + mdev //使用 mdev
-> [*] Enable root login with password (NEW) //使能登录密码
    -> Root password = 123456 //登录密码为 123456
    
-> Filesystem images #配置根文件系统类型
    -> [*] ext2/3/4 root filesystem //如果是 EMMC 或 SD 卡的话就用 ext3/ext4
        -> ext2/3/4 variant = ext4 //选择 ext4 格式
    -> [*] ubi image containing an ubifs root filesystem //如果使用 NAND 的话就用 ubifs   
    
#禁止编译 Linux 内核和uboot,否则会自行下载uboot和内核进行编译。
-> Kernel
    -> [ ] Linux Kernel //不要选择编译 Linux Kernel 选项!
-> Bootloaders
    -> [ ] U-Boot //不要选择编译 U-Boot 选项!

#编译buildroot
sudo make //注意,一定要加 sudo,而且不能通过-jx来指定多核编译!!!
#编译过程耗时几小时,buildroot需要从网上下载源码,可能存在源码无法下载或者下载很慢的情况,可以自行下载文件拷贝到buildroot源目录下的dl文件夹
#编译完成以后的文件在buildroot-2019.02.06/output/images下生成根文件系统rootfs.tar

2.第三方库配置

(1)使能alsa-lib、alsa-utils库
cd rootfs
make menuconfig
#
Target packages
    -> Libraries
        -> Audio/Sound
            -> -*- alsa-lib ---> 此配置项下的文件全部选中
          
Target packages
    -> Audio and video applications
        -> alsa-utils 此目录下的软件全部选中 
     
#   
sudo make

二、ubuntu-base根文件系统移植

1.ubuntu-base根文件系统的下载

http://cdimage.ubuntu.com/ -> ubuntu-base -> releases -> 16.04.05 -> release -> ubuntu-base-16.04.5-base-armhf.tar.gz
根据自己板子的类型架构选取对应的根文件系统。

2.构建根文件系统

(1)解压
sudo tar -vzxf ubuntu-base-16.04.5-base-armhf.tar.gz
(2)安装qemu
sudo apt-get install qemu-user-static
cd ubuntu_rootfs #进入到 ubuntu_rootfs 目录下
sudo cp /usr/bin/qemu-arm-static ./usr/bin/ #拷贝qemu-arm-static到指定位置
(3)更改软件源
cd ubuntu_rootfs
sudo cp /etc/resolv.conf ./etc/resolv.conf
sudo gedit ./etc/apt/sources.list
#
#中科大源
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
#
(4)在主机挂载
  1. 方法1
#添加挂载脚本1 mount.sh
#!/bin/bash
echo "MOUNTING"
sudo mount -t proc /proc /.../ubuntu_rootfs/proc
sudo mount -t sysfs /sys /.../ubuntu_rootfs/sys
sudo mount -o bind /dev /.../ubuntu_rootfs/dev
sudo mount -o bind /dev/pts /.../ubuntu_rootfs/dev/pts
sudo chroot /.../ubuntu_rootfs

#添加卸载脚本2 unmount.sh
#!/bin/bash
echo "UNMOUNTING"
sudo umount /.../ubuntu_rootfs/proc
sudo umount /.../ubuntu_rootfs/sys
sudo umount /.../ubuntu_rootfs/dev
sudo umount /.../ubuntu_rootfs/dev/pts

#添加权限并执行
sudo chmod 777 mount.sh unmount.sh
sudo ./mount.sh

  1. 方法2(方法一有时候卸载会报忙碌的问题)
#创建脚本mu.sh

#!/bin/bash
mnt () 
{
    echo "MOUNTING"
    sudo mount -t proc /proc ${2}proc
    sudo mount -t sysfs /sys ${2}sys
    sudo mount -o bind /dev ${2}dev
    sudo mount -o bind /dev/pts ${2}dev/pts      
    sudo chroot ${2}    
}
umnt ()
{
    echo "UNMOUNTING"
    sudo umount ${2}proc
    sudo umount ${2}sys
    sudo umount ${2}dev/pts
    sudo umount ${2}dev 
}

if [ "$1" = "-m" ] && [ -n "$2" ];
then
    mnt $1 $2
    echo "mnt -m pwd"
elif [ "$1" = "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
    echo "mnt -u pwd"
else
    echo ""
    echo "Either 1'st, 2'nd or bothparameters were missing"
    echo ""
    echo "1'st parameter can be one ofthese: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full pathof rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m/media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}
fi

#添加权限并执行
sudo chmod 777 mu.sh
#挂载命令
sudo sh mu.sh -m ./
#卸载命令
sudo sh mu.sh -u ./
(5)挂载后安装常用的命令和软件
apt update
apt install sudo
apt install vim
apt install kmod
apt install net-tools
apt install ethtool
apt install ifupdown
apt install language-pack-en-base
apt install rsyslog
apt install htop
apt install iputils-ping
(6)设置root用户密码
passwd root
(7)设置本机名称和IP地址
echo "hostname" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 hostname" >> /etc/hosts
(8)设置串口终端
ln -s /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
(9)退出
exit
sudo ./unmount.sh

3.根文件系统制作完毕,加载到板子上测试

(1) nfs挂载
#bootarg中root的格式
root=/dev/nfs nfsroot=[:][,] ip=::::::::
:存放根文件系统主机的IP地址,如我的ubuntu ip: 192.168.1.19
:主机文件路径
: NFS 的其他可选选项,一般不设置
: 客户端 IP 地址,也就是我们开发板的 IP 地址。
: 网关地址,我的就是 192.168.1.1。
:子网掩码,我的就是 255.255.255.0。
:客户机的名字,一般不设置,此值可以空着。
: 设备名,也就是网卡名,一般是 eth0, eth1…。
: 自动配置,一般不使用,所以设置为 off。
: DNS0 服务器 IP 地址,不使用。
: DNS1 服务器 IP 地址,不使用。
#整合后再uboot中设置
setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs rw nfsroot=192.168.1.19:/home/ht/imx6ull/nfs/ubuntu_rootfs ip=192.168.1.20:192.168.1.19:192.168.1.1:255.255.255.0::eth0:off' 
saveenv 
(2) 添加新用户
adduser ht #添加普通用户
(3) 设置新用户可以使用sudo
su  
chmod u+w /etc/sudoers
vi /etc/sudoers
#添加
ht ALL=(ALL:ALL)ALL
#
chmod u-w /etc/sudoers

若在使用sudo时出现错误提示:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
#重启切换到root用户执行如下命令:
chown root:root /usr/bin/sudo
chmod 4755 /usr/bin/sudo
(4) 网络DHCP设置

由于默认没有配置DHCP,因此ubuntu启动后不能直接联网,需要配置IP地址,所以我们这里要配置一下DHCP。

#eth0配置
su
echo auto eth0 > /etc/network/interfaces.d/eth0
echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
/etc/init.d/networking restart
#eth1配置
echo auto eth1 > /etc/network/interfaces.d/eth1
echo iface eth1 inet dhcp >> /etc/network/interfaces.d/eth1
/etc/init.d/networking restart

你可能感兴趣的:(Linux嵌入式,linux,嵌入式)