Example #1
0
 def RTxxx_configureBootDevice(self):
     self._RTxxx_prepareForBootDeviceOperation()
     configOptList = []
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor or \
        self.bootDevice == RTxxx_uidef.kBootDevice_QuadspiNor:
         flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel = uivar.getBootDeviceConfiguration(
             uidef.kBootDevice_XspiNor)
         configOptList.extend([flexspiNorOpt0, flexspiNorOpt1])
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         configOptList.extend([flexcommSpiNorOpt0, flexcommSpiNorOpt1])
     else:
         pass
     status = boot.status.kStatus_Success
     for i in range(len(configOptList)):
         if self.RTxxx_isDeviceEnabledToOperate:
             status, results, cmdStr = self.blhost.fillMemory(
                 RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt + 4 * i, 0x4,
                 configOptList[i])
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
     if self.RTxxx_isDeviceEnabledToOperate:
         status, results, cmdStr = self.blhost.configureMemory(
             self.bootDeviceMemId,
             RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
     return True
 def _RTxxx_adjustDestSbAppFilenameForBd(self,
                                         sbType=RTxxx_gendef.kSbFileType_All
                                         ):
     if sbType == RTxxx_gendef.kSbFileType_All:
         srcAppName = os.path.splitext(
             os.path.split(self.srcAppFilename)[1])[0]
         destSbAppPath, destSbAppFile = os.path.split(
             self.destSbAppFilename)
         destSbAppName, destSbAppType = os.path.splitext(destSbAppFile)
         destSbAppName = srcAppName
         if self.secureBootType == RTxxx_uidef.kSecureBootType_PlainUnsigned:
             destSbAppName += '_unsigned'
         if self.secureBootType == RTxxx_uidef.kSecureBootType_PlainCrc:
             destSbAppName += '_crc'
         else:
             pass
         destSbAppName += '_' + self.sbEnableBootDeviceMagic
         if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
             flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel, isFdcbKept = uivar.getBootDeviceConfiguration(
                 self.bootDevice)
             if flexspiNorDeviceModel == 'No':
                 destSbAppName += '_' + self.convertLongIntHexText(
                     str(hex(flexspiNorOpt0))
                 ) + '_' + self.convertLongIntHexText(
                     str(hex(flexspiNorOpt1)))
             else:
                 destSbAppName += '_' + flexspiNorDeviceModel
         elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
             flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
                 self.bootDevice)
             destSbAppName += '_' + self.convertLongIntHexText(
                 str(hex(flexcommSpiNorOpt0))
             ) + '_' + self.convertLongIntHexText(
                 str(hex(flexcommSpiNorOpt1)))
         elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd:
             pass
         elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
             pass
         else:
             pass
         self.destSbAppFilename = os.path.join(
             destSbAppPath, destSbAppName + destSbAppType)
     elif sbType == RTxxx_gendef.kSbFileType_Flash:
         pass
     elif sbType == RTxxx_gendef.kSbFileType_Otp:
         pass
     else:
         pass
Example #3
0
 def flashBootableImage ( self ):
     self._prepareForBootDeviceOperation()
     imageLen = os.path.getsize(self.destAppFilename)
     if self.bootDevice == uidef.kBootDevice_SemcNand:
         semcNandOpt, semcNandFcbOpt, imageInfo = uivar.getBootDeviceConfiguration(self.bootDevice)
         memEraseLen = misc.align_up(imageLen, self.semcNandBlockSize)
         for i in range(self.semcNandImageCopies):
             imageLoadAddr = self.bootDeviceMemBase + (imageInfo[i] >> 16) * self.semcNandBlockSize
             status, results, cmdStr = self.blhost.flashEraseRegion(imageLoadAddr, memEraseLen, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
             status, results, cmdStr = self.blhost.writeMemory(imageLoadAddr, self.destAppFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
     elif self.bootDevice == uidef.kBootDevice_FlexspiNor:
         if not self.isFlexspiNorErasedForImage:
             self._eraseFlexspiNorForImageLoading()
             if self.secureBootType == uidef.kSecureBootType_Development or \
                self.secureBootType == uidef.kSecureBootType_HabAuth or \
                (self.secureBootType == uidef.kSecureBootType_BeeCrypto and self.keyStorageRegion == uidef.kKeyStorageRegion_FlexibleUserKeys):
                 self._programFlexspiNorConfigBlock()
         if self.secureBootType == uidef.kSecureBootType_BeeCrypto and self.keyStorageRegion == uidef.kKeyStorageRegion_FlexibleUserKeys:
             self._genDestEncAppFileWithoutCfgBlock()
             imageLoadAddr = self.bootDeviceMemBase + rundef.kFlexspiNorCfgInfo_Length
             status, results, cmdStr = self.blhost.writeMemory(imageLoadAddr, self.destEncAppNoCfgBlockFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
         else:
             imageLoadAddr = self.bootDeviceMemBase + gendef.kIvtOffset_NOR
             status, results, cmdStr = self.blhost.writeMemory(imageLoadAddr, self.destAppNoPaddingFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
         self.isFlexspiNorErasedForImage = False
     else:
         pass
 def _getDcdInfo(self):
     dcdCtrlDict, dcdSettingsDict = uivar.getBootDeviceConfiguration(
         RTyyyy_uidef.kBootDevice_Dcd)
     if dcdCtrlDict['isDcdEnabled']:
         self.destAppDcdLength = os.path.getsize(self.dcdBinFilename)
     else:
         self.destAppDcdLength = 0
 def _getFlexcommSpiNorDeviceInfo(self):
     pageByteSize = 0
     sectorByteSize = 0
     totalByteSize = 0
     flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
         self.bootDevice)
     val = (flexcommSpiNorOpt0 & 0x0000000F) >> 0
     if val <= 2:
         pageByteSize = int(math.pow(2, val + 8))
     else:
         pageByteSize = int(math.pow(2, val + 2))
     val = (flexcommSpiNorOpt0 & 0x000000F0) >> 4
     if val <= 1:
         sectorByteSize = int(math.pow(2, val + 12))
     else:
         sectorByteSize = int(math.pow(2, val + 13))
     val = (flexcommSpiNorOpt0 & 0x00000F00) >> 8
     if val <= 11:
         totalByteSize = int(math.pow(2, val + 19))
     else:
         totalByteSize = int(math.pow(2, val + 3))
     self.printDeviceStatus("Page Size   = " +
                            self.showAsOptimalMemoryUnit(pageByteSize))
     self.printDeviceStatus("Sector Size = " +
                            self.showAsOptimalMemoryUnit(sectorByteSize))
     self.printDeviceStatus("Total Size  = " +
                            self.showAsOptimalMemoryUnit(totalByteSize))
     self.comMemWriteUnit = pageByteSize
     self.comMemEraseUnit = sectorByteSize
     self.comMemReadUnit = pageByteSize
     return True
 def RTxxx_burnBootDeviceOtps( self ):
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
         pass
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         setFlexcommSpiCfg = 0
         flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(self.bootDevice)
         # Set Spi Index
         spiIndex = ((flexcommSpiNorOpt0 & 0x00F00000) >> 20)
         setFlexcommSpiCfg = (setFlexcommSpiCfg & (~self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']) | (spiIndex << self.tgt.otpmapDefnDict['kOtpShift_RedundantSpiPort']))
         getFlexcommSpiCfg = self._getMcuDeviceFlexcommSpiCfg()
         if getFlexcommSpiCfg != None:
             destFlexcommSpiCfg = setFlexcommSpiCfg | getFlexcommSpiCfg
             if (destFlexcommSpiCfg & self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']) != setFlexcommSpiCfg:
                 self.popupMsgBox(uilang.kMsgLanguageContentDict['burnOtpError_bootCfg0HasBeenBurned'][self.languageIndex])
                 return False
             else:
                 # We do ^ operation here, because only bit 1 in fuse word will take affect, bit 0 will be bypassed by OCOTP controller
                 destFlexcommSpiCfg = destFlexcommSpiCfg ^ getFlexcommSpiCfg
                 burnResult = self.RTxxx_burnMcuDeviceOtpByBlhost(self.tgt.otpmapIndexDict['kOtpLocation_FlexcommSpiCfg'], destFlexcommSpiCfg)
                 if not burnResult:
                     self.popupMsgBox(uilang.kMsgLanguageContentDict['burnOtpError_failToBurnBootCfg0'][self.languageIndex])
                     return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd:
         pass
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
         pass
     else:
         pass
     return True
Example #7
0
 def extractFdcbDataFromSrcApp(self, initialLoadAppBytes):
     flexspiNorOpt0, flexspiNorOpt1, flexspiDeviceModel, isFdcbKept = uivar.getBootDeviceConfiguration(
         uidef.kBootDevice_XspiNor)
     self.isFdcbFromSrcApp = isFdcbKept
     if self.isFdcbFromSrcApp:
         with open(self.fdcbBinFilename, 'wb') as fileObj:
             fileObj.write(initialLoadAppBytes[0:memdef.kMemBlockSize_FDCB])
             fileObj.close()
Example #8
0
 def configureBootDevice ( self ):
     self._prepareForBootDeviceOperation()
     if self.bootDevice == uidef.kBootDevice_SemcNand:
         semcNandOpt, semcNandFcbOpt, semcNandImageInfo = uivar.getBootDeviceConfiguration(self.bootDevice)
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadCommOpt, 0x4, semcNandOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadCommOpt + 4, 0x4, semcNandFcbOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         for i in range(len(semcNandImageInfo)):
             if semcNandImageInfo[i] != None:
                 status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadCommOpt + 8 + i * 4, 0x4, semcNandImageInfo[i])
                 self.printLog(cmdStr)
                 if status != boot.status.kStatus_Success:
                     return False
             else:
                 break
         status, results, cmdStr = self.blhost.configureMemory(self.bootDeviceMemId, rundef.kRamFreeSpaceStart_LoadCommOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
     elif self.bootDevice == uidef.kBootDevice_FlexspiNor:
         flexspiNorOpt0, flexspiNorOpt1 = uivar.getBootDeviceConfiguration(self.bootDevice)
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadCommOpt, 0x4, flexspiNorOpt0)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadCommOpt + 4, 0x4, flexspiNorOpt1)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.configureMemory(self.bootDeviceMemId, rundef.kRamFreeSpaceStart_LoadCommOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         self._eraseFlexspiNorForConfigBlockLoading()
         self._programFlexspiNorConfigBlock()
     else:
         pass
     return True
 def _RTxxx_updateSbAppBdBatfileContent(self,
                                        sbType=RTxxx_gendef.kSbFileType_All
                                        ):
     destAppFilename = None
     sbAppBdFilename = None
     destSbAppFilename = None
     sbAppBdBatFilename = None
     self._RTxxx_adjustDestSbAppFilenameForBd(sbType)
     if sbType == RTxxx_gendef.kSbFileType_All:
         sbAppBdFilename = self.sbAppBdFilename
         destSbAppFilename = self.destSbAppFilename
         sbAppBdBatFilename = self.sbAppBdBatFilename
     elif sbType == RTxxx_gendef.kSbFileType_Flash:
         pass
     elif sbType == RTxxx_gendef.kSbFileType_Otp:
         pass
     else:
         pass
     if sbType == RTxxx_gendef.kSbFileType_All or sbType == RTxxx_gendef.kSbFileType_Flash:
         if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
             destAppFilename = self.destAppFilename
         elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
             pass
         elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd or \
              self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
             pass
         destAppFilename = ' ' + "\"" + destAppFilename + "\""
     else:
         destAppFilename = ''
     familyStr = ''
     if self.mcuDevice == uidef.kMcuDevice_iMXRT500 or \
        self.mcuDevice == uidef.kMcuDevice_iMXRT500S:
         familyStr = RTxxx_gendef.kMcuDeviceFamily_RT500
     elif self.mcuDevice == uidef.kMcuDevice_iMXRT600 or \
          self.mcuDevice == uidef.kMcuDevice_iMXRT600S:
         familyStr = RTxxx_gendef.kMcuDeviceFamily_RT600
     else:
         pass
     sbBatContent = "\"" + self.elftosbPath + "\""
     sbBatContent += " -d -V -f " + familyStr + " -c " + "\"" + sbAppBdFilename + "\"" + ' -o ' + "\"" + destSbAppFilename + "\"" + destAppFilename
     if sbType == RTxxx_gendef.kSbFileType_All or sbType == RTxxx_gendef.kSbFileType_Flash:
         if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
             flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel, isFdcbKept = uivar.getBootDeviceConfiguration(
                 uidef.kBootDevice_XspiNor)
             if flexspiNorDeviceModel == uidef.kFlexspiNorDevice_FDCB:
                 sbBatContent += ' ' + "\"" + self.cfgFdcbBinFilename + "\""
     with open(sbAppBdBatFilename, 'wb') as fileObj:
         fileObj.write(sbBatContent)
         fileObj.close()
Example #10
0
 def RTxxx_burnBootDeviceOtps(self):
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
         pass
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         setFlexcommSpiCfg = 0
         flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         # Set Spi Index
         spiIndex = ((flexcommSpiNorOpt0 & 0x00F00000) >> 20)
         setFlexcommSpiCfg = (
             setFlexcommSpiCfg &
             (~self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']) |
             (spiIndex <<
              self.tgt.otpmapDefnDict['kOtpShift_RedundantSpiPort']))
         getFlexcommSpiCfg = self._getMcuDeviceFlexcommSpiCfg()
         if getFlexcommSpiCfg != None:
             getFlexcommSpiCfg = getFlexcommSpiCfg | setFlexcommSpiCfg
             if (getFlexcommSpiCfg
                     & self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']
                 ) != setFlexcommSpiCfg:
                 self.popupMsgBox(uilang.kMsgLanguageContentDict[
                     'burnOtpError_bootCfg0HasBeenBurned'][
                         self.languageIndex])
                 return False
             else:
                 burnResult = self.RTxxx_burnMcuDeviceOtpByBlhost(
                     self.tgt.
                     otpmapIndexDict['kOtpLocation_FlexcommSpiCfg'],
                     getFlexcommSpiCfg)
                 if not burnResult:
                     self.popupMsgBox(uilang.kMsgLanguageContentDict[
                         'burnOtpError_failToBurnBootCfg0'][
                             self.languageIndex])
                     return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd:
         pass
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
         pass
     else:
         pass
     return True
 def RTxxx_burnBootDeviceOtps(self):
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor:
         if self.tgt.hasFlexspiNorDualImageBoot:
             flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel, isFdcbKept, flexspiNorDualImageInfoList = uivar.getBootDeviceConfiguration(
                 self.bootDevice)
             flexspiNorImage1Offset = (flexspiNorDualImageInfoList[2]
                                       & 0xFFFF)
             flexspiNorImage1Size = ((flexspiNorDualImageInfoList[2] >> 16)
                                     & 0xFFFF)
             if flexspiNorImage1Offset != 0:
                 if not self._burnCommonMcuOtpBits(
                         'kOtpLocation_FlexspiNorDualImageBootCfg3',
                         'kOtpMask_FlexspiNorImage1Offset',
                         'kOtpShift_FlexspiNorImage1Offset',
                         flexspiNorImage1Offset):
                     self.popupMsgBox(uilang.kMsgLanguageContentDict[
                         'burnOtpError_failToBurnDualImageBootCfg3'][
                             self.languageIndex])
                     return False
                 if not self._burnCommonMcuOtpBits(
                         'kOtpLocation_FlexspiNorDualImageBootCfg2',
                         'kOtpMask_FlexspiNorImage1Size',
                         'kOtpShift_FlexspiNorImage1Size',
                         flexspiNorImage1Size):
                     self.popupMsgBox(uilang.kMsgLanguageContentDict[
                         'burnOtpError_failToBurnDualImageBootCfg2'][
                             self.languageIndex])
                     return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         setFlexcommSpiCfg = 0
         flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         # Set Spi Index
         spiIndex = ((flexcommSpiNorOpt0 & 0x00F00000) >> 20)
         setFlexcommSpiCfg = (
             setFlexcommSpiCfg &
             (~self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']) |
             (spiIndex <<
              self.tgt.otpmapDefnDict['kOtpShift_RedundantSpiPort']))
         getFlexcommSpiCfg = self._getMcuDeviceFlexcommSpiCfg()
         if getFlexcommSpiCfg != None:
             destFlexcommSpiCfg = setFlexcommSpiCfg | getFlexcommSpiCfg
             if (destFlexcommSpiCfg
                     & self.tgt.otpmapDefnDict['kOtpMask_RedundantSpiPort']
                 ) != setFlexcommSpiCfg:
                 self.popupMsgBox(uilang.kMsgLanguageContentDict[
                     'burnOtpError_bootCfg0HasBeenBurned'][
                         self.languageIndex])
                 return False
             else:
                 # We do ^ operation here, because only bit 1 in fuse word will take affect, bit 0 will be bypassed by OCOTP controller
                 destFlexcommSpiCfg = destFlexcommSpiCfg ^ getFlexcommSpiCfg
                 burnResult = self.RTxxx_burnMcuDeviceOtpByBlhost(
                     self.tgt.
                     otpmapIndexDict['kOtpLocation_FlexcommSpiCfg'],
                     destFlexcommSpiCfg)
                 if not burnResult:
                     self.popupMsgBox(uilang.kMsgLanguageContentDict[
                         'burnOtpError_failToBurnBootCfg0'][
                             self.languageIndex])
                     return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd:
         pass
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
         pass
     else:
         pass
     return True
 def RTxxx_flashBootableImage(self):
     self._RTxxx_prepareForBootDeviceOperation()
     imageLen = os.path.getsize(self.destAppFilename)
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor or \
        self.bootDevice == RTxxx_uidef.kBootDevice_QuadspiNor:
         image0Size = 0
         if not self.isXspiNorErasedForImage:
             if not self._eraseXspiNorForImageLoading():
                 return False
             if self.secureBootType == RTxxx_uidef.kSecureBootType_PlainUnsigned or \
                self.secureBootType == RTxxx_uidef.kSecureBootType_PlainCrc:
                 if not self._programXspiNorConfigBlock():
                     self.isXspiNorErasedForImage = False
                     self.isFdcbFromSrcApp = False
                     return False
         flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel, isFdcbKept, flexspiNorDualImageInfoList = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         if self.tgt.hasFlexspiNorDualImageBoot and (
             (flexspiNorDualImageInfoList[2] & 0xFFFF) != 0):
             if flexspiNorDualImageInfoList[0] == 0xffffffff:
                 self.flexspiNorImage0Version = flexspiNorDualImageInfoList[
                     0]
             else:
                 self.flexspiNorImage0Version = flexspiNorDualImageInfoList[
                     0] + ((flexspiNorDualImageInfoList[0] ^ 0xFFFF) << 16)
         if self.flexspiNorImage0Version != None and self.flexspiNorImage0Version != rundef.kFlexspiNorContent_Blank32:
             versionLoadAddr = self.bootDeviceMemBase + gendef.kImgVerOffset_NOR
             if self.isSbFileEnabledToGen:
                 self._RTxxx_addFlashActionIntoSbAppBdContent(
                     "    load " + self.convertLongIntHexText(
                         str(hex(self.flexspiNorImage0Version))) + " > " +
                     self.convertLongIntHexText(str(hex(versionLoadAddr))) +
                     ";\n")
                 status = boot.status.kStatus_Success
             else:
                 status, results, cmdStr = self.blhost.fillMemory(
                     versionLoadAddr, 0x4, self.flexspiNorImage0Version)
                 self.printLog(cmdStr)
         imageLoadAddr = self.bootDeviceMemBase + RTxxx_gendef.kBootImageOffset_NOR_SD_EEPROM
         if self.isSbFileEnabledToGen:
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    load " + self.sbAccessBootDeviceMagic +
                 " myBinFile > " +
                 self.convertLongIntHexText(str(hex(imageLoadAddr))) +
                 ";\n")
             status = boot.status.kStatus_Success
         else:
             status, results, cmdStr = self.blhost.writeMemory(
                 imageLoadAddr, self.destAppFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
         image0Size = imageLoadAddr - self.bootDeviceMemBase + os.path.getsize(
             self.destAppFilename)
         self.isXspiNorErasedForImage = False
         self.isFdcbFromSrcApp = False
         if status != boot.status.kStatus_Success:
             return False
         else:
             # Check if dual image boot is enabled
             if self.tgt.hasFlexspiNorDualImageBoot and (
                 (flexspiNorDualImageInfoList[2] & 0xFFFF) != 0):
                 image1Start = self.bootDeviceMemBase + (
                     flexspiNorDualImageInfoList[2] & 0xFFFF) * 256 * 1024
                 image1Size = image0Size
                 if flexspiNorDualImageInfoList[1] == 0xffffffff:
                     self.flexspiNorImage1Version = flexspiNorDualImageInfoList[
                         1]
                 else:
                     self.flexspiNorImage1Version = flexspiNorDualImageInfoList[
                         1] + ((flexspiNorDualImageInfoList[1] ^ 0xFFFF) <<
                               16)
                 if not self.flash2ndBootableImageIntoFlexspiNor(
                         image1Start, image1Size,
                         self.flexspiNorImage1Version,
                         self.flexspiNorImage0Version):
                     return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         memEraseLen = misc.align_up(imageLen, self.comMemEraseUnit)
         imageLoadAddr = self.bootDeviceMemBase + RTxxx_gendef.kBootImageOffset_NOR_SD_EEPROM
         if self.isSbFileEnabledToGen:
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    erase " + self.sbAccessBootDeviceMagic + " " +
                 self.convertLongIntHexText(str(hex(imageLoadAddr))) +
                 ".." + self.convertLongIntHexText(
                     str(hex(imageLoadAddr + memEraseLen))) + ";\n")
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    load " + self.sbAccessBootDeviceMagic +
                 " myBinFile > " +
                 self.convertLongIntHexText(str(hex(imageLoadAddr))) +
                 ";\n")
         else:
             status, results, cmdStr = self.blhost.flashEraseRegion(
                 imageLoadAddr, memEraseLen, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
             status, results, cmdStr = self.blhost.writeMemory(
                 imageLoadAddr, self.destAppFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd or \
          self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
         memEraseLen = misc.align_up(imageLen, self.comMemEraseUnit)
         imageLoadAddr = self.bootDeviceMemBase + RTxxx_gendef.kBootImageOffset_NOR_SD_EEPROM
         if self.isSbFileEnabledToGen:
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    erase " + self.sbAccessBootDeviceMagic + " " +
                 self.convertLongIntHexText(str(hex(imageLoadAddr))) +
                 ".." + self.convertLongIntHexText(
                     str(hex(imageLoadAddr + memEraseLen))) + ";\n")
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    load " + self.sbAccessBootDeviceMagic +
                 " myBinFile > " +
                 self.convertLongIntHexText(str(hex(imageLoadAddr))) +
                 ";\n")
         else:
             status, results, cmdStr = self.blhost.flashEraseRegion(
                 imageLoadAddr, memEraseLen, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
             status, results, cmdStr = self.blhost.writeMemory(
                 imageLoadAddr, self.destAppFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
     else:
         pass
     if self.isConvertedAppUsed:
         try:
             os.remove(self.srcAppFilename)
         except:
             pass
         self.isConvertedAppUsed = False
     return True
 def RTxxx_configureBootDevice(self):
     self._RTxxx_prepareForBootDeviceOperation()
     flexspiNorDeviceModel = None
     configOptList = []
     if self.bootDevice == RTxxx_uidef.kBootDevice_FlexspiNor or \
        self.bootDevice == RTxxx_uidef.kBootDevice_QuadspiNor:
         flexspiNorOpt0, flexspiNorOpt1, flexspiNorDeviceModel, isFdcbKept, flexspiNorDualImageInfoList = uivar.getBootDeviceConfiguration(
             uidef.kBootDevice_XspiNor)
         configOptList.extend([flexspiNorOpt0, flexspiNorOpt1])
     elif self.bootDevice == RTxxx_uidef.kBootDevice_FlexcommSpiNor:
         flexcommSpiNorOpt0, flexcommSpiNorOpt1 = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         configOptList.extend([flexcommSpiNorOpt0, flexcommSpiNorOpt1])
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcSd:
         usdhcSdOpt = uivar.getBootDeviceConfiguration(self.bootDevice)
         configOptList.extend([usdhcSdOpt])
     elif self.bootDevice == RTxxx_uidef.kBootDevice_UsdhcMmc:
         usdhcMmcOpt0, usdhcMmcOpt1 = uivar.getBootDeviceConfiguration(
             self.bootDevice)
         configOptList.extend([usdhcMmcOpt0, usdhcMmcOpt1])
     else:
         pass
     status = boot.status.kStatus_Success
     if flexspiNorDeviceModel == uidef.kFlexspiNorDevice_FDCB:
         if self.RTxxx_isDeviceEnabledToOperate:
             status, results, cmdStr = self.blhost.writeMemory(
                 RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt,
                 self.cfgFdcbBinFilename, self.bootDeviceMemId)
             self.printLog(cmdStr)
         if self.isSbFileEnabledToGen:
             self._RTxxx_addFlashActionIntoSbAppBdContent(
                 "    load " + self.sbAccessBootDeviceMagic +
                 " cfgFdcbBinFile > " + self.convertLongIntHexText(
                     str(hex(RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt)))
                 + ";\n")
         if status != boot.status.kStatus_Success:
             return False
     else:
         for i in range(len(configOptList)):
             if self.RTxxx_isDeviceEnabledToOperate:
                 status, results, cmdStr = self.blhost.fillMemory(
                     RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt + 4 * i,
                     0x4, configOptList[i])
                 self.printLog(cmdStr)
             if self.isSbFileEnabledToGen:
                 self._RTxxx_addFlashActionIntoSbAppBdContent(
                     "    load " + self.convertLongIntHexText(
                         str(hex(configOptList[i]))) + " > " +
                     self.convertLongIntHexText(
                         str(
                             hex(RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt
                                 + 4 * i))) + ";\n")
             if status != boot.status.kStatus_Success:
                 return False
     if self.RTxxx_isDeviceEnabledToOperate:
         status, results, cmdStr = self.blhost.configureMemory(
             self.bootDeviceMemId,
             RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt)
         self.printLog(cmdStr)
     if self.isSbFileEnabledToGen:
         self._RTxxx_addFlashActionIntoSbAppBdContent(
             "    enable " + self.sbEnableBootDeviceMagic + " " +
             self.convertLongIntHexText(
                 str(hex(RTxxx_rundef.kRamFreeSpaceStart_LoadCommOpt))) +
             ";\n")
     if status != boot.status.kStatus_Success:
         return False
     return True
    def RTyyyy_readProgrammedMemoryAndShow(self):
        if not os.path.isfile(self.destAppFilename):
            self.popupMsgBox(
                uilang.kMsgLanguageContentDict['operImgError_hasnotProgImage'][
                    self.languageIndex])
            return
        self.clearMem()
        self._getInfoFromIvt()
        self._getDcdInfo()

        imageMemBase = 0
        readoutMemLen = 0
        imageFileLen = os.path.getsize(self.destAppFilename)
        if self.bootDevice == RTyyyy_uidef.kBootDevice_SemcNand:
            semcNandOpt, semcNandFcbOpt, semcNandImageInfoList = uivar.getBootDeviceConfiguration(
                self.bootDevice)
            status, dbbtAddr = self._showSemcNandFcb()
            if status:
                self._showSemcNandDbbt(dbbtAddr)
            # Only Readout first image
            imageMemBase = self.bootDeviceMemBase + (
                semcNandImageInfoList[0] >> 16) * self.semcNandBlockSize
        elif self.bootDevice == RTyyyy_uidef.kBootDevice_FlexspiNor or \
             self.bootDevice == RTyyyy_uidef.kBootDevice_SemcNor or \
             self.bootDevice == RTyyyy_uidef.kBootDevice_LpspiNor:
            imageMemBase = self.bootDeviceMemBase
        elif self.bootDevice == RTyyyy_uidef.kBootDevice_UsdhcSd or \
             self.bootDevice == RTyyyy_uidef.kBootDevice_UsdhcMmc:
            self._showUsdhcSdMmcMbrdpt()
            imageMemBase = self.bootDeviceMemBase
        else:
            pass
        if self.habDekDataOffset != None and (
                self.habDekDataOffset + RTyyyy_memdef.kMemBlockSize_HabKeyBlob
                > imageFileLen):
            readoutMemLen += self.habDekDataOffset + RTyyyy_memdef.kMemBlockSize_HabKeyBlob
        else:
            readoutMemLen += imageFileLen

        memFilename = 'bootableImageFromBootDevice.dat'
        memFilepath = os.path.join(self.blhostVectorsDir, memFilename)
        status, results, cmdStr = self.blhost.readMemory(
            imageMemBase, readoutMemLen, memFilename, self.bootDeviceMemId)
        self.printLog(cmdStr)
        if status != boot.status.kStatus_Success:
            return False

        readoutMemLen = os.path.getsize(memFilepath)
        memLeft = readoutMemLen
        addr = imageMemBase
        with open(memFilepath, 'rb') as fileObj:
            while memLeft > 0:
                contentToShow, memContent = self.getOneLineContentToShow(
                    addr, memLeft, fileObj)
                memLeft -= len(memContent)
                addr += len(memContent)
                if (self.isXipableDevice and
                        addr <= imageMemBase + self.tgt.xspiNorCfgInfoOffset):
                    if self.secureBootType == RTyyyy_uidef.kSecureBootType_OtfadCrypto:
                        keyBlobStart = imageMemBase + RTyyyy_memdef.kMemBlockOffset_HwCryptoKeyBlob
                        if addr > keyBlobStart and addr <= keyBlobStart + RTyyyy_memdef.kMemBlockSize_HwCryptoKeyBlob:
                            if self.needToShowHwCryptoKeyBlobIntr:
                                self.printMem(
                                    '-----------------------------OTFAD DEK KeyBlob----------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_HwCryptoKeyBlob
                                )
                                self.needToShowHwCryptoKeyBlobIntr = False
                            self.printMem(
                                contentToShow,
                                RTyyyy_uidef.kMemBlockColor_HwCryptoKeyBlob)
                        else:
                            self.printMem(contentToShow)
                    else:
                        self.printMem(contentToShow)
                elif (self.isXipableDevice and
                      addr <= imageMemBase + self.tgt.xspiNorCfgInfoOffset +
                      RTyyyy_memdef.kMemBlockSize_FDCB) or (
                          addr <=
                          imageMemBase + RTyyyy_memdef.kMemBlockSize_FDCB):
                    if not self.isSdmmcCard:
                        if self.needToShowCfgIntr:
                            self.printMem(
                                '------------------------------------FDCB----------------------------------------------',
                                RTyyyy_uidef.kMemBlockColor_FDCB)
                            self.needToShowCfgIntr = False
                        self.printMem(contentToShow,
                                      RTyyyy_uidef.kMemBlockColor_FDCB)
                    else:
                        if addr >= self.bootDeviceMemBase + RTyyyy_memdef.kMemBlockSize_MBRDPT:
                            self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppIvtOffset:
                    if self.secureBootType == RTyyyy_uidef.kSecureBootType_BeeCrypto:
                        ekib0Start = imageMemBase + RTyyyy_memdef.kMemBlockOffset_EKIB0
                        eprdb0Start = imageMemBase + RTyyyy_memdef.kMemBlockOffset_EPRDB0
                        ekib1Start = imageMemBase + RTyyyy_memdef.kMemBlockOffset_EKIB1
                        eprdb1Start = imageMemBase + RTyyyy_memdef.kMemBlockOffset_EPRDB1
                        if addr > ekib0Start and addr <= ekib0Start + RTyyyy_memdef.kMemBlockSize_EKIB:
                            if self.needToShowEkib0Intr:
                                self.printMem(
                                    '-----------------------------------EKIB0----------------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_EKIB)
                                self.needToShowEkib0Intr = False
                            self.printMem(contentToShow,
                                          RTyyyy_uidef.kMemBlockColor_EKIB)
                        elif addr > eprdb0Start and addr <= eprdb0Start + RTyyyy_memdef.kMemBlockSize_EPRDB:
                            if self.needToShowEprdb0Intr:
                                self.printMem(
                                    '-----------------------------------EPRDB0---------------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_EPRDB)
                                self.needToShowEprdb0Intr = False
                            self.printMem(contentToShow,
                                          RTyyyy_uidef.kMemBlockColor_EPRDB)
                        elif addr > ekib1Start and addr <= ekib1Start + RTyyyy_memdef.kMemBlockSize_EKIB:
                            if self.needToShowEkib1Intr:
                                self.printMem(
                                    '-----------------------------------EKIB1----------------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_EKIB)
                                self.needToShowEkib1Intr = False
                            self.printMem(contentToShow,
                                          RTyyyy_uidef.kMemBlockColor_EKIB)
                        elif addr > eprdb1Start and addr <= eprdb1Start + RTyyyy_memdef.kMemBlockSize_EPRDB:
                            if self.needToShowEprdb1Intr:
                                self.printMem(
                                    '-----------------------------------EPRDB1---------------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_EPRDB)
                                self.needToShowEprdb1Intr = False
                            self.printMem(contentToShow,
                                          RTyyyy_uidef.kMemBlockColor_EPRDB)
                        else:
                            self.printMem(contentToShow)
                    else:
                        self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppIvtOffset + RTyyyy_memdef.kMemBlockSize_IVT:
                    if self.needToShowIvtIntr:
                        self.printMem(
                            '------------------------------------IVT-----------------------------------------------',
                            RTyyyy_uidef.kMemBlockColor_IVT)
                        self.needToShowIvtIntr = False
                    self.printMem(contentToShow,
                                  RTyyyy_uidef.kMemBlockColor_IVT)
                elif addr <= imageMemBase + self.destAppIvtOffset + RTyyyy_memdef.kMemBlockSize_IVT + RTyyyy_memdef.kMemBlockSize_BootData:
                    if self.needToShowBootDataIntr:
                        self.printMem(
                            '---------------------------------Boot Data--------------------------------------------',
                            RTyyyy_uidef.kMemBlockColor_BootData)
                        self.needToShowBootDataIntr = False
                    self.printMem(contentToShow,
                                  RTyyyy_uidef.kMemBlockColor_BootData)
                elif addr <= imageMemBase + self.destAppIvtOffset + RTyyyy_memdef.kMemBlockOffsetToIvt_DCD:
                    self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppIvtOffset + RTyyyy_memdef.kMemBlockOffsetToIvt_DCD + self.destAppDcdLength:
                    if self.needToShowDcdIntr:
                        self.printMem(
                            '------------------------------------DCD-----------------------------------------------',
                            RTyyyy_uidef.kMemBlockColor_DCD)
                        self.needToShowDcdIntr = False
                    self.printMem(contentToShow,
                                  RTyyyy_uidef.kMemBlockColor_DCD)
                elif addr <= imageMemBase + self.destAppVectorOffset:
                    self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppVectorOffset + self.destAppBinaryBytes:
                    if self.needToShowImageIntr:
                        self.printMem(
                            '-----------------------------------Image----------------------------------------------',
                            RTyyyy_uidef.kMemBlockColor_Image)
                        self.needToShowImageIntr = False
                    self.printMem(contentToShow,
                                  RTyyyy_uidef.kMemBlockColor_Image)
                else:
                    hasShowed = False
                    if self.secureBootType == RTyyyy_uidef.kSecureBootType_HabAuth or self.secureBootType == RTyyyy_uidef.kSecureBootType_HabCrypto or \
                       ((self.secureBootType in RTyyyy_uidef.kSecureBootType_HwCrypto) and self.isCertEnabledForHwCrypto):
                        csfStart = imageMemBase + (
                            self.destAppCsfAddress - self.destAppVectorAddress
                        ) + self.destAppInitialLoadSize
                        if addr > csfStart and addr <= csfStart + RTyyyy_memdef.kMemBlockSize_CSF:
                            if self.needToShowCsfIntr:
                                self.printMem(
                                    '------------------------------------CSF-----------------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_CSF)
                                self.needToShowCsfIntr = False
                            self.printMem(contentToShow,
                                          RTyyyy_uidef.kMemBlockColor_CSF)
                            hasShowed = True
                    if self.secureBootType == RTyyyy_uidef.kSecureBootType_HabCrypto and self.habDekDataOffset != None:
                        keyBlobStart = imageMemBase + (
                            self.destAppVectorOffset -
                            self.destAppInitialLoadSize
                        ) + self.habDekDataOffset
                        if addr > keyBlobStart and addr <= keyBlobStart + RTyyyy_memdef.kMemBlockSize_HabKeyBlob:
                            if self.needToShowHabKeyBlobIntr:
                                self.printMem(
                                    '------------------------------HAB DEK KeyBlob-----------------------------------------',
                                    RTyyyy_uidef.kMemBlockColor_HabKeyBlob)
                                self.needToShowHabKeyBlobIntr = False
                            self.printMem(
                                contentToShow,
                                RTyyyy_uidef.kMemBlockColor_HabKeyBlob)
                            hasShowed = True
                    if not hasShowed:
                        if not self.isSdmmcCard:
                            self.printMem(contentToShow)
                        else:
                            if addr >= self.bootDeviceMemBase + RTyyyy_memdef.kMemBlockSize_MBRDPT:
                                self.printMem(contentToShow)
            fileObj.close()
        self._RTyyyy_initShowIntr()
        self.tryToSaveImageDataFile(memFilepath)
Example #15
0
 def flashHabDekToGenerateKeyBlob ( self ):
     if os.path.isfile(self.habDekFilename) and self.habDekDataOffset != None:
         self._prepareForBootDeviceOperation()
         imageLen = os.path.getsize(self.destAppFilename)
         imageCopies = 0x1
         eraseUnit = 0x0
         if self.bootDevice == uidef.kBootDevice_SemcNand:
             imageCopies = self.semcNandImageCopies
             eraseUnit = self.semcNandBlockSize
         elif self.bootDevice == uidef.kBootDevice_FlexspiNor:
             eraseUnit = self.flexspiNorSectorSize
         else:
             pass
         # Construct KeyBlob Option
         #---------------------------------------------------------------------------
         # bit [31:28] tag, fixed to 0x0b
         # bit [27:24] type, 0 - Update KeyBlob context, 1 Program Keyblob to SPI NAND
         # bit [23:20] keyblob option block size, must equal to 3 if type =0,
         #             reserved if type = 1
         # bit [19:08] Reserved
         # bit [07:04] DEK size, 0-128bit 1-192bit 2-256 bit, only applicable if type=0
         # bit [03:00] Firmware Index, only applicable if type = 1
         # if type = 0, next words indicate the address that holds dek
         #              the 3rd word
         #----------------------------------------------------------------------------
         keyBlobContextOpt = 0xb0300000
         keyBlobDataOpt = 0xb1000000
         status, results, cmdStr = self.blhost.writeMemory(rundef.kRamFreeSpaceStart_LoadDekData, self.habDekFilename)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadKeyBlobContext, 0x4, keyBlobContextOpt)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadKeyBlobContext + 4, 0x4, rundef.kRamFreeSpaceStart_LoadDekData)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.fillMemory(rundef.kRamFreeSpaceStart_LoadKeyBlobContext + 8, 0x4, self.habDekDataOffset)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         status, results, cmdStr = self.blhost.configureMemory(self.bootDeviceMemId, rundef.kRamFreeSpaceStart_LoadKeyBlobContext)
         self.printLog(cmdStr)
         if status != boot.status.kStatus_Success:
             return False
         for i in range(imageCopies):
             ramFreeSpace = rundef.kRamFreeSpaceStart_LoadKeyBlobData + (rundef.kRamFreeSpaceStep_LoadKeyBlobData * i)
             status, results, cmdStr = self.blhost.fillMemory(ramFreeSpace, 0x4, keyBlobDataOpt + i)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
             ########################################################################
             # Flashloader will not erase keyblob region automatically, so we need to handle it here manually
             imageLoadAddr = 0x0
             if self.bootDevice == uidef.kBootDevice_SemcNand:
                 semcNandOpt, semcNandFcbOpt, imageInfo = uivar.getBootDeviceConfiguration(self.bootDevice)
                 imageLoadAddr = self.bootDeviceMemBase + (imageInfo[i] >> 16) * self.semcNandBlockSize
             elif self.bootDevice == uidef.kBootDevice_FlexspiNor:
                 imageLoadAddr = self.bootDeviceMemBase
             else:
                 pass
             alignedErasedSize = misc.align_up(imageLen, eraseUnit)
             needToBeErasedSize = misc.align_up(self.habDekDataOffset + rundef.kKeyBlobMaxSize, eraseUnit)
             if alignedErasedSize < needToBeErasedSize:
                 memEraseLen = needToBeErasedSize - alignedErasedSize
                 alignedMemEraseAddr = imageLoadAddr + alignedErasedSize
                 status, results, cmdStr = self.blhost.flashEraseRegion(alignedMemEraseAddr, memEraseLen, self.bootDeviceMemId)
                 self.printLog(cmdStr)
                 if status != boot.status.kStatus_Success:
                     return False
             ########################################################################
             status, results, cmdStr = self.blhost.configureMemory(self.bootDeviceMemId, ramFreeSpace)
             self.printLog(cmdStr)
             if status != boot.status.kStatus_Success:
                 return False
         if self.bootDevice == uidef.kBootDevice_FlexspiNor:
             self._programFlexspiNorConfigBlock()
     else:
         self.popupMsgBox('Dek file hasn\'t been generated!')
Example #16
0
    def readProgrammedMemoryAndShow(self):
        if not os.path.isfile(self.destAppFilename):
            self.popupMsgBox('You should program your image first!')
            return

        memLen = 0
        imageLen = os.path.getsize(self.destAppFilename)
        if self.bootDevice == uidef.kBootDevice_SemcNand:
            semcNandOpt, semcNandFcbOpt, imageInfo = uivar.getBootDeviceConfiguration(
                self.bootDevice)
            memLen += (imageInfo[self.semcNandImageCopies - 1] >>
                       16) * self.semcNandBlockSize
        elif self.bootDevice == uidef.kBootDevice_FlexspiNor:
            pass
        else:
            pass
        if self.habDekDataOffset != None and (
                self.habDekDataOffset + rundef.kKeyBlobMaxSize > imageLen):
            memLen += self.habDekDataOffset + rundef.kKeyBlobMaxSize
        else:
            memLen += imageLen

        memFilename = 'bootDeviceMem.dat'
        memFilepath = os.path.join(self.blhostVectorsDir, memFilename)
        status, results, cmdStr = self.blhost.readMemory(
            self.bootDeviceMemBase, memLen, memFilename, self.bootDeviceMemId)
        self.printLog(cmdStr)
        if status != boot.status.kStatus_Success:
            return False

        self.clearMem()
        memLen = os.path.getsize(memFilepath)
        memLeft = memLen
        addr = self.bootDeviceMemBase
        with open(memFilepath, 'rb') as fileObj:
            while memLeft > 0:
                memContent = ''
                contentToShow = self.getFormattedHexValue(addr) + '    '
                if memLeft > 16:
                    memContent = fileObj.read(16)
                else:
                    memContent = fileObj.read(memLeft)
                memLeft -= len(memContent)
                addr += len(memContent)
                visibleContent = ''
                for i in range(16):
                    if i < len(memContent):
                        halfbyteStr = str(
                            hex((ord(memContent[i]) & 0xF0) >> 4))
                        contentToShow += halfbyteStr[2]
                        halfbyteStr = str(
                            hex((ord(memContent[i]) & 0x0F) >> 0))
                        contentToShow += halfbyteStr[2] + ' '
                        if memContent[i] >= s_visibleAsciiStart and \
                           memContent[i] <= s_visibleAsciiEnd:
                            visibleContent += memContent[i]
                        else:
                            visibleContent += '.'
                    else:
                        contentToShow += '-- '
                        visibleContent += '-'
                contentToShow += '        ' + visibleContent
                self.printMem(contentToShow)
            fileObj.close()

        try:
            os.remove(memFilepath)
        except:
            pass
Example #17
0
    def readProgrammedMemoryAndShow( self ):
        if not os.path.isfile(self.destAppFilename):
            self.popupMsgBox('You should program your image first!')
            return
        self.clearMem()
        self._getInfoFromIvt()

        imageMemBase = 0
        readoutMemLen = 0
        imageFileLen = os.path.getsize(self.destAppFilename)
        if self.bootDevice == uidef.kBootDevice_SemcNand:
            semcNandOpt, semcNandFcbOpt, imageInfo = uivar.getBootDeviceConfiguration(self.bootDevice)
            status, dbbtAddr = self._showSemcNandFcb()
            if status:
                self._showSemcNandDbbt(dbbtAddr)
            # Only Readout first image
            imageMemBase = self.bootDeviceMemBase + (imageInfo[0] >> 16) * self.semcNandBlockSize
        elif self.bootDevice == uidef.kBootDevice_FlexspiNor or self.bootDevice == uidef.kBootDevice_LpspiNor:
            imageMemBase = self.bootDeviceMemBase
        else:
            pass
        if self.habDekDataOffset != None and (self.habDekDataOffset + memdef.kMemBlockSize_KeyBlob > imageFileLen):
            readoutMemLen += self.habDekDataOffset + memdef.kMemBlockSize_KeyBlob
        else:
            readoutMemLen += imageFileLen

        memFilename = 'bootDeviceMem.dat'
        memFilepath = os.path.join(self.blhostVectorsDir, memFilename)
        status, results, cmdStr = self.blhost.readMemory(imageMemBase, readoutMemLen, memFilename, self.bootDeviceMemId)
        self.printLog(cmdStr)
        if status != boot.status.kStatus_Success:
            return False

        readoutMemLen = os.path.getsize(memFilepath)
        memLeft = readoutMemLen
        addr = imageMemBase
        with open(memFilepath, 'rb') as fileObj:
            while memLeft > 0:
                contentToShow, memContent = self._getOneLineContentToShow(addr, memLeft, fileObj)
                memLeft -= len(memContent)
                addr += len(memContent)
                if addr <= imageMemBase + memdef.kMemBlockSize_FDCB:
                    if self.needToShowCfgIntr:
                        self.printMem('------------------------------------FDCB----------------------------------------------', uidef.kMemBlockColor_FDCB)
                        self.needToShowCfgIntr = False
                    self.printMem(contentToShow, uidef.kMemBlockColor_FDCB)
                elif addr <= imageMemBase + self.destAppIvtOffset:
                    if self.secureBootType == uidef.kSecureBootType_BeeCrypto:
                        ekib0Start = imageMemBase + memdef.kMemBlockOffset_EKIB0
                        eprdb0Start = imageMemBase + memdef.kMemBlockOffset_EPRDB0
                        ekib1Start = imageMemBase + memdef.kMemBlockOffset_EKIB1
                        eprdb1Start = imageMemBase + memdef.kMemBlockOffset_EPRDB1
                        if addr > ekib0Start and addr <= ekib0Start + memdef.kMemBlockSize_EKIB:
                            if self.needToShowEkib0Intr:
                                self.printMem('-----------------------------------EKIB0----------------------------------------------', uidef.kMemBlockColor_EKIB)
                                self.needToShowEkib0Intr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_EKIB)
                        elif addr > eprdb0Start and addr <= eprdb0Start + memdef.kMemBlockSize_EPRDB:
                            if self.needToShowEprdb0Intr:
                                self.printMem('-----------------------------------EPRDB0---------------------------------------------', uidef.kMemBlockColor_EPRDB)
                                self.needToShowEprdb0Intr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_EPRDB)
                        elif addr > ekib1Start and addr <= ekib1Start + memdef.kMemBlockSize_EKIB:
                            if self.needToShowEkib1Intr:
                                self.printMem('-----------------------------------EKIB1----------------------------------------------', uidef.kMemBlockColor_EKIB)
                                self.needToShowEkib1Intr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_EKIB)
                        elif addr > eprdb1Start and addr <= eprdb1Start + memdef.kMemBlockSize_EPRDB:
                            if self.needToShowEprdb1Intr:
                                self.printMem('-----------------------------------EPRDB1---------------------------------------------', uidef.kMemBlockColor_EPRDB)
                                self.needToShowEprdb1Intr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_EPRDB)
                        else:
                            self.printMem(contentToShow)
                    else:
                        self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppIvtOffset + memdef.kMemBlockSize_IVT:
                    if self.needToShowIvtIntr:
                        self.printMem('------------------------------------IVT-----------------------------------------------', uidef.kMemBlockColor_IVT)
                        self.needToShowIvtIntr = False
                    self.printMem(contentToShow, uidef.kMemBlockColor_IVT)
                elif addr <= imageMemBase + self.destAppIvtOffset + memdef.kMemBlockSize_IVT + memdef.kMemBlockSize_BootData:
                    if self.needToShowBootDataIntr:
                        self.printMem('---------------------------------Boot Data--------------------------------------------', uidef.kMemBlockColor_BootData)
                        self.needToShowBootDataIntr = False
                    self.printMem(contentToShow, uidef.kMemBlockColor_BootData)
                elif addr <= imageMemBase + self.destAppVectorOffset:
                    self.printMem(contentToShow)
                elif addr <= imageMemBase + self.destAppVectorOffset + self.destAppBinaryBytes:
                    if self.needToShowImageIntr:
                        self.printMem('-----------------------------------Image----------------------------------------------', uidef.kMemBlockColor_Image)
                        self.needToShowImageIntr = False
                    self.printMem(contentToShow, uidef.kMemBlockColor_Image)
                else:
                    hasShowed = False
                    if self.secureBootType == uidef.kSecureBootType_HabAuth or self.secureBootType == uidef.kSecureBootType_HabCrypto or \
                       (self.secureBootType == uidef.kSecureBootType_BeeCrypto and self.isCertEnabledForBee):
                        csfStart = imageMemBase + (self.destAppCsfAddress - self.destAppVectorAddress) + self.destAppInitialLoadSize
                        if addr > csfStart and addr <= csfStart + memdef.kMemBlockSize_CSF:
                            if self.needToShowCsfIntr:
                                self.printMem('------------------------------------CSF-----------------------------------------------', uidef.kMemBlockColor_CSF)
                                self.needToShowCsfIntr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_CSF)
                            hasShowed = True
                    if self.secureBootType == uidef.kSecureBootType_HabCrypto and self.habDekDataOffset != None:
                        keyBlobStart = imageMemBase + (self.destAppVectorOffset - self.destAppInitialLoadSize) + self.habDekDataOffset
                        if addr > keyBlobStart and addr <= keyBlobStart + memdef.kMemBlockSize_KeyBlob:
                            if self.needToShowKeyBlobIntr:
                                self.printMem('--------------------------------DEK KeyBlob-------------------------------------------', uidef.kMemBlockColor_KeyBlob)
                                self.needToShowKeyBlobIntr = False
                            self.printMem(contentToShow, uidef.kMemBlockColor_KeyBlob)
                            hasShowed = True
                    if not hasShowed:
                        self.printMem(contentToShow)
            fileObj.close()
        self._initShowIntr()
        try:
            os.remove(memFilepath)
        except:
            pass