diff --git a/config/boards/oneplus-kebab.conf b/config/boards/oneplus-kebab.conf new file mode 100644 index 000000000000..30472d9aa3ed --- /dev/null +++ b/config/boards/oneplus-kebab.conf @@ -0,0 +1,104 @@ +# Generate kernel and rootfs image for Qcom ABL booting +declare -g BOARD_NAME="Oneplus Kebab" +declare -g BOARD_MAINTAINER="amazingfate" +declare -g BOARDFAMILY="sm8250" +declare -g KERNEL_TARGET="current,edge" +declare -g KERNEL_TEST_TARGET="edge" +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-oneplus-kebab") + +# Use the full firmware, complete linux-firmware plus Armbian's (for qcom/a650_sqe.fw) +declare -g BOARD_FIRMWARE_INSTALL="-full" + +function oneplus-kebab_is_userspace_supported() { + [[ "${RELEASE}" == "jammy" ]] && return 0 + [[ "${RELEASE}" == "trixie" ]] && return 0 + [[ "${RELEASE}" == "noble" ]] && return 0 + return 1 +} + +function post_family_tweaks_bsp__oneplus-kebab_firmware() { + display_alert "$BOARD" "Install firmwares for oneplus kebab" "info" + + # 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/ + + # Bluetooth MAC addr setup service + install -Dm655 $SRC/packages/bsp/generate-bt-mac-addr/bt-fixed-mac.sh $destination/usr/local/bin/ + install -Dm644 $SRC/packages/bsp/generate-bt-mac-addr/bt-fixed-mac.service $destination/usr/lib/systemd/system/ + + # Kernel postinst script to update abl boot partition + install -Dm655 $SRC/packages/bsp/oneplus-kebab/zz-update-abl-kernel $destination/etc/kernel/postinst.d/ + + # Add kebab firmwares + mkdir -p $destination/lib/firmware/qcom/sm8250/OnePlus/kebab + install -Dm644 $SRC/packages/bsp/oneplus-kebab/a650_zap.mbn $destination/lib/firmware/qcom/sm8250/OnePlus/ + install -Dm644 $SRC/packages/bsp/oneplus-kebab/adsp.mbn $destination/lib/firmware/qcom/sm8250/OnePlus/ + install -Dm644 $SRC/packages/bsp/oneplus-kebab/cdsp.mbn $destination/lib/firmware/qcom/sm8250/OnePlus/ + install -Dm644 $SRC/packages/bsp/oneplus-kebab/venus.mbn $destination/lib/firmware/qcom/sm8250/OnePlus/kebab + + return 0 +} + +function post_family_tweaks__oneplus-kebab_enable_services() { + if ! oneplus-kebab_is_userspace_supported; then + 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" ]] || [[ "${RELEASE}" == "noble" ]];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 + chroot_sdcard systemctl enable bt-fixed-mac.service + return 0 +} + +function post_family_tweaks_bsp__oneplus-kebab_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 + add_file_from_stdin_to_bsp_destination "/etc/initramfs-tools/hooks/oneplus-kebab-firmware" <<- 'FIRMWARE_HOOK' + #!/bin/bash + [[ "$1" == "prereqs" ]] && exit 0 + . /usr/share/initramfs-tools/hook-functions + for f in /lib/firmware/qcom/sm8250/OnePlus/* ; 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__oneplus-kebab_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 +} diff --git a/packages/bsp/oneplus-kebab/a650_zap.mbn b/packages/bsp/oneplus-kebab/a650_zap.mbn new file mode 100644 index 000000000000..87be0da72049 Binary files /dev/null and b/packages/bsp/oneplus-kebab/a650_zap.mbn differ diff --git a/packages/bsp/oneplus-kebab/adsp.mbn b/packages/bsp/oneplus-kebab/adsp.mbn new file mode 100644 index 000000000000..dc08cc3d74d9 Binary files /dev/null and b/packages/bsp/oneplus-kebab/adsp.mbn differ diff --git a/packages/bsp/oneplus-kebab/cdsp.mbn b/packages/bsp/oneplus-kebab/cdsp.mbn new file mode 100644 index 000000000000..fc560dc48230 Binary files /dev/null and b/packages/bsp/oneplus-kebab/cdsp.mbn differ diff --git a/packages/bsp/oneplus-kebab/venus.mbn b/packages/bsp/oneplus-kebab/venus.mbn new file mode 100644 index 000000000000..225a0c3842ce Binary files /dev/null and b/packages/bsp/oneplus-kebab/venus.mbn differ diff --git a/packages/bsp/oneplus-kebab/zz-update-abl-kernel b/packages/bsp/oneplus-kebab/zz-update-abl-kernel new file mode 100755 index 000000000000..c08fe837aa53 --- /dev/null +++ b/packages/bsp/oneplus-kebab/zz-update-abl-kernel @@ -0,0 +1,28 @@ +#!/bin/bash +set -ex +new_rootfs_image_uuid=$(sed -e 's/^.*root=UUID=//' -e 's/ .*$//' < /proc/cmdline) +gzip -c /boot/vmlinuz-*-sm8250 > /tmp/Image.gz + +cat /tmp/Image.gz /usr/lib/linux-image-*-sm8250/qcom/sm8250-oneplus-kebab.dtb > /tmp/Image.gz-dtb + +source /boot/armbianEnv.txt +/usr/bin/mkbootimg \ + --kernel /tmp/Image.gz-dtb \ + --ramdisk /boot/initrd.img-*-sm8250 \ + --base 0x0 \ + --second_offset 0x00f00000 \ + --cmdline "root=UUID=${new_rootfs_image_uuid} slot_suffix=${abl_boot_partition_label#boot}" \ + --kernel_offset 0x8000 \ + --ramdisk_offset 0x1000000 \ + --tags_offset 0x100 \ + --pagesize 4096 \ + -o /boot/armbian-kernel.img +rm -f /tmp/Image.gz /tmp/Image.gz-dtb + +if [ -n "$abl_boot_partition_label" ];then + echo abl boot partition label is $abl_boot_partition_label + dd if=/boot/armbian-kernel.img of=/dev/disk/by-partlabel/${abl_boot_partition_label} +else + echo abl boot partition label is not defined, exit + exit +fi