创龙3588——debian根文件系统制作

news2025/1/7 20:09:03

文章目录

  • build.sh debian 执行流程
    • build.sh
      • 源码
      • 流程
    • 30-rootfs.sh
      • 源码
      • 流程
    • mk-rootfs-bullseys.sh
      • 源码
      • 流程
    • mk-sysroot.sh
      • 源码
      • 流程
    • mk-image.sh
      • 源码
      • 流程
    • post-build.sh
  • 大致流程
  • 系统制作步骤

build.sh debian 执行流程

build.sh

源码

run_hooks()
{
	DIR="$1"
	shift

	for dir in "$CHIP_DIR/$(basename "$DIR")/" "$DIR"; do
		[ -d "$dir" ] || continue

		for hook in $(find "$dir" -maxdepth 1 -name "*.sh" | sort); do
			"$hook" $@ && continue
			HOOK_RET=$?
			err_handler $HOOK_RET "${FUNCNAME[0]} $*" "$hook $*"
			exit $HOOK_RET
		done
	done
}

run_build_hooks()
{
	# Don't log these hooks
	case "$1" in
		init | pre-build | make-* | usage | support-cmds)
			run_hooks "$RK_BUILD_HOOK_DIR" $@ || true
			return 0
			;;
	esac

	LOG_FILE="$(start_log "$1")"

	echo -e "# run hook: $@\n" >> "$LOG_FILE"
	run_hooks "$RK_BUILD_HOOK_DIR" $@ 2>&1 | tee -a "$LOG_FILE"
	HOOK_RET=${PIPESTATUS[0]}
	if [ $HOOK_RET -ne 0 ]; then
		err_handler $HOOK_RET "${FUNCNAME[0]} $*" "$@"
		exit $HOOK_RET
	fi
}

main()
{
	[ -z "$DEBUG" ] || set -x

	trap 'err_handler' ERR
	set -eE

	# Save intial envionments
	unset INITIAL_SESSION
	INITIAL_ENV=$(mktemp -u)
	if [ -z "$RK_SESSION" ]; then
		INITIAL_SESSION=1
		env > "$INITIAL_ENV"
	fi

	export LC_ALL=C

	export SCRIPTS_DIR="$(dirname "$(realpath "$BASH_SOURCE")")"
	export COMMON_DIR="$(realpath "$SCRIPTS_DIR/..")"
	export SDK_DIR="$(realpath "$COMMON_DIR/../../..")"
	export DEVICE_DIR="$SDK_DIR/device/rockchip"
	export CHIPS_DIR="$DEVICE_DIR/.chips"
	export CHIP_DIR="$DEVICE_DIR/.chip"

	export RK_DATA_DIR="$COMMON_DIR/data"
	export RK_TOOL_DIR="$COMMON_DIR/tools"
	export RK_IMAGE_DIR="$COMMON_DIR/images"
	export RK_KBUILD_DIR="$COMMON_DIR/linux-kbuild"
	export RK_CONFIG_IN="$COMMON_DIR/configs/Config.in"

	export RK_BUILD_HOOK_DIR="$COMMON_DIR/build-hooks"
	export BUILD_HELPER="$RK_BUILD_HOOK_DIR/build-helper"
	export RK_POST_HOOK_DIR="$COMMON_DIR/post-hooks"
	export POST_HELPER="$RK_POST_HOOK_DIR/post-helper"

	export PARTITION_HELPER="$SCRIPTS_DIR/partition-helper"

	export RK_SESSION="${RK_SESSION:-$(date +%F_%H-%M-%S)}"

	export RK_OUTDIR="$SDK_DIR/output"
	export RK_SESSION_DIR="$RK_OUTDIR/sessions"
	export RK_LOG_BASE_DIR="$RK_OUTDIR/log"
	export RK_LOG_DIR="$RK_SESSION_DIR/$RK_SESSION"
	export RK_INITIAL_ENV="$RK_LOG_DIR/initial.env"
	export RK_CUSTOM_ENV="$RK_LOG_DIR/custom.env"
	export RK_FINAL_ENV="$RK_LOG_DIR/final.env"
	export RK_ROCKDEV_DIR="$SDK_DIR/rockdev"
	export RK_FIRMWARE_DIR="$RK_OUTDIR/firmware"
	export RK_SECURITY_FIRMWARE_DIR="$RK_OUTDIR/security-firmware"
	export RK_CONFIG="$RK_OUTDIR/.config"
	export RK_DEFCONFIG_LINK="$RK_OUTDIR/defconfig"

	# For Makefile
	case "$@" in
		make-targets | make-usage)
			run_build_hooks "$@"
			rm -f "$INITIAL_ENV"
			exit 0 ;;
	esac

	# Prepare firmware dirs
	mkdir -p "$RK_FIRMWARE_DIR" "$RK_SECURITY_FIRMWARE_DIR"

	cd "$SDK_DIR"
	[ -f README.md ] || ln -rsf "$COMMON_DIR/README.md" .

	# TODO: Remove it in the repo manifest.xml
	rm -f envsetup.sh

	OPTIONS="${@:-allsave}"

	# Options checking
	CMDS="$(run_build_hooks support-cmds all | xargs)"
	for opt in $OPTIONS; do
		case "$opt" in
			help | h | -h | --help | usage | \?) usage ;;
			shell | cleanall)
				# Check single options
				if [ "$opt" = "$OPTIONS" ]; then
					break
				fi

				echo "ERROR: $opt cannot combine with other options!"
				;;
			post-rootfs)
				if [ "$opt" = "$1" -a -d "$2" ]; then
					# Hide other args from build stages
					OPTIONS=$opt
					break
				fi

				echo "ERROR: $opt should be the first option followed by rootfs dir!"
				;;
			*)
				# Make sure that all options are handled
				if option_check "$CMDS" $opt; then
					continue
				fi

				echo "ERROR: Unhandled option: $opt"
				;;
		esac

		usage
	done

	# Prepare log dirs
	if [ ! -d "$RK_LOG_DIR" ]; then
		rm -rf "$RK_LOG_BASE_DIR" "$RK_LOG_DIR" "$RK_SESSION_DIR/latest"
		mkdir -p "$RK_LOG_DIR"
		ln -rsf "$RK_SESSION_DIR" "$RK_LOG_BASE_DIR"
		ln -rsf "$RK_LOG_DIR" "$RK_SESSION_DIR/latest"
		echo -e "\e[33mLog saved at $RK_LOG_DIR\e[0m"
		echo
	fi

	# Drop old logs
	cd "$RK_LOG_BASE_DIR"
	rm -rf $(ls -t | sed '1,10d')
	cd "$SDK_DIR"

	# Save initial envionments
	if [ "$INITIAL_SESSION" ]; then
		rm -f "$RK_INITIAL_ENV"
		mv "$INITIAL_ENV" "$RK_INITIAL_ENV"
		ln -rsf "$RK_INITIAL_ENV" "$RK_OUTDIR/"
	fi

	# Init stage (preparing SDK configs, etc.)
	run_build_hooks init $OPTIONS
	rm -f "$RK_OUTDIR/.tmpconfig*"

	# No need to go further
	CMDS="$(run_build_hooks support-cmds pre-build build \
		post-build | xargs) shell cleanall post-rootfs"
	option_check "$CMDS" $OPTIONS || return 0

	# Force exporting config environments
	set -a

	# Load config environments
	source "$RK_CONFIG"
	cp "$RK_CONFIG" "$RK_LOG_DIR"

	if [ -z "$INITIAL_SESSION" ]; then
		# Inherit session environments
		sed -n 's/^\(RK_.*=\)\(.*\)/\1"\2"/p' "$RK_FINAL_ENV" > \
			"$INITIAL_ENV"
		source "$INITIAL_ENV"
		rm -f "$INITIAL_ENV"
	else
		# Detect and save custom environments

		# Find custom environments
		rm -f "$RK_CUSTOM_ENV"
		for cfg in $(grep "^RK_" "$RK_INITIAL_ENV" || true); do
			env | grep -q "^${cfg//\"/}$" || \
				echo "$cfg" >> "$RK_CUSTOM_ENV"
		done

		# Allow custom environments overriding
		if [ -e "$RK_CUSTOM_ENV" ]; then
			ln -rsf "$RK_CUSTOM_ENV" "$RK_OUTDIR/"

			echo -e "\e[31mWARN: Found custom environments: \e[0m"
			cat "$RK_CUSTOM_ENV"

			echo -e "\e[31mAssuming that is expected, please clear them if otherwise.\e[0m"
			read -t 10 -p "Press enter to continue."
			source "$RK_CUSTOM_ENV"

			if grep -q "^RK_KERNEL_VERSION=" "$RK_CUSTOM_ENV"; then
				echo -e "\e[31mCustom RK_KERNEL_VERSION ignored!\e[0m"
				load_config RK_KERNEL_VERSION
			fi

			if grep -q "^RK_ROOTFS_SYSTEM=" "$RK_CUSTOM_ENV"; then
				echo -e "\e[31mCustom RK_ROOTFS_SYSTEM ignored!\e[0m"
				load_config RK_ROOTFS_SYSTEM
			fi
		fi
	fi

	source "$PARTITION_HELPER"
	rk_partition_init

	set +a

	export PYTHON3=/usr/bin/python3

	if [ "$RK_KERNEL_CFG" ]; then
		export RK_KERNEL_TOOLCHAIN="$(get_toolchain "$RK_KERNEL_ARCH")"

		CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
		export KMAKE="make -C "$SDK_DIR/kernel/" -j$(( $CPUS + 1 )) \
			CROSS_COMPILE=$RK_KERNEL_TOOLCHAIN ARCH=$RK_KERNEL_ARCH"

		export RK_KERNEL_VERSION_REAL=$(kernel_version_real)
	fi

	# Handle special commands
	case "$OPTIONS" in
		shell)
			echo -e "\e[35mDoing this is dangerous and for developing only.\e[0m"
			# No error handling in develop shell.
			set +e; trap ERR
			/bin/bash
			echo -e "\e[35mExit from $BASH_SOURCE shell.\e[0m"
			exit 0 ;;
		cleanall)
			run_build_hooks clean
			rm -rf "$RK_OUTDIR" "$SDK_DIR/rockdev"
			finish_build cleanall
			exit 0 ;;
		post-rootfs)
			shift
			run_post_hooks $@
			finish_build post-rootfs
			exit 0 ;;
	esac

	# Save final environments
	rm -f "$RK_FINAL_ENV"
	env > "$RK_FINAL_ENV"
	ln -rsf "$RK_FINAL_ENV" "$RK_OUTDIR/"

	# Log configs
	echo
	echo "=========================================="
	echo "          Final configs"
	echo "=========================================="
	env | grep -E "^RK_.*=.+" | grep -vE "PARTITION_[0-9]" | \
		grep -vE "=\"\"$|_DEFAULT=y" | \
		grep -vE "^RK_CONFIG|_BASE_CFG=|_LINK=|DIR=|_ENV=|_NAME=" | sort
	echo

	# Pre-build stage (submodule configuring, etc.)
	run_build_hooks pre-build $OPTIONS

	# No need to go further
	CMDS="$(run_build_hooks support-cmds build post-build | xargs)"
	option_check "$CMDS" $OPTIONS || return 0

	# Build stage (building, etc.)
	run_build_hooks build $OPTIONS

	# No need to go further
	CMDS="$(run_build_hooks support-cmds post-build | xargs)"
	option_check "$CMDS" $OPTIONS || return 0

	# Post-build stage (firmware packing, etc.)
	run_build_hooks post-build $OPTIONS
}

if [ "$0" != "$BASH_SOURCE" ]; then
	# Sourced, executing it directly
	"$BASH_SOURCE" ${@:-shell}
elif [ "$0" == "$BASH_SOURCE" ]; then
	# Executed directly
	main $@
fi

流程

  1. 设置导出环境变量

  2. make-targets | make-usage 参数的执行分支

  3. 创建输出目录,软连接redme等

  4. 获取支持的命令

    1. CMDS="$(run_build_hooks support-cmds all | xargs)"
      通过调用run_build_hooks 并传入参数support-cmds all 最后输出通过xargs处理,赋值给CMDS
      这个字符串包含了所有支持的命令或选项。
      
  5. 遍历选项

    1. help | h | -h | --help | usage 等调用 usage 输出帮助
    2. shell | cleanall:如果选项是shellcleanall,则执行一段检查代码,确保这些选项不是与其他选项组合使用的。如果是单独使用(即$opt等于$OPTIONS),则跳出循环;否则,显示错误信息。
    3. post-rootfs:如果选项是post-rootfs,则检查它是否是第一个选项,并且后面跟着一个目录参数。如果是,将OPTIONS设置为post-rootfs并跳出循环;否则,显示错误信息。
    4. *:对于所有其他选项,使用option_check函数检查它们是否在$CMDS中定义的支持命令列表中。如果是,则继续循环;否则,显示错误信息。
  6. 日志相关

  7. 初始化

  8. 加载配置环境变量等

  9. 设置环境变量,处理特殊命令等

  10. 输出显示最终配置信息

  11. 开始构建,最终进入run_build_hooks 传入参数 build debian

    1. 在这里插入图片描述
  12. run_build_hooks 函数

    1. 匹配分支 init | pre-build | make-* | usage | support-cmds
    2. 日志记录
    3. 调用 run_hooks device/rockchip/common/build-hook debian
  13. run_hooks

    1. 调用device/rockchip/common/build-hook 下面的sh文件

30-rootfs.sh

源码

build_debian()
{
	check_config RK_DEBIAN_VERSION || return 0

	ROOTFS_DIR="${1:-$RK_OUTDIR/debian}"
	ARCH=${RK_DEBIAN_ARCH:-armhf}

	"$SCRIPTS_DIR/check-debian.sh"

	echo "=========================================="
	echo "          Start building $RK_DEBIAN_VERSION($ARCH)"
	echo "=========================================="

	cd debian
	if [ ! -f linaro-$RK_DEBIAN_VERSION-alip-*.tar.gz ]; then
		RELEASE=$RK_DEBIAN_VERSION TARGET=desktop ARCH=$ARCH \
			./mk-base-debian.sh
		ln -sf linaro-$RK_DEBIAN_VERSION-alip-*.tar.gz \
			linaro-$RK_DEBIAN_VERSION-$ARCH.tar.gz
	fi

	VERSION=debug ARCH=$ARCH ./mk-xwrootfs-$RK_DEBIAN_VERSION.sh
	. mk-xwsysroot.sh
	./mk-image.sh

	ln -rsf "$PWD/linaro-rootfs.img" $ROOTFS_DIR/rootfs.ext4

	finish_build build_debian $@
}
build_hook()
{
	check_config RK_ROOTFS_TYPE || return 0

	if [ -z "$1" -o "$1" = rootfs ]; then
		ROOTFS=${RK_ROOTFS_SYSTEM:-buildroot}
	else
		ROOTFS=$1
	fi

	ROOTFS_IMG=rootfs.${RK_ROOTFS_TYPE}
	ROOTFS_DIR="$RK_OUTDIR/rootfs"

	echo "=========================================="
	echo "          Start building rootfs($ROOTFS)"
	echo "=========================================="

	rm -rf "$ROOTFS_DIR"
	mkdir -p "$ROOTFS_DIR"

	case "$ROOTFS" in
		yocto) build_yocto "$ROOTFS_DIR" ;;
		debian) build_debian "$ROOTFS_DIR" ;;
		buildroot) build_buildroot "$ROOTFS_DIR" ;;
		*) usage ;;
	esac

	if [ ! -f "$ROOTFS_DIR/$ROOTFS_IMG" ]; then
		echo "There's no $ROOTFS_IMG generated..."
		exit 1
	fi

	if [ "$RK_ROOTFS_INITRD" ]; then
		/usr/bin/time -f "you take %E to pack initrd image" \
			"$SCRIPTS_DIR/mk-ramdisk.sh" "$ROOTFS_DIR/$ROOTFS_IMG" \
			"$ROOTFS_DIR/boot.img" "$RK_BOOT_FIT_ITS"
		ln -rsf "$ROOTFS_DIR/boot.img" "$RK_FIRMWARE_DIR/boot.img"
	else
		ln -rsf "$ROOTFS_DIR/$ROOTFS_IMG" "$RK_FIRMWARE_DIR/rootfs.img"
	fi

	finish_build build_rootfs $@
}

流程

  1. build_hook()
    1. 进入分支build_debian
  2. build_debian
    1. 执行
    2. mk-rootfs-bullseys.sh
    3. mk-xwsysroot.sh
    4. mk-image.sh.

mk-rootfs-bullseys.sh

源码

#!/bin/bash -e

# Directory contains the target rootfs
TARGET_ROOTFS_DIR="binary"

case "${ARCH:-$1}" in
	arm|arm32|armhf)
		ARCH=armhf
		;;
	*)
		ARCH=arm64
		;;
esac

echo -e "\033[36m Building for $ARCH \033[0m"

if [ ! $VERSION ]; then
	VERSION="release"
fi

echo -e "\033[36m Building for $VERSION \033[0m"

if [ ! -e linaro-bullseye-alip-*.tar.gz ]; then
	echo "\033[36m Run mk-base-debian.sh first \033[0m"
	exit -1
fi

# 卸载挂载的目录,binary/dev
finish() {
	sudo umount $TARGET_ROOTFS_DIR/dev
	exit -1
}
# 错误处理
trap finish ERR

echo -e "\033[36m Extract image \033[0m"
sudo tar -xpf linaro-bullseye-alip-*.tar.gz

# packages folder  devmem2直接物理内存读写工具等
sudo mkdir -p $TARGET_ROOTFS_DIR/packages
sudo cp -rpf packages/$ARCH/* $TARGET_ROOTFS_DIR/packages
sudo cp -f packages/arm64/devmem2/devmem2 $TARGET_ROOTFS_DIR/usr/bin/

# overlay folder wqy-zenhei.ttf特定的字体文件
sudo cp -rpf overlay/* $TARGET_ROOTFS_DIR/
sudo cp -f overlay/usr/share/wqy-zenhei.ttf $TARGET_ROOTFS_DIR/usr/share/fonts/

# overlay-firmware folder 存放设备固件bin lib share,不能删除去掉
sudo cp -rpf overlay-firmware/* $TARGET_ROOTFS_DIR/

# overlay-debug folder
# adb, video, camera  test file 如 adb(Android Debug Bridge)、视频和相机测试文件等,可以删除
if [ "$VERSION" == "debug" ]; then
	sudo cp -rpf overlay-debug/* $TARGET_ROOTFS_DIR/
fi

# bt/wifi firmware 用于存放蓝牙和WiFi固件, 下面cp可以删除
sudo mkdir -p $TARGET_ROOTFS_DIR/system/lib/modules/
sudo mkdir -p $TARGET_ROOTFS_DIR/vendor/etc

sudo find ../kernel/drivers/net/wireless/rockchip_wlan/*  -name "*.ko" | \
    xargs -n1 -i sudo cp {} $TARGET_ROOTFS_DIR/system/lib/modules/

#这行代码将在终端中打印青色的 "Change root....................." 文本。
echo -e "\033[36m Change root.....................\033[0m"
#QEMU 用户模式模拟器
if [ "$ARCH" == "armhf" ]; then
	sudo cp /usr/bin/qemu-arm-static $TARGET_ROOTFS_DIR/usr/bin/
elif [ "$ARCH" == "arm64"  ]; then
	sudo cp /usr/bin/qemu-aarch64-static $TARGET_ROOTFS_DIR/usr/bin/
fi
# DNS 解析器配置
sudo cp -f /etc/resolv.conf $TARGET_ROOTFS_DIR/etc/

#这行代码使用 sudo mount -o bind 命令将主机的 /dev 目录绑定挂载到 $TARGET_ROOTFS_DIR/dev。
#绑定挂载是一种特殊的挂载类型,它允许你将一个已存在的目录树挂载到另一个位置,而不需要复制文件。这对于在 chroot 环境中运行程序时访问设备文件非常有用
sudo mount -o bind /dev $TARGET_ROOTFS_DIR/dev

#获取目录所有者用户ID
ID=$(stat --format %u $TARGET_ROOTFS_DIR)
#切换到根文件系统目录
cat << EOF | sudo chroot $TARGET_ROOTFS_DIR

# Fixup owners 修复文件所有者

if [ "$ID" -ne 0 ]; then
       find / -user $ID -exec chown -h 0:0 {} \;
fi
# 设置 /home 目录下各用户的主目录所有权
for u in \$(ls /home/); do
	chown -h -R \$u:\$u /home/\$u
done

# 更新软件包列表并升级已安装的软件包
echo "deb http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list

apt-get update
apt-get upgrade -y

apt-get install xinput-calibrator microcom xinput rt-tests iperf3 stress lmbench udhcpc udhcpd fio hostapd nfs-common tftp-hpa gdb gdbserver fbset ca-certificates curl gnupg lsb-release mosquitto mosquitto-clients dos2unix binutils libmosquitto-dev sqlite3 telnet vsftpd mtd-utils -y

apt-get install docker.io -y

ln -sf /usr/lib/lmbench/bin/bw_mem /usr/bin/bw_mem
ln -sf /usr/lib/lmbench/bin/stream /usr/bin/stream
ln -sf /usr/lib/lmbench/bin/msleep /usr/bin/msleep

apt-get install python3-dev python3-pip python3-libevdev -y
ln -s /usr/bin/python3 /usr/bin/python
pip3 install evdev

apt-get install  libxkbcommon-x11-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-xinerama0-dev libssl-dev libsqlite3-dev -y

chmod o+x /usr/lib/dbus-1.0/dbus-daemon-launch-helper
chmod +x /etc/rc.local

export APT_INSTALL="apt-get install -fy --allow-downgrades"

# enter root username without password
sed -i "s~\(^ExecStart=.*\)~# \1\nExecStart=-/bin/sh -c '/bin/bash -l </dev/%I >/dev/%I 2>\&1'~" /usr/lib/systemd/system/serial-getty@.service

#---------------power management --------------
\${APT_INSTALL} pm-utils triggerhappy bsdmainutils
cp /etc/Powermanager/triggerhappy.service  /lib/systemd/system/triggerhappy.service

#---------------Rga--------------
\${APT_INSTALL} /packages/rga2/*.deb

echo -e "\033[36m Setup Video.................... \033[0m"
\${APT_INSTALL} gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-alsa \
gstreamer1.0-plugins-base-apps qtmultimedia5-examples

\${APT_INSTALL} /packages/mpp/*
\${APT_INSTALL} /packages/gst-rkmpp/*.deb
\${APT_INSTALL} /packages/gstreamer/*.deb
\${APT_INSTALL} /packages/gst-plugins-base1.0/*.deb
\${APT_INSTALL} /packages/gst-plugins-bad1.0/*.deb
\${APT_INSTALL} /packages/gst-plugins-good1.0/*.deb
\${APT_INSTALL} /packages/gst-plugins-ugly1.0/*.deb
\${APT_INSTALL} /packages/gst-libav1.0/*.deb

#---------Camera---------
echo -e "\033[36m Install camera.................... \033[0m"
\${APT_INSTALL} cheese v4l-utils
\${APT_INSTALL} /packages/libv4l/*.deb
\${APT_INSTALL} /packages/cheese/*.deb

#---------Xserver---------
echo -e "\033[36m Install Xserver.................... \033[0m"
\${APT_INSTALL} /packages/xserver/*.deb

apt-mark hold xserver-common xserver-xorg-core xserver-xorg-legacy

#---------------Openbox--------------
echo -e "\033[36m Install openbox.................... \033[0m"
\${APT_INSTALL} /packages/openbox/*.deb

#---------update chromium-----
\${APT_INSTALL} /packages/chromium/*.deb

#------------------libdrm------------
echo -e "\033[36m Install libdrm.................... \033[0m"
\${APT_INSTALL} /packages/libdrm/*.deb

#------------------libdrm-cursor------------
echo -e "\033[36m Install libdrm-cursor.................... \033[0m"
\${APT_INSTALL} /packages/libdrm-cursor/*.deb

#------------------blueman------------
echo -e "\033[36m Install blueman.................... \033[0m"
\${APT_INSTALL} blueman
echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
\${APT_INSTALL} blueman
rm -f /usr/sbin/policy-rc.d

#------------------blueman------------
echo -e "\033[36m Install blueman.................... \033[0m"
\${APT_INSTALL} /packages/blueman/*.deb

#------------------rkwifibt------------
echo -e "\033[36m Install rkwifibt.................... \033[0m"
\${APT_INSTALL} /packages/rkwifibt/*.deb
ln -s /system/etc/firmware /vendor/etc/

if [ "$VERSION" == "debug" ]; then
#------------------glmark2------------
echo -e "\033[36m Install glmark2.................... \033[0m"
\${APT_INSTALL} /packages/glmark2/*.deb
fi

if [ -e "/usr/lib/aarch64-linux-gnu" ] ;
then
#------------------rknpu2------------
echo -e "\033[36m move rknpu2.................... \033[0m"
mv /packages/rknpu2/*.tar  /
fi

#------------------rktoolkit------------
echo -e "\033[36m Install rktoolkit.................... \033[0m"
\${APT_INSTALL} /packages/rktoolkit/*.deb

echo -e "\033[36m Install Chinese fonts.................... \033[0m"
# Uncomment zh_CN.UTF-8 for inclusion in generation
sed -i 's/^# *\(zh_CN.UTF-8\)/\1/' /etc/locale.gen
echo "LANG=zh_CN.UTF-8" >> /etc/default/locale

# Generate locale
locale-gen

# Export env vars
echo "export LANG=C.UTF-8" >> ~/.bashrc

source ~/.bashrc

\${APT_INSTALL} ttf-wqy-zenhei fonts-aenigma
\${APT_INSTALL} xfonts-intl-chinese

# HACK debian11.3 to fix bug
\${APT_INSTALL} fontconfig --reinstall

#\${APT_INSTALL} xfce4
#ln -sf /usr/bin/startxfce4 /etc/alternatives/x-session-manager

# HACK to disable the kernel logo on bootup 禁用启动时的内核logo
#sed -i "/exit 0/i \ echo 3 > /sys/class/graphics/fb0/blank" /etc/rc.local

cp /packages/libmali/libmali-*-x11*.deb /
cp -rf /packages/rkisp/*.deb /
cp -rf /packages/rkaiq/*.deb /
cp -rf /usr/lib/firmware/rockchip/ /

# reduce 500M size for rootfs
rm -rf /usr/lib/firmware
mkdir -p /usr/lib/firmware/
mv /rockchip /usr/lib/firmware/

# mark package to hold  锁定已安装的软件包,以防止它们被自动更新
apt list --installed | grep -v oldstable | cut -d/ -f1 | xargs apt-mark hold

#---------------Custom Script-------------- 禁用自启动的一些服务,wifi等
systemctl mask systemd-networkd-wait-online.service
systemctl mask NetworkManager-wait-online.service
rm /lib/systemd/system/wpa_supplicant@.service

#------remove unused packages------------
apt remove --purge -fy linux-firmware*

#---------------Clean--------------
if [ -e "/usr/lib/arm-linux-gnueabihf/dri" ] ;
then
        # Only preload libdrm-cursor for X
        sed -i "1aexport LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libdrm-cursor.so.1" /usr/bin/X
        cd /usr/lib/arm-linux-gnueabihf/dri/
        cp kms_swrast_dri.so swrast_dri.so rockchip_dri.so /
        rm /usr/lib/arm-linux-gnueabihf/dri/*.so
        mv /*.so /usr/lib/arm-linux-gnueabihf/dri/
elif [ -e "/usr/lib/aarch64-linux-gnu/dri" ];
then
        # Only preload libdrm-cursor for X
        sed -i "1aexport LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libdrm-cursor.so.1" /usr/bin/X
        cd /usr/lib/aarch64-linux-gnu/dri/
        cp kms_swrast_dri.so swrast_dri.so rockchip_dri.so /
        rm /usr/lib/aarch64-linux-gnu/dri/*.so
        mv /*.so /usr/lib/aarch64-linux-gnu/dri/
        rm /etc/profile.d/qt.sh
fi
cd -

rm -rf /var/lib/apt/lists/*
rm -rf /var/cache/
rm -rf /packages/

# Remove usb network card rules
rm /usr/lib/systemd/network/73-usb-net-by-mac.link


EOF

# let root user can autologin and enter the ~ directory
sudo sed -i 's|ExecStart=-/bin/sh -c '\''/bin/bash -l </dev/%I >/dev/%I 2>&1'\''|ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM|' $TARGET_ROOTFS_DIR/lib/systemd/system/serial-getty@.service

sudo umount $TARGET_ROOTFS_DIR/dev

流程

  1. 进行文件系统构建,安装库,等

mk-sysroot.sh

源码

#!/bin/bash -e

TARGET_ARM_DIR="./sysroots/armv8a-linux"
TARGET_x86_DIR="./sysroots/x86_64-linux"

LOCAL_PATH=$(pwd)
SDK_PATH_=$(dirname "$PWD")

export DEBIAN_PATH=$LOCAL_PATH

if [ -d "sysroots" ]; then
  sudo rm -r sysroots
fi

# Create sysroot
echo "----------copy binary-----------"
sudo mkdir -p sysroots
sudo mkdir -p $TARGET_ARM_DIR
sudo mkdir -p $TARGET_x86_DIR
sudo mkdir -p $TARGET_x86_DIR/environment-setup.d

sudo cp -r ./binary/usr/lib $TARGET_ARM_DIR
sudo cp -r ./binary/{boot,etc,opt,proc,run,srv,sys,tmp,usr,var} $TARGET_ARM_DIR

# Copy toolchain lib
TOOLCHAIN_PATH=../extra-tools/gcc-linaro-10.2.1-2021.01-x86_64_aarch64-linux-gnu
sudo mkdir -p $TARGET_ARM_DIR/usr/lib64
sudo mkdir -p $TARGET_ARM_DIR/lib64
sudo cp $TOOLCHAIN_PATH/aarch64-linux-gnu/lib64/* $TARGET_ARM_DIR/usr/lib64 -r
sudo cp $TOOLCHAIN_PATH/aarch64-linux-gnu/lib64/* $TARGET_ARM_DIR/lib64 -r
sudo cp $TOOLCHAIN_PATH/aarch64-linux-gnu/libc/lib/libm.so.6 $TOOLCHAIN_PATH/aarch64-linux-gnu/libc/lib/libc.so.6 $TARGET_ARM_DIR/lib64

# Create environment
# Used to set environment variables
sudo touch $LOCAL_PATH/sysroots/environment

ENV_PATH=$LOCAL_PATH/sysroots/environment

echo "export _SDK_PATH=$SDK_PATH_" | sudo tee -a $ENV_PATH
echo 'export PATH=$_SDK_PATH/extra-tools/gcc-linaro-10.2.1-2021.01-x86_64_aarch64-linux-gnu/bin:$PATH' | sudo tee -a $ENV_PATH
echo 'export CC=aarch64-linux-gnu-gcc' | sudo tee -a $ENV_PATH
echo 'export CXX=aarch64-linux-gnu-g++' | sudo tee -a $ENV_PATH
echo 'export AR=aarch64-linux-gnu-ar' | sudo tee -a $ENV_PATH
echo 'export OBJCOPY=aarch64-linux-gnu-objcopy' | sudo tee -a $ENV_PATH
echo 'export NM=aarch64-linux-gnu-nm' | sudo tee -a $ENV_PATH
echo 'export STRIP=aarch64-linux-gnu-strip' | sudo tee -a $ENV_PATH
echo 'if [ -d "$_SDK_PATH/debian/sysroots/x86_64-linux/environment-setup.d" ]; then
    for envfile in $_SDK_PATH/debian/sysroots/x86_64-linux/environment-setup.d/*.sh; do
        . $envfile
    done
fi' | sudo tee -a $ENV_PATH


sudo touch $TARGET_x86_DIR/environment-setup.d/qt5.sh

QT5_PATH="$TARGET_x86_DIR/environment-setup.d/qt5.sh"
echo 'export SDK_QMAKE_CC="$CC"' | sudo tee -a $QT5_PATH
echo 'export SDK_QMAKE_CXX="$CXX"' | sudo tee -a $QT5_PATH
echo 'export SDK_QMAKE_LINK="$CXX"' | sudo tee -a $QT5_PATH
echo 'export SDK_QMAKE_AR="$AR"' | sudo tee -a $QT5_PATH
echo 'export SDK_QMAKE_STRIP="$STRIP"' | sudo tee -a $QT5_PATH
echo 'export SDK_QMAKE_OBJCOPY="$OBJCOPY"' | sudo tee -a $QT5_PATH

source ./sysroots/environment

# Establish library soft link
sudo rm ./sysroots/armv8a-linux/lib/aarch64-linux-gnu/libpthread.a
sudo rm ./sysroots/armv8a-linux/lib/aarch64-linux-gnu/libdl.a
cd ./sysroots/armv8a-linux/usr/lib/aarch64-linux-gnu/
sudo ln -sf ../../lib/aarch64-linux-gnu/libz.so.1.2.11 libz.so
sudo ln -sf libsystemd.so.0 libsystemd.so
sudo ln -sf ../../lib/aarch64-linux-gnu/liblzma.so.5.2.5 liblzma.so
sudo ln -sf libgcrypt.so.20 libgcrypt.so
sudo ln -sf libgpg-error.so.0 libgpg-error.so
sudo ln -sf libstdc++.so.6 libstdc++.so
sudo ln -sf libbsd.so.0 libbsd.so
sudo ln -sf libmd.so.0 libmd.so
sudo rm libdl.so
sudo ln -sf libdl.so.2 libdl.so
sudo rm libm.so
sudo ln -sf libm.so.6 libm.so
sudo ln -sf libxcb-util.so.1 libxcb-util.so
sudo rm libpcre.so
sudo ln -sf libpcre.so.3 libpcre.so
sudo rm libpthread.a
sudo rm libpthread.so
sudo ln -sf libpthread.so.0 libpthread.so
cd -

echo "----------copy binary success-----------"

# Compile Qt
#cd ./packages/arm64/qt5
#source qt-build.sh

#sudo mkdir -p $(pwd)/binary/usr/lib/qt-5.15.8
#QT5_LIB=$(pwd)/binary/usr/lib/qt-5.15.8

#sudo cp $TARGET_x86_DIR/lib $QT5_LIB -r
#sudo cp $TARGET_x86_DIR/plugins $QT5_LIB -r
#sudo mkdir -p $TARGET_ARM_DIR/usr/lib/qt-5.15.8
#sudo cp $TARGET_x86_DIR/lib $TARGET_ARM_DIR/usr/lib/qt-5.15.8 -r
#sudo cp $TARGET_x86_DIR/include $TARGET_ARM_DIR/usr/lib/qt-5.15.8 -r
#sudo cp $TARGET_x86_DIR/bin $TARGET_ARM_DIR/usr/lib/qt-5.15.8 -r
#sudo cp $TARGET_x86_DIR/mkspecs $TARGET_ARM_DIR/usr/lib/qt-5.15.8 -r
##sudo cp $TARGET_x86_DIR/plugins $TARGET_ARM_DIR/usr/lib/qt-5.15.8 -r

# Set Qt environment variables
#QT5SH_PATH=$LOCAL_PATH/binary/etc/profile.d/qt5.15.8.sh

#sudo touch $QT5SH_PATH
#echo "export QT_ROOT=/usr/lib/qt-5.15.8" | sudo tee -a $QT5SH_PATH
#echo "export QT_QPA_FONTDIR=/usr/share/fonts" | sudo tee -a $QT5SH_PATH
#echo 'export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins' | sudo tee -a $QT5SH_PATH
#echo 'export QT_PLUGIN_PATH=$QT_ROOT/plugins' | sudo tee -a $QT5SH_PATH
#echo 'export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms' | sudo tee -a $QT5SH_PATH

流程

  1. cp 跟文件系统的库,制作交叉编译环境
  2. 制作交叉编译,配置文件
  3. 配置,编译qt,并cp到跟文件系统

mk-image.sh

源码

#!/bin/bash -e

TARGET_ROOTFS_DIR=./binary
ROOTFSIMAGE=linaro-rootfs.img
EXTRA_SIZE_MB=300
IMAGE_SIZE_MB=$(( $(sudo du -sh -m ${TARGET_ROOTFS_DIR} | cut -f1) + ${EXTRA_SIZE_MB} ))


echo Making rootfs!

if [ -e ${ROOTFSIMAGE} ]; then
	rm ${ROOTFSIMAGE}
fi

for script in ./post-build.sh ../device/rockchip/common/post-build.sh; do
	[ -x $script ] || continue
	sudo $script "$(realpath "$TARGET_ROOTFS_DIR")"
done

dd if=/dev/zero of=${ROOTFSIMAGE} bs=1M count=0 seek=${IMAGE_SIZE_MB}

sudo mkfs.ext4 -d ${TARGET_ROOTFS_DIR} ${ROOTFSIMAGE}

echo Rootfs Image: ${ROOTFSIMAGE}

流程

  1. 运行2个 post-build.sh
  2. 制作打包跟文件系统

post-build.sh

后续的配置信息

  1. 文件系统的挂载信息修改添加
  2. 执行 device/rockchip/common/post-hooks 下的sh,启动一些服务?
    1. 02-usb.sh
    2. 05-udev.sh
    3. 06-async-commit.sh
    4. 10-os-release.sh
    5. 20-info.sh
    6. 30-fstab.sh
    7. 40-busybox-reboot.sh
    8. 50-locale.sh
    9. 60-dirs.sh
    10. 90-overlay.sh
    11. 95-partitions.sh
    12. 99-owner.sh

大致流程

  1. 编译安装必要库drm,npu等
    1. 进入文件系统,然后gtp命令安装
  2. 然后cp ln等,qt编译安装
  3. 文件系统制作

系统制作步骤

  1. 解压 debian,原始根文件系统

    sudo tar -xpf linaro-bullseye-alip-20240903-1.tar.gz 
    
  2. 获取文件系统大小,然后+300

    sudo du -sh -m ./binary | cut -f1
    
  3. 创建文件

    dd if=/dev/zero of=linaro-rootfsxw.img bs=1M count=0 seek=2385
    
  4. 写入内容并格式化ext4

    sudo mkfs.ext4 -d ./binary linaro-rootfsxw.img 
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2272817.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

倾斜摄影相机在不动产确权登记和权籍调查中的应用

一、项目背景 1.1 项目背景 为贯彻落实中央、国务院关于实施乡村振兴战略、关于“扎实推进房地一体的农村集体建设用地和宅基地使用权确权登记颁证&#xff0c;完善农民闲置宅基地和闲置农房政策&#xff0c;探索宅基地所有权、资格权、使用权‘三权分置’”的要求&#xff0…

在K8S上部署OceanBase的最佳实践

在K8S上部署OceanBase的最佳实践 目录 1. 背景与选型 1.1 为什么选择OB1.2 为什么选择ob-operator实现OB on K8S 2. 部署实操 2.1 环境准备2.2 安装 ob-operator2.3 配置 OB 集群2.4 配置 OBProxy 集群2.5 Headless Service 和 CoreDNS 配置2.6 监控与运维 2.6.1 Promethues部…

【设计模式-1】软件设计模式概述

1. 软件设计模式的产生背景 “设计模式”这个术语最初并不是出现在软件设计中&#xff0c;而是被用于建筑领域的设计中。 1977 年&#xff0c;美国著名建筑大师、加利福尼亚大学伯克利分校环境结构中心主任克里斯托夫亚历山大&#xff08;Christopher Alexander&#xff09;在…

Nginx——反向代理(三/五)

目录 1.Nginx 反向代理1.1.Nginx 反向代理概述1.2.Nginx 反向代理的配置语法1.2.1.proxy_pass1.2.2.proxy_set_header1.2.3.proxy_redirect 1.3.Nginx 反向代理实战1.4.Nginx 的安全控制1.4.1.如何使用 SSL 对流量进行加密1.4.2.Nginx 添加 SSL 的支持1.4.3.Nginx 的 SSL 相关指…

win10 VS2019上libtorch库配置过程

win10 VS2019上libtorch库配置过程 0 引言1 获取libtorch2 在VS上配置使用libtorch库3 结语 0 引言 &#x1f4bb;&#x1f4bb;AI一下&#x1f4bb;&#x1f4bb;   libtorch库是一个用于深度学习的C库&#xff0c;是PyTorch的官方C前端。它提供了用于构建和训练深度学习模…

Windows 环境配置 HTTPS 服务实战

一、 环境准备 win10以上操作系统安装 Certbot申请阿里云\腾讯云域名安装 nginx 1.3以上版本 二、Certbot 安装及 SSL 证书生成 Certbot 是一个免费、开源工具&#xff0c;用于自动化在Web服务器上获取和更新SSL/TLS证书。它可以通过Let’s Encrypt服务获取免费的SSL/TLS证书…

【C++数据结构——图】最小生成树(头歌实践教学平台习题) 【合集】

目录&#x1f60b; 任务描述 相关知识 带权无向图 建立邻接矩阵 Prim算法 1. 算法基本概念 2. 算法背景与目标 3. 算法具体步骤 4. 算法结束条件与结果 测试说明 通关代码 测试结果 任务描述 本关任务&#xff1a;编写一个程序求图的最小生成树。 相关知识 为了完成…

11.认识异常

本节目标 1.异常概念与体系结构 2.异常的处理方式 3.异常的处理流程 4.自定义异常类 1.异常的概念与体系结构 1.1异常的概念 在Java中,将程序执行过程中发生的不正常行为称为异常,比如: 1.算术异常 System.out.println(10/0);//执行结果 Exception in thread "mai…

基于海思soc的智能产品开发(camera sensor的两种接口)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 对于嵌入式开发设备来说&#xff0c;除了图像显示&#xff0c;图像输入也是很重要的一部分。说到图像输入&#xff0c;就不得不提到camera。目前ca…

vulnhub靶场-potato(至获取shell)

arp-scan -l 扫描IP 使用御剑端口扫描扫描端口&#xff0c;扫到了80和7120两个端口&#xff0c;其中7120为ssh端口 使用dirb http://192.168.171.134 扫描目录 发现info.php 访问为phpinfo界面 访问192.168.171.134为一个大土豆&#xff0c;没什么用 所以我们从ssh入手 盲…

Flutter:邀请海报,Widget转图片,保存相册

记录下&#xff0c;把页面红色区域内的内容&#xff0c;转成图片后保存到相册的功能 依赖 # 生成二维码 qr_flutter: ^4.1.0 # 保存图片 image_gallery_saver_plus: ^3.0.5view import package:demo/common/index.dart; import package:ducafe_ui_core/ducafe_ui_core.dart; i…

Milvus×合邦电力:向量数据库如何提升15%电价预测精度

01. 全球能源市场化改革下的合邦电力 在全球能源转型和市场化改革的大背景下&#xff0c;电力交易市场正逐渐成为优化资源配置、提升系统效率的关键平台。电力交易通过市场化手段&#xff0c;促进了电力资源的有效分配&#xff0c;为电力行业的可持续发展提供了动力。 合邦电力…

网络层协议之IP数据包层分片随笔

1.全篇内容均在图中&#xff0c;如何分片以及分片举例细节拆解&#xff0c;见下图: 1.1分片公式&#xff1a; 上述公式中有关/8 再*8目的是为了使用8字节对齐&#xff0c;从而使的分片数据包均为8字节整数倍&#xff01; 1.2.ip层数据包分片计算&图解

TDengine + MQTT :车联网时序数据库如何高效接入

现代新能源汽车&#xff0c;作为一种内部系统极为复杂的交通工具&#xff0c;配备了大量传感器、导航设备、应用软件&#xff0c;这些传感器产生的数据都需要上报到车联网平台当中。对于这些车辆的状态数据&#xff08;如车速、发动机转速等&#xff09;、位置数据&#xff08;…

jenkins入门3 --执行一个小demo

1、新建视图 视图可以理解为是item的集合&#xff0c;这样可以将item分类。新建视频可以选择加入已有的item 2、新建item 1)输入任务名称、选择一个类型&#xff0c;常用的是第一个freestyle project 2&#xff09;进行item相关配置&#xff0c;general 设置项目名字,描述,参数…

【Vue.js】监听器功能(EventListener)的实际应用【合集】

目录 &#x1f914;在实际开发过程中&#xff0c;我遇到了一个颇为棘手的小问题 &#x1f60b;解决这个小问题 问题出现的原因剖析 解决方法阐述 问题成功解决&#xff01;​ &#x1f4d6;相关知识总结 基本概念 使用方法 实际应用场景 &#x1f914;在实际开发过程中…

【C++数据结构——线性表】顺序表的基本运算(头歌实践教学平台习题)【合集】

目录&#x1f60b; 任务描述 相关知识 一、线性表的基本概念 二、初始化线性表 三、销毁线性表 四、判定是否为空表 五、求线性表的长度 六、输出线性表 七、求线性表中某个数据元素值 八、按元素值查找 九、插入数据元素 十、删除数据元素 测试说明 通关代码 测…

【C++数据结构——查找】二分查找(头歌实践教学平台习题)【合集】

目录&#x1f60b; 任务描述 相关知识 一、根据键盘输入的一组有序数据建立顺序表 二、顺序表的输出 三、二分查找算法 测试说明 通关代码 测试结果 任务描述 本关任务&#xff1a;实现二分查找的算法。 相关知识 为了完成本关任务&#xff0c;你需要掌握&#xff1a; …

20250103在Ubuntu20.04.5的Android Studio 2024.2.1.12中跑通Hello World

20250103在Ubuntu20.04.5的Android Studio 2024.2.1.12中跑通Hello World 2025/1/3 14:06 百度&#xff1a;android studio helloworld android studio hello world kotlin helloword kotlin 串口 no run configurations added android studio no run configurations added 1、…

卸载干净 IDEA(图文讲解)

目录 1、卸载 IDEA 程序 2、注册表清理 3、残留清理 1、卸载 IDEA 程序 点击屏幕左下角 Windows 图标 -> 设置-控制面板->intellij idea 勾选第一栏 Delete IntelliJ IDEA 2022.2 caches and local history&#xff0c;表示同时删除 IDEA 本地缓存以及历史。 Delete I…