Command line flashing script with media verification, xz image support
#1
Hi all,

I've seen a lot of people struggling flashing images to sd cards/emmc from the command line and even more people asking for support after flashing images improperly or without media verification. I wrote a script to make this process easier, hopefully it will reduce the number of problems people are experiencing.

The script handles both raw images (.img files) and xz compressed images and will write and then verify, or with the --verify-only flag simply verify, that your media has been written correctly.

The script is located here: https://github.com/foundObjects/sbc-flasher

Installation is simple, either download the script and optionally make it executable and place it somewhere in your path or just run the installer code below. If pv isn't installed in your distribution by default you'll need to install it if you want pretty progress meters. The installer will ask for sudo permission to install the script in /usr/local/sbin as needed, so there's no need to run it with sudo or as root.

Code:
bash <(wget -o /dev/null -qO- https://raw.githubusercontent.com/foundObjects/sbc-flasher/master/install.sh)
sudo apt install -y pv

Use:

Code:
# sudo flasher.sh
Usage: /usr/local/sbin/flasher.sh (--flags) image(.img|.xz) /dev/target_block_device

Flags:
  -W | --write-only  | --write    Write pass only, no verification
  -V | --verify-only | --verify   Verify only
  -x | --debug                    Extremely verbose output (like bash -x ...)
       --no-pv                    Don't use pipeviewer

Flashing an image:

Code:
root@pinebookpro:/data/images# flasher.sh pinebookpro-debian-mrfixit-191127.img.xz /dev/mmcblk0
writing xz compressed image to /dev/mmcblk0
5.01GiB 0:02:46 [30.8MiB/s] [==================================================================>] 100%
0+574861 records in
0+574861 records out
5377097728 bytes (5.4 GB, 5.0 GiB) copied, 181.469 s, 29.6 MB/s
Write successful
Verifying xz image
5.01GiB 0:03:37 [23.6MiB/s] [==================================================================>] 100%
Image verified successfully

Flash verification is simple as well:

Code:
root@pinebookpro:/data/images# flasher.sh --verify-only pinebookpro-debian-mrfixit-191127.img /dev/mmcblk0
Verifying raw image
335MiB 0:00:11 [26.6MiB/s] [===>                                                                               ]  6% ETA 0:02:37

Debugging:

Run the script with -x: `sudo flasher.sh -x yourimage /dev/flash_target |& tee flashlog` to see what's going wrong and dump execution flow to a file. Please use pastebin.com (or hastebin.com, everyone should use hastebin because hastebin is awesome) instead of pasting debug output here if you need help.

You're welcome to do whatever you want with this script, hopefully it saves everyone some time.
#2
Well done!
You can find me on IRC, Discord and Twitter


#3
Hey all,

It looks like 'pv' isn't installed by default on Debian so you'll need to "sudo apt install pv" before using the script if you want pretty progress bars. I'll push an update that checks for pv and works without it soon™.

Edit: And done. Script now supports running without pv (use --no-pv), lives in a proper git repo and has a one-line installer from the shell. Have fun!


Possibly Related Threads…
Thread Author Replies Views Last Post
  Video Flashing/adjusting on boot and reboot jbradley419 0 629 01-16-2024, 09:17 AM
Last Post: jbradley419
  Doesn’t power on after flashing emmc badguru 3 1,795 02-25-2023, 09:00 PM
Last Post: badguru
  Pinebook Pro won't turn on after flashing image Idaho 2 1,483 02-21-2023, 02:31 PM
Last Post: Idaho
  Unable to boot from emmc after flashing it rfm83 3 2,323 11-08-2022, 10:59 PM
Last Post: rfm83
  After Flashing eMMC, Will Not Boot Mossbot 5 3,176 09-28-2022, 06:22 PM
Last Post: wdt
  U-Boot with direct NVMe boot support for eMMC/SPI Flash pcm720 125 238,242 09-27-2022, 07:41 AM
Last Post: olyavi
  Pinebook Pro bricked after flashing eMMC User 24592 0 1,472 02-17-2022, 07:55 AM
Last Post: User 24592
  My pbp is a sleek, black, flat brick, and won't boot from any kind of media rotwang 15 16,476 08-24-2021, 04:25 PM
Last Post: bkenn
  Wiped EMMC, forgot do write new image, won't recognize EMMC zeno 4 4,957 05-11-2021, 01:53 PM
Last Post: wdt
  Latest PBP Factory Image? calinb 2 3,330 05-10-2021, 03:24 PM
Last Post: calinb

Forum Jump:


Users browsing this thread: 1 Guest(s)