[Xiaomi Redmi Note 4 Questions & Answers] alecxs:
first install MediaTek MT67xx USB VCOM Preloader USB Drivers. the preloader is the important mode for flashing via COM port. it works best with battery removed. here is a video how it looks like when preloader is visible in device manager

next download stock ROM and SP Flash Tool. in the firmware folder you will find the scatter file for this ROM. With this do a readback of boot and recovery partition. Do not flash (download) anything, just dump current partitions from phone. now modify boot against dm-verity (magisk manager can do this). if it works, you know the scatter file is matching your device. if it fails, you must create your own scatter file and repeat readback. there is a tutorial for creating scatter file with WwR MTK (skip this)

How to flash custom recovery, by-pass screen lock, root with Magisk (with locked bootloader)

requirements

- adb and fastboot platform-tools

- MediaTek SP Flash Tool

- MediaTek PreLoader USB VCOM driver

- stock ROM

- magisk manager

- TWRP

- MT6797_Android_scatter.txt (specific for ROM)

- MTK_AllInOne_DA.bin

- auth_sv5.auth (optional)

steps

- install MediaTek MT67xx VCOM Preloader USB Drivers

[IMG="SP_FLASH_TOOL_MediaTek_MT65xx_USB-VCOM_Preloader_Drivers.png"]https://www.dropbox.com/s/q0ypowtf1oskzxm/SP_FLASH_TOOL_MediaTek_MT65xx_USB-VCOM_Preloader_Drivers.png?dl=1[/IMG]

power off phone

open device manager

connect usb cable with PC (preloader appears for ~ 1 second only)

click on the unknown device (be fast)

manually assign the driver usb2ser_Win764.inf

- readback boot and recovery partition

[IMG="sp_flash_tool_readback.png"]https://www.dropbox.com/s/sgk3tns80ecsbas/sp_flash_tool_readback.png?dl=1[/IMG]

run flash_tool.exe, on the Download tab,

choose Download-Agent "MTK_AllInOne_DA.bin"

choose Scatter-loading File "MT6797_Android_scatter.txt"

on the Readback tab, Add new entry

click on filename "ROM_0" and rename to boot.img

select Region EMMC_USER

Start Address: 0x000000000B800000

Length: 0x0000000001000000

Add new entry

click on filename "ROM_1" and rename to recovery.img

select Region EMMC_USER

Start Address: 0x0000000000008000

Length: 0x0000000001000000

when both entries okay, compare with scatter file

click on "Read back" (readback will start as soon as preloader is detected)

power off phone

connect usb cable with PC (readback start)

when finished you will see green checkmark Ok

- patch boot.img with magisk manager

download Latest Magisk Manager to any android device (not rooted)

enable settings - security - unknown sources

open file manager and navigate to Download folder

install MagiskManager.apk

copy boot.img from readback to the android device

open Magisk Manager, tap on Advanced Settings

select Preserve force encryption

tap on Magisk is not installed - INSTALL - INSTALL (2x times)

Select and Patch a File

grant permission to storage

navigate to boot.img from readback

tap on boot.img (patching will start)

Note: the Magisk dialog is misleading. It says Flashing... but nothing is flashed to this android device, this devices remains safe/unrooted

when finished you will see the output file name and text "All done!"

disable settings - security - unknown sources

(you can uninstall Magisk Manager from this device now)

copy the file to PC with adb command

adb pull /storage/emulated/0/Download/magisk_patched.img

- flash patched boot and twrp

[IMG="sp_flash_tool.png"]https://www.dropbox.com/s/6fwdi7algabgq8k/sp_flash_tool.png?dl=1[/IMG]

run flash_tool.exe, on the Download tab,

choose Download-Agent "MTK_AllInOne_DA.bin"

choose Scatter-loading File "MT6797_Android_scatter.txt"

choose Authentication File "auth_sv5.auth" (optional)

choose Method "Download only"

WARNING: Make sure not to "Format All + Download" (devices with secure boot) or flash using "Firmware Upgrade" option. This will damage/hard brick your device

Important: always de-select the check box "preloader" (EMMC_BOOT)

de-select all check boxes

click on recovery, select cofface_twrp_nikel_recovery1121.img

click on boot, select magisk_patched.img

click on "Download" (flashing will start as soon as preloader is detected)

power off phone

connect usb cable with PC (flashing start)

when finished you will see green checkmark Download Ok

press and hold Volume Up Button

disconnect the usb cable (still holding Volume Up)

reconnect the usb cable (still holding)

Note: you may hear multiple connecting sounds - don't release the Volume Up Button yet

when TWRP Team Win recovery appears, release Volume Up Button

- check if twrp is able to decrypt userdata (without credentials)

- create a backup of data partition, copy to PC

- delete /data/system/locksettings.db* files (only if backup successful)

- reboot device, check if screen lock is removed

- install Magisk Manager

Note: everything untested - may not work! If flashing boot or recovery fails, it is most likely denied by secure boot. In this case it may work only with proper Download-Agent (and auth_sv5.auth file)