source: umon/ports/beagleboneblack/sd_setup.sh @ ddf6706

Last change on this file since ddf6706 was b919871, checked in by Jarielle Catbagan <jcatbagan93@…>, on 07/13/15 at 23:25:20

BBB: sd_setup.sh: Change /bin/bash -> /bin/sh to solely adhere to POSIX shell constructs

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/bin/sh
2#
3# This script automates the process of setting up an SD card for
4# either "raw" or FAT mode booting for the Beaglebone Black.
5
6if [ $# -ne 2 ]; then
7        printf  "Please specify both the boot mode and the SD card to set up\n"
8        printf "Usage: ./sd_setup.sh <boot mode> /dev/<device>\n"
9        printf "where <boot mode> is either RAW or FAT and <device> is the SD card"
10        exit 1
11fi
12
13BOOTMODE=$1
14SDDEV=$2
15
16case $1 in
17RAW)
18        if [ ! -e ./build_BEAGLEBONEBLACK/rawboot.bin ]; then
19                printf "rawboot.bin does not exist in ./build_BEAGLEBONEBLACK\n"
20                printf "Please build uMon before proceeding"
21                exit 1
22        fi
23
24        # Clear all offsets where a vaild uMon image for "raw" mode booting can exist
25        dd if=/dev/zero of=${SDDEV} bs=1M count=1
26
27        # Get the size of the uMon image to transfer into the SD card.
28        UMON_IMG_SIZE=`wc --bytes ./build_BEAGLEBONEBLACK/rawboot.bin | cut -f 1 -d ' '`
29
30        # Store the uMon image at offset 0x00000 by default
31        dd if=./build_BEAGLEBONEBLACK/rawboot.bin of=${SDDEV} bs=1 count=${UMON_IMG_SIZE}
32        ;;
33FAT)
34        if [ ! -e ./build_BEAGLEBONEBLACK/MLO ]; then
35                printf "MLO does not exist in ./build_BEAGLEBONEBLACK\n"
36                printf "Please build uMon before proceeding"
37                exit 1
38        fi
39
40        # Clear the partition table at the base of the SD card
41        dd if=/dev/zero of=${SDDEV} bs=1M count=1
42
43        # Create the FAT16 primary partition and mark it bootable
44        printf "n\np\n1\n\n+3M\nt\n6\na\n1\nw\n" | fdisk ${SDDEV}
45
46        # Wait for some time to allow the partition to register under /dev
47        sleep 1
48
49        mkfs.fat -v -f 2 -F 16 -M 0xF8 -s 1 -S 512 ${SDDEV}1
50
51        mkdir mnt
52        mount ${SDDEV}1 mnt
53        cp ./build_BEAGLEBONEBLACK/MLO mnt
54        sync
55        umount mnt
56        sync
57        rm -rf mnt
58        ;;
59*)
60        printf "Invalid boot mode specified.  Valid boot modes are RAW/FAT."
61        exit 1
62        ;;
63esac
64
Note: See TracBrowser for help on using the repository browser.