def cumulative_write(bl, memType, memIndex, usingSbComamnd=False): (availableMemStartAddress, availableMemEndAddress, availableMemSize) = common_util.get_available_memory_region( bl, memType, memIndex) if (availableMemSize == 0 ): # K3S TO1.0, all the M4 ITCM SRAM regions are reserved. print("available%s%dSize = %d Bytes." % (memType.capitalize(), memIndex, availableMemSize)) print("No need to test cumulative write for %s%d!" % (memType.capitalize(), memIndex)) return else: writeStartAddress = availableMemStartAddress writeBytesLength = 0x400 writeEndAddress = writeStartAddress + writeBytesLength # Generate two random bin files. binFilePath1 = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) binFilePath2 = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath1, writeStartAddress, writeEndAddress) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath2, writeStartAddress, writeEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) status, results = bl.receive_sb_file(sbFile) else: status, results = bl.write_memory(writeStartAddress, binFilePath1) assert status == bootloader.status.kStatus_Success print('\nCumulative write %s:' % memType), status, results = bl.write_memory(writeStartAddress, binFilePath2) if (memType == 'ram'): assert status == bootloader.status.kStatus_Success elif (memType == 'flash'): assert ((status == bootloader.status.kStatus_FlashCommandFailure) or (status == bootloader.status.kStatusMemoryCumulativeWrite)) # EOF
def test_sb_write_unaligned_address(self, bl, memType): sb_commandDictionay['writeMemory'].cumulativeWrite = False startAddress, endAddress, length = common_util.get_available_memory_region( bl, memType) # Here we just need a small amount data for this case. Set the length as 1KB. length = 0x400 alignedBase = bl.target.programAlignmentSize for offset in range(1, alignedBase): sb_commandDictionay['writeMemory'].length = length sb_commandDictionay['writeMemory'].dataType = 'file_bin' sb_commandDictionay[ 'writeMemory'].startAddress = startAddress + offset sb_commandDictionay[ 'writeMemory'].endAddress = startAddress + length + offset sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, sb_commandDictionay['writeMemory'].startAddress, length) sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) if memType == 'flash': assert status == bootloader.status.kStatus_FlashAlignmentError elif memType == 'ram': assert status == bootloader.status.kStatus_Success
def test_sb_write_all_available_region(self, bl, memType): sb_commandDictionay['writeMemory'].cumulativeWrite = False startAddress, endAddress, length = common_util.get_available_memory_region( bl, memType) sb_commandDictionay['writeMemory'].length = length sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, startAddress, length) sb_commandDictionay['writeMemory'].dataType = 'file_bin' sb_commandDictionay['writeMemory'].startAddress = startAddress sb_commandDictionay['writeMemory'].endAddress = startAddress + length sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatus_Success # Read back the data from memory readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_Success # The two data files should be the same. with open(sb_commandDictionay['writeMemory'].data, 'rb') as fileObj1: data1 = fileObj1.read() fileObj1.close() with open(readFile, 'rb') as fileObj2: data2 = fileObj2.read() fileObj2.close() assert data1 == data2
def test_erase_all_available_flash(self, bl): availableRegionStartAddress, availableRegionEndAddress, availableRegionSize = common_util.get_available_memory_region( bl, 'flash') # 1. erase all the flash status, results = bl.flash_erase_all() assert status == bootloader.status.kStatus_Success # 2. write random data to [availableRegionStartAddress, availableRegionEndAddress] randomFile = common_util.generate_random_data_file( bl, availableRegionStartAddress, availableRegionSize) status, results = bl.write_memory(availableRegionStartAddress, randomFile) assert status == bootloader.status.kStatus_Success # 3. erase flash status, results = bl.flash_erase_region(availableRegionStartAddress, availableRegionSize) assert status == bootloader.status.kStatus_Success # 4. read data from [availableRegionStartAddress, availableRegionEndAddress] filePath = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results == bl.read_memory(availableRegionStartAddress, availableRegionSize, filePath) assert status == bootloader.status.kStatus_Success # 5. verify all the data are FF flag = True fileObj = open(filePath, 'rb') for i in range(0, availableRegionSize): fileObj.seek(i) data_tmp = fileObj.read(1) if ord(data_tmp) != 0xFF: flag = False break fileObj.close() assert flag == True
def write_reserved_memory_region(bl, memType, usingSbComamnd=False): (reservedMemStartAddress, reservedMemEndAddress, reservedMemSize) = common_util.get_reserved_memory_region(bl, memType) if (reservedMemSize == 0): # ROM has no reserved flash region print('No reserved region for %s memory.' % (memType.upper())) return else: writeStartAddress = reservedMemStartAddress writeBytesLength = reservedMemSize writeEndAddress = writeStartAddress + writeBytesLength binFilePath = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath, writeStartAddress, writeEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) status, results = bl.receive_sb_file(sbFile) else: status, results = bl.write_memory(writeStartAddress, binFilePath) assert status == bootloader.status.kStatusMemoryRangeInvalid
def write_out_of_memory_range(bl, memType, memIndex, usingSbComamnd=False): memStartAddress, memEndAddress = common_util.get_memory_start_end_address( bl, memType, memIndex) writeStartAddress = memEndAddress + 1 writeBytesLength = 0x400 writeEndAddress = writeStartAddress + writeBytesLength binFilePath = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath, writeStartAddress, writeEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) status, results = bl.receive_sb_file(sbFile) else: status, results = bl.write_memory(writeStartAddress, binFilePath) assert status == bootloader.status.kStatusMemoryRangeInvalid
def test_all_supported_can_speed(self, bl, canSpeed): # Change the can speed bl.set_CAN_parameters(canSpeed) common_util.reset_with_check(bl) # 1. Get available flash region availableRegionStartAddress, availableRegionEndAddress, availableRegionSize = common_util.get_available_memory_region(bl, 'flash') # 2. Erase all the available flash region status, results = bl.flash_erase_region(availableRegionStartAddress, availableRegionSize) assert status == bootloader.status.kStatus_Success # 3. Program all the available flash region randomFile = common_util.generate_random_data_file(bl, availableRegionStartAddress, availableRegionSize) status, results = bl.write_memory(availableRegionStartAddress, randomFile) assert status == bootloader.status.kStatus_Success # 4. Read back the data readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(availableRegionStartAddress, availableRegionSize, readFile) assert status == bootloader.status.kStatus_Success # 5. Verify data randomFileObj = file(randomFile, 'rb') data1 = randomFileObj.read() readFileObj = file(readFile, 'rb') data2 = readFileObj.read() assert data1 == data2
def test_write_without_enable_QSPI(self, bl): startAddress, actualLength = get_QSPI_flash_address_and_length( 1, 'Sectors', 'StartOfMemory') # Creat random file that contains actualLength bytes. randomFile = common_util.generate_random_data_file( bl, startAddress, actualLength) status, results = bl.write_memory(startAddress, randomFile) assert status == bootloader.status.kStatus_QspiNotConfigured
def test_access_QSPI_with_reset_after_QSPI_enabled(self, bl, qcbLocation): # 1. Write QSPI config block data to ram/flash and config QSPI module. config_QSPI_flash(bl, kQspiConfigBlockFile, qcbLocation) # 2. Access qspi flash should be successful after configure qspi startAddress = qspiFlashStartAddress length = qspiFlashPageSize # Erase status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_Success # Write randomFilePath = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_Success # Fill status, results = bl.fill_memory(startAddress, length, kFillValue) assert status == bootloader.status.kStatus_QspiFlashCommandFailure # Read readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_Success # 3. Access qspi flash should fail after rest. # Reset status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(2) startAddress = qspiFlashStartAddress length = qspiFlashPageSize # Erase status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_QspiNotConfigured # Write randomFilePath = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_QspiNotConfigured # Fill status, results = bl.fill_memory(startAddress, length, kFillValue) assert status == bootloader.status.kStatus_QspiNotConfigured # Read readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_QspiNotConfigured
def test_cumulative_write(self, bl): availableRegionStartAddress, availableRegionEndAddress, availableRegionSize = common_util.get_available_memory_region( bl, 'flash') # Create a random file which contains 1KB bytes. randomFile = common_util.generate_random_data_file( bl, availableRegionStartAddress, 0x400) # write file to the specific available flash region status, results = bl.write_memory(availableRegionStartAddress, randomFile) assert status == bootloader.status.kStatus_Success # Create a random file which contains 1KB bytes. randomFile = common_util.generate_random_data_file( bl, availableRegionStartAddress, 0x400) # attempt to write 0 to 1, expected return value is kStatus_FlashCommandFailure status, results = bl.write_memory(availableRegionStartAddress, randomFile) assert status == bootloader.status.kStatus_FlashCommandFailure or status == bootloader.status.kStatusMemoryCumulativeWrite
def test_write_unaligned_QSPI_flash_address(self, bl): # Generate a file that contains 1024 bytes random data randomFilePath = common_util.generate_random_data_file( bl, qspiFlashStartAddress, 1024) # The start address must be page size aligned when program the qspi flash. alignBase = qspiFlashPageSize for i in range(1, alignBase): status, results = bl.write_memory(qspiFlashStartAddress + i, randomFilePath) assert status == bootloader.status.kStatus_QspiFlashAlignmentError
def write_unaligned_memory_address(bl, memType, memIndex, usingSbComamnd=False): (availableMemStartAddress, availableMemEndAddress, availableMemSize) = common_util.get_available_memory_region( bl, memType, memIndex) if (availableMemSize == 0 ): # K3S TO1.0, all the M4 ITCM SRAM regions are reserved. print("available%s%dSize = %d Bytes." % (memType.capitalize(), memIndex, availableMemSize)) print("No need to write the unagined memory address for %s%d!" % (memType.capitalize(), memIndex)) return writeBytesLength = 0x10 for i in range(1, bl.target.programAlignmentSize): writeStartAddress = availableMemStartAddress + i # unaligned address writeEndAddress = writeStartAddress + writeBytesLength # If not in the available region, just quit the loop if (writeStartAddress + writeBytesLength > availableMemEndAddress): break # If in the available region else: binFilePath = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath, writeStartAddress, writeEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) status, results = bl.receive_sb_file(sbFile) else: status, results = bl.write_memory(writeStartAddress, binFilePath) # 1. For SRAM, should return success if (memType == 'ram'): assert status == bootloader.status.kStatus_Success verifyWriteResult = common_util.verify_write_memory( bl, writeStartAddress, binFilePath) assert verifyWriteResult == True elif (memType == 'flash'): assert status == bootloader.status.kStatus_FlashAlignmentError
def write_start_of_available_memory_region(bl, memType, memIndex, bytesNumber, usingSbComamnd=False): (availableMemStartAddress, availableMemEndAddress, availableMemSize) = common_util.get_available_memory_region( bl, memType, memIndex) if (availableMemSize == 0 ): # K3S TO1.0, all the M4 ITCM SRAM regions are reserved. print("available%s%dSize = %d Bytes." % (memType.capitalize(), memIndex, availableMemSize)) print("No available region for %s%d!" % (memType.capitalize(), memIndex)) return if (bytesNumber == 'halfOfAvailableMemory'): bytesNumber = availableMemSize / 2 elif (bytesNumber == 'allOfAvailableMemory'): bytesNumber = availableMemSize if (bytesNumber <= availableMemSize): writeStartAddress = availableMemStartAddress writeBytesLength = bytesNumber writeEndAddress = writeStartAddress + writeBytesLength binFilePath = common_util.generate_random_data_file( bl, writeStartAddress, writeBytesLength) if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_write_memory( bdContent, binFilePath, writeStartAddress, writeEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) status, results = bl.receive_sb_file(sbFile) else: status, results = bl.write_memory(writeStartAddress, binFilePath) assert status == bootloader.status.kStatus_Success verifyWriteResult = common_util.verify_write_memory( bl, writeStartAddress, binFilePath) assert verifyWriteResult == True else: print("writeLength = %d Bytes > available%s%dSize = %d Bytes." % (bytesNumber, memType.capitalize(), memIndex, availableMemSize))
def test_cumulative_write_QSPI_flash(self, bl): startAddress = qspiFlashStartAddress actualLength = qspiFlashPageSize # Erase the qspi flash status, results = bl.flash_erase_region(startAddress, actualLength) assert status == bootloader.status.kStatus_Success # Generate a file that contains actualLength bytes random data randomFilePath = common_util.generate_random_data_file( bl, startAddress, actualLength) # Write qspi flash after erase should be success status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_Success # Generate a file that contains actualLength bytes random data randomFilePath = common_util.generate_random_data_file( bl, startAddress, actualLength) # Write qspi flash without erase should be fail status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_QspiFlashCommandFailure
def test_config_QCB_at_internal_memory(self, bl, qcbLocation): # 1. Erase the whole flash status, results = bl.flash_erase_all() assert status == bootloader.status.kStatus_Success # 2. get the available address to place the qspi config block data and set qspiConfigBlockPointer to BCA qspiConfigBlockPointer = config_QSPI_flash(bl, kQspiConfigBlockFile, qcbLocation) bcaFilePath = user_config_area.create_BCA_data_file( bl, qspiConfigBlockPointer=qspiConfigBlockPointer) status, results = bl.write_memory( bl.target.BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0, bcaFilePath) assert status == bootloader.status.kStatus_Success # 3. Set FOPT to let MCU boot from ROM, configure qspi and enter into bootloader mode. # For the flash-resident bootloader on the ROM tape-out chip, the FOPT is already 0xBD, # so no need to configure FOPT here, what's more it will get Flash_Command_Failure. if bl.target.bootloaderType == bootsources.kBootROM_ExecuteROM: flashConfigDataFilePath = flash_config_area.generate_flash_config_data( flashOptionRegister=0xBD) # 0xBD/0xBF is OK status, results = bl.write_memory(0x400, flashConfigDataFilePath) assert status == bootloader.status.kStatus_Success else: pass # 4. Reset target status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(2) # 5. After reset, ROM code will configure qspi automatically, so accessing qspi flash should be successful startAddress = qspiFlashStartAddress length = qspiFlashPageSize # Erase status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_Success # Write randomFilePath = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_Success # Fill status, results = bl.fill_memory(startAddress, length, kFillValue) assert status == bootloader.status.kStatus_QspiFlashCommandFailure # Read readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_Success
def test_sb_load_nothing_to_nonzero_size_space(self, bl): # data size is zero while start address is not equal to end address (return kStatusRomLdrChecksum) sb_commandDictionay['writeMemory'].cumulativeWrite = False sb_commandDictionay['writeMemory'].length = 0 sb_commandDictionay['writeMemory'].dataType = 'file_bin' sb_commandDictionay['writeMemory'].startAddress = 0x1000 sb_commandDictionay['writeMemory'].endAddress = 0x2000 sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, sb_commandDictionay['writeMemory'].startAddress, sb_commandDictionay['writeMemory'].length) sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatusRomLdrIdNotFound
def test_sb_erase_available_flash_region(self, bl, availableFlashSize): startAddress, endAddress, length = common_util.get_available_memory_region( bl, 'flash') # 1. Get actual erased length according to the parameter if availableFlashSize == 'zero': length = 0 elif availableFlashSize == 'oneSectorSize': length = common_util.get_flash_sector_size(bl) elif availableFlashSize == 'allAvailableSize': length = length # 2. erase with blhost command status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_Success # 3. write random data to [startAddress, endAddress] randomFile = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFile) assert status == bootloader.status.kStatus_Success # 4. generate sb file and erase with sb command sb_commandDictionay['flashEraseRegion'].startAddress = startAddress sb_commandDictionay[ 'flashEraseRegion'].endAddress = startAddress + length sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'flashEraseRegion') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatus_Success # 5. read data from [startAddress, endAddress] filePath = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results == bl.read_memory(startAddress, length, filePath) assert status == bootloader.status.kStatus_Success # 6. verify all the data are FF flag = True fileObj = open(filePath, 'rb') for i in range(0, length): fileObj.seek(i) data_tmp = fileObj.read(1) if ord(data_tmp) != 0xFF: flag = False break fileObj.close() assert flag == True if bl.target.bootloaderType == bootsources.kBootROM_ExecuteROM: # 7. unsecure the flash status, results = bl.flash_erase_all_unsecure() assert status == bootloader.status.kStatus_Success else: pass
def test_sb_erase_all_internal_flash(self, bl): # 1. generate sb file with "erase all" and send the sb file to target, should be success sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'internalFlashEraseAll') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatus_Success # 2. get flash region that can be erased by 'erase all' with sb file startAddress, endAddress, length = common_util.get_available_memory_region( bl, 'flash') # 3. write random data to [startAddress, endAddress], should be success randomFile = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFile) assert status == bootloader.status.kStatus_Success # 4. erase all the internal flash with sb file, should be success status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatus_Success # 5. read data from [startAddress, endAddress] filePath = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results == bl.read_memory(startAddress, length, filePath) assert status == bootloader.status.kStatus_Success # 6. verify all the data are FF flag = True fileObj = open(filePath, 'rb') for i in range(0, length): fileObj.seek(i) data_tmp = fileObj.read(1) if ord(data_tmp) != 0xFF: flag = False break fileObj.close() assert flag == True if bl.target.bootloaderType == bootsources.kBootROM_ExecuteROM: # 7. reset the target, flash should be in secure state status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(2) status, results = bl.get_property( bootloader.properties.kPropertyTag_FlashSecurityState) assert status == bootloader.status.kStatus_Success assert results[0] == 1 # 8. unsecure the flash status, results = bl.flash_erase_all_unsecure() assert status == bootloader.status.kStatus_Success else: pass
def test_write_all_available_memory(self, bl, memType): availableRegionStartAddress, availableRegionEndAddress, availableRegionSize = common_util.get_available_memory_region( bl, memType) # Create a random file which contains availableRegionSize bytes. randomFile = common_util.generate_random_data_file( bl, availableRegionStartAddress, availableRegionSize) # write file to the specific available flash region status, results = bl.write_memory(availableRegionStartAddress, randomFile) assert status == bootloader.status.kStatus_Success # Read back the data from Flash readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(availableRegionStartAddress, availableRegionSize, readFile) assert status == bootloader.status.kStatus_Success # The two data files should be the same. assert True == common_util.file_comparison(randomFile, readFile)
def test_sb_write_all_reserved_region(self, bl, memType): sb_commandDictionay['writeMemory'].cumulativeWrite = False startAddress, endAddress, length = common_util.get_reserved_memory_region( bl, memType) if length == 0: pass # ROM has no flash reserved region. else: sb_commandDictionay['writeMemory'].length = length sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, startAddress, length) sb_commandDictionay['writeMemory'].dataType = 'file_bin' sb_commandDictionay['writeMemory'].startAddress = startAddress sb_commandDictionay[ 'writeMemory'].endAddress = startAddress + length sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatusMemoryRangeInvalid
def test_sb_cumulative_write(self, bl, memType): sb_commandDictionay['writeMemory'].cumulativeWrite = True startAddress, endAddress, length = common_util.get_available_memory_region( bl, memType) # Here we just need a small amount data for this case. Set the length as 1KB. length = 0x400 sb_commandDictionay['writeMemory'].length = length sb_commandDictionay['writeMemory'].dataType = 'file_bin' sb_commandDictionay['writeMemory'].startAddress = startAddress sb_commandDictionay['writeMemory'].endAddress = startAddress + length sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, startAddress, length) sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) if memType == 'flash': assert status == bootloader.status.kStatus_FlashCommandFailure or status == bootloader.status.kStatusMemoryCumulativeWrite elif memType == 'ram': assert status == bootloader.status.kStatus_Success
def test_sb_write_memory_out_of_range(self, bl, memType): sb_commandDictionay['writeMemory'].cumulativeWrite = False startAddress, endAddress, length = common_util.get_available_memory_region( bl, memType) # Here we just need a small amount data for this case. Set the length as 1KB. length = 0x400 sb_commandDictionay['writeMemory'].length = length sb_commandDictionay['writeMemory'].dataType = 'file_bin' # Make sure the start_addr is anligned and near the end of the memory region. sb_commandDictionay[ 'writeMemory'].startAddress = endAddress + 1 - bl.target.programAlignmentSize sb_commandDictionay['writeMemory'].endAddress = sb_commandDictionay[ 'writeMemory'].startAddress + length sb_commandDictionay[ 'writeMemory'].data = common_util.generate_random_data_file( bl, startAddress, length) sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'writeMemory') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatusMemoryRangeInvalid
def write_QSPI_flash_according_to_parameters(bl, length, lengthType, locationType): startAddress, actualLength = get_QSPI_flash_address_and_length( length, lengthType, locationType) # Erase the qspi flash before program it. eraseStatus, results = bl.flash_erase_region(startAddress, actualLength) # Generate a file contains random contents with actualLength bytes randomFilePath = common_util.generate_random_data_file( bl, startAddress, actualLength) # Write memory writeStatus, results = bl.write_memory(startAddress, randomFilePath) # Get the location of the block data location = block_location(startAddress, actualLength) if location == common_util.kZeroSizeBlock: assert eraseStatus == bootloader.status.kStatus_Success assert writeStatus == bootloader.status.kStatus_Success elif location == common_util.kInvalidMemoryRange: assert eraseStatus == bootloader.status.kStatusMemoryRangeInvalid assert writeStatus == bootloader.status.kStatusMemoryRangeInvalid elif location == common_util.kValidMemoryRange: assert eraseStatus == bootloader.status.kStatus_Success # The start address must be page size aligned when program the qspi flash. if (startAddress % qspiFlashPageSize) == 0: assert writeStatus == bootloader.status.kStatus_Success # read back the data readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') read_status, results = bl.read_memory(startAddress, actualLength, readFile) assert read_status == bootloader.status.kStatus_Success # The two data files should be the same. assert True == common_util.file_comparison(randomFilePath, readFile) elif (startAddress % qspiFlashPageSize) > 0: assert writeStatus == bootloader.status.kStatus_QspiFlashAlignmentError
def test_enable_QSPI_with_sb_file(self, bl, qcbLocation): # Operate qspi flash will fail before enable qspi startAddress, actualLength = get_QSPI_flash_address_and_length( 1, 'Sectors', 'StartOfMemory') # Creat random file that contains actualLength bytes. randomFile = common_util.generate_random_data_file( bl, startAddress, actualLength) status, results = bl.write_memory(startAddress, randomFile) assert status == bootloader.status.kStatus_QspiNotConfigured # Get qspi block data sbCmdDict['enableQspi'].qspiConfigBlock = os.path.abspath( os.path.join(bl.vectorsDir, 'QSPI', kQspiConfigBlockFile)) # Get the location of the qspi block data sbCmdDict['enableQspi'].qcbLocation = qcbLocation # Generate sb file sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'internalFlashEraseAll', 'enableQspi') status, results = bl.receive_sb_file(sbFilePath) if qcbLocation == 0: if bl.target.bootloaderType == bootsources.kBootFlash_ExecuteFlash: # The memory address 0x0 is in the reserved region for flash-resident bootloader. assert status == bootloader.status.kStatusMemoryRangeInvalid else: # Cannot enable QSPI at 0x0 even it is available. assert status == bootloader.status.kStatus_InvalidArgument # Operate qspi flash will fail status, results = bl.flash_erase_region(startAddress, actualLength) assert status == bootloader.status.kStatus_QspiNotConfigured else: assert status == bootloader.status.kStatus_Success # Operate qspi flash will be successful after enable qspi status, results = bl.flash_erase_region(startAddress, actualLength) assert status == bootloader.status.kStatus_Success
def write_memory_according_to_parameters(bl, length, lengthType, memType, locationType): # Get actual start address and byte count to be written. startAddress, actualLength = common_util.get_start_address_and_length( bl, length, lengthType, memType, locationType) # Create a random file which contains actualLength bytes. randomFile = common_util.generate_random_data_file(bl, startAddress, actualLength) # Write file to memory status, results = bl.write_memory(startAddress, randomFile) # Get the location of a given block. locationStatus = common_util.block_location(bl, startAddress, actualLength, memType) if locationStatus == common_util.kInvalidParameter: assert status != bootloader.status.kStatus_Success elif locationStatus == common_util.kZeroSizeBlock: assert status == bootloader.status.kStatus_Success elif locationStatus == common_util.kInvalidMemoryRange: assert status == bootloader.status.kStatusMemoryRangeInvalid elif locationStatus == common_util.kValidMemoryRange: if startAddress % bl.target.programAlignmentSize == 0 or memType == 'ram': assert status == bootloader.status.kStatus_Success elif startAddress % bl.target.programAlignmentSize > 0: assert status == bootloader.status.kStatus_FlashAlignmentError
def test_config_QCB_at_QSPI_start_address(self, bl): # 1. Make sure QCB is located in qspi flash start address # Write QSPI config block data to RAM and config QSPI module. config_QSPI_flash(bl, kQspiConfigBlockFile, 'ram') # Erase qspi flash. status, results = bl.flash_erase_region(qspiFlashStartAddress, qspiFlashSectorSize) assert status == bootloader.status.kStatus_Success # Write QCB to qspi flash start address fullFileName = os.path.abspath( os.path.join(bl.vectorsDir, 'QSPI', kQspiConfigBlockFile)) status, results = bl.write_memory(qspiFlashStartAddress, fullFileName) assert status == bootloader.status.kStatus_Success # 2. Reset target and access the qspi flash will fail for ROM. if bl.target.bootloaderType == bootsources.kBootROM_ExecuteROM: # Reset status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(2) startAddress = qspiFlashStartAddress length = qspiFlashPageSize # Erase status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_QspiNotConfigured # Write randomFilePath = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_QspiNotConfigured # Fill status, results = bl.fill_memory(startAddress, length, kFillValue) assert status == bootloader.status.kStatus_QspiNotConfigured # Read readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_QspiNotConfigured # 3. Set FOPT to let MCU boot from ROM, configure qspi and enter into bootloader mode. # For the flash-resident bootloader on the ROM tape-out chip, the FOPT is already 0xBD. status, results = bl.flash_erase_all() assert status == bootloader.status.kStatus_Success flashConfigDataFilePath = flash_config_area.generate_flash_config_data( flashOptionRegister=0xBD) # 0xBD/0xBF is OK status, results = bl.write_memory(0x400, flashConfigDataFilePath) assert status == bootloader.status.kStatus_Success else: pass # 4. After reset, ROM code will configure qspi automatically, so accessing qspi flash should be successful # Reset. It seeems we must press the SW3/SW5 to reset the target on fpga board, so that this case can pass, maybe it's a fpga board issue. status, results = bl.reset() assert status == bootloader.status.kStatus_Success time.sleep(2) startAddress = qspiFlashStartAddress length = qspiFlashPageSize # Erase status, results = bl.flash_erase_region(startAddress, length) assert status == bootloader.status.kStatus_Success # Write randomFilePath = common_util.generate_random_data_file( bl, startAddress, length) status, results = bl.write_memory(startAddress, randomFilePath) assert status == bootloader.status.kStatus_Success # Fill status, results = bl.fill_memory(startAddress, length, kFillValue) assert status == bootloader.status.kStatus_QspiFlashCommandFailure # Read readFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin') status, results = bl.read_memory(startAddress, length, readFile) assert status == bootloader.status.kStatus_Success