BeagleBone Initilization Scripts

This forum is for supported devices using an ARMv7 Texas Instruments (TI) SoC.

BeagleBone Initilization Scripts

Postby calzon65 » Thu Jun 13, 2013 1:00 am

Here are a few scripts I use to partition an SD card, format/upload to the SD card, and initialize the eMMC memory in a BeagleBone Black. With some slight modifications, the scripts will probably work on other hardware platforms.

Partition SD Card:
$this->bbcode_second_pass_code('', '# This script partitions SD media for use as a boot device for a BeagleBone
# or BeagleBone black. The first partition (boot) is sized at 16MB. If you
# want a larger partition, change the code below (look for +16M). This script
# assumes the device you want to partition is located at /dev/sd?. Make sure
# you verify the correct device name before proceeding.

DEVICELIST=`ls /dev/sd? 2> /dev/null | sed s:/dev/::`
if [ -z "${DEVICELIST}" ]; then
echo "ERROR: No /dev/sd? devices"
exit
fi

clear
echo Device Choices: $DEVICELIST
echo
while true
do
read -p "Enter device name: " DEVICECHOICE
if echo "$DEVICECHOICE" | grep -q "$DEVICELIST"
then
break
else
echo "ERROR: You entered an invalid device name."
fi
done

echo
while true
do
read -p "Are you sure you want to use /dev/$DEVICECHOICE (answer yes or no)? " ANSWER
case $ANSWER in
yes ) break;;
no ) exit;;
* ) echo "ERROR: Please answer yes or no.";;
esac
done

fdisk /dev/$DEVICECHOICE << EOF
o
p
n
p
1

+16M
n
p
2


a
1
t
1
e
p
w
EOF')

Format/Upload ArchLinux to SD Card:
$this->bbcode_second_pass_code('', '# This script is used to create a new (clean) install of ArchLinux for the BeagleBone or
# BeagleBoneBlack on a microSD card. Verify your media devices before you proceed. This
# script assumes your media device is /dev/sd?. Ensure you have partitioned (fdisk) your
# media before proceeding. You will need two partitions. The first partition does not need
# to be large, but needs to be set to bootable and must be type 'e' which is FAT 16.
# The second partition is a normal Linux partition, probably ext4. If you can't mkfs.vfat,
# download the dosfstools (pacman -Sy dosfstools).

clear
DEVICELIST=`ls /dev/sd? 2> /dev/null | sed s:/dev/::`
if [ -z "${DEVICELIST}" ]; then
echo "ERROR: No /dev/sd? devices"
exit
fi

echo Device Choices: $DEVICELIST
echo
while true
do
read -p "Enter device name: " DEVICECHOICE
if echo "$DEVICECHOICE" | grep -q "$DEVICELIST"
then
break
else
echo "ERROR: You entered an invalid device name."
fi
done

echo
while true
do
read -p "Are you sure you want to use /dev/$DEVICECHOICE (answer yes or no)? " ANSWER
case $ANSWER in
yes) break;;
no) exit;;
*) echo "ERROR: Please answer yes or no.";;
esac
done

BOOTLOADER=BeagleBone-bootloader.tar.gz
ARCHLINUX=ArchLinuxARM-am33x-latest.tar.gz
WORKINGDIR=.
BOOTDEV=/dev/$DEVICECHOICE'1'
BOOTTMP=$WORKINGDIR/boot
ROOTDEV=/dev/$DEVICECHOICE'2'
ROOTTMP=$WORKINGDIR/root
BOOTIMAGE=$ROOTTMP/boot/zImage

mkfs.vfat -F 16 -n "bootloader" $BOOTDEV
sleep 1
mkfs.ext4 -L "rootfs" $ROOTDEV
sleep 1

mkdir $BOOTTMP
mkdir $ROOTTMP
mount $BOOTDEV $BOOTTMP
mount $ROOTDEV $ROOTTMP

wget http://archlinuxarm.org/os/omap/$BOOTLOADER -O $WORKINGDIR/$BOOTLOADER
sleep 1
wget http://archlinuxarm.org/os/$ARCHLINUX -O $WORKINGDIR/$ARCHLINUX
sleep 1

if which pv &> /dev/null
then
pv $WORKINGDIR/$BOOTLOADER | tar xzf - -C $BOOTTMP
pv $WORKINGDIR/$ARCHLINUX | tar xzf - -C $ROOTTMP
else
tar xvf $WORKINGDIR/$BOOTLOADER -C $BOOTTMP
tar xvf $WORKINGDIR/$ARCHLINUX -C $ROOTTMP
fi

echo "Copying Boot Image"
cp $BOOTIMAGE $BOOTTMP

echo "Synching"
sync

umount $BOOTTMP
umount $ROOTTMP
rmdir $BOOTTMP
rmdir $ROOTTMP

clear
echo "Upload Complete"
echo
while true
do
read -p "Delete downloaded files (answer yes or no)? " ANSWER
case $ANSWER in
yes)
rm $WORKINGDIR/$BOOTLOADER
rm $WORKINGDIR/$ARCHLINUX
exit
;;
no) exit;;
*) echo "ERROR: Please answer yes or no.";;
esac
done')

Format/Upload to BeagleBone Black eMMC:
$this->bbcode_second_pass_code('', '# This script is used to create a new (clean) install of ArchLinux to the BeagleBoneBlack's
# onboard eMMC memory. This script assumes you have booted the BeagleBoneBlack (not using
# the onboard eMMC) and now want to install ArchLinux in the onboard eMMC memory.

BOOTLOADER=BeagleBone-bootloader.tar.gz
ARCHLINUX=ArchLinuxARM-am33x-latest.tar.gz
WORKINGDIR=.
BOOTDEV=/dev/mmcblk1p1
BOOTTMP=$WORKINGDIR/boot
ROOTDEV=/dev/mmcblk1p2
ROOTTMP=$WORKINGDIR/root
BOOTIMAGE=$ROOTTMP/boot/zImage

mkfs.vfat -F 16 -n "bootloader" $BOOTDEV
sleep 1
mkfs.ext4 -L "rootfs" $ROOTDEV
sleep 1

mkdir $BOOTTMP
mkdir $ROOTTMP
mount $BOOTDEV $BOOTTMP
mount $ROOTDEV $ROOTTMP

wget http://archlinuxarm.org/os/omap/$BOOTLOADER -O $WORKINGDIR/$BOOTLOADER
sleep 1
wget http://archlinuxarm.org/os/$ARCHLINUX -O $WORKINGDIR/$ARCHLINUX
sleep 1

if which pv &> /dev/null
then
pv $WORKINGDIR/$BOOTLOADER | tar xzf - -C $BOOTTMP
pv $WORKINGDIR/$ARCHLINUX | tar xzf - -C $ROOTTMP
else
tar xvf $WORKINGDIR/$BOOTLOADER -C $BOOTTMP
tar xvf $WORKINGDIR/$ARCHLINUX -C $ROOTTMP
fi

echo "Copying Boot Image"
cp $BOOTIMAGE $BOOTTMP

echo "Synching"
sync

umount $BOOTTMP
umount $ROOTTMP
rmdir $BOOTTMP
rmdir $ROOTTMP

clear
while true
do
read -p "Delete downloaded files (answer yes or no)? " ANSWER
case $ANSWER in
yes)
rm $WORKINGDIR/$BOOTLOADER
rm $WORKINGDIR/$ARCHLINUX
exit
;;
no) exit;;
*) echo "ERROR: Please answer yes or no.";;
esac
done')
calzon65
 
Posts: 80
Joined: Wed May 25, 2011 9:06 pm

Return to Texas Instruments (TI)

Who is online

Users browsing this forum: No registered users and 8 guests