def flash_loader_test(board_id): with ConnectHelper.session_with_chosen_probe(unique_id=board_id, **get_session_options()) as session: board = session.board target = session.target target_type = board.target_type test_params = get_target_test_params(session) session.probe.set_clock(test_params['test_clock']) memory_map = board.target.get_memory_map() boot_region = memory_map.get_boot_memory() boot_start_addr = boot_region.start boot_end_addr = boot_region.end boot_blocksize = boot_region.blocksize binary_file = os.path.join(parentdir, 'binaries', board.test_binary) # Generate an Intel hex file from the binary test file. temp_test_hex_name = binary_to_hex_file(binary_file, boot_region.start) test_pass_count = 0 test_count = 0 result = FlashLoaderTestResult() with open(binary_file, "rb") as f: data = list(bytearray(f.read())) data_length = len(data) print("\n------ Test Basic Load ------") loader = FlashLoader(session, chip_erase=False) loader.add_data(boot_start_addr, data) loader.commit() verify_data = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Load Sector Erase ------") test_data = [0x55] * boot_blocksize addr = (boot_end_addr + 1) - (boot_blocksize * 2) loader = FlashLoader(session, chip_erase=False) loader.add_data(addr, test_data) loader.add_data(addr + boot_blocksize, test_data) loader.commit() verify_data = target.read_memory_block8(addr, boot_blocksize * 2) verify_data2 = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, test_data * 2) and same(verify_data2, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Basic Sector Erase ------") eraser = FlashEraser(session, FlashEraser.Mode.SECTOR) eraser.erase(["0x%x+0x%x" % (addr, boot_blocksize)]) verify_data = target.read_memory_block8(addr, boot_blocksize) if target.memory_map.get_region_for_address(addr).is_erased(verify_data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Load Chip Erase ------") loader = FlashLoader(session, chip_erase=True) loader.add_data(boot_start_addr, data) loader.commit() verify_data = target.read_memory_block8(boot_start_addr, data_length) verify_data2 = target.read_memory_block8(addr, boot_blocksize * 2) if same(verify_data, data) and target.memory_map.get_region_for_address(addr).is_erased(verify_data2): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Binary File Load ------") programmer = FileProgrammer(session) programmer.program(binary_file, file_format='bin', base_address=boot_start_addr) verify_data = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Intel Hex File Load ------") programmer = FileProgrammer(session) programmer.program(temp_test_hex_name, file_format='hex') verify_data = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n\nTest Summary:") print("Pass count %i of %i tests" % (test_pass_count, test_count)) if test_pass_count == test_count: print("FLASH TEST SCRIPT PASSED") else: print("FLASH TEST SCRIPT FAILED") target.reset() result.passed = test_count == test_pass_count return result
def flash_loader_test(board_id): with ConnectHelper.session_with_chosen_probe(unique_id=board_id, **get_session_options()) as session: board = session.board target = session.target target_type = board.target_type test_clock = 10000000 if target_type == "nrf51": # Override clock since 10MHz is too fast test_clock = 1000000 if target_type == "ncs36510": # Override clock since 10MHz is too fast test_clock = 1000000 session.probe.set_clock(test_clock) memory_map = board.target.get_memory_map() boot_region = memory_map.get_boot_memory() boot_start_addr = boot_region.start boot_end_addr = boot_region.end boot_blocksize = boot_region.blocksize test_pass_count = 0 test_count = 0 result = FlashLoaderTestResult() binary_file_path = os.path.join(parentdir, 'binaries', board.test_binary) with open(binary_file_path, "rb") as f: data = list(bytearray(f.read())) data_length = len(data) print("\n------ Test Basic Load ------") loader = FlashLoader(session, chip_erase=False) loader.add_data(boot_start_addr, data) loader.commit() verify_data = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Load Sector Erase ------") test_data = [0x55] * boot_blocksize addr = (boot_end_addr + 1) - (boot_blocksize * 2) loader = FlashLoader(session, chip_erase=False) loader.add_data(addr, test_data) loader.add_data(addr + boot_blocksize, test_data) loader.commit() verify_data = target.read_memory_block8(addr, boot_blocksize * 2) verify_data2 = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, test_data * 2) and same(verify_data2, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Basic Sector Erase ------") eraser = FlashEraser(session, FlashEraser.Mode.SECTOR) eraser.erase(["0x%x+0x%x" % (addr, boot_blocksize)]) verify_data = target.read_memory_block8(addr, boot_blocksize) if target.memory_map.get_region_for_address(addr).is_erased(verify_data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Load Chip Erase ------") loader = FlashLoader(session, chip_erase=True) loader.add_data(boot_start_addr, data) loader.commit() verify_data = target.read_memory_block8(boot_start_addr, data_length) verify_data2 = target.read_memory_block8(addr, boot_blocksize * 2) if same(verify_data, data) and target.memory_map.get_region_for_address(addr).is_erased(verify_data2): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n------ Test Binary File Load ------") programmer = FileProgrammer(session) programmer.program(binary_file_path, format='bin', base_address=boot_start_addr) verify_data = target.read_memory_block8(boot_start_addr, data_length) if same(verify_data, data): print("TEST PASSED") test_pass_count += 1 else: print("TEST FAILED") test_count += 1 print("\n\nTest Summary:") print("Pass count %i of %i tests" % (test_pass_count, test_count)) if test_pass_count == test_count: print("FLASH TEST SCRIPT PASSED") else: print("FLASH TEST SCRIPT FAILED") target.reset() result.passed = test_count == test_pass_count return result