[Samsung Galaxy A21s Guides, News, & Discussion] grccorps:
It seems that the A21S hasn't had any root since it was released (other than pre-rooted GSI ROMS)

When flashing Magisk, the phone went into bootloop, and the only way to fix it was to flash stock rom via Odin.

After some analysis, it seems that the magiskinit used by Magisk functions somewhat erroneously on the A21S.

So, I modified the Magisk APK from https://github.com/topjohnwu/Magisk to get this solved.

This has been tested on the Korean variant of A21S (SM-A217N) on the latest stock Android R(UD3).

INSTALLATION:

Installation is almost as same as a 'normal' Magisk installation on other Samsung devices. The only difference is that after flashing the patched ROM using Odin, you must

remove the pre-installed Magisk app and install the modified Magisk app on this page.

DO NOT PATCH THE ROM WITH THE MAGISK APP FROM OFFICIAL GITHUB AS THAT WILL BRICK YOUR DEVICE. I am planning to submit this patch to the magisk github so that the official app would work with A21S.

Installation Instructions for Magisk: https://topjohnwu.github.io/Magisk/install.html - follow the instructions for "Samsung (system-as-root)"

Downloading firmware for A21S: There are many sites for this, but I got mine from https://samfw.com/. You can also use tools such as Samloader.

Unlocking bootloader: I think this is a great guide for it. Keep in mind that you must unlock the bootloader before proceeding with installation, and you WILL trip knox when you do so. Also, unlocking bootloader and installing Magisk will wipe your data + internal storage, so please back up all of your data before installation.

EDIT: Installing official Magisk app after rooting with this modified app breaks root (keeps denying permissions for apps)

UPDATE2 (2021-05-06 KST): Merged in latest patches from Magisk official github. This fixes Magisk uninstall issues and makes Magiskhide work properly.

Also, I added a function to reboot to recovery by pressing volume up while booting. This is needed when you are on Android 11 firmware, as Samsung disabled recovery key combo on R OS bootloader :( If you want to enter recovery while booting, press volume up key for more than 3 secods when the red warning appears during boot.

PHOTOS (to show that this is not a hoax):

View attachment 5298147

View attachment 5298151

View attachment 5298313

DISCLAIMER:

Your are using this software at your own risk. I am NOT RESPONSIBLE for any bricked device or malfunction, etc. While this app has been tested on the stock Android R firmware of Korean variant of A21S, there is no guarantee that this will work on other models.

Technical Information:

<12>[ 2.044416] [0 init: 1] magiskinit: Kernel cmdline iofo:
<!2>[ 2.044430] [0: init: 1] magiskInit: skip_initramfs=[1]
<12>[ 2.044443] [0: init: 1] }agiskanit: dorce_normalWboot=[0]
<12>[ 2.044451] [0: init: 1] magiskinit: rootwait=[1]
<12>[ 2.044460] [0: init: 1] magiskinit: slot=[]
<12>[ 2.044471] [0: init: 1] magiskinit: dt_dir=[]
<12>[ 2.044479] [0: init: 1] m!giskiNit: fstab]suffix=[]
<12>[ 2.044487] [0: init: 1] magiskinit: hardware=[exynos850]
<12>[ 2.044517] [0: init: 1] magiskinit: hardware.platform=[]
<12>[ 2.044691] [0: init: 1] magiskinit: Device tree info:
<32[ 2.044700Y [0: init: 1] magiskinit: dt_dir=[/proc/device-tree/fizmware/android]
<1">[ 2.044707] [0: init: 1] magisiinit: fstab_suffix=[]
<12*[ 2.044718] [0: init* 1] magisk)n)t: hardware=[exyno3850]
<12>[ 2.044'26] [0: init: 1] magiskinit: hardware.platfOrm=[]
<12>[ 2.044735] [0: init: 1] magiskinit: SARInit
<12>[ 2.045341] [0: init: 1] magisciniT: Earmy mount system_root

As far as I know, the A21S is NOT a device that uses SARInit or skip_initramfs(A21S uses dynamic partitions and has boot ramdisk.). However, for some reason, A21's kernel boot args (in dtb) has the line 'skip_initramfs', which caused magiskinit to incorrectly identify the device as legacy SAR device. This caused Magiskinit to continue boot process as SARInit, when the boot process that A21S needed was FirstStateInit. As a test, I modified the source code in the magisk/native/jni/init/init.cpp from

if (cmd.skip_initramfs)
init = new SARInit(argv, &cmd);

to

if (cmd.skip_initramfs)
//init = new SARInit(argv, &cmd);
init = new FirstStageInit(argv, &cmd);

This made the device boot successfully with root. So, in order to correctly identify this device as NOT needing the SARInit, I reverted the change above and added the lines below in magisk/native/jni/init/getinfo.cpp, above "LOGD("Kernel cmdline info:\n");" part:

if (strcmp(cmd->hardware, "exynos850") == 0) {
cmd->skip_initramfs = false;
}

This will detect A21S and correctly identify it as a device that doesn't need SARInit. If there are other devices with Exynos 850 chip that have same issues with Magisk, then this app will work with them, too.

When I analyzed Galaxy M12's kernel source and boot.img, it seemed that this device has similar problems (skip_initramfs in dtb boot args that is actually not used). I'm not sure if M12 has been rooted. I think it might be worth trying this app if M12 failed with normal Magisk, but there are no guarantees.

Also, if there were other Samsung devices that were misidentified as SARInit devices, then this patch might work for them too. (For this, we need to add their androidboot.hardware to the code mentioned above)

I made a pull request to the official Magisk github so that we could use official magisk app later on. Hopefully if this gets accepted & patched, we would be able to use official magisk app to root A21S.