https://www.digikey.com/eewiki/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-Availability
在BBB板上直接做image, 由于板上空间不够做不了,所以用虚拟机制作BBB image
一、环境:
主机:win10
虚拟机:vmware player安装ubuntu16.04 server版
软硬件条件:
MicroSD card:不小于1GB,使用USB卡托插入主机才能被虚拟机正确识别
Cross compiler:(似乎国内总是下载失败,找Fernado在国外下载)https://releases.linaro.org/components/toolchain/binaries/6.4-2018.05/arm-linux-gnueabihf/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
u-boot: https://github.com/u-boot/u-boot
Linux Kernel: https://github.com/RobertCNelson/bb-kernel
TI Kernel: https://github.com/RobertCNelson/ti-linux-kernel-dev.git
Debian Root File Sytem(rootfs): https://rcn-ee.com/rootfs/eewiki/minfs/debian-9.5-minimal-armhf-2018-07-30.tar.xz
二、制作步骤:
用root登录ubuntu16.04虚拟机
mkdir -p /root/beaglebone
cd /root/beaglebone
1,安装cross compiler:
wget -c https://releases.linaro.org/components/toolchain/binaries/6.4-2018.05/arm-linux-gnueabihf/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
sudo tar xf gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
root@ubuntu:~/beaglebone# export CC=`pwd`/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
root@ubuntu:~/beaglebone# ${CC}gcc --version
arm-linux-gnueabihf-gcc (Linaro GCC 6.4-2018.05) 6.4.1 20180425 [linaro-6.4-2018.05 revision 7b15d0603ad63dc19ab7cf035eb70]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2,安装编译u-boot
cd /root/beaglebone
git clone https://github.com/u-boot/u-boot
cd u-boot/
git checkout v2018.09 -b tmp
cd /root/beaglebone/u-boot
wget -c https://rcn-ee.com/repos/git/u-boot-patches/v2018.09/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
wget -c https://rcn-ee.com/repos/git/u-boot-patches/v2018.09/0002-U-Boot-BeagleBone-Cape-Manager.patch
patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
patch -p1 < 0002-U-Boot-BeagleBone-Cape-Manager.patch
make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_defconfig
vi /root/beaglebone/u-boot/.config
CONFIG_BOOTDELAY=0
make ARCH=arm CROSS_COMPILE=${CC}
3,安装编译Linux kernel
3.1 通用Linux Kernel
cd /root/beaglebone
git clone https://github.com/RobertCNelson/bb-kernel
cd bb-kernel/
git checkout origin/am33x-rt-v4.9 -b tmp
提前把编译器安装好,因为直接下载失败
mkdir -p /root/beaglebone/bb-kernel/dl/
sudo cp /root/beaglebone/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz /root/beaglebone/bb-kernel/dl/
./build_kernel.sh
结束时注意看屏幕输出,后面会用:export kernel_version=4.9.146-bone-rt-r12
3.2 TI Kernel
git clone https://github.com/RobertCNelson/ti-linux-kernel-dev.git
cd ti-linux-kernel-dev/
git checkout origin/ti-linux-rt-4.14.y -b tmp
提前把编译器安装好,因为直接下载失败
mkdir -p /root/ti-linux-kernel-dev/bb-kernel/dl/
sudo cp /root/beaglebone/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz /root/ti-linux-kernel-dev/bb-kernel/dl/
./build_kernel.sh
4,安装Root FileSytem
cd /root/beaglebone
wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-9.5-minimal-armhf-2018-07-30.tar.xz
root@ubuntu:~/beaglebone# sha256sum debian-9.5-minimal-armhf-2018-07-30.tar.xz
9399d649d1ce9910bbfc745f59dc57ee0e1134f57e8cae01c8cd75a8bd9d1e1e debian-9.5-minimal-armhf-2018-07-30.tar.xz
sudo tar xf debian-9.5-minimal-armhf-2018-07-30.tar.xz
5,安装microSD card并制作image
5.1 fdisk -l #找出sd card Disk /dev/sdb
export DISK=/dev/sdb
cd /root/beaglebone
5.2 # Erase partition table/labels on microSD card:
sudo dd if=/dev/zero of=${DISK} bs=1M count=10
5.3 # Install Bootloader:
sudo dd if=./u-boot/MLO of=${DISK} count=1 seek=1 bs=128k
sudo dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 bs=384k
5.4 # Create Partition Layout:先查看sfdisk 版本
查看sfdisk版本:
root@ubuntu:~/beaglebone# sfdisk -v
sfdisk from util-linux 2.27.1
输入以下命令:
sudo sfdisk ${DISK} <<-__EOF__
4M,,L,*
__EOF__
如果sfdisk版本低于2.25x,则输入以下命令:
5.5 分区格式化:
sudo mkfs.ext4 -L rootfs ${DISK}1
一路回车,不用输入信息。
5.6 Mount Partition:
mkdir -p /media/rootfs/
for: DISK=/dev/sdX
sudo mount ${DISK}1 /media/rootfs/
for: DISK=/dev/mmcblk0
sudo mount ${DISK}p1 /media/rootfs/
5.7 Backup Bootloader
cd /root/beaglebone
sudo mkdir -p /media/rootfs/opt/backup/uboot/
sudo cp -v ./u-boot/MLO /media/rootfs/opt/backup/uboot/
sudo cp -v ./u-boot/u-boot.img /media/rootfs/opt/backup/uboot/
5.8 Install Kernel and Root File System
#在上面build_kernel执行完会看见kernel_version
cat ~/beaglebone/ti-linux-kernel-dev/kernel_version
4.14.79-ti-rt-r86
export kernel_version=4.9.146-bone-rt-r12
或export kernel_version=4.14.79-ti-rt-r86
5.8.1 copy root file system
cd /root/beaglebone/
sudo tar xfvp ./*-*-*-armhf-*/armhf-rootfs-*.tar -C /media/rootfs/
sync
sudo chown root:root /media/rootfs/
sudo chmod 755 /media/rootfs/
5.8.2 set uname_r in /boot/uEnv.txt
cd /root/beaglebone/
sudo sh -c "echo 'uname_r=${kernel_version}' >> /media/rootfs/boot/uEnv.txt"
5.8.3 copy kernel image
cd /root/beaglebone/
sudo cp -v ./bb-kernel/deploy/${kernel_version}.zImage /media/rootfs/boot/vmlinuz-${kernel_version}
或sudo cp -v ./ti-linux-kernel-dev/deploy/${kernel_version}.zImage /media/rootfs/boot/vmlinuz-${kernel_version}
5.8.4 copy kernel device tree binaries
cd /root/beaglebone/
sudo mkdir -p /media/rootfs/boot/dtbs/${kernel_version}/
sudo tar xfv ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/
或sudo tar xfv ./ti-linux-kernel-dev/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/
5.8.5 Copy Kernel Modules
cd /root/beaglebone/
sudo tar xfv ./bb-kernel/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/
或sudo tar xfv ./ti-linux-kernel-dev/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/
5.8.6 File Systems Table (/etc/fstab)
sudo sh -c "echo '/dev/mmcblk0p1 / auto errors=remount-ro 0 1' >> /media/rootfs/etc/fstab"
5.8.7 Networking
vi /media/rootfs/etc/network/interfaces
iface eth0 inet static
address 192.168.2.183
netmask 255.255.255.0
gateway 192.168.2.1
5.8.8 Networking: Using a shared SD card with Multiple BeagleBone
vi /media/rootfs/etc/udev/rules.d/70-persistent-net.rules
# BeagleBone: net device ()
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
5.8.9 配置
1)允许root远程登录
vi /media/rootfs/etc/ssh/sshd_config
PermitRootLogin yes
2)安装烧录脚本
cd /root/beaglebone/
wget https://raw.githubusercontent.com/RobertCNelson/boot-scripts/master/tools/eMMC/bbb-eMMC-flasher-eewiki-ext4.sh
chmod +x bbb-eMMC-flasher-eewiki-ext4.sh
cp bbb-eMMC-flasher-eewiki-ext4.sh /media/rootfs/boot/
5.8.10 Remove SD card
sync
sudo umount /media/rootfs
如果一切顺利,至此启动u盘制作成功,断电下插入BBB版,hold BOOT按键(S2),再摁Power键上电,当看到四个灯都亮时,可以松开S2,等待启动完成。
Notes:
1,避免git超时
git config --system http.postBuffer 524288000
git config --system http.sslVerify false
三、第一次启动
1)初始登录:debian/temppwd
2)第一次可以设置root密码
sudo passwd root
3)设置时区和时间
dpkg-reconfigure tzdata
date -s "2019-01-05 14:54:56"
hwclock --systohc //设置硬件时钟与系统时间同步,关机重启时间就复原,需要纽扣电池
4)安装开发调试工具
apt-get update
apt-get install gcc
apt-get install make
apt-get install gdb
apt-get install build-essential
apt-get install linux-perf
apt-get install man
apt-get install tree
apt-get install python
git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
cd rt-tests
git checkout stable/v1.0
make all
make install
编译安装最新valgrind,因为apt-get install valgrind 3.12版本有问题
wget http://www.valgrind.org/downloads/valgrind-3.14.0.tar.bz2
安装gprof2dot和dot工具分析valgrind结果
https://files.pythonhosted.org/packages/9d/36/f977122502979f3dfb50704979c9ed70e6b620787942b089bf1af15f5aba/gprof2dot-2017.9.19.tar.gz
https://graphviz.gitlab.io/pub/graphviz/stable/SOURCES/graphviz.tar.gz
四、优化启动时间:
1,禁止启动不需要服务
systemctl disable nginx.service
systemctl disable unattended-upgrades.service
systemctl disable binfmt-support.service
systemctl disable ofono.service
systemctl disable bluetooth.service //仍然可以被其它进程启动
systemctl mask bluetooth.service //屏蔽后不能被启动
systemctl disable wpa_supplicant.service //wifi服务
systemctl mask wpa_supplicant.service
systemctl set-default multi-user.target
systemctl disable graphical.target
systemctl disable loadcpufreq.service
systemctl disable cpufrequtils.service
systemctl disable dundee.service //dundee/ofono与移动通讯有关ofono.org
systemctl disable hostapd.service //802.11无线通讯
systemctl disable networking.service //不影响ssh登录
systemctl disable dnsmasq.service
systemctl mask dnsmasq.service
systemctl disable udhcpd.service
systemctl mask udhcpd.service
systemctl mask remote-fs.target
systemctl disable rsyslog.service //默认日志服务用不到
systemctl disable apt-daily.timer
systemctl disable apt-daily.service
systemctl disable apt-daily-upgrade.timer
systemctl disable avahi-daemon.service
systemctl disable avahi-daemon.socket
systemctl disable systemd-timesyncd.service
connman.service不能停,否则ssh连接断,生产版可以停
ssh.service 生产版可以disable
2,修改配置
root@arm:~# cat /boot/uEnv.txt
optargs=quiet lpj=1990656(通过dmesg -d查询lpj实际value)
#disable_uboot_overlays=1
disable_uboot_overlay_video=1
disable_uboot_overlay_audio=1
disable_uboot_overlay_wireless=1
disable_uboot_overlay_adc=1
vi /etc/systemd/journald.conf
Storage=none 可以减掉0.5秒,但不建议
vi /etc/systemd/system.conf
DefaultTimeoutStartSec=1s
DefaultTimeoutStopSec=1s
禁用swap分区
swapoff -a
查询swap优先级
sysctl -q vm.swappiness
降低swap优先级
vi /etc/sysctl.conf
增加
vm.swappiness=0
3,增加串口终端登录服务
新建文件/etc/rc.local,内容如下,并增加+x权限
root@arm:~# cat /etc/rc.local
#!/bin/sh -e
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
exec /sbin/getty -L 115200 ttyS0 vt102 &
exit 0
EOF
通过USB线连接BBB板PIN口,需要安装USB驱动。
4,SD卡系统烧录到BBB板flash
用SD卡启动BBB板
cd /boot
/bin/bash ./bbb-eMMC-flasher-eewiki-ext4.sh
五、linux系统备份image
需要硬件环境:
a)BeagleBoneBack开发板
b)4GB MicroSD卡
目标是把BeagleBoneBack开发板上的Linux系统做成镜像文件或复制系统到SD卡
特别注意:源盘和目的盘必须不同!
1,插入足够大备份sd卡,查看当前系统disk
fdisk -l
系统盘:Disk /dev/mmcblk0
备份盘:Disk /dev/sda
2,分区备份image
mkdir -p /mnt/backup
mount /dev/sda1 /mnt/backup
dd bs=512 count=7744512 if=/dev/mmcblk0 of=/mnt/backup/linux_ghost.img;sync
#dd bs=512 count=7471104 if=/dev/mmcblk1 of=/mnt/root/linux_ghost-4.9.146-bone-rt-r12.img;sync
#bs=512(根据源盘mmcblk0 Units: sectors of 1 * 512 = 512 bytes) count=[fdisk命令中系统盘End列最大数+1]
注意要执行sync同步磁盘
3,整个系统全盘复制到SD卡制作启动盘
dd if=/dev/mmcblk0 of=/dev/sda;sync
六、镜像恢复到SD卡
目标是把镜像备份img恢复成可以SD卡启动盘
需要硬件环境:
a)PC机和imag镜像文件
b)4GB MicroSD卡
c)在window上安装镜像刻录软件Etcher
https://www.balena.io/etcher/
如下图,打开Etcher软件,选择镜像文件和目的SD盘,点击Flash开始刻录。
网友评论