def test_sb1x_parse(data_dir): # insufficient size with pytest.raises(ValueError): SecureBootV1.parse(b'') # invalid signature/tag with pytest.raises(ValueError): SecureBootV1.parse(b'0' * 1024)
def test_sb1x_parse(): # insufficient size with pytest.raises(SPSDKError): SecureBootV1.parse(b"") # invalid signature/tag with pytest.raises(SPSDKError): SecureBootV1.parse(b"0" * 1024)
def write_sb(cpu_params: CpuParams, image_file_name: str, img: SecureBootV1) -> None: """Write SB image to the external flash The method behaviour depends on TEST_IMG_CONTENT: - if True (TEST MODE), the method generates the image and compare with previous version - if False (PRODUCTION), the method generates the image and burn into FLASH :param cpu_params: processor specific parameters of the test :param image_file_name: of the image to be written (including file extension) :param img: image instance to be written """ path = os.path.join(cpu_params.data_dir, OUTPUT_IMAGES_SUBDIR, image_file_name) dbg_info = DebugInfo() img_data = img.export(dbg_info=dbg_info, # use the following parameters only for unit test header_padding8=b'\xdb\x00\x76\x7a\xf4\x81\x0b\x86', auth_padding=b'\x36\x72\xf4\x99\x92\x05\x34\xd2\xd5\x17\xa0\xf7') write_dbg_log(cpu_params.data_dir, image_file_name, dbg_info.lines, TEST_IMG_CONTENT) if TEST_IMG_CONTENT: assert img.info() # quick check info prints non-empty output compare_bin_files(path, img_data) img = SecureBootV1.parse(b'0' + img_data, 1) dbg_info2 = DebugInfo() img_data2 = img.export(dbg_info=dbg_info2, header_padding8=b'\xdb\x00\x76\x7a\xf4\x81\x0b\x86', auth_padding=b'\x36\x72\xf4\x99\x92\x05\x34\xd2\xd5\x17\xa0\xf7') assert dbg_info.lines == dbg_info2.lines assert img_data == img_data2 else: with open(path, 'wb') as f: f.write(img_data) mboot = init_flashloader(cpu_params) assert mboot.receive_sb_file(img_data) mboot.close()
def test_sb1x_basic(data_dir): """Basic test of SB 1.x""" img = SecureBootV1(version='1.0') assert img.info() img = SecureBootV1(version='1.2') assert img.info() with pytest.raises(ValueError): img.export() # missing bootable section assert len(img.sections) == 0 img.append(BootSectionV1(0, SecureBootFlagsV1.ROM_SECTION_BOOTABLE)) img.append(BootSectionV1(1)) img.append(BootSectionV1(2, SecureBootFlagsV1.ROM_SECTION_BOOTABLE)) assert len(img.sections) == 3 data = img.export() assert data assert len(data) == img.size assert SecureBootV1.parse(data)