5
May

Beagle Board Quick Start Guide with Setup Scripts

I recently got my hands on a Beagle Board to play around with at work, so I figured I would document and create a set of scripts that anybody can use to quickly setup a Beagle Board to boot from an SD card (2GB+). I’m going to assume you know the standard blurb of instructions: copy/download scripts, give them executable rights, and then run with root privileges while taking caution as to not mess up your Linux box. Also, please keep in mind that images and file locations change over time. Let’s begin!

The first script (setup_sd) will setup your SD card with the proper partitions and geometry. All you need to do is tell it where your SD card is. If you don’t know, use either dmesg or fdisk -l to find out. Likely, it’s located at /dev/sdb, so that’s what I’ll use here as an example on how to use this first script: setup_sd /dev/sdb. This script was obtained from XorA. All I added was a quick check to make sure the user is calling it properly.

#!/bin/sh
# As per instructions:
# http://elinux.org/BeagleBoardBeginners

if [ $# -lt 1 ]; then
   echo "example usage: $0 /dev/sdb"
   exit 1
fi

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 ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE

mkfs.vfat -F 32 -n "boot" ${DRIVE}1
mke2fs -j -L "rootfs" ${DRIVE}2

The second script (load_sd) will obtain and install the required files to boot the Beagle Board to the SD card. Usage is very similar to the above script, load_sd /dev/sdb. I would recommend creating a directory specifically for running this script within, ie. mkdir beagleboard; cd beagleboard, this way, everything is nice and tidy.

#!/bin/sh
# As per instructions:
# http://elinux.org/BeagleBoardBeginners

if [ $# -lt 1 ]; then
   echo "example usage: $0 /dev/sdb"
   exit 1
fi

DISK=$1

if [ -e Angstrom-Beagleboard* -a -e MLO -a -e u-boot* -a -e uImage* -a -e modules* ]; then
	echo "All files found okay... "

	echo "Mounting ${DISK}1 and ${DISK}2"
	mkdir /mnt/sd1; mount ${DISK}1 /mnt/sd1
	mkdir /mnt/sd2; mount ${DISK}2 /mnt/sd2
	sleep 2

	echo "Copying to ${DISK}1 and ${DISK}2"
	cp MLO u-boot.bin /mnt/sd1
	cp uImage* /mnt/sd1/uImage
	tar -xvf Angstrom-Beagleboard-demo-image*.tar.bz2 -C /mnt/sd2
	tar -xvf modules-2.6.*.tgz -C /mnt/sd2

	echo "Unmounting ${DISK}1 and ${DISK}2"
	umount ${DISK}1; umount ${DISK}2
	rm -rf /mnt/sd1 /mnt/sd2
	echo "Done"

else
	echo "Files missing!"
	echo "Downloading required files... this may take some time."
   sleep 2

	wget http://www.angstrom-distribution.org/demo/beagleboard/Angstrom-Beagleboard-demo-image-glibc-ipk-2010.3-beagleboard.rootfs.tar.bz2
	wget http://www.angstrom-distribution.org/demo/beagleboard/MLO
	wget http://www.angstrom-distribution.org/demo/beagleboard/u-boot.bin
	wget http://www.angstrom-distribution.org/demo/beagleboard/uImage-2.6.29-r47-beagleboard.bin
	wget http://www.angstrom-distribution.org/demo/beagleboard/modules-2.6.29-r47-beagleboard.tgz

   echo "Finished downloading files.  Simply run "$0 /dev/sdX" again to load files to SD card."
fi

After these scripts have ran successfully, all you need to do is interrupt the startup sequence of Uboot (Beagle Board’s bootloader) and setup the environment variables to boot from the SD card as mentioned here. For convenience, I have placed the commands you need to run here:

setenv bootargs 'console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw rootwait'
setenv bootcmd 'mmc init;fatload mmc 0 80300000 uImage;bootm 80300000'
saveenv

Then, press the RESET button while holding down the USER button, and you’ll find yourself booting to the Angstrom distribution. More information about it can be found here.

Sources:
http://elinux.org/BeagleBoardBeginners

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 1 Comment So Far

  • training beagles
    December 30th, 2010 at 3:43 pm

    […] Beagle Board Quick Start Guide with Setup Scripts | The Linux Daily […]

Share your thoughts, leave a comment!