Skip to content

Instantly share code, notes, and snippets.

@magno32
Last active December 17, 2015 02:39
Show Gist options
  • Save magno32/5537293 to your computer and use it in GitHub Desktop.
Save magno32/5537293 to your computer and use it in GitHub Desktop.
This is an adaptation of the mkmmc-android.sh script and the instructions found at http://maniacbug.wordpress.com/2012/08/03/pandayocto/ that will load an SD card with your custom Yocto build.. Some modifications had to be made to make the image components work with the beaglebone. The default images assumes you are building "core-image-basic". …
#!/bin/bash
## Arguement Validation
EXPECTED_ARGS=1
if [ $# == $EXPECTED_ARGS ]
then
echo "Assuming Default Locations for Prebuilt Images"
$0 $1 $PWD/tmp/deploy/images/MLO $PWD/tmp/deploy/images/u-boot.img $PWD/tmp/deploy/images/uImage $PWD/tmp/deploy/images/uImage-am335x-bone.dtb $PWD/tmp/deploy/images/core-image-basic-beaglebone.tar.gz
exit
fi
if [[ -z $1 || -z $2 || -z $3 || -z $4 ]]
then
echo "mkmmc-android Usage:"
echo " mkmmc-beaglebone.sh <device> <MLO> <u-boot.img> <uImage> <uImage-am335x-bone.dtb> <rootfs tar.gz >"
echo " Example: mkmmc-beaglebone.sh /dev/sdc MLO u-boot.img uImage uImage-am335x-bone.dtb rootfs.tar.gz"
exit
fi
if ! [[ -e $2 ]]
then
echo "Incorrect MLO location!"
exit
fi
if ! [[ -e $3 ]]
then
echo "Incorrect u-boot.bin location!"
exit
fi
if ! [[ -e $4 ]]
then
echo "Incorrect uImage location!"
exit
fi
if ! [[ -e $5 ]]
then
echo "Incorrect boot.scr location!"
exit
fi
if ! [[ -e $6 ]]
then
echo "Incorrect rootfs location! "
exit
fi
echo "All data on "$1" now will be destroyed! Continue? [y/n]"
read ans
if ! [ $ans == 'y' ]
then
exit
fi
## Unmounting all partitioins
echo "[Unmounting all existing partitions on the device ]"
umount $1*
## Writing new partition table using sfdisk
echo "[Partitioning $1...]"
DRIVE=$1
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
echo DISK SIZE - $SIZE bytes
CYLINDERS=`echo $SIZE/255/63/512 | bc`
echo CYLINDERS - $CYLINDERS
{ echo ,9,0x0C,*; echo ,,,-; } | sudo sfdisk -D -H 255 -S 63 -C $CYLINDERS $1 &> /dev/null
## Making New file systems
echo "[Making filesystems...]"
mkfs.vfat -F 32 -n boot "$1"1 &> /dev/null
mkfs.ext3 -L rootfs "$1"2 &> /dev/null
## Copying Contents
echo "[Copying files...]"
mount "$1"1 /mnt
cp $2 /mnt/MLO
cp $3 /mnt/u-boot.img
sync
umount "$1"1
mount -t ext3 "$1"2 /mnt
export PATH_TO_TMPFS_DIR=$PWD/tmp_fs
export PATH_TO_SDROOTFS=/mnt
echo "[Copying File System to rootfs partition]"
tar -x -f $6 --numeric-owner -C $PATH_TO_SDROOTFS &> /dev/null
cp $4 /mnt/boot/uImage
cp $5 /mnt/boot/am335x-bone.dtb
sync
umount "$1"2
echo "[Done]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment