def main(): valid_keys = set( [ "payload_generator", "payload_generator_config", "inversion_divisor", "inversion_mask", "row_pattern" ]) parser = argparse.ArgumentParser() parser.add_argument("config_file", type=open) args = parser.parse_args() config_string = "" config_lines = args.config_file.readlines() for line in config_lines: index = line.find('#') if index >= 0: line = line[0:index] line += '\n' config_string += line config = json.loads(config_string) assert validate_keys(config, valid_keys) args.config_file.close() pg = PayloadGenerator.get_by_name(config["payload_generator"]) pg.initialize(config) wb = RemoteClient() wb.open() settings = get_litedram_settings() inversion_divisor = 0 inversion_mask = 0 inversion_divisor = config.get("inversion_divisor", 0) inversion_mask = int(config.get("inversion_mask", "0"), 0) row_pattern = config.get("row_pattern", 0) setup_inverters(wb, inversion_divisor, inversion_mask) while not pg.done(): offset, size = pg.get_memset_range(wb, settings) hw_memset(wb, offset, size, [row_pattern]) converter = DRAMAddressConverter.load() bank = 0 sys_clk_freq = float(get_generated_defs()['SYS_CLK_FREQ']) payload = pg.get_payload( settings=settings, bank=bank, payload_mem_size=wb.mems.payload.size, sys_clk_freq=sys_clk_freq) execute_payload(wb, payload) offset, size = pg.get_memtest_range(wb, settings) errors = hw_memtest(wb, offset, size, [row_pattern]) row_errors = decode_errors(wb, settings, converter, bank, errors) pg.process_errors(settings, row_errors) pg.summarize() wb.close()
def run_bist(wb, is_write, pattern): n = wb.mems.main_ram.size pattern = [pattern] def runner(): if is_write: hw_memset(wb, 0, n, pattern) else: hw_memtest(wb, 0, n, pattern) if not is_write: print('Filling memory before reading measurements ...') hw_memset(wb, 0, n, pattern) measure(runner, n)
def run(self, row_pairs, pattern_generator, read_count, row_progress=16, verify_initial=True): print('\nPreparing ...') row_pattern = pattern_generator([self.rows[0]])[0] print('WARNING: only single word patterns supported, using: 0x{:08x}'.format(row_pattern)) print('\nFilling memory with data ...') hw_memset(self.wb, 0x0, self.wb.mems.main_ram.size, [row_pattern]) if verify_initial: print('\nVerifying written memory ...') errors = self.check_errors(row_pattern) if self.errors_count(errors) == 0: print('OK') else: print() self.display_errors(errors) return if self.no_refresh: print('\nDisabling refresh ...') self.wb.regs.controller_settings_refresh.write(0) print('\nRunning row hammer attacks ...') for i, row_tuple in enumerate(row_pairs): s = 'Iter {:{n}} / {:{n}}'.format(i, len(row_pairs), n=len(str(len(row_pairs)))) if self.payload_executor: self.payload_executor_attack(read_count=read_count, row_tuple=row_tuple) else: if len(row_tuple) & (len(row_tuple) - 1) != 0: print("ERROR: BIST only supports power of 2 rows\n") return self.attack(row_tuple, read_count=read_count, progress_header=s) if self.no_refresh: print('\nReenabling refresh ...') self.wb.regs.controller_settings_refresh.write(1) print('\nVerifying attacked memory ...') errors = self.check_errors(row_pattern) if self.errors_count(errors) == 0: print('OK') else: print() self.display_errors(errors) return
if args.srv: litex_server() wb = RemoteClient() wb.open() mem_base = wb.mems.main_ram.base mem_range = wb.mems.main_ram.size # bytes # we are limited to multiples of DMA data width settings = get_litedram_settings() dma_data_width = settings.phy.dfi_databits * settings.phy.nphases nbytes = dma_data_width // 8 if args.test_modules: hw_memset(wb, 0x0, mem_range, [0xffffffff], args.dbg) # --------------------------- Introduce error ------------------------ rng = random.Random(datetime.now()) offsets = [] for i, n in enumerate(range(0, 5000)): print('Generated {:d} offsets'.format(i), end='\r') offset = rng.randrange(0x0, mem_range - 4) offset &= ~0b11 # must be 32-bit aligned if offset // nbytes not in offsets: offsets.append(offset // nbytes) if args.dbg: print('dbg: offset: ' + str(offset)) wb.write(mem_base + offset, wb.read(mem_base + offset) ^ 0x000010000) print()
def runner(): if is_write: hw_memset(wb, 0, n, pattern) else: hw_memtest(wb, 0, n, pattern)