Skip to content

Dual boot sdcard‐pmos or sdcard‐aosp and ufs‐LOS20

99degree edited this page Jun 26, 2024 · 10 revisions

To enable dual boot, here is a pre-requisite. Since that bootloader will append the matched dtb-overlay(dtbo) file found from dtbo partition to the main-and-matched dtb. This is applied to boot partition and fastboot boot cmd. Recovery is another story out of scope of this wiki.

Workaround is to erase dtbo partition and modify los20 boot.img and exchange with a cust build full-fledge dtb(joyeuse.dtb) for particular base dtb(atoll-idp-ab.dtb) as result.

Prepare cust kernel

Build your own kernel is prefered. A github action built kernel, which is untested, is also available https://github.com/99degree/postmarket-nightly-builds/actions

The downloaded file xiaomi-joyeuse-boot.img have all the needed for booting pmOS. Check below wiki for detail https://github.com/99degree/postmarket-nightly-builds/wiki/Boot-image-manipulation

Prepare joyeuse los boot.img

Below is suggested procedure for custom boot.img to elimiate the dependency to dtbo partition. Since "fastboot boot" also apply above bootloader mechanism so is a blocker for dual boot sdcard OS and/or custom recovery image

  1. clone the kernel from https://github.com/LineageOS/android_kernel_xiaomi_sm6250 OR https://github.com/99degree/android_kernel_xiaomi_sm6250/commits/lineage-20/
  2. install aarch64-linux-gnu-gcc etc tools that need to compile kernel.
  3. Modify with https://github.com/99degree/android_kernel_xiaomi_sm6250/commit/d50f3c6cacac00dbafe7363b00854f0ff8981482 or use my repo directly.
  4. Build with "CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 make dtbs"
  5. Get the compiled joyeuse-atoll-ab-idp.dtb and replace the dtb of LOS20 boot.img as cust_boot.img
  6. can use same trick for all other miatoll variant.
  7. (Disclaimer, your own risk)Flash to ufs boot partition, "fastboot flash boot cust_boot.img"
  8. Erase dtbo, "fastboot erase dtbo"

Done. above is to cut the dependence of bootloader chain to dtbo partition and maintain the ufs boot for los

Prepare sdcard with Linux

No attempt. Might be fill up later. Not recommended this way.

General idea is to partition the sdcard with below fastboot listed partition. and write to sdcard. Please note that fastbootd writing dynamic partition to super partition is needed and is next todo for sdcard partitioning. And fastbootd is the best method to manipulate super partition.

Prepare sdcard with cust los recovery

Here is how to prepare sdcard for PMOS and make it boot and results some-what dual boot capable. Note that not only PMOS can use this technique, Android boot on sdcard also use this technique. Assumed all output ramdisk.img are cpio+gzip format. If not, repack into cpio+gz format.

  1. Download from LineageOS/OrangeFox to get a working recovery image android_boot.img and test it too.
  2. Check if gdisk arm64 build binary available. if no, build it yourself.
  3. Download pmos img from its homepage, select the PINE64 PinePhone build (yes, PINE64 PinePhone build instead of its cousin davaci or surya).
  4. after unzip that, a disk img can be mounted by loop device, do losetup -P /dev/loop3 disk.img
  5. There are 2 partitions extracted as file by dd if=/dev/loop3p1 of=boot.img thus 2 files, is boot.img and root.img do losetup -D to close file.
  6. unpack boot.img file, win10 and 7zip is nice tool to use. there are initramfs initramfs-extra, two files.
  7. insert sdcard in pc, prepare with it, for example, 2 partitions. flash boot.img and root.img into sdcard.
  8. best is to use gpt partition on sdcard and named partition as pmOS_root and pmOS_boot.
  9. prepare kernel with needed drivers builtin
  10. prepare fw_ramdisk.img.gz that only contain /lib/firmware/ and put all needed firmware into this directory.
  11. if needed, prepare bootconfig.pmos and put all needed boot param into it
  12. copy initramfs initramfs-extra and fw_ramdisk.img.gz to /tmp
  13. do "cat initramfs initramfs-extra fw_ramdisk.img.gz >> ramdisk.img"
  14. optionally inside kernel build dir, do bootconfig bootconfig.pmos /tmp/ramdisk.img
  15. fastboot boot kernel...
fastboot boot $kernel $ramdisk --dtb $dt --dtb-offset $dt_offset --base $loadBase --kernel-offset $kernel_offset --ramdisk-offset $ramdisk_offset --tags-offset $tag_offset --page-size 4096 --os-version $osVersion --os-patch-level $osPatchLevel --header-version $headerVersion --cmdline "$cmdline"

Here are some default value for androidboot img for miatoll device:

cmdline='pmos_boot=/dev/block/mmcblk2p1 pmos_root=/dev/block/mmcblk2p2 root=/dev/ram0 PMOS_NOSPLASH PMOS_NO_OUTPUT_REDIRECT PMOS_CONTAINERIZED_ENABLE'
kernel_offset='32768'
ramdisk_offset='16777216'
loadBase='0'
tag_offset='256'
dt_offset='32505856'
osVersion='11.0.0'
osPatchLevel='2020-06-00'
headerVersion='2'

Here are 2 important boot cmdline for pmos to find its root, either put it in cmdline or bootconfig.pmos:

 pmos_boot=/dev/block/mmcblk2p1
 pmos_root=/dev/block/mmcblk2p2

Another method to locate root partition is make sure mmc is gpt enabled (by gdisk util) and make sure below as partition name:

 pmOS_root
 pmOS_boot

Here are 1 important boot cmdline for Android to find its root, either put it in cmdline or bootconfig.aosp:

androidboot.boot_device=soc@0/8804000.mmc

And the difference of aosp/pmos ramdisk is its initramfs + initramfs-extra vs ramdisk.lz4 file. Plz note that LOS20 boot/recovery img is having lz4 ramdisk. So better to unzip and cpio+gzip to re-make a new ramdisk

Here are suggested files for fw_ramdisk.img both apply for pmos and aosp:

./lib
./lib/firmware
./lib/firmware/qcom
./lib/firmware/qcom/a650_sqe.fw
./lib/firmware/qcom/sm7125
./lib/firmware/qcom/sm7125/miatoll
./lib/firmware/qcom/sm7125/miatoll/adspua.jsn
./lib/firmware/qcom/sm7125/miatoll/adsps.jsn
./lib/firmware/qcom/sm7125/miatoll/adspr.jsn
./lib/firmware/qcom/sm7125/miatoll/a615_zap.mbn
./lib/firmware/qcom/sm7125/miatoll/adsp.mbn
./lib/firmware/qcom/a660_sqe.fw
./lib/firmware/qcom/a650_gmu.bin
./lib/firmware/qcom/a615_zap.mbn
./lib/firmware/qcom/a660_gmu.bin
./lib/firmware/qcom/a630_sqe.fw
./lib/firmware/qcom/a630_gmu.bin
./lib/firmware/novatek_ts_tianma_fw.bin

Here is how to pack ramdisk file, assumed ramdisk file are cpio with gzip format for best compatibility.

cd fw_ramdisk/
find ./ | cpio -o -Hnewc |gzip -9 > /tmp/fw_ramdisk.img.gz