Commit Graph

471 Commits

Author SHA1 Message Date
bigbiff
df8436b51a fastboot: implement fastbootd in twrp
fastbootd is a userspace daemon that runs in the recovery
ramdisk. It allows writing single partitions to the super
partition via fastboot CLI. When TWRP sees the fastboot option
in the misc partition during startup, it will start with
the fastbootd page and fastbootd running. Otherwise it will
run recovery normally.

Change-Id: Id7b12d29ef21dbd5950dc884dd1cd788f25357f0
2020-10-21 17:47:27 -04:00
Captain Throwback
ca2ba939c9 init: add services to build
hwservicemanager and servicemanager are needed for decryption
and fastbootd in TWRP. Include these services by default since
they are standard Android services and independent of device
tree or SoC.

Change-Id: Id0ec73d9a6ca0289c7b4f67e9dcf541b2157c04e
2020-10-14 12:55:58 -04:00
bigbiff
ad58e1bfae repack: move sbin to /system ramdisk and update repacking
for android-10

This will support updating the ramdisk to a different
compression format and co-exist with magisk.

We are also cleaning up and removing non android-10
api makefile actions.

We are also moving twrp repacking to its own class. We
check the new ramdisk format and if it's different
we have magisk compress using the new ramdisk format.

Change-Id: I770030aae7797e75817178b2f0fccd9f39dc23af
2020-09-08 10:08:33 -04:00
bigbiff
7ba7500953 decrypt: AOSP 10 requires the use of fscrypt
fscrypt aosp doc: https://source.android.com/security/encryption/file-based
kernel fscrypt doc: https://www.kernel.org/doc/html/v4.18/filesystems/fscrypt.html

This commit implements the ability for TWRP to use fscrypt to decrypt
files on the fscrypt implementation. It has been implemented mostly
in a new successor library to e4crypt called libtwrpfscrypt. Most of the
code was ported from AOSP vold.

Notable updates include:
 - updated policy storage by libtar
 - lookup of fbe policies by libtwrpfscrypt
 - threaded keystore operations

Big thanks to Dees_Troy for the initial trailblazing
of encryption in TWRP.

Change-Id: I69cd2eba3693a9914e00213d4943229635d0cdae
2020-06-22 12:17:22 +02:00
mauronofrio
6d3bf891c4 Add ozip decryption for Oppo/Realme device
This function will automatically decrypt .ozip file in a .zip and it will
save the .zip in the same folder of the .ozip and with the same name.
After the decryption, the flash will start.

To enable this function you have to set a Boardconfig flag with the
decryption key like i did here:

a30625f80a

Original projects:
https://github.com/sabpprook/ozip2zip
https://github.com/bkerler/oppo_ozip_decrypt

Change-Id: Ic93243a565008c442bcf2992069b2801532ac7c1
(cherry picked from commit 0ff59845f2f8dddedb4cee9a9faf86a6294cce66)
2020-06-10 22:31:49 +00:00
bigbiff
325e0a2cca ext4crypt: fix include location for recovery-twrp in lineage
Change-Id: Iefa73425fc13f41f5a267cce0c5d4047edc25e9e
(cherry picked from commit 186eb7002d95e28325f2d2e42637c989e08ac618)
2020-06-08 23:28:07 +00:00
bigbiff
32cbabe413 apex: mount up apex files into /sbin for library access
This patch uses the loop device to mount files under
/sbin/ from /system/apex in order for the device to
use libraries or other files store inside these files.

Each apex file is mounted over a loop device into a
directory correpsonding to the apex filename under
/sbin/.

Once apex mounting is completed, TWRP will set a
property twrp.apex.loaded to true so that init
can use them as a LD_LIBARY_PATH source.
Change-Id: I69f14a969123ac9cf1afc85b6cf76836cb092fb2

Change-Id: Ica6a7d8e479bcaec8bec4483b5e8d2b45ee105fb
2020-06-08 20:38:04 +00:00
bigbiff
ee7b7ffba4 super partition: mount super partitions using fs_mgr
We are now requiring fstab v2 for android-10+ trees. You can
specify twrp flags using /etc/twrp.flags to label and
annotate partitions.

This patchset uses fs_mgr to load the super partition and build
device mapper blocks off vendor and system depending on the slot
in use. These are mapped to partitions in TWRP and allowed to
be mounted read-only. The super partition is also mapped into a
TWRP partition in order to backup the entire partition. You cannot
backup individual device mapper blocks due to the device can only
be read-only. Therefore you cannot write back to the device mapper.

Change-Id: Icc1d895dcf96ad5ba03989c9bf759419d83673a3
2020-06-08 20:37:29 +00:00
mauronofrio
babc15ef61 Set toolbox as default for android 9+ TWRPs
I created also a new flag for who wants to use busybox
on android 9+ trees.

To use busybox set the flag like this:

TW_FORCE_USE_BUSYBOX := true

Change-Id: If2231e71c008b36e9ae09857539b82d77e2a9a06
(cherry picked from commit 8ff93eb2234f31298d4f3cfe903887c3f6ecc583)
2020-05-19 14:52:04 +00:00
Captain Throwback
89a03ccd36 vold_decrypt: automatically set Android version & patch level
- Requires TW_INCLUDE_LIBRESETPROP
  (set automatically if TW_OEM_BUILD is not set)
- Set based on installed system (if present)
- Will set values back to TWRP defaults
  after decryption completes
- Only included/run on Oreo+ systems

Change-Id: I41fcc1af8cd4b15329574f7403f7491320199f48
(cherry picked from commit 3284a66e23fbc6e1a82df668b497ef931d9c0081)
2020-05-11 15:22:14 +00:00
bigbiff
437b93a087 Merge remote-tracking branch 'origin/android-9.0' into android-10.0
Change-Id: Ie850f431f0d2c39c86b9c10701676a24770ab447
2020-05-10 20:06:41 -04:00
Mohd Faraz
0d9a62e409 Remove Extra spaces occured while using multiline string variable
* On multiline string variable it adds spaces

Change-Id: I0f9140f3840b0238009af2271ac67b25754f76c9
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-05-10 21:24:00 +00:00
Chaosmaster
97c4541415 libresetprop: not available for Android < 7
Change-Id: I5cf384b472e43ee8d380ac08aeed1a8567844d7e
2020-05-10 21:21:47 +00:00
Chaosmaster
461e39fe89 Add TWFunc::Property_Override(name, value) to override properties
using libresetprop

Change-Id: Ic49e187698c714f8a629d20ceddc40e823555477
2020-05-10 17:17:56 -04:00
bigbiff
973167aff3 ramdisk: move uevent link that build creates
Add missing init.rc files for recovery.
Cleanup init symbolic links.
Comment out removing the source file in relink.sh because we need
to retain files in /system in the ramdisk.
Change-Id: Ie959024296738538f3b3161e38027a44525b0696

Change-Id: I5b1a744414b88a9a15c56bd81f37091664d5cdf1
2020-04-09 16:47:23 -04:00
bigbiff
416fe3a18a toybox: deprecate busybox and toolbox utils
Starting with android-10.0 we should only use tools from toybox.
Toyxbox in android-10.0 is specified as a recovery target, so
we just move the symlinks in our relink target.

Change-Id: Ic0116a7d583519b39422ac4d82d30e00918eb29d
2020-03-28 14:13:43 -04:00
bigbiff
bf3b1564f9 aosp10: minor cleanup, other commented makefiles need to be worked on 2020-03-23 13:58:30 -04:00
bigbiff
d58ba18272 AOSP10 TWRP Merge: fix conflicts and update libraries needed
This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.

The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
2020-03-23 11:18:29 -04:00
bigbiff
26d5d5f0b9 Merge tag 'android-10.0.0_r25' into aosp10-4
Android 10.0.0 release 25
2020-03-23 09:56:16 -04:00
Martin Dünkelmann
c630b3864f Fix 'system/etc/ld.config.txt' not found error
According to

https://android.googlesource.com/platform/system/core/+/refs/tags/android-9.0.0_r51/rootdir/Android.mk#260

the ld.config.txt gets generated with the vndk version as a suffix.
This behaviour exists since API level 28 (Android 9.0), if
BOARD_VNDK_VERSION is defined and BOARD_VNDK_RUNTIME_DISABLE is not
true.

The issue seems to be exist since commit
8d70eb617e in twrp.

Change-Id: I19741c29cda65ce051b7c167a946d551ce149f7b
2020-03-14 21:14:54 +00:00
Ian Macdonald
2923defaea /sbin should come first in the linker search path.
/sbin must come before any other search path when TWRP is built for a
different version of Android than the one on which it will run.

Otherwise, as soon as any of the other paths becomes available via
direct action (i.e. the user mounts a file-system) or indirect action
(e.g. the user flashes a zip that mounts a file-system), incompatible
libraries will be prioritised and loaded instead of the correct ones
from /sbin in TWRP's ramdisk.

This will cause severe disruption of the TWRP environment. Toybox and
other dynamically linked binaries will immediately cease to work; and
since Toybox provides umount, it typically won't be possible to recover
from this state without a reboot.

For example, the following occurs when a Toybox applet is run on a
Samsung Galaxy S10 running Android 10, but using a version of TWRP built
for Android 9:

android:/ # getprop ro.boot.bootloader
CANNOT LINK EXECUTABLE "getprop": cannot locate symbol "_system_properties_init" referenced by "/system_root/system/lib64/libselinux.so"...
linker: CANNOT LINK EXECUTABLE "getprop": cannot locate symbol "_system_properties_init" referenced by "/system_root/system/lib64/libselinux.so"...

Change-Id: I31fe612ebb1c7d9ad71d67be2c615caa3fbb5d6f
2019-12-05 01:54:57 +01:00
Captain Throwback
8d70eb617e ldconfig: add /sbin to search.paths
- Move commands from prebuilt to root Android.mk
- Hotfix for linker errors after https://git.io/JerWD merge
  on some Samsung device(s)

Change-Id: If628ab486689878885b696c2f5a107987092aeba
2019-11-14 11:14:06 -05:00
Ethan Yonker
ae7ff3b2fa Fix symlink creation
Change-Id: I0d0bcdde2957974eb357a6f3d820bd5ab0fa47ee
2019-05-24 16:31:09 -05:00
Ethan Yonker
abf1fb0086 Switch between dependencies and modules
Use LOCAL_REQUIRED_MODULES for Pie and up and
LOCAL_ADDITIONAL_DEPENDENCIES for Oreo and down.

Change-Id: I5365e782f98f3bbf4bf246be22c8f573824b65ee
2019-05-24 22:39:12 +02:00
Ethan Yonker
f0a7e59668 Fix recovery-twrp in some old CM trees
Change-Id: Ie401ab8ec39b721c3747475bcc8269f78963d31c
2019-04-04 10:06:41 -05:00
Michael Bestas
de18923571 Remove duplicate ext4 flags from Android.mk
* They are right above

Change-Id: Ifff889e6ff748ed6bfa4a076b1afcc2c6a7eed3b
2019-03-23 14:39:53 +02:00
Michael Bestas
0cc2376153 Set a dummy CM_PLATFORM_SDK_VERSION if it doesn't exist
* Avoids printing 2 build warnings on every single rebuild
  of anything when building TWRP inline

Change-Id: I5dd3623707c03af0dfe7366f1a77e83762e720b2
2019-03-23 14:39:53 +02:00
dianlujitao
4879b37b5d Fix the long broken format function
* For EXT2/3:
   * Align mke2fs options with Android 9.0 fs_mgr_format.cpp.
 * For EXT4:
   * Note that make_ext4fs is still in use on Android 8.1 to workaround
     a FDE encryption bug even though mke2fs has become the default
     choice. The bug is fixed in Android 9.0+.
 * For F2FS:
   * Drop the broken "-r" option, it's never ported to O, explicitly
     pass number of sectors instead.
   * Keep all options aligned with Pie fs_mgr.
   * Check existence before start wiping, as Wipe_EXT4 does.
 * For all:
   * Calculate block size at runtime, and reserve the space specified
     via negative "length" option from fstab. Note that positive length
     will be ignored.
   * If the partition has crypto footer, and "length" is not specified
     in fstab, automatically reverse CRYPT_FOOTER_OFFSET (16384).
   * Remove the default crypto key location: footer, this is a bad
     assumption since most partitions don't use encryption! We need to
     know the real situation to decide whether to reserve crypto footer
     on format.
   * If the current action is "wipe" or "change filesystem", wipe crypto
     footer or block device after mkfs if the partition is
     unencrypted or undecrypted (e.g., wrong password).
   * If the current action is "format data", unconditionally wipe crypto
     footer or block device.

Change-Id: I7304a8ee703131ea4a08ab7c60334af28cac28b3
2019-03-21 16:15:52 -05:00
Dees Troy
908442dfb5 Merge "Update FDE decrypt to pie from CAF" into android-9.0 2019-03-20 21:40:44 +01:00
Ethan Yonker
98661c1a29 Update FDE decrypt to pie from CAF
cryptfs.cpp based on CAF tag LA.UM.7.3.r1-05900-sdm845.0
Used CAF because AOSP no longer contains code for qcom's hardware
crypto.

Change-Id: I921cbe9bed70989f91449e23b5ac3ec1037b7b97
2019-03-20 15:33:48 -05:00
bigbiff bigbiff
af32bb9c4f MTP FFS updates:
This update splits old MTP code and new MTP code from Google
into two trees, legacy and ffs. Depending on the SDK level,
the build system will select the correct version. The reason
for separating the versions out are due to older android trees
not supporting the updated MTP code from Google.

Most MTP code is from Google, with additions needed from
implementing the Java functions in C++ for TWRP and FFS.

We assume if you are in android-9.0 or above, your kernel
has support for FFS over MTP. Verify that your init.rc
is mounting the MTP FFS driver to the proper location.

Change-Id: I4b107b239bd9bc5699527f9c8c77d9079f264a7e
2019-03-20 14:28:21 -05:00
mauronofrio
e9a49efe75 Adding Edl button in reboot menu
Edl mode is available only on qualcomm devices and it used to fully
restore the bricked devices. I made the button available only if
TW_HAS_EDL_MODE := true like the download button. I set the edl
button to the right of the download button, so devices can support
edl button and download button. I also added the translation for
all languages.

Change-Id: I69d1058b8c050b722395c7b3da6dce1ccfbe7a91
2019-03-20 10:57:07 -05:00
Andreas Blaesius
38d2d5268e TWRP: fix compiling on Android 7
fixes
cp: cannot create regular file (...)/recovery/root/file_contexts': No such file or directory

Change-Id: I094a0bd242c6eb01e84570fbe49e853098e33a8b
2019-03-19 17:58:29 +01:00
bigbiff bigbiff
3ed778ad63 Vibration: allow BoardConfig to disable vibration for a device.
Change-Id: Ibd2f67391ce6d7774498839829e0de9391508781
2019-03-17 22:39:00 -05:00
oshmoun
9220dbab44 fix building TWRP for devices without cache
Some devices do not declare BOARD_CACHEIMAGE_PARTITION_SIZE.
This case is detected and required modules are added to LOCAL_REQUIRED_MODULES.
However, := is used instead of +=  and causes the loss of all previously added modules.
The end result is that twrp is not actually getting built since its module was lost.
Fix that by using += when adding modules required for cache-less devices.

Change-Id: Ib0a4db4955040ced77be7ed04d636905beadf093
2019-03-18 04:27:35 +01:00
bigbiff bigbiff
c630cee1ae slot management: add library for slot management.
Change-Id: I7d0a67bc8e237866485680a5c54443435e7d2737
2019-02-20 18:06:55 -05:00
Ethan Yonker
933828251d Add metadata decrypt support for FBE
Change-Id: Ie0292f4ffea5993a4ae74fa04fc5c8252ca2cfcf
2019-01-17 14:14:59 -06:00
Hridya Valsaraju
6f44c11357 e2fsck_static is no longer needed for remount
Remount will instead use overlayfs. If the device is not configured
to use overlayfs or if the device does not support dynamic partitions
but has chosed to setup an ext4-dedupe filesystem, e2fsck_static must
then be included in recovery.

Bug: 122115286
Test: fastboot flashall
Change-Id: I931282dbc67ff4ef53291bcbc5a078b500e5e807
2019-01-16 23:42:55 +00:00
Ethan Yonker
66bcd499e5 Fix building in Lineage 16.0
Change-Id: Ia7c66d469c69d9c4e9263feae7b48d40c09af155
2019-01-03 20:28:16 -05:00
Tao Bao
c674dfb584 Use dynamically linked f2fs executables.
It also reduces the space cost for devices using f2fs (e.g. crosshatch).
/sbin/mkfs.f2fs   722560 => /system/bin/make_f2fs   49568
/sbin/sload.f2fs 1182456 => /system/bin/sload_f2fs 150032

Test: Build and boot recovery on crosshatch. Factory reset.
Test: Install a non-A/B OTA package that formats a f2fs partition.
Change-Id: Ibe70c8d91a1d07e1c78ff9eac19b1f7955800161
2018-12-20 14:47:11 -08:00
lambdadroid
fc0b16df8b Add option to use ro.serialno for generating device id
On some devices (e.g. ASUS Zenfone) the serial number of the device
is stored in a file in the /factory partition. Consequently, the only
way to load it is using a user space application during the init
process, and to update the ro.serialno system property.

In most places, TWRP already uses the system property to get the
serial number of the device. However, when generating the device ID
used for the backup folder name it checks the boot command line
directly. On these devices, the serialno is not included on the
command line.

Add a TW_USE_SERIALNO_PROPERTY_FOR_DEVICE_ID option that enables
usage of ro.serialno for generating the device id. It is disabled
by default to avoid changing the device id on existing ports.

Change-Id: I4a2eeca883f38fdaeb1209507fd8ebe44b1b04a0
2018-09-26 23:53:28 +02:00
Tianjie Xu
2b1a464a70 Move the parse of last_install to recovery-persist
The recovery-persist used to look for the related recovery logs in
persist storage, and copy them under /data/misc/recovery during the
normal boot process.

As we also want to find out the sideload information from last_install,
it makes more sense to move the parse & report of non-a/b metrics to
recovery-persist. Thus we can avoid the race condition of the file
system between the native code and RecoverySystem.

Bug: 114278989
Test: unit test pass, check the event buffer for metrics report
Change-Id: I32d7b2b831bc74a61a70af9a2f0b8a7e9b3e36ee
2018-09-13 13:27:55 -07:00
Ethan Yonker
58f2132bc3 Merge AOSP android-9.0.0_r3
Fix conflicts and make it build in 5.1, 6.0, 7.1, 8.1, and 9.0

Change-Id: Ida0a64c29ff27d339b7f42a18d820930964ac6e4
2018-08-24 11:17:39 -05:00
Tao Bao
ef5e38fef0 tests: Move to Android.bp.
Also separate libupdater_defaults out to be shareable.

It turns out the `data` property in `cc_test` doesn't follow symlinks as
LOCAL_TEST_DATA does in Android.mk. This CL creates a filegroup in
top-level Android.bp in order to pick up the testdata for ResourcesTest.

Test: `mmma -j bootable/recovery` with aosp_marlin-userdebug
Test: Run recovery_{unit,component,manual}_test on marlin.
Test: Run recovery_host_test.
Change-Id: I4532ab25aeb83c0b0baa8051d5fe34ba7b910a35
2018-08-14 21:46:45 -07:00
Tao Bao
673bb6f051 updater: Move libupdater to Soong.
Test: mmma -j bootable/recovery
Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: I2617b87d13c585addf0ed2fbae8c3ce443ea7200
2018-08-13 09:44:48 -07:00
Tao Bao
df264e0186 Merge "Build recovery with Soong." 2018-08-13 16:25:48 +00:00
Treehugger Robot
bbe881693a Merge "Build boot control HAL with Android.bp" 2018-08-10 22:48:19 +00:00
Tao Bao
5fc72a103b Build recovery with Soong.
Fixes: 110380063
Test: `mmma -j bootable/recovery` with aosp_taimen-userdebug
Test: Build and boot into recovery on taimen. Check the basic
      functionalities (`Apply update from ADB`, `View recovery logs`,
      `Run graphics test`).
Test: Run recovery_unit_test and recovery_component_test on marlin.
Test: Modify `recovery.cpp` locally to trigger the call to
      is_battery_ok(). Check that the battery info is reported
      correctly.
Test: `build/soong/build_test.bash --dist`
Change-Id: I391eb201d57c760e457ba2bf2410ceb72596795c
2018-08-10 14:43:27 -07:00
Tao Bao
afa16480aa Merge "updater_sample: Move to Soong." 2018-08-10 18:10:31 +00:00
Tao Bao
d2be7fc29a updater_sample: Move to Soong.
Test: Follow the steps in "Running tests" in updater_sample/README.md.
Change-Id: I70c3239e3daea0dcdadf02f68abe7d6aafa67a2e
2018-08-10 09:05:56 -07:00