robotnix
robotnix copied to clipboard
twrp: Initial basic support for TWRP builds
Read the commits.
TLDR:
- builds a recovery.img
- ~~on a limited sample size of one device tree, not even known working, does not work~~
- Known to work with limited scope
I guess next steps could be:
- ~~Build with a known working device tree~~ done by @danielfullmer
I don't know if I'll get back to this. It was mostly done so I could try and build the output of the TWRP Device Tree Generator thing, and it ended up not working for the device I tried it with.
Known issues
- Only cares for twrp-9.0 (android 9.0) TWRP
- No handling of device trees; "BYODT", or bring your own DT...
Reading material
- TWRP device tree generator
- Official TWRP compilation guide
- Unofficial thread with conflicting/weird info
That last thread with weird info has this bit:
Before doing the repo sync, we will need a few extra repositories to be downloaded. Create a subfolder .repo/local_manifests and create an XML file (e.g. custom.xml) with the following content:
and
Additionally, we will need some driver binaries that are available from Google. Get the Google (Qcom is not necessary) drivers for the latest Pie release here:
So according to this old, yet updated thread, it looks like it's not turn-key. There may be some manual stuff to do to have upstream trees built.
Sample known working config
#
# Usage
# =====
#
# ```
# $ nix-build --arg configuration ./sofiar-twrp.nix -A config.build.twrp
# ```
#
{ config, pkgs, lib, ... }:
let
inherit (pkgs) fetchFromGitHub;
in
{
device = "sofiar";
androidVersion = 10;
flavor = "twrp";
source.dirs = {
"kernel/motorola/trinket" = {
src = fetchFromGitHub {
owner = "moto-sm6xxx";
repo = "android_kernel_motorola_trinket";
rev = "dc06278614038a6569650168dd1099f48fae1ebe";
sha256 = "0pmls0nxlmb2jbfxngpkdw2i20rrxjq7an8qar8cidhf10sk4mvj";
};
};
"device/motorola/sofiar" = {
src = fetchFromGitHub {
owner = "moto-sm6xxx";
repo = "android_device_motorola_sofiar";
rev = "ece39f82849b3e50b0a1ebbdc689265abeb7b6e0";
sha256 = "1x0g63h4ar7zf6dspz339qri7hkxsgzb45h26xk45g48c1sv5wzm";
};
};
};
}
I've just tried this out and I've got it working on marlin
(Pixel 1 XL) with the following configuration:
{ pkgs, ... }:
{
flavor = "twrp";
device = "marlin";
# At least marlin needs this... https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni/issues/33
envVars.ALLOW_MISSING_DEPENDENCIES = "true";
# https://forum.xda-developers.com/t/how-to-building-twrp-from-source-with-goodies.4029449/
source.dirs."device/google/marlin".src = pkgs.fetchFromGitHub {
owner = "TeamWin";
repo = "android_device_google_marlin";
rev = "72c4888ced18ffdbff962a3916cbd2a830f4c1ef";
sha256 = "06lf0p8gcm5ixsn08j54k79v55g1akaliyvjsws0v947kb4cs9md";
};
source.dirs."hardware/qcom/bootctrl".src = pkgs.fetchgit {
url = "https://android.googlesource.com/platform/hardware/qcom/bootctrl";
rev = "android-9.0.0_r61";
sha256 = "0zm2kqxk7pbn5ihbx3gz0w9ss28qjaxrcfcfx6s4l8gnn0afzk0j";
};
source.dirs."hardware/qcom/msm8998".src = pkgs.fetchgit {
url = "https://android.googlesource.com/platform/hardware/qcom/msm8998";
rev = "android-9.0.0_r61";
sha256 = "0qr2mjqwg947hlwvgy511ay4acziyclxz1l52dg2vgsndqhb9hmr";
};
Built with: nix-build --arg configuration ./marlin-twrp.nix -A config.build.twrp
As @samueldr mentioned in the earlier comment, marlin
is an A/B device and so I had to change the makeTarget
to bootimage
.
BTW, I don't have plans to continue working on this branch in the close future.
Looks like my main goal (a cheap way to make a TWRP build for unsupported devices) didn't work on a sample size of 1.
But, as @danielfullmer observed, it's not far from working properly! So if anyone wants to take over and finish the work (in a fresh PR) feel free to do it.
I have verified with motorola-rav
(Moto g(8)) that this can work.
I'm not sure what should be done about device trees.
The initial PR body has been updated, with a permanent spot for another known good config.
It seems some magic here fails with the twrp-9.0
branch.
Testing with marlin
(and the XXX commit with debug logs):
building '/nix/store/rf1ps97gdbcnxibmxbhy6mlgaxx4nmgl-unpack.sh.drv'...
building '/nix/store/c8dk1j6szv0isdjgflpz2vnsxmn65692-robotnix-omni_marlin-2021032423.drv'...
unpacking sources
$ mkdir -p android
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/gixn28fa6d85pjmcnzq3ryqq9dvygwlq-android-1746d4b android
$ mkdir -p art
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/z0bbwhf0waqwp40kbz301jghbhg4hwyf-android_art-3d61eee art
$ mkdir -p bionic
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/mnlimm01sr3bdajswfimjj435ppqiwkl-android_bionic-37066b6 bionic
$ mkdir -p bootable/recovery
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/i93n87djkszkfrnqmdlg82nadvqw5cw3-bootable=recovery-patched bootable/recovery
$ mkdir -p build/blueprint
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/47ypsm4c6pr1anlzrsjs52fx02bldrrs-blueprint build/blueprint
$ mkdir -p build/kati
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/7273csr2j47sns9m1pkf1yavpym3m8vi-kati build/kati
$ mkdir -p build/make
$ /nix/store/87l7q3bw5lr52hyl48sr0s8kavi13lf9-util-linux-2.36.2-bin/bin/mount --bind /nix/store/yz7k3l5rcm6ik8j7zmr8vgkfmga0cd45-build=make-patched build/make
$ dirname Makefile
$ mkdir -p .
$ cp --reflink=auto -f build/make/core/root.mk Makefile
$ dirname Makefile
$ mkdir -p .
$ cp --reflink=auto -f build/make/core/root.mk Makefile
$ dirname build/CleanSpec.mk
$ mkdir -p build
$ ln -sf --relative build/make/CleanSpec.mk build/CleanSpec.mk
$ dirname build/buildspec.mk.default
$ mkdir -p build
$ ln -sf --relative build/make/buildspec.mk.default build/buildspec.mk.default
$ dirname build/core
$ mkdir -p build
$ ln -sf --relative build/make/core build/core
$ dirname build/envsetup.sh
$ mkdir -p build
$ ln -sf --relative build/make/envsetup.sh build/envsetup.sh
$ dirname build/target
$ mkdir -p build
$ ln -sf --relative build/make/target build/target
$ dirname build/tools
$ mkdir -p build
$ ln -sf --relative build/make/tools build/tools
$ dirname build/CleanSpec.mk
$ mkdir -p build
$ ln -sf --relative build/make/CleanSpec.mk build/CleanSpec.mk
$ dirname build/buildspec.mk.default
$ mkdir -p build
$ ln -sf --relative build/make/buildspec.mk.default build/buildspec.mk.default
$ dirname build/core
$ mkdir -p build
$ ln -sf --relative build/make/core build/core
ln: failed to create symbolic link 'build/core/core': Permission denied
twrp-9.0
branch verified to still produce a working TWRP for marlin (tested on sailfish).
(surfna
produced from twrpdtgen still doesn't work, but eh...)
(Suprisingly) working config for cheeseburger:
# SPDX-FileCopyrightText: 2022 Atemu
# SPDX-FileCopyrightText: 2021 Daniel Fullmer and robotnix contributors
# SPDX-License-Identifier: MIT
#
# Usage
# =====
#
# ```
# $ nix-build --arg configuration ./cheeseburger-twrp.nix -A config.build.twrp
# ```
#
{ pkgs, ... }:
{
device = "cheeseburger_dumpling";
androidVersion = 9;
flavor = "twrp";
envVars.ALLOW_MISSING_DEPENDENCIES = "true";
source.dirs = {
"device/oneplus/cheeseburger_dumpling" = {
src = pkgs.fetchFromGitHub {
owner = "TeamWin";
repo = "android_device_oneplus_cheeseburger_dumpling";
rev = "61f577680c941ca7c1e601105cad4c21cdc2fac9";
sha256 = "sha256-i+87wxWAqvnZOtDeiH1+fnvrjqMIedolbKNcS8S5lZ4=";
};
};
};
}
Also works for an unsupported device ... in case it helps anyone else.
{ pkgs, ... }:
{
device = "togari";
androidVersion = 9;
flavor = "twrp";
envVars.ALLOW_MISSING_DEPENDENCIES = "true";
source.dirs = {
"device/sony/togari" = {
src = pkgs.fetchFromGitHub {
owner = "sony-togari-dev";
repo = "android_device_sony_togari-twrp";
rev = "android-9.0";
sha256 = "sha256-6j3ZRKL+gaBtX2jP0MYr6ktbO6cmqlc9uZmnH2RIct4=";
};
};
"kernel/sony/msm8974" = {
src = pkgs.fetchFromGitHub {
owner = "sony-togari-dev";
repo = "android_kernel_sony_msm8974";
rev = "lineage-18.1";
sha256 = "sha256-KXOF7f3B73OjSC6ABiT7EQ6/RzK3DB5ywzEHn8B9P88=";
};
};
};
}