sdm845: add common sdm845 lunch target

This target builds a "generic" sdm845 device which should boot on all
SDM845 devices with common boot, vendor and system images.
diff --git a/Android.mk b/Android.mk
index d54b34d..32fa53c 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 enchilada beryllium, $(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter enchilada beryllium sdm845, $(TARGET_BOARD_PLATFORM)),)
 
 LOCAL_PATH := $(call my-dir)
 
diff --git a/AndroidProducts.mk b/AndroidProducts.mk
index 7c0b530..0b21cf7 100644
--- a/AndroidProducts.mk
+++ b/AndroidProducts.mk
@@ -11,8 +11,10 @@
 
 PRODUCT_MAKEFILES := \
     $(LOCAL_DIR)/beryllium.mk \
-    $(LOCAL_DIR)/enchilada.mk
+    $(LOCAL_DIR)/enchilada.mk \
+    $(LOCAL_DIR)/sdm845.mk
 
 COMMON_LUNCH_CHOICES := \
     beryllium-userdebug \
-    enchilada-userdebug
+    enchilada-userdebug \
+    sdm845-userdebug
diff --git a/build/tasks/kernel.mk b/build/tasks/kernel.mk
index 74baaf7..052562c 100644
--- a/build/tasks/kernel.mk
+++ b/build/tasks/kernel.mk
@@ -1,7 +1,7 @@
-ifneq ($(filter enchilada, $(TARGET_DEVICE)),)
+ifneq ($(filter enchilada beryllium sdm845, $(TARGET_DEVICE)),)
 
 IMAGE_GZ := device/generic/sdm845/prebuilt-kernel/android-$(TARGET_KERNEL_USE)/Image.gz
-DTB := device/generic/sdm845/prebuilt-kernel/android-$(TARGET_KERNEL_USE)/sdm845-oneplus-enchilada.dtb
+DTB := $(wildcard device/generic/sdm845/prebuilt-kernel/android-$(TARGET_KERNEL_USE)/*.dtb)
 
 $(PRODUCT_OUT)/kernel: $(IMAGE_GZ) $(DTB)
 	cat $(IMAGE_GZ) $(DTB) > $@
diff --git a/sdm845.mk b/sdm845.mk
new file mode 100644
index 0000000..d3c8aee
--- /dev/null
+++ b/sdm845.mk
@@ -0,0 +1,24 @@
+ifndef TARGET_KERNEL_USE
+TARGET_KERNEL_USE := mainline
+endif
+
+KERNEL_MODS := $(wildcard device/generic/sdm845/prebuilt-kernel/android-$(TARGET_KERNEL_USE)/*.ko)
+
+# Following modules go to vendor partition
+# msm.ko is too big (31M) for ramdisk
+VENDOR_KERN_MODS := %/qcom_q6v5_adsp.ko %/qcom_q6v5_mss.ko %/qcom_q6v5_pas.ko
+BOARD_VENDOR_KERNEL_MODULES := $(filter $(VENDOR_KERN_MODS),$(KERNEL_MODS))
+
+# All other modules go to ramdisk
+BOARD_GENERIC_RAMDISK_KERNEL_MODULES := $(filter-out $(VENDOR_KERN_MODS),$(KERNEL_MODS))
+
+# Inherit the full_base and device configurations
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
+$(call inherit-product, device/generic/sdm845/sdm845/device.mk)
+$(call inherit-product, device/generic/sdm845/device-common.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
+
+# Product overrides
+PRODUCT_NAME := sdm845
+PRODUCT_DEVICE := sdm845
+PRODUCT_BRAND := AOSP
diff --git a/sdm845/BoardConfig.mk b/sdm845/BoardConfig.mk
new file mode 100644
index 0000000..48e0d9d
--- /dev/null
+++ b/sdm845/BoardConfig.mk
@@ -0,0 +1,24 @@
+include device/generic/sdm845/BoardConfigCommon.mk
+
+# Copied from https://github.com/LineageOS/android_device_oneplus_sdm845-common/blob/lineage-16.0/BoardConfigCommon.mk
+# Board Information
+TARGET_BOOTLOADER_BOARD_NAME := sdm845
+TARGET_BOARD_PLATFORM := sdm845
+
+# Kernel/boot.img Configuration
+BOARD_KERNEL_BASE        := 0x00000000
+BOARD_KERNEL_PAGESIZE    := 4096
+BOARD_KERNEL_TAGS_OFFSET := 0x00000100
+BOARD_RAMDISK_OFFSET     := 0x01000000
+BOARD_KERNEL_CMDLINE     := earlycon earlyprintk console=ttyMSM0,115200n8 console=ttyGS0,115200 androidboot.console=ttyMSM0
+BOARD_KERNEL_CMDLINE     += androidboot.hardware=sdm845 androidboot.boot_devices=soc@0/1d84000.ufshc
+BOARD_KERNEL_CMDLINE     += firmware_class.path=/vendor/firmware/ init=/init printk.devkmsg=on
+BOARD_KERNEL_CMDLINE     += deferred_probe_timeout=0
+BOARD_KERNEL_CMDLINE     += fw_devlink=on selinux=0
+
+# Image Configuration
+BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864 #64M
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2998927360
+BOARD_USERDATAIMAGE_PARTITION_SIZE := 118112366592
+BOARD_VENDORIMAGE_PARTITION_SIZE := 536870912
+BOARD_FLASH_BLOCK_SIZE := 262144
diff --git a/sdm845/device.mk b/sdm845/device.mk
new file mode 100644
index 0000000..3349e9d
--- /dev/null
+++ b/sdm845/device.mk
@@ -0,0 +1,47 @@
+#
+# Copyright (C) 2011 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.
+#
+
+PRODUCT_SOONG_NAMESPACES += \
+    device/generic/sdm845
+
+# copied from crosshatch
+# setup dalvik vm configs
+$(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
+
+
+PRODUCT_COPY_FILES := \
+    $(LOCAL_PATH)/fstab.ramdisk:$(TARGET_COPY_OUT_RAMDISK)/fstab.sdm845 \
+    $(LOCAL_PATH)/fstab.ramdisk:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.sdm845 \
+    device/generic/sdm845/init.common.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.sdm845.rc \
+    device/generic/sdm845/init.common.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.sdm845.usb.rc \
+    device/generic/sdm845/common.kl:$(TARGET_COPY_OUT_VENDOR)/usr/keylayout/sdm845.kl
+
+# Build generic Audio HAL
+PRODUCT_PACKAGES := audio.primary.sdm845
+
+# Build generic lights HAL
+PRODUCT_PACKAGES += lights.sdm845
+
+PRODUCT_PACKAGES += \
+    pd-mapper \
+    qrtr-ns \
+    qrtr-cfg \
+    qrtr-lookup \
+    rmtfs \
+    tqftpserv
+
+PRODUCT_COPY_FILES += \
+    device/generic/sdm845/qcom/init.qcom.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.qcom.rc
diff --git a/sdm845/fstab.ramdisk b/sdm845/fstab.ramdisk
new file mode 100644
index 0000000..d9c6824
--- /dev/null
+++ b/sdm845/fstab.ramdisk
@@ -0,0 +1,6 @@
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/system_a /system ext4 noatime,ro,errors=panic wait,first_stage_mount
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/vendor_a /vendor ext4 noatime,ro,errors=panic wait,first_stage_mount
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/system /system ext4 noatime,ro,errors=panic wait,first_stage_mount
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/vendor /vendor ext4 noatime,ro,errors=panic wait,first_stage_mount
+/dev/block/platform/soc@0/1d84000.ufshc/by-name/userdata /data		ext4	discard,noatime,noauto_da_alloc,data=ordered,user_xattr,barrier=1	wait,formattable,quota
+/devices/platform/soc@0/8804000.sdhci/mmc_host/mmc*	auto	auto	defaults	voldmanaged=sdcard1:auto