Skip to content

Commit 9028e4a

Browse files
committed
Add partially working TWRP integration
Why partially working? No working build has been produced yet. Though it builds to a recovery image. It is unknown, at the moment, why it fails to boot. Furthermore, this currently does **not** handle devices. Fow now you'll have to provide your device tree manually.
1 parent 7005ea6 commit 9028e4a

File tree

6 files changed

+2280
-0
lines changed

6 files changed

+2280
-0
lines changed

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let
3131
configuration
3232
./flavors/grapheneos
3333
./flavors/lineageos
34+
./flavors/twrp
3435
./flavors/vanilla
3536
./modules/10
3637
./modules/11

flavors/twrp/default.nix

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SPDX-FileCopyrightText: 2020 Daniel Fullmer and robotnix contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
{ config, pkgs, lib, ... }:
5+
let
6+
inherit (lib)
7+
mkDefault
8+
mkIf
9+
mkMerge
10+
;
11+
TWRPBranch = "twrp-9.0";
12+
repoDirs = lib.importJSON (./. + "/repo-${TWRPBranch}.json");
13+
in mkIf (config.flavor == "twrp")
14+
{
15+
androidVersion = mkDefault 9;
16+
17+
# product names start with "omni_"
18+
# → lunch omni_sailfish-eng
19+
productNamePrefix = "omni_";
20+
21+
buildDateTime = mkDefault 1616627550;
22+
23+
# TWRP uses this by default. If your device supports it, I recommend using variant = "user"
24+
variant = mkDefault "eng";
25+
26+
source.dirs = mkMerge ([
27+
repoDirs
28+
{
29+
"bootable/recovery" = {
30+
patches = [
31+
./patches/android_bootable_recovery/0001-gui-Don-t-preserve-mode-owner-when-copying-files.patch
32+
];
33+
};
34+
"build/make" = {
35+
patches = [
36+
./patches/android_build/0001-Work-around-source-files-being-read-only.patch
37+
];
38+
};
39+
}
40+
]);
41+
42+
source.manifest.url = mkDefault "https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
43+
source.manifest.rev = mkDefault "refs/heads/${TWRPBranch}";
44+
envVars.RELEASE_TYPE = mkDefault "EXPERIMENTAL"; # Other options are RELEASE NIGHTLY SNAPSHOT EXPERIMENTAL
45+
46+
build = {
47+
twrp = config.build.mkAndroid {
48+
name = "robotnix-${config.productName}-${config.buildNumber}";
49+
makeTargets = [ "recoveryimage" ];
50+
# Note that $ANDROID_PRODUCT_OUT is set by choosecombo above
51+
installPhase = ''
52+
mkdir -p $out
53+
cp --reflink=auto $ANDROID_PRODUCT_OUT/recovery.img $out/
54+
'';
55+
};
56+
};
57+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 36960782d92c384db2d74795d458a3cfb5f6013d Mon Sep 17 00:00:00 2001
2+
From: Samuel Dionne-Riel <samuel@dionne-riel.com>
3+
Date: Sat, 24 Apr 2021 18:46:05 -0400
4+
Subject: [PATCH] gui: Don't preserve mode,owner when copying files
5+
6+
When building under some strict build environments, like robotnix, it
7+
fails since the source files are in directories without +w.
8+
---
9+
gui/Android.mk | 4 ++--
10+
1 file changed, 2 insertions(+), 2 deletions(-)
11+
12+
diff --git a/gui/Android.mk b/gui/Android.mk
13+
index 32c0d5b1..4ccdf386 100755
14+
--- a/gui/Android.mk
15+
+++ b/gui/Android.mk
16+
@@ -216,8 +216,8 @@ TWRP_RES += $(TW_ADDITIONAL_RES)
17+
TWRP_RES_GEN := $(intermediates)/twrp
18+
$(TWRP_RES_GEN):
19+
mkdir -p $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
20+
- cp -fr $(TWRP_RES) $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
21+
- cp -fr $(TWRP_THEME_LOC)/* $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
22+
+ cp --no-preserve=owner,mode -fr $(TWRP_RES) $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
23+
+ cp --no-preserve=owner,mode -fr $(TWRP_THEME_LOC)/* $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
24+
25+
LOCAL_GENERATED_SOURCES := $(TWRP_RES_GEN)
26+
LOCAL_SRC_FILES := twrp $(TWRP_RES_GEN)
27+
--
28+
2.29.2
29+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
From 12382e7d66d993d89e52e840e7965009de2f81e5 Mon Sep 17 00:00:00 2001
2+
From: Samuel Dionne-Riel <samuel@dionne-riel.com>
3+
Date: Sat, 24 Apr 2021 21:05:00 -0400
4+
Subject: [PATCH] Work around source files being read-only
5+
6+
---
7+
core/Makefile | 33 +++++++++++++++++----------------
8+
1 file changed, 17 insertions(+), 16 deletions(-)
9+
10+
diff --git a/core/Makefile b/core/Makefile
11+
index 2f7219daa..43017a35b 100644
12+
--- a/core/Makefile
13+
+++ b/core/Makefile
14+
@@ -84,7 +84,7 @@ gen := $(OUT_DOCS)/index.html
15+
ALL_DOCS += $(gen)
16+
$(gen): frameworks/base/docs/docs-redirect-index.html
17+
@mkdir -p $(dir $@)
18+
- @cp -f $< $@
19+
+ @cp --no-preserve=owner,mode -f $< $@
20+
endif
21+
22+
ndk_doxygen_out := $(OUT_NDK_DOCS)
23+
@@ -1052,7 +1052,7 @@ $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem: $(addsuffix .x509.pe
24+
25+
ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem
26+
$(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem: $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
27+
- $(hide) cp -f $< $@
28+
+ $(hide) cp --no-preserve=owner,mode -f $< $@
29+
endif
30+
endif
31+
32+
@@ -1413,27 +1413,28 @@ define build-recoveryramdisk
33+
# Use rsync because "cp -Rf" fails to overwrite broken symlinks on Mac.
34+
$(hide) rsync -a --exclude=etc --exclude=sdcard --exclude=vendor $(IGNORE_RECOVERY_SEPOLICY) $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
35+
# Copy adbd from system/bin to recovery/root/sbin
36+
- $(hide) cp -f $(TARGET_OUT_EXECUTABLES)/adbd $(TARGET_RECOVERY_ROOT_OUT)/sbin/adbd
37+
+ $(hide) cp --no-preserve=owner,mode -f $(TARGET_OUT_EXECUTABLES)/adbd $(TARGET_RECOVERY_ROOT_OUT)/sbin/adbd
38+
# Modifying ramdisk contents...
39+
$(if $(BOARD_RECOVERY_KERNEL_MODULES), \
40+
$(call build-image-kernel-modules,$(BOARD_RECOVERY_KERNEL_MODULES),$(TARGET_RECOVERY_ROOT_OUT),,$(call intermediates-dir-for,PACKAGING,depmod_recovery)))
41+
# Removes $(TARGET_RECOVERY_ROOT_OUT)/init*.rc EXCEPT init.recovery*.rc.
42+
$(hide) find $(TARGET_RECOVERY_ROOT_OUT) -maxdepth 1 -name 'init*.rc' -type f -not -name "init.recovery.*.rc" | xargs rm -f
43+
- $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
44+
- $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
45+
+ $(hide) cp --no-preserve=owner,mode -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
46+
+ chmod -R +w $(TARGET_RECOVERY_ROOT_OUT)
47+
+ $(hide) cp --no-preserve=owner,mode $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
48+
$(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
49+
$(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
50+
- $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
51+
- $(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
52+
+ $(hide) cp --no-preserve=owner,mode -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
53+
+ $(hide) cp --no-preserve=owner,mode -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
54+
$(hide) $(foreach item,$(recovery_root_private), \
55+
- cp -rf $(item) $(TARGET_RECOVERY_OUT)/;)
56+
+ cp --no-preserve=owner,mode -rf $(item) $(TARGET_RECOVERY_OUT)/;)
57+
$(hide) $(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
58+
- cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
59+
+ cp --no-preserve=owner,mode -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
60+
$(hide) $(foreach item,$(recovery_fstab), \
61+
- cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
62+
+ cp --no-preserve=owner,mode -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
63+
$(if $(strip $(recovery_wipe)), \
64+
- $(hide) cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.wipe)
65+
- $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
66+
+ $(hide) cp --no-preserve=mode -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.wipe)
67+
+ $(hide) cp --no-preserve=owner,mode $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
68+
$(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) \
69+
> $(TARGET_RECOVERY_ROOT_OUT)/prop.default
70+
$(if $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET), \
71+
@@ -1514,7 +1515,7 @@ $(recovery_uncompressed_ramdisk): $(MKBOOTFS) $(ADBD) \
72+
$(BOARD_RECOVERY_KERNEL_MODULES) \
73+
$(DEPMOD)
74+
$(call build-recoveryramdisk)
75+
- @echo ----- Making uncompressed recovery ramdisk ------
76+
+ @echo ----- Making uncompressed recovery ramdisk YAY ------
77+
$(hide) $(MKBOOTFS) $(TARGET_RECOVERY_ROOT_OUT) > $@
78+
79+
$(recovery_ramdisk): $(MINIGZIP) \
80+
@@ -1857,7 +1858,7 @@ endif
81+
define build-boottarball-target
82+
$(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
83+
$(hide) mkdir -p $(PRODUCT_OUT)/boot
84+
- $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
85+
+ $(hide) cp --no-preserve=owner,mode -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
86+
$(hide) echo $(INTERNAL_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
87+
$(hide) $(MKTARBALL) $(FS_GET_STATS) \
88+
$(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
89+
@@ -3398,9 +3399,9 @@ $(INTERNAL_SDK_TARGET): $(deps)
90+
-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
91+
-v "FONT_OUT=$(SDK_FONT_TEMP)" \
92+
-o $(PRIVATE_DIR) && \
93+
- cp -f $(target_notice_file_txt) \
94+
+ cp --no-preserve=owner,mode -f $(target_notice_file_txt) \
95+
$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
96+
- cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
97+
+ cp --no-preserve=owner,mode -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
98+
HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
99+
development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
100+
chmod -R ug+rwX $(PRIVATE_DIR) && \
101+
--
102+
2.29.2
103+

0 commit comments

Comments
 (0)