mt8163 / android_device_amazon_karnak_old

Android device tree for the Amazon Fire HD8 2018
GNU General Public License v2.0
9 stars 0 forks source link

Bluetooth address appears to be hard coded / help building. #24

Closed ladar closed 1 year ago

ladar commented 2 years ago

I had trouble getting two karnak tablets to connect with each other. I don't know if the value being reported by the settings app is accurate, but both devices appeared to showed the same address. Both devices discovered each other just fine, but would repeated fail to pair with each other.

@488315 / @R0rt1z2 can either of you provide the secret sauce needed to build a bootable karnak ROM? The topic came up on XDA, where I also reported this issue.

It might help to have a starting point:

#!/bin/bash -e
# Monitor the output.
# bash -i -c 'tput setab 1 ; tail -F $HOME/android-build.log ' ; tput sgr0
cd $HOME && rm -rf device_manifest.xml android-build.log .gitconfig .repo_.gitconfig.json .repoconfig/ .gnupg/ .cache/ android/ cache/ temp/ && sudo sync
mkdir -p $HOME/temp && mkdir -p $HOME/cache && mkdir -p $HOME/android/lineage
cat <<-EOF > $HOME/device_manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
   <!-- Device Tree -->
   <project name="mt8163/android_device_amazon_karnak" path="device/amazon/karnak" remote="github" revision="lineage-18.1"/>

   <!-- Kernel sources -->
   <project name="mt8163/android_kernel_amazon_karnak_4.9" path="kernel/amazon/karnak" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_kernel_mediatek_mt8163_4.9" path="kernel/mediatek/mt8163/4.9" remote="github" revision="lineage-17.1"/>

   <!-- Vendor trees -->
   <project name="mt8163/android_vendor_amazon_karnak" path="vendor/amazon/karnak" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_vendor_amazon_mt8163" path="vendor/amazon/mt8163" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_vendor_raffy" path="vendor/raffy" remote="github" revision="lineage-18.1"/>
</manifest>
EOF
cd $HOME/android/lineage
git config --global user.name "Ladar Levison"
git config --global user.email "ladar@lavabit.com"
git config --global color.ui false
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

export LANG=en_US.UTF-8
export VENDOR=amazon
export DEVICE=karnak
export BRANCH=lineage-18.1
export TMPDIR="$HOME/temp"
export USE_CCACHE=1
export CCACHE_COMPRESS=1
export BUILD_UUID=$(uuidgen)
export CCACHE_DIR="$HOME/cache"
export ANDROID_QUIET_BUILD=true
export BUILDSTAMP=`date --utc +'%Y%m%d'`
export CCACHE_EXEC="prebuilts/misc/linux-x86/ccache/ccache"
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8G"
# export OVERRIDE_TARGET_FLATTEN_APEX=true
# export ANDROID_JACK_EXTRA_ARGS="--verbose debug --sanity-checks on -D sched.runner=single-threaded"
repo init -u git://github.com/LineageOS/android.git -b lineage-18.1
mkdir -p .repo/local_manifests/
mv $HOME/device_manifest.xml .repo/local_manifests/device_manifest.xml
repo sync --jobs=32 --current-branch --no-clone-bundle --no-tags || exit 1

# GCC 7.5.0
mkdir -p prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu/
curl -Lo $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
echo "3b6465fb91564b54bbdf9578b4cc3aa198dd363f7a43820eab06ea2932c8e0bf  $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz" | sha256sum -c || exit 1
tar -x -J --strip-components=1 -C prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu/ -f $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz
rm -f $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz

sed -i 's/const const struct/const struct/g' kernel/amazon/karnak/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
sed -i 's/CONFIG_FRAME_WARN=1500/CONFIG_FRAME_WARN=1520/g' kernel/amazon/karnak/arch/arm64/configs/lineageos_karnak_defconfig
sed -i 's/CONFIG_FRAME_WARN,COMMON,,,1500,1500,1500,1500,1500,1500/CONFIG_FRAME_WARN,COMMON,,,1520,1520,1520,1520,1520,1520/g' kernel/amazon/karnak/scripts/kcrs/correct_config.csv

#####
# export PYTHONDONTWRITEBYTECODE=true
# export BUILD_ENFORCE_SELINUX=1
# export OVERRIDE_TARGET_FLATTEN_APEX=true 
# # convert this to a runtime check, grep "sse4_2.*popcnt" /proc/cpuinfo
# export CPU_SSE42=false
#####

# Set the output label.
LINEAGE_BUILDTYPE="UPSTREAM"

source build/envsetup.sh
if [ ! -x "$CCACHE_EXEC" ]; then
  export CCACHE_EXEC="$(which ccache)"
fi
"$CCACHE_EXEC" -M 20G

croot
rm -rf out
set +e

printf "Breakfast starting.\n" | tee -a $HOME/android-build.log

breakfast karnak &>> $HOME/android-build.log
if [[ "$TARGET_PRODUCT" != lineage_* ]]; then
  printf "\n\nBuild karnak failed. (breakfast)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Lunch starting.\n" | tee -a $HOME/android-build.log

lunch lineage_karnak-userdebug &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (lunch)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Build starting.\n" | tee -a $HOME/android-build.log

cmka &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (cmka)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Dist starting.\n" | tee -a $HOME/android-build.log

mka otatools-package target-files-package dist &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (dist)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Finished.\n" | tee -a $HOME/android-build.log
R0rt1z2 commented 2 years ago

I had trouble getting two karnak tablets to connect with each other. I don't know if the value being reported by the settings app is accurate, but both devices appeared to showed the same address. Both devices discovered each other just fine, but would repeated fail to pair with each other.

@488315 / @R0rt1z2 can either of you provide the secret sauce needed to build a bootable karnak ROM? The topic came up on XDA, where I also reported this issue.

It might help to have a starting point:

#!/bin/bash -e
# Monitor the output.
# bash -i -c 'tput setab 1 ; tail -F $HOME/android-build.log ' ; tput sgr0
cd $HOME && rm -rf device_manifest.xml android-build.log .gitconfig .repo_.gitconfig.json .repoconfig/ .gnupg/ .cache/ android/ cache/ temp/ && sudo sync
mkdir -p $HOME/temp && mkdir -p $HOME/cache && mkdir -p $HOME/android/lineage
cat <<-EOF > $HOME/device_manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
   <!-- Device Tree -->
   <project name="mt8163/android_device_amazon_karnak" path="device/amazon/karnak" remote="github" revision="lineage-18.1"/>

   <!-- Kernel sources -->
   <project name="mt8163/android_kernel_amazon_karnak_4.9" path="kernel/amazon/karnak" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_kernel_mediatek_mt8163_4.9" path="kernel/mediatek/mt8163/4.9" remote="github" revision="lineage-17.1"/>

   <!-- Vendor trees -->
   <project name="mt8163/android_vendor_amazon_karnak" path="vendor/amazon/karnak" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_vendor_amazon_mt8163" path="vendor/amazon/mt8163" remote="github" revision="lineage-18.1"/>
   <project name="mt8163/android_vendor_raffy" path="vendor/raffy" remote="github" revision="lineage-18.1"/>
</manifest>
EOF
cd $HOME/android/lineage
git config --global user.name "Ladar Levison"
git config --global user.email "ladar@lavabit.com"
git config --global color.ui false
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

export LANG=en_US.UTF-8
export VENDOR=amazon
export DEVICE=karnak
export BRANCH=lineage-18.1
export TMPDIR="$HOME/temp"
export USE_CCACHE=1
export CCACHE_COMPRESS=1
export BUILD_UUID=$(uuidgen)
export CCACHE_DIR="$HOME/cache"
export ANDROID_QUIET_BUILD=true
export BUILDSTAMP=`date --utc +'%Y%m%d'`
export CCACHE_EXEC="prebuilts/misc/linux-x86/ccache/ccache"
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8G"
# export OVERRIDE_TARGET_FLATTEN_APEX=true
# export ANDROID_JACK_EXTRA_ARGS="--verbose debug --sanity-checks on -D sched.runner=single-threaded"
repo init -u git://github.com/LineageOS/android.git -b lineage-18.1
mkdir -p .repo/local_manifests/
mv $HOME/device_manifest.xml .repo/local_manifests/device_manifest.xml
repo sync --jobs=32 --current-branch --no-clone-bundle --no-tags || exit 1

# GCC 7.5.0
mkdir -p prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu/
curl -Lo $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
echo "3b6465fb91564b54bbdf9578b4cc3aa198dd363f7a43820eab06ea2932c8e0bf  $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz" | sha256sum -c || exit 1
tar -x -J --strip-components=1 -C prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu/ -f $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz
rm -f $HOME/gcc-linaro-7.5.0-x86_64_aarch64-linux-gnu.tar.xz

sed -i 's/const const struct/const struct/g' kernel/amazon/karnak/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
sed -i 's/CONFIG_FRAME_WARN=1500/CONFIG_FRAME_WARN=1520/g' kernel/amazon/karnak/arch/arm64/configs/lineageos_karnak_defconfig
sed -i 's/CONFIG_FRAME_WARN,COMMON,,,1500,1500,1500,1500,1500,1500/CONFIG_FRAME_WARN,COMMON,,,1520,1520,1520,1520,1520,1520/g' kernel/amazon/karnak/scripts/kcrs/correct_config.csv

#####
# export PYTHONDONTWRITEBYTECODE=true
# export BUILD_ENFORCE_SELINUX=1
# export OVERRIDE_TARGET_FLATTEN_APEX=true 
# # convert this to a runtime check, grep "sse4_2.*popcnt" /proc/cpuinfo
# export CPU_SSE42=false
#####

# Set the output label.
LINEAGE_BUILDTYPE="UPSTREAM"

source build/envsetup.sh
if [ ! -x "$CCACHE_EXEC" ]; then
  export CCACHE_EXEC="$(which ccache)"
fi
"$CCACHE_EXEC" -M 20G

croot
rm -rf out
set +e

printf "Breakfast starting.\n" | tee -a $HOME/android-build.log

breakfast karnak &>> $HOME/android-build.log
if [[ "$TARGET_PRODUCT" != lineage_* ]]; then
  printf "\n\nBuild karnak failed. (breakfast)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Lunch starting.\n" | tee -a $HOME/android-build.log

lunch lineage_karnak-userdebug &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (lunch)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Build starting.\n" | tee -a $HOME/android-build.log

cmka &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (cmka)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Dist starting.\n" | tee -a $HOME/android-build.log

mka otatools-package target-files-package dist &>> $HOME/android-build.log
if [[ "$?" != "0" ]]; then
  printf "\n\nBuild karnak failed. (dist)\n\n\n" | tee -a $HOME/android-build.log
  exit 1
fi

printf "Finished.\n" | tee -a $HOME/android-build.log

That's weird,

Besides the bluetooth problem, is everything else working fine? If so, I guess there is something wrong with the mediatek bluetooth library.

I'm not sure how accurate the bluetooth settings are when it comes to the mac address, but I guess you could try to check the address stored in boot1 (idme)

Can you check the contents of /proc/idme/bt_mac_addr (alternatively, you can use the idme print bt_mac_addr command in the ADB shell) on both tablets and see if they are the same?

ladar commented 2 years ago

Besides the bluetooth problem, is everything else working fine?

I bought them in December, setup them up in January, and used them a bit in February, but haven't really had a need, or time to revisit since.

I have several douglas tablets, and several karnaks, and two suez tablets. I originally bought them to use as low power SSH servers. And in that role they've been great. I have 2 douglas, and 2 karnks setup with Termux + OpenSSHD, and they stay pretty busy running my bash scripts. Occasionally they make noise when I need to look at something. They've also been great as load generators, when I needed that, and for testing my Android VPN app, as each device can use a different config/server node and/or service provider. Having separate physical devices for this type of testing makes it much easier.

And having 2 devices using a ROM based off Android 11, and 2 devices using a ROM based off Android 8.1 is useful. I haven't needed to use the 14.1 / 12.1 ROMs for suez all that much, or the older ROMs for douglas/karnak yet, as I have other devices with versions of Android. But having that option is nice.

Anyways this went so well, that I decided to buy several more karnak devices. I was planning to use them each for a different purpose. Like one as an IoT remote control for the smart vacuum, bulbs, etc. And use others to handle specific apps/tasks.

So far that's gone reasonably well. When I went abroad last month I setup several for different tasks because I didn't want to bring my primary devices on this trip. That was when I notice the BT issue, but didn't have my computer with me, or my GH password to report it back.

As for other issues. I didn't realize when I bought the extra karnak devices that they were using the 32 bit ABI. Hence the work on my own builds using the 64 ABI. I can compile things just fine at this point, I've been having trouble getting the 32 bit and 64 bit ROMs to boot, which makes me thing I'm not building them right. Any suggestions?

I haven't loaded any of the douglas ROMs I compiled onto devices yet, so I dont know if that's an issue yet.

As for other "issues" ... I did a lot of bench marking when I realized the ABI difference. The karnak devices are actually about 20% slower, despite having an identical CPU. The UI does feel slightly more sluggish, but looks nicer. And I had hoped they would be useful for a long time into the future with Android 11.

In terms of bugs, the karnak is pretending to be a Pixel. I assume that is on purpose.

And in terms of functionality, I tried to setup full disk encryption on one of the karnak devices before I went abroad. It seemed like the encryption process went fine, so I rebooted, and wasn't able to get it to decrypt/boot. I went into recovery mode, and TWRP saw the encryption, but also couldn't decrypt it.

The one caveat. I was using a pattern as my screen lock/decrypt key. I haven't had time to retry using a different type of lock, like the more common pin/passphrase yet.

That is a bit of an issue, since I was planning to dedicate one of the devices to being a semi-offline crypto wallet.

If so, I guess there is something wrong with the mediatek bluetooth library.

I'm not sure how accurate the bluetooth settings are when it comes to the mac address, but I guess you could try to check the address stored in boot1 (idme)

Can you check the contents of /proc/idme/bt_mac_addr (alternatively, you can use the idme print bt_mac_addr command in the ADB shell) on both tablets and see if they are the same?

Yes, I definitely CAN. The hard part will be remember to when I get home. I don't find myself connected directly to those tablets very often. In fact I can't recall cnnecting viia ADB since I unlocked the boot loader. Not counting my attempts to troubleshooting the non booting ROMs, since they were loaded off USB sticks via TWRP, and I wasn't able to connect up via fastboot or adb after that.

Hopefully I can pull what you need using over SSH, if I can hit those paths via the Termux shell.

I also want to try searching the fully checked out source code for address it shows on the settings screen. I think it was all 0s, except for something like 4 octets, which were set to F (I think). It just looked like something a developer would hard code.

P.S. @srccrow is also trying to build his own ROM.

ladar commented 2 years ago

Can you check the contents of /proc/idme/bt_mac_addr (alternatively, you can use the idme print bt_mac_addr command in the ADB shell) on both tablets and see if they are the same?

@R0rt1z2 I did a little bit of testing. I was able to pair with other devices and send files, so it seems the issue only comes into play when two karnaks are involved.

So I checked the address, and see the screenshots below, settings shows 00:00:46:00:00:01 as the BT address, which is also the address my computer is seeing when paired.

The idme value in the proc file system that you suggested checking is completely different.

Settings

Paired

Idme

ladar commented 2 years ago

The only two problematics things are the codecs, and the kernel so far.

From what I saw it plays youtube fine, but not other things, so I guess that or the source miss something or the OMX should be fixed again on a future new build.

For the kernel it compiled fine with the sed -i you given, but it doesn't boot, using the old one boots fine.

The offers HW assisted decoding, for H264, to play video. As I recall from my own testing, the CPU isn't fastest enough to do H265 without HW acceleration (few mobile ARM processors are).

I also recall, there is a vendor lib/drover that gets installed during the build to facilitate offloading video decoding to the HW, and it has an /etc/ config file.

If we can figure out how to build our own ROMs it may be what needs tweaking/fixing.

@R0rt1z2 were you ever able to compile a bootable ROM for the karnak? @488315 / KaiJones hasn't been very active on XDA or GH as of late, so I'm hoping he isn't the only one to know what's needed?

@srccrow while we wait, have you tried swapping out the toolchain in the script I sent you? You might have better luck with a different version, like 4.9.0.

R0rt1z2 commented 2 years ago

Can you check the contents of /proc/idme/bt_mac_addr (alternatively, you can use the idme print bt_mac_addr command in the ADB shell) on both tablets and see if they are the same?

@R0rt1z2 I did a little bit of testing. I was able to pair with other devices and send files, so it seems the issue only comes into play when two karnaks are involved.

So I checked the address, and see the screenshots below, settings shows 00:00:46:00:00:01 as the BT address, which is also the address my computer is seeing when paired.

The idme value in the proc file system that you suggested checking is completely different.

I see, that confirms my theory about the bluetooth library.

I guess the library expects the address to be somewhere else and fallbacks to some sort of default (or randomly generated) address, which in this case is 00:00:46:00:00:00:00:01.

If that's the case, I guess we'll have to include some sort of helper that reads and sanitizes the format of the actual address from /proc/idme.

According to your screenshot, the actual address of that karnak is 5C:41:5A:69:56:A9. I'm not sure if this will make a difference, but you can try writing your real bluetooth MAC address to /data/vendor/bluetooth/macbt and setting the ro.bt.bdaddr_path property to that path. To make the changes persistent across reboots, write the property to /vendor/build.prop.

mount -o rw,remount /vendor
mkdir -p /data/vendor/bluedroid
chmod 0771 /data/vendor/bluedroid
chown bluetooth:bluetooth /data/vendor/bluedroid
echo "5C:41:5A:69:56:A9" > /data/vendor/bluedroid/macbt
echo "ro.bt.bdaddr_path=/data/vendor/bluedroid/macbt" >> /vendor/build.prop

@R0rt1z2 were you ever able to compile a bootable ROM for the karnak? @488315 / KaiJones hasn't been very active on XDA or GH as of late, so I'm hoping he isn't the only one to know what's needed?

Unfortunately I don't have karnak and therefore I have never tried to build a ROM for it. However, from what I remember, the current sources were enough to build a bootable ROM (with the bugs described in the XDA thread, of course). So yes, unless the main developer has changed something, you shouldn't need any special hacks or anything like that.

As for Kai, I think he's busy with life and he's taking an (indefinite) break from development, but I'll talk to him.

ladar commented 2 years ago

According to your screenshot, the actual address of that karnak is 5C:41:5A:69:56:A9. I'm not sure if this will make a difference, but you can try writing your real bluetooth MAC address to /data/vendor/bluetooth/macbt and setting the ro.bt.bdaddr_path property to that path. To make the changes persistent across reboots, write the property to /vendor/build.prop.

Thanks for the tip. I'll see if this works later and report back, unless @srccrow is able to test it before me...? I don't have the USB cable I'd need for ADB access at the moment.

Unfortunately I don't have karnak and therefore I have never tried to build a ROM for it. However, from what I remember, the current sources were enough to build a bootable ROM (with the bugs described in the XDA thread, of course). So yes, unless the main developer has changed something, you shouldn't need any special hacks or anything like that.

I've mostly worked with official Lineage devices in the past, and while I've built ROMs for lots of different deivces at this point, the only ones I really modified, and used were for a pretty old device.

As such, I wasn't sure if something special, or different is now required to a generate bootable ROM, given the newer version of Android/Lineage? I haven't worked much with devices which didn't have official Lineage support, so I don't know the conventions.

For the karnak build, I had to manually the Linaro toolchain, since the toolchain bundled with Android/Lineage didn't appear to work.

I guessed that it was the Linaro toolchain based on some of the path/executable references, but have no idea which version Kai might have used, or even if my guess regarding Linaro was right? Plus within the same version of the Linaro toolchain, there seemed to be multiple toolchain variants. I was hoping you might have some insight on what he might have used, and where to download it/set it up?

Also, are there any Android "make" commands that we should be using? My script was originally developed for a device running Lineage 14.1, so perhaps I'm not signing/preparing the ROM/kernel properly? To make things even more complicated, karnaks use a boot loader exploit, so I didn't know if something special, that isn't part of the standard Android/Lineage code base, is needed?

As for Kai, I think he's busy with life and he's taking an (indefinite) break from development, but I'll talk to him.

I can appreciate that! And I don't want to bug him. but I'm starting to thnk he didn't commit/push all of his code changes. Or perhaps there is some other secret build fu that he never posted online (at least anywhere I could find)?

So I'm hoping you know what we're missing, but if you don't, I'm hoping you can get word to him, and can convince him to share his magic with us -- before he rides off into the sunset?

@R0rt1z2 speaking of which, this is the build script I created for douglas devices. I know it was generating ROMs, but I never tried loading any of them onto a device. Any suggestions for improvement? Note, I combined my script with the upstream variant (that uses your repos), and set it up to switch between the two using an environment variable before posting. Hopefully it works, but figured that was far more streamlined and two, almost identical scripts. Your welcome to repost this script to your repos if you think it will help. It's designed to work with the Vagrant virtual machine images I maintain for building Lineage.

#!/bin/bash -e
# Monitor the output.
# bash -i -c 'tput setab 1 ; tail -F $HOME/android-build.log ' ; tput sgr0

# Use "UPSTREAM" for the original douglas code repositories, and "CRAPTASTIC" for the alternative.
# export LINEAGE_BUILDTYPE="UPSTREAM"
export LINEAGE_BUILDTYPE="CRAPTASTIC"

# Cleanup and reset the environment between build attempts.
cd $HOME && rm -rf linaro_manifest.xml device_manifest.xml upstream_manifest.xml craptastic_manifest.xml android-build.log .gitconfig .repo_.gitconfig.json .repoconfig/ .gnupg/ .cache/ android/ cache/ temp/ && sudo sync
mkdir -p $HOME/temp && mkdir -p $HOME/cache && mkdir -p $HOME/android/lineage

# The two manifests.
cat <<-EOF > $HOME/craptastic_manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
   <!-- Device Tree -->
   <project name="craptastic-droids/android_device_amazon_douglas" path="device/amazon/douglas" remote="github" revision="lineage-15.1"/>
   <project name="craptastic-droids/android_device_amazon_mt8163-common" path="device/amazon/mt8163-common" remote="github" revision="lineage-15.1"/>

   <!-- Kernel sources -->
   <project name="craptastic-droids/android_kernel_amazon_giza_douglas" path="kernel/amazon/mt8163" remote="github" revision="lineage-15.1"/>

   <!-- Vendor trees -->
   <project name="craptastic-droids/android_vendor_amazon_mt8163-common" path="vendor/amazon/mt8163-common" remote="github" revision="lineage-15.1"/>
   <project name="craptastic-droids/android_vendor_amazon_douglas" path="vendor/amazon/douglas" remote="github" revision="lineage-15.1"/>
</manifest>
EOF
cat <<-EOF > $HOME/upstream_manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
   <!-- Device Trees -->
   <project name="mt8163-dev/android_device_amazon_douglas" path="device/amazon/douglas" remote="github" revision="lineage-15.1"/>
   <project name="mt8163-dev/android_device_amazon_mt8163-common" path="device/amazon/mt8163-common" remote="github" revision="lineage-15.1"/>

   <!-- Kernel Sources -->
   <project name="mt8163-dev/android_kernel_amazon_mt8163" path="kernel/amazon/mt8163" remote="github" revision="lineage-15.1"/>

   <!-- Vendor Trees -->
   <project name="mt8163-dev/android_vendor_amazon_mt8163-common" path="vendor/amazon/mt8163-common" remote="github" revision="lineage-15.1"/>
   <project name="mt8163-dev/android_vendor_amazon_douglas" path="vendor/amazon/douglas" remote="github" revision="lineage-15.1"/>
</manifest>
EOF

cd $HOME/android/lineage
git config --global user.name "Ladar Levison"
git config --global user.email "ladar@lavabit.com"
git config --global color.ui false
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

export LANG=en_US.UTF-8
export VENDOR=amazon
export DEVICE=douglas
export BRANCH=lineage-15.1
export TMPDIR="$HOME/temp"
export USE_CCACHE=1
export CCACHE_COMPRESS=1
export BUILD_UUID=$(uuidgen)
export CCACHE_DIR="$HOME/cache"
# export ANDROID_QUIET_BUILD=true
export BUILDSTAMP=`date --utc +'%Y%m%d'`
export CCACHE_EXEC="prebuilts/misc/linux-x86/ccache/ccache"
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8G"
# export ANDROID_JACK_EXTRA_ARGS="--verbose debug --sanity-checks on -D sched.runner=single-threaded"

#####
export PYTHONDONTWRITEBYTECODE=true
export BUILD_ENFORCE_SELINUX=1
# Convert this to a runtime check somehow: grep "sse4_2.*popcnt" /proc/cpuinfo
export CPU_SSE42=false
#####

# Only applies to Android 10+
# export OVERRIDE_TARGET_FLATTEN_APEX=true 

repo init -u git://github.com/LineageOS/android.git -b lineage-15.1
mkdir -p .repo/local_manifests/
cp "$HOME/$(echo $LINEAGE_BUILDTYPE | tr "[:upper:]" "[:lower:]")_manifest.xml" .repo/local_manifests/device_manifest.xml
repo sync --jobs=32 --current-branch --no-clone-bundle --no-tags || exit 1

source build/envsetup.sh
if [ ! -x "$CCACHE_EXEC" ]; then
  export CCACHE_EXEC="$(which ccache)"
fi
"$CCACHE_EXEC" -M 20G

croot
rm -rf out
( breakfast $DEVICE 2>&1 | tee -a $HOME/android-build.log ) || { printf "\n\n\nBuild failed. (breakfast)\n\n\n"; exit 1 }
sudo updatedb &

# <!-- Remove Default projects -->
#  <remove-project path="hardware/qcom/audio-caf/msm8996" name="LineageOS/android_hardware_qcom_audio"/>
#  <remove-project path="hardware/qcom/display-caf/msm8996" name="LineageOS/android_hardware_qcom_display"/>
#  <remove-project path="hardware/qcom/media-caf/msm8996" name="LineageOS/android_hardware_qcom_media"/>
# git clone https://github.com/LineageOS/android_device_qcom_common.git -b lineage-15.1 device/qcom/common

croot
( brunch $DEVICE 2>&1 | tee -a $HOME/android-build.log ) || { printf "\n\n\nBuild failed. (brunch)\n\n\n"; exit 1 }
# mka otatools-package target-files-package dist 2>&1 | tee -a $HOME/android-build.log
derSascha commented 1 year ago

were you ever able to compile a bootable ROM for the karnak?

Yes! Running a build using the 18.1 branch, and created a fresh build today. My .repo/local_manifests/manifest.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
    <!-- Sync local_manifest on each repo sync-->
    <!-- project name="mt8163/local_manifests" path=".repo/local_manifests" remote="github" revision="lineage-18.1"/ -->

    <!-- Device Tree -->
    <project name="mt8163/android_device_amazon_karnak" path="device/amazon/karnak" remote="github" revision="lineage-18.1"/>

    <!-- prebuilds -->
    <project name="LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-gnu-6.4.1" path="prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu" remote="github" revision="lineage-18.1"/>
    <!--
    <project name="LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9" path="prebuilts/linaro/linux-x86/aarch64/aarch64-linux-gnu" remote="github" revision="lineage-18.1"/>
    -->

    <!-- Kernel sources -->
    <project name="mt8163/android_kernel_amazon_karnak_4.9" path="kernel/amazon/karnak" remote="github" revision="lineage-18.1"/>
    <!--
    <project name="mt8163/android_kernel_mediatek_mt8163_4.9" path="kernel/mediatek/mt8163/4.9" remote="github" revision="lineage-18.1"/>
    -->

    <!-- Vendor trees -->
    <project name="mt8163/android_vendor_amazon_karnak" path="vendor/amazon/karnak" remote="github" revision="lineage-18.1"/>
    <project name="mt8163/android_vendor_amazon_mt8163" path="vendor/amazon/mt8163" remote="github" revision="lineage-18.1"/>
    <project name="mt8163/android_vendor_raffy" path="vendor/raffy" remote="github" revision="lineage-18.1"/>
</manifest>

The mentioned fix from above works like a charm and fixed the bluetooth problem on my tablet:

mount -o rw,remount /vendor
mkdir -p /data/vendor/bluedroid
chmod 0771 /data/vendor/bluedroid
chown bluetooth:bluetooth /data/vendor/bluedroid
sed -e 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/g' < /proc/idme/bt_mac_addr > /data/vendor/bluedroid/macbt
echo "ro.bt.bdaddr_path=/data/vendor/bluedroid/macbt" >> /vendor/build.prop
giovEra commented 1 year ago

@derSascha, before compiling, did you apply the three patches to the kernel?

sed -i 's/const const struct/const struct/g' kernel/amazon/karnak/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
sed -i 's/CONFIG_FRAME_WARN=1500/CONFIG_FRAME_WARN=1520/g' kernel/amazon/karnak/arch/arm64/configs/lineageos_karnak_defconfig
sed -i 's/CONFIG_FRAME_WARN,COMMON,,,1500,1500,1500,1500,1500,1500/CONFIG_FRAME_WARN,COMMON,,,1520,1520,1520,1520,1520,1520/g' kernel/amazon/karnak/scripts/kcrs/correct_config.csv
488315 commented 1 year ago

@derSascha, before compiling, did you apply the three patches to the kernel?

sed -i 's/const const struct/const struct/g' kernel/amazon/karnak/drivers/pinctrl/mediatek/pinctrl-mtk-common.h
sed -i 's/CONFIG_FRAME_WARN=1500/CONFIG_FRAME_WARN=1520/g' kernel/amazon/karnak/arch/arm64/configs/lineageos_karnak_defconfig
sed -i 's/CONFIG_FRAME_WARN,COMMON,,,1500,1500,1500,1500,1500,1500/CONFIG_FRAME_WARN,COMMON,,,1520,1520,1520,1520,1520,1520/g' kernel/amazon/karnak/scripts/kcrs/correct_config.csv

I don't think there will be patches needed for the kernel.

488315 commented 1 year ago

I have several douglas tablets, and several karnaks, and two suez tablets. I originally bought them to use as low power SSH servers. And in that role they've been great. I have 2 douglas, and 2 karnks setup with Termux + OpenSSHD, and they stay pretty busy running my bash scripts. Occasionally they make noise when I need to look at something. They've also been great as load generators, when I needed that, and for testing my Android VPN app, as each device can use a different config/server node and/or service provider. Having separate physical devices for this type of testing makes it much easier.

And having 2 devices using a ROM based off Android 11, and 2 devices using a ROM based off Android 8.1 is useful. I haven't needed to use the 14.1 / 12.1 ROMs for suez all that much, or the older ROMs for douglas/karnak yet, as I have other devices with versions of Android. But having that option is nice.

Anyways this went so well, that I decided to buy several more karnak devices. I was planning to use them each for a different purpose. Like one as an IoT remote control for the smart vacuum, bulbs, etc. And use others to handle specific apps/tasks.

So far that's gone reasonably well. When I went abroad last month I setup several for different tasks because I didn't want to bring my primary devices on this trip. That was when I notice the BT issue, but didn't have my computer with me, or my GH password to report it back.

As for other issues. I didn't realize when I bought the extra karnak devices that they were using the 32 bit ABI. Hence the work on my own builds using the 64 ABI. I can compile things just fine at this point, I've been having trouble getting the 32 bit and 64 bit ROMs to boot, which makes me thing I'm not building them right. Any suggestions?

The issue is that the vendor, when amazon provides the system updates, only gave arm blobs for it. The kernel is 64-bit with 64-bit binder.

As for other "issues" ... I did a lot of benchmarking when I realized the ABI difference. The karnak devices are actually about 20% slower, despite having an identical CPU. The UI does feel slightly more sluggish, but looks nicer. And I had hoped they would be useful for a long time into the future with Android 11.

In terms of bugs, the karnak is pretending to be a Pixel. I assume that is on purpose. The reason why I put the pixel fingerprint is to attempt to bypass SafetyNet.

And in terms of functionality, I tried to setup full disk encryption on one of the karnak devices before I went abroad. It seemed like the encryption process went fine, so I rebooted, and wasn't able to get it to decrypt/boot. I went into recovery mode, and TWRP saw the encryption, but also couldn't decrypt it.

Right Now, Android 13 does not support userdata encryption at all but i will need to find a way to add some encryption support

I have released an Android 13 Build and do you mind running some tests on them?