sm8x50-userdebug: Add a generic build target for Qcom ARMv9 devboards am: bd765d63de

Original change: https://android-review.googlesource.com/c/device/linaro/dragonboard/+/3022523

Change-Id: I07080d0103f7baf94766ce8a25d2508609bffe12
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/Android.mk b/Android.mk
index 044c695..602e63e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -20,7 +20,7 @@
 # to only building on ARM if they include assembly. Individual makefiles
 # are responsible for having their own logic, for fine-grained control.
 
-ifneq ($(filter db845c linaro_swr, $(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter db845c linaro_swr sm8x50, $(TARGET_BOARD_PLATFORM)),)
 
 LOCAL_PATH := $(call my-dir)
 
diff --git a/AndroidProducts.mk b/AndroidProducts.mk
index 2479437..f121e04 100644
--- a/AndroidProducts.mk
+++ b/AndroidProducts.mk
@@ -14,6 +14,7 @@
     $(LOCAL_DIR)/db845c_mini.mk \
     $(LOCAL_DIR)/sm8450_mini.mk \
     $(LOCAL_DIR)/linaro_swr.mk \
+    $(LOCAL_DIR)/sm8x50/sm8x50.mk
 
 COMMON_LUNCH_CHOICES := \
     db845c-trunk_staging-userdebug
diff --git a/build/tasks/kernel.mk b/build/tasks/kernel.mk
index ed747b7..1478753 100644
--- a/build/tasks/kernel.mk
+++ b/build/tasks/kernel.mk
@@ -1,7 +1,26 @@
-ifneq ($(filter db845c db845c_mini linaro_swr, $(TARGET_DEVICE)),)
+ifneq ($(filter db845c db845c_mini linaro_swr sm8x50, $(TARGET_DEVICE)),)
 
-$(PRODUCT_OUT)/dtb.img: $(TARGET_KERNEL_DIR)/sdm845-db845c.dtb $(wildcard $(TARGET_KERNEL_DIR)/qrb5165-rb5.dtb)
-	cat $^ > $@
+DTC := $(HOST_OUT)/bin/dtc
+FDTOVERLAY := $(HOST_OUT)/bin/fdtoverlay
+SM8550HDK_DTS_OVERLAY := device/linaro/dragonboard/sm8x50/dtb-overlays/sm8550-hdk.dts
+SM8550QRD_DTS_OVERLAY := device/linaro/dragonboard/sm8x50/dtb-overlays/sm8550-qrd.dts
+SM8650QRD_DTS_OVERLAY := device/linaro/dragonboard/sm8x50/dtb-overlays/sm8650-qrd.dts
+
+DB845C_DTB := $(TARGET_KERNEL_DIR)/sdm845-db845c.dtb
+RB5_DTB := $(wildcard $(TARGET_KERNEL_DIR)/qrb5165-rb5.dtb)
+SM8550HDK_DTB := $(wildcard $(TARGET_KERNEL_DIR)/sm8550-hdk.dtb)
+SM8550QRD_DTB := $(wildcard $(TARGET_KERNEL_DIR)/sm8550-qrd.dtb)
+SM8650QRD_DTB := $(wildcard $(TARGET_KERNEL_DIR)/sm8650-qrd.dtb)
+
+$(PRODUCT_OUT)/dtb.img: $(DTC) $(FDTOVERLAY)
+	-$(DTC) -@ -I dts -O dtb -o $(PRODUCT_OUT)/sm8550-hdk.dtbo $(SM8550HDK_DTS_OVERLAY)
+	-$(FDTOVERLAY) -i $(SM8550HDK_DTB) -o $(PRODUCT_OUT)/sm8550-hdk.dtb $(PRODUCT_OUT)/sm8550-hdk.dtbo
+	-$(DTC) -@ -I dts -O dtb -o $(PRODUCT_OUT)/sm8550-qrd.dtbo $(SM8550QRD_DTS_OVERLAY)
+	-$(FDTOVERLAY) -i $(SM8550QRD_DTB) -o $(PRODUCT_OUT)/sm8550-qrd.dtb $(PRODUCT_OUT)/sm8550-qrd.dtbo
+	-$(DTC) -@ -I dts -O dtb -o $(PRODUCT_OUT)/sm8650-qrd.dtbo $(SM8650QRD_DTS_OVERLAY)
+	-$(FDTOVERLAY) -i $(SM8650QRD_DTB) -o $(PRODUCT_OUT)/sm8650-qrd.dtb $(PRODUCT_OUT)/sm8650-qrd.dtbo
+	-cat $(DB845C_DTB) $(RB5_DTB) $(PRODUCT_OUT)/sm8550-hdk.dtb $(PRODUCT_OUT)/sm8550-qrd.dtb $(PRODUCT_OUT)/sm8650-qrd.dtbo > $@
+	-rm $(PRODUCT_OUT)/sm8*dtb*
 
 droidcore: $(PRODUCT_OUT)/dtb.img
 
diff --git a/full.mk b/full.mk
index 9971c62..00e3eb8 100644
--- a/full.mk
+++ b/full.mk
@@ -170,8 +170,11 @@
 PRODUCT_PACKAGES += \
     suspend_blocker
 
+# dtc and fdtoverlay tools to apply dt overlays
 # mkbootimg host tool to build boot.img separately
 PRODUCT_HOST_PACKAGES := \
+    dtc \
+    fdtoverlay \
     mkbootimg
 
 # Userspace vendor services for WiFi/Audio to work
diff --git a/sepolicy/tqftpserv.te b/sepolicy/tqftpserv.te
index d437c0d..6838c12 100644
--- a/sepolicy/tqftpserv.te
+++ b/sepolicy/tqftpserv.te
@@ -7,4 +7,4 @@
 allow tqftpserv sysfs_remoteproc:dir { open read search };
 allow tqftpserv sysfs_remoteproc:file { open read };
 allow tqftpserv tqftpserv_vendor_data_file:dir { add_name create open read search write };
-allow tqftpserv tqftpserv_vendor_data_file:file { create open write };
+allow tqftpserv tqftpserv_vendor_data_file:file { create getattr open read write };
diff --git a/shared/utils/set_hw.sh b/shared/utils/set_hw.sh
index 98f76c3..305a345 100644
--- a/shared/utils/set_hw.sh
+++ b/shared/utils/set_hw.sh
@@ -3,10 +3,32 @@
 #
 # grep the device name from /proc/device-tree/compatible
 
-HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep rb5`
-
-if [ -z "${HW}" ]; then
+HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep db845c`
+if [ -n "${HW}" ]; then
     setprop vendor.hw db845c
-else
+    exit 0
+fi
+
+HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep rb5`
+if [ -n "${HW}" ]; then
     setprop vendor.hw rb5
+    exit 0
+fi
+
+HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep sm8550-hdk`
+if [ -n "${HW}" ]; then
+    setprop vendor.hw sm8550hdk
+    exit 0
+fi
+
+HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep sm8550-qrd`
+if [ -n "${HW}" ]; then
+    setprop vendor.hw sm8550qrd
+    exit 0
+fi
+
+HW=`/vendor/bin/cat /proc/device-tree/compatible | /vendor/bin/grep sm8650-qrd`
+if [ -n "${HW}" ]; then
+    setprop vendor.hw sm8650qrd
+    exit 0
 fi
diff --git a/sm8x50/BoardConfig.mk b/sm8x50/BoardConfig.mk
new file mode 100644
index 0000000..9015b1c
--- /dev/null
+++ b/sm8x50/BoardConfig.mk
@@ -0,0 +1,52 @@
+include device/linaro/dragonboard/BoardConfigCommon.mk
+
+# Primary Arch
+TARGET_ARCH := arm64
+TARGET_ARCH_VARIANT := armv9-a
+TARGET_CPU_VARIANT := kryo385
+TARGET_CPU_ABI := arm64-v8a
+
+# Board Information
+TARGET_BOOTLOADER_BOARD_NAME := sm8x50
+TARGET_BOARD_PLATFORM := sm8x50
+
+TARGET_NO_KERNEL := false
+BOARD_INCLUDE_DTB_IN_BOOTIMG := true
+BOARD_BOOT_HEADER_VERSION := 2 # XXX v4 is WIP
+BOARD_MKBOOTIMG_ARGS := --header_version $(BOARD_BOOT_HEADER_VERSION)
+
+BOARD_KERNEL_BASE := 0x80000000
+BOARD_KERNEL_PAGESIZE := 4096
+BOARD_KERNEL_CMDLINE += earlycon firmware_class.path=/vendor/firmware/
+BOARD_KERNEL_CMDLINE += init=/init printk.devkmsg=on
+BOARD_KERNEL_CMDLINE += deferred_probe_timeout=30
+BOARD_KERNEL_CMDLINE += qcom_geni_serial.con_enabled=1
+BOARD_KERNEL_CMDLINE += console=ttyMSM0,115200n8
+BOARD_KERNEL_CMDLINE += allow_mismatched_32bit_el0 clk_ignore_unused pd_ignore_unused
+BOARD_KERNEL_CMDLINE += androidboot.boot_devices=soc@0/1d84000.ufs
+BOARD_KERNEL_CMDLINE += androidboot.hardware=sm8x50
+BOARD_KERNEL_CMDLINE += androidboot.verifiedbootstate=orange
+
+# Image Configuration
+BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864 #64M
+BOARD_USERDATAIMAGE_PARTITION_SIZE := 223226966016 #200+G
+BOARD_FLASH_BLOCK_SIZE := 131072
+# Super partition
+BOARD_SUPER_PARTITION_SIZE := 6442450944 #6GB
+BOARD_DB_DYNAMIC_PARTITIONS_SIZE := 6438256640 # Reserve 4M for DAP metadata
+BOARD_SUPER_PARTITION_METADATA_DEVICE := super
+BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE := true
+BOARD_DB_DYNAMIC_PARTITIONS_PARTITION_LIST := system vendor system_ext product
+
+# Platform specific sepolicies
+BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/sm8x50/sepolicy/
+
+# dlkm partitions
+include device/linaro/dragonboard/shared/utils/dlkm_loader/BoardConfig.mk
+BOARD_DB_DYNAMIC_PARTITIONS_PARTITION_LIST += system_dlkm vendor_dlkm
+BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/shared/utils/dlkm_loader/sepolicy/
+
+# Graphics
+include device/linaro/dragonboard/shared/graphics/drm_hwcomposer/BoardConfig.mk
+BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/shared/graphics/swangle/sepolicy
+BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/shared/graphics/minigbm_msm/sepolicy
diff --git a/sm8x50/device.mk b/sm8x50/device.mk
new file mode 100644
index 0000000..1613a5f
--- /dev/null
+++ b/sm8x50/device.mk
@@ -0,0 +1,75 @@
+#
+# Copyright (C) 2024 The Android Open-Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# setup dalvik vm configs
+$(call inherit-product, frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-heap.mk)
+
+include $(LOCAL_PATH)/../vendor-package-ver.mk
+$(call inherit-product, $(SRC_TARGET_DIR)/product/virtual_ab_ota.mk)
+
+# dlkm_loader
+include device/linaro/dragonboard/shared/utils/dlkm_loader/device.mk
+PRODUCT_COPY_FILES += \
+    device/linaro/dragonboard/shared/utils/dlkm_loader/dlkm_loader.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/dlkm_loader.rc
+
+# Build generic Audio HAL
+PRODUCT_PACKAGES += audio.primary.sm8x50
+
+# BootControl HAL
+PRODUCT_PACKAGES += \
+    android.hardware.boot@1.2-impl \
+    android.hardware.boot@1.2-impl.recovery \
+    android.hardware.boot@1.2-service
+
+# Set BT address
+PRODUCT_PACKAGES += bdaddr
+
+# Install bdaddr script
+PRODUCT_COPY_FILES += \
+    device/linaro/dragonboard/shared/utils/bdaddr/set_bdaddr.sh:$(TARGET_COPY_OUT_VENDOR)/bin/set_bdaddr.sh
+
+# Install scripts to set vendor.* properties
+PRODUCT_COPY_FILES += \
+    device/linaro/dragonboard/shared/utils/set_hw.sh:$(TARGET_COPY_OUT_VENDOR)/bin/set_hw.sh \
+    device/linaro/dragonboard/shared/utils/set_udc.sh:$(TARGET_COPY_OUT_VENDOR)/bin/set_udc.sh
+
+# Install scripts to set Ethernet MAC address
+PRODUCT_COPY_FILES += \
+    device/linaro/dragonboard/shared/utils/ethaddr/ethaddr.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/ethaddr.rc \
+    device/linaro/dragonboard/shared/utils/ethaddr/set_ethaddr.sh:$(TARGET_COPY_OUT_VENDOR)/bin/set_ethaddr.sh
+
+PRODUCT_COPY_FILES += \
+    $(LOCAL_PATH)/fstab:$(TARGET_COPY_OUT_RAMDISK)/first_stage_ramdisk/fstab.sm8x50 \
+    $(LOCAL_PATH)/fstab:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.sm8x50
+
+PRODUCT_VENDOR_PROPERTIES += \
+    ro.soc.manufacturer=Snapdragon 8 Gen Devboard \
+    ro.soc.model=SM8x50
+
+PRODUCT_SOONG_NAMESPACES += \
+    vendor/linaro/sm8x50/$(EXPECTED_LINARO_VENDOR_VERSION)
+
+# XXX until v4 support
+PRODUCT_COPY_FILES += \
+    device/linaro/dragonboard/shared/utils/dlkm_loader/vendor_ramdisk.modules.blocklist:$(TARGET_COPY_OUT_RAMDISK)/lib/modules/modules.blocklist
+
+# Copy firmware files
+$(call inherit-product-if-exists, vendor/linaro/sm8x50/$(EXPECTED_LINARO_VENDOR_VERSION)/device.mk)
+
+TARGET_HARDWARE := sm8x50
+TARGET_KERNEL_USE ?= mainline
+
+include device/linaro/dragonboard/device-common.mk
diff --git a/sm8x50/dtb-overlays/sm8550-hdk.dts b/sm8x50/dtb-overlays/sm8550-hdk.dts
new file mode 100644
index 0000000..caf4dc1
--- /dev/null
+++ b/sm8x50/dtb-overlays/sm8550-hdk.dts
@@ -0,0 +1,7 @@
+/dts-v1/;
+/plugin/;
+
+&{/} {
+	qcom,msm-id = <536 0x10000>, <536 0x20000>, <601 0x20000>;
+	qcom,board-id = <0x1001f 0>;
+};
diff --git a/sm8x50/dtb-overlays/sm8550-qrd.dts b/sm8x50/dtb-overlays/sm8550-qrd.dts
new file mode 100644
index 0000000..1f1d059
--- /dev/null
+++ b/sm8x50/dtb-overlays/sm8550-qrd.dts
@@ -0,0 +1,7 @@
+/dts-v1/;
+/plugin/;
+
+&{/} {
+	qcom,msm-id = <0x207 0x20000 0x218 0x20000>;
+	qcom,board-id = <0x1000b 0x00>;
+};
diff --git a/sm8x50/dtb-overlays/sm8650-qrd.dts b/sm8x50/dtb-overlays/sm8650-qrd.dts
new file mode 100644
index 0000000..7903ae2
--- /dev/null
+++ b/sm8x50/dtb-overlays/sm8650-qrd.dts
@@ -0,0 +1,7 @@
+/dts-v1/;
+/plugin/;
+
+&{/} {
+	qcom,msm-id = <0x22d 0x10000>;
+	qcom,board-id = <0x0b 0x00>;
+};
diff --git a/sm8x50/fstab b/sm8x50/fstab
new file mode 100644
index 0000000..6483e3e
--- /dev/null
+++ b/sm8x50/fstab
@@ -0,0 +1,11 @@
+system		/system		erofs	ro				wait,logical,first_stage_mount,slotselect
+/dev/block/platform/soc@0/1d84000.ufs/by-name/userdata /data		ext4	discard,noatime,noauto_da_alloc,data=ordered,user_xattr,barrier=1,inlinecrypt	latemount,wait,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized,keydirectory=/metadata/vold/metadata_encryption,quota
+/dev/block/platform/soc@0/1d84000.ufs/by-name/metadata	/metadata	ext4	noatime,nosuid,nodev,discard					wait,formattable,first_stage_mount,check
+/dev/block/platform/soc@0/1d84000.ufs/by-name/misc /misc emmc defaults defaults
+/devices/platform/soc@0/8804000.mmc/mmc_host/mmc*	auto	auto	defaults	voldmanaged=sdcard1:auto
+vendor		/vendor		erofs	ro				wait,logical,first_stage_mount,slotselect
+system_ext	/system_ext	erofs	ro				wait,logical,first_stage_mount,slotselect
+product		/product	erofs	ro				wait,logical,first_stage_mount,slotselect
+system_dlkm	/system_dlkm	erofs	ro				wait,logical,first_stage_mount,slotselect
+vendor_dlkm	/vendor_dlkm	erofs	ro				wait,logical,first_stage_mount,slotselect
+/dev/block/zram0					none	swap	defaults	zramsize=75%
diff --git a/sm8x50/sepolicy/file_contexts b/sm8x50/sepolicy/file_contexts
new file mode 100644
index 0000000..2010957
--- /dev/null
+++ b/sm8x50/sepolicy/file_contexts
@@ -0,0 +1,17 @@
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/fsc				u:object_r:modem_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/fsg				u:object_r:modem_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/modemst[12]			u:object_r:modem_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/metadata				u:object_r:metadata_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/super				u:object_r:super_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/userdata				u:object_r:userdata_block_device:s0
+/dev/block/platform/soc@0/1d84000\.ufs/by-name/misc				u:object_r:misc_block_device:s0
+
+/sys/devices/platform/d4a80000.memory/rmtfs					u:object_r:sysfs_rmtfs:s0
+/sys/devices/platform/d4a80000.rmtfs-region/rmtfs				u:object_r:sysfs_rmtfs:s0
+
+/sys/devices/platform/soc@0/30000000.remoteproc					u:object_r:sysfs_remoteproc:s0
+/sys/devices/platform/soc@0/32300000.remoteproc					u:object_r:sysfs_remoteproc:s0
+
+#wakeups
+/sys/devices/platform/soc@0/4080000.remoteproc/wakeup/wakeup3			u:object_r:sysfs_wakeup:s0
+/sys/devices/platform/soc@0/30000000.remoteproc/wakeup/wakeup4			u:object_r:sysfs_wakeup:s0
diff --git a/sm8x50/sepolicy/genfs_contexts b/sm8x50/sepolicy/genfs_contexts
new file mode 100644
index 0000000..447edb3
--- /dev/null
+++ b/sm8x50/sepolicy/genfs_contexts
@@ -0,0 +1,9 @@
+genfscon	sysfs	/devices/platform/d4a80000.memory/rmtfs					u:object_r:sysfs_rmtfs:s0
+genfscon	sysfs	/devices/platform/d4a80000.rmtfs-region/rmtfs				u:object_r:sysfs_rmtfs:s0
+
+genfscon	sysfs	/devices/platform/soc@0/30000000.remoteproc				u:object_r:sysfs_remoteproc:s0
+genfscon	sysfs	/devices/platform/soc@0/32300000.remoteproc				u:object_r:sysfs_remoteproc:s0
+
+#wakeups
+genfscon	sysfs	/devices/platform/soc@0/4080000.remoteproc/wakeup/wakeup3		u:object_r:sysfs_wakeup:s0
+genfscon	sysfs	/devices/platform/soc@0/30000000.remoteproc/wakeup/wakeup4		u:object_r:sysfs_wakeup:s0
diff --git a/sm8x50/sm8x50.mk b/sm8x50/sm8x50.mk
new file mode 100644
index 0000000..79d5441
--- /dev/null
+++ b/sm8x50/sm8x50.mk
@@ -0,0 +1,16 @@
+$(call inherit-product, device/linaro/dragonboard/full.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit_only.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
+
+# Target boots with software rendering
+TARGET_USES_SWR := true
+$(call inherit-product, device/linaro/dragonboard/shared/graphics/drm_hwcomposer/device.mk)
+$(call inherit-product, device/linaro/dragonboard/shared/graphics/swangle/device.mk)
+$(call inherit-product, device/linaro/dragonboard/shared/graphics/minigbm_msm/device.mk)
+
+$(call inherit-product, device/linaro/dragonboard/sm8x50/device.mk)
+
+# Product overrides
+PRODUCT_NAME := sm8x50
+PRODUCT_DEVICE := sm8x50
+PRODUCT_BRAND := Android