Esempio n. 1
0
def buildBootloader():
    os.chdir(getScriptDir())

    # This might need partner repos enabled
    ensureDependencies(['ia32-libs'])

    print('Building bootloader')

    # Clone RCN's git repository
    gitCloneAndEnter('git://github.com/RobertCNelson/Bootloader-Builder.git',
                     '607af4c206a3f')

    # Patch the bootloader
    # GPIO mux settings can be found in u-boot/board/ti/beagle/beagle.h
    patches = [
        '0001-Only-build-for-beagleboard.patch',
        '0002-Add-patch-to-change-boot-delay-to-0-seconds.patch',
        '0003-Add-patch-to-set-BeagleBoard-xM-pin-mux.patch'
    ]
    patchdir = os.path.realpath(
        os.path.join(getScriptDir(), 'patches', 'Bootloader-Builder'))
    for patch in patches:
        subprocess.call(['git', 'am', os.path.join(patchdir, patch)])

    # Build the bootloader
    subprocess.call(['./build.sh'])
    os.chdir('..')
Esempio n. 2
0
def main():
	# Make sure our current working dir is the script's location
	os.chdir(getScriptDir())
	loadSettings()
	enabledRestricted()
	installDependencies()
	installUtilities()
	installCore()
Esempio n. 3
0
def main():
    # Make sure our current working dir is the script's location
    os.chdir(getScriptDir())
    loadSettings()
    enabledRestricted()
    installDependencies()
    installUtilities()
    installCore()
Esempio n. 4
0
def buildBootloader():
	os.chdir(getScriptDir())

	# This might need partner repos enabled
	ensureDependencies(['ia32-libs'])

	print('Building bootloader')

	# Clone RCN's git repository
	gitCloneAndEnter('git://github.com/RobertCNelson/Bootloader-Builder.git', '607af4c206a3f')
	
	# Patch the bootloader
	# GPIO mux settings can be found in u-boot/board/ti/beagle/beagle.h
	patches = [
		'0001-Only-build-for-beagleboard.patch',
		'0002-Add-patch-to-change-boot-delay-to-0-seconds.patch',
		'0003-Add-patch-to-set-BeagleBoard-xM-pin-mux.patch']
	patchdir = os.path.realpath(os.path.join(getScriptDir(), 'patches', 'Bootloader-Builder'))
	for patch in patches:
		subprocess.call(['git', 'am', os.path.join(patchdir, patch)])
	
	# Build the bootloader
	subprocess.call(['./build.sh'])
	os.chdir('..')
Esempio n. 5
0
def buildQemu():
	os.chdir(getScriptDir())
	# Install dependencies
	ensureDependencies(['libglib2.0-dev', 'binfmt-support', 'qemu'])
	subprocess.call(['sudo', 'apt-get', '-y', 'build-dep', 'qemu'])
	
	# Clone RCN's git repository
	print('Building under Qemu')
	gitCloneAndEnter('git://github.com/RobertCNelson/linaro-tools.git', '4a1cb42df6e58')
	
	# Build and install qemu
	os.chdir('qemu') # MUST CD INTO DIRECTORY
	subprocess.call(['./build_qemu.sh'])
	os.chdir('..')
	os.chdir('..')
Esempio n. 6
0
def buildKernel():
    os.chdir(getScriptDir())
    loadSettings()

    # Install dependencies (Ubuntu needs u-boot-tools, Debian needs uboot-mkimage)
    ensureDependencies(
        ['gcc-arm-linux-gnueabi', 'u-boot-tools', 'device-tree-compiler'])

    # Clone the linux kernel source tree
    print('Cloning the Linux kernel source tree')
    linuxDirName = gitCloneAndEnter(
        'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git',
        'master')
    os.chdir('..')

    # Clone RCN's git repository
    print('Building kernel')
    gitCloneAndEnter('git://github.com/RobertCNelson/stable-kernel.git',
                     '4d82ccd1b2093')

    # Configure the kernel build script
    shutil.copyfile('system.sh.sample',
                    'system.sh')  # Overwrites existing file
    file = open('system.sh', 'a')  # Open for appending
    file.write('LINUX_GIT=' +
               os.path.join(os.path.realpath('..'), linuxDirName) + '\n')
    file.write('ZRELADDR=0x80008000' +
               '\n')  # For TI: OMAP3/4/AM35xx (BB is OMAP3)
    #file.write('BUILD_UIMAGE=1' + '\n') # Do I need to build uImage?
    file.write('MMC=' + getSetting('mmc') + '\n')
    # Pull in Torvalds current master tree before applying local patchset
    # This is very useful during an intial 'rc0' merge.
    # It is never supported... Enable at your own risk
    #file.write('LATEST_GIT=1' + '\n')
    file.write(
        'LOCAL_PATCH_DIR=' +
        os.path.join(os.path.realpath('..'), 'patches', 'stable-kernel') +
        '\n')
    file.close()
    # Adding the CC parameter is a little more complex... we need to seek out
    # the config line and uncomment it.
    replaceAll('system.sh', '#CC=arm-linux-gnueabi-', 'CC=arm-linux-gnueabi-')

    # Build the kernel
    subprocess.call(['./build_deb.sh'])
    os.chdir('..')
Esempio n. 7
0
def installRosDeps():
	# Make sure our current working dir is the script's location
	os.chdir(getScriptDir())
	
	if not os.path.exists('rosdeps'):
		os.makedirs('rosdeps')
	os.chdir('rosdeps')
	
	# yaml-cpp
	# Required by the navigation stack
	# If 0.3.0 doesn't work, use https://github.com/wg-debs/yaml_cpp-release (0.2.7)
	if not os.path.exists('/usr/local/lib/libyaml-cpp.a'):
		if os.path.exists('yaml-cpp'):
			subprocess.call(['rm', '-rf', 'yaml-cpp'])
		get('http://yaml-cpp.googlecode.com/files/yaml-cpp-0.3.0.tar.gz')
		os.chdir('yaml-cpp')
		os.makedirs('build')
		os.chdir('build')
		subprocess.call(['cmake', '..'])
		subprocess.call(['make'])
		subprocess.call(['sudo', 'make', 'install'])
		os.chdir('..')
		os.chdir('..')
		subprocess.call(['rm', '-rf', 'yaml-cpp'])
	
	# ros-fuerte-pcl
	# Required by the perception_pcl stack
	if not os.path.exists('/usr/local/lib/libpcl_common.so'):
		# Install build dependencies (others may be required)
		subprocess.call(['sudo', 'apt-get', 'install', 'libflann-dev'])
		if os.path.exists('pcl'):
			subprocess.call(['rm', '-rf', 'pcl'])
		gitCloneAndEnter('git://github.com/wg-debs/pcl.git', 'master')
		os.makedirs('build')
		os.chdir('build')
		subprocess.call(['cmake', '-DUSE_ROS=ON', '..'])
		subprocess.call(['make'])
		subprocess.call(['sudo', 'make', 'install'])
		os.chdir('..')
		os.chdir('..')
		subprocess.call(['rm', '-rf', 'pcl'])
	
	# All done
	os.chdir('..')
	subprocess.call(['rm', '-rf', 'rosdeps'])
Esempio n. 8
0
def installRosDeps():
    # Make sure our current working dir is the script's location
    os.chdir(getScriptDir())

    if not os.path.exists('rosdeps'):
        os.makedirs('rosdeps')
    os.chdir('rosdeps')

    # yaml-cpp
    # Required by the navigation stack
    # If 0.3.0 doesn't work, use https://github.com/wg-debs/yaml_cpp-release (0.2.7)
    if not os.path.exists('/usr/local/lib/libyaml-cpp.a'):
        if os.path.exists('yaml-cpp'):
            subprocess.call(['rm', '-rf', 'yaml-cpp'])
        get('http://yaml-cpp.googlecode.com/files/yaml-cpp-0.3.0.tar.gz')
        os.chdir('yaml-cpp')
        os.makedirs('build')
        os.chdir('build')
        subprocess.call(['cmake', '..'])
        subprocess.call(['make'])
        subprocess.call(['sudo', 'make', 'install'])
        os.chdir('..')
        os.chdir('..')
        subprocess.call(['rm', '-rf', 'yaml-cpp'])

    # ros-fuerte-pcl
    # Required by the perception_pcl stack
    if not os.path.exists('/usr/local/lib/libpcl_common.so'):
        # Install build dependencies (others may be required)
        subprocess.call(['sudo', 'apt-get', 'install', 'libflann-dev'])
        if os.path.exists('pcl'):
            subprocess.call(['rm', '-rf', 'pcl'])
        gitCloneAndEnter('git://github.com/wg-debs/pcl.git', 'master')
        os.makedirs('build')
        os.chdir('build')
        subprocess.call(['cmake', '-DUSE_ROS=ON', '..'])
        subprocess.call(['make'])
        subprocess.call(['sudo', 'make', 'install'])
        os.chdir('..')
        os.chdir('..')
        subprocess.call(['rm', '-rf', 'pcl'])

    # All done
    os.chdir('..')
    subprocess.call(['rm', '-rf', 'rosdeps'])
Esempio n. 9
0
def installMobile():
    # Make sure our current working dir is the script's location
    os.chdir(getScriptDir())

    if not os.path.exists('/opt/ros/fuerte/setup.bash'):
        subprocess.call(['sudo', './installRosCore.py'])
        if not os.path.exists('/opt/ros/fuerte/setup.bash'):
            print('Script failed: sudo ./installRosCore.py')
            return

    # Acquire sudo privileges for later
    subprocess.call(['sudo', 'cat', '/dev/null'])

    url = 'http://packages.ros.org/cgi-bin/gen_rosinstall.py?rosdistro=' + \
      distro + '&variant=' + variant + '&overlay=no'
    subprocess.call(['rosinstall', os.path.expanduser(target), url])

    # Environment setup
    addBash('source /opt/ros/fuerte/setup.bash')
    # Update the environment so that the changes take effect immediately
    if not os.environ.has_key('ROS_ROOT'):
        updateEnvironment('/opt/ros/fuerte/setup.bash')
    # Bug: Why does this get a newline after ~ ?
    targetsrc = os.path.expanduser(target + '/setup.bash').replace('\n', '')
    addBash('source ' + targetsrc)
    if not os.environ.has_key('ROS_WORKSPACE'):
        updateEnvironment(targetsrc)
    ROS_WORKSPACE = os.path.expanduser(workspace).replace('\n', '')
    addBash('export ROS_PACKAGE_PATH=' + ROS_WORKSPACE + r':$ROS_PACKAGE_PATH')
    addBash('export ROS_WORKSPACE=' + ROS_WORKSPACE)

    # Build higher-level libraries and tools
    subprocess.call(['sudo', 'rosdep', 'init'])
    subprocess.call(['sudo', 'rosdep', 'update'])  # This might not need sudo

    # Install dependencies (from source, if necessary)
    installDependencies()

    # Build the ROS stacks using rosmake (might need `sudo chown -hR garrett ~/.ros`)
    # Also, this still failed, so running `rosmake -a` once as garrett and interrupting fixed it
    subprocess.call(['rosmake', '-a'])
Esempio n. 10
0
def installMobile():
	# Make sure our current working dir is the script's location
	os.chdir(getScriptDir())
	
	if not os.path.exists('/opt/ros/fuerte/setup.bash'):
		subprocess.call(['sudo', './installRosCore.py'])
		if not os.path.exists('/opt/ros/fuerte/setup.bash'):
			print('Script failed: sudo ./installRosCore.py')
			return
	
	# Acquire sudo privileges for later
	subprocess.call(['sudo', 'cat', '/dev/null'])
	
	url = 'http://packages.ros.org/cgi-bin/gen_rosinstall.py?rosdistro=' + \
			distro + '&variant=' + variant + '&overlay=no'
	subprocess.call(['rosinstall', os.path.expanduser(target), url])
	
	# Environment setup
	addBash('source /opt/ros/fuerte/setup.bash')
	# Update the environment so that the changes take effect immediately
	if not os.environ.has_key('ROS_ROOT'):
		updateEnvironment('/opt/ros/fuerte/setup.bash')
	# Bug: Why does this get a newline after ~ ?
	targetsrc = os.path.expanduser(target + '/setup.bash').replace('\n', '')
	addBash('source ' + targetsrc)
	if not os.environ.has_key('ROS_WORKSPACE'):
		updateEnvironment(targetsrc)
	ROS_WORKSPACE = os.path.expanduser(workspace).replace('\n', '')
	addBash('export ROS_PACKAGE_PATH=' + ROS_WORKSPACE + r':$ROS_PACKAGE_PATH')
	addBash('export ROS_WORKSPACE=' + ROS_WORKSPACE)
	
	# Build higher-level libraries and tools
	subprocess.call(['sudo', 'rosdep', 'init'])
	subprocess.call(['sudo', 'rosdep', 'update']) # This might not need sudo
	
	# Install dependencies (from source, if necessary)
	installDependencies()
	
	# Build the ROS stacks using rosmake (might need `sudo chown -hR garrett ~/.ros`)
	# Also, this still failed, so running `rosmake -a` once as garrett and interrupting fixed it
	subprocess.call(['rosmake', '-a'])
Esempio n. 11
0
def buildKernel():
    os.chdir(getScriptDir())
    loadSettings()

    # Install dependencies (Ubuntu needs u-boot-tools, Debian needs uboot-mkimage)
    ensureDependencies(["gcc-arm-linux-gnueabi", "u-boot-tools", "device-tree-compiler"])

    # Clone the linux kernel source tree
    print("Cloning the Linux kernel source tree")
    linuxDirName = gitCloneAndEnter("git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git", "master")
    os.chdir("..")

    # Clone RCN's git repository
    print("Building kernel")
    gitCloneAndEnter("git://github.com/RobertCNelson/stable-kernel.git", "4d82ccd1b2093")

    # Configure the kernel build script
    shutil.copyfile("system.sh.sample", "system.sh")  # Overwrites existing file
    file = open("system.sh", "a")  # Open for appending
    file.write("LINUX_GIT=" + os.path.join(os.path.realpath(".."), linuxDirName) + "\n")
    file.write("ZRELADDR=0x80008000" + "\n")  # For TI: OMAP3/4/AM35xx (BB is OMAP3)
    # file.write('BUILD_UIMAGE=1' + '\n') # Do I need to build uImage?
    file.write("MMC=" + getSetting("mmc") + "\n")
    # Pull in Torvalds current master tree before applying local patchset
    # This is very useful during an intial 'rc0' merge.
    # It is never supported... Enable at your own risk
    # file.write('LATEST_GIT=1' + '\n')
    file.write("LOCAL_PATCH_DIR=" + os.path.join(os.path.realpath(".."), "patches", "stable-kernel") + "\n")
    file.close()
    # Adding the CC parameter is a little more complex... we need to seek out
    # the config line and uncomment it.
    replaceAll("system.sh", "#CC=arm-linux-gnueabi-", "CC=arm-linux-gnueabi-")

    # Build the kernel
    subprocess.call(["./build_deb.sh"])
    os.chdir("..")
Esempio n. 12
0
def buildImage():
	os.chdir(getScriptDir())
	loadSettings()
	
	# Look for a kernel image
	imgpath = False # Discovered image goes here
	for path in ['images', os.path.join('stable-kernel', 'deploy')]:
		if not os.path.exists(path):
			continue
		files = sorted(os.listdir(path), reverse=True)
		for f in files:
			if f.endswith('.deb') and 'image' in f:
				imgpath = os.path.realpath(os.path.join(path, f))
				print('Found kernel image: ' + imgpath)
				print('rootstock will use this local image instead of http://rcn-ee.net')
				break
		if imgpath:
			break
	
	# Clone RCN's git repository
	print('Building Ubuntu image')
	gitCloneAndEnter('git://github.com/RobertCNelson/omap-image-builder.git', '73e92f5cef5d3')
	#subprocess.call(['git', 'reset', '--hard', 'HEAD'])
	
	patches = [
		'0001-Only-build-Precise-image.patch',
		'0002-Include-additional-packages-specified-in-settings.xm.patch',
		'0003-Force-MAC-address.patch',
		'0004-Remove-text-from-etc-flash-kernel.conf.patch',
		'0005-Copy-keys-to-the-new-filesystem.patch']
	if imgpath:
		patches.append('0006-Primary-kernel-is-on-local-filesystem.patch')
	if False:
		patches.append('0007-Run-script-to-install-ros.patch')
	for p in patches:
		subprocess.call(['git', 'am', os.path.join(getScriptDir(), 'patches',
			'omap-image-builder', p)])
	
	#subprocess.call(['git', 'checkout', 'v2012.4-1', '-b', 'v2012.4-1'])
	
	# Configure image builder
	replaceAll('build_image.sh', 'FQDN="arm"', 'FQDN="' + getSetting('fqdn') + '"')
	replaceAll('build_image.sh', 'USER_LOGIN="******"', 'USER_LOGIN="******"')
	replaceAll('build_image.sh', 'USER_PASS="******"', 'USER_PASS="******"')
	replaceAll('build_image.sh', 'USER_NAME="Demo User"', 'USER_NAME="' + getSetting('name') + '"')
	replaceAll('var/pkg_list.sh', '__MECANUM_PACKAGES__', ','.join(getSetting('packages')))
	if imgpath:
		# Kernel image, e.g. linux-image-3.2.18-x12_1.0precise_armhf.deb
		replaceAll('build_image.sh', '__KERNEL_DEB_FILE__', imgpath)
	
	replaceAll('tools/fixup.sh', 'DE:AD:BE:EF:CA:FE', getSetting('macaddress'))
	# Attempt to copy our ssh keys to the new filesystem
	try:
		id_rsa = open(getScriptDir() + '../../ssh_keys/id_rsa', 'r')
		rsa_private = id_rsa.read()
		id_rsa.close()
		id_rsa_pub = open(getScriptDir() + '../../ssh_keys/id_rsa.pub', 'r')
		rsa_public = id_rsa_pub.read()
		id_rsa_pub.close()
		if (len(rsa_private) and len(rsa_public)):
			replaceAll('tools/fixup.sh', '#USER_NAME=__USER_NAME__', 'USER_NAME="' + getSetting('username') + '"')
			replaceAll('tools/fixup.sh', '__RSA_PRIVATE__', rsa_private)
			replaceAll('tools/fixup.sh', '__RSA_PUBLIC__', rsa_public)
	except:
		pass
	
	# Build the image
	subprocess.call(['./build_image.sh'])
	os.chdir('..')
Esempio n. 13
0
def createCard():
    os.chdir(getScriptDir())
    loadSettings()

    fs = 'ext4'  # btrfs is waaaaaaaaay too slow on a microSD card
    # Set swap equal to amount of RAM for kernel compiling, consider disabling
    # swap for production images
    swap = 512  # MB, set to zero to disable

    # Install dependencies
    ensureDependencies(['uboot-mkimage', 'wget', 'pv', 'dosfstools', 'parted'])

    # Look for u-boot and MLO
    useStable = True  # as opposed to latest GIT
    uboot = False
    mlo = False
    ubootdir = os.path.join('Bootloader-Builder', 'deploy', 'beagleboard')
    if os.path.exists(ubootdir):
        found = useStable
        for f in sorted(os.listdir(ubootdir), reverse=True):
            if os.path.isfile(os.path.join(ubootdir, f)) and 'MLO' in f:
                # Stable will end in -r1. GIT will end in -def (three hex chars)
                # Therefore, in the real stable image comes last and the latest
                # GIT will be second-to-last. Simply use "useStable" as a flag
                # to target the second-to-last.
                if found:
                    mlo = os.path.realpath(os.path.join(ubootdir, f))
                    print('Found MLO: ' + mlo)
                    break
                else:
                    found = True
        found = useStable
        for f in sorted(os.listdir(ubootdir), reverse=True):
            if os.path.isfile(os.path.join(ubootdir, f)) and 'u-boot' in f:
                if found:
                    uboot = os.path.realpath(os.path.join(ubootdir, f))
                    print('Found u-boot: ' + uboot)
                    break
                else:
                    found = True

    # Build the image
    deploy = os.path.join('omap-image-builder', 'deploy')
    if not os.path.exists(deploy):
        print(
            'Error: omap-image-builder directory doesn\'t exist. Try running buildImage()'
        )
        return
    os.chdir(deploy)
    for f in sorted(os.listdir('.'), reverse=True):
        if not os.path.isfile(f):
            os.chdir(f)
            break
    else:
        print('Error: images not found. Try running buildImage()')
        return
    # Enter the only folder
    for f in os.listdir('.'):
        if not os.path.isfile(f):
            os.chdir(f)
            break
    else:
        print('Error: images not found. Try running buildImage()')
        return
    cmd = [
        'sudo', './setup_sdcard.sh', '--mmc',
        getSetting('mmc'), '--uboot', 'beagle_xm', '--rootfs', fs,
        '--boot_label', 'boot', '--rootfs_label', 'rootfs'
    ]
    if uboot and mlo:
        cmd.extend(['--bootloader', uboot, '--spl', mlo])
    if swap:
        cmd.extend(['--swap_file', str(swap)])
    subprocess.call(cmd)
    os.chdir('..')
    os.chdir('..')
    os.chdir('..')
    os.chdir('..')
Esempio n. 14
0
def buildImage():
    os.chdir(getScriptDir())
    loadSettings()

    # Look for a kernel image
    imgpath = False  # Discovered image goes here
    for path in ['images', os.path.join('stable-kernel', 'deploy')]:
        if not os.path.exists(path):
            continue
        files = sorted(os.listdir(path), reverse=True)
        for f in files:
            if f.endswith('.deb') and 'image' in f:
                imgpath = os.path.realpath(os.path.join(path, f))
                print('Found kernel image: ' + imgpath)
                print(
                    'rootstock will use this local image instead of http://rcn-ee.net'
                )
                break
        if imgpath:
            break

    # Clone RCN's git repository
    print('Building Ubuntu image')
    gitCloneAndEnter('git://github.com/RobertCNelson/omap-image-builder.git',
                     '73e92f5cef5d3')
    #subprocess.call(['git', 'reset', '--hard', 'HEAD'])

    patches = [
        '0001-Only-build-Precise-image.patch',
        '0002-Include-additional-packages-specified-in-settings.xm.patch',
        '0003-Force-MAC-address.patch',
        '0004-Remove-text-from-etc-flash-kernel.conf.patch',
        '0005-Copy-keys-to-the-new-filesystem.patch'
    ]
    if imgpath:
        patches.append('0006-Primary-kernel-is-on-local-filesystem.patch')
    if False:
        patches.append('0007-Run-script-to-install-ros.patch')
    for p in patches:
        subprocess.call([
            'git', 'am',
            os.path.join(getScriptDir(), 'patches', 'omap-image-builder', p)
        ])

    #subprocess.call(['git', 'checkout', 'v2012.4-1', '-b', 'v2012.4-1'])

    # Configure image builder
    replaceAll('build_image.sh', 'FQDN="arm"',
               'FQDN="' + getSetting('fqdn') + '"')
    replaceAll('build_image.sh', 'USER_LOGIN="******"',
               'USER_LOGIN="******"')
    replaceAll('build_image.sh', 'USER_PASS="******"',
               'USER_PASS="******"')
    replaceAll('build_image.sh', 'USER_NAME="Demo User"',
               'USER_NAME="' + getSetting('name') + '"')
    replaceAll('var/pkg_list.sh', '__MECANUM_PACKAGES__',
               ','.join(getSetting('packages')))
    if imgpath:
        # Kernel image, e.g. linux-image-3.2.18-x12_1.0precise_armhf.deb
        replaceAll('build_image.sh', '__KERNEL_DEB_FILE__', imgpath)

    replaceAll('tools/fixup.sh', 'DE:AD:BE:EF:CA:FE', getSetting('macaddress'))
    # Attempt to copy our ssh keys to the new filesystem
    try:
        id_rsa = open(getScriptDir() + '../../ssh_keys/id_rsa', 'r')
        rsa_private = id_rsa.read()
        id_rsa.close()
        id_rsa_pub = open(getScriptDir() + '../../ssh_keys/id_rsa.pub', 'r')
        rsa_public = id_rsa_pub.read()
        id_rsa_pub.close()
        if (len(rsa_private) and len(rsa_public)):
            replaceAll('tools/fixup.sh', '#USER_NAME=__USER_NAME__',
                       'USER_NAME="' + getSetting('username') + '"')
            replaceAll('tools/fixup.sh', '__RSA_PRIVATE__', rsa_private)
            replaceAll('tools/fixup.sh', '__RSA_PUBLIC__', rsa_public)
    except:
        pass

    # Build the image
    subprocess.call(['./build_image.sh'])
    os.chdir('..')
Esempio n. 15
0
def createCard():
	os.chdir(getScriptDir())
	loadSettings()
	
	fs = 'ext4' # btrfs is waaaaaaaaay too slow on a microSD card
	# Set swap equal to amount of RAM for kernel compiling, consider disabling
	# swap for production images
	swap = 512 # MB, set to zero to disable
	
	# Install dependencies
	ensureDependencies(['uboot-mkimage', 'wget', 'pv', 'dosfstools', 'parted'])
	
	# Look for u-boot and MLO
	useStable = True # as opposed to latest GIT
	uboot = False
	mlo = False
	ubootdir = os.path.join('Bootloader-Builder', 'deploy', 'beagleboard')
	if os.path.exists(ubootdir):
		found = useStable
		for f in sorted(os.listdir(ubootdir), reverse=True):
			if os.path.isfile(os.path.join(ubootdir, f)) and 'MLO' in f:
				# Stable will end in -r1. GIT will end in -def (three hex chars)
				# Therefore, in the real stable image comes last and the latest
				# GIT will be second-to-last. Simply use "useStable" as a flag
				# to target the second-to-last.
				if found:
					mlo = os.path.realpath(os.path.join(ubootdir, f))
					print('Found MLO: ' + mlo)
					break
				else:
					found = True
		found = useStable
		for f in sorted(os.listdir(ubootdir), reverse=True):
			if os.path.isfile(os.path.join(ubootdir, f)) and 'u-boot' in f:
				if found:
					uboot = os.path.realpath(os.path.join(ubootdir, f))
					print('Found u-boot: ' + uboot)
					break
				else:
					found = True
	
	# Build the image
	deploy = os.path.join('omap-image-builder', 'deploy')
	if not os.path.exists(deploy):
		print('Error: omap-image-builder directory doesn\'t exist. Try running buildImage()')
		return
	os.chdir(deploy)
	for f in sorted(os.listdir('.'), reverse=True):
		if not os.path.isfile(f):
			os.chdir(f)
			break
	else:
		print('Error: images not found. Try running buildImage()')
		return
	# Enter the only folder
	for f in os.listdir('.'):
		if not os.path.isfile(f):
			os.chdir(f)
			break
	else:
		print('Error: images not found. Try running buildImage()')
		return
	cmd = ['sudo', './setup_sdcard.sh', '--mmc', getSetting('mmc'),
		'--uboot', 'beagle_xm', '--rootfs', fs,
		'--boot_label', 'boot', '--rootfs_label', 'rootfs']
	if uboot and mlo:
		cmd.extend(['--bootloader', uboot, '--spl', mlo])
	if swap:
		cmd.extend(['--swap_file', str(swap)])
	subprocess.call(cmd)
	os.chdir('..')
	os.chdir('..')
	os.chdir('..')
	os.chdir('..')