Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 333 lines (303 sloc) 7.313 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
#!/bin/bash
# Licensed under terms of GPLv2
# (c) 2010 BugLabs Mike Grundy <Michael.Grundy@buglabs.net>
#
# mkcard() from mkcard.sh v0.5
# (c) Copyright 2009 Graeme Gregory <dp@xora.org.uk>
#
# Parts of the procudure base on the work of Denys Dmytriyenko
# http://wiki.omap.com/index.php/MMC_Boot_Format

prompt()
{
tvar=L
while [ "$tvar" != "y" ] &&
[ "$tvar" != "Y" ] &&
[ "$tvar" != "n" ] &&
[ "$tvar" != "N" ] &&
[ "$tvar" != "r" ] &&
[ "$tvar" != "R" ]; do

read -n1 tvar

done
export $1=$tvar
}

x-loader () {
cp ./x-loader/MLO $1/MLO
cp ./x-loader/x-load.bin.ift $1/x-load.bin.ift
}

mtest-build () {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./memtest/uImage $1
cp ./memtest/ramdisk.ui $1
cp ./memtest/config.img $1
cp ./u-boot/pu-boot.bin $1
}

ptest-build () {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./pimtest/uImage $1
cp ./pimtest/ramdisk.ui $1
cp ./pimtest/config.img $1
}
pprog-build () {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./pimprog/uImage $1
cp ./pimprog/ramdisk.ui $1
cp ./pimtest/config.img $1
}

fcc-build () {
cp ./u-boot/u-boot.gold-bin $1/u-boot.bin
cp ./fcc/uImage $1
cp ./fcc/ramdisk.gz $1
}

flash-build () {
if [[ "$uboot" == "force" ]]; then
cp ./u-boot/u-boot-force-env $1/u-boot.bin
else
cp ./u-boot/pu-boot.bin $1/u-boot.bin
fi
cp ./u-boot/pu-boot.bin $1
cp ./flash/config.img $1
}

vtest-build() {
cp ./u-boot/u-boot.gold-bin $1/u-boot.bin
cp ./uImage/uImage $1
cp ./vtest/ramdisk.gz $1
}

camera-build() {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./camtest/uImage $1
cp ./camtest/ramdisk.ui $1
cp ./pimtest/config.img $1
}
lcd-build() {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./lcdtest/uImage $1
cp ./lcdtest/ramdisk.ui $1
cp ./pimtest/config.img $1
}
video-build() {
cp ./u-boot/u-boot-force-env $1/u-boot.bin
cp ./videotest/uImage $1
cp ./videotest/ramdisk.ui $1
cp ./pimtest/config.img $1
}
vtest-vars () {
echo wlan_ip=192.168.1.10$1 > $2/testvars
echo test_ip=192.168.1.1 >>$2/testvars
echo source_addr=192.168.1.10$1 >>$2/testvars
echo dest_addr=192.168.1.1 >>$2/testvars
echo wlan_name=bugbasetesting >>$2/testvars
}

mkcard(){
export LC_ALL=C

DRIVE=$1
PARTNAME=$2
if [ -e $PARTNAME ]; then
PARTNAME="BUGCARD"
fi

sleep 5
umount ${DRIVE}*

dd if=/dev/zero of=$DRIVE bs=1024 count=1024
if [ $? != "0" ];then
echo "Partition table wipe (dd) failed"
exit
fi

SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
CYLINDERS=`echo $SIZE/255/63/512 | bc`
# echo DISK SIZE: $SIZE bytes CYLINDERS: $CYLINDERS

{
echo ,9,0x0C,*
echo ,,0x0C,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
if [ $? != "0" ];then
echo sfdisk failed, exiting
exit
fi

sleep 1

if [ -b ${DRIVE}1 ]; then
umount ${DRIVE}1
mkfs.vfat -F 32 -n "${PARTNAME}" ${DRIVE}1
if [ $? != "0" ];then
echo mkfs failed, exiting
exit
fi
elif [ -b ${DRIVE}p1 ]; then
umount ${DRIVE}p1 2&>1 > /dev/null
mkfs.vfat -F 32 -n "${PARTNAME}" ${DRIVE}p1
if [ $? != "0" ];then
echo mkfs failed, exiting
exit
fi
else
echo "Cant find boot partition in /dev"
exit
fi

if [ -b ${DRIVE}2 ]; then
umount ${DRIVE}2
mkfs.vfat -F 32 -n "${PARTNAME}-2" ${DRIVE}2
if [ $? != "0" ];then
echo mkfs failed, exiting
exit
fi
elif [ -b ${DRIVE}p2 ]; then
umount ${DRIVE}p2
mkfs.vfat -F 32 -n "${PARTNAME}-2" ${DRIVE}p2
if [ $? != "0" ];then
echo mkfs failed, exiting
exit
fi
else
echo "Cant find 2nd partition in /dev"
exit
fi
}

help () {
echo sdbuild - Designed to keep Rao and the fine folks at CircuitCo happy
echo " -d Device name of the sd card you are building"
echo " -e Override any existing u-boot environment (factory only)"
echo -e " This will erase the mac address (hence factory only)"
echo " -f Create bootloader flash card"
echo " -m Create memory test / burn-in card"
#echo " -p Create module test card"
echo " -n Test Fixture ID (only used with -v)"
echo " -v Create verification test card"
echo " --pprog Create module eeprom programming card"
#echo " --fcc create FCC test card"
echo " --vid Create Video module test card"
echo " --lcd Create LCD module test card"
echo " --cam Create Camera module test card"
}

if [ $# -eq 0 ]; then
help
exit -1
fi

while [ $# -gt 0 ]; do
# -d Device name
if [ "$1" == "-d" ]; then
shift
if [ -b $1 ]; then
devname=$1
mountpoint=/media/$(echo $devname | sed 's:/dev/::')1
else
echo $1 is not a valid block device
exit -1
fi
# --cam Create camera pim test
elif [ "$1" == "--cam" ]; then
buildtype=camera
# -e Elpida memory (micron is the default)
elif [ "$1" == "-e" ]; then
uboot=force
# -f Create bootloader flash disk
elif [ "$1" == "-f" ]; then
buildtype=flash
# --fcc Create FCC certification disk
elif [ "$1" == "--fcc" ]; then
buildtype=fcc
# --pprog Create pim test
elif [ "$1" == "--pprog" ]; then
buildtype=pprog
# --lcd Create lcd pim test
elif [ "$1" == "--lcd" ]; then
buildtype=lcd
# -m Create memory test
elif [ "$1" == "-m" ]; then
buildtype=mtest
# -n Test Fixture ID (only used with -v)
elif [ "$1" == "-n" ]; then
shift
fixid=$1
# -v Create verification test
elif [ "$1" == "-v" ]; then
buildtype=vtest
# -v Create pim test
elif [ "$1" == "-p" ]; then
buildtype=ptest
# --vid Create video pim test
elif [ "$1" == "--vid" ]; then
buildtype=video
# Create a better informed user
elif [ "$1" == "--help" ]; then
help
exit -1
else
echo
echo $1 is not a valid option. Try one of these instead:
echo
help
exit
fi
shift
done

if [ "$devname" == "" ]; then
echo
echo "you must specify a device with the -d option"
echo
help
exit -1
fi

if [[ $EUID -ne 0 ]]; then
echo
echo "You need superuser privs to do anything constructive, sudo please"
echo
help
exit 1
fi

if [ "$buildtype" == "vtest" ]; then
if [ "$fixid" == "" ]; then
echo You have to specify -n with -v
help
exit
fi
volid=TESTRIG${fixid}
elif [ "$buildtype" == "ptest" ]; then
volid=PIMTEST
elif [ "$buildtype" == "pprog" ]; then
volid=PIMPROG
elif [ "$buildtype" == "mtest" ]; then
volid=MEMTEST
elif [ "$buildtype" == "flash" ]; then
volid=FLASH
elif [ "$buildtype" == "fcc" ]; then
volid=FCCTEST
elif [ "$buildtype" == "camera" ]; then
volid=CAMERATEST
elif [ "$buildtype" == "lcd" ]; then
volid=LCDTEST
elif [ "$buildtype" == "video" ]; then
volid=VIDEOTEST
else
echo Internal Error, sorry
exit
fi

while [ 1 ]; do

echo partitioning and formatting card
mkcard $devname $volid
echo mounting partition
pmount ${devname}1
if [ ! -d $mountpoint ]; then
echo mount failed
exit
fi
echo Writing x-loader for ${memtype}
x-loader ${mountpoint}
echo Writing files to disk
${buildtype}-build ${mountpoint}
if [ "$buildtype" == "vtest" ] ||[ "$buildtype" == "fcc" ] ; then
vtest-vars ${fixid} ${mountpoint}
fi

pumount ${devname}1
clear
echo
echo
echo
echo
echo "********************************************************************"
echo "SD Card build complete. Would you like to create another copy? (y/n)"
echo "********************************************************************"

prompt finished

if [ $finished == "n" ]; then
break
else
continue
fi
done
Something went wrong with that request. Please try again.