Rock64 Linux Image Writing Scripts Codes and Tutorial
#1
Brick 
Greetings,

The purpose of this post is to make available as quickly as possible the Rock64 Linux Image Writing Scripts ( codes and tutorials ) as well giving theory and instructions for their use.

Both of the scripts presented her derive directly, and were ported from, ayufan's "Pinebook to eMMC" script and perform the same function, yet over the Rock64 repos ( the arm64 primary images ).

Theory

Place these scripts ( as well the "curl" and "jq" packages ) on your gnu+linux system and use them to download and write the desired image from the network repos directly to the SD card ;  or even to the eMMC module using an adapter !  In addition the scripts may be placed on your bootable SD card in preparation for using the jumper setting technique for writing a network repo image directly to the eMMC memory module.  The flexibility is your own choice.  I have pushed the script(s) as a github PR, and eventually they will be included in the images automatically.

The Scripts


rock64_install_to_emmc.sh

Code:
#!/bin/bash

set -eo pipefail

if [[ "$(id -u)" -ne "0" ]]; then
    echo "This script requires root."
    exit 1
fi

echo "Rock64 Release Installer!"
echo "(C) 2017. Kamil Trzciński (https://ayufan.eu)."
echo ""

usage() {
   echo "Usage:"
   echo "$ $0 <system> [version]"
   echo ""
   echo "Systems:"
   echo " - xenial-minimal (https://github.com/ayufan-rock64/linux-build/releases)"
   echo " - xenial-mate (https://github.com/ayufan-rock64/linux-build/releases)"
   echo " - xenial-i3 (https://github.com/ayufan-rock64/linux-build/releases)"
   echo ""
   echo "Version:"
   echo " - latest will be used if version is not defined"
   exit 1
}

if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
   usage
fi

if [[ ! -d /sys/devices/soc.0/1c10000.sdmmc/mmc_host/mmc1 ]]; then
   echo "You should boot from SD card"
   exit 1
fi

if [[ ! -e /dev/mmcblk1 ]]; then
   echo "You should boot from SD card"
   exit 1
fi

case "$1" in
   xenial-minimal|xenial-mate|xenial-i3)
       REPO="ayufan-rock64/linux-build"
       PREFIX="$1-rock64-"
       SUFFIX="-[0-9]*-arm64.img.xz"
       ARCHIVER="xz -d"
       ;;

   *)
       echo "Unknown system: $1"
       echo ""
       usage
       ;;
esac

VERSION="$2"

if [[ -z "$VERSION" ]]; then
    VERSION=$(curl -f -sS https://api.github.com/repos/$REPO/releases/latest | jq -r ".tag_name")
    if [ -z "$VERSION" ]; then
        echo "Latest release was not for $1."
       echo "Please go to: https://github.com/$REPO/releases/latest"
       exit 1
    fi

    echo "Using latest release: $VERSION from https://github.com/$REPO/releases."
fi

NAME="$PREFIX$VERSION$SUFFIX"
NAME_SAFE="${NAME//./\\.}"
VERSION_SAFE="${VERSION//./\\.}"

echo "Looking for download URL..."
DOWNLOAD_URL=$(curl -f -sS https://api.github.com/repos/$REPO/releases | \
   jq -r ".[].assets | .[].browser_download_url" | \
   ( grep -o "https://github\.com/$REPO/releases/download/$VERSION_SAFE/$NAME_SAFE" || true))

if [[ -z "$DOWNLOAD_URL" ]]; then
   echo "The download URL for $NAME not found".
   echo "Look at https://github.com/$REPO/releases for correct versions."
   exit 1
fi

echo "Doing this will overwrite all data stored on eMMC."

while true; do
   echo "Type YES to continue or Ctrl-C to abort."
   read CONFIRM
   if [[ "$CONFIRM" == "YES" ]]; then
       break
   fi
done

echo ""
echo "Using $DOWNLOAD_URL..."
echo "Umounting..."
umount -f /dev/mmcblk1* || true
echo ""

echo "Downloading and writing to /dev/mmcblk1..."
curl -L -f "$DOWNLOAD_URL" | $ARCHIVER | dd bs=30M of=/dev/mmcblk1
sync
echo ""

echo "Done."



rock64_install_to_SD.sh

Code:
#!/bin/bash

set -eo pipefail

if [[ "$(id -u)" -ne "0" ]]; then
    echo "This script requires root."
    exit 1
fi

echo "Rock64 Release Installer!"
echo "(C) 2017. Kamil Trzciński (https://ayufan.eu)."
echo ""

usage() {
   echo "Usage:"
   echo "$ $0 <system> [version]"
   echo ""
   echo "Systems:"
   echo " - xenial-minimal (https://github.com/ayufan-rock64/linux-build/releases)"
   echo " - xenial-mate (https://github.com/ayufan-rock64/linux-build/releases)"
   echo " - xenial-i3 (https://github.com/ayufan-rock64/linux-build/releases)"
   echo ""
   echo "Version:"
   echo " - latest will be used if version is not defined"
   exit 1
}

if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
   usage
fi

#if [[ ! -d /sys/devices/soc.0/1c10000.sdmmc/mmc_host/mmc1 ]]; then
#    echo "You should boot from SD card"
#    exit 1
#fi

#if [[ ! -e /dev/mmcblk0 ]]; then
#    echo "You should boot from SD card"
#    exit 1
#fi

case "$1" in
   xenial-minimal|xenial-mate|xenial-i3)
       REPO="ayufan-rock64/linux-build"
       PREFIX="$1-rock64-"
       SUFFIX="-[0-9]*-arm64.img.xz"
       ARCHIVER="xz -d"
       ;;

   *)
       echo "Unknown system: $1"
       echo ""
       usage
       ;;
esac

VERSION="$2"

if [[ -z "$VERSION" ]]; then
    VERSION=$(curl -f -sS https://api.github.com/repos/$REPO/releases/latest | jq -r ".tag_name")
    if [ -z "$VERSION" ]; then
        echo "Latest release was not for $1."
       echo "Please go to: https://github.com/$REPO/releases/latest"
       exit 1
    fi

    echo "Using latest release: $VERSION from https://github.com/$REPO/releases."
fi

NAME="$PREFIX$VERSION$SUFFIX"
NAME_SAFE="${NAME//./\\.}"
VERSION_SAFE="${VERSION//./\\.}"

echo "Looking for download URL..."
DOWNLOAD_URL=$(curl -f -sS https://api.github.com/repos/$REPO/releases | \
   jq -r ".[].assets | .[].browser_download_url" | \
   ( grep -o "https://github\.com/$REPO/releases/download/$VERSION_SAFE/$NAME_SAFE" || true))

if [[ -z "$DOWNLOAD_URL" ]]; then
   echo "The download URL for $NAME not found".
   echo "Look at https://github.com/$REPO/releases for correct versions."
   exit 1
fi

echo "Doing this will overwrite all data stored on eMMC."

while true; do
   echo "Type YES to continue or Ctrl-C to abort."
   read CONFIRM
   if [[ "$CONFIRM" == "YES" ]]; then
       break
   fi
done

echo ""
echo "Using $DOWNLOAD_URL..."
echo "Umounting..."
umount -f /dev/mmcblk0* || true
echo ""

echo "Downloading and writing to /dev/mmcblk0..."
curl -L -f "$DOWNLOAD_URL" | $ARCHIVER | dd bs=30M of=/dev/mmcblk0
sync
echo ""

echo "Done."



Instructions for Use:

Be sure to make both scripts executable as always with :

      chmod  0754  rock64_install_to_SD.sh

Both of the above scripts function the same way and have some very subtle differences, but generally have the same theory of operation;  the user selects a system image and version -- the script then finds the latest ( not pre release ) build, verifies it, and then downloads it from the network repos directly to the SD card, or even to the eMMC module via an adapter.

Sample syntax of the command is :

      sudo  ./rock64_install_to_SD.sh  xenial-mate  0.4.16

      sudo  ./rock64_install_to_SD.sh  xenial-minimal

If the version number is omitted then the script will find the latest ( not pre release ) build release!  The three primary arm64 versions are supported with this script:  xenial-mate | xenial-i3 |  xenial-minimal

The scripts differ mostly in their error checking, and where they write;  the SD.sh script writes to /dev/mmcblk0 while the emmc.sh script writes to mmcblk1.  The emmc.sh script makes sure that you're booted on the SD card first ! (very important for writing to the eMMC on the same system).  Otherwise, the two scripts are mostly identical and perform the same function.

The SD.sh script may be also used to write to the eMMC module if the module is placed into an adapter for use with the PC gnu+linux system.  The benefits of these scripts is two fold:  1) they are very fast with no intermediary step, and 2) the SD or eMMC is written to without having to play around with dd or Etcher ( or some other ) as well the syntax checking and command parsing is completely automatic ;  all the user has to know is the system and the version.

I have tested both of these scripts within reason and have found that they are functional and useful;  if the scripts are placed on your bootable SD card ( for writing to the eMMC module on-board with the jumper technique ) then they become very powerful for downloading and installing the desired image directly to the eMMC module from the network repos.  This is the very same technique that is used on the Pinebook to write images to its on-board eMMC module.

The Rock64 eMMC tutorial will be updated with this information.

As with any derived work, I have left ayufan's name attached due to respect, as well copyright and dignity of propriety;  however,  any errors are mine alone and I am responsible to correct any errors that might be found, quickly.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#2
Hi Mark, I'm a bit confused.
If I currently have Xenial-mate running from the SD card, can I run the "rock64_install_to_emmc.sh" script and it will install the latest image to the eMMC module I have installed?
Will it work or do I still need a jumper and a serial console cable?

Thank you.
#3
(08-17-2017, 07:03 AM)kershaw Wrote: Hi Mark, I'm a bit confused.
If I currently have Xenial-mate running from the SD card, can I run the "rock64_install_to_emmc.sh" script and it will install the latest image to the eMMC module I have installed?
Will it work or do I still need a jumper and a serial console cable?

Thank you.

Yes, it will install the newest available release image to eMMC. However, you still need to boot the R64 so that it starts from SD but can see the eMMC, which does require the jumper and console cable.
Community administrator and sysadmin for PINE64
(Translation: If something breaks on the website, forum, or chat network, I'm a good person to yell at about it)

#4
Hi Mark, I'm also a bit confused.
In your how-to-write-to-emmc-tutorial, you wrote that mmcblk0 should be emmc, and mmcblk1 would be sd.
This seems to be consistent with my findings via fdisk.

In your scripts above, it seems that in the install_to_sd mmcblk0 (isn't this emmc?) would be target of dd. And the install_to_emmc targets mmcblk1. This seems to be counter-intuitive for me. But i have to admit that i learned about dd just ten minutes ago. And your bash-fu is so far superior to mine - i don't fully understand what each line of your script does.

Thank you and best regards,
-ac
#5
Count me as also confused.     I've tried to mount Rock64 booting microSD cards on FreeBSD 11 to see what is being done and try to expand the written to filesystem.    The MATE and stock Debian show up as ext4 when you log in.   But they show up as  /dev/da10       /dev/da10p2     /dev/da10p4     /dev/da10p6  /dev/da10p1     /dev/da10p3     /dev/da10p5     /dev/da10p7   on FreeBSD.   Now the stock android microSD didn't work, the stock straight android eMMC didn't work as dd transfer to a hardkernel rev 0:2 20130402 MicroSD eMMC Reader mounted eMMC , but the microSD to eMMC DID work and that was a msdos filesystem.    


At this point I have no idea how the build process happens and that script gets to a bootable filesystem on the Rock64.     I was hoping for a way to boot from USB but that does not seem to be built in.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock64 No Audio @ Debian 12 dmitrymyadzelets 2 239 04-08-2024, 06:47 AM
Last Post: dmitrymyadzelets
  OpenWRT on the Rock64 CanadianBacon 14 8,197 04-03-2024, 08:48 AM
Last Post: helpmerock
  Rock64 bricked shawwwn 7 5,614 03-17-2024, 12:22 PM
Last Post: dmitrymyadzelets
  Rock64 won't boot luminosity7 10 4,045 03-16-2024, 08:33 AM
Last Post: dmitrymyadzelets
  Rock64 doesn't boot dstallmo 1 317 03-16-2024, 08:29 AM
Last Post: dmitrymyadzelets
  How well does Rock64 deal with HDR and Atmos on Kodi? drvlikhell 3 1,858 04-29-2023, 04:24 AM
Last Post: newestssd
  Rock64 board not working, no HDMI no Ethernet. EDited 3 3,480 01-17-2023, 02:31 PM
Last Post: Flagtrax
  ROCK64 v3 can it boot from USB? Tsagualsa 4 2,068 11-29-2022, 11:31 AM
Last Post: Macgyver
  rock64 v3 spiflash Macgyver 0 740 11-28-2022, 02:18 PM
Last Post: Macgyver
  my rock64 dosen't work rookie_267 0 939 10-07-2022, 07:50 PM
Last Post: rookie_267

Forum Jump:


Users browsing this thread: 1 Guest(s)