[ROOT] Modified Magisk for Galaxy A21S (R)

Search This thread

grccorps

Member
Mar 1, 2012
47
64
Seoul
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):

Screenshot_20210503-210736_Settings.jpg


Screenshot_20210503-210210.jpg

Screenshot_20210504-001758.jpg


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:
Code:
<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
C++:
if (cmd.skip_initramfs)
   init = new SARInit(argv, &cmd);
to
C++:
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:
C++:
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.
 

Attachments

  • Magisk_patched_for_A21S.apk
    6.3 MB · Views: 5,568
Last edited:

thatha

Senior Member
Jul 14, 2010
195
38
SGN
Redmi 9
I confirm that I have rooted my A21S sucessfully using this modified magisk (U3 Rom). No need to patch the whole AP.tar file, just patch boot.img file only. I upload my patched boot.img for those who need it. Just flash it via odin in AP slot. Thank you very much grccorps.
 

Attachments

  • boot.tar
    36 MB · Views: 3,653

thatha

Senior Member
Jul 14, 2010
195
38
SGN
Redmi 9
For U5 boot.tar:
 
Last edited:

grccorps

Member
Mar 1, 2012
47
64
Seoul
I updated the modified Magisk app with the latest changes from the official Magisk github, so you should update to the latest app attached at the OP. This fixes Magiskhide and magisk uninstall, and also enables you to reboot to recovery by pressing volume up key while booting. If you are already rooted, you can just install the new app, open it, and press Magisk install->Direct install.
 
  • Like
Reactions: cater2 and thatha

thatha

Senior Member
Jul 14, 2010
195
38
SGN
Redmi 9
I updated the modified Magisk app with the latest changes from the official Magisk github, so you should update to the latest app attached at the OP. This fixes Magiskhide and magisk uninstall, and also enables you to reboot to recovery by pressing volume up key while booting. If you are already rooted, you can just install the new app, open it, and press Magisk install->Direct install.
Thank you very much
 

Olep84

Member
May 6, 2021
7
0
Hi,

I have a big problem, and hope anyone can help me.
I tried the above method, but now I stock in a boot loop, I can acces recovery menu (volume +) but not be able to flash stock firmware.
How can I flash stock firmware in recovery, or is there a way to come in to download mode?

data swipe is no problem, please help

stock imag.PNG
 

grccorps

Member
Mar 1, 2012
47
64
Seoul
Hi,

I have a big problem, and hope anyone can help me.
I tried the above method, but now I stock in a boot loop, I can acces recovery menu (volume +) but not be able to flash stock firmware.
How can I flash stock firmware in recovery, or is there a way to come in to download mode?

data swipe is no problem, please help

View attachment 5301431
You cannot flash firmware in stock recovery. The only thing it allows you to do is wipe data.
If you want to flash stock firmware, you need to go to download mode and use Odin.

Are you having problems after flashing odin? You need to wipe data once after flashing patched firmware.
 

Olep84

Member
May 6, 2021
7
0
Thanks for information,
I was now able to get into download mode, and flashed stock FW with odin.
and the device is booting :)

I think my mistake was extract by winrar and not 7zip.
I try again ;)
 
Last edited:

Olep84

Member
May 6, 2021
7
0
OK, I stock again by that screen....

flashed back to stock, and do all the named steps again.

what is my mistake? I patched the AP . tar with the special Magisk, copy with ADB back to PC and flash it with Odin.
Do I need something to do with the magisk-patched file before flashing??

I used the BL, CSC, and CP form Stock, and the AP patched magisk
 

Bluebloomer

Member
Jul 17, 2018
13
0
47
Eindhoven
Samsung Galaxy A21s
Hi,

I have a big problem, and hope anyone can help me.
I tried the above method, but now I stock in a boot loop, I can acces recovery menu (volume +) but not be able to flash stock firmware.
How can I flash stock firmware in recovery, or is there a way to come in to download mode?

data swipe is no problem, please help

Hi,

I have a big problem, and hope anyone can help me.
I tried the above method, but now I stock in a boot loop, I can acces recovery menu (volume +) but not be able to flash stock firmware.
How can I flash stock firmware in recovery, or is there a way to come in to download mode?

data swipe is no problem, please help

View attachment 5301431
I have an A21s, finaly managed to install Android 11, but same problem after patching the AP file. Used ADB PULL, unlocked bootloader before, latest Magisk (22100) but had to reflash stock again. Too bad, I miss root on my new phone !
 

thatha

Senior Member
Jul 14, 2010
195
38
SGN
Redmi 9
OK, I stock again by that screen....

flashed back to stock, and do all the named steps again.

what is my mistake? I patched the AP . tar with the special Magisk, copy with ADB back to PC and flash it with Odin.
Do I need something to do with the magisk-patched file before flashing??

I used the BL, CSC, and CP form Stock, and the AP patched magisk
What do you want to do ? If you want to root your phone, just patch the boot.img and flash it via odin in AP slot
 

Olep84

Member
May 6, 2021
7
0
How do I patch boot.img?
Extract, copy to phone and use magisk from this post?

the U5 boot.img linked above, can not be used on my device, Odin response fail when try to flash as AP

Sorry I do not have much experience with Android, I like to use the phone in my car with AA Mirror and therefore I need root to work properly.

Thanks
 
Last edited:

thatha

Senior Member
Jul 14, 2010
195
38
SGN
Redmi 9
How do I patch boot.img?
Extract, copy to phone and use magisk from this post?

the U5 boot.img linked above, can not be used on my device, Odin response fail when try to flash as AP

Sorry I do not have much experience with Android, I like to use the phone in my car with AA Mirror and therefore I need root to work properly.

Thanks
 

grccorps

Member
Mar 1, 2012
47
64
Seoul
OK, I stock again by that screen....

flashed back to stock, and do all the named steps again.

what is my mistake? I patched the AP . tar with the special Magisk, copy with ADB back to PC and flash it with Odin.
Do I need something to do with the magisk-patched file before flashing??

I used the BL, CSC, and CP form Stock, and the AP patched magisk
You have followed the correct instructions from official Magisk website. Considering that the volume up to reboot recovery worked, the modification that I made to Magiskinit is working, but something else is causing boot loop. What is your device's model no. and what firmware does it have? I think this might be another problem that needs further examination.
 
Last edited:

grccorps

Member
Mar 1, 2012
47
64
Seoul
OK, I stock again by that screen....

flashed back to stock, and do all the named steps again.

what is my mistake? I patched the AP . tar with the special Magisk, copy with ADB back to PC and flash it with Odin.
Do I need something to do with the magisk-patched file before flashing??

I used the BL, CSC, and CP form Stock, and the AP patched magisk
Could you please upload the boot.img from the AP file that you patched with magisk? This might give a better look into this problem.
 

prestigexda

Member
Nov 29, 2019
11
0
23
does anyone know if this will work on a BTU galaxy a21s?, its just a retail one i put a sim in from uk and i really wanna root it and this is my only phone
 

Top Liked Posts

  • There are no posts matching your filters.
  • 13
    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):

    Screenshot_20210503-210736_Settings.jpg


    Screenshot_20210503-210210.jpg

    Screenshot_20210504-001758.jpg


    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:
    Code:
    <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
    C++:
    if (cmd.skip_initramfs)
       init = new SARInit(argv, &cmd);
    to
    C++:
    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:
    C++:
    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.
    2
    I updated the modified Magisk app with the latest changes from the official Magisk github, so you should update to the latest app attached at the OP. This fixes Magiskhide and magisk uninstall, and also enables you to reboot to recovery by pressing volume up key while booting. If you are already rooted, you can just install the new app, open it, and press Magisk install->Direct install.
    2
    Also, can you help me with this?

    I have come across a very strange phenomena on Galaxy M12. When I install an app as user it exists in /data/app forder in a weird way. The folders in /data/app are like ~~h8DR1aXXIZfV_DXfqwYf3g== (see attachment) and in these folders there is another folder with the app package name. On regular devices I hvae seen app package folder in /data/app itself.

    When I copy the app package folder from /data/app/~~h8DR1aXXIZfV_DXfqwYf3g== to /system/app it does not work. I can see the app folder after reboot or even reset but app in not installed on the system. I have confirmed by running the activity using 'am' and tried listing with 'pm'. I have also given same permissions as other app folders in /system/app. I have also tried /system/app~~h8DR1aXXIZfV_DXfqwYf3g==.

    Edit: As it turns out when I am copying to /system/app the base.apk is not copied properly. I have tried it multiple time, the system is mounted. Whatever I do it is either 0 kb or 100 kb exactl and the file is ~6mb. Still strange behaviour.
    I'd recommend you to use a file explorer (I use Mixplorer) to copy the "base.apk" to /sdcard and then install the "Terminal Systemizer" module in magisk manager, then in a terminal, you type "su", then "systemize" and choose the 3rd option and type the path to the app (In this case it's /sdcard/base.apk)

    You're not the only one with this problem and I've managed to workaround it
    2
    @Steker Unik @F308 @Malaahim @Knockout Newbie @panda822 @platonicbomb @wonkeyeyes @Subliminize @kcchan48 @johnny_nb @Israelleite @heats @David112+ @ankush1492 @Jukmisael @geocamus @Wowoslaw @cater2 @MaBo2020 @Devilrock09 @Elkingb @thatha @Jaan_e_ahsan45 @Olep84 @Bluebloomer

    Hello everybody there, this is the latest magisk manager canary build v24.1 f880b575, as feature of zygisk (Beta) has been finally introduced and other changes are to be added.. as the compiled app is tested by me and woks fine for me. you people can upgrade your magisk manager to v24.1 easily, to see whats new please refer magisk manager github page.
    Thankyou :)

    photo_2022-01-29_00-54-18.jpg
    1
    @sahil_bhandari
    This new exploit has a probability to root the device without having to unlock the bootloader.
    Specific process is unknown but there needs to be some changes for the kernel?

    Could someone look into this?