Skip to content

Commit f74a95a

Browse files
committed
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>
1 parent e3b424a commit f74a95a

File tree

3 files changed

+227
-74
lines changed

3 files changed

+227
-74
lines changed

README.md

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@
99

1010
**What is Boot Image Flasher?**
1111

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.
1313

1414
### Key Features
1515

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.
2021

2122
### Prerequisites
2223

2324
- 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.
2526

26-
### Usage
27+
## Methods of Use
2728

2829
#### Method 1: Via Termux
2930

@@ -34,41 +35,81 @@ Boot Image Flasher is a shell script designed to simplify the process of flashin
3435
```
3536
3. Download the script and necessary tools using the following command:
3637
```bash
37-
curl -s https://raw.githubusercontent.com/gitclone-url/Boot-img-flasher/Master/boot-img-flasher.sh -o boot-img-flasher.sh && { command -v tput figlet &>/dev/null || pkg install -y figlet ncurses-utils; } && { which sudo &>/dev/null || pkg install -y tsu; }
38+
curl -s https://raw.githubusercontent.com/gitclone-url/Boot-img-flasher/Master/boot-img-flasher.sh -o boot-img-flasher.sh && \ { command -v tput >/dev/null && command -v figlet >/dev/null && command -v file >/dev/null || pkg install -y figlet file ncurses-utils; } && \ { command -v sudo >/dev/null || pkg install -y tsu; }
3839
```
39-
> **Note:** It may take some time for the script to be downloaded first along with the required tools. Please be patient.
40+
> **Note:** It may take some time for the script to be downloaded, along with the required tools. Please be patient.
4041
41-
4. Run the script by executing:
42+
43+
##### Running the Script:
44+
45+
**Basic usage:**
4246
```bash
43-
sudo bash boot-img-flasher.sh
47+
boot-img-flasher.sh [-h|--help]
48+
49+
boot-img-flasher.sh <IMAGE_PATH> --image-type <TYPE>
4450
```
45-
> **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` &nbsp;&nbsp; Display help message with usage information.
53+
- `-t`, `--image-type` &nbsp;&nbsp; Manually specify the type of image to flash.
54+
55+
Arguments:
56+
- `<IMAGE_PATH>` &nbsp;&nbsp; Path to the boot or init_boot image file.
57+
- `<TYPE>` &nbsp;&nbsp; Must be either `boot` or `init_boot`.
58+
----
4659

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:**
63+
64+
```bash
65+
sudo bash boot-img-flasher.sh /path/to/boot.img --image-type boot
66+
```
67+
68+
2. **Flash an image from current directory by only specifying type:**
69+
70+
```bash
71+
sudo bash boot-img-flasher.sh -t init_boot
72+
```
73+
74+
**Or flash by only specifying path (type will be auto-determined):**
75+
76+
```bash
77+
sudo bash boot-img-flasher.sh /path/to/init_boot.img
78+
```
79+
80+
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.
4887

4988
#### Method 2: Magisk
5089

5190
1. Download `boot_flasher.zip` from [here](https://github.com/gitclone-url/Boot-img-flasher/raw/Master/boot_flasher.zip).
5291
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.
5493
4. Select all files inside the folder and archive them as a zip.
5594
5. Install the zip as a Magisk module.
5695
6. Restart your device.
5796

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+
5899
### Preview
59100

60101
Below are some screenshots demonstrating the Boot Image Flasher in action:
61102

62103
<div style="display: flex; justify-content: space-around;">
63-
<img src="https://github.com/gitclone-url/Boot-img-flasher/assets/98699436/e4f328e9-dc48-4835-a47d-edbad2729d04" width="200" alt="Preview 1" />
64-
<img src="https://github.com/gitclone-url/Boot-img-flasher/assets/98699436/cbcad4f5-c35a-4254-9ee3-5d5c8a8ce6ef" width="200" alt="Preview 2" />
104+
<img src="https://github.com/user-attachments/assets/2f39d431-4d08-4084-bb81-69149ecb9748" width="200" alt="Preview 1" />
105+
<img src="https://github.com/user-attachments/assets/b2356962-9160-4e17-bed9-c47b1088ae9a" width="200" alt="Preview 2" />
65106
</div>
66107

67108
### Additional Information
68109

69-
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.
70111

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.
72113
73114
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).
74115

@@ -90,4 +131,4 @@ Contributions are welcome. Please fork the repository, make your modifications,
90131

91132
### Contact
92133

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

Comments
 (0)