From 0cd1499fa30ed9d9a229f060fdd2e7fb7afe742e Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Sat, 5 Sep 2026 15:02:55 +0200 Subject: [PATCH] general: automate recovery build --- README.md | 14 +++++++++++++- build_twrp.sh | 49 +++++++++++++++++++++++++++++++------------------ shell.nix | 7 ++++++- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4f1c09f..ab87854 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,13 @@ recoveries and ROMs for the Galaxy Tab Active SM-T365. ## Recovery ``` -nix-shell shell.nix --run ./build_recovery.sh +./build_twrp.sh ``` +This builds the recovery inside the nix-shell FHS environment (shell.nix); +the script re-executes itself there, so it works from the host even though +`nix-shell --run` is broken by the `exec android-env` shellHook. + # Device information | Basic | Spec sheet | @@ -33,3 +37,11 @@ nix-shell shell.nix --run ./build_recovery.sh | Rear camera | 3.1 Mpx | | Front camera | 1.2 Mpx | | Similar devices | milletlte, matisselte, motorola_thea | + +# Links to device trees, manifests, etc. + +- https://github.com/matteo0026/android_device_samsung_rubenslte +- https://git.cfpi-fpsi.eu/rubenslte/twrp_device_samsung_rubenslte +- https://git.cfpi-fpsi.eu/rubenslte/android_kernel_samsung_rubenslte +- https://github.com/matteo0026/twrp_device_samsung_milletlte +- https://github.com/matteo0026/twrp_device_samsung_matisselte diff --git a/build_twrp.sh b/build_twrp.sh index e46ac79..31de96a 100755 --- a/build_twrp.sh +++ b/build_twrp.sh @@ -1,11 +1,22 @@ #!/usr/bin/env bash +# Build a TWRP recovery image for Samsung Galaxy Tab Active (SM-T365, rubenslte). +# Must run inside the nix-shell FHS environment (shell.nix): if invoked from the +# host, it re-executes itself inside that environment via its stdin pipe. set -euo pipefail -export ALLOW_NINJA_ENV=true USE_CCACHE=1 LD_LIBRARY_PATH=/usr/lib:/usr/lib32 LC_ALL=C LANG=C LC_CTYPE=C +SCRIPT="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -cd "$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -SCRIPT="$PWD" +if [ -z "${RUBENSLTE_BUILD_IN_ENV:-}" ]; then + echo "[*] Entering nix-shell FHS build environment ..." + cd "$SCRIPT" + printf '\nexport RUBENSLTE_BUILD_IN_ENV=1\nbash "%s/build_twrp.sh"\n' "$SCRIPT" \ + | nix-shell shell.nix + exit $? +fi +export LC_ALL=C LANG=C LC_CTYPE=C + +cd "$SCRIPT" mkdir -p twrp-build cd twrp-build @@ -13,30 +24,32 @@ if [ ! -d .repo ]; then repo init --depth 1 -u https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git -b twrp-5.1 fi -repo sync -j$(nproc) +repo sync -c -j$(nproc) +# Device tree (gitea mirror of this repo) if [ ! -d device/samsung/rubenslte ]; then git clone --depth 1 https://git.cfpi-fpsi.eu/rubenslte/twrp_device_samsung_rubenslte device/samsung/rubenslte fi +# Kernel built from source (gitea mirror of Samsung msm8226 stock tree) +if [ ! -d kernel/samsung/rubenslte ]; then + git clone --depth 1 https://git.cfpi-fpsi.eu/rubenslte/android_kernel_samsung_rubenslte kernel/samsung/rubenslte +fi + for p in "$SCRIPT"/patches/*.patch; do patch -p1 -s < "$p" 2>/dev/null || true done -export AR="$(command -v ar)" -export CC="$(command -v gcc)" -export CXX="$(command -v g++)" - -HOST_TOOLCHAIN="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin" -if [ ! -f "$HOST_TOOLCHAIN/x86_64-linux-ar" ]; then - mkdir -p "$HOST_TOOLCHAIN" - for tool in ar gcc g++; do - src="$(command -v $tool)" - if [ -n "$src" ]; then - ln -sf "$src" "$HOST_TOOLCHAIN/x86_64-linux-$tool" - fi - done +# arm-eabi-4.8 cross toolchain (AOSP prebuilt, plain gcc host binary) +ARM_EABI_DIR="prebuilts/gcc/linux-x86/arm/arm-eabi-4.8" +if [ ! -x "$ARM_EABI_DIR/bin/arm-eabi-gcc" ]; then + echo "[*] Downloading arm-eabi-4.8 prebuilt toolchain ..." + mkdir -p "$ARM_EABI_DIR" + curl -L --fail \ + "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/+archive/refs/tags/android-5.1.1_r38.tar.gz" \ + | tar -xz -C "$ARM_EABI_DIR" fi +export PATH="$PWD/$ARM_EABI_DIR/bin:$PATH" export TOP="$PWD" set +u @@ -45,5 +58,5 @@ lunch omni_rubenslte-userdebug set -u mka recoveryimage -cp out/target/product/rubenslte/recovery.img "$SCRIPT" +cp out/target/product/rubenslte/recovery.img "$SCRIPT/" echo "Done: $SCRIPT/recovery.img" \ No newline at end of file diff --git a/shell.nix b/shell.nix index 6681b8f..1174d22 100644 --- a/shell.nix +++ b/shell.nix @@ -48,5 +48,10 @@ let in pkgs.stdenv.mkDerivation { name = "android-env-shell"; nativeBuildInputs = [ fhs ]; - shellHook = "exec android-env"; + shellHook = '' + if [ -n "$BASH_EXECUTION_STRING" ]; then + exec android-env -c "$BASH_EXECUTION_STRING" + fi + exec android-env + ''; }