Skip to content

Instantly share code, notes, and snippets.

@gunnarx
Created July 6, 2018 14:04
Show Gist options
  • Save gunnarx/ec50d269edd9a537c8034b49690b9e1f to your computer and use it in GitHub Desktop.
Save gunnarx/ec50d269edd9a537c8034b49690b9e1f to your computer and use it in GitHub Desktop.
GDP to R-Car SD card. Pretty awful hack, be careful :)
#!/bin/bash
# SETTINGS WARNING - get HOST DEVICE right or overwrite the wrong disk!
HOST_DEVICE=/dev/sda
HOST_DEVICE_PARTIION=${HOST_DEVICE}1
SDIMG=genivi-dev-platform-r-car.sdimg
DD=dcfldd # Change to dd if you don't have dcfldd installed
MOUNTPOINT=/tmp/rcar_sd_mount
#set -e
#set -o pipefail
print() {
echo $@
}
if [ -z "$1" -o -z "$2" ] ; then
echo "Usage: $0 <rootfs.tar.gz> <devicetree.dtb>"
exit 1
fi
TARBALL="$1"
DTB="$2"
if [ "$DTB" != "Image-r8a7796-m3ulcb.dtb" ] ; then
echo "*** WARNING *** DTB file should likely be named Image-r8a7796-m3ulcb.dtb instead?"
echo "Hit return to continue"
read x
fi
if [ ! -e "$HOST_DEVICE" ] ; then
echo "Can't find HOST_DEVICE $HOST_DEVICE - (edit this value in script). Stopping."
exit 2
fi
print "WARNING -- will overwrite disk $HOST_DEVICE !. Press RETURN to continue, or CTRL-C to abort"
read x
print "Zeroing image file"
rm -f "$SDIMG"
$DD if=/dev/zero of="$SDIMG" bs=2048 count=1M
mkfs.ext3 $SDIMG
print "Creating partition table on image"
cat <<EOT | sudo fdisk $HOST_DEVICE
o
n
p
w
EOT
print "Writing rootfs to image"
mkdir -p $MOUNTPOINT
sudo mount -o loop $SDIMG $MOUNTPOINT
sudo tar --numeric-owner --preserve-permissions --preserve-order --totals -xvf $TARBALL -C $MOUNTPOINT/
print Copying DTB to image file /boot
sudo cp "$DTB" $MOUNTPOINT/boot/
sudo umount $MOUNTPOINT
print Writing actual SD card with image
mount | fgrep -q "$HOST_DEVICE"
if [ $? -eq 0 ] ; then
print "Warning HOST_DEVICE $HOST_DEVICE is mounted!"
print "Are you sure to unmount and continue writing?"
print
print "WARNING -- will overwrite disk $HOST_DEVICE !. Press RETURN to continue, or CTRL-C to abort"
echo
read x
# This is sloppy and could certainly be improved...
sudo umount -f ${HOST_DEVICE}1 ${HOST_DEVICE}2 ${HOST_DEVICE}3 ${HOST_DEVICE}p1 ${HOST_DEVICE}p2 ${HOST_DEVICE}p3 2>/dev/null || true
fi
if [ ! -e "$HOST_DEVICE" ] ; then
print "Can't find HOST_DEVICE $HOST_DEVICE - stopping."
exit 2
fi
set -x
sudo $DD if=$SDIMG of=$HOST_DEVICE_PARTIION bs=1M
set +x
print Syncing
sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment