def test_BCA_can_slave_txrx_id(self, bl): if bl.peripheral != 'can': pytest.skip("This case is only supported on CAN peripheral.") else: kCanDefaultSlaveTxId = 0x321 kCanDefaultSlaveRxId = 0x123 kCanTestSlaveTxIdList = [0x7FF, 0x322, kCanDefaultSlaveTxId, 0x001] kCanTestSlaveRxIdList = [0x7FE, 0x124, kCanDefaultSlaveRxId, 0x000] for i in range(0, len(kCanTestSlaveTxIdList)): for j in range(0, len(kCanTestSlaveRxIdList)): # Step 1. Generate a user config file with the specified TxId and RxId bcaFile = user_config_area.create_BCA_data_file( bl, canTxId=kCanTestSlaveTxIdList[i], canRxId=kCanTestSlaveRxIdList[j]) # Step 2. Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFile) assert status == bootloader.status.kStatus_Success # Step 3. Reset the target so that the BCA data can be used. status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) # Step 4. Change the can TxId and RxId after BCA taking effect. Should be OK. bl.set_CAN_parameters(bl.speed, kCanTestSlaveRxIdList[j], kCanTestSlaveTxIdList[i]) status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) assert status == bootloader.status.kStatus_Success # Step 5. Chang the can TxId and RxId again. # Actually, the TxId and RxId cannot be changed again, # otherwise, target should not send response to host k = random.randint(0, len(kCanTestSlaveTxIdList) - 1) l = random.randint(0, len(kCanTestSlaveRxIdList) - 1) bl.set_CAN_parameters(bl.speed, kCanTestSlaveRxIdList[l], kCanTestSlaveTxIdList[k]) status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) if i == k and j == l: assert status == bootloader.status.kStatus_Success else: assert status != bootloader.status.kStatus_Success # Step 6. Set back the correct TxId and RxId, so that it can work properly. bl.set_CAN_parameters(bl.speed, kCanTestSlaveRxIdList[j], kCanTestSlaveTxIdList[i]) time.sleep(3) # Step 7. Erase the flash including the BCA field, so that Step 2 will not encounter kStatus_FlashCommandFailure. common_util.erase_all_available_flash_unsecure(bl) # Reset the target to clean the test environment. status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) # Set back the default TxId and RxId bl.set_CAN_parameters(bl.speed, kCanDefaultSlaveTxId, kCanDefaultSlaveRxId)
def setup(self, bl, request): common_util.reset_with_check(bl) common_util.erase_all_available_flash_unsecure(bl) def teardown(): pass request.addfinalizer(teardown)
def setup(self, request, bl): common_util.reset_with_check(bl) common_util.erase_all_available_flash_unsecure(bl) def teardown(): if bl.target.hasErasableIFR: bl.target.unlock() else: pass request.addfinalizer(teardown)
def setup(self, request, bl): common_util.reset_with_check(bl) common_util.erase_all_available_flash_unsecure(bl) status, results = bl.reset() time.sleep(3) assert status == bootloader.status.kStatus_Success def teardown(): common_util.erase_all_available_flash_unsecure(bl) request.addfinalizer(teardown)
def test_BCA_can_speed_index(self, bl): if bl.peripheral != 'can': pytest.skip("This case is only supported on CAN peripheral.") else: kCanUserDefinedSpeedList = [0xF0, 0xF1, 0xF2, 0xF4] kSupportedPeripheralSpeed_can = [0, 1, 2, 4] # 125k, 250k, 500k, 1M for i in range(0, len(kCanUserDefinedSpeedList)): # Step 1. Generate a user config file with pre-defined can speed bcaFile = user_config_area.create_BCA_data_file( bl, canConfig1=kCanUserDefinedSpeedList[i]) # Step 2. Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFile) assert status == bootloader.status.kStatus_Success # Step 3. Reset the target so that the BCA data can be used. status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) # Step 4. Change the can speed after BCA taking effect. Should be OK. bl.set_CAN_parameters(kSupportedPeripheralSpeed_can[i]) status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) assert status == bootloader.status.kStatus_Success for j in range(0, len(kCanUserDefinedSpeedList)): # Step 5. Change the can speed again. # If the two speeds are equal, target should send response to host, # otherwise, target should not send response to host bl.set_CAN_parameters(kSupportedPeripheralSpeed_can[j]) status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) if j == i: assert status == bootloader.status.kStatus_Success else: assert status != bootloader.status.kStatus_Success time.sleep(3) # Step 6. Set back the correct can speed, so that it can work properly. bl.set_CAN_parameters(kSupportedPeripheralSpeed_can[i]) # Step 7. Erase the flash including the BCA field, so that Step 2 will not encounter kStatus_FlashCommandFailure. common_util.erase_all_available_flash_unsecure(bl) # Reset the target to clean the test environment. status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3)
def teardown(): # Set flash as unsecure state common_util.erase_all_available_flash_unsecure(bl)
def teardown(): common_util.erase_all_available_flash_unsecure(bl)
def test_BCA_enabledPeripherals(self, bl): # Reset target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) peripherals = ['uart', 'i2c', 'spi', 'can', 'usb'] defaultPeripheral = bl.peripheral # Detect the available peripheals except the default peripheral availablePeripherals = [] for peripheral in peripherals: # Change the peripheral originalPeripheral = bl.change_peripheral(peripheral) if peripheral == defaultPeripheral: continue # Use reset command to ping the peripherals status, results = bl.reset() time.sleep(3) if status == bootloader.status.kStatus_Success: availablePeripherals.append(peripheral) else: unvailablePeripheral = bl.change_peripheral(originalPeripheral) print 'available peripherals: %s' % (availablePeripherals) if len(availablePeripherals) == 0: pytest.skip( 'Skip this case because only one peripheral is availabe.') # Change to the default peripheral originalPeripheral = bl.change_peripheral(defaultPeripheral) # Disable the default peripheral in BCA if defaultPeripheral == 'uart': bcaFilePath = user_config_area.create_BCA_data_file( bl, enabledPeripherals=0xff - (1 << 0)) elif defaultPeripheral == 'i2c': bcaFilePath = user_config_area.create_BCA_data_file( bl, enabledPeripherals=0xff - (1 << 1)) elif defaultPeripheral == 'spi': bcaFilePath = user_config_area.create_BCA_data_file( bl, enabledPeripherals=0xff - (1 << 2)) elif defaultPeripheral == 'can': bcaFilePath = user_config_area.create_BCA_data_file( bl, enabledPeripherals=0xff - (1 << 3)) elif defaultPeripheral == 'usb': bcaFilePath = user_config_area.create_BCA_data_file( bl, enabledPeripherals=0xff - (1 << 4)) else: pass # Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFilePath) assert status == bootloader.status.kStatus_Success # Reset the target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) # The default peripheral should be not available now status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) assert status != bootloader.status.kStatus_Success # Change to the other available peripheral, should work fine originalPeripheral = bl.change_peripheral(availablePeripherals[0]) status, results = bl.get_property( bootloader.properties.kPropertyTag_CurrentVersion) assert status == bootloader.status.kStatus_Success # Erase the BCA region common_util.erase_all_available_flash_unsecure(bl) # Reset target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) # Change to the default peripheral originalPeripheral = bl.change_peripheral(defaultPeripheral)
def test_CRC_check_out_of_range(self, bl): #case 1:BCA is invalid and CRC byte count is equal to zero bcaFilePath = user_config_area.create_BCA_data_file( bl, tag=user_config_area.four_char_code('k', 'c', 'f', 'g'), crcStartAddress=0x00000000, crcByteCount=0x00000000, crcExpectedValue=0xffffffff) # Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFilePath) assert status == bootloader.status.kStatus_Success #Create file which contains PC pointer filePath = create_data_file( bl, FirstFourByte=0xffffffff, SecondFourByte=0x00000001, ) #write PC pointer to Vector_table_address status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS, filePath) assert status == bootloader.status.kStatus_Success # Reset the target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) status, results = bl.get_property(8) assert results[0] == bootloader.status.kStatus_AppCrcCheckOutOfRange #erase and reset common_util.erase_all_available_flash_unsecure(bl) status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) #case 2:BCA is invalid and CRC address exceed 4G bcaFilePath = user_config_area.create_BCA_data_file( bl, tag=user_config_area.four_char_code('k', 'c', 'f', 'g'), crcStartAddress=0xffffffff, crcByteCount=0x00000002, crcExpectedValue=0xffffffff) # Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFilePath) assert status == bootloader.status.kStatus_Success #Create file which contains PC pointer filePath = create_data_file( bl, FirstFourByte=0xffffffff, SecondFourByte=0x00000001, ) #write PC pointer to Vector_table_address status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS, filePath) assert status == bootloader.status.kStatus_Success # Reset the target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) status, results = bl.get_property(8) assert results[0] == bootloader.status.kStatus_AppCrcCheckOutOfRange #erase and reset common_util.erase_all_available_flash_unsecure(bl) status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) #case 3:BCA is invalid and CRC address exceed flash size bcaFilePath = user_config_area.create_BCA_data_file( bl, tag=user_config_area.four_char_code('k', 'c', 'f', 'g'), crcStartAddress=0x10000000, crcByteCount=0x00000002, crcExpectedValue=0xffffffff) # Write the BCA configuration data to flash status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFilePath) assert status == bootloader.status.kStatus_Success #Create file which contains PC pointer filePath = create_data_file( bl, FirstFourByte=0xffffffff, SecondFourByte=0x00000001, ) #write PC pointer to Vector_table_address status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS, filePath) assert status == bootloader.status.kStatus_Success # Reset the target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(3) status, results = bl.get_property(8) assert results[0] == bootloader.status.kStatus_AppCrcCheckOutOfRange