首页 > 系统相关 >红米note4x mido移植Ubuntu20.04过程记录

红米note4x mido移植Ubuntu20.04过程记录

时间:2024-03-03 21:12:31浏览次数:27  
标签:Ubuntu20.04 mido chroot workspaces img note4x -- mkboot tmp

mido设备移植Ubuntu20.04

一、初始化环境

1.安装编译依赖环境

#这里宿主机使用Ubuntu20.04系统
sudo apt install binfmt-support qemu-user-static gcc-10-aarch64-linux-gnu kernel-package fakeroot simg2img img2simg mkbootimg bison flex gcc-aarch64-linux-gnu pkg-config libncurses-dev libssl-dev unzip git debootstrap

2.下载最新内核源码

mkdir workspaces && cd workspaces
git clone https://github.com/msm8953-mainline/linux.git --depth 1

(可选)设置git代理使用科学的网络:

cat > gitproxy.sh << EOF
#!/bin/bash
case \$1 in
on)
git config --global http.proxy 'http://192.168.2.64:7897' 
git config --global https.proxy 'http://192.168.2.64:7897'
;;
off)
git config --global --unset http.proxy
git config --global --unset https.proxy
;;
status)
git config --get http.proxy
git config --get https.proxy
;;
esac
EOF
chmod +x gitproxy.sh

3.下载内核编译.config文件

参考大佬仓库的.config文件https://gitee.com/meiziyang2023/ubuntu-ports-xiaomi-625-phones
或者pmos的config-postmarketos-qcom-msm8953.aarch64文件https://gitlab.com/postmarketOS/pmaports/-/tree/master/device/community/linux-postmarketos-qcom-msm8953

cd cd ~/workspaces/linux
wget https://gitee.com/meiziyang2023/ubuntu-ports-xiaomi-625-phones/raw/master/.config

二、编译内核和内核deb安装包

1.设置编译环境变量

cd ~/workspaces
cat > env.sh << EOF
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
export CC=aarch64-linux-gnu-gcc
EOF
chmod +x env.sh

2.开始编译内核

source ./env.sh
cd ./linux
make clean
rm -r ./debian
make menuconfig
make -j$(nproc)

3.编译内核deb安装包

fakeroot make-kpkg  --initrd --cross-compile aarch64-linux-gnu- --arch arm64 kernel_image kernel_headers -j$(nproc)
#编译完成,内核安装包生成在源码上级目录

三、制作rootfs.img镜像

1.创建空白rootfs.img镜像文件

cd ~/workspaces
dd if=/dev/zero of=rootfs-focal.img bs=1G count=2
mkfs.ext4 rootfs-focal.img

2.使用debootstrap

mkdir ~/chroot
sudo mount rootfs-focal.img ~/chroot
sudo debootstrap --arch arm64 focal ~/chroot https://mirrors.aliyun.com/ubuntu-ports
#sudo debootstrap --arch arm64 --variant=minbase --include=vim,ca-certificates,apt-utils,locales focal ~/chroot https://mirrors.aliyun.com/ubuntu-ports

3.chroot进入rootfs安装喜欢的包,初始化一些配置

sudo mount --bind /proc ~/chroot/proc
sudo mount --bind /dev ~/chroot/dev
sudo mount --bind /dev/pts ~/chroot/dev/pts
sudo mount --bind /sys ~/chroot/sys

sudo chroot ~/chroot
#以下命令即都是在chroot环境中
#修改阿里源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
EOF
#更新源
apt update && apt upgrade
#设置locales
locale-gen en_US.UTF-8
locale-gen zh_CN.UTF-8
update-locale LANG=en_US.UTF-8
#设置中国时区
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#设置hostname
echo 'xiaomi-mido' > /etc/hostname
#卸载netplan
apt purge netplan.io
#创建用户
useradd -m -s /bin/bash hol
usermod -aG sudo hol
#设置密码
passwd hol
#安装一些包
apt install man man-db bash-completion vim tmux network-manager chrony openssh-server initramfs-tools --no-install-recommends -y

4.安装编译的内核

宿主机中执行拷贝内核安装包到rootfs中

cp ~/workspaces/linux*.deb ~/chroot/tmp

chroot环境中执行安装内核,安装之前确保chroot环境中已经安装了initramfs-tools

cd /tmp
dpkg --get-selections | grep linux
dpkg -l | grep -E "linux-headers|linux-image" |awk '{print $2}'|xargs dpkg -P
rm -rf /lib/modules/*

dpkg -i linux*.deb
dpkg --get-selections | grep linux

ls /lib/modules

5.拷贝firmware文件

宿主机中执行拷贝firmware到rootfs中,firmwar文件来自https://github.com/Kiciuk/proprietary_firmware_mido

cd ~/workspaces
git clone https://github.com/Kiciuk/proprietary_firmware_mido.git
cp -r ./proprietary_firmware_mido/apnhlos/* ~/chroot/usr/lib/firmware/
cp -r ./proprietary_firmware_mido/firmware/* ~/chroot/usr/lib/firmware/
cp -r ./proprietary_firmware_mido/modem/* ~/chroot/usr/lib/firmware/

chroot环境中执行

cd /usr/lib/firmware/
ldconfig

6.制作boot.img

宿主机中执行

mkdir ~/workspaces/tmp_mkboot
rm -rf ~/workspaces/tmp_mkboot/*
cp ~/workspaces/linux/arch/arm64/boot/dts/qcom/*mido*.dtb ~/workspaces/tmp_mkboot/
cp ~/workspaces/linux/arch/arm64/boot/Image.gz ~/workspaces/tmp_mkboot/
cp ~/chroot/boot/initrd* ~/workspaces/tmp_mkboot/

cp ~/workspaces/tmp_mkboot/initrd* ~/workspaces/tmp_mkboot/initrd.img
cp ~/workspaces/tmp_mkboot/msm*.dtb ~/workspaces/tmp_mkboot/dtb
cat ~/workspaces/tmp_mkboot/Image.gz ~/workspaces/tmp_mkboot/dtb > ~/workspaces/tmp_mkboot/kernel-dtb
mkbootimg --base 0x80000000 \
        --kernel_offset 0x00008000 \
        --ramdisk_offset 0x01000000 \
        --tags_offset 0x00000100 \
        --pagesize 2048 \
        --second_offset 0x00f00000 \
        --ramdisk ~/workspaces/tmp_mkboot/initrd.img \
        --cmdline "console=tty0 root=UUID=20336aa9-c9de-431a-b679-dcf10065c121 rw loglevel=3 splash"\
        --kernel ~/workspaces/tmp_mkboot/kernel-dtb -o ~/workspaces/tmp_mkboot/boot.img

#这里的UUID需要替换成自己的rootfs.img的uuid,通过file查看,格式化后的rootfs.img的uuid不会变。
file ~/workspaces/rootfs-focal.img
#其他偏移量可以在pmos网站的deviceinfo上找到

7.一些优化

自动扩展文件系统

cat > /etc/systemd/system/resizefs.service << 'EOF'
[Unit]
Description=Expand root filesystem to fill partition
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c 'exec /usr/sbin/resize2fs $(findmnt -nvo SOURCE /)'
ExecStartPost=/usr/bin/systemctl disable resizefs.service
RemainAfterExit=true

[Install]
WantedBy=default.target
EOF
systemctl enable resizefs.service

开启串口登录

cat > /etc/systemd/system/[email protected] << EOF
[Unit]
Description=Serial Console Service on ttyGS0

[Service]
ExecStart=-/usr/sbin/agetty -L 115200 ttyGS0 xterm+256color
Type=idle
Restart=always
RestartSec=0

[Install]
WantedBy=multi-user.target
EOF
systemctl enable [email protected]
#如果串口登录失效,可能是g_serial模块没有加载
echo g_serial >> /etc/modules

8.清理chroot环境,并退出

chroot环境中执行

apt clean
rm -f /tmp/*
history -c
Ctrl + D

9.卸载rootfs镜像挂载,转换成刷机镜像

宿主机中执行

sudo umount ~/chroot/proc
sudo umount ~/chroot/dev/pts
sudo umount ~/chroot/dev
sudo umount ~/chroot/sys
sudo umount ~/chroot
img2simg ~/workspaces/rootfs-focal.img ~/workspaces/tmp_mkboot/rootfs.img

这样在~/workspaces/tmp_mkboot目录中就得到了可以刷机的rootfs.img和boot.img了。可以愉快的去刷机了:)

感谢postmarketOS项目,感谢umeiko大佬的教程https://github.com/umeiko/KlipperPhonesLinux/

标签:Ubuntu20.04,mido,chroot,workspaces,img,note4x,--,mkboot,tmp
From: https://www.cnblogs.com/holdmyhand/p/18050728

相关文章

  • 记录 Ubuntu20.04 配置 vscode/gcc/g++ 和 java17
    换源问题在网上找的教程,基本都是安装好Ubuntu后立刻更换软件下载源,但20.04版本我换源之后非常慢,并且后续安装软件时出现依赖问题无法解决等等,我试了清华源和自动选择最佳服务器都不行,最后只能重装。vscode参考:Ubuntu20.04下安装VSCode(配置C/C++开发环境)建议用sudosnapinstal......
  • ubuntu20.04开启ftp服务
    sudoaptupdatesudoaptinstallvsftpdsudovi/etc/vsftpd.conflocal_enable=YES允许本地用户通过FTP登录到服务器 取消注释并将其设置为:chroot_local_user=YES这将限制本地用户的FTP访问仅限于其家目录。 sudosystemctlstartvsftpd#启动sudosystemctl......
  • Ubuntu20.04 系统 ALERT! UUID=xxx does not exist. Dropping to a shell!
    Gaveupwaitingforrootdevice.Commonproblems:-Bootargs(cat/proc/cmdline)-Checkrootdelay=(didthesystemwaitlongenough?)-Missingmodules(cat/proc/modules;ls/dev)ALERT!UUID=718ed077-947d-4018-80ad-59825678e81ddoesnotexist.Dropping......
  • Ubuntu20.04 问题+解决方案(不定期更新)
    问题1:Ubuntu20.04错误提醒:无法修正错误E:Unabletocorrectproblems,youhaveheldbrokenpackages.例如:解决方案:https://blog.csdn.net/weixin_44284939/article/details/122647791问题2:dpkg:errorprocessingpackage***(--configure)错误解决办法E:Sub-proce......
  • Mybatis Plus java.lang.NoSuchMethodError: com.baomidou.mybatisplus.core.toolkit.
    问题描述在进行SpringBoot整合MybatisPlus时提示10:49:08.390[restartedMain]DEBUGorg.springframework.boot.context.logging.ClasspathLoggingApplicationListener-Applicationfailedtostartwithclasspath:[file:/D:/%e7%99%be%e5%ba%a6%e7%bd%91%e7%9b%98/Vue......
  • Ubuntu20.04安装后,root账户无法登录,ssh无法远程连接处理方法
    摘自:https://blog.csdn.net/Alex_81D/article/details/131512358 二、给root账户设置密码,并保证可成功登录1.设置root用户密码在桌面上使用快捷键Ctrl+Alt+T打开终端模拟器执行sudopasswdroot,然后输入设置的密码,输入两次,完成了设置root用户密码2.修改配置文件修改gdm-auto......
  • linux ubuntu20.04+php+apache
    1.安装apache2首先更新一下:sudoapt-getupdatesudoapt-getupgrade安装Apache2:sudoapt-get installapache2  #输入y,继续。等着他下载安装就好了打开浏览器访问http://serverIPAddress/  #可以直接访问检查apache是否安装成功,tomcat默认是使用80端口ps......
  • Ubuntu20.04静态编译Boost记录
    下载Boost源码地址:https://www.boost.org/users/history/version_1_72_0.html指定安装位置./bootstrap.sh--prefix=/usr/local/boost-1-72-0编译release版本的boost库./b2toolset=gcclink=staticruntime-link=staticthreading=multi开始编译sudo./b2install--......
  • Ubuntu20.04安装部署Jenkins
     Jenkins要求Java8及更高版本,检查系统上是否安装了Javajava--version如果没有安装Java,执行如下命令,在您的系统上安装Javasudoaptinstall-yopenjdk-17-jre-headless再次验证Java版本安装Jenkins会启用JenkinsAPT软件源,导入源GPGkey,并且安装Jenkins软件包......
  • Ubuntu20.04部署docker环境
    1.卸载旧的docker版本forpkgindocker.iodocker-docdocker-composepodman-dockercontainerdrunc;doapt-getremove$pkg;done2.切换国内的软件源cat>/etc/apt/sources.list<<EOFdebhttps://mirrors.aliyun.com/ubuntu/focalmainrestricteduniversemultiv......