コード例 #1
0
    def test_sb_jump_to_sp_pc_with_arg(self, bl, hasArg):
        # Extract SP and PC address from app demo bin file, and then jump to SP and PC without argument
        (elfFile, hexFile, binFile) = common_util.get_led_demo_path(bl)

        sb_commandDictionay['writeMemory'].cumulativeWrite = False
        sb_commandDictionay['writeMemory'].data = binFile
        sb_commandDictionay['writeMemory'].dataType = 'app_bin'
        sb_commandDictionay[
            'writeMemory'].startAddress = bl.target.BL_APP_VECTOR_TABLE_ADDRESS
        sb_commandDictionay['writeMemory'].endAddress = sb_commandDictionay[
            'writeMemory'].startAddress + os.path.getsize(binFile)

        sb_commandDictionay['jumpStackPoint'].hasArg = hasArg
        if hasArg:
            # Set the argument as random 32-bit data if has.
            sb_commandDictionay['jumpStackPoint'].arg = random.randint(
                0, 0xffffffff)
        else:
            sb_commandDictionay['jumpStackPoint'].arg = None
        # Generate sb file
        sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '',
                                                 'writeMemory',
                                                 'jumpStackPoint')
        # After excuting receive-sb-file the led will blink immediately and blhost returns kStatus_AbortDataPhase.
        status, results = bl.receive_sb_file(sbFilePath)
        assert status == bootloader.status.kStatus_AbortDataPhase
        # Send command to blhost, it will fail
        status, results = bl.get_property(
            bootloader.properties.kPropertyTag_CurrentVersion)
        status != bootloader.status.kStatus_Success
        # Let led blink for some time so that we can see the correct phenomenon.
        time.sleep(3)
コード例 #2
0
    def test_sb_jump_to_pc_address(self, bl):
        # Extract PC address from app demo bin file, and then jump to PC.
        # The case can pass on K80 while fail on L5K. Jump will not support jump to explicit address, but only support jump to app entry point
        (elfFile, hexFile, binFile) = common_util.get_led_demo_path(bl)

        sb_commandDictionay['writeMemory'].cumulativeWrite = False
        sb_commandDictionay['writeMemory'].data = binFile
        sb_commandDictionay['writeMemory'].dataType = 'app_bin'
        sb_commandDictionay[
            'writeMemory'].startAddress = bl.target.BL_APP_VECTOR_TABLE_ADDRESS
        sb_commandDictionay['writeMemory'].endAddress = sb_commandDictionay[
            'writeMemory'].startAddress + os.path.getsize(binFile)

        # Generate sb file
        sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '',
                                                 'writeMemory',
                                                 'jumpEntryPoint')
        # After excuting receive-sb-file the led will blink immediately and blhost returns kStatus_AbortDataPhase.
        status, results = bl.receive_sb_file(sbFilePath)
        assert status == bootloader.status.kStatus_AbortDataPhase
        # Send command to blhost, it will fail
        status, results = bl.get_property(
            bootloader.properties.kPropertyTag_CurrentVersion)
        status != bootloader.status.kStatus_Success
        # Let led blink for some time so that we can see the correct phenomenon.
        time.sleep(3)
コード例 #3
0
def init_sbCmdDict(bl, encryptionType, dataType, memType):
    startAddress, endAddress, length = common_util.get_available_memory_region(
        bl, memType)
    sbCmdDict['writeMemory'].cumulativeWrite = False
    sbCmdDict['writeMemory'].dataType = dataType
    if dataType == 'string':
        sbCmdDict['writeMemory'].data = kStringForSimpleSbFile
        sbCmdDict['writeMemory'].length = len(kStringForSimpleSbFile)
        sbCmdDict['writeMemory'].startAddress = startAddress
        sbCmdDict['writeMemory'].endAddress = startAddress + len(
            kStringForSimpleSbFile)
    elif dataType == 'function':
        sbCmdDict['writeMemory'].data = kFormatStringForFunctionSbFile
        sbCmdDict['writeMemory'].length = len(kFormatStringForFunctionSbFile)
        sbCmdDict['writeMemory'].startAddress = startAddress
        sbCmdDict['writeMemory'].endAddress = startAddress + len(
            kFormatStringForFunctionSbFile)
    elif dataType == 'app_bin':
        (elfFile, hexFile, binFile) = common_util.get_led_demo_path(bl)
        sbCmdDict['writeMemory'].data = binFile
        sbCmdDict['writeMemory'].length = os.path.getsize(binFile)
        sbCmdDict[
            'writeMemory'].startAddress = bl.target.BL_APP_VECTOR_TABLE_ADDRESS
        sbCmdDict[
            'writeMemory'].endAddress = bl.target.BL_APP_VECTOR_TABLE_ADDRESS + os.path.getsize(
                binFile)
コード例 #4
0
def generate_demo(bl, isBcaOpen, isCrcOpen, isCrcRight):
    elfFile, hexFile, binFile = common_util.get_led_demo_path(bl)
    vectorAddress = bl.target.BL_APP_VECTOR_TABLE_ADDRESS
    #create a bytearray to store the bca and CRC configuration
    byte = bytearray()
    if isBcaOpen:
        byte.append(ord('k'))
        byte.append(ord('c'))
        byte.append(ord('f'))
        byte.append(ord('g'))
    else:
        byte.append(ord('k'))
        byte.append(ord('c'))
        byte.append(ord('f'))
        byte.append(ord('a'))
    #crc start address
    if isCrcOpen:
        byte.append(vectorAddress & 0x000000ff)
        byte.append((vectorAddress & 0x0000ff00) >> 8)
        byte.append((vectorAddress & 0x00ff0000) >> 16)
        byte.append((vectorAddress & 0xff000000) >> 24)
    else:
        byte.append(0xff)
        byte.append(0xff)
        byte.append(0xff)
        byte.append(0xff)
    #crc count to be calculated
    byte.append(0x4)
    byte.append(0x00)
    byte.append(0x00)
    byte.append(0x00)
    #create a list to store the first 4 bytes value of APP, then use crc algorithm to calculate the 4 bytes
    appDataArray = range(0, 4)
    with open(binFile, 'rb+') as fileObj:
        for i in range(0, 4):
            data = fileObj.read(int(1))
            appDataArray[i] = (ord(data))
        #value, = struct.unpack('L', data)
        print appDataArray
        crcResult = crc32.ComputeCRC32().calculate(0xffffffff,
                                                   appDataArray[0:4])
        print crcResult
        #crc expected result
        if isCrcRight:
            byte.append(crcResult & 0x000000ff)
            byte.append((crcResult & 0x0000ff00) >> 8)
            byte.append((crcResult & 0x00ff0000) >> 16)
            byte.append((crcResult & 0xff000000) >> 24)
        else:
            byte.append(0xff)
            byte.append(0xff)
            byte.append(0xff)
            byte.append(0xff)
        #get the BCA loaction, then modify BCA & CRC configuration of the app
        fileObj.seek(0x3c0, 0)
        fileObj.write(byte)
        fileObj.close()
    return binFile
コード例 #5
0
 def test_sb_jump_to_entry_point(self, bl):
     # .out and .elf file has entry point while .bin file doesn't have.
     (elfFile, hexFile, binFile) = common_util.get_led_demo_path(bl)
     sb_commandDictionay['writeMemory'].cumulativeWrite = False
     sb_commandDictionay['writeMemory'].data = elfFile
     sb_commandDictionay['writeMemory'].dataType = 'app_out'
     # Generate sb file
     sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '',
                                              'writeMemory',
                                              'jumpEntryPoint')
     # After excuting receive-sb-file the led will blink immediately and blhost returns kStatus_AbortDataPhase.
     status, results = bl.receive_sb_file(sbFilePath)
     assert status == bootloader.status.kStatus_AbortDataPhase
     # Send command to blhost, it will fail
     status, results = bl.get_property(
         bootloader.properties.kPropertyTag_CurrentVersion)
     status != bootloader.status.kStatus_Success
     # Let led blink for some time so that we can see the correct phenomenon.
     time.sleep(3)
コード例 #6
0
    def test_download_encrypted_app_with_encrypted_sb_file(self, bl):
        # Get the led demo that running in the qspi flash
        app_exists, qspiDemo = common_util.get_led_demo_path(
            bl, 'app_srec', running_in_qspi_flash=True)
        if app_exists == False:
            # if not exist the app file, should mark the case as SKIPPED but not FAILED
            print qspiDemo
            pytest.skip("\nDo not find the app demo srec file.")
        else:
            # Get the path of the QCB bin file path
            qcbBinFile = os.path.abspath(
                os.path.join(bl.vectorsDir, 'QSPI', kQspiConfigBlockFile))
            sbCmdDict['otfadDecryption'].qspiDemo = qspiDemo
            # Check if the led demo code is located at 0x68001000
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_START_ADDR = 0x68001000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_END_ADDR = 0x68001FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX0_CTR = "FFFFFFFFFFFFFFFF"

            sbCmdDict[
                'otfadDecryption'].encrypted_type_0 = 'encrypt_appSrecFile'

            sbCmdDict[
                'otfadDecryption'].Key_Encryption_Key = "00f1e2d3c4b5a69788796a5b4c3d2e1f"
            # Check if the keyBlobPointer is 0x1000 in the BCA
            sbCmdDict['otfadDecryption'].kek_location = 0x1000

            # Enable the qspi in bd file
            sbCmdDict['enableQspi'].qspiConfigBlock = qcbBinFile
            sbCmdDict['enableQspi'].qcbLocation = 0x20000000
            # Erase qspi flash in bd file
            sbCmdDict['flashEraseRegion'].startAddress = 0x68000000
            sbCmdDict['flashEraseRegion'].endAddress = 0x68002000

            # Erase the whole flash
            status, results = bl.flash_erase_all()
            assert status == bootloader.status.kStatus_Success

            # Generate encrypted sb file
            sb_file_encryption_key = '000102030405060708090a0b0c0d0e0f'
            sbFilePath = sb_command.generate_sb_file(bl, 'nonZeroKeyEncrypted',
                                                     sb_file_encryption_key,
                                                     'enableQspi',
                                                     'flashEraseRegion',
                                                     'otfadDecryption')

            # Get the sb file IFR key according to the given sb_file_encryption_key
            key1, key2, key3, key4 = sb_command.convert_32bit_key(
                sb_file_encryption_key)

            # Program the key to IFR
            key = [key1, key2, key3, key4]
            for i in range(0, len(key)):
                status, results = bl.flash_program_once(0x30 + i, 4, key[i])
                assert status == bootloader.status.kStatus_Success

            # Reset the target and let it be in secure
            status, results = bl.reset()
            assert status == bootloader.status.kStatus_Success
            time.sleep(2)

            # Check if flash is in secure
            status, results = bl.get_property(
                bootloader.properties.kPropertyTag_FlashSecurityState)
            assert status == bootloader.status.kStatus_Success
            assert results[0] == 1

            # Send the encrypted sb file to target
            status, results = bl.receive_sb_file(sbFilePath)
            assert status == bootloader.status.kStatus_Success

            # Reset the target we can see the led blinking
            status, results = bl.reset()
            assert status == bootloader.status.kStatus_Success
            # Let led blink for some time so that we can see the correct phenomenon.
            time.sleep(3)

            # Now communicate with bootloader, it has no response which means OTFAD decrypts the app successfully
            status, results = bl.get_property(
                bootloader.properties.kPropertyTag_CurrentVersion)
            assert status != bootloader.status.kStatus_Success
コード例 #7
0
    def test_decrypt_four_nonoverlapped_regions(self, bl):
        # Get the led demo that running in the qspi flash
        app_exists, qspiDemo = common_util.get_led_demo_path(
            bl, 'app_srec', running_in_qspi_flash=True)
        if app_exists == False:
            # if not exist the app file, should mark the case as SKIPPED but not FAILED
            print qspiDemo
            pytest.skip("\nDo not find the app demo srec file.")
        else:
            # Get the path of the QCB bin file path
            qcbBinFile = os.path.abspath(
                os.path.join(bl.vectorsDir, 'QSPI', kQspiConfigBlockFile))

            sbCmdDict['otfadDecryption'].qspiDemo = qspiDemo
            # The first keyblob region. App demo is encrypted and decrypted in this region.
            # Check if the app demo code is located at 0x68001000.
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_START_ADDR = 0x68001000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_END_ADDR = 0x68001FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX0_CTR = "FFFFFFFFFFFFFFFF"

            sbCmdDict[
                'otfadDecryption'].encrypted_type_0 = 'encrypt_appSrecFile'

            # The second keyblob region
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_START_ADDR = 0x68002000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_END_ADDR = 0x68002FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX1_CTR = "FFFFFFFFFFFFFFFF"

            sbCmdDict['otfadDecryption'].encrypted_type_1 = 'encrypt_write'
            sbCmdDict[
                'otfadDecryption'].encrypted_data_1 = qcbBinFile  # Here can be any other bin files
            sbCmdDict['otfadDecryption'].data_location_start_1 = sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_START_ADDR
            encrypt_data_size_1 = os.path.getsize(
                sbCmdDict['otfadDecryption'].encrypted_data_1)
            sbCmdDict['otfadDecryption'].data_location_end_1 = sbCmdDict[
                'otfadDecryption'].data_location_start_1 + encrypt_data_size_1

            # The third keyblob region
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_START_ADDR = 0x68003000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_END_ADDR = 0x68003FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX2_CTR = "FFFFFFFFFFFFFFFF"

            sbCmdDict['otfadDecryption'].encrypted_type_2 = 'encrypt_write'
            sbCmdDict[
                'otfadDecryption'].encrypted_data_2 = qcbBinFile  # Here can be any other bin files
            sbCmdDict['otfadDecryption'].data_location_start_2 = sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_START_ADDR
            encrypt_data_size_2 = os.path.getsize(
                sbCmdDict['otfadDecryption'].encrypted_data_2)
            sbCmdDict['otfadDecryption'].data_location_end_2 = sbCmdDict[
                'otfadDecryption'].data_location_start_2 + encrypt_data_size_2

            # The fourth keyblob region
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX3_START_ADDR = 0x68004000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX3_END_ADDR = 0x68004FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX3_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX3_CTR = "FFFFFFFFFFFFFFFF"

            sbCmdDict['otfadDecryption'].encrypted_type_3 = 'encrypt_write'
            sbCmdDict[
                'otfadDecryption'].encrypted_data_3 = qcbBinFile  # Here can be any other bin files
            sbCmdDict['otfadDecryption'].data_location_start_3 = sbCmdDict[
                'otfadDecryption'].OTFAD_CTX3_START_ADDR
            encrypt_data_size_3 = os.path.getsize(
                sbCmdDict['otfadDecryption'].encrypted_data_3)
            sbCmdDict['otfadDecryption'].data_location_end_3 = sbCmdDict[
                'otfadDecryption'].data_location_start_3 + encrypt_data_size_3

            sbCmdDict[
                'otfadDecryption'].Key_Encryption_Key = "5391e2d3c4b5a69788796a5b4c3d2e1f"
            # Check if the keyBlobPointer is 0x1000 in the BCA
            sbCmdDict['otfadDecryption'].kek_location = 0x1000

            # Enable the qspi in bd file
            sbCmdDict['enableQspi'].qspiConfigBlock = qcbBinFile
            sbCmdDict['enableQspi'].qcbLocation = 0x20000000
            # Erase qspi flash in bd file
            sbCmdDict['flashEraseRegion'].startAddress = 0x68000000
            sbCmdDict['flashEraseRegion'].endAddress = 0x68005000

            # Generate encrypted sb file and send the sb file to target
            sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '',
                                                     'enableQspi',
                                                     'flashEraseRegion',
                                                     'otfadDecryption')
            status, results = bl.receive_sb_file(sbFilePath)
            assert status == bootloader.status.kStatus_Success

            # ---------------------------------------------------------------------------------------------------
            # Check if the data in these four independent keyblob regions can be successfully decrypted by OTFAD.
            # ---------------------------------------------------------------------------------------------------
            # 1. Reset the target, the led will blink, which means OTFAD decrypts the first keyblob region data.
            status, results = bl.reset()
            assert status == bootloader.status.kStatus_Success
            time.sleep(3)

            # 2. Communicate with bootloader, it will have no response.
            status, results = bl.get_property(
                bootloader.properties.kPropertyTag_CurrentVersion)
            assert status != bootloader.status.kStatus_Success

            # 3. Use JLink to read data from the other three keyblob regions
            decrypted_data_1 = bl.target.read(
                sbCmdDict['otfadDecryption'].data_location_start_1,
                encrypt_data_size_1)
            decrypted_data_2 = bl.target.read(
                sbCmdDict['otfadDecryption'].data_location_start_2,
                encrypt_data_size_2)
            decrypted_data_3 = bl.target.read(
                sbCmdDict['otfadDecryption'].data_location_start_3,
                encrypt_data_size_3)

            # 4. Compare the decryption data with the pliantext
            with open(qcbBinFile, 'rb') as fileObj:
                plaintext = fileObj.read()
                fileObj.close()
            assert decrypted_data_1 == plaintext
            assert decrypted_data_2 == plaintext
            assert decrypted_data_3 == plaintext
コード例 #8
0
    def test_encrypt_decrypt_overlapped_region(self, bl):
        # Get the led demo that running in the qspi flash
        app_exists, qspiDemo = common_util.get_led_demo_path(
            bl, running_in_qspi_flash=True)
        if app_exists == False:
            # if not exist the app file, should mark the case as SKIPPED but not FAILED
            print qspiDemo
            pytest.skip("\nDo not find the app demo srec file.")
        else:
            # Get the path of the QCB bin file path
            qcbBinFile = os.path.abspath(
                os.path.join(bl.vectorsDir, 'QSPI', kQspiConfigBlockFile))

            sbCmdDict['otfadDecryption'].qspiDemo = qspiDemo
            # Check if the led demo code is located at 0x68001000
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_START_ADDR = 0x68001000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_END_ADDR = 0x68001FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX0_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX0_CTR = "FFFFFFFFFFFFFFFF"
            # Encrypt app demo
            sbCmdDict[
                'otfadDecryption'].encrypted_type_0 = 'encrypt_appSrecFile'

            # The second keyblob region
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_START_ADDR = 0x68002000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_END_ADDR = 0x68002FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX1_CTR = "FFFFFFFFFFFFFFFF"
            # Encrypt data in the overlapped region (0x68002000 ~ 0x68002FFF)
            sbCmdDict['otfadDecryption'].encrypted_type_1 = 'encrypt_write'
            sbCmdDict[
                'otfadDecryption'].encrypted_data_1 = qcbBinFile  # Here can be any other bin files
            sbCmdDict['otfadDecryption'].data_location_start_1 = sbCmdDict[
                'otfadDecryption'].OTFAD_CTX1_START_ADDR
            encrypt_data_size_1 = os.path.getsize(
                sbCmdDict['otfadDecryption'].encrypted_data_1)
            sbCmdDict['otfadDecryption'].data_location_end_1 = sbCmdDict[
                'otfadDecryption'].data_location_start_1 + encrypt_data_size_1

            # The third keyblob region, which is overlapped with the second keyblob region
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_START_ADDR = 0x68002000  # keyblob start address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_END_ADDR = 0x68003FFF  # keyblob end address
            sbCmdDict[
                'otfadDecryption'].OTFAD_CTX2_KEY = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
            sbCmdDict['otfadDecryption'].OTFAD_CTX2_CTR = "FFFFFFFFFFFFFFFF"
            # Encrypt data in the undefined region
            sbCmdDict['otfadDecryption'].encrypted_type_2 = 'encrypt_write'
            sbCmdDict[
                'otfadDecryption'].encrypted_data_2 = qcbBinFile  # Here can be any other bin files
            sbCmdDict[
                'otfadDecryption'].data_location_start_2 = 0x68004000  # undefined keyblob region
            encrypt_data_size_2 = os.path.getsize(
                sbCmdDict['otfadDecryption'].encrypted_data_2)
            sbCmdDict['otfadDecryption'].data_location_end_2 = sbCmdDict[
                'otfadDecryption'].data_location_start_2 + encrypt_data_size_2

            sbCmdDict[
                'otfadDecryption'].Key_Encryption_Key = "5391e2d3c4b5a69788796a5b4c3d2e1f"
            # Check if the keyBlobPointer is 0x1000 in the BCA
            sbCmdDict['otfadDecryption'].kek_location = 0x1000

            # Enable the qspi in bd file
            sbCmdDict['enableQspi'].qspiConfigBlock = qcbBinFile
            sbCmdDict['enableQspi'].qcbLocation = 0x20000000
            # Erase qspi flash in bd file
            sbCmdDict['flashEraseRegion'].startAddress = 0x68000000
            sbCmdDict['flashEraseRegion'].endAddress = 0x68005000

            # Generate encrypted sb file and send the sb file to target
            sbFilePath = sb_command.generate_sb_file(bl, 'unencrypted', '',
                                                     'enableQspi',
                                                     'flashEraseRegion',
                                                     'otfadDecryption')
            status, results = bl.receive_sb_file(sbFilePath)
            assert status == bootloader.status.kStatus_Success

            # ----------------------------------------------------------------------------------------------
            # Check if elftosb.exe encrypts the overlapped region (will encrypt), and
            # check if the elftosb.exe encrypts the undefined region (will not encrypt)
            # ----------------------------------------------------------------------------------------------
            # 1. Get the original data that will be encrypted in the overlapped region
            with open(sbCmdDict['otfadDecryption'].encrypted_data_1,
                      'rb') as fileObj:
                original_data_overlapped = fileObj.read()
                fileObj.close()

            # 2. Get data from the overlapped region after encryption
            binFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin')
            status, results = bl.read_memory(
                sbCmdDict['otfadDecryption'].data_location_start_1,
                encrypt_data_size_1, binFile)
            assert status == bootloader.status.kStatus_Success
            with open(binFile, 'rb') as fileObj:
                encrypted_data_overlapped = fileObj.read()
                fileObj.close()
            # elftosb encrypts the overlapped region, so encrypted_data_overlapped is not equal to original_data_overlapped
            assert encrypted_data_overlapped != original_data_overlapped

            # 3. Get the original data that will be encrypted in the undefined region
            with open(sbCmdDict['otfadDecryption'].encrypted_data_2,
                      'rb') as fileObj:
                original_data_undefined = fileObj.read()
                fileObj.close()

            # 4. Get data from the undefined region after encryption
            binFile = os.path.join(bl.vectorsDir, 'read_data_from_memory.bin')
            status, results = bl.read_memory(
                sbCmdDict['otfadDecryption'].data_location_start_2,
                encrypt_data_size_2, binFile)
            assert status == bootloader.status.kStatus_Success
            with open(binFile, 'rb') as fileObj:
                encrypted_data_undefined = fileObj.read()
                fileObj.close()
            # elftosb does not encrypt the undefined region, so encrypted_data_undefined is equal to original_data_undefined
            assert encrypted_data_undefined == original_data_undefined

            # 5. Reset the target we can see the led blinking. OTFAD starts to decrypt after app running.
            status, results = bl.reset()
            assert status == bootloader.status.kStatus_Success
            # Let led blink for some time so that we can see the correct phenomenon.
            time.sleep(3)

            # 6. Now communicate with bootloader, it has no response which means OTFAD decrypts the app successfully
            status, results = bl.get_property(
                bootloader.properties.kPropertyTag_CurrentVersion)
            assert status != bootloader.status.kStatus_Success

            # 7. Get data from the overlapped region after decryption
            decrypted_data_overlapped = bl.target.read(
                sbCmdDict['otfadDecryption'].data_location_start_1,
                encrypt_data_size_1)
            # OTFAD does not decrypt the overlapped region, so decrypted_data_overlapped is equal to encrypted_data_overlapped
            assert decrypted_data_overlapped == encrypted_data_overlapped

            # 8. Get data from the undefined region after decryption
            decrypted_data_undefined = bl.target.read(
                sbCmdDict['otfadDecryption'].data_location_start_2,
                encrypt_data_size_2)
            # OTFAD does not decrypt the undefined region, so decrypted_data_undefined is equal to encrypted_data_undefined
            assert decrypted_data_undefined == encrypted_data_undefined
コード例 #9
0
def generate_demo(bl):
    elfFile, hexFile, binFile = common_util.get_led_demo_path(bl)
    return binFile