Manual flashing

From postmarketOS
Note If you only need to slightly adjust the way pmbootstrap runs a flasher, you can grab the exact command it uses from the pmbootstrap log and modify it when running manually.

Sometimes you just need to flash ready system image externally. Export the images that pmbootstrap generated with pmbootstrap export and read on, how to call the flashing application from your host OS.

Fastboot

See fastboot --help, and expand this section if you find out something that would have helped you.

LineageOS Recovery can be flashed with Odin. From LOS Recovery you can enter userspace fastbootd to flash .img files via fastboot. This was implemented in Android 10, provided the recovery supports entering into fastbootd. Yes, fastboot on a Samsung device. Tested and working on Tab S5e, but should work on all Samsung from A10 + with supporting recovery.

Note Recent (circa Sep-Nov2023) versions of fastboot (as available in the android-tools package on common linux distributions) may be broken. fastboot will coredump when flashing known good pmos.img files. The error message is
terminate called after throwing an instance of 'std::out_of_range'
  what(): basic_string::compare: __pos (which is 464) > this->size() (which is 0)

Known problematic packages are (archlinux): android-tools-34.0.4-[2,3].

Known working package is android-tools-34.0.1-2.

Odin

Odin is an official flasher for many Samsung devices, runs only on Windows. Make sure you have the latest Samsung USB drivers installed before plugging in the smartphone in Odin mode. As of right now, it is available in Linux. See https://xdaforums.com/t/official-samsung-odin-v4-1-2-1-dc05e3ea-for-linux.4453423/ for details

To flash your phone with it you will need .pit file containing information about all partitions, you can find one online or download it from the device e.g using Heimdall.

Heimdall

Flash tab in heimdall-frontend

Heimdall is an opensource alternative to Odin that runs on Windows, Mac and Linux and can flash many Samsung phones. Be aware that Heimdall doesn't support some Samsung phones (usually that uses different file than .pit).

The user grimler maintains a Heimdall fork here with some additional patches, since the development at the official repository has stalled.

Easy way

Use heimdall-frontend

On tab Utilities you can obtain .pit file from the device by choosing save location and clicking download

Note NEVER select "Repartition", it will most certainly brick your phone!

When you have .pit file and required img files you can go to Flash tab, select your .pit file, add new partition, configure it (name and flashed file), optionally add more partitions and click Start to flash everything to the device.

Hard way

First, turn on your phone in download mode (You can use heimdall detect to see if Heimdall detects it.)

To download .pit from the device:

heimdall download-pit --output file.pit --no-reboot

Note The inclusion of --no-reboot ensures the phone will not reboot after PIT file has been downloaded and displayed. After executing a command with the --no-reboot argument, the next command should include the --resume argument. NOTE: You can still safely reboot your phone manually (with the power button) after executing --no-reboot commands. See also pmbootstrap#2258
Note code below was not yet tested, I would advise against using it

When you have .pit file and required img files you can flash your device with:

heimdall flash --resume --pit file.pit [--<partition name> <filename>] [--<partition identifier> <filename>]

You should be able to flash several partitions at once

Flashing TWRP can be done in the following way (change filepath to the location of your twrp):

heimdall flash --RECOVERY ~/twrp.img --no-reboot

Manual Flashing With Existing Sub Partitions On Drive

Generate your image file with pmbootstrap

pmbootstrap init

pmbootstrap install [plus any other options such as --fde]

pmbootstrap export


Now use fdisk to inspect the image file from the exported .img in the logs from pmbootstrap export and losetup to check what it will be mapped to in /dev/loop, with the last part of the file will be the loop number.

fdisk -l [path to .img file]

# losetup --find --show --partscan --read-only [path to .img file]


Before you progress make sure you set up the partitions correctly on the drive with boot starting at 2048.

From here you need to mount the image file to /dev/loop, 1 will be boot and 2 will be root (typically) and then dd to the drive. After use losetup -d to umount the /dev/loop.


# losetup -fP [path to .img file]

# dd if=/dev/loop0p1 of=/dev/sdb1 bs=4M status=progress

# dd if=/dev/loop0p2 of=/dev/sdb2 bs=4M status=progress

# losetup -d /dev/loop0