def main(): # Make sure our current working dir is the script's location os.chdir(getScriptDir()) loadSettings() enabledRestricted() installDependencies() installUtilities() installCore()
def main(): # Make sure our current working dir is the script's location os.chdir(getScriptDir()) loadSettings() enabledRestricted() installDependencies() installUtilities() installCore()
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("..")
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('..')
def main(): """ Entry point for command 'impact-model'. """ args = parser.parse_args(sys.argv[2:]) def rm_temp_dir(path): if args.workpath == None: shutil.rmtree(path) if args.verbosity == 1: logging.getLogger().setLevel(logging.INFO) elif args.verbosity > 1: logging.getLogger().setLevel(logging.DEBUG) if (args.resultpath != None) and os.path.exists(args.resultpath): print("Error: destination result path already exists:", args.resultpath, file=sys.stderr) return 1 try: mconfig, submach = loadMachineConfig(args.machine, args.submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading machine configuration:", e, file=sys.stderr) return 1 try: layout = loadLayout(args.layoutpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading layout:", e, file=sys.stderr) return 1 try: settings = loadSettings(args.settingspath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading settings:", e, file=sys.stderr) return 1 try: config = loadLatticeConfig(args.configpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading configuration:", e, file=sys.stderr) return 1 try: lattice = build_lattice(layout, config=config, settings=settings, start=args.start, end=args.end) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error building lattice:", e, file=sys.stderr) return 1 lattice.outputMode = OUTPUT_MODE_END try: result_dir = run_lattice(lattice, config=config, data_dir=args.datapath, work_dir=args.workpath) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error running lattice:", e, file=sys.stderr) return 1 try: result = build_result(impact="FRIB", directory=result_dir, keep=True) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error building result:", e, file=sys.stderr) rm_temp_dir(result_dir) return 1 spos = result.getSPosition() energy = result.getEnergy() xorbit = result.getOrbit("X") yorbit = result.getOrbit("Y") xrms = result.getBeamRms("X") yrms = result.getBeamRms("Y") #zrms = result.getBeamRms("Z") xalpha = result.getTwissAlpha("X") yalpha = result.getTwissAlpha("Y") xemit = result.getEmittance("X") yemit = result.getEmittance("Y") zemit = result.getEmittance("Z") if args.plot: try: plt.figure(figsize=(16,10), dpi=80) plt.subplot(221) plt.title("Beam Orbit") plt.plot(spos, xorbit, 'r-', label="X") plt.plot(spos, yorbit, 'b-', label="Y") plt.xlabel("S [m]") plt.ylabel("Beam Position [m]") plt.legend(loc="upper left") plt.grid() plt.subplot(222) plt.title("Beam RMS") plt.plot(spos, xrms, 'r-', label="X") plt.plot(spos, yrms, 'b-', label="Y") #plt.plot(zrms[:,0], zrms[:,1], 'g-', label="Z") plt.xlabel("S [m]") plt.ylabel("Beam RMS [m]") plt.legend(loc="upper left") plt.grid() plt.subplot(223) plt.title("Beam Energy") plt.plot(spos, energy, 'r-') plt.xlabel("S [m]") plt.ylabel("Beam Energy [MeV]") plt.grid() plt.subplot(224) plt.title("Beam Emittance") plt.plot(spos, xemit, 'r-', label="X") plt.plot(spos, yemit, 'b-', label="Y") #plt.plot(zemit[:,0], zemit[:,1], 'g-', label="Z") plt.xlabel("S [m]") plt.ylabel("Beam Emittance [m-rad]") plt.legend(loc="upper left") plt.grid() if args.resultpath == None: plt.show() else: plt.savefig(args.resultpath) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error generating plot: ", e, file=sys.stderr) else: try: if args.resultpath == None: csvfile = sys.stdout else: csvfile = open(args.resultpath, "w") csvfile.write("# i name s energy codx cody rmsx rmsy alphax alphay emittancex emittancey emittancez TM\r\n") csvfile.write("# [m] [eV] [m] [m] [m] [m] \r\n") for idx in xrange(len(lattice.elements)): csvfile.write(str(idx)) csvfile.write(" ") csvfile.write(lattice.elements[idx].name) csvfile.write(" ") csvfile.write(str(spos[idx])) csvfile.write(" ") csvfile.write(str(energy[idx])) csvfile.write(" ") csvfile.write(str(xorbit[idx])) csvfile.write(" ") csvfile.write(str(yorbit[idx])) csvfile.write(" ") csvfile.write(str(xrms[idx])) csvfile.write(" ") csvfile.write(str(yrms[idx])) csvfile.write(" ") csvfile.write(str(xalpha[idx])) csvfile.write(" ") csvfile.write(str(yalpha[idx])) csvfile.write(" ") csvfile.write(str(xemit[idx])) csvfile.write(" ") csvfile.write(str(yemit[idx])) csvfile.write(" ") csvfile.write(str(zemit[idx])) csvfile.write(" ") csvfile.write("0.0") csvfile.write("\r\n") except Exception as e: print("Error writing CSV result: ", e, file=sys.stderr) finally: if csvfile != sys.stdout: csvfile.close() rm_temp_dir(result_dir) return 0
def main(): """ Entry point for command 'impact-lattice'. """ args = parser.parse_args(sys.argv[2:]) if args.verbosity == 1: logging.getLogger().setLevel(logging.INFO) elif args.verbosity > 1: logging.getLogger().setLevel(logging.DEBUG) if (args.latticepath != None) and os.path.exists(args.latticepath): print("Destination file already exists: {}".format(args.latticepath), file=sys.stderr) return 1 if (args.chanmap != None) and os.path.exists(args.chanmap): print("Destination file already exists: {}".format(args.chanmap), file=sys.stderr) return 1 if (args.latdata != None) and os.path.exists(args.latdata): print("Destination file already exists: {}".format(args.latdata), file=sys.stderr) return 1 try: mconfig, submach = loadMachineConfig(args.machine, args.submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading machine configuration:", e, file=sys.stderr) return 1 try: layout = loadLayout(args.layoutpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading layout:", e, file=sys.stderr) return 1 try: settings = loadSettings(args.settingspath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading settings:", e, file=sys.stderr) return 1 try: config = loadLatticeConfig(args.configpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading lattice configuration:", e, file=sys.stderr) return 1 try: lat = impact.build_lattice(layout, config=config, settings=settings, start=args.start, end=args.end, template=args.template) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error building lattice:", e, file=sys.stderr) return 1 if args.chanmap != None: try: channels = loadChannels(args.cfsurl, args.cfstag, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading channels:", e, file=sys.stderr) return 1 with open(args.chanmap, "w") as fp: _write_channel_map(layout, lat, channels, fp) if args.latdata != None: with open(args.latdata, "w") as fp: _write_lattice_data(lat, fp) if args.latticepath != None: name, _ = os.path.splitext(args.latticepath) maps = name + ".map" with open(args.latticepath, "w") as fp, open(maps, "w") as fmp: lat.write(fp, fmp, withElemData=args.with_elem_data) else: lat.write(sys.stdout, withElemData=args.with_elem_data) return 0
def main(): """ Entry point for command 'impact-vastart'. """ args = parser.parse_args(sys.argv[2:]) if args.verbosity == 1: logging.getLogger().setLevel(logging.INFO) elif args.verbosity > 1: logging.getLogger().setLevel(logging.DEBUG) try: mconfig, submach = loadMachineConfig(args.machine, args.submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error readings machine configuration:", e, file=sys.stderr) return 1 try: layout = loadLayout(args.layoutpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading layout:", e, file=sys.stderr) return 1 try: settings = loadSettings(args.settingspath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading settings:", e, file=sys.stderr) return 1 try: config = loadLatticeConfig(args.configpath, mconfig, submach) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error loading configuration:", e, file=sys.stderr) return 1 channels = loadChannels(args.cfsurl, None, mconfig, submach) try: va = build_virtaccel(layout, config=config, channels=channels, settings=settings, start=args.start, end=args.end, data_dir=args.datapath, work_dir=args.workpath) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error building virtual accelerator:", e, file=sys.stderr) return 1 try: va.start(True) except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error starting virtual accelerator:", e, file=sys.stderr) return 1 try: va.wait() except KeyboardInterrupt: va.stop() va.wait() except Exception as e: if args.verbosity > 0: traceback.print_exc() print("Error executing virtual accelerator:", e, file=sys.stderr) return 1 return 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('..')