You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add support for flashing init_boot images and enhance CLI
Description:
- Added support for flashing `init_boot` images alongside `boot` images.
- Introduced `--image-type` flag, allowing users to specify either `boot` or `init_boot` as the image type.
- Added `print_usage()` function to display script usage instructions and options
- Implemented `parse_arguments()` function for handling user-specified arguments and flags:
- supports both short (-h, -t) and long (--help, --image-type) option formats.
- Processes help option, image type option, and image path.
- Handles errors for invalid or unexpected arguments. Uses the `exit_with_error` function to display error messages and exit the script.
- Calls `validate_arguments()` when an image path or type is provided by the user.
- `validate_arguments()` ensures:
- The image type is either `boot` or `init_boot`.
- The specified image file exists and has a `.img` extension.
- Finally sets environment variables IMAGE and IMAGE_TYPE based on the provided arguments input.
- Added a new function `determine_image_type()`:
- First tries to use the `file` command to identify the image type based on its contents.
- If `file` is not available or can't determine the type, it falls back to a size-based heuristic.
- The size-based heuristic assumes that init_boot images are typically smaller than boot images. The threshold (10MB in this case).
- Renamed `find_boot_block` → `find_partition_block` to better align with its purpose and consistency.
- Refactored `find_boot_image` to `processImageFile`:
- Uses IMAGE and IMAGE_TYPE variable values if set by `parse_arguments()`.
- Separated Termux and Magisk environment-specific code into two functions `magisk_env()` and `termux_env()`.
- Execute Magisk-related code if `DEBUG` variable is set and true; otherwise, execute `termux_env()` to search for the image in the current directory if the image variable is empty.
- Determines image type if not provided, using file name or `determine_image_type()`.
- Returns both image path and image type.
- Updated logic in `main()`:
- Calls `parse_arguments()` to process and validate arguments only in Termux.
- Reads image path and image type values from `processImageFile()` and assigns them locally.
- Display the provided image file name.
- Calls `find_partition_block()` with the image type and the value of the slot variable.
- Improved overall user feedback messages and minor changes in variable names.
Signed-off-by: Abhijeet <98699436+gitclone-url@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+60-19Lines changed: 60 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,21 +9,22 @@
9
9
10
10
**What is Boot Image Flasher?**
11
11
12
-
Boot Image Flasher is a shell script designed to simplify the process of flashing boot images on Android devices, supporting both A/B and legacy (non-A/B) devices. typically, flashing boot images involves using custom recovery or fastboot, which can be complex and time-consuming. This script eliminates the need for those methods, offering a straightforward, efficient, and user-friendly solution.
12
+
Boot Image Flasher is a shell script designed to simplify the process of flashing boot and init_boot images on Android devices, supporting both [A/B](https://source.android.com/devices/tech/ota/ab) and [legacy (non-A/B)](https://source.android.com/devices/bootloader/partitions) devices. Typically, flashing these images involves using custom recovery or fastboot, which can be complex and time-consuming. Furthermore many devices lack custom recovery support, and accessing fastboot often requires a PC. Boot Image Flasher addresses this issues by providing a straightforward, efficient, and user-friendly solution for Android enthusiasts and developers that operates directly on the device. The core functionality and image flashing logic of this script is based on Magisk's utility functions. Other well-known rooting applications like [KernelSU](https://github.com/tiann/KernelSU) and [APatch](https://github.com/bmax121/APatch) also use the same approach.
13
13
14
14
### Key Features
15
15
16
-
-**Automated and User-Friendly:** Simplifies the boot image flashing process with minimal user intervention.
17
-
-**Broad Device Support:** Compatible with any Android device, including both A/B and legacy (non-A/B) partition styles.
18
-
-**Saves Time and Effort:** Reduces the time and complexity involved in flashing boot images using fastboot or custom recoveries, making it accessible for users with varying levels of technical expertise.
19
-
-**Flexible Usage:** Can be used via Termux or flashed as a Magisk module, providing flexibility based on user preferences.
16
+
-**Supports dual partition flash:** capable of Automatically detecting and flashing both init_boot and boot images.
17
+
-**Automated and User-Friendly:** Simplifies the image flashing process with minimal user intervention.
18
+
-**Universal Compatibility:** works on any Android device, including both A/B and legacy (non-A/B) partition styles.
19
+
-**Saves Time and Effort:** Reduces the time and complexity involved in flashing boot and init_boot images using fastboot or custom recoveries, making it accessible for users with varying levels of technical expertise.
20
+
-**Flexible Usage:** Can be used via Termux with command-line options, or flash over like a module in magisk, providing flexibility based on use case and preferences.
20
21
21
22
### Prerequisites
22
23
23
24
- An Android device with root access.
24
-
- To use in Termux, `figlet` and `ncurses-utils` need to be installed if not already available.
25
+
- To use in Termux, `figlet`, `file` and `ncurses-utils` need to be installed if not already available.
25
26
26
-
### Usage
27
+
##Methods of Use
27
28
28
29
#### Method 1: Via Termux
29
30
@@ -34,41 +35,81 @@ Boot Image Flasher is a shell script designed to simplify the process of flashin
34
35
```
35
36
3. Download the script and necessary tools using the following command:
> **Optional Argument:** You can also specify the path to your boot image as an argument. If you don't provide one, the script will search for the boot image in the current directory.
51
+
Options:
52
+
-`-h`, `--help` Display help message with usage information.
53
+
-`-t`, `--image-type` Manually specify the type of image to flash.
54
+
55
+
Arguments:
56
+
-`<IMAGE_PATH>` Path to the boot or init_boot image file.
57
+
-`<TYPE>` Must be either `boot` or `init_boot`.
58
+
----
46
59
47
-
5. Restart your device after the flashing process is complete.
60
+
#### Examples of Use:
61
+
62
+
1.**Flash an image by providing the image path and it's type:**
3.**Flash an image from current directory without providing any argument:**
81
+
82
+
```bash
83
+
sudo bash boot-img-flasher.sh
84
+
```
85
+
86
+
Once flashing process is completed you may restart your device.
48
87
49
88
#### Method 2: Magisk
50
89
51
90
1. Download `boot_flasher.zip` from [here](https://github.com/gitclone-url/Boot-img-flasher/raw/Master/boot_flasher.zip).
52
91
2. Extract the archive using an app like [ZArchiver](https://play.google.com/store/apps/details?id=ru.zdevs.zarchiver).
53
-
3. After extracting, copy and paste your `boot.img` inside the created folder.
92
+
3. After extracting, copy and paste your `boot.img`or `init_boot.img` file inside the created folder.
54
93
4. Select all files inside the folder and archive them as a zip.
55
94
5. Install the zip as a Magisk module.
56
95
6. Restart your device.
57
96
97
+
> **Note:** It is recommended that the image file is properly named as either `boot` or `init_boot` to avoid errors, as the script may not always auto-detect the image type if not specified.
98
+
58
99
### Preview
59
100
60
101
Below are some screenshots demonstrating the Boot Image Flasher in action:
Some GSIs (Generic System Images) based on PHH come with prebuilt root access, meaning the `su` binary is already included in the system. If you are using one of those GSIs and your phone is not actually rooted with Magisk or other root providers, you can just patch the boot image of your phone and then flash the patched boot image using this script, with root permissions granted through the PHH Superuser App. This way, you can easily root using Magisk or other rooting apps just by using your device without needing additional tools, a PC, or any hassles.
110
+
Some GSIs (Generic System Images) based on PHH come with prebuilt root access, meaning the `su` binary is already included in the system. If you are using one of those GSIs and your phone is not actually rooted with Magisk or other root providers, you can just patch the boot/init_boot image of your phone and then flash the patched image using this script, with root permissions granted through the PHH Superuser App. This way, you can easily root using Magisk or other rooting apps just by using your device without needing additional tools, a PC, or any hassles.
70
111
71
-
> **Note:** For patching the boot image, you can use either [Magisk](https://github.com/topjohnwu/Magisk) or [APatch](https://github.com/bmax121/APatch) app.
112
+
> **Note:** For patching the boot or init_boot image, you can use either [Magisk](https://github.com/topjohnwu/Magisk) or [APatch](https://github.com/bmax121/APatch) app.
72
113
73
114
For information about GSIs, check the [FAQ](https://github.com/phhusson/treble_experimentations/wiki/Frequently-Asked-Questions-%28FAQ%29) and choose your specific GSI image from [here](https://github.com/phhusson/treble_experimentations/wiki/Generic-System-Image-%28GSI%29-list).
74
115
@@ -90,4 +131,4 @@ Contributions are welcome. Please fork the repository, make your modifications,
90
131
91
132
### Contact
92
133
93
-
For support, inquiries, or suggestions, contact the developer via [Telegram](https://t.me/PhantomXPain).
134
+
For support, inquiries, or suggestions, contact the developer via [Telegram](https://t.me/PhantomXPain).
0 commit comments