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
  My pbp is a sleek, black, flat brick, and won't boot from any kind of media rotwang 9 203 4 hours ago
Last Post: straightwalker
  U-Boot with direct NVMe boot support for eMMC/SPI Flash pcm720 118 95,522 06-08-2021, 11:04 PM
Last Post: calinb
  Wiped EMMC, forgot do write new image, won't recognize EMMC zeno 4 505 05-11-2021, 01:53 PM
Last Post: wdt
  Latest PBP Factory Image? calinb 2 345 05-10-2021, 03:24 PM
Last Post: calinb
  [split] U-Boot with NVMe support, keyboard & display working as400 83 35,061 01-27-2021, 12:48 AM
Last Post: as400
  PBP problem and a silent support team pbp_user234 1 782 10-28-2020, 10:00 AM
Last Post: vfr400racer
  mhwd-kernel: command not found motezart 1 1,008 10-16-2020, 03:11 PM
Last Post: wdt
Exclamation Pinebook Pro worst support ever gentux 10 4,105 09-27-2020, 11:19 AM
Last Post: LinAdmin2
  apt-get command not found motezart 11 3,182 09-25-2020, 11:45 AM
Last Post: Paulie420
  Pinebook Pro Support robheaton 2 1,134 09-15-2020, 01:08 AM
Last Post: robheaton

Forum Jump:


Users browsing this thread: 1 Guest(s)