EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Partitioning SD card for pandaboard and beagleboard XM

Go down

Partitioning SD card for pandaboard and beagleboard XM Empty Partitioning SD card for pandaboard and beagleboard XM

Post  Admin Sat Jun 29, 2013 6:28 pm

SD Configuration and Setup for pandaboard and beagleboard XM

There are 2 approaches to format the SD card. You could either use the script available or follow the step by step instructions below.
Note: All these instructions are common across all OMAP platforms.



Preparation

Before you start, you need to know the device name for your SD-Card.

Getting the device name for your SD-Card:
If you have no idea which device name is correct run the following command.

Code:
$ sudo fdisk -ls

The device name you are looking for is the Disk which comes close the size of your SD-Card (e.g. for a 8 GB SD-Card one line might look like this: Disk /dev/sde: 8011 MByte, 8011120640 Byte. - so the device name for the SD-Card will be /dev/sde).



Script to partition/format SDCards


Attention: On 2010-07-29 the name of the second partition has been changed from "rootfs" to "Angstrom". So in order to use the script to create your SD-Card and use it with some prebuild binaries (like e.g. Pandroid) you have to change the name back to "rootfs" as it otherwise won't work.
http://git.openembedded.org/openembedded/tree/contrib/angstrom/omap3-mkcard.sh Note You have to open the link and copy the script to a local file, otherwise it just downloads the HTML code.

The usage of the script is:

Code:
$ sudo ./omap3-mkcard.sh /dev/sd<x>





You can also use this script which will refuse to use /dev/sda as the device (that tends to be your primary HDD!):


Code:

#!/bin/bash
if [ ! "$1" = "/dev/sda" ] ; then
 unset LANG
 DRIVE=$1
 if [ -b "$DRIVE" ] ; then
 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
 fi
fi


After running the script mount the SD card partitions on host:


Code:
mkdir /tmp/mmc1
mkdir /tmp/mmc2
sudo mount /dev/sdx1 /tmp/mmc1
sudo mount /dev/sdx2 /tmp/mmc2

Verified to work on Ubuntu to boot boards such as beagle, omapzoom2 etc. A big thanks to XorA!






Alternative Script to format SD Cards for 3 partitions

Some times you may want 3 partitions. You may also want to format only the boot and rootfs partitions, and leave the media files in a separate partition for reuse with the new images.

When we format the boot partition we also need to change Android BOOT binaries in order to work around some known limitations. But every time we format the boot partition, we have to copy all the media files once again (which is very annoying). So, it is more convenient to place the video clips, jpegs and any other media content in a separate FAT partition which need not be touched while changing the boot binaries.

Here is a script which lets you either created 2 or 3 partitions (the optional 'media drive' if you want to). It is more generalized than the above script -- because it extends its functionality. With this script you can also just format the first two drives without touching the media drive (the third one):


  •    FAT/boot partition


  •    EXT3 partition


  •    FAT partition for media files


Copy the below text into a file (say, mkcard.sh). Make the file an executable file (chmod +x mkcard.sh). Then you can run it with administrative privileges like $sudo ./mkcard.sh /dev/sdx.) sdx is the name of your device on which the SD card is mounted. (Warning: This is, of course, a dangerous process if wrong arguments are given.)

For some reason the script may not work when running the first time (at least with brand new SD). Getting errors such as "Can't find rootfs partition in /dev". Then just run the script again and it should work.

Code:

#! /bin/bash
# mkcard.sh v0.5
# (c) Copyright 2009 Graeme Gregory <dp@xora.org.uk>
# Licensed under terms of GPLv2
#
# Parts of the procudure base on the work of Denys Dmytriyenko
# http://wiki.omap.com/index.php/MMC_Boot_Format
#
# Extended for 3 partitions by Prasad Golla <golla@ti.com> in April 2011.
# The 'media' partition can be used for storing media clips which can
# be preserved even if the binaries in the other partitions are erased.

export LC_ALL=C

if [ $# -ne 1 ]; then
        echo "Usage: $0 <drive>"
        exit 1;
fi

DRIVE=$1

SKIPMEDIA=0

function format_boot_drive (){
echo "Formatting boot drive"
if [ -b ${DRIVE}1 ]; then
        umount ${DRIVE}1
        mkfs.vfat -F 32 -n "boot" ${DRIVE}1
else
        if [ -b ${DRIVE}p1 ]; then
                umount ${DRIVE}p1
                mkfs.vfat -F 32 -n "boot" ${DRIVE}p1
        else
                echo "Can't find boot partition in /dev"
        fi
fi
}

function format_rootfs_drive (){
echo "Formatting rootfs drive"
if [ -b ${DRIVE}2 ]; then
        umount ${DRIVE}2
        mke2fs -j -L "rootfs" ${DRIVE}2
else
        if [ -b ${DRIVE}p2 ]; then
                umount ${DRIVE}p2
                mke2fs -j -L "rootfs" ${DRIVE}p2
        else
                echo "Can't find rootfs partition in /dev"
        fi
fi
}

function format_media_drive (){
echo "Formatting media mediadrive"
if [ -b ${DRIVE}3 ]; then
        umount ${DRIVE}3
        mkfs.vfat -F 32 -n "media" ${DRIVE}3
else
        if [ -b ${DRIVE}p3 ]; then
                umount ${DRIVE}p3
                mkfs.vfat -F 32 -n "media" ${DRIVE}p3
        else
                echo "Can't find media partition in /dev"
        fi
fi
}

function get_media_drive_size(){

echo "How big of a media drive do you want?"
echo "Enter 0 to NOT create the media drive."
echo "Enter 1 for 1GB."
echo "Enter 64 for 64MB."
echo "Enter 128 for 128MB."
echo "Enter 512 for 512MB."
echo "Enter 256 for 256MB."
echo -n "Enter size of media drive you want: "

read disksize

case "$disksize" in
0)   SKIPMEDIA=1; return ;;
1)   MEDIASIZEREQ=`echo "1024 * 1024 * 1024" | bc` ;;
512) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 2" | bc` ;;
256) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 4" | bc` ;;
128) MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 8" | bc` ;;
64)  MEDIASIZEREQ=`echo "1024 * 1024 * 1024 / 16" | bc` ;;
*)   echo "Not a valid option. Try again."; get_media_drive_size;;
esac

echo Media size in bytes - $MEDIASIZEREQ
MEDIACYLINDERS=`echo $MEDIASIZEREQ/255/63/512 | bc`
echo Media CYLINDERS - $MEDIACYLINDERS

}

function create_drives(){
dd if=/dev/zero of=$DRIVE bs=1024 count=1024

SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`

echo DISK SIZE - $SIZE bytes

CYLINDERS=`echo $SIZE/255/63/512 | bc`
echo CYLINDERS - $CYLINDERS

get_media_drive_size;

if [ $SKIPMEDIA == 1 ] ; then
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
sleep 1
return;
fi

LASTCYLINDERLINUX=`echo $CYLINDERS - 9 - $MEDIACYLINDERS | bc`

{
echo ,9,0x0C,*
echo ,$LASTCYLINDERLINUX,,-
echo ,,0x0C,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE

sleep 1
}

echo "To format the boot and rootfs only, enter 'f'."
echo "To create the boot, media and rootfs and format them, enter 'c'."
echo -n "Enter c or f:"

read answer

case "$answer" in
f) format_boot_drive; format_rootfs_drive; exit ;;
c) create_drives; format_boot_drive; format_rootfs_drive; format_media_drive; exit;;
*) echo "Not a valid option. Exiting"; exit ;;
esac




Step by Step Instructions to format SD card


Since putting a Linux file system on a FAT32 partition is problematic, it is recommended to also create a 2nd partition.


  •    Insert your SD card into your Linux box


  •    Do not mount it


The card shows up as /dev/sd*. To identify the card, you can either do:


  •    dmesg | grep sd[a-z]. You will see something like [172407.246308] sdb: sdb1 sdb2 so drive is /dev/sdb


  •    ls /dev/sd* before and after plugging SD card and find created devices



For this example


  •    we will assume the card shows up as /dev/sdc - substitute this for the real device on your specific machine. Fdisk the drive and print the partition information


Code:
sudo fdisk /dev/sdc
Command (m for help): p
Disk /dev/sdc: 1018 MB, 993001472 bytes
...<more>...

Look for the size in bytes of the device and calculate the number of cylinders, dropping fractions, if we have 255 heads and 63 sectors (and 512 bytes per sector so 1 cylinder is 255 * 63 * 512 = 8225280 bytes).


new_cylinders = Size / 8225280 (for this example we will have 993001472 / 8225280 which equals 120.725 or 120 cylinders)




Delete existing Partitions



Since we are changing the underlying geometry of the disk, we must clear the partition table before doing it. So delete all partitions using the fdisk 'd' command - yes, you will lose all data on the card. Once that is done, we can set the new geometry in expert mode. We will set the number of heads to 255, number of sectors to 63, and number of cylinders to new_cylinders.

Code:
Command (m for help):  d
Partition number (1-4): 1
Command (m for help):  d
Partition number (1-4): 2

Delete existing Partitions Configure SD Card


Code:
Command (m for help): x
Expert command (m for help): h
Number of heads (1-256, default 30): 255
Expert command (m for help): s
Number of sectors (1-63, default 29): 63
Warning: setting sector offset for DOS compatiblity
Expert command (m for help): c
Number of cylinders (1-1048576, default 2286): <new_cylinders calculated from above>




Configure SD Partitions


Now we return to the main menu and create 2 partitions as needed - 1 boot partition of 64Meg and the rest a linux partition.


  •    Note: +64M is used to set the boot partition to 64MB. If media content is stored on the SD this parition size should be increased to make room for media content (mp3, mp4, aac, etc...). Assuming a 2GB SD card is used a partition size of +1024MB should be enough to handle 1GB of media content.


Code:

Expert command (m for help): r
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-123, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-123, default 123): +64M (see note above)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (10-123, default 10):
Using default value 10
Last cylinder or +size or +sizeM or +sizeK (10-123, default 123):
Using default value 123


Fat32 Partition

Code:
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))
* You have to format 1st partitions with vfat32 filesystem.
Command (m for help): a
Partition number (1-4): 1


Check Partition Table

Code:

The partition table should look something like the following. Notice the heads, sectors, and cylinders. Make sure partition 1 is active and FAT32. If it looks good - write the new partition information out.

Command (m for help): p
Disk /dev/sdc: 993 MB, 993001472 bytes
255 heads, 63 sectors/track, 120 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdc1 * 1 9 72261 c W95 FAT32 (LBA)
/dev/sdc2 10 120 891607+ 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.


Formatting Partitions

Format the filesystems on the partitions:

Code:
# sudo mkfs.vfat -F 32 -n boot /dev/sdc1
# sudo mkfs.ext3 -L rootfs /dev/sdc2

Creating a mount point

Code:
mkdir /tmp/mmc1
mkdir /tmp/mmc2
sudo mount /dev/sdc1 /tmp/mmc1
sudo mount /dev/sdc2 /tmp/mmc2



Problem seen with FDISK not erasing the first sector
The fdisk utility does not seem to erase the first few bytes of the first sector in the card when the partition table is saved.
Use dd to erase the first sector.

Code:
sudo dd if=/dev/zero of=/dev/<sdb> bs=1024 count=1


Then use the procedure listed in section above to create new partitions and format them accordingly



Video walkthrough


A video walkthrough of the above process can be found below:



Admin
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum