def main(): if os.environ['PYTHONHASHSEED'] != "1": print( "PYTHONHASHEED must be set to 1 for consistent validation results. Failing to set this results in non-deterministic compilation results") exit() parser = argparse.ArgumentParser(description="Build the Betrusted Embedded Controller") parser.add_argument( "--revision", choices=["dvt", "pvt"], default="pvt", help="build EC for a particular hardware revision" ) parser.add_argument( "-D", "--document-only", default=False, action="store_true", help="Build docs only" ) parser.add_argument( "--with-dsp", help="use dsp inference in yosys (not all yosys builds have -dsp)", action="store_true" ) parser.add_argument( "--no-cpu", help="disable cpu generation for debugging purposes", action="store_true" ) parser.add_argument( "--placer", choices=["sa", "heap"], help="which placer to use in nextpnr", default="heap", ) parser.add_argument( "--seed", default=0, help="seed to use in nextpnr" ) args = parser.parse_args() output_dir = 'build' compile_gateware = True compile_software = False # this is now done with Rust if args.document_only: compile_gateware = False compile_software = False cpu_type = "vexriscv" cpu_variant = "minimal" cpu_variant = cpu_variant + "+debug" if args.no_cpu: cpu_type = None cpu_variant = None if args.revision == 'dvt' or args.revision == 'pvt': io = io_pvt else: print("Invalid hardware revision") exit(1) platform = BetrustedPlatform(io, revision=args.revision) soc = BaseSoC(platform, cpu_type=cpu_type, cpu_variant=cpu_variant, use_dsp=args.with_dsp, placer=args.placer, pnr_seed=args.seed, output_dir=output_dir) builder = Builder(soc, output_dir=output_dir, csr_csv="build/csr.csv", compile_software=compile_software, compile_gateware=compile_gateware) # If we compile software, pull the code from somewhere other than # the built-in litex "bios" binary, which makes assumptions about # what peripherals are available. if compile_software: builder.software_packages = [ ("bios", os.path.abspath(os.path.join(os.path.dirname(__file__), "bios"))) ] try: vns = builder.build() except OSError: exit(1) soc.do_exit(vns) if not args.document_only: make_multiboot_header(os.path.join(output_dir, "gateware", "multiboot-header.bin"), [ 160, 160, 157696, 262144, 262144 + 32768, ]) with open(os.path.join(output_dir, 'gateware', 'multiboot-header.bin'), 'rb') as multiboot_header_file: multiboot_header = multiboot_header_file.read() with open(os.path.join(output_dir, 'gateware', 'betrusted_ec.bin'), 'rb') as top_file: top = top_file.read() with open(os.path.join(output_dir, 'gateware', 'betrusted_ec_multiboot.bin'), 'wb') as top_multiboot_file: top_multiboot_file.write(multiboot_header) top_multiboot_file.write(top) pad_file(os.path.join(output_dir, 'gateware', 'betrusted_ec.bin'), os.path.join(output_dir, 'gateware', 'betrusted_ec_pad.bin'), 0x1a000) pad_file(os.path.join(output_dir, 'gateware', 'betrusted_ec_multiboot.bin'), os.path.join(output_dir, 'gateware', 'betrusted_ec_multiboot_pad.bin'), 0x1a000) lxsocdoc.generate_docs(soc, "build/documentation", note_pulses=True) lxsocdoc.generate_svd(soc, "build/software")
def main(): parser = argparse.ArgumentParser( description="Build Fomu Main Gateware") parser.add_argument( "--boot-source", choices=["spi", "rand", "bios"], default="bios", help="where to have the CPU obtain its executable code from" ) parser.add_argument( "--document-only", default=False, action="store_true", help="Don't build gateware or software, only build documentation" ) parser.add_argument( "--revision", choices=["evt", "dvt", "pvt", "hacker"], required=True, help="build foboot for a particular hardware revision" ) parser.add_argument( "--bios", help="use specified file as a BIOS, rather than building one" ) parser.add_argument( "--with-debug", help="enable debug support", choices=["usb", "uart", "spi", None] ) parser.add_argument( "--with-dsp", help="use dsp inference in yosys (not all yosys builds have -dsp)", action="store_true" ) parser.add_argument( "--no-cpu", help="disable cpu generation for debugging purposes", action="store_true" ) parser.add_argument( "--placer", choices=["sa", "heap"], default="heap", help="which placer to use in nextpnr" ) parser.add_argument( "--seed", default=0, help="seed to use in nextpnr" ) parser.add_argument( "--export-random-rom-file", help="Generate a random ROM file and save it to a file" ) args = parser.parse_args() output_dir = 'build' if args.export_random_rom_file is not None: size = 0x2000 def xorshift32(x): x = x ^ (x << 13) & 0xffffffff x = x ^ (x >> 17) & 0xffffffff x = x ^ (x << 5) & 0xffffffff return x & 0xffffffff def get_rand(x): out = 0 for i in range(32): x = xorshift32(x) if (x & 1) == 1: out = out | (1 << i) return out & 0xffffffff seed = 1 with open(args.export_random_rom_file, "w", newline="\n") as output: for d in range(int(size / 4)): seed = get_rand(seed) print("{:08x}".format(seed), file=output) return 0 compile_software = False if (args.boot_source == "bios" or args.boot_source == "spi") and args.bios is None: compile_software = True cpu_type = "vexriscv" cpu_variant = "min" if args.with_debug: cpu_variant = cpu_variant + "+debug" if args.no_cpu: cpu_type = None cpu_variant = None compile_gateware = True if args.document_only: compile_gateware = False compile_software = False warmboot_offsets = [ 160, 160, 157696, 262144, 262144 + 32768, ] os.environ["LITEX"] = "1" # Give our Makefile something to look for platform = Platform(revision=args.revision) soc = BaseSoC(platform, cpu_type=cpu_type, cpu_variant=cpu_variant, debug=args.with_debug, boot_source=args.boot_source, bios_file=args.bios, use_dsp=args.with_dsp, placer=args.placer, pnr_seed=int(args.seed), output_dir=output_dir, warmboot_offsets=warmboot_offsets[1:]) builder = Builder(soc, output_dir=output_dir, csr_csv="build/csr.csv", compile_software=compile_software, compile_gateware=compile_gateware) if compile_software: builder.software_packages = [ ("bios", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "sw"))) ] vns = builder.build() soc.do_exit(vns) lxsocdoc.generate_docs(soc, "build/documentation/", project_name="Fomu Bootloader", author="Sean Cross") lxsocdoc.generate_svd(soc, "build/software", vendor="Foosn", name="Fomu") if not args.document_only: make_multiboot_header(os.path.join(output_dir, "gateware", "multiboot-header.bin"), warmboot_offsets) with open(os.path.join(output_dir, 'gateware', 'multiboot-header.bin'), 'rb') as multiboot_header_file: multiboot_header = multiboot_header_file.read() with open(os.path.join(output_dir, 'gateware', 'top.bin'), 'rb') as top_file: top = top_file.read() with open(os.path.join(output_dir, 'gateware', 'top-multiboot.bin'), 'wb') as top_multiboot_file: top_multiboot_file.write(multiboot_header) top_multiboot_file.write(top) print( """Foboot build complete. Output files: {}/gateware/top.bin Bitstream file. Load this onto the FPGA for testing. {}/gateware/top-multiboot.bin Multiboot-enabled bitstream file. Flash this onto FPGA ROM. {}/gateware/top.v Source Verilog file. Useful for debugging issues. {}/software/include/generated/ Directory with header files for API access. {}/software/bios/bios.elf ELF file for debugging bios. """.format(output_dir, output_dir, output_dir, output_dir, output_dir))
def main(): parser = argparse.ArgumentParser(description="Build Fomu Main Gateware") parser.add_argument( "--boot-source", choices=["spi", "rand", "bios"], default="bios", help="where to have the CPU obtain its executable code from") parser.add_argument("--revision", choices=["pvt", "dvt", "evt", "hacker"], required=True, help="build foboot for a particular hardware revision") parser.add_argument( "--bios", help="use specified file as a BIOS, rather than building one") parser.add_argument("--with-debug", help="enable debug support", choices=["usb", "uart", None]) parser.add_argument( "--with-dsp", help="use dsp inference in yosys (not all yosys builds have -dsp)", action="store_true") parser.add_argument("--no-cpu", help="disable cpu generation for debugging purposes", action="store_true") parser.add_argument("--placer", choices=["sa", "heap"], default="heap", help="which placer to use in nextpnr") args = parser.parse_args() output_dir = 'build' compile_software = False if args.boot_source == "bios" and args.bios is None: compile_software = True cpu_type = "vexriscv" cpu_variant = "min" if args.with_debug: cpu_variant = cpu_variant + "+debug" if args.no_cpu: cpu_type = None cpu_variant = None os.environ["LITEX"] = "1" # Give our Makefile something to look for platform = Platform(revision=args.revision) soc = BaseSoC(platform, cpu_type=cpu_type, cpu_variant=cpu_variant, debug=args.with_debug, boot_source=args.boot_source, bios_file=args.bios, use_dsp=args.with_dsp, placer=args.placer, output_dir=output_dir) builder = Builder(soc, output_dir=output_dir, csr_csv="test/csr.csv", compile_software=compile_software) if compile_software: builder.software_packages = [ ("bios", os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "sw"))) ] vns = builder.build() soc.do_exit(vns) print("""Foboot build complete. Output files: {}/gateware/top.bin Bitstream file. Load this onto the FPGA for testing. {}/gateware/top.v Source Verilog file. Useful for debugging issues. {}/software/include/generated/ Directory with header files for API access. {}/software/bios/bios.elf ELF file for debugging bios. """.format(output_dir, output_dir, output_dir, output_dir))