小米MIX3尝试运行ubuntu-desktop的一些记录

小米MIX3尝试运行ubuntu-desktop的一些记录

文中部分方法来自网络。
作者:斈 (QQ:1405728198),Sophon

rootfs制作

目前我使用的是方法2

方法1 使用 ubuntu-base文件进行制作

准备 ubuntu-base文件

根文件包采用 ubuntu-base-20.04.2-base-arm64.tar.gz

wget http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.2-base-arm64.tar.gz
mkdir rootfs-perseus
cd rootfs-perseus
sudo tar -zxvf ../ubuntu-base-20.04.2-base-arm64.tar.gz

准备 chroot 环境

安装 qemu

sudo apt install qemu-user-static

复制系统的 resolv.conf 以便联网

sudo cp /etc/resolv.conf etc/resolv.conf
cd ..

因为 ubuntu20.04-base 默认没有安装 locales ,因此需要在执行 apt install 之前使用 dpkg -i 命令安装,以避免在 apt install 过程中提示错误

wget http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/locales_2.31-0ubuntu9_all.deb # 目前最新版为 locales_2.31
sudo cp locales_2.31-0ubuntu9_all.deb rootfs-perseus/root/

进行chroot

sudo ./ch-mount.sh -m rootfs-perseus

ch-mount.sh 内容:

#!/bin/bash

function mnt() {
	echo "Mounting file system ..."
	mount -t proc /proc ${1}proc
	mount -t sysfs /sys ${1}sys
	mount -o bind /dev ${1}dev
	mount -o bind /dev/pts ${1}dev/pts
	chroot ${1}
}
function umnt() {
	echo "UnMounting file system ..."
	umount ${1}proc
	umount ${1}sys
	umount ${1}dev/pts
	umount ${1}dev
}

if [[ $EUID -ne 0 ]]; then
   echo "Error:This script must be run as root!" 1>&2
   exit 1
fi
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
	mnt ${2}
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
	umnt ${2}
else
	echo ""
	echo "Either 1'st, 2'nd or both parameters were missing"
	echo ""
	echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
	echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
	echo ""
	echo "For example: ch-mount -m /media/sdcard/"
	echo ""
	echo 1st parameter : ${1}
	echo 2nd parameter : ${2}
fi

系统配置

安装 locales

cd root
dpkg -i locales_2.31-0ubuntu9_all.deb

设置 locales

locale-gen en_US.UTF-8
locale-gen zh_CN.UTF-8

设置 hostname (内容随意)

echo 'Mix3' > /etc/hostname

更新 apt 列表

apt update

安装基础包 [ubuntu 20.04] 这里使用 netplan 配置网络 (这里没有安装桌面环境)

apt install man-db sudo openssh-server net-tools network-manager iputils-ping bash-completion kmod busybox-initramfs cpio initramfs-tools initramfs-tools-bin initramfs-tools-core linux-base netplan.io --no-install-recommends -y

实际安装的包

bash-completion bsdmainutils busybox-initramfs cpio dbus groff-base initramfs-tools initramfs-tools-bin initramfs-tools-core iproute2 iputils-ping klibc-utils kmod libapparmor1 libargon2-1 \
libasn1-8-heimdal libbluetooth3 libbrotli1 libbsd0 libcap2 libcap2-bin libcbor0.6 libcryptsetup12 libcurl3-gnutls libdbus-1-3 libdevmapper1.02.1 libedit2 libelf1 libexpat1 libfido2-1 libgdbm6 \
libglib2.0-0 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal libip4tc2 libjansson4 libjson-c4 libk5crypto3 libkeyutils1 libklibc \
libkmod2 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common libmm-glib0 libmnl0 libmpdec2 libndp0 libnetplan0 libnewt0.52 libnghttp2-14 libnl-3-200 libnl-genl-3-200 \
libnl-route-3-200 libnm0 libpam-systemd libpcsclite1 libpipeline1 libpolkit-agent-1-0 libpolkit-gobject-1-0 libpsl5 libpython3-stdlib libpython3.8-minimal libpython3.8-stdlib libreadline8 \
libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules-db libslang2 libsqlite3-0 libssh-4 libssl1.1 libteamdctl0 libuchardet0 libwind0-heimdal libwrap0 libxtables12 libyaml-0-2 linux-base lz4 \
man-db mime-support net-tools netplan.io network-manager openssh-client openssh-server openssh-sftp-server policykit-1 python3 python3-minimal python3-netifaces python3-yaml python3.8 \
python3.8-minimal readline-common sudo systemd systemd-sysv systemd-timesyncd ucf udev wpasupplicant

安装内核文件

这一部分为使用 dpkg -i 进行安装 (参照 locales 的安装方式)
安装后的 dtb 文件在 /usr/lib/linux-image-5.12.9-xiaomi-sdm845/qcom/ 路径下

清理前期手动添加到 root目录下的 .deb 文件

rm linux* locales_2.31-0ubuntu9_all.deb

创建initrd.img

mkinitramfs -o /boot/initrd.img [内核版本号]
# 例如 :mkinitramfs -o /boot/initrd.img 5.12.9-xiaomi-sdm845

退出chroot

exit

取消挂载

sudo ./ch-mount.sh -u rootfs-perseus

方法2 使用 focal-desktop-arm64.iso文件进行制作

准备iso文件

下载 focal-desktop-arm64.iso 文件,下载地址:
http://cdimage.ubuntu.com/focal/daily-live/current/

使用解压软件打开 iso 文件,提取 casper/filesystem.squashfs

unsquashfs -d mydir filesystem.squashfs # 解压到mydir目录,mydir目录不允许存在
unsquashfs filesystem.squashfs # 得到 squashfs-root 文件夹

修改squashfs-root

删除系统自带的多余软件

Ubuntu pre-12.04
From a gnome-terminal do:

cat filesystem.manifest-desktop | awk '{print $1}' | sort > default.txt

This will get rid of the package versions and leave you with a sorted list default.txt containing all packages that are installed by default. As mentioned in the linked question, keep in mind that you might changed the default installation when installing updates and/or restricted packages during the installation of Ubuntu.

Ubuntu 12.04
The above step has changed a bit. To get a list of the packages that are initially installed, you need to unpack two files:

filesystem.manifest
filesystem.manifest-remove

To get what you want, you need to remove the latter from the former:

comm -3 <(cat filesystem.manifest | awk '{print $1}' | sort) <(cat filesystem.manifest-remove | sort) > default.txt
comm -3 <(cat filesystem.manifest | awk '{print $1}' | sort) <(cat filesystem.manifest-minimal-remove | sort) > default.txt

Now continue like pre-12.04:

dpkg --get-selections | awk '{print $1}' | sort > current.txt

This will get you a sorted list current.txt of all currently installed packages.

diff -u default.txt current.txt | grep "^+[^+]" | cut -c 2- > installed.txt
diff -u default.txt current.txt | grep "^-[^-]" | cut -c 2- > uninstalled.txt

This will get you the differences between the two package lists, where installed.txt contains all packages not part of the default installation, and uninstalled.txt contains all packages you are missing compared to a default installation.

修改分区信息

手机分区uuid信息 [ esp(efi):07A6-8B46 linux:7e454382-2dc0-467b-ae53-0972ad622530 ]
uuid 可通过 blkid /dev/block/sdaXX 获得

文件 /etc/fstab # 位于 linux 分区

cat << __EOF__ > /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during installation
UUID=7e454382-2dc0-467b-ae53-0972ad622530 /    ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=07A6-8B46  /boot/efi       vfat    umask=0077      0       1
/swapfile       none            swap    sw              0       0
__EOF__

配置grub

文件 EFI/ubuntu/grub.cfg # 位于 esp 分区

cat << __EOF__ > EFI/ubuntu/grub.cfg
search.fs_uuid 7e454382-2dc0-467b-ae53-0972ad622530 root 
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
__EOF__

文件 /boot/grub/grub.cfg # 位于 linux 分区

cat << __EOF__ > /boot/grub/grub.cfg
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; then
  clear
fi

insmod gzio

set timeout=1
menuentry  'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-7e454382-2dc0-467b-ae53-0972ad622530' {
	set gfxpayload=keep
	devicetree /boot/perseus.dtb
	search --no-floppy --fs-uuid --set=root 7e454382-2dc0-467b-ae53-0972ad622530
	linux	/boot/vmlinuz root=UUID=7e454382-2dc0-467b-ae53-0972ad622530 rw pd_ignore_unused clk_ignore_unused efi=novamap loglevel=7 splash --
	initrd	/boot/initrd.img
}

menuentry 'Boot from next volume' {
	exit 1
}

menuentry 'UEFI Firmware Settings' {
	fwsetup
}
__EOF__

内核

来源

  • linux-next

    包含最新的Linux源码,更新频繁,同时也比较不稳定

  • edk2-porting/linux-snapdragon

    基于最新的linux-stable,同时并入了一些来自linux-next或patchwork的与高通平台有关的patch

修改dts

为了OTG挂载U盘,我需要将dts文件中的

&usb_1_dwc3 {
	dr_mode = "peripheral";

	/* fastest mode for USB 2 */
	maximum-speed = "high-speed";
	
	/* Remove USB3 phy */
	phys = <&usb_1_hsphy>;
	phy-names = "usb2-phy";
};

修改为

&usb_1_dwc3 {
	dr_mode = "host";

	/* fastest mode for USB 2 */
	maximum-speed = "high-speed";
	
	/* Remove USB3 phy */
	phys = <&usb_1_hsphy>;
	phy-names = "usb2-phy";
};

编译内核deb文件

修改 scripts/setlocalversion 中的 res 可以避免在版本号后面添加 “+”号(直接删除那段if-else) [这完全没必要]
禁用 fts 驱动可以避免屏幕一直打印geni_i2c a90000.i2c:dma_map_single:for tx faild
方法 : 新建 /etc/modprobe.d/fts.conf 添加内容为 blacklist fts (将 fts 加入黑名单以避免加载)
查看日志 journalctl --root=

ccache make -j4 ARCH=arm64 KBUILD_DEBARCH=arm64 KDEB_CHANGELOG_DIST=focal CROSS_COMPILE=aarch64-linux-gnu- O=out perseus_defconfig bindeb-pkg

或者从 GNU Toolchain | GNU-A Downloads – Arm Developer 下载

make -j4 ARCH=arm64 KBUILD_DEBARCH=arm64 KDEB_CHANGELOG_DIST=focal CROSS_COMPILE=/home/xue/WorkSpace/perseus/dl/gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- deb-pkg

wifi 相关

生成手机的 board-2.bin 文件
创建 board-2.bin 文件夹

mkdir -p board-2.bin/bdf && cd board-2.bin/bdf

从手机 /firmware/image 目录复制 bdwlan.b* 文件

cp bdwlan.b* .
cd ..

创建脚本内容如下

cat << __EOF__ > make_board-2.bin.sh
#!/bin/bash

if [ \! -d qca-swiss-army-knife ]; then
        git clone https://hub.fastgit.org/qca/qca-swiss-army-knife.git
        exit 0
fi

JSON="bdf/board-2.json"

iter=0
echo "[" > "${JSON}"
for file in bdf/bdwlan.*; do
 [[ $file == *.txt ]] && continue

 iter=$((iter+1))
 [ $iter -ne 1 ] && echo "  }," >> "${JSON}"

 echo "  {" >> "${JSON}"
 echo "          \"data\": \"$file\"," >> "${JSON}"
 if [[ $file == */bdwlan.bin ]]; then
  file_ext="ff"	# 注意,Mix3此处为 ff
 else
  file_ext="$(printf '%x\n' "$(basename "${file}" | sed -E 's:^.*\.b?([0-9a-f]*)$:0x\1:')")"
 fi
 echo "          \"names\": [\"bus=snoc,qmi-board-id=${file_ext}\"]" >> "${JSON}"
done

echo "  }" >> "${JSON}"
echo "]" >> "${JSON}"

python2 qca-swiss-army-knife/tools/scripts/ath10k/ath10k-bdencoder -c "${JSON}" -o board-2.bin
__EOF__

为 make_board-2.bin.sh 添加执行权限

chmod +x make_board-2.bin.sh

执行 make_board-2.bin.sh 创建 board-2.bin 文件

./make_board-2.bin.sh

将生成的 board-2.bin 文件拷贝至 /lib/firmware/ath10k/WCN3990/hw1.0/ 下

cp board-2.bin /lib/firmware/ath10k/WCN3990/hw1.0/

安装 qrtr rmtfs pd-mapper tqftpserv ( 后面三个依赖第一个 )

apt install git build-essential libudev-dev --no-install-recommends -y

git clone https://hub.fastgit.org/andersson/qrtr.git
git clone https://hub.fastgit.org/andersson/rmtfs.git
git clone https://hub.fastgit.org/andersson/pd-mapper.git
git clone https://hub.fastgit.org/andersson/tqftpserv.git

注意此4个程序的默认安装目录位于 /usr/local/bin /usr/local/include /usr/local/lib 下, 这里我将其安装至 /usr/bin /usr/lib /etc/systemd/system/ 下

cd qrtr && make && make install && cd ..
cd rmtfs && make && make install && cd ..
cd pd-mapper && make && make install && cd ..
cd tqftpserv && make && make install && cd ..

systemctl enable qrtr-ns
systemctl enable pd-mapper
systemctl enable tqftpserv
systemctl enable rmtfs

systemctl start qrtr-ns
systemctl start pd-mapper
systemctl start tqftpserv
systemctl start rmtfs

firmware 相关

生成mbn格式固件

git clone https://hub.fastgit.org/edk2-porting/pil-squasher.git

cd pil-squasher && make && make install

pil-squasher使用方法

pil-squasher xxx.mbn xxx.mdt

涉及的文件包含:

/lib/firmware/qcom/a630_zap.mbn

/lib/firmware/qcom/sdm845/adsp.mbn
/lib/firmware/qcom/sdm845/cdsp.mbn
/lib/firmware/qcom/sdm845/modem.mbn

/lib/firmware/qcom/venus-5.2/venus.mbn

复制替换的文件

/lib/firmware/qcom/a630_sqe.fw
/lib/firmware/qcom/a630_gmu.bin

/lib/firmware/qcom/sdm845/adspr.jsn
/lib/firmware/qcom/sdm845/adspua.jsn
/lib/firmware/qcom/sdm845/cdspr.jsn
/lib/firmware/qcom/sdm845/mba.mbn
/lib/firmware/qcom/sdm845/modemuw.jsn
/lib/firmware/qcom/sdm845/wlanmdsp.mbn

/lib/firmware/qcom/venus-5.2/venus.b00
/lib/firmware/qcom/venus-5.2/venus.b01
/lib/firmware/qcom/venus-5.2/venus.b02
/lib/firmware/qcom/venus-5.2/venus.b03
/lib/firmware/qcom/venus-5.2/venus.b04
/lib/firmware/qcom/venus-5.2/venus.mdt

手动增加以下文件

/lib/firmware/st_fts_e5.ftb	# fts 固件,来自 https://github.com/MiCode/Xiaomi_Kernel_OpenSource/tree/dipper-q-oss 编译文件
/lib/firmware/stm_fts_production_limits.csv	# fts 文件,来自手机
/lib/firmware/tas2557_uCDSP.bin	# 来自手机

grub 相关

5.13.5-sdm845 根据内核具体版本而定

ln -s initrd.img-5.13.5-sdm845 initrd.img
ln -s vmlinuz-5.13.5-sdm845 vmlinuz
ln -s /usr/lib/linux-image-5.12.15-sdm845/qcom/sdm845-xiaomi-perseus.dtb perseus.dtb
2 Likes

:grinning_face_with_smiling_eyes: :smiley: :grinning: :smiley: :grinning: :smiley: :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes: :grin: :laughing: :laughing: :grin: :slightly_smiling_face: :slightly_smiling_face: :blush: :blush: :smiley: :grin:

4 Likes

1+6T可以刷么,驱动都支持么

可以 但我差了触屏 是我自身问题

3 Likes

在手机通过uefi原生运行Ubuntu的教程 - Linux - Renegade Project (renegade-project.org) :grin:

2 Likes
Powered by Nexet