Commit Graph

272 Commits

Author SHA1 Message Date
Konsta
438a85efcf Merge remote-tracking branch 'TeamWin/android-11' into android-11
Change-Id: Id1d534cce0969c98e2b8b6484278342201dd562d
2022-01-12 16:55:24 +02:00
Captain Throwback
e331b8a1b7 tw_crypto_pwtype: move default setting to data.cpp
Change-Id: Id3dda3bc2c32ad286b1ec67595f482f84b5077d7
2022-01-10 21:21:16 +00:00
bigbiff
36cb2ad28e /sdcard: do not bind mount twice
Change-Id: I1757eb8732a01a728392c3499ac3300c81522806
2021-12-09 19:26:06 -05:00
Konsta
894efea684 never keep system and vendor partitions readonly
Change-Id: I72b1740d406b16d066cfb86426529c8f9a4a9912
2021-11-23 14:32:23 +02:00
GarfieldHan
d0b854b31d Add EROFS to file system check list
This commit will add EROFS Filesystem mount support

Since Huawei announced the new file system EROFS and successfully
merged into mainline. More and more OEMs switch the ext4 filesystem
to EROFS filesystem for system/vendor/odm/product partitions like
Oplus (OPPO / Realme / OnePlus).

Test: Import the latest fstab from system, build and boot. EROFS-based
partions like system and vendor partitions were sucessfully mounted.

Notes: Although I tried to change 'ext4' to 'erofs' for correct partition
in twrp.flags, but it was still recognized as 'ext4'. So you can just copy
the line related erofs partitions from recovery.fstab and TWRP will failed
to recognize the line in twrp.flags, and then skip this line, so the issue
was solved.

Signed-off-by: GarfieldHan <2652609017@qq.com>
Change-Id: I49a04e4465f1d92eb589ad6d86b6db9b58d720eb
2021-11-21 23:54:28 +08:00
nkk71
3c1e35f51c Adopted Storage: Add support for mixed mode sdcards
* Adds support for mixed adopted storage + removable
  storage partitioned sdcards.

* Also symlinks Adopted Storage datamedia folder to an
  available /sdcardN (N being 2 through 9) folder.

* Requires a suitable entry in fstab, for example:

    # Removable Storage
    /sd_ext ext4 /dev/block/mmcblk1p2 /dev/block/mmcblk1
        flags=storage;wipeingui;removable;encryptable=footer
    /external_sd vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1
        flags=storage;wipeingui;removable;encryptable=footer

  /sd_ext will be the mountpoint for adopted storage, and /sdcardN
  will become symlinked to /sd_ext/data/media[/0]

* Fix adopted storage nickname being ""

* Output adopted partition info after successful decrypt

* Mimic single lun code for multi lun devices:
  "Mount CurrentStoragePath if it's not /data"

Change-Id: I3874c09f1a1c3a81f04277e17f17cc03ecb4184a
2021-11-18 19:47:13 +00:00
micky387
2ec1df43d3 recovery: Don't exclude the whole data system dir for the factory reset
Factory reset not clean correctly the settings of system.

Change-Id: I3ff616093e4f2f480f11f97ccfb4072756400777
2021-11-09 00:24:06 +00:00
Captain Throwback
37c3aef4e8 crypto: only set crypto state and type if not already set
Move setting crypto state and type to functions and call those
functions rather than arbitrarily setting those props in every
case. This cleans up all the log spam from trying to set
read-only props, since they will now only get set if
they aren't already.

Change-Id: I392bee060d71c6ee50d0d92bf1b118d9049be41a
2021-10-06 22:27:49 +00:00
Captain Throwback
8a8e56cd60 crypto: only show FBE error if device is encrypted
Change-Id: I60da4ff71a15e5bc4e13135abf268bff1c88b8d1
2021-10-06 22:02:32 +00:00
Captain Throwback
63573b550f mtp: don't create storage device after format data
Since we don't re-create data/media on FBE devices,
don't create an MTP storage device for it.

This fixes the bug when, after formatting data on
and FBE device, an empty Internal Storage appears
on the PC.

This also prevents an empty storage device from
being created if recovery is rebooted after formatting
data before booting to Android. A warning will appear
in the console that MTP is disabled in that case.

Currently the path is hardcoded to data/media; this
should probably be adjusted for cases where adoptable
storage is being used.

Change-Id: Iaafc5e3cde54c3ef6ffaf33f76d14c626b6e590d
2021-10-05 22:53:07 +00:00
bigbiff
d21252f1b5 merges: allow user to perform snapshot merges in advanced menu
Change-Id: I894a0ef5a0ec8e208053358f09a6b8a6d4ee408a
2021-10-05 22:32:19 +00:00
bigbiff
437d86f6a0 wrappedkey: don't use twrp for processing anymore
Now in android-11 we can now process legacy and newer wrappedkey
support in our libfscrypt library. TWRP doesn't need to set a
property to check for wrapped key. libfscrypt will just process
wrappedkey fs_mgr flag for legacy wrapped key or wrappedkey_v0
for the newer wrapped key supported in android-11.

Change-Id: Ia94c7ebe34a05c9b25bbb7a5b2e899902c93d203
2021-09-28 00:53:32 +00:00
systemad
db475c9015 f2fs format: Remade f2fs command
Main reason for this change was to add proper support for casefolding and project id quota
so I adapted how the command was built, similar how the AOSP recovery crafts it.

Your device tree also need to include this
$(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk)

references:
https://android.googlesource.com/platform/bootable/recovery/+/refs/tags/android-11.0.0_r29/recovery_utils/roots.cpp#246
https://source.android.com/devices/storage/sdcardfs-deprecate

Change-Id: Id45b8ed33fe4f2317f0559ef77423f70d892b91c
2021-09-27 20:20:07 +00:00
bigbiff
aed1bdfe59 get_args: process /data/cache/command
Change-Id: I744cdc5a72f53fd1224de242e30ff261e6104900
2021-09-25 20:52:58 +00:00
bigbiff
998f839e82 super processing: use logical flag to denote super status
To support all partitions that are on the super partition
we now parse for the logical flag in fstab to denote super
status.

- Remove guards for the first character being '/'.
- Skip commented lines in fstab
- Build Backup_Display_Name from partitions in super.
The first four lines that are in fstab will be
displayed.
Change-Id: I3f8980187bd4a136257dd6eeaeddd7ea71706cd3

Change-Id: I1ee7c02f91aafb646beaf401a43bcb22fa8c8c7a
2021-08-28 17:48:23 +00:00
bigbiff
cfa875c4d4 vab support: merges and unmapping super devices
- check for merges before formatting data
- add advanced option for unmapping super devices

Change-Id: I38d4d3bbdfa071969016c3e000c86a4d03c71e45
2021-08-09 23:04:33 +00:00
bigbiff
a15d02f885 vab: exclude gsi
Change-Id: I00d4b4f19aafcaf87ad951ba4f1cb7e3fe84ced8
2021-07-26 19:20:57 -04:00
bigbiff
2d54867daa fbe formatting: add warning for fbe devices and remove unused string
Change-Id: Id7af18a4c39932d8685e3265bfa158494ffd10f0
2021-07-17 00:14:21 +00:00
bigbiff
be4f46cbc3 sdcard: bind mount in post decrypt
also uncomment wiping code that should not be commented

Change-Id: I445f688628dcedb67544c22c7b0775ee62e0b267
2021-05-18 20:35:51 -04:00
bigbiff
a957f078be FsCrypt update: support fscrypt policies v1 and v2
This patchset introduces support decryption for Android 11.

In this update we deprecate ext4crypt. To specify the
policy version to use, use TW_USE_FSCRYPT_POLICY := 1 or
TW_USE_FSCRYPT_POLICY := 2. By default policy version will
be set to 2 if this variable is omitted.

Change-Id: I62a29c1bef36c259ec4b11259f71be613d20a112
2021-05-18 20:35:51 -04:00
bigbiff
4a60bee82e android root: restore context for android system root
In this patchset we will store and reset the android system
root context after a wipe and restore to prevent issues
with no context labels in the file_contexts being applied.
This will prevent no boot issues in android with selinux
denials on the system root partition.

Change-Id: I87fd3a6060fbaa3e7bdfd7a4b1d09feeb4fa3f27
(cherry picked from commit 35d2bfda3c89ebd212a9bd2328bffd7464f95d47)
2021-02-15 12:29:48 -05:00
Peter Cai
d68e6413e5 partition: add support dm_use_original_path
* On some mediatek devices we must use symlinked path instead of the
      real block device.  Needed for decryption on some MTK HW FDE devices.

Change-Id: Ib48d745fd442c590aea2baf6d2dbe20aaaef9eec
2021-02-15 12:29:27 -05:00
Peter Cai
439d60cb9d partitionmanager: support delayed adopted storage mount
* On some devices, the external mmc driver will only load the card after
  a certain delay. The original code will break and fail to mount any
  adopted storage in this case.

* Add a special fstab flag to allow the partitionmanager to retry after
  a delay.

Change-Id: I219978850ff3ba7ad9dc7ca96fc30634c9574164
2021-02-15 12:29:19 -05:00
Captain Throwback
acc7f0f873 wrappedkey: only run check on FBE devices
Change-Id: I3713fc4619279d8ee2de924df2bc4fbde944d834
2021-02-15 12:27:03 -05:00
Captain Throwback
b5af4f80d0 fbe: move key directory logging within key directory check
Change-Id: I9d1a50ab0fb8b9bbb2e0686c6ffe28b4b22634b4
2021-02-15 12:26:54 -05:00
Captain Throwback
dbc37b7a4c wrappedkey: set prop for metadata partition if flag is present
Change-Id: I0da59e81993a119d198dbfc350b7fca0e1cb3c5c
2021-02-15 12:26:46 -05:00
nebrassy
57f210d409 also set crypto state for non-metadata FBE
Change-Id: I586878cc6134d798b1d087415cb694d6738f279a
2021-02-15 12:25:47 -05:00
nebrassy
f74255ea1e set crypto state/type when detected
Change-Id: I4506d3ef11052dbebf974b5c387a3c7d5055f2ea
2020-11-11 01:59:11 +00:00
Noah Jacobson
81d638d235 Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

multiuser: Parse users only when Decrypt_DE runs successfully

multiuser: Warn when not all users are decrypted

Change-Id: Ia5e943b13c2d5ec5c34ae97661133c19ff471e6d
2020-10-23 00:52:04 +00:00
Captain Throwback
47bf7204f8 partition: support tntfs module
Change-Id: I0532b10f6748d00c80454a051ef63cc74a77780c
2020-10-22 22:26:02 +00:00
Mohd Faraz
815e24079b Fixes Decryption prompt asking when not needed
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
Change-Id: Ic366a50f02f283864cf44d7b36f40ff6432d4970
2020-09-24 16:08:07 -04:00
bigbiff
8da46fa939 Revert "Implement autodetection for SAR, based on the installed system"
Change-Id: I9e6c549013c1d5564d0a2e369510535e3869dff6
2020-09-09 20:13:12 -04:00
Mohd Faraz
e3948ece83 Fix up issue during decryption
* Since some devices are unable to decrypt after processing of the fstab,
   because of the partition details updation, and after intro of dynamic partitioning
   here decryption process was going on after complete processing of the dynamic volumes.

 * This patch fix these issue, it process the logical volumes at their time not after all processing fstabs.
   This fixes the decryption issue.
   Translate more partitions i.e., ODM, Product.
   Added more partitions in unmount partitions.

Change-Id: I977c0cf0c40e5311f54a78c98f1fd89f71c6ac57
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-09-09 22:49:37 +00: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
aac58612ea persist logs: remove persist from available log directories in
partitions.

Too many problems have been reported for TWRP attempting to store
logs in the persist partition. Selinux denials have caused issues
booting Android, and filling up persist has caused IMEI issues.

This patchset will remove persist from the list of available log
directories by default in order to avoid these and other possible
issues.

Change-Id: I29889d69f76270a8fbb764a79be3523821d8579c
2020-08-30 18:16:35 -04:00
DarthJabba9
43d70f4bc7 Exclude the dumpsys dumps from backups, to avoid error 255 when restoring data backups
Change-Id: I7a83b3789828c1400e31007e868263c54d8eb38c
(cherry picked from commit 13b07f8dbe27d85254e0a04f689a9ed6bde7673e)
2020-08-04 23:03:14 +00:00
bigbiff
5b911ca621 persist: contexts for lost+found not found when running e2fsdroid
When running e2fsdroid on persist, lost+found doesn't have any
entries in file_contexts. We are removing the lost+found directory
after a wipe now, and before the restore of the tar.
Change-Id: If5db0971884e296fae0211ff4806f3e16e394632

Change-Id: I9fa51dc9ef558cd82445df9a8fa377b1feda11aa
2020-07-19 09:32:13 -04:00
Mohd Faraz
e1d72623b7 Fix up cache wipe issue in A-Only device
* missed in 3754fabbea

Change-Id: I8fc3719e7f98c3d9b5fd96a9820b84773d4f5d7d
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit 25371a7e1f7f7d690755e3b12140b39567456a98)
2020-07-06 20:56:57 -04:00
bigbiff
25d25b9e67 log storage: change AB device log storage to /data/recovery
This patchset is now exlcuding /data/cache from backup, and removing it
from the wipe exclusion list to prevent errors on restore and wiping
/data.

This patchset changes the directory from /data/cache to /data/recovery for TWRP
to store logs and other file information. This will help with AB
devices that don't want recovery to mess with /data/cache.

This patchset will make ORS use /data/cache for AB devices.

Remove policy code because we don't need to set a policy for the
recovery directory.

Change-Id: I1d140276314fd34804a72297d6e25a52e58210a0
2020-07-07 00:55:42 +00: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
Captain Throwback
87d73d6620 FBE: set TW_IS_FBE based on whether key version path exists
- Should not be determined by whether support exists in TWRP
- Set to 0 by default if FBE is not detected

This also prevents the wrappedkey check from running
on FDE devices

Change-Id: I85d1952facdfafdaa1571fc1b11d4b4b7d9ba48e
(cherry picked from commit cf0dffce3413261f149a3565d8f27cb32490ae54)
2020-06-10 16:33:52 -04: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
bigbiff
adc599e005 Revert "Add support for multi-user decryption"
This reverts commit 0b25b1d79b.

Reason for revert: Changes need to be made to libtwrpfscrypt to include this patchset. Will cherry-pick this patch later and make necessary modifications.

Change-Id: I7601d7b820129709b05d9b4368573b6f1048de02
2020-05-28 19:36:30 +00:00
Noah Jacobson
0b25b1d79b Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

Change-Id: Id2681bc2b1012a0571417f7a6e0b980b1b25c61c
(cherry picked from commit 5a79f67a1b1bd1bcadeca0a4896a871646652534)
2020-05-20 19:11:15 -04:00
mauronofrio
fc79aa6375 Encryption: don't try wrapped key if not needed
This commit is used to directly use the wrapped key
decryption when the "wrappedkey" flag is set in the
fstab.

Change-Id: I74310c3bbec378ee684a8f6d0395a9776dd22abf
(cherry picked from commit 1db943295de9728e364bf0e75bfe9f1a98d413a1)
2020-05-13 00:40:25 +00:00
Peter Cai
28ea7b000a partition: set fbe.data.wrappedkey automatically via flag
In change I79c2855d577156670b45c10c7c7b1fcd9fece8d9 we introduced a
property to enable wrappedkey mode. This change supports an extra
`wrappedkey` flag in fstab to automatically set the property to true.

Change-Id: I4f060d4ed6b2a5680649b8746dfa7fd903fe2d35
(cherry picked from commit 40ed06e850de2dc7cc06c2e647688212563f1ec2)
2020-05-13 00:39:19 +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
dianlujitao
b76a73a1a9 Fix backup and restore after autodetection for SAR
This reverts commit 8a411c8d25.

 * Always use "/system" to interact with the frontend and replace it
   with the detected path before taking actions.
 * Don't replace the pretty display name and backup name set during
   processing fstab after wipe. This improves UX and ensures that the
   system backup is always named system.ext4.win despite the actual
   mount point is /system_root so TWRP is able to recover either SAR or
   non-SAR backups.

Change-Id: Ie2594d2678d0c75ce25c0d1087d47b035b3f10e9
2020-05-10 21:35:01 +00:00
Chaosmaster
f6e42ce390 Implement autodetection for SAR, based on the installed system
This will detect whether SAR is present in the currently installed
OS and set the property ro.twrp.sar accordingly.
After setting the property it will call the bootscript
/sbin/sarsetup.sh (if present) to give device maintainers the
option to do setup operations depending on SAR-status, such
as modifiyng the fstab.

If no system is detected and AB_OTA_UPDATER is defined or built with
Android 10 and upwards, it will fallback to using SAR, otherwise it
will use ro.build.system_root_image as basis for deciding whether SAR
is required or not.

The property ro.twrp.sar will also be used by
TWPartitionManager::Get_Android_Root_Path()

This allows maintaining a single TWRP-build for devices switching
to SAR for Android 10.

The default behavior (when no system is installed)
is determined by the build-flags AB_OTA_UPDATER and
BOARD_BUILD_SYSTEM_ROOT_IMAGE

Change-Id: I2a48c6c81a6ea6fad6e452c06bfbe4d9da0f1e5c
2020-05-10 15:43:56 -04:00