Working USB and auto-generate working recovery.img

This commit is contained in:
TheSithLordDarthImperivious 2025-01-10 19:32:51 -05:00
commit 1e2f94ed51
5 changed files with 23 additions and 31 deletions

View file

@ -51,9 +51,6 @@ QCOM_BOARD_PLATFORMS += kalama
# Kernel # Kernel
TARGET_PREBUILT_KERNEL := $(DEVICE_PATH)/prebuilt/kernel TARGET_PREBUILT_KERNEL := $(DEVICE_PATH)/prebuilt/kernel
TARGET_PREBUILT_DTB := $(DEVICE_PATH)/prebuilt/dtb.img TARGET_PREBUILT_DTB := $(DEVICE_PATH)/prebuilt/dtb.img
#BOARD_PREBUILT_DTBOIMAGE := $(DEVICE_PATH)/prebuilt/dtbo
#BOARD_INCLUDE_DTB_IN_BOOTIMG := true
#BOARD_INCLUDE_RECOVERY_DTBO := true
TARGET_KERNEL_ARCH := arm64 TARGET_KERNEL_ARCH := arm64
# Boot # Boot
@ -67,11 +64,9 @@ BOARD_BOOTCONFIG += androidboot.hardware=qcom
BOARD_BOOTCONFIG += androidboot.memcg=1 BOARD_BOOTCONFIG += androidboot.memcg=1
BOARD_BOOTCONFIG += androidboot.usbcontroller=a600000.dwc3 BOARD_BOOTCONFIG += androidboot.usbcontroller=a600000.dwc3
BOARD_BOOTCONFIG += console=tty0 BOARD_BOOTCONFIG += console=tty0
BOARD_MKBOOTIMG_ARGS := --header_version $(BOARD_BOOT_HEADER_VERSION) --pagesize $(BOARD_KERNEL_PAGESIZE)
BOARD_MKBOOTIMG_ARGS += --dtb $(TARGET_PREBUILT_DTB)
BOARD_RAMDISK_USE_LZ4 := true BOARD_RAMDISK_USE_LZ4 := true
BOARD_USES_GENERIC_KERNEL_IMAGE := true BOARD_USES_GENERIC_KERNEL_IMAGE := true
BOARD_CUSTOM_BOOTIMG_MK := $(DEVICE_PATH)/bootimg.mk
# Recovery # Recovery
BOARD_HAS_LARGE_FILESYSTEM := true BOARD_HAS_LARGE_FILESYSTEM := true

View file

@ -13,14 +13,14 @@ This is an unofficial TWRP device tree for the Motorola Edge 40 Pro/Motorola Edg
* do some research if you have any concerns about this unofficial TWRP port * do some research if you have any concerns about this unofficial TWRP port
* before flashing it! YOU are choosing to make these modifications, and if * before flashing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you. * you point the finger at me for messing up your device, I will laugh at you.
* Note that I am also sacrificing my device just to make this TWRP port, * I am also sacrificing my device just to make this TWRP port,
* so you will be putting your device at risk too. * so you will be putting your device at risk by using certain features of this TWRP port.
*/ */
``` ```
# Note # Note
This family of phones uses boot.img's kernel to boot the recovery (kind of like recovery-on-boot, except recovery is on a second ramdisk). As a result, an empty kernel image is provided as a workaround (the TWRP build system needs a kernel image). **Do not flash the recovery.img generated by the build system when building.** Otherwise, it will throw you This family of phones uses boot.img's kernel to boot the recovery (kind of like recovery-on-boot, except recovery is on a second ramdisk). As a result, an empty kernel image is provided as a workaround (the TWRP build system needs a kernel image). A special command is included in `bootimg.mk`. Without it, the device will throw you
`No valid operating system found` `No valid operating system found`
@ -31,33 +31,28 @@ Attempting to boot using `fastboot boot` will not work; it must be flashed to re
# Working Features # Working Features
- It can boot - It can boot
- Touchscreen - Touchscreen
- File Manager (can browse /system) - File Manager (can browse files and mounted partitions such as `/system`)
- Can read (and possibly write) internal storage (you have to mount from terminal currently). Exception is `/data`, which is encrypted. - Can read (and possibly write) internal storage (you have to mount from terminal currently). Exception is `/data`, which is encrypted.
- CPU Temperature - CPU Temperature
- Brightness - Brightness (there is a default brightness that works in most environments set, but it of course can be adjusted through the slider)
- USB with adb (MTP appears in lsusb, so this should work as well)
- Super partition mapping (dm devices appear in /dev/block, and all match up with Android's numbering).
# Non-working features # Non-working features
- USB (and in turn adb, mtp, this is top priority) - USB host mode (eg. Read USB drives)
- Battery percentage (LineageOS recovery has the same issue) - Battery percentage (LineageOS recovery has the same issue, so it is universal across all recoveries)
- fastbootd (please do not try to boot into fastbootd, it may throw your device into a state where it can only boot into Android when "fastboot boot boot.img" is used, and it can only be exited when stock/LineageOS recovery.img is flashed). - fastbootd (please do not try to boot into fastbootd, it may throw your device into a state where it can only boot into Android when "fastboot boot boot.img" is used, and it can only be exited when stock/LineageOS recovery.img is flashed).
- `/data` partition with FBE (FBE just does not work) - `/data` partition with FBE (FBE just does not work)
# Untested # Untested
- Flashing - Flashing ZIPs/adb sideload (will test with LineageOS upgrade from 21 to 22 soon)
- Sideload - Factory reset (I do not want to wipe my phone just to test TWRP)
- Backup/Restore super partition (backup of `/data` is guaranteed not going to work because again, encryption)
- Anything else that you may use TWRP for normally - Anything else that you may use TWRP for normally
# Instructions to Build # Instructions to Build
Same as all other TWRP (Android 12.1) device trees (when you git clone, the device tree is supposed to be located in device/motorola/rtwo, and no branch is required). However, ignore the existing `recovery.img` in the `/out/target/product/rtwo` directory and instead run this command from within the root directory of the build system: Same as all other TWRP (Android 12.1) device trees (when you git clone, the device tree is supposed to be located in device/motorola/rtwo, and no branch is required).
```bash
out/host/linux-x86/bin/mkbootimg --ramdisk out/target/product/rtwo/ramdisk-recovery.img --base 0x00000000 --pagesize 4096 --dtb device/motorola/rtwo/prebuilt/dtb.img --os_version 14 --os_patch_level 2024-12-01 --header_version 4 --output recovery.img
```
This will generate a `recovery.img` (stored in the root directory of the build system) which is bootable on these devices.
This is to avoid the `No valid operating system found` error, which can occur if the `recovery.img` is not in the format generated from the command above.
# Credits # Credits

View file

@ -9,10 +9,6 @@ $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOTIM
@echo "Made boot image: $@" @echo "Made boot image: $@"
$(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTIMG) $(recovery_ramdisk) $(recovery_kernel) $(RECOVERYIMAGE_EXTRA_DEPS) $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTIMG) $(recovery_ramdisk) $(recovery_kernel) $(RECOVERYIMAGE_EXTRA_DEPS)
@echo "----- Making recovery image ------" @echo "----- Making bootable recovery image for rtwo ------"
$(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@ $(MKBOOTIMG) --ramdisk $(PRODUCT_OUT)/ramdisk-recovery.img --base $(BOARD_KERNEL_BASE) --pagesize $(BOARD_KERNEL_PAGESIZE) --dtb $(TARGET_PREBUILT_DTB) --os_version 14 --os_patch_level 2024-12-01 --header_version $(BOARD_BOOT_HEADER_VERSION) --output $@
@echo "----- Lying about SEAndroid state to Samsung bootloader ------" @echo "DONE! You can now flash the image using fastboot flash."
$(hide) echo -n "SEANDROIDENFORCE" >> $@
@echo "Made recovery image: $@"
$(hide) tar -C $(PRODUCT_OUT) -c recovery.img > $(FLASH_IMAGE_TARGET)
@echo "Made flashable $(FLASH_IMAGE_TARGET): $@"

BIN
mkbootimg

Binary file not shown.

View file

@ -31,6 +31,7 @@ on init
# to cut charging battery path # to cut charging battery path
write /sys/class/power_supply/battery/siop_level 0 write /sys/class/power_supply/battery/siop_level 0
setprop prepdecrypt.setpatch true setprop prepdecrypt.setpatch true
setprop sys.usb.configfs 1
on fs on fs
wait /dev/block/platform/soc/${ro.boot.bootdevice} wait /dev/block/platform/soc/${ro.boot.bootdevice}
@ -41,6 +42,7 @@ on fs
mount vfat /dev/block/bootdevice/by-name/apnhlos /vendor/firmware_mnt mount vfat /dev/block/bootdevice/by-name/apnhlos /vendor/firmware_mnt
export ANDROID_ROOT /system_root export ANDROID_ROOT /system_root
# Mount bootdevice
on boot on boot
start health-hal-2-1 start health-hal-2-1
@ -55,3 +57,7 @@ on property:crypto.ready=0
on property:twrp.user.0.decrypt=0 on property:twrp.user.0.decrypt=0
umount /vendor/firmware_mnt umount /vendor/firmware_mnt
on property:ro.boot.usbcontroller=*
setprop sys.usb.controller ${ro.boot.usbcontroller}
write /sys/class/udc/${ro.boot.usbcontroller}/device/../mode peripheral