[Samsung Galaxy Tab A series Guides, News, & Discus] Scarecrow9000:
/*** BEGIN DISCLAIMER ***/

If you follow this procedure and lose every bit of content on your device / end up with a fancy paperweight, I, nor anyone involved with the referenced open source or otherwise licensed projects is responsible. It's all on you, and this will void your warranty. Do not proceed if you don't understand something. Chances are you will have a bad time.

/*** END DISCLAIMER ***/

Hey everyone - my Samsung Galaxy Tab A 10.1" (2019) - SM-T515 - recently applied a security update without my consent (The Samsung Android 11R September 8th 2021 Security update - side note, make sure that you turn off Samsung's push service 😅), which canned my previous root access. I use server software and internal port forwarding to do... Things on my device, so I needed my root access back.

Here's how I retrieved it, and how I put TWRP in place as my recovery partition in the process.

The Tools

Make sure you have these before you start. Because this is a Samsung device, you'll have to do some things under Windows, like using Frija and Odin (unfortunately).

1.) Frija - Available here - https://xdaforums.com/t/tool-frija-samsung-firmware-downloader-checker.3910594/

2.) The latest SM-T515 / SM-T510 firmware from Samsung for your device's CSC (if you use the firmware for the wrong CSC code the most common problem that I have seen as a result is typically incorrect partition sizes after flashing, which can be corrected with TWRP). Frija is listed first, because you'll use Frija to get this directly from Samsung.

3.) Some kind of generic tool that you're comfortable with for working with archives. Ideally whatever tool you choose should be able to work with .tar, .gz, and .zip archives for this process. Personally I like 7-Zip on *Nix and Windows, and ZArchiver on Android.

4.) Odin (firmware flash tool by Samsung) - attached.

5.) The latest Samsung device USB drivers for your environment (they're fine as long as they enable both ADB and MTP correctly) - available here https://developer.samsung.com/mobile/android-usb-driver.html

6.) The latest TWRP image for Samsung SM-T5xx devices - available here https://androidfilehost.com/?fid=14943124697586374577 (and attached)

7.) ADB - downloading / installing and using adb are outside the scope of this post. It is available here - https://xdaforums.com/t/official-to...vers-15-seconds-adb-installer-v1-4-3.2588979/

8.) The latest Magisk APK file - available here https://github.com/topjohnwu/Magisk/releases/download/v23.0/Magisk-v23.0.apk

The Process

0.) Back up your stuff, and remove your SD card if it makes you more comfortable - do whatever you need to do to be comfortable with "I might lose EVERYTHING on this device." If you plan on following this procedure, you should know how to do this, and I'm not going to try to explain it. If you can't get past this part, you should stop while you're ahead and still have a device that boots.

1.) Unlock your bootloader.

2.) Download the most recent firmware package for your device using Frija and extract all of the individual .md5 files which it contains.

2.) Use Odin to flash the most recent firmware to your device, and factory reset / wipe / format partitions and caches until you have a clean device that boots correctly. If your partitions aren't sized properly at this point it isn't something to be too concerned with, as you can correct them later using TWRP.

3.) Turn developer options back on, enable USB debugging, set the default USB configuration to "File Transfer", connect your device to your PC and copy the Magisk APK over to the internal storage of your device.

4.) Remove .md5 from the filename of the AP file that was included in your firmware package from Samsung and extract its contents into its own directory.

5.) Extract the contents of the latest TWRP package for these devices into the same directory where you extracted the individual partition image files contained in the AP file. Overwrite contents in the destination directory as necessary. The TWRP package should contain three files - param.bin.lz4, recovery.img.lz4, and vbmeta.img.lz4 - If there are uncompressed images (.img files) that correspond to the LZ4 compressed images from the TWRP package in the AP file of your firmware package, remove them first. Odin will (understandably) freak out if you try to flash two different images to the same partition in the same flash operation.

6.) Compress the contents of your modified AP directory which now contains the TWRP package's contents into a tar ball on your PC, and then copy it somewhere that Magisk will be able to access it on the Internal storage of your device (the Downloads directory - "/storage/emulated/0/Downloads/" is a good choice).

7.) Copy the latest Magisk APK to your device (again, the Downloads directory is a good choice), and then install it on your device.

8.) Launch Magisk on your device and choose "Install". Be sure to uncheck the "Recovery Mode" option. We don't want to use "Recovery mode" for Magisk's patching process. Even though this is a Samsung device and this would normally be how to proceed, in this case we're using our own custom TWRP recovery partition, and we don't want Magisk to mess with it. So make sure you aren't patching the bootloader or recovery images in unnecessary ways with Magisk.

9.) In Magisk on your device, choose "Select and patch a file" and then choose the AP file that you created and copied to the device which now contains TWRP as its recovery partition.

10). Let Magisk do its patching and when it has completed take note of where the patched file which it generated was written.

11.) Launch a command line / Powershell / Bash terminal where you can perform ADB commands, and issue the command "adb pull "/storage/emulated/0/Download/magisk_patched-23000_xYzXyZ.tar" (replace "XyZxYz" with whatever random sequence of characters that Magisk generated during its patching operations) to use ADB to download the patched AP file from your device.

12.) Power off your device.

13.) Reboot your device into FANCY download mode by holding the volume up and volume down keys simultaneously while inserting a USB cable that is connected to your PC into your device's USB C charger port. Your device should boot as you insert the USB cable and your bootloader should already be unlocked, so when prompted press the volume up button to continue.

14.) Launch Odin on your PC, and choose the BL, CP, CSC, and UserData images from the firmware package that you retrieved from Samsung to flash the corresponding slots in Odin. In the AP file slot, choose the Magisk patched AP file which contains TWRP as its recovery partition which you retrieved previously using ADB.

15.) Start the flash operation in Odin, and wait patiently for it to complete. Stay alert, because if you left "Auto reboot" checked in the Odin options, your device will reboot immediately upon completion, and there are actions that you need to take while the device is in its "off" state before it re-launches itself.

16.) Once the Odin flash operation has completed, boot to recovery mode. If you left "Auto reboot" checked in Odin, immediately as the flash operation completes, press and hold the power key and the volume up key and remove the USB cable from the device. Otherwise press and hold the power button and the volume down button until the device restarts, and while the device is in its "off" state remove the USB cable and press and hold the power button and the volume up button during device restart to enter recovery mode.

17.) Immediately upon entering recovery mode you should see TWRP do a couple of things that ensure that Samsung's device protection solutions don't remove it. Once those operations have completed, reboot into the system partition.

18.) Your device should be BASICALLY ready to go. Go through the steps to "complete" setup as you see fit. If you have not already done so, connect your device to a WiFi or to an LTE network and then launch the Magisk application.

19.) Magisk may want to download updates, if it does, let it do so.

20.) Once any necessary updates / downloads have completed, re-launch Magisk and it should present you with a prompt to the effect of "Magisk is installed, but additional configuration needs to be done on your device for it to work the right way. Do you want to reboot now?" If you've made it this far, the answer is "Yes, please do."

21.) After rebooting, your device will now be configured, and be running TWRP in its recovery partition, along with a properly Magisk rooted system partition.

22.) ????

23.) PROFIT!

I hope this helps some people out!

- The Scarecrow - 2021/09/22