def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "msp430", "bsp.c3") startercode = io.StringIO(self.startercode) obj = build( base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang, ) flash = obj.get_image("flash") ivect = obj.get_image("vector16") rom = merge_memories(flash, ivect, "rom") rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + ".bin", "wb") as f: f.write(rom_data) mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print("%02x%02x" % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'msp430', 'bsp.c3') startercode = io.StringIO(self.startercode) obj = build(base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang) flash = obj.get_image('flash') ivect = obj.get_image('vector16') rom = merge_memories(flash, ivect, 'rom') rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + '.bin', 'wb') as f: f.write(rom_data) mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print('%02x%02x' % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build( base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format="bin", elf_format="elf", code_image="flash", ) flash = obj.get_image("flash") data = obj.get_image("ram") rom = merge_memories(flash, data, "rom") rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(filewordsize): if i < datawordlen: w = rom_data[4 * i:4 * i + 4] print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]), file=f) else: print("00000000", file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build(base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format='bin', elf_format='elf', code_image='flash') flash = obj.get_image('flash') data = obj.get_image('ram') rom = merge_memories(flash, data, 'rom') rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(filewordsize): if (i < datawordlen): w = rom_data[4 * i:4 * i + 4] print('%02x%02x%02x%02x' % (w[3], w[2], w[1], w[0]), file=f) else: print('00000000', file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)
obj = link([o1, o2] + obj, "firmware.mmap", use_runtime=True, reporter=reporter, debug=True) with open("firmware.oj", "w") as of: obj.save(of) objcopy(obj, "flash", "elf", "firmware.elf") objcopy(obj, "flash", "bin", "code.bin") objcopy(obj, "ram", "bin", "data.bin") size = 0x8000 cimg = obj.get_image('flash') dimg = obj.get_image('ram') img = merge_memories(cimg, dimg, 'img') imgdata = img.data with open('Murax.bin', 'wb') as f: f.write(imgdata) assert len(imgdata) % 4 == 0 f0 = open("Murax.v_toplevel_system_ram_ram_symbol0" + ".bin", "w") f1 = open("Murax.v_toplevel_system_ram_ram_symbol1" + ".bin", "w") f2 = open("Murax.v_toplevel_system_ram_ram_symbol2" + ".bin", "w") f3 = open("Murax.v_toplevel_system_ram_ram_symbol3" + ".bin", "w") for i in range(len(imgdata) // 4): w = imgdata[4 * i:4 * i + 4] print("{0:08b}".format(w[0]), file=f0) print("{0:08b}".format(w[1]), file=f1)
import argparse from ppci.api import get_object from ppci.binutils.objectfile import merge_memories parser = argparse.ArgumentParser() parser.add_argument('object_file', type=argparse.FileType('r')) args = parser.parse_args() o = get_object(args.object_file) print('using object', o) flash = o.get_image('flash') ivect = o.get_image('vector16') rom = merge_memories(flash, ivect, 'rom') rom_data = rom.data assert len(rom_data) % 2 == 0 with open('pmem.mem', 'w') as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print('%02x%02x' % (w[1], w[0]), file=f)
obj2 = c3c( c3_sources, [], "riscv", reporter=reporter, debug=True, opt_level=2 ) obj = link( [obj1, obj2], "firmware.mmap", use_runtime=False, reporter=reporter, debug=True, ) with open("firmware.oj", "w") as of: obj.save(of) objcopy(obj, "flash", "bin", "code.bin") objcopy(obj, "ram", "bin", "data.bin") objcopy(obj, "flash", "elf", "firmware.elf") size = 0x8000 cimg = obj.get_image("flash") dimg = obj.get_image("ram") img = merge_memories(cimg, dimg, "img") imgdata = img.data with open("firmware.hex", "w") as f: for i in range(size): if i < len(imgdata) // 4: w = imgdata[4 * i : 4 * i + 4] print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]), file=f) else: print("00000000", file=f)