Esempio n. 1
0
    void Initialize()
    {
#if defined(PLATFORM_ARM_MOTE2)
        if (COM_IsUsb(HalSystemConfig.DebugTextPort))
            WaitInterval = 5000;        // The USB port must be selected and the Start button pressed all during this time
        else
            WaitInterval = 2000;        // The USART port may be selected before powering on the Imote2, so it takes less time
#else
        WaitInterval     = 2000;
#endif

        SerialPortActive = FALSE;

        UsartPort        = USART_DEFAULT_PORT;

        UsingUsb         = FALSE;
        UsbPort          = USB1;
        UsbEventCode     = USB_DEBUG_EVENT_IN;

        //--//

        // wait an extra second for buttons and COM port to stabilize
        Events_WaitForEvents( 0, 1000 );

        // COM init is now delayed for TinyBootloader, so we need to initialize it here
        CPU_InitializeCommunication();

        //--//

        // set default baud rate
        if(UsartPort != DEBUG_TEXT_PORT)
        {
            DebuggerPort_Initialize( UsartPort );
        }
        // extra time to allow USB setup, so that we can see the printf
        Events_WaitForEvents( 0, 1000 );


        hal_printf( "PortBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_printf( "Build Date: %s %s\r\n",  __DATE__, __TIME__);

#if defined(__GNUC__)
        hal_printf( "GNU Compiler version %d\r\n", __GNUC__);
#elif defined(__ADSPBLACKFIN__)
        hal_printf( "Blackfin Compiler version %d\r\n", __VERSIONNUM__ );
#else
        hal_printf( "ARM Compiler version %d\r\n", __ARMCC_VERSION);
#endif
       
        //--//

        BlockStorageStream stream;
        FLASH_WORD ProgramWordCheck;

        if(!stream.Initialize(BlockUsage::CODE)) return;



        do
        {
            do
            {
            
                UINT32 addr = stream.CurrentAddress();
    			FLASH_WORD *pWord = &ProgramWordCheck;

                stream.Read( (BYTE**)&pWord, sizeof(FLASH_WORD) );

                if(*pWord == PROGRAM_WORD_CHECK)
                {
                    hal_printf("*** nXIP Program found at 0x%08x\r\n", addr );
    				Programs[ProgramCount++] = (UINT32)addr;
                }

                if(ProgramCount == MAX_PROGRAMS) break;
            }
            while( stream.Seek( BlockStorageStream::STREAM_SEEK_NEXT_BLOCK, BlockStorageStream::SeekCurrent ) );

        } while(stream.NextStream());

    }
BOOL MicroBooterUpdateProvider::InstallUpdate( MFUpdate* pUpdate, UINT8* pValidation, INT32 validationLen )
{
    if(pUpdate->Providers->Storage == NULL) return FALSE;

    if(!pUpdate->IsValidated()) return FALSE;

    switch(pUpdate->Header.UpdateType)
    {
        case MFUPDATE_UPDATETYPE_FIRMWARE:
            {
                HAL_UPDATE_CONFIG cfg;

                if(sizeof(cfg.UpdateSignature) < validationLen) return FALSE;
                
                cfg.Header.Enable = TRUE;
                cfg.UpdateID = pUpdate->Header.UpdateID;

                if(validationLen == sizeof(UINT32))
                {
                    cfg.UpdateSignType = HAL_UPDATE_CONFIG_SIGN_TYPE__CRC;
                }
                else
                {
                    cfg.UpdateSignType = HAL_UPDATE_CONFIG_SIGN_TYPE__SIGNATURE;
                }
                
                memcpy( cfg.UpdateSignature, pValidation, validationLen );

                if(HAL_CONFIG_BLOCK::UpdateBlockWithName(cfg.GetDriverName(), &cfg, sizeof(cfg), FALSE))
                {
                    CPU_Reset();
                }
            }
            break;
            
        case MFUPDATE_UPDATETYPE_ASSEMBLY:
            {
                BlockStorageStream stream;
                
                if(NULL == BlockStorageList::GetFirstDevice())
                {
                    BlockStorageList::Initialize();
                
                    BlockStorage_AddDevices();
                
                    BlockStorageList::InitializeDevices();
                }

                if(stream.Initialize(BlockUsage::DEPLOYMENT))
                {
                    if(pUpdate->Header.UpdateSubType == MFUPDATE_UPDATESUBTYPE_ASSEMBLY_REPLACE_DEPLOY)
                    {
                        do
                        {
                            stream.Erase(stream.Length);
                        }
                        while(stream.NextStream());

                        stream.Initialize(BlockUsage::DEPLOYMENT);
                    }
                    
                    do
                    {
                        UINT8 buf[512];
                        INT32 offset = 0;
                        INT32 len = sizeof(buf);
                        const BlockDeviceInfo* deviceInfo = stream.Device->GetDeviceInfo();
                        BOOL isXIP = deviceInfo->Attribute.SupportsXIP;
                        
                        const CLR_RECORD_ASSEMBLY* header;
                        INT32  headerInBytes = sizeof(CLR_RECORD_ASSEMBLY);
                        BYTE * headerBuffer  = NULL;
                        
                        if(!isXIP)
                        {
                            headerBuffer = (BYTE*)private_malloc( headerInBytes );  if(!headerBuffer) return FALSE;
                            memset( headerBuffer, 0,  headerInBytes );
                        }
                        
                        while(TRUE)
                        {
                            if(!stream.Read( &headerBuffer, headerInBytes )) break;
                        
                            header = (const CLR_RECORD_ASSEMBLY*)headerBuffer;
                        
                            // check header first before read
                            if(!header->GoodHeader())
                            {
                                stream.Seek(-headerInBytes);
                                
                                if(stream.IsErased(pUpdate->Header.UpdateSize))
                                {
                                    while(offset < pUpdate->Header.UpdateSize)
                                    {
                                        if((pUpdate->Header.UpdateSize - offset) < len)
                                        {
                                            len = pUpdate->Header.UpdateSize - offset;
                                        }
                                        
                                        offset += pUpdate->Providers->Storage->Read(pUpdate->StorageHandle, offset, buf, len);

                                        stream.Write(buf, len);
                                    }

                                    ClrReboot();
                                    return TRUE;
                                }
                                break;
                            }
                        
                            UINT32 AssemblySizeInByte = ROUNDTOMULTIPLE(header->TotalSize(), CLR_UINT32);
                        
                            stream.Seek( AssemblySizeInByte );
                        }
                        if(!isXIP) private_free( headerBuffer );
                    
                    }
                    while(stream.NextStream());
                }

            }
            break;
    }
    
    return FALSE;
}