Monday, September 24, 2012

Objective 3: Load an Angstrom Linux Distribution onto a microSD Card

Loading a custom Angstrom or other Linux distribution gives you the flexibility to choose which packages you need for a given application. For example, if you are developing a lightweight server you may not need to include the X11 GUI framework. Also, if anything should happen to your precious microSD card preloaded with Angstrom, you should know how to build another for yourself.
  1. Plug a new microSD card (Not the one provided by TI) into your computer using your card reader or USB Adapter.
  2. Determine where it is mounted by opening up a terminal and typing the following command:
  3. df -h
    

    The output will look something like:
    Filesystem      Size  Used Avail Use% Mounted on 
    /dev/sda1       147G   13G  128G   9% / 
    udev            999M  4.0K  999M   1% /dev 
    tmpfs           403M  864K  402M   1% /run 
    none            5.0M     0  5.0M   0% /run/lock 
    none           1006M  216K 1006M   1% /run/shm 
    /dev/sdc1       7.5G  4.0K  7.5G   1% /media/2C10-00CD 
    

    The microSD card in this example is the file system on the last line and the device directory of the card is “/dev/sdc”. Notice that I did not say “sdc1”. The “1” refers to the partition on the card. Since this card is fresh it has only 1 partition.

  4. The Angstrom Linux Distribution requires two partitions on the microSD card. The FAT partition holds the boot files and the EXT3 partition holds everything else. Graeme Gregory, a contributor to openEmbedded, has made available a script to correctly partition your microSD card. Use the following commands to make a working directory, download the script, and execute the script. Remember, if your microSD card's device directory is different than mine (/dev/sdc), replace it in the last two lines and include the partition number in the second-to-last line for the following commands:
  5. mkdir ~/angstrom-wrk
    cd ~/angstrom-wrk
    wget http://cgit.openembedded.org/cgit.cgi/openembedded/plain/contrib/angstrom/omap3-mkcard.sh
    chmod +x omap3-mkcard.sh
    umount /dev/sdc1
    sudo ./omap3-mkcard.sh /dev/sdc
    

    The output will look something like:
    1024+0 records in 
    1024+0 records out 
    1048576 bytes (1.0 MB) copied, 3.07149 s, 341 kB/s 
    Disk /dev/sdc doesn't contain a valid partition table 
    DISK SIZE - 8035237888 bytes 
    CYLINDERS - 976 
    
    Disk /dev/sdc: 976 cylinders, 255 heads, 63 sectors/track 
    
    sfdisk: ERROR: sector 0 does not have an msdos signature 
     /dev/sdc: unrecognized partition table type 
    Old situation: 
    No partitions found 
    New situation: 
    Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 
    
       Device Boot Start     End   #cyls    #blocks   Id  System 
    /dev/sdc1   *      0+      8       9-     72261    c  W95 FAT32 (LBA) 
    /dev/sdc2          9     975     967    7767427+  83  Linux 
    /dev/sdc3          0       -       0          0    0  Empty 
    /dev/sdc4          0       -       0          0    0  Empty 
    Successfully wrote the new partition table 
    
    Re-reading the partition table ... 
    
    If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) 
    to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1 
    (See fdisk(8).) 
    ./omap3-mkcard.sh: 37: ./omap3-mkcard.sh: kpartx: not found 
    umount: /dev/sdc1: not mounted 
    mkfs.vfat 3.0.12 (29 Oct 2011) 
    umount: /dev/sdc2: not mounted 
    mke2fs 1.42 (29-Nov-2011) 
    Filesystem label=Angstrom 
    OS type: Linux 
    Block size=4096 (log=2) 
    Fragment size=4096 (log=2) 
    Stride=0 blocks, Stripe width=0 blocks 
    485760 inodes, 1941856 blocks 
    97092 blocks (5.00%) reserved for the super user 
    First data block=0 
    Maximum filesystem blocks=1992294400 
    60 block groups 
    32768 blocks per group, 32768 fragments per group 
    8096 inodes per group 
    Superblock backups stored on blocks: 
     32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done 
    Writing superblocks and filesystem accounting information: done
    

  6. Execute the following command:
  7. sync
    

  8. Remove the microSd card from the computer, wait a couple seconds, and plug it back in. Execute the following command to verify that the correct partitions have been created:
  9. df -h
    

    The output should look something like:
    Filesystem      Size  Used Avail Use% Mounted on 
    /dev/sda1       147G   13G  128G   9% / 
    udev            999M  4.0K  999M   1% /dev 
    tmpfs           403M  868K  402M   1% /run 
    none            5.0M     0  5.0M   0% /run/lock 
    none           1006M  216K 1006M   1% /run/shm 
    /dev/sdc2       7.3G  145M  6.8G   3% /media/Angstrom 
    /dev/sdc1        70M   512   70M   1% /media/boot 
    

    Notice that there is now an sdc1 partition mounted on /media/boot and an sdc2 partition mounted on /media/Angstrom
  10. The Narcissus website contains a tool that creates root file system images for Angstrom Linux Distributions. Go to this website using the following link: http://narcissus.angstrom-distribution.org/
  11. Select “Beagleboard” from the list of machines to build the rootfs for. Both the Beagleboard and Beagleboard-xM us the same build from the Narcissus rootfs image tool. Choose “simple” for the complexity of the options to choose from. Choose “Console only” for the user interface selection. For the additional packages selection, expand “Platform Specific Packages”, and select “Bootloader Files (x-load/u-boot/scripts)” under “Texas Instruments OMAP3x/AM3x family”.
  12. Click the “Build Me!” button. When the requested files are generated, download the file with the .tar.gz extension into your /angstrom-wrk directory. My generated file is “random-c534e16b-image-beagleboard.tar.gz”
  13. To extract and copy the required boot files to the proper directories on the microSD card, execute the following commands:
  14. tar --wildcards -xzvf random-c534e16b-image-beagleboard.tar.gz ./boot/*
    cp boot/MLO-* /media/boot/MLO
    cp boot/uImage-* /media/boot/uImage
    cp boot/u-boot-*.bin /media/boot/u-boot.bin
    sync
    sudo tar -xzv -C /media/Angstrom -f random-c534e16b-image-beagleboard.tar.gz
    sync
    

  15. Unmount the microSD card by executing the following commmands:
  16. umount /media/boot
    umount /media/Angstrom
    

  17. Remove the microSD card from your computer and insert it into the Beagleboard-xM. Apply power to the Beagleboard-xM and allow Angstrom to boot. You can login to Angstrom as username “root”.

How I learned this:

No comments:

Post a Comment