def ttypager(text): """Page through text on a text terminal.""" lines = string.split(plain(text), '\n') if redirect.state != redirect.NOLOG_STATE: with redirect.logonly(): sys.stdout.write(string.join(lines, '\n') + '\n') if redirect.state == redirect.LOGONLY_STATE: return with pager.nopager(): with redirect.nolog(): height = min(bits.get_width_height(term)[1] for term in range(bits.get_term_count())) r = inc = height - 1 sys.stdout.write(string.join(lines[:inc], '\n') + '\n') while True: if lines[r:]: prompt = '-- any key to advance; PgUp to page up; q to quit --' else: prompt = '-- END; PgUp to page up; q to quit --' prompt_len = len(prompt) sys.stdout.write(prompt) c = bits.get_key() # Write the spaces one at a time to defeat word-wrap sys.stdout.write('\r') for i in range(prompt_len): sys.stdout.write(' ') sys.stdout.write('\r') if c in (ord('q'), ord('Q')): break elif c in (ord('\r'), ord('\n'), bits.KEY_DOWN, bits.MOD_CTRL | ord('n')): if lines[r:]: sys.stdout.write(lines[r] + '\n') r = r + 1 continue if c == bits.KEY_HOME: bits.clear_screen() r = 0 if c == bits.KEY_END: bits.clear_screen() r = len(lines) - inc if r < 0: r = 0 if c in (bits.KEY_UP, bits.MOD_CTRL | ord('p')): bits.clear_screen() r = r - 1 - inc if r < 0: r = 0 if c in (bits.KEY_PAGE_UP, ord('b'), ord('B')): bits.clear_screen() r = r - inc - inc if r < 0: r = 0 if lines[r:]: sys.stdout.write(string.join(lines[r:r+inc], '\n') + '\n') r = r + inc if not lines[r:]: r = len(lines)
def log_efi_info(): with redirect.logonly(): try: print print "EFI system information:" print "Firmware Vendor:", system_table.FirmwareVendor print "Firmware Revision: {:#x}".format(system_table.FirmwareRevision) print "Supported EFI configuration table UUIDs:" for t in system_table.ConfigurationTable: print t.VendorGuid, known_uuids.get(t.VendorGuid.uuid, '') print except: print "Error printing EFI information:" import traceback traceback.print_exc()
def log_smbios_info(): with redirect.logonly(): try: sm = SMBIOS() print if sm is None: print "No SMBIOS structures found" return output = {} known_types = (0, 1) for sm_struct in sm.structures: if sm_struct.type in known_types: output.setdefault(sm_struct.type, []).append(sm_struct) if len(output) == len(known_types): break print "SMBIOS information:" for key in sorted(known_types): for s in output.get(key, ["No structure of type {} found".format(key)]): print ttypager._wrap("{}: {}".format(key, s)) except: print "Error parsing SMBIOS information:" import traceback traceback.print_exc()
def init(): import_start_msg("bitsconfig") import bitsconfig end_msg() init_start_msg("bitsconfig") bitsconfig.init() end_msg() import_start_msg("grubcmds") import grubcmds end_msg() init_start_msg("grubcmds") grubcmds.register() end_msg() import_start_msg("bits") import bits end_msg() import os import sys try: import acpi init_start_msg("PCI Express MCFG detection", False) mcfg = acpi.parse_table("MCFG") if mcfg is None: print 'No ACPI MCFG Table found. This table is required for PCI Express.' else: for mcfg_resource in mcfg.resources: if mcfg_resource.segment == 0: if mcfg_resource.address >= (1 << 32): print "Error: PCI Express base above 32 bits is unsupported by BITS" break bits.pcie_set_base(mcfg_resource.address) os.putenv('pciexbase', '{:#x}'.format(mcfg_resource.address)) os.putenv('pcie_startbus', '{:#x}'.format(mcfg_resource.start_bus)) os.putenv('pcie_endbus', '{:#x}'.format(mcfg_resource.end_bus)) break else: print "Error initializing PCI Express base from MCFG: no resource with segment 0" except Exception as e: print "Error occurred initializing PCI Express base from MCFG:" print e init_end_msg("PCI Express MCFG detection") import_start_msg("readline") import readline end_msg() init_start_msg("readline") readline.init() end_msg() import_start_msg("rlcompleter_extra") import rlcompleter_extra end_msg() import_start_msg("testacpi") import testacpi end_msg() init_start_msg("testacpi") testacpi.register_tests() end_msg() if sys.platform == "BITS-EFI": import_start_msg("testefi") import testefi end_msg() init_start_msg("testefi") testefi.register_tests() end_msg() import_start_msg("testsmrr") import testsmrr end_msg() testsmrr.register_tests() import_start_msg("smilatency") import smilatency end_msg() init_start_msg("smilatency") smilatency.register_tests() end_msg() import_start_msg("mptable") import mptable end_msg() init_start_msg("mptable") mptable.register_tests() end_msg() import_start_msg("cpulib") from cpudetect import cpulib end_msg() init_start_msg("cpulib") cpulib.register_tests() end_msg() import_start_msg("testsuite") import testsuite end_msg() init_start_msg("testsuite") testsuite.finalize_cfgs() end_msg() import_start_msg("sysinfo") import sysinfo end_msg() init_start_msg("sysinfo", False) sysinfo.log_sysinfo() init_end_msg("sysinfo") import_start_msg("smbios") import smbios end_msg() init_start_msg("smbios", False) smbios.log_smbios_info() init_end_msg("smbios") if sys.platform == "BITS-EFI": import_start_msg("efi") import efi end_msg() init_start_msg("efi", False) efi.log_efi_info() init_end_msg("efi") batch = bitsconfig.config.get("bits", "batch").strip() if batch: import redirect print "\nBatch mode enabled:", batch for batch_keyword in batch.split(): print "\nRunning batch operation", batch_keyword try: if batch_keyword == "test": testsuite.run_all_tests() with redirect.logonly(): if batch_keyword == "acpi": import acpi print acpi.dumptables() if batch_keyword == "smbios": import smbios smbios.dump_raw() except: print "\nError in batch operation", batch_keyword import traceback traceback.print_exc() print "\nBatch mode complete\n" redirect.write_logfile("/boot/bits-log.txt") import_start_msg("cpumenu") import cpumenu end_msg() init_start_msg("cpumenu") cpumenu.generate_cpu_menu() end_msg() import_start_msg("bootmenu") import bootmenu end_msg() init_start_msg("bootmenu") bootmenu.generate_boot_menu() end_msg() import_start_msg("mwaitmenu") import mwaitmenu end_msg() init_start_msg("mwaitmenu") mwaitmenu.generate_mwait_menu() end_msg() import_start_msg("builtin") import __builtin__ end_msg() __builtin__.help = _Helper()
def init(): import bitsconfig bitsconfig.init() import grubcmds grubcmds.register() import bits import os try: import acpi mcfg = acpi.parse_table("MCFG") if mcfg is None: print 'No ACPI MCFG Table found. This table is required for PCI Express.' else: for mcfg_resource in mcfg.resources: if mcfg_resource.segment == 0: if mcfg_resource.address >= (1 << 32): print "Error: PCI Express base above 32 bits is unsupported by BITS" break bits.pcie_set_base(mcfg_resource.address) os.putenv('pciexbase', '{:#x}'.format(mcfg_resource.address)) os.putenv('pcie_startbus', '{:#x}'.format(mcfg_resource.start_bus)) os.putenv('pcie_endbus', '{:#x}'.format(mcfg_resource.end_bus)) break else: print "Error initializing PCI Express base from MCFG: no resource with segment 0" except Exception as e: print "Error occurred initializing PCI Express base from MCFG:" print e import readline readline.init() import rlcompleter_extra import testacpi testacpi.register_tests() try: import testefi testefi.register_tests() except ImportError as e: pass import testsmrr testsmrr.register_tests() import smilatency smilatency.register_tests() import mptable mptable.register_tests() from cpudetect import cpulib cpulib.register_tests() import testsuite testsuite.finalize_cfgs() import sysinfo sysinfo.log_sysinfo() import smbios smbios.log_smbios_info() try: import efi efi.log_efi_info() except ImportError as e: pass batch = bitsconfig.config.get("bits", "batch").strip() if batch: import redirect print "\nBatch mode enabled:", batch for batch_keyword in batch.split(): print "\nRunning batch operation", batch_keyword try: if batch_keyword == "test": testsuite.run_all_tests() with redirect.logonly(): if batch_keyword == "acpi": import acpi print acpi.dumptables() if batch_keyword == "smbios": import smbios smbios.dump_raw() except: print "\nError in batch operation", batch_keyword import traceback traceback.print_exc() print "\nBatch mode complete\n" redirect.write_logfile("/boot/bits-log.txt") import __builtin__ __builtin__.help = _Helper() import pydoc import ttypager pydoc.getpager = ttypager.getpager
def ttypager(text): """Page through text on a text terminal.""" try: import efi efi_options = ["f to write file"] except ImportError as e: efi_options = [] lines = string.split(plain(text), '\n') if redirect.state != redirect.NOLOG_STATE: with redirect.logonly(): sys.stdout.write(string.join(lines, '\n') + '\n') if redirect.state == redirect.LOGONLY_STATE: return with pager.nopager(): with redirect.nolog(): height = min(bits.get_width_height(term)[1] for term in range(bits.get_term_count())) r = inc = height - 1 sys.stdout.write(string.join(lines[:inc], '\n') + '\n') while True: if lines[r:]: advance = ['any key to advance'] else: advance = ['END'] if r > inc: back = ["Up/PgUp to go back"] else: back = [] options = "; ".join(advance + back + efi_options + ["q to quit"]) prompt = '-- {} --'.format(options) prompt_len = len(prompt) sys.stdout.write(prompt) c = bits.get_key() # Write the spaces one at a time to defeat word-wrap sys.stdout.write('\r') for i in range(prompt_len): sys.stdout.write(' ') sys.stdout.write('\r') if efi_options and c in (ord('f'), ord('F')): ttydir = efi.get_boot_fs() filepath = os.path.normpath(str.strip(readline._readline("filename: "), "\n")) basepath, fname = os.path.split(filepath) for dirname in str.split(basepath, os.sep): if dirname is not "": ttydir = ttydir.mkdir(dirname) print "Saving {}...".format(filepath), ttydir.create(fname).write(string.join(lines, '\n') + '\n') print "Done" print "Hit any key to continue..." c = bits.get_key() if c in (ord('q'), ord('Q')): break elif c in (ord('\r'), ord('\n'), bits.KEY_DOWN, bits.MOD_CTRL | ord('n')): if lines[r:]: sys.stdout.write(lines[r] + '\n') r = r + 1 continue if c == bits.KEY_HOME: bits.clear_screen() r = 0 if c == bits.KEY_END: bits.clear_screen() r = len(lines) - inc if r < 0: r = 0 if c in (bits.KEY_UP, bits.MOD_CTRL | ord('p')): bits.clear_screen() r = r - 1 - inc if r < 0: r = 0 if c in (bits.KEY_PAGE_UP, ord('b'), ord('B')): bits.clear_screen() r = r - inc - inc if r < 0: r = 0 if lines[r:]: sys.stdout.write(string.join(lines[r:r+inc], '\n') + '\n') r = r + inc if not lines[r:]: r = len(lines)
def log_sysinfo(): with redirect.logonly(): signature = bits.cpuid(bits.bsp_apicid(),1).eax print "Processor signature {:#x}, detected CPU as {}".format(signature, cpulib.name)
def init(): with import_annotation("bitsconfig"): import bitsconfig with init_annotation("bitsconfig"): bitsconfig.init() with import_annotation("grubcmds"): import grubcmds with init_annotation("grubcmds"): grubcmds.register() with import_annotation("bits"): import bits with import_annotation("os"): import os with import_annotation("sys"): import sys sys.argv = [] with init_annotation("PCI Express MCFG detection"): try: import acpi mcfg = acpi.parse_table("MCFG") if mcfg is None: print 'No ACPI MCFG Table found. This table is required for PCI Express.' else: for mcfg_resource in mcfg.resources: if mcfg_resource.segment == 0: if mcfg_resource.address >= (1 << 32): print "Error: PCI Express base above 32 bits is unsupported by BITS" break bits.pcie_set_base(mcfg_resource.address) os.putenv('pciexbase', '{:#x}'.format(mcfg_resource.address)) os.putenv('pcie_startbus', '{:#x}'.format(mcfg_resource.start_bus)) os.putenv('pcie_endbus', '{:#x}'.format(mcfg_resource.end_bus)) break else: print "Error initializing PCI Express base from MCFG: no resource with segment 0" except Exception as e: print "Error occurred initializing PCI Express base from MCFG:" print e with import_annotation("readline"): import readline with init_annotation("readline"): readline.init() with import_annotation("rlcompleter_extra"): import rlcompleter_extra with import_annotation("testacpi"): import testacpi with init_annotation("testacpi"): testacpi.register_tests() if sys.platform == "BITS-EFI": with import_annotation("testefi"): import testefi with init_annotation("testefi"): testefi.register_tests() with import_annotation("testsmrr"): import testsmrr with init_annotation("testsmrr"): testsmrr.register_tests() with import_annotation("smilatency"): import smilatency with init_annotation("smilatency"): smilatency.register_tests() with import_annotation("mptable"): import mptable with init_annotation("mptable"): mptable.register_tests() with import_annotation("cpulib"): from cpudetect import cpulib with init_annotation("cpulib"): cpulib.register_tests() with import_annotation("testsuite"): import testsuite with init_annotation("testsuite"): testsuite.finalize_cfgs() with import_annotation("sysinfo"): import sysinfo with init_annotation("sysinfo"): sysinfo.log_sysinfo() with import_annotation("smbios"): import smbios with init_annotation("smbios"): smbios.log_smbios_info() if sys.platform == "BITS-EFI": with import_annotation("efi"): import efi with init_annotation("efi"): efi.log_efi_info() efi.register_keyboard_interrupt_handler() batch = bitsconfig.config.get("bits", "batch").strip() if batch: import redirect print "\nBatch mode enabled:", batch for batch_keyword in batch.split(): print "\nRunning batch operation", batch_keyword try: if batch_keyword == "test": testsuite.run_all_tests() with redirect.logonly(): if batch_keyword == "acpi": import acpi print acpi.dumptables() if batch_keyword == "smbios": import smbios smbios.dump_raw() except: print "\nError in batch operation", batch_keyword import traceback traceback.print_exc() print "\nBatch mode complete\n" redirect.write_logfile("/boot/bits-log.txt") with import_annotation("cpumenu"): import cpumenu with init_annotation("cpumenu"): cpumenu.generate_cpu_menu() with import_annotation("bootmenu"): import bootmenu with init_annotation("bootmenu"): bootmenu.generate_boot_menu() with import_annotation("mwaitmenu"): import mwaitmenu with init_annotation("mwaitmenu"): mwaitmenu.generate_mwait_menu() with import_annotation("__builtin__"): import __builtin__ with init_annotation("__builtin__"): __builtin__.help = _Helper()
def log_sysinfo(): with redirect.logonly(): signature = bits.cpuid(bits.bsp_apicid(), 1).eax print "Processor signature {:#x}, detected CPU as {}".format( signature, cpulib.name)
def ttypager(text): """Page through text on a text terminal.""" try: import efi import readline efi_options = ["f to write file"] except ImportError as e: efi_options = [] lines = string.split(plain(text), '\n') if redirect.state != redirect.NOLOG_STATE: with redirect.logonly(): sys.stdout.write(string.join(lines, '\n') + '\n') if redirect.state == redirect.LOGONLY_STATE: return with pager.nopager(): with redirect.nolog(): height = min(bits.get_width_height(term)[1] for term in range(bits.get_term_count())) r = inc = height - 1 sys.stdout.write(string.join(lines[:inc], '\n') + '\n') while True: if lines[r:]: advance = ['any key to advance'] else: advance = ['END'] if r > inc: back = ["Up/PgUp to go back"] else: back = [] options = "; ".join(advance + back + efi_options + ["q to quit"]) prompt = '-- {} --'.format(options) prompt_len = len(prompt) sys.stdout.write(prompt) c = bits.input.get_key() key = bits.input.key # Write the spaces one at a time to defeat word-wrap sys.stdout.write('\r') for i in range(prompt_len): sys.stdout.write(' ') sys.stdout.write('\r') if efi_options and c in (key('f'), key('F')): ttydir = efi.get_boot_fs() filepath = os.path.normpath(str.strip(readline._readline("filename: "), "\n")) basepath, fname = os.path.split(filepath) for dirname in str.split(basepath, os.sep): if dirname is not "": ttydir = ttydir.mkdir(dirname) print "Saving {}...".format(filepath), ttydir.create(fname).write(string.join(lines, '\n') + '\n') print "Done" print "Hit any key to continue..." c = bits.input.get_key() if c in (key('q'), key('Q')): break elif c in (key('\r'), key('\n'), key(bits.input.KEY_DOWN), key('n', ctrl=True)): if lines[r:]: sys.stdout.write(lines[r] + '\n') r = r + 1 continue if c == key(bits.input.KEY_HOME): bits.clear_screen() r = 0 if c == key(bits.input.KEY_END): bits.clear_screen() r = len(lines) - inc if r < 0: r = 0 if c in (key(bits.input.KEY_UP), key('p', ctrl=True)): bits.clear_screen() r = r - 1 - inc if r < 0: r = 0 if c in (key(bits.input.KEY_PAGE_UP), key('b'), key('B')): bits.clear_screen() r = r - inc - inc if r < 0: r = 0 if lines[r:]: sys.stdout.write(string.join(lines[r:r+inc], '\n') + '\n') r = r + inc if not lines[r:]: r = len(lines)