def config_QSPI_flash(bl, qcbFileName, qcbResident): # get the file path qcbFilePath = os.path.abspath( os.path.join(bl.vectorsDir, 'QSPI', qcbFileName)) # Get available memory address to place the QCB availableRegionStartAddress, availableRegionEndAddress, availableRegionSize = common_util.get_available_memory_region( bl, qcbResident) qcbLocation = availableRegionStartAddress if qcbResident == 'ram': pass elif qcbResident == 'flash': if availableRegionStartAddress == 0: # QCB cannot be located in flash start address as it is used to place the app's vector table. # Let QCB locate at the end of the flash address for the boundary value testing. qcbLocation = qcbLocation + common_util.get_memory_total_size( bl, 'flash') - os.path.getsize(qcbFilePath) else: pass # Erase 1 sector flash before program flashSectorSize = common_util.get_flash_sector_size(bl) startAddressSectorAlign = common_util.flash_align_down( qcbLocation, flashSectorSize) status, results = bl.flash_erase_region(startAddressSectorAlign, flashSectorSize) assert status == bootloader.status.kStatus_Success # write qspi config block data to ram status, results = bl.write_memory(qcbLocation, qcbFilePath) assert status == bootloader.status.kStatus_Success # execute configure-quadspi command status, results = bl.configure_memory(1, qcbLocation) assert status == bootloader.status.kStatus_Success return qcbLocation
def get_indicator_address(bl, status): startAddress = common_util.get_memory_start_address(bl, 'flash') totalSize = common_util.get_memory_total_size(bl, 'flash') sectorSize = common_util.get_flash_sector_size(bl) if status: #address for reliable update address = startAddress + totalSize / 2 - sectorSize return address else: #wrong address for test swap indicator address invalid address = startAddress + totalSize / 2 - sectorSize * 2 return address
def test_sb_erase_out_of_range(self, bl, memType): startAddress, endAddress, length = common_util.get_available_memory_region( bl, memType) # Here we just need a small amount data for this case. Set the erase length as 1 sector. length = common_util.get_flash_sector_size(bl) # Make sure the start_addr is anligned and near the end of the memory region. sb_commandDictionay[ 'flashEraseRegion'].startAddress = endAddress + 1 - bl.target.eraseAlignmentSize sb_commandDictionay[ 'flashEraseRegion'].endAddress = sb_commandDictionay[ 'flashEraseRegion'].startAddress + length sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '', 'flashEraseRegion') status, results = bl.receive_sb_file(sbFilePath) assert status == bootloader.status.kStatusMemoryRangeInvalid
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_available_ram_region(self, bl, availableRamSize): startAddress, endAddress, length = common_util.get_available_memory_region( bl, 'ram') # 1. Get actual erased length according to the parameter if availableRamSize == 'zero': length = 0 elif availableRamSize == 'oneSectorSize': length = common_util.get_flash_sector_size(bl) elif availableRamSize == 'allAvailableSize': length = length # 2. 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) if length == 0: assert status == bootloader.status.kStatus_Success else: # erase ram region (including available region and reserved reigion) should return kStatus_FlashAddressError assert status == bootloader.status.kStatus_FlashAddressError
def test_erase_region_out_of_flash(self, bl): address = common_util.get_memory_start_address( bl, 'flash') + common_util.get_memory_total_size(bl, 'flash') bytesNumber = common_util.get_flash_sector_size(bl) status, results = bl.flash_erase_region(address, bytesNumber) assert status == bootloader.status.kStatusMemoryRangeInvalid
def erase_sectors_at_start_of_available_region(bl, memType, memIndex, sectorsNumber, 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 (str(sectorsNumber).isdigit()): # Get flash sector size flashSectorSize = common_util.get_flash_sector_size(bl, memIndex) eraseBytes = sectorsNumber * flashSectorSize elif (sectorsNumber == 'halfOfAvailableMemory'): eraseBytes = availableMemSize / 2 elif (sectorsNumber == 'allOfAvailableMemory'): eraseBytes = availableMemSize if (eraseBytes <= availableMemSize): eraseStartAddress = availableMemStartAddress eraseBytesLength = eraseBytes eraseEndAddress = eraseStartAddress + eraseBytesLength if (memType == 'ram'): if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_flash_erase_region( bdContent, eraseStartAddress, eraseEndAddress) 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) assert status == bootloader.status.kStatus_FlashAddressError else: status, results = bl.flash_erase_region( eraseStartAddress, eraseBytesLength) assert status == bootloader.status.kStatus_FlashAddressError elif (memType == 'flash'): print("Program the %s%d:" % (memType.capitalize(), memIndex)), status, results = bl.fill_memory(availableMemStartAddress, eraseBytes, 0x12345678, 'word') assert status == bootloader.status.kStatus_Success if (usingSbComamnd == True): bdContent = SBFile.bd_content_init(bl, needSign=False) bdContent = SBFile.bd_content_update_for_flash_erase_region( bdContent, eraseStartAddress, eraseEndAddress) bdFile = SBFile.bd_content_finish(bl, bdContent) sbFile = SBFile.generate_sb_file(bl, bdFile, needEncrypt=False, encryptionKey=None, needSign=False, s=[], S=[], R=[]) print("Erase the programmed data with erase sb command:"), status, results = bl.receive_sb_file(sbFile) assert status == bootloader.status.kStatus_Success else: print( "Erase the programmed data with flash-erase-region command:" ), status, results = bl.flash_erase_region( eraseStartAddress, eraseBytesLength) assert status == bootloader.status.kStatus_Success verifyEraseResult = common_util.verify_flash_erase( bl, eraseStartAddress, eraseBytesLength) assert verifyEraseResult == True else: print("eraseBytes = %d Bytes > available%s%dSize = %d Bytes." % (eraseBytes, memType.capitalize(), memIndex, availableMemSize))