Jump to content

Xiaomi Redmi Note 7 (xiaomi-lavender): Difference between revisions

From postmarketOS Wiki
Links: link to NixOS merged PR
Since linux 6.13-sdm660 some sensors are working
 
(80 intermediate revisions by 11 users not shown)
Line 3: Line 3:
| name = Redmi Note 7
| name = Redmi Note 7
| codename = xiaomi-lavender
| codename = xiaomi-lavender
| image = File:xiaomi-lavender.jpg
| image = File:Xiaomi-lavender-613-plamo-2.png
| imagecaption = Redmi Note 7
| imagecaption = Redmi Note 7
| releaseyear = 2019
| releaseyear = 2019
| originalsoftware = Android 9, MIUI 10
| category = testing
| chipset = Qualcomm SDM660 Snapdragon 660 (14 nm)
| originalsoftware = Android (MIUI)
| cpu = 8-core (4x2.2 GHz Kryo 260 & 4x1.8 GHz Kryo 260)
| originalversion = 9 (MIUI 10)
| chipset = Qualcomm Snapdragon 660 (SDM660)
| cpu = 8-core (4x 2.2 GHz Kryo 260 & 4x 1.8 GHz Kryo 260)
| gpu = Adreno 512
| gpu = Adreno 512
| storage = 32 (64) Gb
| storage = 32/64/128 GB
| display = 1080 x 2340
| display = 1080 x 2340
| memory = 3 (4) Gb
| memory = 3/4/6 GB
| architecture = aarch64
| architecture = aarch64
| type = Handset
| status_usbnet = Y
| status_usbnet = Y
| status_flashing = Y
| status_flashing = Y
| status_touch =  
| status_emmc = Y
| status_screen =  
| status_touch = Y
| status_wifi =  
| status_screen = Y
| status_xwayland =  
| status_wifi = P
| status_fde =  
| status_xwayland = Y
| status_mainline =  
| status_fde = Y
| status_battery =  
| status_mainline = Y
| status_3d =  
| status_battery = Y
| status_accel =
| status_3d = Y
| status_audio =  
| status_audio = N
| status_bluetooth =  
| status_bluetooth = Y
| status_camera =  
| status_camera = N
| status_gps =  
| status_gps = N
| status_mobiledata =  
| status_mobiledata = N
| status_sms =  
| status_sms = N
| status_calls =  
| status_calls = N
| status = "Early WIP"
| status_sdcard = Y
| status_accel = Y
| status_magnet = N
| status_light = N
| status_proximity = N
| status_barometer = -
| status_powersensor = -
| status_hall = -
| status_haptics = Y
| booting = yes
| booting = yes
| pmoskernel = 4.4.153
| pmoskernel = 6.13
| whet_dhry = -
| status_otg = N
| status_otg =  
| status_cameraflash = N
| status_nfc = -
| status_dvb = -
| status_keyboard = -
| status_touchpad = -
| status_usba = -
| status_hdmidp = -
| status_irtx = -
| status_irrx = -
| status_stylus = -
| status_ethernet = -
| status_fossbootloader = P
| status_uboot = P
| status_uboot_mainline = -
| status_uboot_primary = N
| status_uboot_secondary = P
| status_uboot_internalstorage = Y
| status_uboot_sd = N
| status_uboot_usbhost = N
| status_uboot_usbperipheral = Y
| status_uboot_screen = Y
| status_uboot_keyboard = N
| status_uboot_buttons = P
}}
}}
{{Based on SoC|Qualcomm_Snapdragon_660_(SDM660)|Snapdragon 660}}


== Contributors ==
== Contributors ==
Line 47: Line 81:
== Users owning this device ==
== Users owning this device ==
{{Device owners}}
{{Device owners}}
== Device variants ==
There are at least 3 variants of lavender with different combintaions of panel and touchscreen:
* BOE panel + some touchscreen unknown to science "synaptics-tcm" (only panel is suuported, no ts driver ported yet)
* Shenchao panel + Novatek touchscreen (not supported at all yet, but tianma variant may work on pmos kernels 6.10, 6.11)
* Tianma panel + Novatek NT36672A touchscreen (fully supported)
In order to identify your device variant, easiest way is to look at <code>/proc/cmdline</code> while running Android (in Android you need root for this, in TWRP you need nothing). Look for part starting with <code>mdss_mdp.panel=</code>. For example you see this:
mdss_mdp.panel=1:dsi:0:qcom,mdss_dsi_nt36672a_shenchao_fhdplus_video:config0:1:none:cfg:single_dsi
This means that you have shenchao panel.


== How to enter flash mode ==
== How to enter flash mode ==
Line 56: Line 102:
=== Recovery mode ===
=== Recovery mode ===
* Turn the device off (or restart also works)
* Turn the device off (or restart also works)
* Hold volume+ button and power button
* Hold {{button|Volume Up}} and {{button|Power}} button
* Once you feel vibration and phone turns on, release power button
* Once you feel vibration and phone turns on, release {{button|Power}} button
* Keep holding volume+ until you get to recovery.
* Keep holding {{button|Volume Up}} until you get to recovery.


=== Flashing (Download, Fastboot) mode ===
=== Flashing (Download, Fastboot) mode ===
* Same as recovery, but this time hold the volume- and power keys.
* Same as recovery, but this time hold the {{button|Volume Down}} and {{button|Power}} keys.
 
=== Fastboot boot ===
In theory <code>pmbootstrap flasher boot</code> allows to directly boot kernel through USB without flashing it, but does not currently work. Bootloader does not like something about kernel compression:
<div class="toccolours mw-collapsible mw-collapsed" style="width: 620px; overflow: auto;">
Bootloader UART logs during "pmbootstrap flasher boot":
<div class="mw-collapsible-content">
  Handling Cmd: boot
Booting Into Mission Mode
avb_slot_verify.c:432: DEBUG: Loading vbmeta struct from partition 'vbmeta'.
Partition found: vbmeta
avb_slot_verify.c:627: ERROR: vbmeta: Public key used to sign data rejected.
avb_slot_verify.c:704: DEBUG: vbmeta: VERIFICATION_DISABLED bit is set.
avb_slot_verify.c:317: DEBUG: dtbo: Loading entire partition.
Partition found: dtbo
State: Unlocked, AvbSlotVerify returned ERROR_PUBLIC_KEY_REJECTED, continue boot
VB2: Authenticate complete! boot state is: orange
VB2: boot state: orange(1)
Display menu is not enabled!
Device is unlocked, Skipping boot verification
VB2: BootState = 1
ReadKeyInternal: gEfiSimpleTextInputExProtocolGuid handles = 3
ReadKeyInternal: Read KEY = 0x0
  bootstate = 4
Cannot find GraphicsHandles.
ImageWidth=1080,ImageHeight=1920,LogoPosX=0,LogoPosY=0
Avoid flicking for 2160x1080 images
Cannot find GraphicsHandles.
Render Splash  [3360687]
VB2: RenderSplashScreen end , BootState = 4
No Ffbm cookie found, ignore: Not Found
Memory Base Address: 0x40000000
Decompressing kernel image start: 3360690 ms
Error in decompression: Something went wrong while decompression
Decompressing kernel image failed!!!
</div>
</div>
But it was reported to work for some people. Try it, might work for you


== Installation ==
== Installation ==


=== Flash a working custom Android ROM first ===
* [[Installing_pmbootstrap|Install pmbootstrap]] first on your PC
Flash a working custom Android ROM first - it will likely contain all needed custom partition images like <code>vbmeta</code> or <code>dtbo</code> (not sure if it's strictly needed). For example this [[https://forum.xda-developers.com/redmi-note-7/development/rom-lineageos-16-0-t3923203 LineageOS 16.0 ROM]]. The situation is a bit hard, because there is no official LineageOS release for this device yet, not even a official TWRP.
* make sure you have TWRP installed on the phone, it will help you to make backups:
* backup <code>boot</code>, <code>dtbo</code> and <code>system</code> partitions first from TWRP, something like this, for example, to SD card:
adb shell
dd if=/dev/block/bootdevice/by-name/boot of=/external_sd/backups/orig_boot.img
dd if=/dev/block/bootdevice/by-name/dtbo of=/external_sd/backups/orig_dtbo.img
dd if=/dev/block/bootdevice/by-name/system of=/external_sd/backups/orig_system.img
* in ADB shell (or in TWRP Advanced -> Terminal) execute <code>cat /proc/cmdline</code> and see which panel type is mentioned there
* zap & reinit pmbootstrap (<code>pmbootstrap -y zap ; pmbootstrap init</code>), choose vendor <code>xiaomi</code> and device <code>lavender</code>
* choose your panel variant correctly (BOE or Tianma)
* proceed with installation as usual: reboot device to fastboot mode, then:
pmbootstrap install
pmbootstrap flasher flash_kernel
pmbootstrap flasher flash_rootfs
pmbootstrap flasher flash_vbmeta
fastboot erase dtbo


=== WIP ===
And finally
This is still a work-in-progress. If you want to test that kernel boots, backup <code>boot</code> and <code>system</code> partitions first. Then checkout my development branch in pmaports (link below in links section), zap & reinit pmbootstrap (<code>pmbootstrap -y zap ; pmbootstrap init</code>), choosing <code>xiaomi-lavender</code> as a device; then rebuild every package mentioned in the last commits on my branch (for now: <code>pmbootstrap build --force --arch aarch64 linux-xiaomi-lavender device-xiaomi-lavender postmarketos-mkinitfs </code>) then proceed as usual (reboot device to fastboot mode, <code>pmbootstrap install ; pmbootstrap flasher flash_kernel ; pmbootstrap flasher flash_rootfs</code>).
fastboot reboot
 
== WI-Fi ==
Marked as partial, because there is modem crash on attempt to disconnect from Wi-Fi, looks like this in dmesg:
[ 4383.715292] wlan0: failed to remove key (0, redacted) from hardware (-110)
[ 4383.968264] qcom-q6v5-mss 4080000.remoteproc: fatal error received: err_qdi.c:459:EX:wlan_process:1:WLAN RT:2083:PC=b00c87e0
[ 4383.968304] remoteproc remoteproc1: crash detected in 4080000.remoteproc: type fatal error
 
After that ath10k driver fails to handle remoteproc crash very well and you can't make it probe fine again, even re-inserting module doesn't help. Only reboot. But if you don't disconnect from Wi-Fi, it works fine.
 
== Photos ==
<gallery>
File:Lavender downstream weston.jpg|thumb|left|Weston on downstream kernel
File:Lavender boot log sm.jpg|thumb|left|Lavender booting mainline
File:Lavender_plamo_ds_01.jpg|thumb|left|PlaMo on fbdev 1
File:Lavender_plamo_ds_02.jpg|thumb|left|PlaMo on fbdev 2
File:RMN7_XFCE.png|thumb|left|X11 (Xfce) on fbdev
File:Lavender_plasma_desktop_framebuffer.jpg|thumb|left|Plasma Desktop on fbdev
File:Xiaomi-lavender-613-plamo.png|thumb|left|lavender running Plasma Mobile #1
File:Xiaomi-lavender-613-plamo-2.png|thumb|left|lavender running Plasma Mobile #2
</gallery>


== Additional info ==
== Additional info ==
=== Partition list ===
=== Partition list ===
<div class="toccolours mw-collapsible mw-collapsed" style="width: 620px; overflow: auto;">
Partition list
<div class="mw-collapsible-content">
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 211: Line 333:
| mmcblk0rpmb ||  || 4096 ||
| mmcblk0rpmb ||  || 4096 ||
|}
|}
</div>
</div>


=== Android Verified Boot (vbmeta) ===
=== Android Verified Boot (vbmeta) ===
This device is using '''Android Verified Boot''' ( https://android.googlesource.com/platform/external/avb/+/refs/tags/android-vts-8.0_r11/README.md ) so you may need to flash <code>vbmeta</code> partition with <code>vbmeta.img</code> from LineageOS zip or downloaded separately (from https://androidfilehost.com/?fid=1395089523397954291 for example); or we need to find a way to generate it with <code>avbtool</code> and flash it during installation somehow. (add <code>pmbootstrap flasher flash_vbmeta</code>?)
This device is using [[Android_Verified_Boot_(AVB)]] so, if you did not flash any custom Android ROM, you may need to flash <code>vbmeta</code> partition with <code>vbmeta.img</code> with verification disabled flag. pmbootstrap now can generate such empty vbmeta image and flash it with one command:
$ pmbootstrap flasher flash_vbmeta


=== DTBO partition ===
=== DTBO partition ===
This device is using a dedicated partition to store the [[Device_Tree_(dtb)|Device Tree Blob]] Overlay. Read more at https://source.android.com/devices/architecture/dto/partitions . We need to find a way to flash generated <code>dt.img</code> to <code>dtbo</code> partition during installation process. (add <code>pmbootstrap flasher flash_dtbo</code>?)
This device is using a dedicated partition to store the [[Device_Tree_(dtb)|Device Tree Blob]] Overlay. Read more at https://source.android.com/devices/architecture/dto/partitions .  


Update: looks like '''dtbo''' partition is not used during boot by LineageOS's kernel, because it is using appended DTB (<code>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE=y</code>)
Update: looks like '''dtbo''' partition is not used during boot by LineageOS's kernel, because it is using appended DTB (<code>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE=y</code>)


Update2: device tree from dtbo partition can still be used by bootloader?
Update2: device tree from dtbo partition is used by bootloader to apply some fixups on top of appended dtb. Bootloader tries to apply overlay dtb from dtbo partition over a dtb found appended to kernel, and if it fails to do so, it falls back into fastboot mode. Example bootloader debug UART output in that case:
Memory Base Address: 0x40000000
Decompressing kernel image start: 2700 ms
Decompressing kernel image done: 2852 ms
ufdt apply overlay failed
Launching fastboot
 
See also Zhuowei's notes on creating custom dtbo partition: https://gitlab.com/zhuowei/dtbo-google-crosshatch-mainline
 
For mainline kernel just <code>fastboot erase dtbo</code> works. Bootloader ignores missing dtbo, example output when dtbo partition is erased:
Memory Base Address: 0x40000000
Decompressing kernel image start: 2641 ms
Decompressing kernel image done: 2793 ms
Dtbo hdr magic mismatch 0, with D7B7AB1E
Best match DTB tags 317/00020008/0x00000000/0/1001B/102001A/0/0/(offset)0x97128304/(size)0x00000653
Using pmic info 0x1001B/0x102001A/0x0/0x0 for device 0x2001B/0x102001A/0x0/0x0
Memory Base Address: 0x40000000
smem protocol = 9C2FA0A0
board_id1 is 1
  board_id2 is 1
  board_id3 is 0
board_id is 1
get_boardid_from_smem,SUCCESS ,board_id=0x102,cpu_id=0x39148C8C,hwdefined=0
  PON Reason is 17 cold_boot:1 charger path: 1
...(proceeding to normal boot procedure)...
 
For downstream kernel, leave stock dtbo partition untouched.


=== Bootloader cmdline ===
=== Bootloader cmdline ===
Stock bootloader is doing nasty things with kernel command line: it passes a lot of arguments that make booting custom OS (like postmarketOS) impossible
Stock bootloader is doing nasty things with kernel command line: it passes a lot of arguments that make booting custom OS (like postmarketOS) impossible


<div class="toccolours mw-collapsible mw-collapsed" style="width: 620px; overflow: auto;">
Full list of stock command line parameters:
Full list of stock command line parameters:
<div class="mw-collapsible-content">
<pre>
<pre>
ramoops_memreserve=4M
ramoops_memreserve=4M
Line 268: Line 422:
androidboot.hwdevice=lavender
androidboot.hwdevice=lavender
</pre>
</pre>
</div>
</div>


<code>ramoops_memreserve=4M</code> comes from defconfig, next from boot.img, others (starting with first <code>androidboot.</code> and below) come from bootloader directly.
<code>ramoops_memreserve=4M</code> comes from defconfig, next from boot.img, others (starting with first <code>androidboot.</code> and below) come from bootloader directly.


==== Harmful kernel command line params from bootloader ====
==== Harmful kernel command line params from bootloader ====
Options like <code>root=</code>, <code>skip_initramfs</code> make kernel look for a specific partition to mount at /, skipping initramfs, which is incompatible with default booting methods of postmarketOS. That's why some tricky patches are needed, similar to ones used by Zhuowei in Google Pixel port: [https://gitlab.com/postmarketOS/pmaports/blob/master/device/linux-google-crosshatch/init-ignore-dm-parameter.patch 1], [https://gitlab.com/postmarketOS/pmaports/blob/master/device/linux-google-crosshatch/init-initramfs-disable-do_skip_initramfs.patch 2].
Options like <code>root=</code>, <code>skip_initramfs</code> make kernel look for a specific partition to mount at /, skipping initramfs, which is incompatible with default booting methods of postmarketOS. That's why some tricky patches are needed like by opendata26: [https://gitlab.com/opendata26/linux/commit/40095e9a8b1eb32ad7ccd705c8990792e692ba1d init: ignore bootloader cmdline params for mounts]


Another hack to fix bootloader cmdline params by opendata26: [https://gitlab.com/opendata26/linux/commit/40095e9a8b1eb32ad7ccd705c8990792e692ba1d init: ignore bootloader cmdline params for mounts]
Some info on <code>skip_initramfs</code> kernel cmdline parameter: https://forum.xda-developers.com/apps/magisk/pixel-2-pixel-2-xl-support-t3697427/post74361728#post74361728


Some info on <code>skip_initramfs</code> kernel cmdline parameter: https://forum.xda-developers.com/apps/magisk/pixel-2-pixel-2-xl-support-t3697427/post74361728#post74361728
Since version 6.9 postmarketOS's close-to-mainline linux kernel fork for 630/660 devices contains a workaround to ignore such cmdline parameters - https://github.com/sdm660-mainline/linux/commit/d0b6901c00ceaaad48447cd299545d4872d11b76 .


=== Way to get boot log ===
=== Way to get boot log ===
This is the first device known to ship with the <code>oem getlog</code> fastboot command.
This device known to ship with the <code>oem getlog</code> fastboot command.


This is not a trivial command to use, but it is extremely useful as it allows side-stepping the need to boot in a known working system to use the ramoops
This is not a trivial command to use, but it is extremely useful as it allows side-stepping the need to boot in a known working system to use the ramoops
console.
console. The output of the command is a jumble, but is still usable for figuring out early boot issues. It is much better than having to rely on a booted system to
 
The output of the command is a jumble, but is still usable for figuring out early boot issues. It is much better than having to rely on a booted system to
get the information, but still not as good as having a dedicated serial access.
get the information, but still not as good as having a dedicated serial access.


Line 314: Line 468:




It is unknown if there are ways to make the output better.
It is unknown if there are ways to make the output better. (Apply some kind error correction algorithm?)
 
EDIT: seems to not work for me, whatever you do, the output is:
 
$ fastboot oem getlog
                                                  (bootloader) [Macle]Maybe no last kmsg
OKAY [  0.000s]
Finished. Total time: 0.000s
 
Probably needs a crash? But I can read pstore-console (dmesg) logs from booted TWRP recovery fine..
 
[[File:Xiaomi-lavender-uart-pins.jpg|200px|thumb|right|Xiaomi Redmi Note 7 (lavender) UART test pins schematic]]
[[File:Xiaomi-lavender-uart-pins-real-photo.jpg|200px|thumb|right|Xiaomi Redmi Note 7 (lavender) UART test pins photo]]
 
=== Getting logs through debug UART ===
 
You have to disassemble the phone (just removing back cover is enough). You'll have to heat up edges of the back cover (as shown in disassembling video, see '''Links''' below) before trying to remove it. Be careful! It is made of glass! Also be careful about fingerprint sensor connector, it is connected to a back cover you are trying to remove. Don't rip it.
 
In the center you will see 4 test points that are available. (See the picture) Two bigger ones (0.8mm) are '''EDL''' (FORCE_USB_BOOT) pins. UART test points are two smaller ones on the left (0.5mm). TP11 is '''UART TX''' (gpio 4), TP10 is '''UART RX''' (gpio 5). GND is that whole metal shielding, that covers the center of the board. So, to get debug logs from UART it is enough to connect UART TX from the board to RX pin on the converter, and connect GND between phone and GND pin on the converter.


== Links ==
== Links ==
<!--
* {{MR|1095|pmaports}} Initial merge request
Link to related gitlab issues or merge requests like the following (replace CHANGEME with the ID, e.g. 1234):
* {{Device package|xiaomi-lavender}}
* {{MR|CHANGEME|pmaports}} Initial merge request
* [https://gitlab.postmarketos.org/postmarketOS/pmaports/tree/master/device/testing/linux-postmarketos-qcom-sdm660 Mainline kernel package]
* {{issue|CHANGEME|pmaports}} Some related issue
* [https://github.com/sdm660-mainline/linux Close-to mainline kernel source repository]
You can also add normal web links:
* [[Xiaomi_Redmi_Note_7_(xiaomi-lavender)/Mainline_development|Mainline development BLOG]]
* [https://redmine.replicant.us/projects/replicant/wiki/GalaxyS2I9100 Replicant wiki page]
* {{issue|494|pmaports}} (OLD) How to make Wi-Fi work?
-->
* [https://github.com/NixOS/mobile-nixos/pull/28 NixOS-mobile lavender MR]
* [https://gitlab.com/minlexx/pmaports/commits/minlexx/xiaomi-lavender Current development branch]
* https://www.youtube.com/watch?v=6GqXqW2Nygc Disassembling video (Rus)
<!--
* https://www.anandtech.com/show/11338/qualcomm-announces-snapdragon-660-630-mobile-platforms
If you manage to get your device packages merged, uncomment links below and change DEVICE_CODENAME with the actual one.
* List of mobile phones on SDM660 SoC: [https://www.kimovil.com/en/list-smartphones-by-processor/qualcomm-snapdragon-660-msm8976-plus 1], [https://www.gsmarena.com/results.php3?nRamMin=2000&sFreeText=sdm660 2]
* [https://gitlab.com/postmarketOS/pmaports/tree/master/device/device-DEVICE_CODENAME Device package]
 
* [https://gitlab.com/postmarketOS/pmaports/tree/master/device/linux-DEVICE_CODENAME Kernel package]
[[Category:Devices with known UART pinout]]
-->
* [[Xiaomi_Redmi_Note_7_(xiaomi-lavender)/Mainline_development]]
* https://github.com/NixOS/mobile-nixos/pull/28/files

Latest revision as of 03:40, 19 March 2025

Xiaomi Redmi Note 7
Redmi Note 7
Redmi Note 7
Manufacturer Xiaomi
Name Redmi Note 7
Codename xiaomi-lavender
Released 2019
Type handset
Hardware
Chipset Qualcomm Snapdragon 660 (SDM660)
CPU 8-core (4x 2.2 GHz Kryo 260 & 4x 1.8 GHz Kryo 260)
GPU Adreno 512
Display 1080 x 2340
Storage 32/64/128 GB
Memory 3/4/6 GB
Architecture aarch64
Software
Original software Android (MIUI)
Original version 9 (MIUI 10)
FOSS bootloader partial
postmarketOS
Category testing
Pre-built images no
Mainline yes
postmarketOS kernel 6.13
Features
Flashing
Works
USB Networking
Works
Internal storage
Works
SD card
Works
Battery
Works
Screen
Works
Touchscreen
Works
Multimedia
3D Acceleration
Works
Audio
Broken
Camera
Broken
Camera Flash
Broken
Connectivity
WiFi
Partial
Bluetooth
Works
GPS
Broken
Modem
Calls
Broken
SMS
Broken
Mobile data
Broken
Miscellaneous
FDE
Works
USB OTG
Broken
Sensors
Accelerometer
Works
Magnetometer
Broken
Ambient Light
Broken
Proximity
Broken
Haptics
Works
U-Boot
Primary Bootloader
Broken
Secondary Bootloader
Partial
Internal Storage
Works
SD card
Broken
USB Host
Broken
USB Peripheral
Works
Display
Works
Keyboard
Broken
Buttons
Partial

Contributors

Maintainer(s)

Users owning this device


Device variants

There are at least 3 variants of lavender with different combintaions of panel and touchscreen:

  • BOE panel + some touchscreen unknown to science "synaptics-tcm" (only panel is suuported, no ts driver ported yet)
  • Shenchao panel + Novatek touchscreen (not supported at all yet, but tianma variant may work on pmos kernels 6.10, 6.11)
  • Tianma panel + Novatek NT36672A touchscreen (fully supported)

In order to identify your device variant, easiest way is to look at /proc/cmdline while running Android (in Android you need root for this, in TWRP you need nothing). Look for part starting with mdss_mdp.panel=. For example you see this:

mdss_mdp.panel=1:dsi:0:qcom,mdss_dsi_nt36672a_shenchao_fhdplus_video:config0:1:none:cfg:single_dsi

This means that you have shenchao panel.

How to enter flash mode

Bootloader Unlocking

Like other Xiaomi devices, the user will have to acquire the bootloader unlock key: https://en.miui.com/unlock

The device will not unlock if the device isn't 7 days old (from the time when your device connects to internet and powered on, and linked with Mi Account)

Recovery mode

  • Turn the device off (or restart also works)
  • Hold Volume Up and Power button
  • Once you feel vibration and phone turns on, release Power button
  • Keep holding Volume Up until you get to recovery.

Flashing (Download, Fastboot) mode

  • Same as recovery, but this time hold the Volume Down and Power keys.

Fastboot boot

In theory pmbootstrap flasher boot allows to directly boot kernel through USB without flashing it, but does not currently work. Bootloader does not like something about kernel compression:

Bootloader UART logs during "pmbootstrap flasher boot":

But it was reported to work for some people. Try it, might work for you

Installation

  • Install pmbootstrap first on your PC
  • make sure you have TWRP installed on the phone, it will help you to make backups:
  • backup boot, dtbo and system partitions first from TWRP, something like this, for example, to SD card:
adb shell
dd if=/dev/block/bootdevice/by-name/boot of=/external_sd/backups/orig_boot.img
dd if=/dev/block/bootdevice/by-name/dtbo of=/external_sd/backups/orig_dtbo.img
dd if=/dev/block/bootdevice/by-name/system of=/external_sd/backups/orig_system.img
  • in ADB shell (or in TWRP Advanced -> Terminal) execute cat /proc/cmdline and see which panel type is mentioned there
  • zap & reinit pmbootstrap (pmbootstrap -y zap ; pmbootstrap init), choose vendor xiaomi and device lavender
  • choose your panel variant correctly (BOE or Tianma)
  • proceed with installation as usual: reboot device to fastboot mode, then:
pmbootstrap install
pmbootstrap flasher flash_kernel
pmbootstrap flasher flash_rootfs
pmbootstrap flasher flash_vbmeta
fastboot erase dtbo

And finally

fastboot reboot

WI-Fi

Marked as partial, because there is modem crash on attempt to disconnect from Wi-Fi, looks like this in dmesg:

[ 4383.715292] wlan0: failed to remove key (0, redacted) from hardware (-110)
[ 4383.968264] qcom-q6v5-mss 4080000.remoteproc: fatal error received: err_qdi.c:459:EX:wlan_process:1:WLAN RT:2083:PC=b00c87e0
[ 4383.968304] remoteproc remoteproc1: crash detected in 4080000.remoteproc: type fatal error

After that ath10k driver fails to handle remoteproc crash very well and you can't make it probe fine again, even re-inserting module doesn't help. Only reboot. But if you don't disconnect from Wi-Fi, it works fine.

Photos

Additional info

Partition list

Partition list

Android Verified Boot (vbmeta)

This device is using Android_Verified_Boot_(AVB) so, if you did not flash any custom Android ROM, you may need to flash vbmeta partition with vbmeta.img with verification disabled flag. pmbootstrap now can generate such empty vbmeta image and flash it with one command:

$ pmbootstrap flasher flash_vbmeta

DTBO partition

This device is using a dedicated partition to store the Device Tree Blob Overlay. Read more at https://source.android.com/devices/architecture/dto/partitions .

Update: looks like dtbo partition is not used during boot by LineageOS's kernel, because it is using appended DTB (CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE=y)

Update2: device tree from dtbo partition is used by bootloader to apply some fixups on top of appended dtb. Bootloader tries to apply overlay dtb from dtbo partition over a dtb found appended to kernel, and if it fails to do so, it falls back into fastboot mode. Example bootloader debug UART output in that case:

Memory Base Address: 0x40000000
Decompressing kernel image start: 2700 ms
Decompressing kernel image done: 2852 ms
ufdt apply overlay failed
Launching fastboot

See also Zhuowei's notes on creating custom dtbo partition: https://gitlab.com/zhuowei/dtbo-google-crosshatch-mainline

For mainline kernel just fastboot erase dtbo works. Bootloader ignores missing dtbo, example output when dtbo partition is erased:

Memory Base Address: 0x40000000
Decompressing kernel image start: 2641 ms
Decompressing kernel image done: 2793 ms
Dtbo hdr magic mismatch 0, with D7B7AB1E
Best match DTB tags 317/00020008/0x00000000/0/1001B/102001A/0/0/(offset)0x97128304/(size)0x00000653
Using pmic info 0x1001B/0x102001A/0x0/0x0 for device 0x2001B/0x102001A/0x0/0x0
Memory Base Address: 0x40000000
smem protocol = 9C2FA0A0
board_id1 is 1
 board_id2 is 1
 board_id3 is 0
board_id is 1
get_boardid_from_smem,SUCCESS ,board_id=0x102,cpu_id=0x39148C8C,hwdefined=0
 PON Reason is 17 cold_boot:1 charger path: 1
...(proceeding to normal boot procedure)...

For downstream kernel, leave stock dtbo partition untouched.

Bootloader cmdline

Stock bootloader is doing nasty things with kernel command line: it passes a lot of arguments that make booting custom OS (like postmarketOS) impossible

Full list of stock command line parameters:

ramoops_memreserve=4M comes from defconfig, next from boot.img, others (starting with first androidboot. and below) come from bootloader directly.

Harmful kernel command line params from bootloader

Options like root=, skip_initramfs make kernel look for a specific partition to mount at /, skipping initramfs, which is incompatible with default booting methods of postmarketOS. That's why some tricky patches are needed like by opendata26: init: ignore bootloader cmdline params for mounts

Some info on skip_initramfs kernel cmdline parameter: https://forum.xda-developers.com/apps/magisk/pixel-2-pixel-2-xl-support-t3697427/post74361728#post74361728

Since version 6.9 postmarketOS's close-to-mainline linux kernel fork for 630/660 devices contains a workaround to ignore such cmdline parameters - https://github.com/sdm660-mainline/linux/commit/d0b6901c00ceaaad48447cd299545d4872d11b76 .

Way to get boot log

This device known to ship with the oem getlog fastboot command.

This is not a trivial command to use, but it is extremely useful as it allows side-stepping the need to boot in a known working system to use the ramoops console. The output of the command is a jumble, but is still usable for figuring out early boot issues. It is much better than having to rely on a booted system to get the information, but still not as good as having a dedicated serial access.

Example usage follows.


$ fastboot oem getlog 2>&1
(bootloader) [    0.000000] Booting Linux on physical CPU 0x0
[    0.000
(bootloader) 000] Initializing cgroup subsys cpuset
[    0.000000] Initi
(bootloader) alizing cgroup subsys cpu
[    0.000000] Initializing cgrou
(bootloader) p subsys cpuacct
[    0.000000] Initializing cgroup subsys
(bootloader) schedtune
[    0.000000] Linux version 4.4.153 (nixbld@loca
(bootloader) lhost) (gcc version 4.9.4 (GCC) ) #2 SMP PREEMPT Sat Nov 23
(bootloader)  20:31:33 UTC 2019
[    0.000000] Boot CPU: AArch64 Process
(bootloader) or [51af8014]
[...]


As the output of the command is on stderr, here's how to output to a file.


$ fastboot oem getlog > log.txt 2>&1


It is unknown if there are ways to make the output better. (Apply some kind error correction algorithm?)

EDIT: seems to not work for me, whatever you do, the output is:

$ fastboot oem getlog
                                                  (bootloader) [Macle]Maybe no last kmsg
OKAY [  0.000s]
Finished. Total time: 0.000s

Probably needs a crash? But I can read pstore-console (dmesg) logs from booted TWRP recovery fine..

Xiaomi Redmi Note 7 (lavender) UART test pins schematic
Xiaomi Redmi Note 7 (lavender) UART test pins photo

Getting logs through debug UART

You have to disassemble the phone (just removing back cover is enough). You'll have to heat up edges of the back cover (as shown in disassembling video, see Links below) before trying to remove it. Be careful! It is made of glass! Also be careful about fingerprint sensor connector, it is connected to a back cover you are trying to remove. Don't rip it.

In the center you will see 4 test points that are available. (See the picture) Two bigger ones (0.8mm) are EDL (FORCE_USB_BOOT) pins. UART test points are two smaller ones on the left (0.5mm). TP11 is UART TX (gpio 4), TP10 is UART RX (gpio 5). GND is that whole metal shielding, that covers the center of the board. So, to get debug logs from UART it is enough to connect UART TX from the board to RX pin on the converter, and connect GND between phone and GND pin on the converter.

Links