1. 制作rootfs
1.1 下载
#!/bin/bash -e
# Directory contains the target rootfs
TARGET_ROOTFS_DIR="ubuntu_rootfs"
ROOTFSIMAGE=ubuntu-rootfs.img
MOUNTPOINT=./rootfs
OUT=../out
#sudo VERSION=debug TARGET=desktop ARCH=arm64 RELEASE=bionic ./mk-base.sh
if [ ! $RELEASE ]; then
RELEASE='bionic'
fi
if [ ! $ARCH ]; then
ARCH='arm64'
fi
if [ ! $TARGET ]; then
TARGET='desktop'
fi
if [ ! $VERSION ]; then
VERSION='debug'
fi
#mkdir -p ubuntu-build-service
mkdir -p $RELEASE-$TARGET-$ARCH
#进入$RELEASE-$TARGET-$ARCH目录,检查是否有固件
cd $RELEASE-$TARGET-$ARCH
echo -e "\033[36m Staring Download...... \033[0m"
if [ -e ubuntu-base*.tar.gz ]; then
echo -e "\033[36m Ubuntu-base-18.04 Downloaded!!!!!! \033[0m"
else
echo -e "\033[36m Ubuntu-base-18.04 Downloading...... \033[0m"
wget -c http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/ubuntu-base-18.04.1-base-arm64.tar.gz
fi
sudo chmod 0666 ubuntu-base*.tar.gz
cd ..
if [ -e $TARGET_ROOTFS_DIR ]; then
echo -e "\033[36m Del $TARGET_ROOTFS_DIR...... \033[0m"
sudo rm -rf $TARGET_ROOTFS_DIR
fi
mkdir -p $TARGET_ROOTFS_DIR
#进入$TARGET_ROOTFS_DIR目录,解包固件
# cd $TARGET_ROOTFS_DIR
echo -e "\033[36m Extract image \033[0m"
#sudo tar -xzvf ../$RELEASE-$TARGET-$ARCH/ubuntu-base*.tar.gz
sudo tar -xzvf $RELEASE-$TARGET-$ARCH/ubuntu-base*.tar.gz -C $TARGET_ROOTFS_DIR
# cd ..
echo -e "\033[36m Copy packages...... \033[0m"
mkdir -p $TARGET_ROOTFS_DIR/packages
#拷贝数据包
#sudo cp -rf packages/$ARCH/* $TARGET_ROOTFS_DIR/packages
sudo cp -rf overlay/* $TARGET_ROOTFS_DIR/
if [ "$ARCH" == "arm64" ]; then
sudo cp overlay-firmware/usr/bin/brcm_patchram_plus1_64 $TARGET_ROOTFS_DIR/usr/bin/brcm_patchram_plus1
sudo cp overlay-firmware/usr/bin/rk_wifi_init_64 $TARGET_ROOTFS_DIR/usr/bin/rk_wifi_init
fi
# bt,wifi,audio firmware
sudo mkdir -p $TARGET_ROOTFS_DIR/system/lib/modules/
#sudo find ../kernel/drivers/net/wireless/rockchip_wlan/* -name "*.ko" | \
# xargs -n1 -i sudo cp {} $TARGET_ROOTFS_DIR/system/lib/modules/
sudo cp -rf overlay-firmware/* $TARGET_ROOTFS_DIR/
if [ "$VERSION" == "debug" ]; then
# adb, video, camera test file
sudo cp -rf overlay-debug/* $TARGET_ROOTFS_DIR/
fi
if [ "$ARCH" == "arm64" ]; then
sudo cp -rf overlay-debug/usr/local/share/adb/adbd-64 $TARGET_ROOTFS_DIR/usr/local/sbin/adbd
sudo cp -rf overlay-debug/usr/local/share/adb/S60adbd $TARGET_ROOTFS_DIR/usr/local/sbin
sudo cp -rf overlay-debug/usr/local/share/adb/libcutils.so $TARGET_ROOTFS_DIR/usr/lib
sudo cp -rf overlay-debug/usr/local/share/adb/libcrypto.so.1.0.0 $TARGET_ROOTFS_DIR/usr/lib
fi
echo -e "\033[36m Change root.....................\033[0m"
sudo cp /usr/bin/qemu-aarch64-static $TARGET_ROOTFS_DIR/usr/bin/
#mount -o bind:被挂载目录的block被屏蔽掉,inode被重定向到挂载目录的inode
#sudo mount -o bind /dev $TARGET_ROOTFS_DIR/dev
cat <<EOF | sudo chroot $TARGET_ROOTFS_DIR
HOST=rk3308-ubuntu
USER=dolphin
USER_PASSWD=860118
GROUP_NAME=root
#useradd -G sudo -m -s /bin/bash $USER
#PASSWORD="860118"
#egrep "^$username" /etc/passwd >/dev/null
#pass=$(perl -e 'print crypt($ARGV[0], "password")' $PASSWORD)
#useradd -m -d /home/$USER -p $pass -s /bin/bash -G $GROUP_NAME $USER
#passwd $USER
echo $HOST /etc/hostname
echo "127.0.0.1 $HOST" >> /etc/hosts
echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
mkdir /etc/network
mkdir /etc/network/interfaces.d
echo "auto eth0" > /etc/network/interfaces.d/eth0
echo "iface eth0 inet dhcp" >> /etc/network/interfaces.d/eth0
echo "nameserver 127.0.1.1" > /etc/resolv.conf
echo "nameserver 8.8.8.8 " >> /etc/resolv.conf
# chmod o+x /usr/lib/dbus-1.0/dbus-daemon-launch-helper
apt-get update
#apt-get upgrade -y
apt-get install -y udev sudo ssh language-pack-en-base --no-install-recommends
apt-get install -y systemd systemd-sysv dbus --no-install-recommends
apt-get install -y ifupdown net-tools network-manager ethtool --no-install-recommends
apt-get install -y vim udev sudo ssh git rsyslog bash-completion htop --no-install-recommends
# 无线网络配置工具
apt-get install -y wireless-tools wpasupplicant iputils-ping --no-install-recomme
apt-get install -y wireless-tools wpasupplicant --no-install-recomme
pt-get install -y blueman --no-install-recommends
apt-get install -y i2c-tools libi2c-dev python-smbus
echo -e "\033[36m rootfs: Conflict workaround\033[0m"
#apt-get remove -y xserver-xorg-input-evdev
#apt-get install -y libxfont1 libinput-bin libinput10 libwacom-common libwacom2 libunwind8 xserver-xorg-input-libinput
echo -e "\033[36m Setup Xserver \033[0m"
apt-get install -y xserver-xorg xinit xubuntu-desktop --no-install-recommends
echo -e "\033[36m Setup Video \033[0m"
#apt-get install -y gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-alsa \
# gstreamer1.0-plugins-good gstreamer1.0-plugins-bad
apt-get install -y alsa-utils mplayer
#dpkg -i /packages/video/mpp/*.deb
#dpkg -i /packages/video/gstreamer/*.deb
#dpkg -i /packages/workaround/*.deb
#apt-get install -f -y
echo -e "\033[36m Setup libdrm \033[0m"
#dpkg -i /packages/libdrm/*.deb
#apt-get install -f -y
echo -e "\033[36m Setup debug SSH \033[0m"
#Custom Script
systemctl enable rockchip.service
systemctl mask systemd-networkd-wait-online.service
systemctl mask NetworkManager-wait-online.service
#rm /lib/systemd/system/wpa_supplicant@.service
#Get accelerated back for chromium v61
#ln -s /usr/lib/aarch64-linux-gnu/libGLESv2.so /usr/lib/chromium/libGLESv2.so
#ln -s /usr/lib/aarch64-linux-gnu/libEGL.so /usr/lib/chromium/libEGL.so
ln -s /lib/systemd/system/serial-getty\@.service \
/etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service
#Clean
#rm -rf /var/lib/apt/lists/*
EOF
echo -e "\033[36m Rootfs Finished\033[0m"
4. 创建用户
sudo chroot ubuntu_rootfs
useradd -G sudo -m -s /bin/bash dolphin
passwd dolphin
passwd root
exit
3. 制作rootfs镜像
#!/bin/bash -e
# Directory contains the target rootfs
TARGET_ROOTFS_DIR="ubuntu_rootfs"
ROOTFSIMAGE=ubuntu-rootfs.img
MOUNTPOINT=./rootfs
OUT=../out
#sudo ./mk-img.sh
#sudo umount $TARGET_ROOTFS_DIR/dev
echo -e "\033[36m Making rootfs \033[0m"
if [ -e ${ROOTFSIMAGE} ]; then
echo -e "\033[36m Del existing rootfsfile! \033[0m"
rm ${ROOTFSIMAGE}
fi
if [ -e ${MOUNTPOINT} ]; then
echo -e "\033[36m Del existing mountpoint! \033[0m"
rm -r ${MOUNTPOINT}
fi
mkdir ${MOUNTPOINT}
dd if=/dev/zero of=${ROOTFSIMAGE} bs=1M count=0 seek=4000
finish() {
sudo umount ${MOUNTPOINT} || true
echo -e "\e[31m MAKE ROOTFS FAILED.\e[0m"
exit -1
}
echo -e "\033[36m Format rootfs to ext4 \033[0m"
mkfs.ext4 ${ROOTFSIMAGE}
echo -e "\033[36m Mount rootfs to ${MOUNTPOINT} \033[0m"
sudo mount ${ROOTFSIMAGE} ${MOUNTPOINT}
trap finish ERR
echo -e "\033[36m Copy rootfs to ${MOUNTPOINT} \033[0m"
sudo cp -rfp ${TARGET_ROOTFS_DIR}/* ${MOUNTPOINT}
echo -e "\033[36m Umount rootfs \033[0m"
sudo umount ${MOUNTPOINT}
echo -e "\033[36m Rootfs Image: ${ROOTFSIMAGE} \033[0m"
e2fsck -p -f ${ROOTFSIMAGE}
resize2fs -M ${ROOTFSIMAGE}
echo -e "\033[36m Rootfs Finished as ${ROOTFSIMAGE} \033[0m"
4. 将用户添加到组
usermod -a -G video root
sudo usermod -a -G audio root
sudo usermod -a -G video dolphin
sudo usermod -a -G audio dolphin