Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add redmi k30 pro #6256

Closed
wants to merge 13 commits into from
106 changes: 106 additions & 0 deletions config/boards/xiaomi-lmi.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Generate kernel and rootfs image for Qcom ABL booting
declare -g BOARD_NAME="Xiaomi lmi"
declare -g BOARD_MAINTAINER="FantasyGmm"
declare -g BOARDFAMILY="qcom-abl"
declare -g KERNEL_TARGET="sm8250"
declare -g KERNELPATCHDIR="arm64-sm8250"
declare -g EXTRAWIFI="no"
declare -g MODULES="spi-geni-qcom"
declare -g BOOTCONFIG="none"
declare -g IMAGE_PARTITION_TABLE="gpt"
declare -g -a ABL_DTB_LIST=("sm8250-xiaomi-lmi")

# Use the full firmware, complete linux-firmware plus Armbian's (for qcom/a650_sqe.fw)
declare -g BOARD_FIRMWARE_INSTALL="-full"

function post_family_config_branch_sm8250__pmos_kernel() {
display_alert "Setting up kernel for" "${BOARD}" "info"
declare -g KERNEL_MAJOR_MINOR="6.7" # Major and minor versions of this kernel.
declare -g KERNELBRANCH='branch:linux-6.7.y'
}

function xiaomi-lmi_is_userspace_supported() {
[[ "${RELEASE}" == "jammy" ]] && return 0
[[ "${RELEASE}" == "trixie" ]] && return 0
[[ "${RELEASE}" == "noble" ]] && return 0
return 1
}

function post_family_tweaks_bsp__xiaomi-lmi_firmware() {
display_alert "$BOARD" "Install firmwares for xiaomi lmi" "info"

# Alsa-ucm-conf profile for Xiaomi lmi
mkdir -p $destination/usr/share/alsa/ucm2/conf.d/sm8250
install -Dm644 $SRC/packages/bsp/xiaomi-lmi/lmi.conf $destination/usr/share/alsa/ucm2/Xiaomi/lmi/lmi.conf
install -Dm644 $SRC/packages/bsp/xiaomi-lmi/lmi_HiFi.conf $destination/usr/share/alsa/ucm2/Xiaomi/lmi/HiFi.conf
ln -sfv ../../Xiaomi/lmi/lmi.conf \
"$destination/usr/share/alsa/ucm2/conf.d/sm8250/Xiaomi Mi 10.conf"

# USB Gadget Network service
mkdir -p $destination/usr/local/bin/
mkdir -p $destination/usr/lib/systemd/system/
install -Dm655 $SRC/packages/bsp/usb-gadget-network/setup-usbgadget-network.sh $destination/usr/local/bin/
install -Dm655 $SRC/packages/bsp/usb-gadget-network/remove-usbgadget-network.sh $destination/usr/local/bin/
install -Dm644 $SRC/packages/bsp/usb-gadget-network/usbgadget-rndis.service $destination/usr/lib/systemd/system/

# Kernel postinst script to update abl boot partition
install -Dm655 $SRC/packages/bsp/xiaomi-lmi/zz-update-abl-kernel $destination/etc/kernel/postinst.d/

return 0
}

function post_family_tweaks__xiaomi-lmi_enable_services() {
if ! xiaomi-lmi_is_userspace_supported; then
viraniac marked this conversation as resolved.
Show resolved Hide resolved
if [[ "${RELEASE}" != "" ]]; then
display_alert "Missing userspace for ${BOARD}" "${RELEASE} does not have the userspace necessary to support the ${BOARD}" "warn"
fi
return 0
fi

if [[ "${RELEASE}" == "jammy" ]]; then
display_alert "Adding qcom-mainline PPA" "${BOARD}" "info"
do_with_retries 3 chroot_sdcard add-apt-repository ppa:liujianfeng1994/qcom-mainline --yes --no-update
fi

# We need unudhcpd from armbian repo, so enable it
mv "${SDCARD}"/etc/apt/sources.list.d/armbian.list.disabled "${SDCARD}"/etc/apt/sources.list.d/armbian.list

do_with_retries 3 chroot_sdcard_apt_get_update
display_alert "$BOARD" "Installing board tweaks" "info"
do_with_retries 3 chroot_sdcard_apt_get_install alsa-ucm-conf qbootctl qrtr-tools protection-domain-mapper tqftpserv unudhcpd mkbootimg

# Disable armbian repo back
mv "${SDCARD}"/etc/apt/sources.list.d/armbian.list "${SDCARD}"/etc/apt/sources.list.d/armbian.list.disabled
do_with_retries 3 chroot_sdcard_apt_get_update

chroot_sdcard systemctl enable qbootctl.service
chroot_sdcard systemctl enable usbgadget-rndis.service
chroot_sdcard systemctl enable pd-mapper.service
chroot_sdcard systemctl enable tqftpserv.service
return 0
}

function post_family_tweaks_bsp__xiaomi-lmi_bsp_firmware_in_initrd() {
display_alert "Adding to bsp-cli" "${BOARD}: firmware in initrd" "info"
declare file_added_to_bsp_destination # Will be filled in by add_file_from_stdin_to_bsp_destination
# Using Elish's firmware for now
add_file_from_stdin_to_bsp_destination "/etc/initramfs-tools/hooks/xiaomi-elish-firmware" <<- 'FIRMWARE_HOOK'
#!/bin/bash
[[ "$1" == "prereqs" ]] && exit 0
. /usr/share/initramfs-tools/hook-functions
for f in /lib/firmware/qcom/sm8250/xiaomi/elish/* ; do
add_firmware "${f#/lib/firmware/}"
done
add_firmware "qcom/a650_sqe.fw" # Extra one for dpu
add_firmware "qcom/a650_gmu.bin" # Extra one for gpu
FIRMWARE_HOOK
run_host_command_logged chmod -v +x "${file_added_to_bsp_destination}"
}

## Modules, required to boot, add them to initrd
function post_family_tweaks_bsp__xiaomi-lmi_bsp_modules_in_initrd() {
display_alert "Adding to bsp-cli" "${BOARD}: modules in initrd" "info"
add_file_from_stdin_to_bsp_destination "/etc/initramfs-tools/modules" <<- 'EXTRA_MODULES'
spi-geni-qcom
EXTRA_MODULES
}
6 changes: 6 additions & 0 deletions packages/bsp/xiaomi-lmi/lmi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Syntax 3

SectionUseCase."HiFi" {
File "/Xiaomi/lmi/HiFi.conf"
Comment "HiFi quality Music."
}
63 changes: 63 additions & 0 deletions packages/bsp/xiaomi-lmi/lmi_HiFi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
SectionVerb {
EnableSequence [
cset "name='TLH DSP1 Preload Switch' 1"
cset "name='TLH DRE Switch' 1"
cset "name='TLH PCM Soft Ramp' 4ms"
cset "name='TLH Analog PCM Volume' 18"
cset "name='TLH ASP TX1 Source' DSPTX1"
cset "name='TLH DSP RX1 Source' ASPRX1"
cset "name='TLH DSP RX2 Source' ASPTX2"

cset "name='TERT_TDM_RX_0 Audio Mixer MultiMedia1' 1"
]

DisableSequence [
cset "name='TLH DSP1 Preload Switch' 0"
cset "name='TLH DRE Switch' 0"
cset "name='TLH PCM Soft Ramp' zero"
cset "name='TLH Analog PCM Volume' 0"
cset "name='TLH ASP TX1 Source' zero"
cset "name='TLH DSP RX1 Source' zero"
cset "name='TLH DSP RX2 Source' zero"

cset "name='TERT_TDM_RX_0 Audio Mixer MultiMedia1' 0"
]

Value {
TQ "HiFi"
}
}

SectionDevice."Speaker" {
Comment "Speaker playback"

EnableSequence [
cset "name='TLH PCM Source' DSP"
cset "name='TLL PCM Source' DSP"
cset "name='TRH PCM Source' DSP"
cset "name='TRL PCM Source' DSP"
cset "name='BLH PCM Source' DSP"
cset "name='BLL PCM Source' DSP"
cset "name='BRH PCM Source' DSP"
cset "name='BRL PCM Source' DSP"
]

DisableSequence [
cset "name='TLH PCM Source' zero"
cset "name='TLL PCM Source' zero"
cset "name='TRH PCM Source' zero"
cset "name='TRL PCM Source' zero"
cset "name='BLH PCM Source' zero"
cset "name='BLL PCM Source' zero"
cset "name='BRH PCM Source' zero"
cset "name='BRL PCM Source' zero"
]

Value {
PlaybackPriority 100
PlaybackPCM "hw:${CardId},0"
PlaybackMixerElem "Digital PCM"
PlaybackMasterElem "Analog PCM"
PlaybackVolume "Digital PCM Volume"
}
}
34 changes: 34 additions & 0 deletions packages/bsp/xiaomi-lmi/zz-update-abl-kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -ex
machine_model=$(cat /sys/firmware/devicetree/base/model|tr '\0' '\n')
case $machine_model in
"Redmi k30 pro (SMS)")
panel_type=sms
;;
"Redmi k30 pro (CSOT)")
panel_type=csot
Comment on lines +4 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model is define as Redmi k30 pro (lmi) in devicetree, I think this will not work.

;;
*)
# echo "$machine_model is not supported, exit"
# exit
panel_type=csot
;;
esac
new_rootfs_image_uuid=$(sed -e 's/^.*root=UUID=//' -e 's/ .*$//' < /proc/cmdline)
gzip -c /boot/vmlinuz-*-sm8250-arm64 > /tmp/Image.gz

cat /tmp/Image.gz /usr/lib/linux-image-*-sm8250-arm64/qcom/sm8250-xiaomi-lmi-${panel_type}.dtb > /tmp/Image.gz-dtb-${panel_type}

source /boot/armbianEnv.txt
/usr/bin/mkbootimg \
--kernel /tmp/Image.gz-dtb-${panel_type} \
--ramdisk /boot/initrd.img-*-sm8250-arm64 \
--base 0x0 \
--second_offset 0x00f00000 \
--cmdline "clk_ignore_unused pd_ignore_unused root=UUID=${new_rootfs_image_uuid}" \
--kernel_offset 0x8000 \
--ramdisk_offset 0x1000000 \
--tags_offset 0x100 \
--pagesize 4096 \
-o /boot/armbian-kernel-${panel_type}.img
rm -f /tmp/Image.gz /tmp/Image.gz-dtb-${panel_type}
Loading
Loading