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 fill_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:
        fillStartAddress = reservedMemStartAddress
        fillBytesLength = reservedMemSize
        fillEndAddress = fillStartAddress + fillBytesLength
        if (usingSbComamnd == True):
            bdContent = SBFile.bd_content_init(bl, needSign=False)
            bdContent = SBFile.bd_content_update_for_fill_memory(
                bdContent, kFillPattern, 'byte', fillStartAddress,
                fillEndAddress)
            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.fill_memory(fillStartAddress, fillBytesLength,
                                             kFillPattern, 'byte')
        assert status == bootloader.status.kStatusMemoryRangeInvalid
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 erase_out_of_memory_range(bl, memType, memIndex, usingSbComamnd=False):
    memStartAddress, memEndAddress = common_util.get_memory_start_end_address(
        bl, memType, memIndex)
    eraseStartAddress = memEndAddress + 1
    eraseBytesLength = 0x400
    eraseEndAddress = eraseStartAddress + eraseBytesLength
    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.kStatusMemoryRangeInvalid
    else:
        status, results = bl.flash_erase_region(eraseStartAddress,
                                                eraseBytesLength)
        assert status == bootloader.status.kStatusMemoryRangeInvalid


# EOF
def erase_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:
        eraseStartAddress = reservedMemStartAddress
        eraseBytesLength = reservedMemSize
        eraseEndAddress = eraseStartAddress + eraseBytesLength
        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)
        else:
            status, results = bl.flash_erase_region(eraseStartAddress,
                                                    eraseBytesLength)

        if (memType == 'ram'):
            assert status == bootloader.status.kStatus_FlashAddressError
        elif (memType == 'flash'):
            assert status == bootloader.status.kStatusMemoryRangeInvalid
def cumulative_fill(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 fill for %s%d!" %
              (memType.capitalize(), memIndex))
        return
    else:
        fillStartAddress = availableMemStartAddress
        fillBytesLength = 0x400
        fillEndAddress = fillStartAddress + fillBytesLength

        firstFillPattern = 0x00
        secondFillPattern = 0xFF

        if (usingSbComamnd == True):
            bdContent = SBFile.bd_content_init(bl, needSign=False)
            bdContent = SBFile.bd_content_update_for_fill_memory(
                bdContent, firstFillPattern, 'word', fillStartAddress,
                fillEndAddress)
            bdContent = SBFile.bd_content_update_for_fill_memory(
                bdContent, secondFillPattern, 'byte', fillStartAddress,
                fillEndAddress)
            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.fill_memory(fillStartAddress, fillBytesLength,
                                             firstFillPattern, 'byte')
            assert status == bootloader.status.kStatus_Success
            print('\nCumulative fill %s:' % memType),
            status, results = bl.fill_memory(fillStartAddress, fillBytesLength,
                                             secondFillPattern, 'byte')

        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 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 fill_start_of_available_memory_region(bl,
                                          memType,
                                          memIndex,
                                          pattern,
                                          bytesNumber,
                                          format,
                                          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):
        fillStartAddress = availableMemStartAddress
        fillBytesLength = bytesNumber
        fillEndAddress = fillStartAddress + fillBytesLength
        if (usingSbComamnd == True):
            bdContent = SBFile.bd_content_init(bl, needSign=False)
            bdContent = SBFile.bd_content_update_for_fill_memory(
                bdContent, pattern, format, fillStartAddress, fillEndAddress)
            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.fill_memory(fillStartAddress, fillBytesLength,
                                             pattern, format)
        assert status == bootloader.status.kStatus_Success
        verifyFillResult = common_util.verify_fill_memory(
            bl, fillStartAddress, fillBytesLength, pattern, format)
        assert verifyFillResult == True
    else:
        print("fillLength = %d Bytes > available%s%dSize = %d Bytes." %
              (bytesNumber, memType.capitalize(), memIndex, availableMemSize))
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))
Esempio n. 10
0
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 erase_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 erase the unagined memory address for %s%d!" %
              (memType.capitalize(), memIndex))
        return

    for i in range(1, bl.target.eraseAlignmentSize):
        eraseStartAddress = availableMemStartAddress + i  # unaligned address
        eraseBytesLength = bl.target.eraseAlignmentSize
        eraseEndAddress = eraseStartAddress + eraseBytesLength
        # If not in the available region, just quit the loop
        if (eraseStartAddress + eraseBytesLength > availableMemEndAddress):
            break
        # If in the available region
        else:
            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)
            else:
                status, results = bl.flash_erase_region(
                    eraseStartAddress, eraseBytesLength)

            if (memType == 'ram'):
                assert status == bootloader.status.kStatus_FlashAddressError
            elif (memType == 'flash'):
                assert status == bootloader.status.kStatus_FlashAlignmentError
Esempio n. 12
0
def fill_out_of_memory_range(bl, memType, memIndex, usingSbComamnd=False):
    memStartAddress, memEndAddress = common_util.get_memory_start_end_address(
        bl, memType, memIndex)
    fillStartAddress = memEndAddress + 1
    fillBytesLength = 0x400
    fillEndAddress = fillStartAddress + fillBytesLength
    if (usingSbComamnd == True):
        bdContent = SBFile.bd_content_init(bl, needSign=False)
        bdContent = SBFile.bd_content_update_for_fill_memory(
            bdContent, kFillPattern, 'byte', fillStartAddress, fillEndAddress)
        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.fill_memory(fillStartAddress, fillBytesLength,
                                         kFillPattern, 'byte')
    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))